INTERFACEDefines a procedure for solving a conjunctive normal form constraint. This procedure performs both unification closure to solve for list structure, and Newton-Raphson iteration to solve for numeric values.JunoSolve ;
IMPORT RTVal; TYPE Private <: ROOT; Public = Private OBJECT known: BOOLEAN; val: RTVal.T; END; Var <: Public; Vars = REF ARRAY OF Var;If
x
is a Var
, the x.known
implies x.val
is a legal Juno value. If
x.known = FALSE
but x.val # NIL
, then x.val
is a hint for the initial
value of x
.
TYPE Constraint <: REFANY; Constraints = REF ARRAY OF Constraint; PROCEDURE New(known := FALSE; val: RTVal.T := NIL): Var;
Return a new, validVar
with the given field values. It will remain valid until the next call toDispose
.
PROCEDURE NewEqual(x, y: Var): Constraint;
Return the constraint x = y
.
PROCEDURE NewCons(x, y, z: Var): Constraint;
Return the constraint x = (y,z)
.
PROCEDURE NewPlus(x, y, z: Var): Constraint;
Return the constraint x = y + z
.
PROCEDURE NewTimes(x, y, z: Var): Constraint;
Return the constraint x = y * z
.
PROCEDURE NewAtan(x, y, z: Var): Constraint;
Return the constraint x = ATAN(y, z)
.
PROCEDURE NewSin(x, y: Var): Constraint;
Return the constraint x = SIN(y)
.
PROCEDURE NewCos(x, y: Var): Constraint;
Return the constraint x = COS(y)
.
PROCEDURE NewExp(x, y: Var): Constraint;
Return constraint x = EXP(y)
.
PROCEDURE NewReal(x: Var): Constraint;
Return the constraint REAL(x)
.
PROCEDURE NewText(x: Var): Constraint;
Return constraint TEXT(x)
.
PROCEDURE Dispose();
Invalidate and reclaim all existingVar
's andConstraint
's.
PROCEDURE P(READONLY c: ARRAY OF Constraint): BOOLEAN;
Solvec
for its unknowns and returnTRUE
, setting theirval
fields so as to solve the constraints. ReturnFALSE
if there is no solution. IfP
returnsFALSE
, it can have arbitrary effects on theknown
andval
fields of variables referenced inc
.Requires that
Init
has been called on every variable referenced inc
since each was last passed in a call toP
.
END JunoSolve.