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

PositiveInteger and NonNegativeInteger are subdomains of Integer.

Domain is a domain whose values are all domains. Categories are values of the domain SubDomain Domain. For example:

axiom
Integer

\label{eq1}\hbox{\axiomType{Integer}\ }(1)
Type: Domain
axiom
Ring

\label{eq2}\hbox{\axiomType{Ring}\ }(2)
Type: SubDomain(Domain)

Unfortunately the original Axiom library did not include definitions of these domains.

axiom
[Integer,PrimeField(3)]
LISP output: (UNPRINTABLE UNPRINTABLE)
Type: List(Domain)

axiom
[Ring,Field]
LISP output: (UNPRINTABLE UNPRINTABLE)
Type: List(SubDomain(Domain))

OpenAxiom has implemented Domain and replaced SubDomain Domain with Category. Here we try to provide something similar for FriCAS.

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.
compiling exported = : ($,$) -> Boolean Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |Domain| REDEFINED
;;; *** |Domain| REDEFINED Time: 0.01 SEC.
Cumulative Statistics for Constructor Domain Time: 0.04 seconds
finalizing NRLIB DOMAIN Processing Domain for Browser database: --->-->Domain(): Missing Description ; compiling file "/var/zope2/var/LatexWiki/DOMAIN.NRLIB/DOMAIN.lsp" (written 06 MAR 2010 05:53:06 PM): ; compiling (/VERSIONCHECK 2) ; compiling (DEFUN |DOMAIN;coerce;$Of;1| ...) ; compiling (DEFUN |DOMAIN;=;2$B;2| ...) ; compiling (DEFUN |Domain| ...) ; compiling (DEFUN |Domain;| ...) ; compiling (MAKEPROP (QUOTE |Domain|) ...) ; compiling (MAKEPROP (QUOTE |Domain|) ...)
; /var/zope2/var/LatexWiki/DOMAIN.NRLIB/DOMAIN.fasl written ; compilation finished in 0:00:00.058 ------------------------------------------------------------------------ Domain is now explicitly exposed in frame initial Domain will be automatically loaded when needed from /var/zope2/var/LatexWiki/DOMAIN.NRLIB/DOMAIN

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.
compiling exported = : ($,$) -> Boolean Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |SubDomain| REDEFINED
;;; *** |SubDomain| REDEFINED Time: 0.01 SEC.
Cumulative Statistics for Constructor SubDomain Time: 0.03 seconds
finalizing NRLIB SUBDOM Processing SubDomain for Browser database: --->-->SubDomain(): Missing Description ; compiling file "/var/zope2/var/LatexWiki/SUBDOM.NRLIB/SUBDOM.lsp" (written 06 MAR 2010 05:53:07 PM): ; compiling (/VERSIONCHECK 2) ; compiling (DEFUN |SUBDOM;coerce;$Of;1| ...) ; compiling (DEFUN |SUBDOM;=;2$B;2| ...) ; compiling (DEFUN |SubDomain| ...) ; compiling (DEFUN |SubDomain;| ...) ; compiling (MAKEPROP (QUOTE |SubDomain|) ...)
; /var/zope2/var/LatexWiki/SUBDOM.NRLIB/SUBDOM.fasl written ; compilation finished in 0:00:00.040 ------------------------------------------------------------------------ SubDomain is now explicitly exposed in frame initial SubDomain will be automatically loaded when needed from /var/zope2/var/LatexWiki/SUBDOM.NRLIB/SUBDOM

axiom
[Integer,PrimeField(3)]

\label{eq3}\left[ \hbox{\axiomType{Integer}\ } , \:{\hbox{\axiomType{PrimeField}\ } \left({3}\right)}\right](3)
Type: List(Domain)
axiom
%.1

\label{eq4}\hbox{\axiomType{Integer}\ }(4)
Type: Domain

axiom
[Ring,Field,IntegerNumberSystem]

\label{eq5}\left[ \hbox{\axiomType{Ring}\ } , \: \hbox{\axiomType{Field}\ } , \: \hbox{\axiomType{IntegerNumberSystem}\ } \right](5)
Type: List(SubDomain(NIL))

Also we would like to be able to coerce both Domain and SubDomain to InputForm

axiom
Integer::InputForm

\label{eq6}\left(\hbox{\axiomType{Integer}\ } \right)(6)
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| ...)
; /var/zope2/var/LatexWiki/5299509375252708736-25px009.fasl written ; compilation finished in 0:00:00.026 Value = T

Now we get

axiom
a:=Integer::InputForm

\label{eq7}\left(\hbox{\axiomType{Integer}\ } \right)(7)
Type: InputForm
axiom
interpret(a)$InputForm

\label{eq8}\hbox{\axiomType{Integer}\ }(8)
Type: Domain
axiom
unparse(a)$InputForm

\label{eq9}\mbox{\tt "Integer"}(9)
Type: String
axiom
b:=PrimeField(11)::InputForm

\label{eq10}\left(\hbox{\axiomType{PrimeField}\ } \ {11}\right)(10)
Type: InputForm
axiom
interpret(b)$InputForm

\label{eq11}\hbox{\axiomType{PrimeField}\ } (11)(11)
Type: Domain
axiom
unparse(b)$InputForm

\label{eq12}\mbox{\tt "PrimeField(11)"}(12)
Type: String
axiom
c:=DirectProduct(3,Fraction Integer)::InputForm

\label{eq13}\left(\hbox{\axiomType{DirectProduct}\ } \  3 \ {\left(\hbox{\axiomType{Fraction}\ } \ {\left(\hbox{\axiomType{Integer}\ } \right)}\right)}\right)(13)
Type: InputForm
axiom
interpret(c)$InputForm

\label{eq14}\hbox{\axiomType{DirectProduct}\ } (3, \hbox{\axiomType{Fraction}\ } (\hbox{\axiomType{Integer}\ }))(14)
Type: Domain
axiom
unparse(c)$InputForm

\label{eq15}\mbox{\tt "DirectProduct(3,Fraction(Integer))"}(15)
Type: String
axiom
d:=Ring::InputForm

\label{eq16}\left(\hbox{\axiomType{Ring}\ } \right)(16)
Type: InputForm
axiom
interpret(d)$InputForm

\label{eq17}\hbox{\axiomType{Ring}\ }(17)
Type: SubDomain(Domain)
axiom
unparse(d)$InputForm

\label{eq18}\mbox{\tt "Ring"}(18)
Type: String

Here is a useful function for parsing input strings

axiom
parse(s:String):InputForm == ncParseFromString(s)$Lisp pretend InputForm
Function declaration parse : String -> InputForm has been added to workspace.
Type: Void
axiom
parse("Integer")
axiom
Compiling function parse with type String -> InputForm

\label{eq19}\hbox{\axiomType{Integer}\ }(19)
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]])
(23) CliffordAlgebra(4,Fraction(Integer),[[1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,- 1]])
Type: Domain
axiom
%::InputForm
(24) (CliffordAlgebra 4 (Fraction (Integer))
[[1(),0(),0(),0()], [0(),- 1(),0(),0()], [0(),0(),- 1(),0()], [0(),0(),0(),- 1()]] )
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]])")
(25) (CliffordAlgebra 4 (Fraction Integer)
(quadraticForm
(matrix
(construct (construct 1 0 0 0) (construct 0 (- 1) 0 0) (construct 0 0 (- 1) 0) (construct 0 0 0 (- 1))) ) ) )
Type: InputForm
axiom
interpret(%)
(26) CliffordAlgebra(4,Fraction(Integer),[[1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,- 1]])
Type: Domain
axiom
%::InputForm
(27) ((Domain) CliffordAlgebra 4 (Fraction (Integer))
[[1(),0(),0(),0()], [0(),- 1(),0(),0()], [0(),0(),- 1(),0()], [0(),0(),0(),- 1()]] )
Type: InputForm

We can easily implement similar functionality at the Spad (algebra library) level by extending the InputFormFunction1 package. But limitation of FriCAS that prevent us from passing domain-values as parameters of functions mean we must do it this way.

spad
)abbrev package INFORM1 InputFormFunctions1
--)boot $noSubsumption := false
++ Tools for manipulating input forms ++ Author: Manuel Bronstein ++ Date Created: ??? ++ Date Last Updated: 19 April 1991 ++ Description: Tools for manipulating input forms.
InputFormFunctions1(R:Type):with packageCall: Symbol -> InputForm ++ packageCall(f) returns the input form corresponding to f$R. interpret : InputForm -> R ++ interpret(f) passes f to the interpreter, and transforms ++ the result into an object of type R. domainToInputForm: () -> InputForm ++ convert a domain to InputForm == add domainToInputForm():InputForm == devaluate(R)$Lisp
packageCall name == convert([convert("$elt"::Symbol), domainToInputForm(), convert name]$List(InputForm))@InputForm
interpret form ==
retract(interpret(convert([convert("@"::Symbol), form, domainToInputForm()]$List(InputForm))@InputForm)$InputForm)$AnyFunctions1(R)
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.
compiling exported packageCall : Symbol -> InputForm Time: 0.02 SEC.
compiling exported interpret : InputForm -> R Time: 0.02 SEC.
(time taken in buildFunctor: 0)
;;; *** |InputFormFunctions1| REDEFINED
;;; *** |InputFormFunctions1| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor InputFormFunctions1 Time: 0.06 seconds
finalizing NRLIB INFORM1 Processing InputFormFunctions1 for Browser database: --------(packageCall ((InputForm) (Symbol)))--------- --------(interpret (R (InputForm)))--------- --------(domainToInputForm ((InputForm)))--------- --->/usr/local/lib/fricas/target/x86_64-unknown-linux/../../src/algebra/INFORM1.spad-->InputFormFunctions1((domainToInputForm ((InputForm)))): Improper first word in comments: convert "convert a domain to InputForm" --------constructor--------- ; compiling file "/var/zope2/var/LatexWiki/INFORM1.NRLIB/INFORM1.lsp" (written 06 MAR 2010 05:53:08 PM): ; compiling (/VERSIONCHECK 2) ; compiling (DEFUN |INFORM1;domainToInputForm;If;1| ...) ; compiling (DEFUN |INFORM1;packageCall;SIf;2| ...) ; compiling (DEFUN |INFORM1;interpret;IfR;3| ...) ; compiling (DEFUN |InputFormFunctions1| ...) ; compiling (DEFUN |InputFormFunctions1;| ...) ; compiling (MAKEPROP (QUOTE |InputFormFunctions1|) ...)
; /var/zope2/var/LatexWiki/INFORM1.NRLIB/INFORM1.fasl written ; compilation finished in 0:00:00.040 ------------------------------------------------------------------------ InputFormFunctions1 is now explicitly exposed in frame initial InputFormFunctions1 will be automatically loaded when needed from /var/zope2/var/LatexWiki/INFORM1.NRLIB/INFORM1

axiom
domainToInputForm()$INFORM1(PrimeField 7)
(28) (PrimeField 7)
Type: InputForm
axiom
interpret(parse("x^2+1"))$INFORM1(Polynomial Float)
2 (29) x + 1.0
Type: Polynomial(Float)




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