INTERFACEProcedures for compiling a constraint in normal form.JunoCompileNF ;
IMPORT JunoAST, JunoScope, JunoCompileErr, StackTbl; PROCEDURE Normalize(p: JunoAST.Formula; tbl: StackTbl.T): JunoAST.NormalForm;
Returns a formula equivalent topthat has been ``normalized''. A constraint is in ``normal form'' if it is an (optional)Equantification (all of whose variables are unhinted) over (optional) conjunctions of ``normal simple formulas''. A normal simple formula takes one of the following forms:
1) x ~= y, 2) P(v_1,...,v_n) 3) x ~= F(v_1,...,v_n) 4) CF(nsf_1,...,nsf_n)where~=denotes~(near) or=(equality),x,y, andv_1throughv_ndenote either literals or variables,nsf_1throughnsf_ndenote normal simple formulas,Pis a predicate,Fis a function, andCFis a compound formula other thanAND(i.e.,NOTorOR). Moreover, compound formulas (4) are guaranteed to be original top-level conjuncts of the input formulap. Note that a normal simple formula does not contain any grouped (parenthesized) expressions.This is a purely syntactic transformation. The
tblis used to annotate new variables as they are introduced inEquantifications. New variables are not added totbl. The variables in the result are all unhinted, and they all have theirevarbits set.Requires that all existentially quantified variables are distinct, and that every use of any of the existentially quantified variables occurs within the scope of its quantification.
PROCEDURE ToCmd(
nf: JunoAST.NormalForm;
scp: JunoScope.T;
stack_tbl: StackTbl.T;
xtra_vars: JunoAST.NearVarList := NIL):
JunoAST.Cmd RAISES {JunoCompileErr.Error};
Return a command that solves the unknown variables innf.var\unionxtra_varsfor the conjunctionnf.conjif there is a solution, and fails otherwise. The resulting command contains only simple equality queries, assignments, and queries to be passed to the Juno solver (i.e.,JunoAST.ConjQuery's). The queries passed to the Juno solver must be a conjunction of normal simple formulas that contain only primitive predicates (REAL, TEXT, PAIR) and functions (+, *, CONS, SIN, COS, ATAN, EXP, LN).Requires all
evarfields of the variables innf.varto be true, allevarfields of the variables inxtra_varsto be false, and all variables innf.var\unionxtra_varsto be unhinted. Thefrozenbits innf.varmust all be reset, and those ofxtra_varsare set iff the corresponding variable's value has been initialized.
END JunoCompileNF.