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

Edit detail for SandBoxDefineInteger revision 1 of 11

1 2 3 4 5 6 7 8 9 10 11
Editor: Bill Page
Time: 2008/07/21 06:49:36 GMT-7
Note: new

changed:
-
Why are PositiveInteger and NonNegativeInteger defined as SubDomains of Integer?
Here is an (imperfect) example of defining Integers from a more primitive domain
rather than the other way around.

This definition was suggested by Ralf Hemmecke in discussions at ISSAC 2008.

First let's define a constructor name 'Difference'. Like 'Fraction'
the representation will be pairs of some suitable type and equality
will be defined by an equivalence relation on this representation.
'Integer' then can be constructed as 'Difference(CardinalNumber)'
as a kind of algebraic "quotient".

The point of this construction is to illustrate several problems.
One is to ask why the current generation of compilers in computer
algebra systems such as Axiom, e.g. Spad and Aldor, are not able
to automatically convert this mathematically correct specification
to an efficient implementation. Another issue is why these languages
do not have some built-in support for such common algebraic
constructions as "taking a quotient". In particular, there seems
to be no general way of defining a "canonical representation".

\begin{spad}
)abbrev domain DIFF Difference
Difference(T:AbelianMonoid): AbelianMonoid with
    _-:(%,%) -> %
  == add
    Rep == Record(neg:T, pos:T)

    0 == per [0,0]
    1 == per [0,1]

    x+y == per [rep(x).neg+rep(y).neg, rep(x).pos+rep(y).pos]
    x-y == per [rep(x).neg+rep(y).pos, rep(x).pos+rep(y).neg
    x=y == rep(x).neg+rep(y).pos = rep(x).pos+rep(y).neg

    -- how to define this properly?
    coerce(x:%):OutputForm == rep(x)::OutputForm
\end{spad}

Why are PositiveInteger? and NonNegativeInteger? defined as SubDomains? of Integer? Here is an (imperfect) example of defining Integers from a more primitive domain rather than the other way around.

This definition was suggested by Ralf Hemmecke in discussions at ISSAC 2008.

First let's define a constructor name Difference. Like Fraction the representation will be pairs of some suitable type and equality will be defined by an equivalence relation on this representation. Integer then can be constructed as Difference(CardinalNumber) as a kind of algebraic "quotient".

The point of this construction is to illustrate several problems. One is to ask why the current generation of compilers in computer algebra systems such as Axiom, e.g. Spad and Aldor, are not able to automatically convert this mathematically correct specification to an efficient implementation. Another issue is why these languages do not have some built-in support for such common algebraic constructions as "taking a quotient". In particular, there seems to be no general way of defining a "canonical representation".

spad
)abbrev domain DIFF Difference Difference(T:AbelianMonoid): AbelianMonoid with _-:(%,%) -> % == add Rep == Record(neg:T, pos:T)
0 == per [0,0] 1 == per [0,1]
x+y == per [rep(x).neg+rep(y).neg, rep(x).pos+rep(y).pos] x-y == per [rep(x).neg+rep(y).pos, rep(x).pos+rep(y).neg x=y == rep(x).neg+rep(y).pos = rep(x).pos+rep(y).neg
-- how to define this properly? coerce(x:%):OutputForm == rep(x)::OutputForm
spad
   Compiling OpenAxiom source code from file 
      /var/zope2/var/LatexWiki/5180795550171710960-25px001.spad using 
      Spad compiler.
   DIFF abbreviates domain Difference 
******** Boot Syntax Error detected ********
The current line is:
8> ; ^ Currently preparsed lines are:
9> x=y == rep(x).neg+rep(y).pos = rep(x).pos+rep(y).neg; 11> coerce(x:%):OutputForm == rep(x)::OutputForm)
There are no valid tokens. The prior token was
Structure of type TOKEN Byte:[Slot Type]Slot Name :Slot Value 0:SYMBOL :|neg| 8:TYPE :IDENTIFIER 16:NONBLANK :T