Martin's beautiful idea: We can use the Aldor aldor #include "axiom" aldor Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/mymonoid.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 ./mymonoid.lsp
Issuing )library command for mymonoid
Reading /var/zope2/var/LatexWiki/mymonoid.asy
MyMonoid is now explicitly exposed in frame initial
MyMonoid will be automatically loaded when needed from
/var/zope2/var/LatexWiki/mymonoidaldor #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;
}
aldor Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/9179840256381573157-25px002.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
./9179840256381573157-25px002.lsp
Issuing )library command for 9179840256381573157-25px002
Reading /var/zope2/var/LatexWiki/9179840256381573157-25px002.asy
MyWord is now explicitly exposed in frame initial
MyWord will be automatically loaded when needed from
/var/zope2/var/LatexWiki/9179840256381573157-25px002This is what Axiom sees: axiom )sh MyMonoid axiom )sh MyWord Try it: axiom a := "Bingo"::MyWord
Type: MyWord axiom square a
Type: MyWord axiom MyWord has MyMonoid(MyWord, c)
Type: Boolean That's pretty cool that Axiom knows But: axiom MyWord has MyMonoid(MyWord, d)
Type: Boolean Oops, that's not cool! :( Aldor and the Axiom interpreter ought to be able to do better than this. Here are some more examples: 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;
aldor Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/797595480097738355-25px006.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
./797595480097738355-25px006.lsp
Issuing )library command for 797595480097738355-25px006
Reading /var/zope2/var/LatexWiki/797595480097738355-25px006.asy
MyInt is now explicitly exposed in frame initial
MyInt will be automatically loaded when needed from
/var/zope2/var/LatexWiki/797595480097738355-25px006This is what Axiom sees: axiom )sh MyInt Try it: axiom b := 3::MyInt
Type: MyInt axiom b+1
Type: MyInt axiom square b
Type: MyInt This is very general. Notice that we can rename the monoid operation from * to +! 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;
aldor Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/4949806727147037492-25px009.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
./4949806727147037492-25px009.lsp
Issuing )library command for 4949806727147037492-25px009
Reading /var/zope2/var/LatexWiki/4949806727147037492-25px009.asy
MyFloat is now explicitly exposed in frame initial
MyFloat will be automatically loaded when needed from
/var/zope2/var/LatexWiki/4949806727147037492-25px009This is what Axiom sees: axiom )sh MyFloat Try it: axiom f := 3.1::DoubleFloat::MyFloat
Type: MyFloat axiom g := 2::DoubleFloat::MyFloat
Type: MyFloat axiom -- The operator + in MyInt is * in Integer! f+g
Type: MyFloat axiom square f
Type: MyFloat Here's a variation on the example aldor #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;
}
aldor Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/mydirprod.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 ./mydirprod.lsp
Issuing )library command for mydirprod
Reading /var/zope2/var/LatexWiki/mydirprod.asy
DirProdCat is now explicitly exposed in frame initial
DirProdCat will be automatically loaded when needed from
/var/zope2/var/LatexWiki/mydirprod
DirProd is now explicitly exposed in frame initial
DirProd will be automatically loaded when needed from
/var/zope2/var/LatexWiki/mydirprodTry it: axiom x:= Integer; Type: Domain axiom y:= NonNegativeInteger; Type: Domain axiom DPx ==> DirProd(2, x); Type: Void axiom DPx has DirProdCat(2, x)
Type: Boolean axiom DPx has DirProdCat(2, y)
Type: Boolean axiom DPx has DirProdCat(3, x)
Type: Boolean axiom DPx has DirProdCat(3, y)
Type: Boolean 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 axiom )show DirProd(2,x) axiom )show DirProd(2,y) |