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.

\begin{aldor}[mymonoid] #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) } } \end{aldor}

\begin{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; \end{aldor}

This is what Axiom sees: \begin{axiom} )sh MyMonoid )sh MyWord \end{axiom}

Try it: \begin{axiom} a := Bingo square a MyWord has MyMonoid(MyWord, c) \end{axiom}

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

But: \begin{axiom} MyWord has MyMonoid(MyWord, d) \end{axiom} Oops, that's not cool! :( Aldor and the Axiom interpreter ought to be able to do better than this.

Here are some more examples: \begin{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; \end{aldor}

This is what Axiom sees: \begin{axiom} )sh MyInt \end{axiom}

Try it: \begin{axiom} b := 3::MyInt b+1 square b \end{axiom}

This is very general. Notice that we can rename the monoid operation from to +! \begin{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; \end{aldor}

This is what Axiom sees: \begin{axiom} )sh MyFloat \end{axiom}

Try it: \begin{axiom} f := 3.1::DoubleFloat::MyFloat g := 2::DoubleFloat::MyFloat -- The operator + in MyInt is * in Integer! f+g square f \end{axiom}

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'

\begin{aldor}[mydirprod] #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; } \end{aldor}

Try it:

\begin{axiom} x:= Integer; y:= NonNegativeInteger; DPx ==> DirProd(2, x); DPx has DirProdCat(2, x) DPx has DirProdCat(2, y) DPx has DirProdCat(3, x) DPx has DirProdCat(3, y) \end{axiom}

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

\begin{axiom} )show DirProd(2,x) )show DirProd(2,y) \end{axiom}


Some or all expressions may not have rendered properly, because Axiom returned the following error:
Error: export AXIOM=/usr/local/lib/open-axiom/x86_64-unknown-linux/1.2.0-2008-05-25; export ALDORROOT=/usr/local/aldor/linux/1.1.0; export PATH=$ALDORROOT/bin:$PATH; export HOME=/var/zope2/var/LatexWiki; ulimit -t 240; $AXIOM/bin/AXIOMsys < /var/zope2/var/LatexWiki/7529637680036276826-25px.axm
/bin/sh: /usr/local/lib/open-axiom/x86_64-unknown-linux/1.2.0-2008-05-25/bin/AXIOMsys: not found


Some or all expressions may not have rendered properly, because Latex returned the following error:
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
 \write18 enabled.
 %&-line parsing enabled.
entering extended mode
(./4193123159003299828-16.0px.tex
LaTeX2e <2005/12/01>
Babel <v3.8h> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, arabic, farsi, croatian, ukrainian, russian, bulgarian, czech, slov
ak, danish, dutch, finnish, basque, french, german, ngerman, ibycus, greek, mon
ogreek, ancientgreek, hungarian, italian, latin, mongolian, norsk, icelandic, i
nterlingua, turkish, coptic, romanian, welsh, serbian, slovenian, estonian, esp
eranto, uppersorbian, indonesian, polish, portuguese, spanish, catalan, galicia
n, swedish, ukenglish, pinyin, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2005/09/16 v1.4f Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size12.clo))
(/usr/share/texmf-texlive/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `? option.
(/usr/share/texmf-texlive/tex/latex/amsmath/amstext.sty
(/usr/share/texmf-texlive/tex/latex/amsmath/amsgen.sty))
(/usr/share/texmf-texlive/tex/latex/amsmath/amsbsy.sty)
(/usr/share/texmf-texlive/tex/latex/amsmath/amsopn.sty))
(/usr/share/texmf-texlive/tex/latex/amsfonts/amsfonts.sty)
(/usr/share/texmf-texlive/tex/latex/amsfonts/amssymb.sty)
(/usr/share/texmf-texlive/tex/latex/amscls/amsthm.sty)
(/usr/share/texmf-texlive/tex/latex/setspace/setspace.sty
Package: `setspace 6.7 <2000/12/01>
) (/usr/share/texmf-texlive/tex/generic/xypic/xy.sty
(/usr/share/texmf-texlive/tex/generic/xypic/xy.tex Bootstrap'ing: catcodes,
docmode, (/usr/share/texmf-texlive/tex/generic/xypic/xyrecat.tex)
(/usr/share/texmf-texlive/tex/generic/xypic/xyidioms.tex)

Xy-pic version 3.7 <1999/02/16> Copyright (c) 1991-1998 by Kristoffer H. Rose <krisrose@ens-lyon.fr> Xy-pic is free software: see the User's Guide for details.

Loading kernel: messages; fonts; allocations: state, direction, utility macros; pictures: \xy, positions, objects, decorations; kernel objects: directionals, circles, text; options; algorithms: directions, edges, connections; Xy-pic loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyall.tex Xy-pic option: All features v.3.3 (/usr/share/texmf-texlive/tex/generic/xypic/xycurve.tex Xy-pic option: Curve and Spline extension v.3.7 curve, circles, loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyframe.tex Xy-pic option: Frame and Bracket extension v.3.7 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xycmtip.tex Xy-pic option: Computer Modern tip extension v.3.3 (/usr/share/texmf-texlive/tex/generic/xypic/xytips.tex Xy-pic option: More Tips extension v.3.3 loaded) loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyline.tex Xy-pic option: Line styles extension v.3.6 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyrotate.tex Xy-pic option: Rotate and Scale extension v.3.3 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xycolor.tex Xy-pic option: Colour extension v.3.3 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xymatrix.tex Xy-pic option: Matrix feature v.3.4 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyarrow.tex Xy-pic option: Arrow and Path feature v.3.5 path, \ar, loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xygraph.tex Xy-pic option: Graph feature v.3.7 loaded) loaded)) (/usr/share/texmf-texlive/tex/latex/graphics/graphicx.sty (/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty) (/usr/share/texmf-texlive/tex/latex/graphics/graphics.sty (/usr/share/texmf-texlive/tex/latex/graphics/trig.sty) (/etc/texmf/tex/latex/config/graphics.cfg) (/usr/share/texmf-texlive/tex/latex/graphics/dvips.def))) (/usr/share/texmf-texlive/tex/latex/graphics/color.sty (/etc/texmf/tex/latex/config/color.cfg) (/usr/share/texmf-texlive/tex/latex/graphics/dvipsnam.def)) (/usr/share/texmf-texlive/tex/latex/tools/verbatim.sty) (/usr/share/texmf/tex/latex/graphviz/graphviz.sty (/usr/share/texmf-texlive/tex/latex/psfrag/psfrag.sty)) (/usr/share/texmf/tex/latex/sagetex.sty Writing sage input file 4193123159003299828-16.0px.sage (./4193123159003299828-16.0px.sout)) (/usr/share/texmf-texlive/tex/latex/gnuplottex/gnuplottex.sty (/usr/share/texmf-texlive/tex/latex/base/latexsym.sty) (/usr/share/texmf-texlive/tex/latex/moreverb/moreverb.sty) (/usr/share/texmf-texlive/tex/latex/base/ifthen.sty)) (./4193123159003299828-16.0px.aux) You can't use `macro parameter character #' in horizontal mode. l.63 # include "axiom" [1] You can't use `macro parameter character #' in vertical mode. l.78 # include "axiom" You can't use `macro parameter character #' in horizontal mode. l.79 # library MyMonoid "mymonoid.ao"; [2] [3] [4] [5] You can't use `macro parameter character #' in vertical mode. l.114 # include "axiom" You can't use `macro parameter character #' in horizontal mode. l.115 # library MyMonoid "mymonoid.ao"; [6] [7] [8] You can't use `macro parameter character #' in vertical mode. l.142 # include "axiom" You can't use `macro parameter character #' in horizontal mode. l.143 # library MyMonoid "mymonoid.ao"; [9] [10] [11] You can't use `macro parameter character #' in horizontal mode. l.172 # include "axiom" [12] [13] [14] (/usr/share/texmf-texlive/tex/latex/amsfonts/umsa.fd) (/usr/share/texmf-texlive/tex/latex/amsfonts/umsb.fd) (/usr/share/texmf-texlive/tex/latex/base/ulasy.fd) [15] (./4193123159003299828-16.0px.aux) ) (see the transcript file for additional information) Output written on 4193123159003299828-16.0px.dvi (15 pages, 5488 bytes). Transcript written on 4193123159003299828-16.0px.log.




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