spad
)abbrev domain MAYBE Maybe
Maybe(T: Type) == Union(T,"failed")
spad
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/3867167196268790065-25px001.spad
using old system compiler.
MAYBE abbreviates domain Maybe
------------------------------------------------------------------------
initializing NRLIB MAYBE for Maybe
compiling into NRLIB MAYBE
****** comp fails at level 1 with expression: ******
((|UnionCategory| T$ "failed"))
****** level 1 ******
$x:= (UnionCategory T$ failed)
$m:= $EmptyMode
$f:=
((((T$ # #) (|$DomainsInScope| # #))))
>> Apparent user error:
cannot compile (UnionCategory T$ failed)
spad
)abbrev domain MAYBE Maybe
Maybe(T: Type):Type == Union(T,"failed")
spad
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6798525157762352212-25px002.spad
using old system compiler.
MAYBE abbreviates domain Maybe
------------------------------------------------------------------------
initializing NRLIB MAYBE for Maybe
compiling into NRLIB MAYBE
;;; *** |Maybe| REDEFINED
;;; *** |Maybe| REDEFINED
Time: 0 SEC.
Cumulative Statistics for Constructor Maybe
Time: 0 seconds
--------------non extending category----------------------
.. Maybe(#1) of cat
(|Type|) has no
(|UnionCategory| |#1| "failed") finalizing NRLIB MAYBE
Processing Maybe for Browser database:
--->-->Maybe(): Missing Description
; compiling file "/var/aw/var/LatexWiki/MAYBE.NRLIB/MAYBE.lsp" (written 04 APR 2022 05:52:28 PM):
; /var/aw/var/LatexWiki/MAYBE.NRLIB/MAYBE.fasl written
; compilation finished in 0:00:00.005
------------------------------------------------------------------------
Maybe is now explicitly exposed in frame initial
Maybe will be automatically loaded when needed from
/var/aw/var/LatexWiki/MAYBE.NRLIB/MAYBE
fricas
)show Maybe
Maybe(T$: Type) is a domain constructor
Abbreviation for Maybe is MAYBE
This constructor is exposed in this frame.
------------------------------- Operations --------------------------------
No, there should not be a need for specifying result type. In fact, if you specify
"Type" as result type, you explicitly ask for not having any exported
operation. That wasn't the intent. The intent was to get whatever the
right hand side exported as exports. Such as in
spad
)abbrev domain MYFIELD MyField
MyField() == Fraction Integer
spad
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/2205496008028295448-25px004.spad
using old system compiler.
MYFIELD abbreviates domain MyField
------------------------------------------------------------------------
initializing NRLIB MYFIELD for MyField
compiling into NRLIB MYFIELD
****** Domain: $ already in scope
augmenting $: (CharacteristicNonZero)
****** Domain: (Integer) already in scope
augmenting (Integer): (ConvertibleTo (Pattern (Float)))
****** Domain: (Integer) already in scope
augmenting (Integer): (Eltable (Integer) (Integer))
****** Domain: (Integer) already in scope
augmenting (Integer): (Evalable (Integer))
****** Domain: (Integer) already in scope
augmenting (Integer): (InnerEvalable (Symbol) (Integer))
****** Domain: (Integer) already in scope
augmenting (Integer): (PartialDifferentialRing (Symbol))
****** Domain: (Integer) already in scope
augmenting (Integer): (PatternMatchable (Float))
****** Domain: (Integer) already in scope
augmenting (Integer): (RetractableTo (Symbol))
(time taken in buildFunctor: 90)
;;; *** |MyField| REDEFINED
;;; *** |MyField| REDEFINED
Time: 0.19 SEC.
Cumulative Statistics for Constructor MyField
Time: 0.19 seconds
finalizing NRLIB MYFIELD
Processing MyField for Browser database:
--->-->MyField(): Missing Description
; compiling file "/var/aw/var/LatexWiki/MYFIELD.NRLIB/MYFIELD.lsp" (written 04 APR 2022 05:52:28 PM):
; /var/aw/var/LatexWiki/MYFIELD.NRLIB/MYFIELD.fasl written
; compilation finished in 0:00:00.013
------------------------------------------------------------------------
MyField is now explicitly exposed in frame initial
MyField will be automatically loaded when needed from
/var/aw/var/LatexWiki/MYFIELD.NRLIB/MYFIELD
fricas
)sh MyField
MyField is a domain constructor.
Abbreviation for MyField is MYFIELD
This constructor is exposed in this frame.
86 Names for 119 Operations in this Domain.
------------------------------- Operations --------------------------------
?*? : (Integer, %) -> % ?*? : (PositiveInteger, %) -> %
?*? : (%, Integer) -> % ?*? : (%, %) -> %
?+? : (%, %) -> % ?-? : (%, %) -> %
-? : % -> % ?/? : (Integer, Integer) -> %
?/? : (%, %) -> % ?<? : (%, %) -> Boolean
?<=? : (%, %) -> Boolean ?=? : (%, %) -> Boolean
?>? : (%, %) -> Boolean ?>=? : (%, %) -> Boolean
D : (%, NonNegativeInteger) -> % D : % -> %
OMwrite : (%, Boolean) -> String OMwrite : % -> String
1 : () -> % 0 : () -> %
?^? : (%, Integer) -> % ?^? : (%, PositiveInteger) -> %
abs : % -> % annihilate? : (%, %) -> Boolean
antiCommutator : (%, %) -> % associates? : (%, %) -> Boolean
associator : (%, %, %) -> % ceiling : % -> Integer
coerce : % -> OutputForm coerce : Fraction(Integer) -> %
coerce : Integer -> % coerce : % -> %
commutator : (%, %) -> % convert : % -> DoubleFloat
convert : % -> Float convert : % -> InputForm
convert : % -> Pattern(Integer) denom : % -> Integer
denominator : % -> % differentiate : % -> %
factor : % -> Factored(%) floor : % -> Integer
fractionPart : % -> % gcd : List(%) -> %
gcd : (%, %) -> % hash : % -> SingleInteger
init : () -> % inv : % -> %
latex : % -> String lcm : List(%) -> %
lcm : (%, %) -> % max : (%, %) -> %
min : (%, %) -> % negative? : % -> Boolean
numer : % -> Integer numerator : % -> %
one? : % -> Boolean opposite? : (%, %) -> Boolean
positive? : % -> Boolean prime? : % -> Boolean
?quo? : (%, %) -> % recip : % -> Union(%,"failed")
?rem? : (%, %) -> % retract : % -> Fraction(Integer)
retract : % -> Integer sample : () -> %
sign : % -> Integer sizeLess? : (%, %) -> Boolean
smaller? : (%, %) -> Boolean squareFree : % -> Factored(%)
squareFreePart : % -> % unit? : % -> Boolean
unitCanonical : % -> % wholePart : % -> Integer
zero? : % -> Boolean ?~=? : (%, %) -> Boolean
?*? : (Fraction(Integer), %) -> %
?*? : (NonNegativeInteger, %) -> %
?*? : (%, Fraction(Integer)) -> %
D : (%, (Integer -> Integer), NonNegativeInteger) -> %
D : (%, (Integer -> Integer)) -> %
OMwrite : (OpenMathDevice, %, Boolean) -> Void
OMwrite : (OpenMathDevice, %) -> Void
?^? : (%, NonNegativeInteger) -> %
characteristic : () -> NonNegativeInteger
differentiate : (%, (Integer -> Integer), NonNegativeInteger) -> %
differentiate : (%, (Integer -> Integer)) -> %
differentiate : (%, NonNegativeInteger) -> %
divide : (%, %) -> Record(quotient: %,remainder: %)
euclideanSize : % -> NonNegativeInteger
expressIdealMember : (List(%), %) -> Union(List(%),"failed")
exquo : (%, %) -> Union(%,"failed")
extendedEuclidean : (%, %) -> Record(coef1: %,coef2: %,generator: %)
extendedEuclidean : (%, %, %) -> Union(Record(coef1: %,coef2: %),"failed")
factorFraction : % -> Fraction(Factored(Integer))
factorPolynomial : SparseUnivariatePolynomial(%) -> Factored(SparseUnivariatePolynomial(%))
factorSquareFreePolynomial : SparseUnivariatePolynomial(%) -> Factored(SparseUnivariatePolynomial(%))
gcdPolynomial : (SparseUnivariatePolynomial(%), SparseUnivariatePolynomial(%)) -> SparseUnivariatePolynomial(%)
hashUpdate! : (HashState, %) -> HashState
lcmCoef : (%, %) -> Record(llcm_res: %,coeff1: %,coeff2: %)
leftPower : (%, NonNegativeInteger) -> %
leftPower : (%, PositiveInteger) -> %
leftRecip : % -> Union(%,"failed")
map : ((Integer -> Integer), %) -> %
multiEuclidean : (List(%), %) -> Union(List(%),"failed")
nextItem : % -> Union(%,"failed")
patternMatch : (%, Pattern(Integer), PatternMatchResult(Integer,%)) -> PatternMatchResult(Integer,%)
principalIdeal : List(%) -> Record(coef: List(%),generator: %)
reducedSystem : Matrix(%) -> Matrix(Integer)
reducedSystem : (Matrix(%), Vector(%)) -> Record(mat: Matrix(Integer),vec: Vector(Integer))
retractIfCan : % -> Union(Fraction(Integer),"failed")
retractIfCan : % -> Union(Integer,"failed")
rightPower : (%, NonNegativeInteger) -> %
rightPower : (%, PositiveInteger) -> %
rightRecip : % -> Union(%,"failed")
solveLinearPolynomialEquation : (List(SparseUnivariatePolynomial(%)), SparseUnivariatePolynomial(%)) -> Union(List(SparseUnivariatePolynomial(%)),"failed")
squareFreePolynomial : SparseUnivariatePolynomial(%) -> Factored(SparseUnivariatePolynomial(%))
subtractIfCan : (%, %) -> Union(%,"failed")
unitNormal : % -> Record(unit: %,canonical: %,associate: %)
Macro versus domain
fricas
macro Maybe(T) == Union(T,"failed")
Type: Void
fricas
)sh Maybe(Integer)
Union(Integer,"failed") is a domain constructor.
5 Names for 11 Operations in this Domain.
------------------------------- Operations --------------------------------
?=? : (%, %) -> Boolean autoCoerce : % -> failed
autoCoerce : % -> Integer autoCoerce : failed -> %
autoCoerce : Integer -> % ?case? : (%, failed) -> Boolean
?case? : (%, Integer) -> Boolean coerce : % -> failed
coerce : % -> Integer coerce : % -> OutputForm
?~=? : (%, %) -> Boolean
fricas
x:Maybe(Integer)
Type: Void
fricas
x:=-3
Type: Union(Integer,...)
spad
)abbrev domain MAYBE2 Maybe2
Maybe2(T: Type):with
_= : (%,%) -> Boolean
autoCoerce : % -> failed
autoCoerce : % -> T
autoCoerce : failed -> %
autoCoerce : T -> %
_case: (%,failed) -> Boolean
_case: (%,T) -> Boolean
coerce : % -> failed
coerce : % -> T
coerce : % -> OutputForm
coerce : T -> %
== Union(T,"failed") add
coerce(x:T):% == autoCoerce(x)
spad
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/7945389118523770429-25px008.spad
using old system compiler.
MAYBE2 abbreviates domain Maybe2
------------------------------------------------------------------------
initializing NRLIB MAYBE2 for Maybe2
compiling into NRLIB MAYBE2
compiling exported coerce : T$ -> $
Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |Maybe2| REDEFINED
;;; *** |Maybe2| REDEFINED
Time: 0 SEC.
Cumulative Statistics for Constructor Maybe2
Time: 0 seconds
--------------non extending category----------------------
.. Maybe2(#1) of cat
(CATEGORY |domain| (SIGNATURE = ((|Boolean|) $ $))
(SIGNATURE |autoCoerce| (|failed| $)) (SIGNATURE |autoCoerce| (|#1| $))
(SIGNATURE |autoCoerce| ($ |failed|)) (SIGNATURE |autoCoerce| ($ |#1|))
(SIGNATURE |case| ((|Boolean|) $ |failed|))
(SIGNATURE |case| ((|Boolean|) $ |#1|)) (SIGNATURE |coerce| (|failed| $))
(SIGNATURE |coerce| (|#1| $)) (SIGNATURE |coerce| ((|OutputForm|) $))
(SIGNATURE |coerce| ($ |#1|))) has no
(|UnionCategory| |#1| "failed") finalizing NRLIB MAYBE2
Processing Maybe2 for Browser database:
--->-->Maybe2(constructor): Not documented!!!!
--->-->Maybe2((= ((Boolean) % %))): Not documented!!!!
--->-->Maybe2((autoCoerce (failed %))): Not documented!!!!
--->-->Maybe2((autoCoerce (T$ %))): Not documented!!!!
--->-->Maybe2((autoCoerce (% failed))): Not documented!!!!
--->-->Maybe2((autoCoerce (% T$))): Not documented!!!!
--->-->Maybe2((case ((Boolean) % failed))): Not documented!!!!
--->-->Maybe2((case ((Boolean) % T$))): Not documented!!!!
--->-->Maybe2((coerce (failed %))): Not documented!!!!
--->-->Maybe2((coerce (T$ %))): Not documented!!!!
--->-->Maybe2((coerce ((OutputForm) %))): Not documented!!!!
--->-->Maybe2((coerce (% T$))): Not documented!!!!
--->-->Maybe2(): Missing Description
; compiling file "/var/aw/var/LatexWiki/MAYBE2.NRLIB/MAYBE2.lsp" (written 04 APR 2022 05:52:28 PM):
; /var/aw/var/LatexWiki/MAYBE2.NRLIB/MAYBE2.fasl written
; compilation finished in 0:00:00.009
------------------------------------------------------------------------
Maybe2 is now explicitly exposed in frame initial
Maybe2 will be automatically loaded when needed from
/var/aw/var/LatexWiki/MAYBE2.NRLIB/MAYBE2
fricas
)show Maybe2
Maybe2(T$: Type) is a domain constructor
Abbreviation for Maybe2 is MAYBE2
This constructor is exposed in this frame.
------------------------------- Operations --------------------------------
?=? : (%, %) -> Boolean autoCoerce : % -> failed
autoCoerce : % -> T$ autoCoerce : failed -> %
autoCoerce : T$ -> % ?case? : (%, failed) -> Boolean
?case? : (%, T$) -> Boolean coerce : % -> failed
coerce : % -> T$ coerce : % -> OutputForm
coerce : T$ -> %
fricas
y:Maybe2(Integer)
Type: Void
fricas
y:=-3
Function: autoCoerce : Integer -> % is missing from domain: Maybe2(Integer)
Internal Error
The function autoCoerce with signature $(Integer) is missing from
domain Maybe2(Integer)
But, the use of macro is a workaround a fundamental problem
in the compiler -- which I'm desperately trying to convey.
This and the original bug comes from the same source
in the compiler.
I agree. I am just trying to understand it.
Why does:
Maybe(T: Type) == Union(T,"failed")
and:
Maybe(T: Type):Type == Union(T,"failed")
have such different semantics? Is this a good thing? Maybe there is a need for something that stands for the type of the rhs:
Maybe(T: Type):rhs == Union(T,"failed")
Remember that Type is a category that exports no operation. so when you say
Maybe(T: Type): Type
, you are exlicitly saying that
Maybe(T: Type)
is a domain
constructor that exports no operation. Indeed, if you try
)show
with
OpenAxiom, you will see that it say,
Maybe
has no exported operations.
Which is right.
However, when one says Maybe(T: Type) == Union(T, "failed")
, one is saying
that Maybe(T)
is exactly like Union(T,"failed")
, except for the name.
Consequently, Maybe
has the exports inferred from the right hand side.
This works for all domains, except the `builtin' domains. If you
try Record
or Enumeration
, you should hit a bug in the compiler at some
point.
spad
)abbrev domain MYPAIR MyPair
MyPair(T:Type) == Record(X:T,Y:T)
spad
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1259072050906152969-25px011.spad
using old system compiler.
MYPAIR abbreviates domain MyPair
------------------------------------------------------------------------
initializing NRLIB MYPAIR for MyPair
compiling into NRLIB MYPAIR
****** comp fails at level 1 with expression: ******
((|RecordCategory| (|:| X T$) (|:| Y T$)))
****** level 1 ******
$x:= (RecordCategory (: X T$) (: Y T$))
$m:= $EmptyMode
$f:=
((((T$ # #) (|$DomainsInScope| # #))))
>> Apparent user error:
cannot compile (RecordCategory (: X T$) (: Y T$))
fricas
)show MyPair(Integer)
MyPair is an unknown constructor and so is unavailable. Did you mean
to use -> but type something different instead?
spad
)abbrev domain MYPAIR2 MyPair2
MyPair2(T:Type): with
_= : (%,%) -> Boolean
coerce : % -> OutputForm
copy : % -> %
_. : (%,X) -> Integer
_. : (%,Y) -> Integer
setelt : (%,X,Integer) -> Integer
setelt : (%,Y,Integer) -> Integer
_~_= : (%,%) -> Boolean
construct : (Integer,Integer) -> %
== Record(X:T,Y:T)
spad
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/5737796087530002187-25px013.spad
using old system compiler.
MYPAIR2 abbreviates domain MyPair2
------------------------------------------------------------------------
initializing NRLIB MYPAIR2 for MyPair2
compiling into NRLIB MYPAIR2
;;; *** |MyPair2| REDEFINED
;;; *** |MyPair2| REDEFINED
Time: 0 SEC.
Cumulative Statistics for Constructor MyPair2
Time: 0 seconds
--------------non extending category----------------------
.. MyPair2(#1) of cat
(CATEGORY |domain| (SIGNATURE = ((|Boolean|) $ $))
(SIGNATURE |coerce| ((|OutputForm|) $)) (SIGNATURE |copy| ($ $))
(SIGNATURE |.| ((|Integer|) $ X)) (SIGNATURE |.| ((|Integer|) $ Y))
(SIGNATURE |setelt| ((|Integer|) $ X (|Integer|)))
(SIGNATURE |setelt| ((|Integer|) $ Y (|Integer|)))
(SIGNATURE ~= ((|Boolean|) $ $))
(SIGNATURE |construct| ($ (|Integer|) (|Integer|)))) has no
(|RecordCategory| (|:| X |#1|) (|:| Y |#1|))
>> System error:
code vector slot is
(Boolean)
; must be number
fricas
)show MyPair2(Integer)
MyPair2 is an unknown constructor and so is unavailable. Did you
mean to use -> but type something different instead?
fricas
x2:MyPair2(INT):=[-1,-2]
MyPair2 is an unknown constructor and so is unavailable. Did you
mean to use -> but type something different instead?
gdr wrote:
- one is saying that Maybe(T) is exactly like Union(T,"failed")
What is the advantage of this notation over the use of a macro
?
Besides domain composition, constant substitution and passing of
parameters, like:
Maybe(T: Type) == Union(Fraction T,"failed")
what other useful expressions are allowed on the rhs?
Persumably add
would not make sense because we cannot
specify new exports - at least not without explicitly
specifying all exports.
This is a common problem for possible re-use of code
(subject of another thread). For example:
NonNegativeInteger():rhs
without
_-:(%,%) -> %
with
subtractIfCan:(%,%)->Union(%,"failed")
== Integer add
subtractIfCan(x,y) ==
x > y => x-y
"failed"
What should I put instead of rhs
? Should I be able to
explicitly "forget" (or replace) some exports?
spad
)abbrev domain MYNNI MyNonNegativeInteger
MyNonNegativeInteger():IntegerNumberSystem with
subtractIfCan:(%,%)->Union(%,"failed")
== Integer add
subtractIfCan(x:%,y:%):Union(%,"failed") ==
x > y => x-y
"failed"
spad
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/5893753003779373514-25px016.spad
using old system compiler.
MYNNI abbreviates domain MyNonNegativeInteger
------------------------------------------------------------------------
initializing NRLIB MYNNI for MyNonNegativeInteger
compiling into NRLIB MYNNI
compiling exported subtractIfCan : ($,$) -> Union($,failed)
Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |MyNonNegativeInteger| REDEFINED
;;; *** |MyNonNegativeInteger| REDEFINED
Time: 0 SEC.
Cumulative Statistics for Constructor MyNonNegativeInteger
Time: 0 seconds
--------------non extending category----------------------
.. MyNonNegativeInteger of cat
(|Join| (|IntegerNumberSystem|)
(CATEGORY |domain|
(SIGNATURE |subtractIfCan| ((|Union| $ "failed") $ $)))) has no
(|LinearlyExplicitOver| (|Integer|)) finalizing NRLIB MYNNI
Processing MyNonNegativeInteger for Browser database:
--->-->MyNonNegativeInteger(constructor): Not documented!!!!
--->-->MyNonNegativeInteger((subtractIfCan ((Union % failed) % %))): Not documented!!!!
--->-->MyNonNegativeInteger(): Missing Description
; compiling file "/var/aw/var/LatexWiki/MYNNI.NRLIB/MYNNI.lsp" (written 04 APR 2022 05:52:28 PM):
; /var/aw/var/LatexWiki/MYNNI.NRLIB/MYNNI.fasl written
; compilation finished in 0:00:00.009
------------------------------------------------------------------------
MyNonNegativeInteger is now explicitly exposed in frame initial
MyNonNegativeInteger will be automatically loaded when needed from
/var/aw/var/LatexWiki/MYNNI.NRLIB/MYNNI
A macro name is not a constructor name, so that makes a fundamental
difference.
Do we have a `without' construct?
With an
OpenAxiom built on May 16, 2008 I have a different behaviour: The assignment
is rejected because there is no conversion from [-1,2] to MyPair2(INT). Which is right.
The output of the compiler indicates to me that the website is running
a very old
OpenAxiom.
The version of
OpenAxiom being used for this page was build from svn on May 27, 2008:
fricas
)version
Value = "FriCAS 1.3.7 compiled at Wed Jun 30 16:44:06 UTC 2021"
No, it's only in my imagination.
Previously
Bill Page wrote:
Macro versus domain
macro Maybe(T) == Union(T,"failed")
gdr wrote:
But, the use of macro is a workaround a fundamental problem
in the compiler ...
Bill Page wrote:
Agreed, but what is the advantage of this notation:
Maybe(T:Type) == Union(T,"failed")
over the use of a macro?
gdr wrote:
A macro name is not a constructor name, so that makes
a fundamental difference.
Of course there is a difference to the compiler but is
there a "fundamental difference" to the programmer? Does
the language benefit from being able to compile domains
with an identical list exports as some other domain?
I suppose here's one possible advantage:
- To provide standard simplified interfaces to more
complex domains defined in the library.
- Macros are not stored as part of the Axiom library.
Well, as you said, macros are not stored in the databases.
In
OpenAxiom, one can use constructor names as arguments to functions.
That does not work with macro names -- they don't really define a
new category or domain or package.
Because you can pass domains as arguments to functions:
fricas
Maybe3(T: Domain):Domain == Union(T,"failed")
Domain is not a valid type.
gdr wrote:
With an OpenAxiom built on May 16, 2008 I have a different behaviour:
The assignment is rejected because there is no conversion from
[-1,2] to MyPair2(INT).
After upgrading this page to OpenAxiom built with current (May 27, 2008 Rev: 614) source:
fricas
)version
Value = "FriCAS 1.3.7 compiled at Wed Jun 30 16:44:06 UTC 2021"
This example still fails:
fricas
xy:MyPair2(INT):=[-1,2]
MyPair2 is an unknown constructor and so is unavailable. Did you
mean to use -> but type something different instead?
this is weird: I cannot reproduce the failure.
- Now, I can
- I failed to copy and paste
properly. And on reflection, the fact the
interpreter rejected the code should have alerted
me to close closer. And yes, the failure
is related to the same bug.