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

Edit detail for SandBoxHiddenOverloading revision 2 of 3

1 2 3
Editor: Bill Page
Time: 2009/03/23 12:26:36 GMT-7
Note: spad version

changed:
-  (i: Integer) * (x: %): % == ((i+i)::%)*x;
-  (r: R) * (x: %): % == (r::%) * x
  ((i: Integer) * (x: %)): % == ((i+i)::%)*x;
  ((r: R) * (x: %)): % == (r::%) * x

added:
Now lets try the same thing in SPAD

\begin{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
  -- ...
\end{spad}

\begin {axiom}
)show MyWeirdPoly2
\end{axiom}

\begin{axiom}
q:=1$MyWeirdPoly2(Integer)
3*q
\end{axiom}

Surprise!

  SPAD produces the opposite result from Aldor.

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-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   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

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

axiom
p:=1$MyWeirdPoly(Integer)
LatexWiki Image(1)
Type: MyWeirdPoly? Integer
axiom
3*p
LatexWiki Image(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.01 SEC.
compiling exported * : (Integer,$) -> $ Time: 0 SEC.
compiling exported * : (R,$) -> $ Time: 0 SEC.
(time taken in buildFunctor: 1)
;;; *** |MyWeirdPoly2| REDEFINED
;;; *** |MyWeirdPoly2| REDEFINED Time: 0.01 SEC.
Cumulative Statistics for Constructor MyWeirdPoly2 Time: 0.02 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 ------------------------------------------------------------------------ MyWeirdPoly2 is now explicitly exposed in frame initial MyWeirdPoly2 will be automatically loaded when needed from /var/zope2/var/LatexWiki/MWP2.NRLIB/code

axiom
)show MyWeirdPoly2
MyWeirdPoly2 R: Ring is a domain constructor Abbreviation for MyWeirdPoly2 is MWP2 This constructor is exposed in this frame. Issue )edit /var/zope2/var/LatexWiki/4436499139492326087-25px004.spad to see algebra source code for MWP2
------------------------------- Operations -------------------------------- ?*? : (R,%) -> % ?*? : (%,%) -> % ?*? : (Integer,%) -> % ?*? : (PositiveInteger,%) -> % ?**? : (%,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) -> % ?^? : (%,NonNegativeInteger) -> % characteristic : () -> NonNegativeInteger subtractIfCan : (%,%) -> Union(%,"failed")

axiom
q:=1$MyWeirdPoly2(Integer)
LatexWiki Image(3)
Type: MyWeirdPoly2? Integer
axiom
3*q
LatexWiki Image(4)
Type: MyWeirdPoly2? Integer

Surprise!

SPAD produces the opposite result from Aldor.