Element Representation
Orchard: TYPE = AlgebraClasses.Object;
OrchardData: TYPE = LIST OF OrchardTerm;
Distributed representation, modelled on a distributed polynomial rep. The terms of a nonNIL Orchard are sorted in order of increasing treeID. The Nil Orchard is represented by OrchardData = NIL.
OrchardTerm: TYPE = REF OrchardTermRec;
TermRec:
TYPE =
RECORD [
coefficient: AlgebraClasses.Object - expected to be either an Int or a Real
tree: Tree,
];
TreeData: TYPE = REF TreeDataRec;
TreeDataRec:
TYPE =
RECORD [
parent: Tree ← NIL, -- parent tree; NIL iff this node is root
children: LIST OF Tree ← NIL, -- NIL iff this node is a leaf
treeID: Ints.Int, -- the hash code for this Tree
label: ASVariables.Variable ← NIL, -- nonNIL iff this is a labeled tree
key: ACInts.Int ← NIL -- nonNIL iff this is a heap-ordered tree
];
Structure Operations
Flavor: AlgebraClasses.FlavorOp;
AlgebraClasses.FlavorOp: TYPE = PROC [object: Object] RETURNS [flavor: Flavor];
AlgebraClasses.flavor: TYPE = { StructureElement, Structure, Class};
Looks (with ISTYPE) for ElementNameData and NameStructureData.
Should be in both StructureElement and Structure class records.
StructureToRope: AlgebraClasses.ToRopeOp;
A functional expression that can be parsed and evaluated to reconstruct the structure
StructureName: AlgebraClasses.ToRopeOp;
A short identifying name, e.g. "Q" for the rational numbers
StructureLBKey: AlgebraClasses.ToRopeOp;
LoganBerry primaryKey attribute value, for searching for this object in a LoganBerry db. Such keys are generated when an Object is to be offlined.
StructureData: AlgebraClasses.UnaryToListOp;
selector: returns LIST[data1, data2] of a Name Structure
IsNameStructure: AlgebraClasses.UnaryPredicate;
Element Conversion and IO
WidenOther: AlgebraClasses.BinaryOp;
Previously called "Recast"
Arguments are a StructureElement and a Structure. firstArg is intended to be an element of a "narrower" Structure than the one being defined by this interface, and secondArg is intended to be a Structure 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.
CanWidenOther: AlgebraClasses.BinaryPredicate;
Previously called "CanRecast"
Arguments are either a StructureElement and a Structure, or two Structures. firstArg is intended to be an element of, or be, a "narrower" Structure than the one being defined by this interface, and secondArg is intended to be a Structure of the kind being defined by this interface. Returns true if firstArg can be widened to be an element of secondArg.
NarrowOther: AlgebraClasses.BinaryOp;
Arguments are a StructureElement and a Structure. firstArg is intended to be an element of a "wider" Structure than the one being defined by this interface, and secondArg is intended to be a Structure 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.
CanNarrowOther: AlgebraClasses.BinaryPredicate;
Arguments are either a StructureElement and a Structure, or two Structures. firstArg is intended to be an element of, or be, a "wider" Structure than the one being defined by this interface, and secondArg is intended to be a Structure of the kind being defined by this interface. Returns true if firstArg can be narrowed to be an element of secondArg.
WidenThis: AlgebraClasses.UnaryOp;
Argument is a StructureElement belonging to a Structure of the kind being defined by this interface. Either we return it unchanged, or we widen it to be an element of some "wider" Structure. 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 structure can be looked up (so we don't need to mention the Cedar interface that defines it), and then just applying that Structure's WidenOther proc to the argument.
The basic AlgebraStructures 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.
NarrowThis: AlgebraClasses.UnaryOp;
Argument is a StructureElement belonging to a Structure 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" Structure. 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.
WidenToGeneralExpression: AlgebraClasses.UnaryOp;
Previously called "ToExpr: AlgebraClasses.ToExprOp";
Optional. A short cut to successive aplication of WidenThis procs until General Expressions reached.
LegalFirstChar: AlgebraClasses.LegalFirstCharOp;
ElementRead: AlgebraClasses.ReadOp;
The Domain-dependent parser
ElementFromRope: AlgebraClasses.FromRopeOp;
ElementToRope: AlgebraClasses.ToRopeOp;
Write out an Element in such a form that the Domain-dependent parser can read it back in.
ElementLBKey: AlgebraClasses.ToRopeOp;
LoganBerry primaryKey attribute value, for searching for this object in a LoganBerry db. Such keys are generated when an Object is to be offlined.
ElementWrite: AlgebraClasses.WriteOp;
Element Operations
Select: AlgebraClasses.BinaryOp;
Args are an Orchard and a treeID, returns the OrchardTerm in that tree with that hash code; return NIL if no such OrchardTerm found.
Insert: AlgebraClasses.BinaryOp;
Args are an OrchardTerm and an Orchard, returns the Orchard resulting from inserting that OrchardTerm into the given Orchard.
Length: AlgebraClasses.UnaryOp;
Arg is an Orchard, returns the length (# of terms) in it (an Int).
UnaryOp: AlgebraClasses.UnaryOp;