Process an evaluated AST given by Eval.eval to produce a CNF AST and output DIMACS
ast_to_cnf is the main function.
Vocabulary
Literal: a possibly negated proposition; we denote them as a, b... and their type is homogenous to Prop _ or Not(Prop _) or Top or Bottom. Exples:
a is a literal,
not b is a literal.
Clause: a disjunction (= separated by "or") of possibly negated literals. Example of clause:
a or not b or c or d is a clause
Conjunction: literals separated by "and"; example:
a and b and not and not d is a conjunction
AST: abstract syntax tree; it is homogenous to Types.Ast.t and is a recursive tree representing a formula, using Or, And, Implies... Example: the formula (1) has the abstract syntax tree (2):
(a or b) and not c (1) natural language
And (Or (Prop x, Prop x),Not (Prop x)) (2) abstract syntax tree
CNF: a Conjunctive Normal Form is an AST that has a special structure with is a conjunction of disjunctions of literals. For example:
ast_to_cnf translates the syntaxic tree made of Or, And, Implies, Equiv... Or, And and Not; moreover, it can only be in a conjunction of formulas (see a reminder of their definition above). For example (instead of And, Or we use "and" and "or" and "not"):
clauses_of_cnf translates the cnf ast (Not, And, Or, Prop; no Bot/Top) into a CNF formula that takes the form of a list of lists of litterals (conjunctions of disjunctions of possibly negated proprositions). neg lit returns the negation of the litteral (not) fresh () returns a newly generated litteral Returns:
the list of lists of litterals
the table literal-to-name Note that the total number of literals is exactly equal to the table size; this size includes the special propositions beginning with '&' (e.g., '&4').
DIMACS output
The following functions are for displaying dimacs/qdimacs format. Example for the formula
rain=>wet and rain and not wet
we get the dimacs file:
c wet 1 <-- (optionnal) [print_table]
c rain 2
c CNF format file <-- by hand
p cnf 2 3 <-- by hand (nb_lits, nb_clauses)
-2 1 0 <-- [print_clauses]
-2 2 0
-2 -1 0
is_dummy name tells (using the name of a litteral) is a 'dummy' literal that was introduced during cnf conversion; these literals are identified by their prefix '&'.