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.

aldor
#include "axiom"
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 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.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mymonoid.as", line 3: MyMonoid(T: Type, m: (T, T) -> T): Category == with { ............^.........^........^ [L3 C13] #9 (Error) No meaning for identifier `Type'. [L3 C23] #12 (Error) Have determined 1 possible types for the expression. Meaning 1: Type, Type The context requires an expression of type Tuple(Type). [L3 C32] #10 (Error) There are 0 meanings for `T' in this context. The possible types were: T: Type, a local The context requires an expression of type Tuple(Type). [L3 C32] #13 (Fatal Error) Too many errors (use `-M emax=n' or `-M no-emax' to change the limit).
The )library system command was not called after compilation.

aldor
#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;
}
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/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.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
#9 (Warning) Could not use archive file `libaxiom.al'.
Program fault (segmentation violation).#10 (Error) Program fault (segmentation violation).
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
The )library system command was not called after compilation.

This is what Axiom sees:

fricas
)sh MyMonoid
The )show system command is used to display information about types or partial types. For example, )show Integer will show information about Integer .
MyMonoid is not the name of a known type constructor. If you want to see information about any operations named MyMonoid , issue )display operations MyMonoid
fricas
)sh MyWord
The )show system command is used to display information about types or partial types. For example, )show Integer will show information about Integer .
MyWord is not the name of a known type constructor. If you want to see information about any operations named MyWord , issue )display operations MyWord

Try it:

fricas
a := "Bingo"::MyWord
Cannot convert from type String to NIL for value "Bingo"
square a
There are no library operations named square Use HyperDoc Browse or issue )what op square to learn if there is any operation containing " square " in its name.
Cannot find a definition or applicable library operation named square with argument type(s) Variable(a)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. MyWord has MyMonoid(MyWord, c)
There are no library operations named MyMonoid Use HyperDoc Browse or issue )what op MyMonoid to learn if there is any operation containing " MyMonoid " in its name.
Cannot find a definition or applicable library operation named MyMonoid with argument type(s) Variable(MyWord) Variable(c)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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

But:

fricas
MyWord has MyMonoid(MyWord, d)
There are no library operations named MyMonoid Use HyperDoc Browse or issue )what op MyMonoid to learn if there is any operation containing " MyMonoid " in its name.
Cannot find a definition or applicable library operation named MyMonoid with argument type(s) Variable(MyWord) Variable(d)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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/lib/zope2.10/instance/axiom-wiki/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.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
#9 (Warning) Could not use archive file `libaxiom.al'.
Program fault (segmentation violation).#10 (Error) Program fault (segmentation violation).
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
The )library system command was not called after compilation.

This is what Axiom sees:

fricas
)sh MyInt
The )show system command is used to display information about types or partial types. For example, )show Integer will show information about Integer .
MyInt is not the name of a known type constructor. If you want to see information about any operations named MyInt , issue )display operations MyInt

Try it:

fricas
b := 3::MyInt
Cannot convert from type PositiveInteger to NIL for value 3
b+1

\label{eq1}b + 1(1)
Type: Polynomial(Integer)
fricas
square b
There are no library operations named square Use HyperDoc Browse or issue )what op square to learn if there is any operation containing " square " in its name.
Cannot find a definition or applicable library operation named square with argument type(s) Variable(b)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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/lib/zope2.10/instance/axiom-wiki/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.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
#9 (Warning) Could not use archive file `libaxiom.al'.
Program fault (segmentation violation).#10 (Error) Program fault (segmentation violation).
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
The )library system command was not called after compilation.

This is what Axiom sees:

fricas
)sh MyFloat
The )show system command is used to display information about types or partial types. For example, )show Integer will show information about Integer .
MyFloat is not the name of a known type constructor. If you want to see information about any operations named MyFloat , issue )display operations MyFloat

Try it:

fricas
f := 3.1::DoubleFloat::MyFloat
Cannot convert from type DoubleFloat to NIL for value 3.0999999999999996
g := 2::DoubleFloat::MyFloat
Cannot convert from type DoubleFloat to NIL for value 2.0
-- The operator + in MyInt is * in Integer! f+g

\label{eq2}g + f(2)
Type: Polynomial(Integer)
fricas
square f
There are no library operations named square Use HyperDoc Browse or issue )what op square to learn if there is any operation containing " square " in its name.
Cannot find a definition or applicable library operation named square with argument type(s) Variable(f)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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 "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/lib/zope2.10/instance/axiom-wiki/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.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mydirprod.as", line 2: define DirProdCat(n: Integer, R: Type): Category == with { ..................^..^...........^ [L2 C19] #11 (Error) Have determined 1 possible types for the expression. Meaning 1: ?, ? The context requires an expression of type Tuple(Type). [L2 C22] #9 (Error) No meaning for identifier `Integer'. [L2 C34] #10 (Error) No meaning for identifier `Type'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mydirprod.as", line 3: identity: % -> %; ................^ [L3 C17] #12 (Error) There are no suitable meanings for the operator `->'. [L3 C17] #13 (Fatal Error) Too many errors (use `-M emax=n' or `-M no-emax' to change the limit).
The )library system command was not called after compilation.

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. DPx has DirProdCat(2, y)
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. DPx has DirProdCat(3, 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. DPx has DirProdCat(3, y)
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 !!
  ( 13 subscribers )  
Please rate this page: