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

Literals and Symbols in Axiom

I think Axiom needs a Literal domain that works in a manner similar to the Aldor language. SPAD and the Axiom interpreter should not automatically treat a constant like 2 is a PositiveInteger.

fricas
(1) -> 2

\label{eq1}2(1)
Type: PositiveInteger?

There are many situations when I might want it to mean something else, e.g. the mathematical category 2 or the some Boolean-like lattice domain, but I do not want to or cannot provide an artificial means of coercing PositiveInteger to things of the kind I want 2 to represent. Instead we should see:

      2
                               Type: Literal

Then if I use 2 in a context that requires, for example a PositiveInteger the interpreter should use it's normal function selection mechanism to choose coercions for 2 and 3 and and a suitable operation for +. So the end result for

fricas
2+3

\label{eq2}5(2)
Type: PositiveInteger?

would be the same.

If SPAD and the Axiom interpreter where changed to deal with literals in this way, then some Axiom domains would need to be extended to provide the needed coercions. Because Aldor already does this, the code required would be similar to that used in the Aldor-Axiom interface.

Here is the code from the Aldor interface for Axiom that deals with coercions from the domain Literal that is created by the Aldor compiler. (Some code is commented out to enable it to compile from within Axiom.) The point is that it must be possible to convert literals like 2 appearing in the Aldor source to something that Axiom can also understand, like Integer or however else it might be used.

aldor
#include "axiom"
-----------------------------------------------------------------------------
----
---- axlit.as: Function definitions needed by the Axiom library.
----
-----------------------------------------------------------------------------
---- Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
-----------------------------------------------------------------------------
-- This file extends some Axiom types provide literal formers and other -- functions for compiling Axiom-generated .ax files.
--import from AxiomLib; --inline from AxiomLib;
macro { -- rep x == x @ % pretend Rep; -- per r == r @ Rep pretend %;
Bit == Boolean; Str == String; SI == SingleInteger; I == Integer; NNI == NonNegativeInteger; PI == PositiveInteger; BVal == BuiltinValue; BArr == BuiltinArray; SEG == Segment; UNISEG == UniversalSegment; }
import { AXL_-error: String -> Exit; } from Foreign Lisp;
--error (s: String) : Exit == AXL_-error s; integer (l: Literal) : Literal == l;
--- Builtin value type. Used to store data values which fit in a single word. --BuiltinValue : with == add;
--- Builtin array type. 0-based indexing. --BuiltinArray : with { -- new: SI -> %; -- #: % -> SI; -- apply: (%, SI) -> BVal; -- set!: (%, SI, BVal) -> (); --} --== add { -- import { -- AXL_-arrayNew: SI -> %; -- AXL_-arraySize: % -> SI; -- AXL_-arrayRef: (%, SI) -> BVal; -- AXL_-arraySet: (%, SI, BVal) -> (); -- } from Foreign Lisp; -- -- new (n: SI) : % == AXL_-arrayNew n; -- # (x: %) : SI == AXL_-arraySize x; -- -- apply (x: %, n: SI) : BVal == -- AXL_-arrayRef(x, n); -- -- set! (x: %, n: SI, v: BVal) : () == -- - AXL_-arraySet(x, n, v); --}
extend String : with { string: Literal -> %; } == add { import { AXL_-LiteralToString: Literal -> %; } from Foreign Lisp;
string (l: Literal) : % == AXL_-LiteralToString l; }
extend Symbol : with { string: Literal -> %; } == add { string (l: Literal) : % == string(l)$String::%; }
extend SingleInteger : with { integer: Literal -> %; coerce: I -> %;
zero: () -> %; one: () -> %; inc: % -> %; dec: % -> %; leq: (%, %) -> Bit; spit: % -> (); } == add { Rep ==> Integer;
import { AXL_-LiteralToSingleInteger: Literal -> %; AXL_-zerofnSingleInteger: () -> %; AXL_-onefnSingleInteger: () -> %; AXL_-incSingleInteger: % -> %; AXL_-decSingleInteger: % -> %; AXL_-leSingleInteger: (%, %) -> Bit; AXL_-spitSInt: % -> (); } from Foreign Lisp;
integer (l: Literal) : % == AXL_-LiteralToSingleInteger l; coerce (n: I) : % == per n;
zero () : % == AXL_-zerofnSingleInteger(); one () : % == AXL_-onefnSingleInteger(); inc (n: %) : % == AXL_-incSingleInteger n; dec (n: %) : % == AXL_-decSingleInteger n; leq (x: %, y: %) : Bit == AXL_-leSingleInteger(x, y); spit (x: %) : () == AXL_-spitSInt x; }
extend Integer : with { integer: Literal -> %; } == add { import { AXL_-LiteralToInteger: Literal -> %; } from Foreign Lisp;
integer (l: Literal) : % == AXL_-LiteralToInteger l; }
extend NonNegativeInteger : with { integer: Literal -> %; coerce: Integer -> %; } == add { import { AXL_-IntegerIsNonNegative: Integer -> Bit; } from Foreign Lisp; Rep ==> Integer; import from Rep, String;
integer (l: Literal) : % == integer(l)$Integer::%;
coerce (i: Integer) : % == { if AXL_-IntegerIsNonNegative i then per i else error "Need a non-negative integer" } }
extend PositiveInteger : with { integer: Literal -> %; coerce: Integer -> %; } == add { import { AXL_-IntegerIsPositive: Integer -> Bit; } from Foreign Lisp; Rep ==> Integer; import from Rep, String; integer (l: Literal) : % == integer(l)$Integer::%; coerce (i: Integer) : % == { if AXL_-IntegerIsPositive i then per i else error "Need a positive integer" }
}
extend DoubleFloat: with { float: Literal -> %; } == add { import { AXL_-LiteralToDoubleFloat: Literal -> %; } from Foreign Lisp;
float (l: Literal) : % == AXL_-LiteralToDoubleFloat l; }
extend Float: with { float: Literal -> %; } == add { import { AXL_-StringToFloat: String -> %; } from Foreign Lisp;
import from String; float (l: Literal) : % == AXL_-StringToFloat string l; }
--extend Tuple (T: Type) : with { -- length: % -> SI; -- element: (%, SI) -> T; -- -- export from T; --} --== add { -- Rep ==> Record(sz: SI, values: BArr); -- import from Rep; -- -- length (t: %) : SI == rep(t).sz; -- element(t: %, n: SI): T == (rep(t).values.(dec n)) pretend T; --}
extend List (S: Type) : with { bracket: Tuple S -> %;
nil: %; first: % -> S; rest: % -> %; cons: (S, %) -> %;
empty: () -> %; empty?: % -> Bit; test: % -> Bit;
setfirst!: (%, S) -> S; setrest!: (%, %) -> %; } == add { import { AXL_-nilfn: () -> %; AXL_-car: % -> S; AXL_-cdr: % -> %; AXL_-cons: (S, %) -> %; AXL_-rplaca: (%, S) -> S; AXL_-rplacd: (%, %) -> %; AXL_-null?: % -> Bit; } from Foreign Lisp;
[t: Tuple S]: % == { import { one: () -> %; dec: % -> %; leq: (%, %) -> Bit; } from SI;
--!! Remove the local when we can use the export. local nil: % := empty();
l := nil; i := length t; while leq(one(), i) repeat { l := cons(element(t, i), l); i := dec i; } l; }
-- Redefine a selection of List operations for efficiency.
nil : % == AXL_-nilfn(); first (x: %): S == AXL_-car x; rest (x: %): % == AXL_-cdr x; cons (x: S, y: %): % == AXL_-cons(x, y); setfirst!(x: %, y: S): S == AXL_-rplaca(x, y); setrest! (x: %, y: %): % == AXL_-rplacd(x, y);
empty (): % == AXL_-nilfn(); empty? (x: %): Bit == AXL_-null? x; test (x: %): Bit == not empty? x; }
aldor
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/7096130453832849089-25px003.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.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/7096130453832849089-25px003.as", line 1: 
#include "axiom"
^
[L1 C1] #1 (Error) Could not open file `axiom'.
The )library system command was not called after compilation.

0 and 1 obsolete --Bill Page, Sun, 27 Jul 2008 03:05:59 -0700 reply
If SPAD and the Axiom interpreter created values from the domain Literal then it would be unnecessary to treat constants like 0 and 1 in a special manner, i.e. as unary functions. The coercions from Literal would do that job.




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