PolynomialJaM.mesa
Michael Plass, December 2, 1982 11:08 am
DIRECTORY JaMFnsDefs, Polynomial;
PolynomialJaM: PROGRAM IMPORTS JaMFnsDefs, Polynomial =
BEGIN
PopPoly:
PROC
RETURNS [p: Polynomial.Ref] =
BEGIN
d: NAT ← JaMFnsDefs.PopInteger[];
p ← Polynomial.Create[d];
FOR i:NAT IN [0..d] DO p[i] ← JaMFnsDefs.GetReal[] ENDLOOP;
END;
PushPoly:
PROC [p: Polynomial.Ref] =
BEGIN
d: NAT ← Polynomial.Degree[p];
FOR i:NAT DECREASING IN [0..d] DO JaMFnsDefs.PushReal[p[i]] ENDLOOP;
JaMFnsDefs.PushInteger[d];
END;
PolyEval:
PROC =
BEGIN
x: REAL ← JaMFnsDefs.GetReal[];
f: Polynomial.Ref ← PopPoly[];
JaMFnsDefs.PushReal[Polynomial.Eval[f,x]]
END;
PolyAdd:
PROC =
BEGIN
g: Polynomial.Ref ← PopPoly[];
f: Polynomial.Ref ← PopPoly[];
PushPoly[Polynomial.Sum[f,g]]
END;
PolySub:
PROC =
BEGIN
g: Polynomial.Ref ← PopPoly[];
f: Polynomial.Ref ← PopPoly[];
PushPoly[Polynomial.Difference[f,g]]
END;
PolyMul:
PROC =
BEGIN
g: Polynomial.Ref ← PopPoly[];
f: Polynomial.Ref ← PopPoly[];
PushPoly[Polynomial.Product[f,g]]
END;
PolyDerivative:
PROC =
BEGIN
f: Polynomial.Ref ← PopPoly[];
PushPoly[Polynomial.Derivative[f]]
END;
PolyIntegral:
PROC =
BEGIN
f: Polynomial.Ref ← PopPoly[];
PushPoly[Polynomial.Integral[f]]
END;
PolyRealRoots:
PROC =
BEGIN
f: Polynomial.Ref ← PopPoly[];
r: REF Polynomial.RealRootRec ← Polynomial.RealRoots[f];
FOR i:NAT IN [0..r.nRoots) DO JaMFnsDefs.PushReal[r[i]] ENDLOOP;
JaMFnsDefs.PushInteger[r.nRoots];
END;
JaMFnsDefs.Register["Polynomial.Eval"L,PolyEval];
JaMFnsDefs.Register["Polynomial.Add"L,PolyAdd];
JaMFnsDefs.Register["Polynomial.Sub"L,PolySub];
JaMFnsDefs.Register["Polynomial.Mul"L,PolyMul];
JaMFnsDefs.Register["Polynomial.Differentiate"L,PolyDerivative];
JaMFnsDefs.Register["Polynomial.Integrate"L,PolyIntegral];
JaMFnsDefs.Register["Polynomial.Roots"L,PolyRealRoots];
END.