login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Martin's beautiful idea:

We can use the Aldor extend construct to add MyMonoid(...) as a category to a previously defined domain.

fricas
(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>
fricas
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.
fricas
Compiling Lisp source code from file ./mymonoid.lsp
   Issuing )library command for mymonoid
fricas
Reading #P"/var/aw/var/LatexWiki/mymonoid.asy"
   MyMonoid is now explicitly exposed in frame initial 
>> System error: The function BOOT::ASHARPMKAUTOLOADFUNCTOR is undefined.

aldor
#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;
aldor
   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 initial

This is what Axiom sees:

fricas
)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 --------------------------------
fricas
)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:

fricas
a := "Bingo"::MyWord

\label{eq1}\hbox{\axiomType{Bingo}\ }(1)
Type: MyWord?
fricas
square a
LISP output: BingoBingo
Type: MyWord?
fricas
MyWord has MyMonoid(MyWord, c)

\label{eq2} \mbox{\rm true} (2)
Type: Boolean

That's pretty cool that FriCAS knows MyWord is a MyMonoid!

But:

fricas
MyWord has MyMonoid(MyWord, d)

\label{eq3} \mbox{\rm true} (3)
Type: Boolean

Oops, that's not cool! :( Aldor and the FriCAS interpreter ought to be able to do better than this.

Here are some more examples:

aldor
#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;
aldor
   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 initial

This is what FriCAS sees:

fricas
)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:

fricas
b := 3::MyInt

\label{eq4}3(4)
Type: MyInt?
fricas
b+1

\label{eq5}4(5)
Type: MyInt?
fricas
square b
LISP output: 6
Type: MyInt?

This is very general. Notice that we can rename the monoid operation from * to +!

aldor
#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;
aldor
   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 initial

This is what FriCAS sees:

fricas
)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:

fricas
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'

aldor
#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;
 }
aldor
   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:

fricas
x:= Integer;
Type: Type
fricas
y:= NonNegativeInteger;
Type: Type
fricas
DPx ==> DirProd(2, x);
Type: Void
fricas
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 :).

fricas
)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
fricas
)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




  Subject:   Be Bold !!
  ( 15 subscribers )  
Please rate this page: