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/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6603601906039884450-25px001.as
using Aldor compiler and options
-O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I $FRICAS/algebra
Use the system command )set compiler args to change these
options.
The )library system command was not called after compilation.
fricas
)show MyWeirdPoly
The )show system command is used to display information about types
or partial types. For example, )show Integer will show
information about Integer .
MyWeirdPoly is not the name of a known type constructor. If you
want to see information about any operations named MyWeirdPoly ,
issue
)display operations MyWeirdPoly
fricas
p:=1$MyWeirdPoly(Integer)
There are no library operations named MyWeirdPoly
Use HyperDoc Browse or issue
)what op MyWeirdPoly
to learn if there is any operation containing " MyWeirdPoly " in
its name.
Cannot find a definition or applicable library operation named
MyWeirdPoly with argument type(s)
Type
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.
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/lib/zope2.10/instance/axiom-wiki/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: 0)
;;; *** |MyWeirdPoly2| REDEFINED
;;; *** |MyWeirdPoly2| REDEFINED
Time: 0 SEC.
Cumulative Statistics for Constructor MyWeirdPoly2
Time: 0.01 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(constructor): Not documented!!!!
--->-->MyWeirdPoly2((* (% (Integer) %))): Not documented!!!!
--->-->MyWeirdPoly2((* (% R %))): Not documented!!!!
--->-->MyWeirdPoly2((coerce (% R))): Not documented!!!!
--->-->MyWeirdPoly2(): Missing Description
; compiling file "/var/aw/var/LatexWiki/MWP2.NRLIB/MWP2.lsp" (written 04 APR 2022 07:14:55 PM):
; /var/aw/var/LatexWiki/MWP2.NRLIB/MWP2.fasl written
; compilation finished in 0:00:00.015
------------------------------------------------------------------------
MyWeirdPoly2 is now explicitly exposed in frame initial
MyWeirdPoly2 will be automatically loaded when needed from
/var/aw/var/LatexWiki/MWP2.NRLIB/MWP2
fricas
)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) -> % annihilate? : (%, %) -> Boolean
antiCommutator : (%, %) -> % associator : (%, %, %) -> %
coerce : R -> % coerce : Integer -> %
coerce : % -> OutputForm commutator : (%, %) -> %
hash : % -> SingleInteger latex : % -> String
one? : % -> Boolean opposite? : (%, %) -> Boolean
recip : % -> Union(%,"failed") sample : () -> %
zero? : % -> Boolean ?~=? : (%, %) -> Boolean
?*? : (NonNegativeInteger, %) -> %
?^? : (%, NonNegativeInteger) -> %
characteristic : () -> NonNegativeInteger
hashUpdate! : (HashState, %) -> HashState
leftPower : (%, NonNegativeInteger) -> %
leftPower : (%, PositiveInteger) -> %
leftRecip : % -> Union(%,"failed")
rightPower : (%, NonNegativeInteger) -> %
rightPower : (%, PositiveInteger) -> %
rightRecip : % -> Union(%,"failed")
subtractIfCan : (%, %) -> Union(%,"failed")
fricas
q:=1$MyWeirdPoly2(Integer)
Type: MyWeirdPoly2
?(Integer)
fricas
3*q
Type: MyWeirdPoly2
?(Integer)
Surprise!
SPAD produces the opposite result from Aldor.