Formula clausify_prepare(Formula f);This routine gets a formula all ready for translation into clauses. The sequence of transformations is
Formula cnf(Formula f, int simplify_flag);This routine transforms a formula into CNF (conjunctive normal form). The argument simplify_flag tells whether to perform basic propositional simplification (not-not, idempotence, $T, $F) along the way.
It is assumed that the given formula is in NNF (negation normal form) (but it need not be flattened).
The result is flattened (w.r.t AND and OR), including all subformulas.
If the given formula is contradictory and simplify_flag is 1, the result should be the empty disjunction, that is, false.
Do not refer to the given formula after the call; a good way to call this routine is f = cnf(f, 1).
Formula dnf(Formula f, int simplify_flag);This routine transforms a formula into DNF (disjunctive normal form). The argument simplify_flag tells whether to perform basic propositional simplification (not-not, idempotence, $T, $F) along the way.
It is assumed that the given formula is in NNF (negation normal form) (but it need not be flattened).
The result is flattened (w.r.t AND and OR), including all subformulas.
If the given formula is valid and simplify_flag is 1, the result should be the empty conjunction, that is, true.
Do not refer to the given formula after the call; a good way to call this routine is f = dnf(f, 1).
Formula eliminate_rebinding(Formula f);This routine renames quantified variables so that no quantified variable occurs in the scope of a quantified variable with the same name.
If you wish to rename variables so that each quantifer has a unique variable, you can use the routine unique_quantified_vars() instead.
(This could be a void routine, because none of the formula nodes is changed; I made it return the Formula so that it is consistent with its friends.)
Formula formula_copy(Formula f);This function returns a copy of the given formula. All subformulas, including the atoms, are copied.
Formula formula_flatten(Formula f);This routine (recursively) flattens all AND and OR formulas.
int formula_ident(Formula f, Formula g);This Boolean function checks if two formulas are identical. The routine term_ident() checks identity of atoms.
The test is for strict identity---it does not consider renamability of bound variables, permutability of AND or OR, or symmetry of IFF or equality.
Formula formula_simplify(Formula f);This routine applies basic propositional simplification to a formula. And/or flattening, idempotence, not-not, and true-false, simplification are applied, but distributivity is not applied. The given formula is assumed to be in NNF (negation normal form).
Do not refer to the given formula after the call; a good way to call this routine is f = simplify(f).
Term formula_to_term(Formula f);
void fprint_formula(FILE *fp, Formula f);This routine prints a formula to a file. If you wish to have a formula printed without extra parentheses, you can call fprint_formula_term() instead.
void fprint_formula_mem(FILE *fp, BOOL heading);This routine prints (to FILE *fp) memory usage statistics for Formulas. The Boolean argument heading tells whether to print a heading on the table.
void free_formula(Formula p);This routine frees a formula node only. If you wish to recursively free all of the subformulas as well, call zap_formula(t) instead.
int greatest_qvar(Formula f);Return the greatest SYMNUM of a quantified variable in Formula f.
Recall that in Formulas, a quantified variable is represented as a constant (which is bound by the quantifier). If the formula has no quantified variables, return -1.
int greatest_symnum_in_formula(Formula f);Return the greatest SYMNUM of a any subterm. This includes quantifed variables that don't occur in any term.
This routine is intended to be used if you need malloc an array for indexing by SYMNUM.
Formula nnf(Formula f, Fpref pref);Transform a formula into negation normal form (NNF). (NNF means that all propositional connectives have been rewritten in terms of AND, OR and NOT, and all negation signs ar up against atomic formulas).
The argument "pref" should be either CONJUNCTION or DISJUNCTION, and it specifies the preferred form to use when translating IFFs.
Do not refer to the given formula after the call; a good way to call this routine is f = nnf(f, CONJUNCTION).
void p_formula(Formula c);This routine prints a formula, followed by ".\n" and fflush, to stdout. If you wish to have a formula printed without extra parentheses, you can call p_formula_term() instead. If you don't want the newline, use fprint_formula() instead.
void p_formula_mem(void);This routine prints memory usage statistics for Formulas to stdout.
Formula remove_universal_quantifiers(Formula f);For each universally quantified variable in the given formula,
Formula skolemize(Formula f);This routine Skolemizes an NNF formula. The quantified variables need not be named in any particular way. If there are universally quantified variables with the same name, one in the scope of another, the inner variable will be renamed. (Existential nodes are removed.)
Formula term_to_formula(Term t);
Assume that no subterm (of t) representing a formula is a term of type VARIABLE.
Formula unique_quantified_vars(Formula f);Rename quantified variables, if necessary, so that each is unique. This works for any formula.
If you wish to rename a quantified variable only if it occurs in the scope of of a quantified variable with the same name, you can use the routine eliminate_rebinding() instead.
(This could be a void routine, because none of the formula nodes is changed; I made it return the Formula so that it is consistent with its friends.)
void zap_formula(Formula f);Free a formula, including all of its subformulas, including its atoms.
/* formula types */ typedef enum { ATOM_FORM, AND_FORM, OR_FORM, NOT_FORM, IFF_FORM, IMP_FORM, IMPBY_FORM, ALL_FORM, EXISTS_FORM} Ftype; typedef struct formula * Formula; struct formula { Ftype type; int arity; char *qvar; /* quantified variable */ Formula *kids; /* for non-atoms */ Term atom; /* for atoms */ }; /* formula preference */ typedef enum { CONJUNCTION, DISJUNCTION } Fpref;
These activities are projects of the Mathematics and Computer Science Division of Argonne National Laboratory.