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

Edit detail for SandBoxMaybe revision 21 of 46

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
Editor: Bill Page
Time: 2008/05/27 12:58:47 GMT-7
Note: exports inferred from RHS

added:

From BillPage Tue May 27 12:58:47 -0700 2008
From: Bill Page
Date: Tue, 27 May 2008 12:58:47 -0700
Subject: exports inferred from RHS
Message-ID: <20080527125847-0700@axiom-wiki.newsynthesis.org>

\begin{spad}
)abbrev domain MYPAIR MyPair
MyPair(T:Type) == Record(X:T,Y:T)
\end{spad}

\begin{axiom}
)show MyPair(Integer)
\end{axiom}

fricas
(1) -> <spad>
fricas
)abbrev domain MAYBE Maybe
Maybe(T: Type) == Union(T,"failed")</spad>
fricas
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)

need result type --Bill Page, Mon, 26 May 2008 20:25:03 -0700 reply
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 
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 14 SEP 2026 07:40:12 AM):
; wrote /var/aw/var/LatexWiki/MAYBE.NRLIB/MAYBE.fasl ; compilation finished in 0:00:00.000 ------------------------------------------------------------------------ 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 --------------------------------

need result type --gdr, Mon, 26 May 2008 22:03:52 -0700 reply
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:  33160)
Time: 0.07 SEC.
Cumulative Statistics for Constructor MyField Time: 0.07 seconds
finalizing NRLIB MYFIELD Processing MyField for Browser database: --->-->MyField(): Missing Description ; compiling file "/var/aw/var/LatexWiki/MYFIELD.NRLIB/MYFIELD.lsp" (written 14 SEP 2026 07:40:13 AM):
; wrote /var/aw/var/LatexWiki/MYFIELD.NRLIB/MYFIELD.fasl ; compilation finished in 0:00:00.028 ------------------------------------------------------------------------ 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. 87 names for 120 operations in this domain. ------------------------------- Operations --------------------------------
0 : () -> % 1 : () -> % ?*? : (%, %) -> % ?*? : (%, Integer) -> % ?*? : (Integer, %) -> % ?*? : (PositiveInteger, %) -> % ?+? : (%, %) -> % -? : % -> % ?-? : (%, %) -> % ?/? : (%, %) -> % ?/? : (Integer, Integer) -> % ?<? : (%, %) -> Boolean ?<=? : (%, %) -> Boolean ?=? : (%, %) -> Boolean ?>? : (%, %) -> Boolean ?>=? : (%, %) -> Boolean D : % -> % D : (%, NonNegativeInteger) -> % OMwrite : % -> String OMwrite : (%, Boolean) -> String ?^? : (%, Integer) -> % ?^? : (%, PositiveInteger) -> % abs : % -> % annihilate? : (%, %) -> Boolean antiCommutator : (%, %) -> % associates? : (%, %) -> Boolean associator : (%, %, %) -> % ceiling : % -> Integer coerce : % -> % coerce : Fraction(Integer) -> % coerce : Integer -> % coerce : % -> OutputForm commutator : (%, %) -> % convert : % -> DoubleFloat convert : % -> Float convert : % -> InputForm convert : % -> Pattern(Integer) denom : % -> Integer denominator : % -> % differentiate : % -> % factor : % -> Factored(%) floor : % -> Integer fractionPart : % -> % gcd : (%, %) -> % gcd : List(%) -> % hash : % -> SingleInteger init : () -> % inv : % -> % latex : % -> String lcm : (%, %) -> % lcm : List(%) -> % 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)) -> % ?*? : (Fraction(Integer), %) -> % ?*? : (NonNegativeInteger, %) -> % D : (%, (Integer -> Integer)) -> % D : (%, (Integer -> Integer), NonNegativeInteger) -> % OMwrite : (OpenMathDevice, %) -> Void OMwrite : (OpenMathDevice, %, Boolean) -> Void ?^? : (%, NonNegativeInteger) -> % characteristic : () -> NonNegativeInteger differentiate : (%, (Integer -> Integer)) -> % differentiate : (%, (Integer -> Integer), NonNegativeInteger) -> % 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,%) plenaryPower : (%, PositiveInteger) -> % 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

\label{eq1}- 3(1)
Type: Union(Integer,...)

explicit exports --Bill Page, Tue, 27 May 2008 07:46:20 -0700 reply
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) 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 14 SEP 2026 07:40:13 AM):
; wrote /var/aw/var/LatexWiki/MAYBE2.NRLIB/MAYBE2.fasl ; compilation finished in 0:00:00.008 ------------------------------------------------------------------------ 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.

explicit exports --gdr, Tue, 27 May 2008 08:03:19 -0700 reply
This and the original bug comes from the same source in the compiler.

Re: problem in the compiler --Bill Page, Tue, 27 May 2008 08:06:29 -0700 reply
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")

Re: problem in the compiler --gdr, Tue, 27 May 2008 09:20:19 -0700 reply
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.

exports inferred from RHS --Bill Page, Tue, 27 May 2008 12:58:47 -0700 reply
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?