AlgebraicNumbersImpl.mesa
Last Edited by: Arnon, July 19, 1985 2:54:46 pm PDT
DIRECTORY
Rope,
IO,
AlgebraClasses,
Polynomials,
RatIntervals,
AlgebraicNumbers;
AlgebraicNumbersImpl: CEDAR PROGRAM
IMPORTS Rope, IO, RatIntervals
EXPORTS AlgebraicNumbers =
BEGIN OPEN AC: AlgebraClasses, POL: Polynomials, RI: RatIntervals, AlgebraicNumbers;
Errors
BadGroundField: PUBLIC ERROR [groundStructure: AC.Structure] = CODE;
Constructors
MakeAlgebraicNumber: PUBLIC PROC [minPolyRing: AC.Structure, minimalPolynomial: POL.Polynomial, real: BOOLFALSE, isolatingInterval: RI.RatInterval ← NIL] RETURNS [AlgebraicNumber] ~ {
data: POL.PolynomialRingData ← NARROW[minPolyRing.instanceData];
groundStructure: AC.Structure ← data.coeffRing;
IF groundStructure.class.flavor#field AND groundStructure.class.flavor#divisionAlgebra THEN ERROR BadGroundField[groundStructure];
IF NOT real THEN {
IF groundStructure.class.algebraicallyClosedField THEN ERROR;
RETURN[ NEW[AlgebraicNumberRec ← [
minPolyRing: minPolyRing,
minimalPolynomial: minimalPolynomial
]] ]
}
ELSE {
IF NOT groundStructure.class.realField THEN ERROR;
IF groundStructure.class.realClosedField THEN ERROR;
IF isolatingInterval = NIL THEN ERROR;
RETURN[ NEW[AlgebraicNumberRec ← [
minPolyRing: minPolyRing,
minimalPolynomial: minimalPolynomial,
real: TRUE,
isolatingInterval: isolatingInterval
]] ]
};
};
IO
ReadAlgebraicNumber: PUBLIC PROC [in: IO.STREAM, minPolyRing: AC.Structure] RETURNS [out: AlgebraicNumber] ~ {
minimalPolynomial: POL.Polynomial ← NARROW[minPolyRing.class.read[in, minPolyRing] ]; -- should check monic, irreducible
out ← NEW[AlgebraicNumberRec ← [minPolyRing: minPolyRing, minimalPolynomial: minimalPolynomial]];
};
ReadRealAlgebraicNumber: PUBLIC PROC [in: IO.STREAM, minPolyRing: AC.Structure] RETURNS [out: AlgebraicNumber] ~ {
conjugatesDefinition: AlgebraicNumber ← ReadAlgebraicNumber[in, minPolyRing];
isolatingInterval: RI.RatInterval ← RI.ReadRatInterval[in];
out ← NEW[RealAlgebraicNumberRec ← [conjugatesDefinition: conjugatesDefinition, isolatingInterval: isolatingInterval] ]; -- groundField must be real
};
AlgebraicNumberFromRope: PUBLIC PROC [in: Rope.ROPE, minPolyVariable: VARS.VariableSeq ← defaultMinPolyVariable] RETURNS [out: AlgebraicNumber] = {
out ← ReadAlgebraicNumber[IO.RIS[in], minPolyVariable];
};
AlgebraicNumberToRope: PUBLIC PROC [in: AlgebraicNumber] RETURNS [out: Rope.ROPE] ~ {
out ← Rope.Concat[in.minPolyRing.class.toRope[in.minimalPolynomial, in.minPolyRing], "\n"];
IF in.real THEN out ← Rope.Concat[out, RI.RatIntervalToRope[in.isolatingInterval] ];
};
WriteAlgebraicNumber: PUBLIC PROC [in: AlgebraicNumber, out: IO.STREAM] = {
out.PutRope[ AlgebraicNumberToRope[in] ]
};
END.