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 /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

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 /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:

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 : MyWord -> OutputForm coerce : String -> % d : (%, %) -> % square : MyWord -> MyWord

Try it:

fricas
a := "Bingo"::MyWord

\label{eq1}\hbox{\axiomType{Bingo}\ }(1)
Type: MyWord?
fricas
square a

\label{eq2}\hbox{\axiomType{BingoBingo}\ }(2)
Type: MyWord?
fricas
MyWord has MyMonoid(MyWord, c)

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

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

But:

fricas
MyWord has MyMonoid(MyWord, d)

\label{eq4} \mbox{\rm true} (4)
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 /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:

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 : MyInt -> OutputForm coerce : Integer -> % square : MyInt -> MyInt

Try it:

fricas
b := 3::MyInt

\label{eq5}3(5)
Type: MyInt?
fricas
b+1

\label{eq6}4(6)
Type: MyInt?
fricas
square b

\label{eq7}6(7)
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 /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:

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 : MyFloat -> OutputForm coerce : DoubleFloat -> % 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 /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:

fricas
x:= Integer;
Type: Type
fricas
y:= NonNegativeInteger;
Type: Type
fricas
DPx ==> DirProd(2, x);
Type: Void
fricas
DPx has DirProdCat(2, x)

\label{eq8} \mbox{\rm true} (8)
Type: Boolean
fricas
DPx has DirProdCat(2, y)

\label{eq9} \mbox{\rm false} (9)
Type: Boolean
fricas
DPx has DirProdCat(3, x)

\label{eq10} \mbox{\rm true} (10)
Type: Boolean
fricas
DPx has DirProdCat(3, y)

\label{eq11} \mbox{\rm false} (11)
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 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)
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 : % -> %
fricas
)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 : % -> %




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