login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

This page discusses cases where instantiating of a parameter collapses two generically different functions.

The page is connected to the thread http://groups.google.com/group/fricas-devel/browse_frm/thread/5097633953c6841d/c3cb9671206609f8#c3cb9671206609f8

On Tue, Mar 24, 2009 at 4:24 AM, Ralf Hemmecke wrote:

Aldor's libalgebra has some bugs in it that seem to be really hard to track down. I faintly remember one such bug that I could nearly assign to the coexistence of:

  *: (Integer, %) -> % and *: (R, %) -> %

where R is instantiated with Integer. The problem here is a hidden overloading of implementations. Suppose you implement something like

aldor
#include "axiom"
MyWeirdPoly(R: Ring): Ring with { *: (Integer, %) -> %; *: (R, %) -> %; coerce: R -> %; -- ... } == Integer add { coerce(r:R):% == r pretend %; ((i: Integer) * (x: %)): % == ((i+i)::%)*x; ((r: R) * (x: %)): % == (r::%) * x -- ... }
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/6603601906039884450-25px001.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
   Compiling Lisp source code from file 
      ./6603601906039884450-25px001.lsp
   Issuing )library command for 6603601906039884450-25px001
   Reading /var/zope2/var/LatexWiki/6603601906039884450-25px001.asy
   MyWeirdPoly is now explicitly exposed in frame initial 
   MyWeirdPoly will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/6603601906039884450-25px001
>> System error: The bounding indices 163 and 162 are bad for a sequence of length 162. See also: The ANSI Standard, Glossary entry for "bounding index designator" The ANSI Standard, writeup for Issue SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR

axiom
)show MyWeirdPoly
MyWeirdPoly(R: Ring) is a domain constructor Abbreviation for MyWeirdPoly is MYWEIRD This constructor is exposed in this frame. ------------------------------- Operations -------------------------------- ?*? : (PositiveInteger,%) -> % ?*? : (Integer,%) -> % ?*? : (%,%) -> % ?*? : (R,%) -> % ?+? : (%,%) -> % -? : % -> % ?-? : (%,%) -> % 0 : () -> % 1 : () -> % ?=? : (%,%) -> Boolean ?^? : (%,PositiveInteger) -> % coerce : % -> OutputForm coerce : Integer -> % coerce : R -> % hash : % -> SingleInteger latex : % -> String one? : % -> Boolean sample : () -> % zero? : % -> Boolean ?~=? : (%,%) -> Boolean ?*? : (NonNegativeInteger,%) -> % ?^? : (%,NonNegativeInteger) -> % characteristic : () -> NonNegativeInteger recip : % -> Union(value1: %,failed: Enumeration(failed)) subtractIfCan : (%,%) -> Union(value1: %,failed: Enumeration(failed))

axiom
p:=1$MyWeirdPoly(Integer)

\label{eq1}1(1)
Type: MyWeirdPoly?(Integer)
axiom
3*p

\label{eq2}6(2)
Type: MyWeirdPoly?(Integer)

Now lets try the same thing in SPAD

spad
)abbrev package MWP2 MyWeirdPoly2
MyWeirdPoly2(R: Ring): Ring with
  _*: (Integer, %) -> %
  _*: (R, %) -> %
  coerce: R -> %
  -- ...
 == Integer add
  coerce(r:R):% == r pretend %
  ((i: Integer) * (x: %)): % == ((i+i)::%)*x
  ((r: R) * (x: %)): % == (r::%) * x
  -- ...
spad
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/4436499139492326087-25px004.spad using 
      old system compiler.
   MWP2 abbreviates package MyWeirdPoly2 
------------------------------------------------------------------------
   initializing NRLIB MWP2 for MyWeirdPoly2 
   compiling into NRLIB MWP2 
   compiling exported coerce : R -> $
      MWP2;coerce;R$;1 is replaced by r 
Time: 0.04 SEC.
compiling exported * : (Integer,$) -> $ Time: 0.01 SEC.
compiling exported * : (R,$) -> $ Time: 0 SEC.
(time taken in buildFunctor: 10)
;;; *** |MyWeirdPoly2| REDEFINED
;;; *** |MyWeirdPoly2| REDEFINED Time: 0.02 SEC.
Cumulative Statistics for Constructor MyWeirdPoly2 Time: 0.07 seconds
--------------non extending category---------------------- .. MyWeirdPoly2(#1) of cat (|Join| (|Ring|) (CATEGORY |domain| (SIGNATURE * ($ (|Integer|) $)) (SIGNATURE * ($ |#1| $)) (SIGNATURE |coerce| ($ |#1|)))) has no (|IntegerNumberSystem|) finalizing NRLIB MWP2 Processing MyWeirdPoly2 for Browser database: --->-->MyWeirdPoly2((* (% (Integer) %))): Not documented!!!! --->-->MyWeirdPoly2((* (% R %))): Not documented!!!! --->-->MyWeirdPoly2((coerce (% R))): Not documented!!!! --->-->MyWeirdPoly2(constructor): Not documented!!!! --->-->MyWeirdPoly2(): Missing Description ; compiling file "/var/zope2/var/LatexWiki/MWP2.NRLIB/MWP2.lsp" (written 17 AUG 2011 02:59:08 AM):
; /var/zope2/var/LatexWiki/MWP2.NRLIB/MWP2.fasl written ; compilation finished in 0:00:00.062 ------------------------------------------------------------------------ MyWeirdPoly2 is now explicitly exposed in frame initial MyWeirdPoly2 will be automatically loaded when needed from /var/zope2/var/LatexWiki/MWP2.NRLIB/MWP2
>> System error: The bounding indices 163 and 162 are bad for a sequence of length 162. See also: The ANSI Standard, Glossary entry for "bounding index designator" The ANSI Standard, writeup for Issue SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR

axiom
)show MyWeirdPoly2
MyWeirdPoly2(R: Ring) is a domain constructor Abbreviation for MyWeirdPoly2 is MWP2 This constructor is exposed in this frame. ------------------------------- Operations -------------------------------- ?*? : (R,%) -> % ?*? : (%,%) -> % ?*? : (Integer,%) -> % ?*? : (PositiveInteger,%) -> % ?+? : (%,%) -> % ?-? : (%,%) -> % -? : % -> % ?=? : (%,%) -> Boolean 1 : () -> % 0 : () -> % ?^? : (%,PositiveInteger) -> % coerce : R -> % coerce : Integer -> % coerce : % -> OutputForm hash : % -> SingleInteger latex : % -> String one? : % -> Boolean recip : % -> Union(%,"failed") sample : () -> % zero? : % -> Boolean ?~=? : (%,%) -> Boolean ?*? : (NonNegativeInteger,%) -> % ?^? : (%,NonNegativeInteger) -> % characteristic : () -> NonNegativeInteger subtractIfCan : (%,%) -> Union(%,"failed")

axiom
q:=1$MyWeirdPoly2(Integer)

\label{eq3}1(3)
Type: MyWeirdPoly2?(Integer)
axiom
3*q

\label{eq4}3(4)
Type: MyWeirdPoly2?(Integer)

Surprise!

SPAD produces the opposite result from Aldor.




  Subject:   Be Bold !!
  ( 13 subscribers )  
Please rate this page: