section \Tseitin Transformation - Verification and Optimization\
text \
Since most SAT solvers insist on formulas in conjunctive normal form (CNF) as input,
but in general the CNF of a given formula may be exponentially larger, there is interest
in efficient transformations that produce a small equisatisfiable CNF for a given formula.
Probably the earliest and most well-known of these transformation is due to Tseitin.
In this project you will implement several transformations of propositional formulas
into equisatisfiable CNFs and formally prove results about their complexity and that
the resulting CNFs are indeed equisatisfiable to the original formula.
\
theory Project_Tseitin
imports Main
begin
subsection \Syntax and Semantics\
text \
For the purposes of this project propositional formulas (with atoms of an arbitrary type)
are restricted to the following (functionally complete) connectives:
\
datatype 'a form =
Bot \ \the "always false" formula\
| Atm 'a \ \propositional atoms\
| Neg "'a form" \ \negation\
| Imp "'a form" "'a form" \ \implication\
text \
Define a function \eval\ that evaluates the truth value of a formula with respect
to a given truth assignment \\ :: 'a \bool\.
\
fun eval :: "('a \ bool) \ 'a form \ bool"
where
"eval \ \ = undefined"
text \
Define a predicate \sat\ that captures satisfiable formulas.
\
definition sat :: "'a form \ bool"
where
"sat \ \ undefined"
subsection \Conjunctive Normal Forms\
text \
Literals are positive or negative atoms.
\
datatype 'a literal = P 'a | N 'a
text \
A clause is a disjunction of literals, represented as a list of literals.
\
type_synonym 'a clause = "'a literal list"
text \
A CNF is a conjunction of clauses, represented as list of clauses.
\
type_synonym 'a cnf = "'a clause list"
text \
Implement a function \of_cnf\ that, given a CNF (of @{typ "'a cnf"}, computes
a logically equivalent formula (of @{typ "'a form"}).
\
fun of_cnf :: "'a cnf \ 'a form"
where
"of_cnf cs = undefined"
subsection \Tseitin Transformation\
text \
The idea of Tseitin's transformation is to assign to each subformula \\\
a label \a\<^sub>\\ and use the following definitions
\<^item> \a\<^sub>\ \ \\
\<^item> \a\<^sub>\\<^sub>\ \ \ \\
\<^item> \a\<^sub>\\<^sub>\\<^sub>\ \ \ \ \\
to recursively compute clauses \tseitin \\ such that \a\<^sub>\ \ tseitin \\ and \\\
are equisatisfiable (that is, the former is satisfiable iff the latter is).
Define a function \tseitin\ that computes the clauses corresponding to the above idea.
\
fun tseitin :: "'a form \ ('a form) cnf"
where
"tseitin \ = undefined"
text \
Prove that \a\<^sub>\ \ tseitin \\ are equisatisfiable.
\
lemma tseitin_equisat:
"sat (of_cnf ([P \] # tseitin \)) \ sat \"
sorry
text \
Prove linear bounds on the number of clauses and literals by suitably
replacing \n\ and \num_literals\ below:
\
lemma tseitin_num_clauses:
"length (tseitin \) \ n * size \"
sorry
lemma tseitin_num_literals:
"num_literals (tseitin \) \ n * size \"
sorry
text \
Implement a function \t_tseitin\ that computes the number of recursive calls of your
earlier definition of @{const tseitin} and prove a linear bound in the size of the formula
(by suitably replacing \n\):
\
fun t_tseitin :: "'a form \ nat"
where
"t_tseitin \ = undefined"
lemma tseitin_linear:
"t_tseitin \ \ n * size \"
sorry
text \
Implement a tail recursive variant of @{const tseitin} and prove the lemma below:
\
fun tseitin2 :: "'a form \ ('a form) cnf \ ('a form) cnf"
where
"tseitin2 \ acc = undefined"
lemma tseitin2_equisat:
"sat (of_cnf ([P \] # tseitin2 \ [])) \ sat \"
sorry
subsection \A Transformation due to Plaisted and Greenbaum\
text \
Plaisted and Greenbaum had the idea to take the polarity of a subformula into account in order
to reduce the number of clauses and literals needed for an equisatisfiable CNF.
Here, the polarity at the root is positive and it flips whenever we move down to the (first)
argument of a(n) negation (implication).
Implement a variant \plaisted\ of @{const tseitin} that takes the polarity of subformulas
into account and prove that \a\<^sub>\ \ plaisted True \\ and \\\ are equisatisfiable.
\
fun plaisted :: "bool \ 'a form \ ('a form) cnf"
where
"plaisted p \ = undefined"
lemma plaisted_equisat:
"sat (of_cnf ([P \] # plaisted True \)) \ sat \"
sorry
text \
Prove linear bounds on the number of clauses and literals by suitably
replacing \n\ and \num_literals\ below:
\
lemma plaisted_num_clauses:
"length (plaisted p \) \ n * size \"
sorry
lemma plaisted_num_literals:
"num_literals (plaisted p \) \ n * size \"
sorry
text \
Prove that with respect to the number of literals and clauses in the resulting CNF,
@{const plaisted} is at least as good as @{const tseitin}.
\
lemma plaisted_le_tseitin_num_clauses:
"length (plaisted p \) \ length (tseitin \)"
sorry
lemma plaisted_le_tseitin_num_literals:
"num_literals (plaisted p \) \ num_literals (tseitin \)"
sorry
end