fricas
(1) -> <spad>
fricas
)abbrev domain MYPLEX MyComplex
++ Description:
++ Based on \spadtype{Complex(R)},
++ \spadtype{MyComplex(R)} creates the domain of elements of the form
++ \spad{a + b * i} where \spad{a} and b come from the ring R,
++ and i is a new element such that \spad{i^2 = -1}.
MyComplex(R:CommutativeRing): ComplexCategory(R) with
if R has OpenMath then OpenMath
== add
Rep := Record(real:R, imag:R)
if R has OpenMath then
writeOMComplex(dev: OpenMathDevice, x: %): Void ==
OMputApp(dev)
OMputSymbol(dev, "complex1", "complex__cartesian")
OMwrite(dev, real x)
OMwrite(dev, imag x)
OMputEndApp(dev)
OMwrite(x: %): String ==
s: String := ""
sp := OM_-STRINGTOSTRINGPTR(s)$Lisp
dev: OpenMathDevice := OMopenString(sp pretend String, OMencodingXML)
OMputObject(dev)
writeOMComplex(dev, x)
OMputEndObject(dev)
OMclose(dev)
s := OM_-STRINGPTRTOSTRING(sp)$Lisp pretend String
s
OMwrite(x: %, wholeObj: Boolean): String ==
s: String := ""
sp := OM_-STRINGTOSTRINGPTR(s)$Lisp
dev: OpenMathDevice := OMopenString(sp pretend String, OMencodingXML)
if wholeObj then
OMputObject(dev)
writeOMComplex(dev, x)
if wholeObj then
OMputEndObject(dev)
OMclose(dev)
s := OM_-STRINGPTRTOSTRING(sp)$Lisp pretend String
s
OMwrite(dev: OpenMathDevice, x: %): Void ==
OMputObject(dev)
writeOMComplex(dev, x)
OMputEndObject(dev)
OMwrite(dev: OpenMathDevice, x: %, wholeObj: Boolean): Void ==
if wholeObj then
OMputObject(dev)
writeOMComplex(dev, x)
if wholeObj then
OMputEndObject(dev)
0 == [0, 0]
1 == [1, 0]
zero? x == zero?(x.real) and zero?(x.imag)
-- one? x == one?(x.real) and zero?(x.imag)
one? x == ((x.real) = 1) and zero?(x.imag)
coerce(r:R):% == [r, 0]
complex(r, i) == [r, i]
real x == x.real
imag x == x.imag
x + y == [x.real + y.real, x.imag + y.imag]
-- by re-defining this here, we save 5 fn calls
x:% * y:% ==
[x.real * y.real - x.imag * y.imag,
x.imag * y.real + y.imag * x.real] -- here we save nine!
if R has IntegralDomain then
_exquo(x:%, y:%) == -- to correct bad defaulting problem
zero? y.imag => x exquo y.real
x * conjugate(y) exquo norm(y)</spad>
fricas
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/4777213760436474437-25px001.spad
using old system compiler.
MYPLEX abbreviates domain MyComplex
------------------------------------------------------------------------
initializing NRLIB MYPLEX for MyComplex
compiling into NRLIB MYPLEX
****** Domain: R already in scope
augmenting R: (OpenMath)
compiling local writeOMComplex : (OpenMathDevice,%) -> Void
Time: 0.04 SEC.
compiling exported OMwrite : % -> String
****** comp fails at level 2 with expression: ******
error in function OMwrite
(SEQ (|:=| (|:| |s| (|String|)) "") | << |
(|:=| |sp| ((|Sel| |Lisp| OM-STRINGTOSTRINGPTR) |s|)) | >> |
(|:=| (|:| |dev| (|OpenMathDevice|))
(|OMopenString| (|pretend| |sp| (|String|)) |OMencodingXML|))
(|OMputObject| |dev|) (|writeOMComplex| |dev| |x|)
(|OMputEndObject| |dev|) (|OMclose| |dev|)
(|:=| |s|
(|pretend| ((|Sel| |Lisp| OM-STRINGPTRTOSTRING) |sp|) (|String|)))
(|exit| 1 |s|))
****** level 2 ******
$x:= (:= sp ((Sel Lisp OM-STRINGTOSTRINGPTR) s))
$m:= NoValueMode
$f:=
((((|s| # #) (|x| # #) (|writeOMComplex| #))
((|writeOMComplex| #) (|coerce| #) (|void| #) (|$DomainsInScope| # # #) ...)))
>> Apparent user error:
No mode in assignment to:
sp
fricas
myType := MyComplex MyComplex Integer
MyComplex is an unknown constructor and so is unavailable. Did you
mean to use -> but type something different instead?