PositiveInteger and NonNegativeInteger are subdomains of Integer.
axiom Integer
Type: Domain axiom Ring
Type: SubDomain(Domain) Unfortunately the original Axiom library did not include definitions of these domains. axiom [Integer,PrimeField(3)] Type: List(Domain) axiom [Ring,Field] Type: List(SubDomain(Domain)) OpenAxiom has implemented spad )abbrev domain DOMAIN Domain
Domain():SetCategory
== add
coerce(x:%):OutputForm ==
n:SExpression:=devaluate(x)$Lisp
#n=1 => car(n) pretend OutputForm
n pretend OutputForm
x = y ==
devaluate(x)$Lisp = devaluate(y)$Lisp
spad Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/1491057242942260927-25px004.spad using
old system compiler.
DOMAIN abbreviates domain Domain
------------------------------------------------------------------------
initializing NRLIB DOMAIN for Domain
compiling into NRLIB DOMAIN
compiling exported coerce : $ -> OutputForm
Time: 0.03 SEC.spad )abbrev domain SUBDOM SubDomain
SubDomain(D:Domain):SetCategory
== add
coerce(x:%):OutputForm ==
n:SExpression:=devaluate(x)$Lisp
#n=1 => car(n) pretend OutputForm
n pretend OutputForm
x = y ==
devaluate(x)$Lisp = devaluate(y)$Lisp
spad Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/1455332092143083773-25px005.spad using
old system compiler.
SUBDOM abbreviates domain SubDomain
------------------------------------------------------------------------
initializing NRLIB SUBDOM for SubDomain
compiling into NRLIB SUBDOM
compiling exported coerce : $ -> OutputForm
Time: 0.02 SEC.axiom [Integer,PrimeField(3)]
Type: List(Domain) axiom %.1
Type: Domain axiom [Ring,Field,IntegerNumberSystem]
Type: List(SubDomain(NIL)) Also we would like to be able to coerce both Domain and SubDomain to InputForm axiom Integer::InputForm
Type: InputForm Coercions like these are a special case in the Axiom interpreter. Here we modify the treatment for InputForm in references to '(InputForm) below. From: interp/i-coerce.boot boot coerceInteractive(triple,t2) ==
-- bind flag for recording/reporting instantiations
-- (see recordInstantiation)
t1 := objMode triple
val := objVal triple
null(t2) or t2 = $EmptyMode => NIL
t2 = t1 => triple
t2 = '$NoValueMode => objNew(val,t2)
if t2 is ['SubDomain,x,.] then t2:= x
-- JHD added category Aug 1996 for BasicMath
-- WSP modified for coercion to InputForm Sept 2008
t1 in '((Category) (Mode) (Domain) (SubDomain (Domain))) =>
t2 = $OutputForm => objNew(val,t2)
t2 = '(InputForm) => objNewWrap(val,t2)
NIL
t1 = '$NoValueMode =>
if $compilingMap then clearDependentMaps($mapName,nil)
throwKeyedMsg("S2IC0009",[t2,$mapName])
$insideCoerceInteractive: local := true
expr2 := EQUAL(t2,$OutputForm)
if expr2 then startTimingProcess 'print
else startTimingProcess 'coercion
-- next 2 lines handle cases like '"failed"
result :=
expr2 and (t1 = val) => objNew(val,$OutputForm)
expr2 and t1 is ['Variable,var] => objNewWrap(var,$OutputForm)
t2 = '(InputForm) => objNewWrap(val,t2)
coerceInt0(triple,t2)
if expr2 then stopTimingProcess 'print
else stopTimingProcess 'coercion
result
boot Value = T ; compiling file "/var/zope2/var/LatexWiki/5299509375252708736-25px009.clisp" (written 06 MAR 2010 05:53:07 PM): ; compiling (IN-PACKAGE "BOOT") ; compiling (DEFUN |coerceInteractive| ...) Now we get axiom a:=Integer::InputForm
Type: InputForm axiom interpret(a)$InputForm
Type: Domain axiom unparse(a)$InputForm
Type: String axiom b:=PrimeField(11)::InputForm
Type: InputForm axiom interpret(b)$InputForm
Type: Domain axiom unparse(b)$InputForm
Type: String axiom c:=DirectProduct(3,Fraction Integer)::InputForm
Type: InputForm axiom interpret(c)$InputForm
Type: Domain axiom unparse(c)$InputForm
Type: String axiom d:=Ring::InputForm
Type: InputForm axiom interpret(d)$InputForm
Type: SubDomain(Domain) axiom unparse(d)$InputForm
Type: String Here is a useful function for parsing input strings axiom parse(s:String):InputForm == ncParseFromString(s)$Lisp pretend InputForm Type: Void axiom parse("Integer")
axiom Compiling function parse with type String -> InputForm
Type: InputForm There are still problems problems with values of domains in types axiom )set output tex off axiom )set output algebra on axiom CliffordAlgebra(4,Fraction Integer, quadraticForm matrix [[1,0,0,0], [0,-1,0,0], [0,0,-1,0], [0,0,0,-1]]) Type: Domain axiom %::InputForm Type: InputForm axiom parse("CliffordAlgebra(4,Fraction Integer, quadraticForm matrix [[1,0,0,0], [0,-1,0,0],
[0,0,-1,0], [0,0,0,-1]])")
Type: InputForm axiom interpret(%) Type: Domain axiom %::InputForm Type: InputForm We can easily implement similar functionality at the Spad
(algebra library) level by extending the spad )abbrev package INFORM1 InputFormFunctions1 --)boot $noSubsumption := false spad Compiling FriCAS source code from file
/var/zope2/var/LatexWiki/8025279438643830910-25px014.spad using
old system compiler.
INFORM1 abbreviates package InputFormFunctions1
------------------------------------------------------------------------
initializing NRLIB INFORM1 for InputFormFunctions1
compiling into NRLIB INFORM1
compiling exported domainToInputForm : () -> InputForm
Time: 0.02 SEC.axiom domainToInputForm()$INFORM1(PrimeField 7) Type: InputForm axiom interpret(parse("x^2+1"))$INFORM1(Polynomial Float)
Type: Polynomial(Float) |