|
|
|
last edited 1 year 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 #P"/var/aw/var/LatexWiki/mymonoid.asy" MyMonoid is now explicitly exposed in frame initial
>> System error: The function BOOT::ASHARPMKAUTOLOADFUNCTOR is undefined.
#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 #P"/var/aw/var/LatexWiki/7928879980347790310-25px002.asy"
MyWord is now explicitly exposed in frame initialThis 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 : String -> % coerce : MyWord -> OutputForm d : (%, %) -> % square : MyWord -> MyWord
Try it:
a := "Bingo"::MyWord
| (1) |
square a
LISP output: BingoBingo
MyWord has MyMonoid(MyWord,c)
| (2) |
That's pretty cool that FriCAS knows MyWord is a MyMonoid!
But:
MyWord has MyMonoid(MyWord,d)
| (3) |
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 #P"/var/aw/var/LatexWiki/774031628094989668-25px006.asy"
MyInt is now explicitly exposed in frame initialThis 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 : Integer -> % coerce : MyInt -> OutputForm square : MyInt -> MyInt
Try it:
b := 3::MyInt
| (4) |
b+1
| (5) |
square b
LISP output: 6
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 #P"/var/aw/var/LatexWiki/5335661638819928165-25px009.asy"
MyFloat is now explicitly exposed in frame initialThis 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 : DoubleFloat -> % coerce : MyFloat -> OutputForm 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 #P"/var/aw/var/LatexWiki/mydirprod.asy"
DirProdCat is now explicitly exposed in frame initial
>> System error:
The function BOOT::ASHARPMKAUTOLOADFUNCTOR is undefined.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