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

Edit detail for SubDomain revision 3 of 7

1 2 3 4 5 6 7
Editor: Bill Page
Time: 2008/09/18 18:18:40 GMT-7
Note: coercion to InputForm

changed:
-However OpenAxiom has implemented 'Domain' and replaced
OpenAxiom has implemented 'Domain' and replaced

changed:
-Domain():SetCategory with CoercibleTo(InputForm)
Domain():SetCategory

removed:
-    coerce(x:%):InputForm ==
-      devaluate(x)$Lisp

changed:
-SubDomain(D:Domain):SetCategory with CoercibleTo(InputForm)
SubDomain(D:Domain):SetCategory

removed:
-    coerce(x:%):InputForm ==
-      devaluate(x)$Lisp

changed:
-Although it is exported:
-\begin{axiom}
-)sh Domain
-\end{axiom}
-unfortunately the interpreter still does not seem to be
-able to call the 'coerce' to 'InputForm' function even
-though the operation is exported by Domain.
Also we would like to be able to coerce both Domain and
SubDomain to InputForm

removed:
-Ring::InputForm

changed:
-Waldek suggested the following way of converting a type
-to InputForm.
-\begin{spad}
-)abbrev package GETTYNM GetTypeName
-GetTypeName(T : Type) : with
-   coerce: () -> InputForm
- == add
-     coerce() == (devaluate(T)$Lisp) pretend InputForm
-\end{spad}
-
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**
\begin{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
  if t1 in '((Category) (Mode) (Domain) (SubDomain (Domain))) then
    t2 = $OutputForm => objNew(val,t2)
  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)
    -- WSP added Sept 2008: coercion to InputForm for
    -- (Category) (Mode) (Domain) (SubDomain (Domain)
    t2 = '(InputForm) => objNewWrap(val,t2)
    coerceInt0(triple,t2)
  if expr2 then stopTimingProcess 'print
  else stopTimingProcess 'coercion
  result
\end{boot}

Now we get

changed:
-coerce()$GetTypeName(Integer)
-coerce()$GetTypeName(SquareMatrix(3,PrimeField 7))
-unparse(%)
a:=Integer::InputForm
interpret(a)$InputForm
unparse(a)$InputForm
b:=PrimeField(11)::InputForm
interpret(b)$InputForm
unparse(b)$InputForm
c:=Ring::InputForm
interpret(c)$InputForm
unparse(c)$InputForm

added:


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
LatexWiki Image(1)
Type: Domain
axiom
Ring
LatexWiki Image(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.01 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.02 seconds
finalizing NRLIB DOMAIN Processing Domain for Browser database: --->-->Domain(): Missing Description ------------------------------------------------------------------------ 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.01 SEC.
compiling exported = : ($,$) -> Boolean Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |SubDomain| REDEFINED
;;; *** |SubDomain| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor SubDomain Time: 0.01 seconds
finalizing NRLIB SUBDOM Processing SubDomain for Browser database: --->-->SubDomain(): Missing Description ------------------------------------------------------------------------ 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)]
LatexWiki Image(3)
Type: List Domain
axiom
%.1
LatexWiki Image(4)
Type: Domain

axiom
[Ring,Field,IntegerNumberSystem]
LatexWiki Image(5)
Type: List SubDomain? Domain

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

axiom
Integer::InputForm
Cannot convert from type Domain to InputForm for value Integer()

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
  if t1 in '((Category) (Mode) (Domain) (SubDomain (Domain))) then
    t2 = $OutputForm => objNew(val,t2)
  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)
    -- WSP added Sept 2008: coercion to InputForm for
    -- (Category) (Mode) (Domain) (SubDomain (Domain)
    t2 = '(InputForm) => objNewWrap(val,t2)
    coerceInt0(triple,t2)
  if expr2 then stopTimingProcess 'print
  else stopTimingProcess 'coercion
  result
boot
Value = T
; (DEFUN |coerceInteractive| ...) is being compiled.
;; The variable |$OutputForm| is undefined.
;; The compiler will assume this variable is a global.
Value = 2440

Now we get

axiom
a:=Integer::InputForm
LatexWiki Image(6)
Type: InputForm?
axiom
interpret(a)$InputForm
LatexWiki Image(7)
Type: Domain
axiom
unparse(a)$InputForm
LatexWiki Image(8)
Type: String
axiom
b:=PrimeField(11)::InputForm
LatexWiki Image(9)
Type: InputForm?
axiom
interpret(b)$InputForm
LatexWiki Image(10)
Type: Domain
axiom
unparse(b)$InputForm
LatexWiki Image(11)
Type: String
axiom
c:=Ring::InputForm
LatexWiki Image(12)
Type: InputForm?
axiom
interpret(c)$InputForm
LatexWiki Image(13)
Type: SubDomain? Domain
axiom
unparse(c)$InputForm
LatexWiki Image(14)
Type: String