Polynomials.mesa
Last Edited by: Arnon, June 10, 1985 4:19:22 pm PDT
DIRECTORY
Rope USING [ROPE],
IO USING [STREAM],
BigCardinals,
RatNums;
Polynomials: CEDAR DEFINITIONS =
BEGIN OPEN BC: BigCardinals, RN: RatNums;
***** Data Structure *****
PolynomialClass:
TYPE = { constant, nonconstant };
Polynomial:
TYPE =
REF PolynomialRec;
PolynomialRec:
TYPE =
RECORD [
numVars: CARDINAL, -- 0 <=> constant variant
data:
SELECT type: PolynomialClass
FROM
constant => [ value: RN.RatNum ],
nonconstant => [ leadingTerm: Term, reductum: Polynomial],
the terms of a nonconstant polynomial are expected to be listed in order of decreasing exponent, thus the reductum of a polynomial (if nonzero) is expected to be a polynomial in the same number of variables, of lower degree.
ENDCASE
];
Term:
TYPE =
RECORD [
exponent: CARDINAL,
coefficient: Polynomial
];
ZeroPoly: Polynomial =
NIL;
the zero polynomial is represented as the empty list
DPolynomial: TYPE = LIST OF DTerm;
DTerm:
TYPE =
RECORD [
coefficient: RN.RatNum,
degreeVector: DegreeVector
];
DegreeVector: TYPE = LIST OF CARDINAL;
ZeroDPoly: DPolynomial =
NIL;
the zero polynomial is represented as the empty list
VariableList:
TYPE =
LIST
OF Rope.
ROPE;
***** Arithmetic *****
PolynomialAdd:
PROC [in1, in2: Polynomial]
RETURNS [out: Polynomial];
PolynomialNegate:
PROC [in: Polynomial]
RETURNS [out: Polynomial];
PolynomialSubtract:
PROC [in1, in2: Polynomial]
RETURNS [Polynomial];
PolynomialMultiply:
PROC [in1, in2: Polynomial]
RETURNS [out: Polynomial];
***** Constructors *****
UnivariateMonomial:
PROC [coeff:
RN.RatNum, exp:
CARDINAL]
RETURNS [out: Polynomial];
MultivariateMonomial:
PROC [coeff: Polynomial, exp:
CARDINAL]
RETURNS [out: Polynomial];
MakePolynomialZero:
PROC
RETURNS [out: Polynomial ← ZeroPoly];
Construct Polynomial representation for zero
***** Conversion and I/O *****
ReadVariableList:
PROC [in:
IO.
STREAM]
RETURNS [V: VariableList];
VariableListFromRope:
PROC [in: Rope.
ROPE]
RETURNS [V: VariableList];
VariableListToRope:
PROC [V: VariableList]
RETURNS [out: Rope.
ROPE];
WriteVariableList:
PROC [V: VariableList, out:
IO.
STREAM];
ReadDPolynomial:
PROC [in:
IO.
STREAM, V: VariableList]
RETURNS [poly: DPolynomial];
DPolynomialFromRope:
PROC [in: Rope.
ROPE, V: VariableList]
RETURNS [out: DPolynomial];
DPolynomialToRope:
PROC [in: DPolynomial
, V: VariableList]
RETURNS [out: Rope.
ROPE];
WriteDPolynomial:
PROC [in: DPolynomial, V: VariableList, out:
IO.
STREAM];
PolyFromDPoly:
PROC [in: DPolynomial, V: VariableList]
RETURNS [out: Polynomial];
DPolyFromPoly: PROC [in: Polynomial, V: VariableList] RETURNS [out: DPolynomial];
ReadPolynomial:
PROC [in:
IO.
STREAM, V: VariableList]
RETURNS [poly: Polynomial];
PolynomialFromRope:
PROC [in: Rope.
ROPE, V: VariableList]
RETURNS [out: Polynomial];
If needed: an inline, converting the rope to a stream (IO.RIS), then calling ReadPolynomial. MessageRope is the result of ROS'ing a newly created MessageStream passed in to ReadPolynomial.
PolynomialSAC2RepToRope:
PROC [in: Polynomial]
RETURNS [out: Rope.
ROPE];
Dump the internal representation in SAC2 list format
PolynomialToRope:
PROC [in: Polynomial, V: VariableList]
RETURNS [out: Rope.
ROPE];
A reasonable format
WritePolynomial:
PROC [in: Polynomial, V: VariableList, out:
IO.
STREAM];
Write in a reasonable format
END.