DIRECTORY SafeStorage, IO, Atom, Rope, Basics, MathExpr; AlgebraClasses: CEDAR DEFINITIONS = BEGIN Object: TYPE = REF ObjectRec; ObjectRec: TYPE = RECORD [ name: Rope.ROPE _ NIL, -- hook onto this particular object structure: Structure, propList: Atom.PropList _ NIL, data: REF _ NIL ]; Structure: TYPE = REF StructureRec; StructureRec: TYPE = RECORD [ class: StructureClass, instanceData: REF _ NIL ]; Category: TYPE = {set, lattice, group, ring, field, module, vectorSpace, algebra, divisionAlgebra}; StructureClass: TYPE = REF StructureClassRec; StructureClassRec: TYPE = RECORD [ category: Category, flavor: Rope.ROPE _ NIL, printName: PrintNameProc, shortPrintName: PrintNameProc, -- if none, should be set to printName hashCode: CARDINAL _ 0, -- for quick checks of structure equality structureEqual: StructureEqualityTest, characteristic: StructureRankOp _ NIL, -- rings, fields, modules, vector spaces, algebras, divisionAlgebras only dimension: StructureRankOp _ NIL,-- modules, vector spaces, algebras, divisionAlgebras only isElementOf: ElementOfProc, legalFirstChar: LegalFirstCharOp, read: ReadOp, fromRope: FromRopeOp, toRope: ToRopeOp, write: WriteOp, fromExpr: FromExprOp _ NIL, toExpr: ToExprOp _ NIL, recast: UnaryImbedOp _ NIL, -- convert an element of a structure that conforms to this one (should be a noop on elements of this structure). Should use fastest available determination of structure, e.g. hashCode or shortPrintName. add: BinaryOp _ NIL, negate: UnaryOp _ NIL, subtract: BinaryOp _ NIL, zero: NullaryOp _ NIL, multiply: BinaryOp _ NIL, -- assumed associative; commutative or noncommutative ok commutative: BOOL _ TRUE, invert: UnaryOp _ NIL, divide: BinaryOp _ NIL, -- (lattices only) set difference operation goes here if appropriate one: NullaryOp, equal: EqualityOp _ NIL, -- need not be present in sets and lattices rightModule: BOOL _ FALSE, -- modules are left modules by default scalarMultiply: BinaryOp _ NIL, -- unless rightModule, this is left multiplication, i.e. scalar * vector. The underlying field of a vector space may be commutative or noncommutative. booleanAlgebra: BOOL _ FALSE, complement: UnaryOp _ NIL, ordered: BOOL _ FALSE, sign: CompareToZeroOp _ NIL, abs: UnaryOp _ NIL, compare: BinaryCompareOp _ NIL, integralDomain: BOOL _ FALSE, gcdDomain: BOOL _ FALSE, gcd: BinaryOp _ NIL, -- gcdDomains only euclideanDomain: BOOL _ FALSE, remainder: BinaryOp _ NIL, -- euclideanDomains only degree: ElementRankOp _ NIL, -- euclideanDomains only completeField: BOOL _ FALSE, realField: BOOL _ FALSE, realClosedField: BOOL _ FALSE, algebraicallyClosedField: BOOL _ FALSE, propList: Atom.PropList _ NIL ]; PrintNameProc: TYPE = PROC [structure: Structure] RETURNS [Rope.ROPE]; StructureEqualityTest: TYPE = PROC [thisStructure, otherStructure: Structure] RETURNS [BOOL]; defaultStructureEqualityTest: StructureEqualityTest; StructureRankOp: TYPE = PROC [structure: Structure] RETURNS [CARDINAL]; StructureCategoryToRope: PROC [category: Category] RETURNS [rope: Rope.ROPE]; GetProperty: PROC [structure: Structure, prop: ATOM] RETURNS [val: REF]; ElementOfProc: TYPE = PROC [item: Object, structure: Structure] RETURNS [BOOL]; defaultElementOfProc: ElementOfProc; LegalFirstCharOp: TYPE = PROC [char: CHAR, structure: Structure] RETURNS [BOOL]; ReadOp: TYPE = PROC [in: IO.STREAM, structure: Structure] RETURNS [out: Object]; FromRopeOp: TYPE = PROC [in: Rope.ROPE, structure: Structure] RETURNS [out: Object]; ToRopeOp: TYPE = PROC [in: Object] RETURNS [out: Rope.ROPE]; WriteOp: TYPE = PROC [stream: IO.STREAM, in: Object]; FromExprOp: TYPE = PROC [in: MathExpr.EXPR, structure: Structure] RETURNS [out: Object]; ToExprOp: TYPE = PROC [in: Object] RETURNS [out: MathExpr.EXPR]; NullaryOp: TYPE = PROC[structure: Structure] RETURNS [result: Object]; UnaryOp: TYPE = PROC [arg: Object] RETURNS [result: Object]; BinaryOp: TYPE = PROC [firstArg, secondArg: Object] RETURNS [result: Object]; EqualityOp: TYPE = PROC [firstArg, secondArg: Object] RETURNS [BOOL]; CompareToZeroOp: TYPE = PROC [arg: Object] RETURNS [Basics.Comparison]; BinaryCompareOp: TYPE = PROC [firstArg, secondArg: Object] RETURNS [Basics.Comparison]; StructuredToGroundOp: TYPE = PROC [structuredElt: Object] RETURNS [groundElement: Object]; ElementRankOp: TYPE = PROC [arg: Object] RETURNS [CARDINAL]; UnaryImbedOp: TYPE = PROC [in: Object, structure: Structure] RETURNS [out: Object]; BinaryImbedOp: TYPE = PROC [data1: Object, data2: REF, structure: Structure] RETURNS [out: Object]; END. xAlgebraClasses.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Arnon, March 4, 1986 12:02:24 pm PST Objects Structures Structure Classes Structure properties Flavor identifies outermost constructor (if any) used to build objects of this structure. Is a rope to allow expansion without interface changes. Examples: "Ints" "BigRats" "Points" "Polynomials" "Matrices" "Quotients" Test whether a given item belongs to this structure (run-time typechecking) I/O and Conversion Addition (lattices, rings, fields, vectorSpaces, algebras, divisionAlgebras only) Multiplication (lattices, groups, rings, fields, algebras, divisionAlgebras only) Equality testing Modules Scalar multiplication (modules, vectorSpaces, algebras, divisionAlgebras only) Lattice ops Ordered structure ops (rings, fields, modules, vectorSpaces, algebras, divisionAlgebras only) Some common varieties of rings (and algebras) Some common varieties of fields (and divisionAlgebras) Operations on Structures Identify the particular structure to the world. Test whether some other structure is the same algebraic domain as this one For things like ring characteristic (smallest positive integer k such that k*1 = 0; 0 if k infinite) and vector space dimension. Retrieve from property list Operations on Elements of Structures True if item is an element of the structure. True if char is legal first char in an external rep of a structure element. Since no object arg, need a hook to structure For things like determinant and coefficient extraction For things like degree functions in euclidean domains, rank of matrices Construct an element of one Structure from element(s) of another UnaryImbedOp should suffice in most instances (e.g. diagonal matrix); BinaryImbedOp is e.g. for constructing a term of a polynomial. Imbed in as an element of structure Construct an element of structure from data1 and data2 ΚM– "Mesa" style˜codešœΟc™Kšœ Οmœ1™