|
|
last edited 5 months ago by test1 |
1 2 | ||
Editor: test1
Time: 2024/04/09 12:42:36 GMT+0 |
||
Note: |
changed: -#include "axiom" #include "fricas" changed: -#include "axiom" #include "fricas" changed: -That's pretty cool that Axiom knows 'MyWord' is a 'MyMonoid'! That's pretty cool that FriCAS knows 'MyWord' is a 'MyMonoid'! changed: -Oops, that's **not** cool! :( Aldor and the Axiom interpreter Oops, that's **not** cool! :( Aldor and the FriCAS interpreter changed: -#include "axiom" #include "fricas" changed: -This is what Axiom sees: This is what FriCAS sees: changed: -#include "axiom" #include "fricas" changed: -This is what Axiom sees: This is what FriCAS sees: changed: -#include "axiom" #include "fricas"
We can use the Aldor extend
construct to add MyMonoid(...)
as
a category to a previously defined domain.
(1) -> <aldor> #include "fricas"
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) } }</aldor>
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mymonoid.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.
Compiling Lisp source code from file ./mymonoid.lsp Issuing )library command for mymonoid
Reading /var/aw/var/LatexWiki/mymonoid.asy MyMonoid is now explicitly exposed in frame initial MyMonoid will be automatically loaded when needed from /var/aw/var/LatexWiki/mymonoid
#include "fricas" #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/axiom-wiki/var/LatexWiki/7928879980347790310-25px002.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. Compiling Lisp source code from file ./7928879980347790310-25px002.lsp Issuing )library command for 7928879980347790310-25px002 Reading /var/aw/var/LatexWiki/7928879980347790310-25px002.asy MyWord is now explicitly exposed in frame initial MyWord will be automatically loaded when needed from /var/aw/var/LatexWiki/7928879980347790310-25px002
This is what Axiom sees:
)sh MyMonoid
MyMonoid(T: Type,m: ((T, T) -> T)) is a category constructor Abbreviation for MyMonoid is MYMONOI This constructor is exposed in this frame. ------------------------------- Operations --------------------------------
)sh MyWord
MyWord is a domain constructor. Abbreviation for MyWord is MYWORD This constructor is exposed in this frame. 4 Names for 5 Operations in this Domain. ------------------------------- Operations --------------------------------
c : (%,%) -> % coerce : MyWord -> OutputForm coerce : String -> % d : (%, %) -> % square : MyWord -> MyWord
Try it:
a := "Bingo"::MyWord
(1) |
square a
(2) |
MyWord has MyMonoid(MyWord,c)
(3) |
That's pretty cool that FriCAS knows MyWord
is a MyMonoid
!
But:
MyWord has MyMonoid(MyWord,d)
(4) |
Oops, that's not cool! :( Aldor and the FriCAS interpreter ought to be able to do better than this.
Here are some more examples:
#include "fricas" #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/axiom-wiki/var/LatexWiki/774031628094989668-25px006.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. Compiling Lisp source code from file ./774031628094989668-25px006.lsp Issuing )library command for 774031628094989668-25px006 Reading /var/aw/var/LatexWiki/774031628094989668-25px006.asy MyInt is now explicitly exposed in frame initial MyInt will be automatically loaded when needed from /var/aw/var/LatexWiki/774031628094989668-25px006
This is what FriCAS sees:
)sh MyInt
MyInt is a domain constructor. Abbreviation for MyInt is MYINT This constructor is exposed in this frame. 3 Names for 4 Operations in this Domain. ------------------------------- Operations --------------------------------
?+? : (%,%) -> % coerce : MyInt -> OutputForm coerce : Integer -> % square : MyInt -> MyInt
Try it:
b := 3::MyInt
(5) |
b+1
(6) |
square b
(7) |
This is very general. Notice that we can rename the monoid operation from * to +!
#include "fricas" #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/axiom-wiki/var/LatexWiki/5335661638819928165-25px009.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. Compiling Lisp source code from file ./5335661638819928165-25px009.lsp Issuing )library command for 5335661638819928165-25px009 Reading /var/aw/var/LatexWiki/5335661638819928165-25px009.asy MyFloat is now explicitly exposed in frame initial MyFloat will be automatically loaded when needed from /var/aw/var/LatexWiki/5335661638819928165-25px009
This is what FriCAS sees:
)sh MyFloat
MyFloat is a domain constructor. Abbreviation for MyFloat is MYFLOAT This constructor is exposed in this frame. 3 Names for 4 Operations in this Domain. ------------------------------- Operations --------------------------------
?+? : (%,%) -> % coerce : MyFloat -> OutputForm coerce : DoubleFloat -> % square : MyFloat -> MyFloat
Try it:
f := 3.1::DoubleFloat::MyFloat
>> Error detected within library code: Unrecognized atom in OutputForm
Here's a variation on the example dirprod.as
posted by Ralf Hemmecke on Mon, 13 Mar 2006 14:33:34 +0100
'[Axiom-developer]? Re: BINGO,Curiosities with Axiom mathematical structures'
#include "fricas" 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/axiom-wiki/var/LatexWiki/mydirprod.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. Compiling Lisp source code from file ./mydirprod.lsp Issuing )library command for mydirprod Reading /var/aw/var/LatexWiki/mydirprod.asy DirProdCat is now explicitly exposed in frame initial DirProdCat will be automatically loaded when needed from /var/aw/var/LatexWiki/mydirprod DirProd is now explicitly exposed in frame initial DirProd will be automatically loaded when needed from /var/aw/var/LatexWiki/mydirprod
Try it:
x:= Integer;
y:= NonNegativeInteger;
DPx ==> DirProd(2,x);
DPx has DirProdCat(2,x)
(8) |
DPx has DirProdCat(2,y)
(9) |
DPx has DirProdCat(3,x)
(10) |
DPx has DirProdCat(3,y)
(11) |
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)
DirProd(2,Integer) is a domain constructor. Abbreviation for DirProd is DirProd This constructor is exposed in this frame. 1 Names for 1 Operations in this Domain. ------------------------------- Operations --------------------------------
identity : % -> %
)show DirProd(2,y)
DirProd(2,NonNegativeInteger) is a domain constructor. Abbreviation for DirProd is DirProd This constructor is exposed in this frame. 1 Names for 1 Operations in this Domain. ------------------------------- Operations --------------------------------
identity : % -> %