

last edited 15 years ago 
1  
Editor:
Time: 2007/11/18 18:29:09 GMT8 

Note: 
changed:  Martin's beautiful idea: We can use the Aldor 'extend' construct to add 'MyMonoid(...)' as a category to a previously defined domain. \begin{aldor}[mymonoid] #include "axiom" MyMonoid(T: Type, m: (T, T) > T): Category == with { square:T > T; coerce:T > OutputForm; default {  This hack for output only works for domains that  have a representation known to Lisp. coerce(x:T):OutputForm == x pretend OutputForm; square(t: T): T == m(t,t) } } \end{aldor} \begin{aldor} #include "axiom" #library MyMonoid "mymonoid.ao"; import from MyMonoid; MyWord: with { coerce: String > %; c:(%, %) > %; d:(%, %) > %; } == add { Rep == String; import from String; coerce(a: String): % == per(a); c(a: %, b: %):% == per(concat(rep(a), rep(b))); d(a: %, b: %):% == a; } import from MyWord; extend MyWord: MyMonoid(MyWord, c) == add; \end{aldor} This is what Axiom sees: \begin{axiom} )sh MyMonoid )sh MyWord \end{axiom} Try it: \begin{axiom} a := "Bingo"::MyWord square a MyWord has MyMonoid(MyWord, c) \end{axiom} That's pretty cool that Axiom knows 'MyWord' is a 'MyMonoid'! But: \begin{axiom} MyWord has MyMonoid(MyWord, d) \end{axiom} Oops, that's **not** cool! :( Aldor and the Axiom interpreter ought to be able to do better than this. Here are some more examples: \begin{aldor} #include "axiom" #library MyMonoid "mymonoid.ao"; import from MyMonoid; MyInt: with { coerce: Integer > %; +:(%, %) > %; } == add { Rep == Integer; import from Integer; coerce(a: Integer): % == per(a); (a:%) + (b:%):% == per(rep(a)+rep(b)) } import from MyInt; extend MyInt: MyMonoid(MyInt, +) == add; \end{aldor} This is what Axiom sees: \begin{axiom} )sh MyInt \end{axiom} Try it: \begin{axiom} b := 3::MyInt b+1 square b \end{axiom} This is very general. Notice that we can rename the monoid operation from * to +! \begin{aldor} #include "axiom" #library MyMonoid "mymonoid.ao"; import from MyMonoid; MyFloat: with { coerce: DoubleFloat > %; +:(%, %) > %; } == add { Rep == DoubleFloat; import from DoubleFloat; coerce(a: DoubleFloat): % == per(a); (a:%) + (b:%):% == per(rep(a)*rep(b)) } import from MyFloat; extend MyFloat: MyMonoid(MyFloat, +) == add; \end{aldor} This is what Axiom sees: \begin{axiom} )sh MyFloat \end{axiom} Try it: \begin{axiom} f := 3.1::DoubleFloat::MyFloat g := 2::DoubleFloat::MyFloat  The operator + in MyInt is * in Integer! f+g square f \end{axiom} Here's a variation on the example 'dirprod.as' posted by Ralf Hemmecke on 'Mon, 13 Mar 2006 14:33:34 +0100' '[Axiomdeveloper] Re: BINGO,Curiosities with Axiom mathematical structures' \begin{aldor}[mydirprod] #include "axiom" define DirProdCat(n: Integer, R: Type): Category == with { identity: % > %; } DirProd(n: Integer, R: Type): DirProdCat(n, R) == add { Rep == List Integer;  dummy implementation import from Rep; identity(x: %): % == x; } \end{aldor} Try it: \begin{axiom} x:= Integer; y:= NonNegativeInteger; DPx ==> DirProd(2, x); DPx has DirProdCat(2, x) DPx has DirProdCat(2, y) DPx has DirProdCat(3, x) DPx has DirProdCat(3, y) \end{axiom} The results show that the Aldor compiler treats a domain (R) and an element of a domain (n) differently in terms of information retained for the 'has' operation. Had the 'Type' in 'R: Type' been replaced by 'Symbol' and the lines defining x, y removed, all results would have been 'true'. Notice here, contrary to Ralf's example, both the 'DirProdCat' and 'DirProd' constructors totally ignored the parameters. The two constructions 'DirProd(2,x)' and 'DirProd(2,y)' are really identical in implemetation. So the only information to distinguish 'DirProdCat(2,x)' and 'DirProdCat(2,y)' must have come from the declaration of the parameters (on the left of ':'). \begin{axiom} )show DirProd(2,x) )show DirProd(2,y) \end{axiom}
We can use the Aldor extend
construct to add MyMonoid(...)
as
a category to a previously defined domain.
#include "axiom"
MyMonoid(T: Type,m: (T, T) > T): Category == with { square:T > T; coerce:T > OutputForm; default {  This hack for output only works for domains that  have a representation known to Lisp. coerce(x:T):OutputForm == x pretend OutputForm; square(t: T): T == m(t, t) } }
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiomwiki/var/LatexWiki/mymonoid.as using Aldor compiler and options O Fasy Fao Flsp lfricas MnoALDOR_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.
#include "axiom" #library MyMonoid "mymonoid.ao"; import from MyMonoid; MyWord: with { coerce: String > %; c:(%,%) > %; d:(%, %) > %; } == add { Rep == String; import from String; coerce(a: String): % == per(a); c(a: %, b: %):% == per(concat(rep(a), rep(b))); d(a: %, b: %):% == a; }
import from MyWord; extend MyWord: MyMonoid(MyWord,c) == add;
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiomwiki/var/LatexWiki/917984025638157315725px002.as using Aldor compiler and options O Fasy Fao Flsp lfricas MnoALDOR_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.
This is what Axiom sees:
)sh MyMonoid
The )show system command is used to display information about types or partial types. For example,)show Integer will show information about Integer .
MyMonoid is not the name of a known type constructor. If you want to see information about any operations named MyMonoid ,issue )display operations MyMonoid
)sh MyWord
The )show system command is used to display information about types or partial types. For example,)show Integer will show information about Integer .
MyWord is not the name of a known type constructor. If you want to see information about any operations named MyWord ,issue )display operations MyWord
Try it:
a := "Bingo"::MyWord
MyWord is not a valid type.
That's pretty cool that Axiom knows MyWord
is a MyMonoid
!
But:
MyWord has MyMonoid(MyWord,d)
MyWord is not a valid type.
Oops, that's not cool! :( Aldor and the Axiom interpreter ought to be able to do better than this.
Here are some more examples:
#include "axiom" #library MyMonoid "mymonoid.ao"; import from MyMonoid; MyInt: with { coerce: Integer > %; +:(%,%) > %; } == add { Rep == Integer; import from Integer; coerce(a: Integer): % == per(a); (a:%) + (b:%):% == per(rep(a)+rep(b)) } import from MyInt; extend MyInt: MyMonoid(MyInt, +) == add;
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiomwiki/var/LatexWiki/79759548009773835525px006.as using Aldor compiler and options O Fasy Fao Flsp lfricas MnoALDOR_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.
This is what Axiom sees:
)sh MyInt
The )show system command is used to display information about types or partial types. For example,)show Integer will show information about Integer .
MyInt is not the name of a known type constructor. If you want to see information about any operations named MyInt ,issue )display operations MyInt
Try it:
b := 3::MyInt
MyInt is not a valid type.
This is very general. Notice that we can rename the monoid operation from * to +!
#include "axiom" #library MyMonoid "mymonoid.ao"; import from MyMonoid; MyFloat: with { coerce: DoubleFloat > %; +:(%,%) > %; } == add { Rep == DoubleFloat; import from DoubleFloat; coerce(a: DoubleFloat): % == per(a); (a:%) + (b:%):% == per(rep(a)*rep(b)) } import from MyFloat; extend MyFloat: MyMonoid(MyFloat, +) == add;
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiomwiki/var/LatexWiki/494980672714703749225px009.as using Aldor compiler and options O Fasy Fao Flsp lfricas MnoALDOR_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.
This is what Axiom sees:
)sh MyFloat
The )show system command is used to display information about types or partial types. For example,)show Integer will show information about Integer .
MyFloat is not the name of a known type constructor. If you want to see information about any operations named MyFloat ,issue )display operations MyFloat
Try it:
f := 3.1::DoubleFloat::MyFloat
MyFloat is not a valid type.
Here's a variation on the example dirprod.as
posted by Ralf Hemmecke on Mon, 13 Mar 2006 14:33:34 +0100
'[Axiomdeveloper]? Re: BINGO,Curiosities with Axiom mathematical structures'
#include "axiom" define DirProdCat(n: Integer,R: Type): Category == with { identity: % > %; } DirProd(n: Integer, R: Type): DirProdCat(n, R) == add { Rep == List Integer;  dummy implementation import from Rep; identity(x: %): % == x; }
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiomwiki/var/LatexWiki/mydirprod.as using Aldor compiler and options O Fasy Fao Flsp lfricas MnoALDOR_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.
Try it:
x:= Integer;
y:= NonNegativeInteger;
DPx ==> DirProd(2,x);
DPx has DirProdCat(2,x)
There are no library operations named DirProd Use HyperDoc Browse or issue )what op DirProd to learn if there is any operation containing " DirProd " in its name.
Cannot find a definition or applicable library operation named DirProd with argument type(s) PositiveInteger Type
Perhaps you should use "@" to indicate the required return type,or "$" to specify which version of the function you need.
The results show that the Aldor compiler treats a domain (R) and an element of a domain (n) differently in terms of information retained for the has
operation. Had the Type
in R: Type
been replaced by Symbol
and the lines defining x, y removed, all results would have been true
. Notice here, contrary to Ralf's example, both the DirProdCat
and DirProd
constructors totally ignored the parameters. The two constructions DirProd(2,x)
and DirProd(2,y)
are really identical in implemetation. So the only information to distinguish DirProdCat(2,x)
and DirProdCat(2,y)
must have come from the declaration of the parameters (on the left of :
).
)show DirProd(2,x)
The )show system command is used to display information about types or partial types. For example,)show Integer will show information about Integer .
DirProd is not the name of a known type constructor. If you want to see information about any operations named DirProd ,issue )display operations DirProd
2 is not the name of a known type constructor. If you want to see information about any operations named 2 ,issue )display operations 2
x is not the name of a known type constructor. If you want to see information about any operations named x ,issue )display operations x
)show DirProd(2,y)
The )show system command is used to display information about types or partial types. For example,)show Integer will show information about Integer .
DirProd is not the name of a known type constructor. If you want to see information about any operations named DirProd ,issue )display operations DirProd
2 is not the name of a known type constructor. If you want to see information about any operations named 2 ,issue )display operations 2
y is not the name of a known type constructor. If you want to see information about any operations named y ,issue )display operations y