DIRECTORY Rope, MathObjects, MathStructures; MathExprs: CEDAR DEFINITIONS ~ BEGIN ROPE: TYPE = Rope.ROPE; STREAM: TYPE = IO.STREAM; Object: TYPE = MathObjects.Object; Expr: TYPE = Object; ExprData: TYPE ~ REF ExprDataRep; -- external abstract type ExprDataRep: TYPE; -- internal concrete rep None - no Domain-specific data DomMake: PROC RETURNS [domain: Object]; EltDisplay: MathObjects.UnaryOp; EltRead: MathObjects.ReadOp; EltToRope: MathObjects.ToRopeOp; EltFromRope: MathObjects.FromRopeOp; LegalFirstChar: MathObjects.LegalFirstCharOp; EltLBKey: MathObjects.ToRopeOp; EltWrite: MathObjects.WriteOp; WidenOther: MathObjects.BinaryOp; CanWidenOther: MathObjects.BinaryPredicate; NarrowOther: MathObjects.BinaryOp; CanNarrowOther: MathObjects.BinaryPredicate; WidenThis: MathObjects.UnaryOp; NarrowThis: MathObjects.UnaryOp; GetNameDomainData: MathObjects.GetDomainDataProc; Data1: MathObjects.UnaryOp; Data2: MathObjects.UnaryOp; Flavor: MathObjects.FlavorOp; DomToRope: MathObjects.ToRopeOp; DomName: MathObjects.ToRopeOp; DomLBKey: MathObjects.ToRopeOp; DomData: MathObjects.UnaryToListOp; IsNameDomain: MathObjects.UnaryPredicate; MakeName: MathObjects.ListImbedOp; MakeElementNameData: PROC [field1, field2] RETURNS [elementData: ElementNameData]; GetNameElementData: MathObjects.GetElementDataProc; Field1: MathObjects.UnaryOp; Field2: MathObjects.UnaryOp; BinaryOp: MathObjects.BinaryOp; UnaryOp: MathObjects.UnaryOp; END. (L MathExprs.mesa Last Edited by Arnon: September 6, 1989 10:51:10 am PDT Ground Domain corresponding to General Expressions External rep is "Exprs" Types From Other Interfaces Element Representation Domain Representation Domain Constructors class = category = {Sets} build methodDictionary RETURN[MathObjects.MakeObject[class, [methodDictionary, NIL] ] Element Conversion and IO Create a Display Object for a given Element. Straightforward for atomic Exprs For compound Exprs, recursively applies EltDisplay procs of subObject domains, then uses method and # of args to consult a domain-specific (i.e. for this domain) dbase of special formatting procs to look for match, else uses default functional form display. Note that one cannot expect the domain of a subObject of a displayed Expr to necessarily be evident from its displayed appearance. E.g. when we see what looks like an integer, we don't know strictly from the rendered BoxTree for it whether it is the display of an element of Exprs, or an element of Integers. Same e.g. for "matrix of integers". To facilitate system support for "letting a user model his data any way he wants to", we expect elements of all domains to have (one or more) "EltToExpr" procs, which produce a "completely Exprish" element of Exprs, i.e. a "pure functional" Expr, and which we would like to be "consistent" or "invertible" in at least one, preferably both of the following senses: 1) weaker: if you are given the destination domain, then by recursion, subObject instantiation, and composition, knowing domains in which to lookup the given method at each step, you can rebuild the object. 2) stronger: without being given the destination domain, then by recursion, subObject instantiation, and composition, using system type inference & resolution capabilities, and method lookup capabilities (including of course knowledge of the subObject domains at each step), you can rebuild the object. Of course, the remarks below about absence of unique "natural" or "obvious" EltToExprRope procs apply equally to EltToExpr procs. Assuming willingness to call instantiation of atomic subObjects "EltEval" (connoting e.g. evaluation (substitution and recursive evaluation until no change) of variables), then we are saying that we want "EltToExpr" and "EltEval" to be inverses of each other, at least in the weaker, and possibly also in the stronger, sense. Note that we are saying that EltEval means - recursively evaluate subObjects; given a variable, replace it by its value in the current environment (and recursively EltEval that value until no further change occurs); the result of each subObject EltEval is an object in some domain, then lookup a proc implementing the given method, in the "current environment", i.e. using the system's method lookup capabilities, and apply that proc to get a final object in some domain. Thus we are implicitly suggesting that any use of pattern matching or rules in EltEval is expected to be bundled up inside some proc. Domains may or may not support EltEval procs. If their Objects can contain "symbols" or "variables" (e.g. polynomials), rather than just "constants", then they probably should (because e.g. we may want to "eval in the presence of some environment". One typical way a domain can get an EltEval proc is by applying eltEval$Exprs to the result of a EltToExpr of the Object, since eltEval$Exprs is a locus of type inference & resolution, and method lookup, expertise. In general, the implementor of a domain D should think carefully about what the ways in which clients might wish to "eltEval" Objects in it. If the verdict is that all elements of the domain are constants, then probably the domain should have a noOp $eltEval method, so that eltEval$Exprs[parse$D[""] ] can quickly do the right thing. In general, of course, the $eltEval method for a structured domain simply recursively invokes the domains' $eltEval methods of subObjects, and then computes some function of the results. E.g. for matrix domains, it just evaluates the elements, then constructs up a new matrix to hold them. Again, this could be done by eltEval$Exprs[eltToExpr$Matrices(whatever)[] ]. The Domain-dependent parser for general expressions. Assumes that subObjects have been displayed with a EltToExprRope command, i.e. not their domain-dependent Ropes. Thus the Expr that it builds is "purely functional", i.e. subObjects belong to domain Exprs at all levels. Note that we cannot in general expect elements of domains to have a "natural" or "obvious" EltToExprRope form, especially the more complex the domain is. In general, there is a range between "storing (a pointer to) a finished object spec" in the Rope, i.e. specifying the domain, hence its parser, and just giving a (possibly terse and incomprehensible) Rope that that parser can use to rebuild the (mathematical) object as an element of that domain, and "storing abstract syntax" in the Rope, i.e. putting out something like pure functional form, with little or no domain indications, and leaving it to the system's (general expression evaluator's) type inference & resolution capabilities, and method lookup capabilities, to rebuild the object, if the need arises. Write out an Element in such a form that the Domain parser can read it back in. LoganBerry primaryKey attribute value, for searching for this object in a LoganBerry db. Such keys are generated when an Object is to be offlined. Previously called "Recast" Arguments are a DomainElement and a Domain. firstArg is intended to be an element of a "narrower" Domain than the one being defined by this interface, and secondArg is intended to be a Domain of the kind being defined by this interface. We attempt to widen firstArg to be an element of secondArg. If CanWidenOther[firstArg], then either we return firstArg unchanged (it is already an element of secondArg), or we create and return a new Object belonging to secondArg, i.e. we never modify the input Object. Previously called "CanRecast" Arguments are either a DomainElement and a Domain, or two Domains. firstArg is intended to be an element of, or be, a "narrower" Domain than the one being defined by this interface, and secondArg is intended to be a Domain of the kind being defined by this interface. Returns true if firstArg can be widened to be an element of secondArg. Arguments are a DomainElement and a Domain. firstArg is intended to be an element of a "wider" Domain than the one being defined by this interface, and secondArg is intended to be a Domain of the kind being defined by this interface. We attempt to narrow firstArg to be an element of secondArg. If CanNarrowOther[firstArg], then either we return firstArg unchanged (it is already an element of secondArg), or we create and return a new Object belonging to secondArg, i.e. we never modify the input Object. Arguments are either a DomainElement and a Domain, or two Domains. firstArg is intended to be an element of, or be, a "wider" Domain than the one being defined by this interface, and secondArg is intended to be a Domain of the kind being defined by this interface. Returns true if firstArg can be narrowed to be an element of secondArg. Argument is a DomainElement belonging to a Domain of the kind being defined by this interface. Either we return it unchanged, or we widen it to be an element of some "wider" Domain. In the latter case, we create a new Object, i.e. don't modify input. However it is expected that only General Expressions could ever be returned unchanged by a WidenThis proc, since it should be possible to widen anything else into a General Expression. For example, an integer can be widened to be a rational number. Usually a (nontrivial) WidenThis proc is written by knowing some tag with which the intended domain can be looked up (so we don't need to mention the Cedar interface that defines it), and then just applying that Domain's WidenOther proc to the argument. The basic AlgebraDomains method lookup procedure is to look for a method in this Object's class and all its superclasses, then set x _ WidenThis[input]; IF x.class.Equal[x, input] then FAIL else recursive call on x. Argument is a DomainElement belonging to a Domain of the kind being defined by this interface. Either we return it unchanged, or we narrow it to be an element of the narrowest possible "narrower" Domain. In the latter case, we create a new Object, i.e. don't modify input. For example, the NarrowThis proc for the rational numbers should return a BigInt for 3/1, but (the unchanged input argument) BigRat for 3/5. Expression evaluators are examples of NarrowThis procs. The fact that typically NarrowThis[V: Variable] looks for a value associated with V in some "environment", and if found, returns value.class.NarrowThis[value], is a detail that is entirely consistent with this assertion. Domain Selectors MathObjects.GetDomainDataProc: TYPE = PROC [domain: Object] RETURNS [DomainData: REF ANY]; output is a NameDomainData Input is a domain, output is the data1 field of its DomainData (assuming this field is an Object) Input is a domain, output is the data2 field of its DomainData (assuming this field is an Object) Domain Operations MathObjects.FlavorOp: TYPE = PROC [object: Object] RETURNS [flavor: Flavor]; MathObjects.flavor: TYPE = { DomainElement, Domain, Class}; Looks (with ISTYPE) for ElementNameData and NameDomainData. Should be in both DomainElement and Domain class records. A functional expression that can be parsed and evaluated to reconstruct the domain A short identifying name, e.g. "Q" for the rational numbers LoganBerry primaryKey attribute value, for searching for this object in a LoganBerry db. Such keys are generated when an Object is to be offlined. selector: returns LIST[data1, data2] of a Name Domain Element Constructors Arguments are the fields of an ElementNameData. Element Selectors MathObjects.GetElementDataProc: TYPE = PROC [domainElement: Object] RETURNS [ElementData: REF ANY]; output is a ElementNameData Input is a domain, output is the field1 field of its ElementData (assuming this field is an Object) Input is a domain, output is the field2 field of its ElementData (assuming this field is an Object) Element Operations Êö•NewlineDelimiter ™Jšœ™Jšœ7™7J˜Jšœ2™2J™J™šÏk ˜ Icodešœ˜Kšœ ˜ Kšœ˜—Ihead2šœ œ ˜Jšœ˜headšÏn™Kšœœœ˜Kšœœœœ˜Kšœœ˜"—šž™Jšœœ ˜J˜Kšœ œœÏc˜<šœ œŸ˜,K˜——šœž™KšŸ˜—šœ™šžœ œ˜'Kšœ™K™Kšœ>™>K™——šœ™šž œ˜ J™,J™ Jšœ(ž œÏ™JšœÜ™ÜJšœë™ëJšœ‚™‚JšœŸ™ŸJ™…J™ÑJ™ÚJ™üJšœ™—šžœ˜J™’Jšœÿ™ÿJ™—šž œ˜ JšœO™OJ˜—šž œ˜$J˜—šžœ˜-J˜—šžœ˜Kšœ”™”K˜—šžœ˜J˜—šž œ˜!Jšœ™Jšœª™ªJšœÑ™ÑJ˜—šž œ˜+Jšœ™JšœÓ™ÓJ˜—šž œ˜"Jšœ¨™¨JšœÒ™ÒJ˜—šžœ˜,JšœÑ™ÑJ˜—šž œ˜Jšœ¶™¶J™?Jšœ žœÜ™ýJšœ‡ž œG™×J™—šž œ˜ Jšœ’™’JšœŒ™ŒJšœ•™•J™——šœ™šžœ ˜3Kšœœœœ™ZKšœ Ïtœ œ ™K™—šžœ˜Kšœ! œ œ-™cK™—šžœ˜Kšœ! œ œ-™c——šœ™šžœ˜Kšœœœœ™LKšœœœ™;Kš œ œ  œ  œ œ ™?Kšœ9™9K˜—šž œ˜ KšœR™RK˜—šžœ˜K™;K˜—šžœ˜Kšœ”™”K˜—šžœ˜#Jš œ œ œ œ œ™;J™—Jšžœ˜+—šœ™šž œ˜$Kšœ œ  œ™1K™—Kšž œ  žœœ œ œ œ œœ œ  œ˜Z—šœ™šžœ!˜5Kšœœœœ™cKšœ  œ  œ™K™—šžœ˜Kšœ! œ œ.™eK™—šžœ˜Kšœ! œ œ.™e——šœ™šž œ˜!J˜—šž œ˜J˜——J˜Jšœ˜J˜—…—Ì3