MultiPolynomial.mesa
Multivariate polynomials with real coefficients.
Copyright (C) 1986 by Xerox Corporation. All rights reserved.
James Rauen August 14, 1986 6:07:38 pm PDT
DIRECTORY
Polynomial USING [Ref],
Rope USING [ROPE];
MultiPolynomial: CEDAR DEFINITIONS ~ BEGIN
Type declarations
Ref: TYPE ~ REF MultiPolRec;
MultiPolSequence: TYPE ~ RECORD [
pols: SEQUENCE length: NAT OF Ref];
MultiPolRec: TYPE ~ RECORD [terms: SEQUENCE length: NAT OF Monomial];
Monomial: TYPE ~ RECORD[
coefficient: REAL,
vars: REF PoweredVariableSequence];
PoweredVariableSequence: TYPE ~ RECORD [
varList: SEQUENCE numVars: NAT OF PoweredVariable];
PoweredVariable: TYPE ~ RECORD[
variable: ATOM,
degree: INTEGER];
EvaluationBindings: TYPE ~ LIST OF EvaluationBinding;
EvaluationBinding: TYPE ~ RECORD[
variable: ATOM,
value: REAL];
SubstitutionBindings: TYPE ~ LIST OF SubstitutionBinding;
SubstitutionBinding: TYPE ~ RECORD[
variable: ATOM,
replacement: Ref];
TSUBindings: TYPE ~ LIST OF TSUBinding;
TSUBinding: TYPE ~ RECORD[
variable: ATOM,
replacement: Polynomial.Ref];
Errors
Error: ERROR [reason: ErrorCode];
ErrorCode: TYPE ~ {
NotUnivariate,
tried to make a univariate polynomial from a Ref that had other variables
NotConstant,
tried to make a nonconstant polynomial into a real
BadFormat,
tried to make a Ref from an incorrectly formatted rope
UnsubstitutedVariables,
didn't substitute for all the variables when you should have
BadVariableName,
tried to use a variable name which was not alphabetic or was longer than 1 char
InternalError
track down the implementor and kill him
};
Conversions to and from other representations
RefFromRope: PROC [rope: Rope.ROPE] RETURNS [Ref];
Obtains a Ref from the rope representation, according to the grammar in the Rope Representation section below. If the representation is not valid, Error[BadFormat] is raised. Note: this is usually the easiest way to create a MultiPolynomial. Warning: "e" notation doesn't work (e is treated as a variable).
UnivariateFromRef: PROC [a: Ref, var: ATOM] RETURNS [Polynomial.Ref];
Returns a univariate polynomial. If variables other than var occur in a, raises Error[NotUnivariate].
RefFromUnivariate: PROC [pol: Polynomial.Ref, var: ATOM] RETURNS [Ref];
Returns a Ref from a univariate polynomial, using var for the variable. If var is not a legal variable name, raises Error[BadVariableName].
RealFromRef: PROC [a: Ref] RETURNS [REAL];
Returns the real value of a. If a is not a constant, raises Error[NotConstant].
RopeFromRef: PROC [a: Ref] RETURNS [Rope.ROPE];
Returns a Rope representation of the polynomial.
Operations on MultiPols
Sum: PROC [a, b: Ref] RETURNS [Ref];
Returns the sum of the two polynomials.
Difference: PROC [a, b: Ref] RETURNS [Ref];
Returns the difference of the two polynomials.
Power: PROC [a: Ref, n: NAT] RETURNS [Ref];
Returns the nth power of a.
Product: PROC [a, b: Ref] RETURNS [Ref];
Returns the product of the two polynomials.
Scale: PROC [p: Ref, c: REAL] RETURNS [Ref];
Returns the product of a and c.
Differentiate: PROC [a: Ref, var: ATOM] RETURNS [Ref];
Returns the derivative of a with respect to var.
Degree: PROC [a: Ref] RETURNS [NAT];
Returns the degree of a.
Substitution Mechanisms
Evaluate: PROC [a: Ref, variable: ATOM, value: REAL] RETURNS [Ref];
Substitutes real value for variable in a and returns the resulting polynomial.
EvaluateList: PROC [a: Ref, bindings: EvaluationBindings] RETURNS [Ref];
Substitutes real values for variables in a and returns the resulting polynomial.
TotallyEvaluate: PROC [a: Ref, bindings: EvaluationBindings] RETURNS [REAL];
Substitutes real values for all variables in a and returns the resulting real value. If unsubstituted variables remain in a, Error[UnsubstitutedVariables] is raised.
Substitute: PROC [a: Ref, variable: ATOM, replacement: Ref] RETURNS [Ref];
Substitutes replacement for variable in a and returns the resulting polynomial.
SubstituteList: PROC [a: Ref, bindings: SubstitutionBindings] RETURNS [Ref];
Substitutes replacements for variables in a and returns the resulting polynomial.
TotallySubstituteUnivariates: PROC [a: Ref, bindings: TSUBindings] RETURNS [Polynomial.Ref];
Completely substitutes univariate polynomials into a. If unsubstituted variables remain in a, Error[UnsubstitutedVariables] is raised.
Rope representation grammar
Grammar:
ropeRepresentation ::= leadingTerm | leadingTerm moreTerms
leadingTerm ::= term | sign term
moreTerms ::= sign term | sign term moreTerms
sign ::= + | -
term ::= coefficient | poweredVariables | coefficient poweredVariables
coefficient ::= string representation of REAL
poweredVariables ::= poweredVariable | poweredVariable poweredVariables
poweredVariable ::= variable | variable ^ exponent
variable ::= a..z | A..Z
exponent ::= string representation of NAT
Note that whitespace is ignored.
Examples:
"-x^2-y^2-z^2+2"
"xyzzy - 3Ab^2c^2b^3"
"+2y - 4y"
"-6.170"
END.