| author | wenzelm | 
| Sat, 13 Aug 2022 14:45:36 +0200 | |
| changeset 75841 | 7c00d5266bf8 | 
| parent 70486 | 1dc3514c1719 | 
| child 80637 | e2f0265f64e3 | 
| permissions | -rw-r--r-- | 
| 55239 | 1 | (* Title: HOL/Tools/cnf.ML | 
| 17618 | 2 | Author: Alwen Tiu, QSL Team, LORIA (http://qsl.loria.fr) | 
| 29265 
5b4247055bd7
moved old add_term_vars, add_term_frees etc. to structure OldTerm;
 wenzelm parents: 
26341diff
changeset | 3 | Author: Tjark Weber, TU Muenchen | 
| 17618 | 4 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 5 | FIXME: major overlaps with the code in meson.ML | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 6 | |
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 7 | Functions and tactics to transform a formula into Conjunctive Normal | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 8 | Form (CNF). | 
| 24958 | 9 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 10 | A formula in CNF is of the following form: | 
| 17618 | 11 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 12 | (x11 | x12 | ... | x1n) & ... & (xm1 | xm2 | ... | xmk) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 13 | False | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 14 | True | 
| 17618 | 15 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 16 | where each xij is a literal (a positive or negative atomic Boolean | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 17 | term), i.e. the formula is a conjunction of disjunctions of literals, | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 18 | or "False", or "True". | 
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 19 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 20 | A (non-empty) disjunction of literals is referred to as "clause". | 
| 17618 | 21 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 22 | For the purpose of SAT proof reconstruction, we also make use of | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 23 | another representation of clauses, which we call the "raw clauses". | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 24 | Raw clauses are of the form | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 25 | |
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 26 | [..., x1', x2', ..., xn'] |- False , | 
| 17618 | 27 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 28 | where each xi is a literal, and each xi' is the negation normal form | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 29 | of ~xi. | 
| 19236 
150e8b0fb991
clauses now use (meta-)hyps instead of (meta-)implications; significant speedup
 webertj parents: 
17809diff
changeset | 30 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 31 | Literals are successively removed from the hyps of raw clauses by | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32740diff
changeset | 32 | resolution during SAT proof reconstruction. | 
| 17618 | 33 | *) | 
| 34 | ||
| 35 | signature CNF = | |
| 36 | sig | |
| 41447 | 37 | val is_atom: term -> bool | 
| 38 | val is_literal: term -> bool | |
| 39 | val is_clause: term -> bool | |
| 40 | val clause_is_trivial: term -> bool | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 41 | |
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
58963diff
changeset | 42 | val clause2raw_thm: Proof.context -> thm -> thm | 
| 42335 | 43 | val make_nnf_thm: theory -> term -> thm | 
| 17618 | 44 | |
| 58963 
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
 wenzelm parents: 
58839diff
changeset | 45 | val weakening_tac: Proof.context -> int -> tactic (* removes the first hypothesis of a subgoal *) | 
| 17618 | 46 | |
| 42335 | 47 | val make_cnf_thm: Proof.context -> term -> thm | 
| 48 | val make_cnfx_thm: Proof.context -> term -> thm | |
| 41447 | 49 | val cnf_rewrite_tac: Proof.context -> int -> tactic (* converts all prems of a subgoal to CNF *) | 
| 50 | val cnfx_rewrite_tac: Proof.context -> int -> tactic | |
| 51 | (* converts all prems of a subgoal to (almost) definitional CNF *) | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 52 | end; | 
| 17618 | 53 | |
| 55239 | 54 | structure CNF : CNF = | 
| 17618 | 55 | struct | 
| 56 | ||
| 67149 | 57 | fun is_atom (Const (\<^const_name>\<open>False\<close>, _)) = false | 
| 58 | | is_atom (Const (\<^const_name>\<open>True\<close>, _)) = false | |
| 59 | | is_atom (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ _ $ _) = false | |
| 60 | | is_atom (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ _ $ _) = false | |
| 61 | | is_atom (Const (\<^const_name>\<open>HOL.implies\<close>, _) $ _ $ _) = false | |
| 62 |   | is_atom (Const (\<^const_name>\<open>HOL.eq\<close>, Type ("fun", \<^typ>\<open>bool\<close> :: _)) $ _ $ _) = false
 | |
| 63 | | is_atom (Const (\<^const_name>\<open>Not\<close>, _) $ _) = false | |
| 41447 | 64 | | is_atom _ = true; | 
| 17618 | 65 | |
| 67149 | 66 | fun is_literal (Const (\<^const_name>\<open>Not\<close>, _) $ x) = is_atom x | 
| 41447 | 67 | | is_literal x = is_atom x; | 
| 17618 | 68 | |
| 67149 | 69 | fun is_clause (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ x $ y) = is_clause x andalso is_clause y | 
| 41447 | 70 | | is_clause x = is_literal x; | 
| 17618 | 71 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 72 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 73 | (* clause_is_trivial: a clause is trivially true if it contains both an atom *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 74 | (* and the atom's negation *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 75 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 76 | |
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 77 | fun clause_is_trivial c = | 
| 41447 | 78 | let | 
| 67149 | 79 | fun dual (Const (\<^const_name>\<open>Not\<close>, _) $ x) = x | 
| 41447 | 80 | | dual x = HOLogic.Not $ x | 
| 81 | fun has_duals [] = false | |
| 82 | | has_duals (x::xs) = member (op =) xs (dual x) orelse has_duals xs | |
| 83 | in | |
| 84 | has_duals (HOLogic.disjuncts c) | |
| 85 | end; | |
| 17618 | 86 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 87 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 88 | (* clause2raw_thm: translates a clause into a raw clause, i.e. *) | 
| 20440 
e6fe74eebda3
faster clause representation (again): full CNF formula as a hypothesis, instead of separate clauses
 webertj parents: 
19236diff
changeset | 89 | (* [...] |- x1 | ... | xn *) | 
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 90 | (* (where each xi is a literal) is translated to *) | 
| 20440 
e6fe74eebda3
faster clause representation (again): full CNF formula as a hypothesis, instead of separate clauses
 webertj parents: 
19236diff
changeset | 91 | (* [..., x1', ..., xn'] |- False , *) | 
| 
e6fe74eebda3
faster clause representation (again): full CNF formula as a hypothesis, instead of separate clauses
 webertj parents: 
19236diff
changeset | 92 | (* where each xi' is the negation normal form of ~xi *) | 
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 93 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 94 | |
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
58963diff
changeset | 95 | fun clause2raw_thm ctxt clause = | 
| 41447 | 96 | let | 
| 97 | (* eliminates negated disjunctions from the i-th premise, possibly *) | |
| 98 | (* adding new premises, then continues with the (i+1)-th premise *) | |
| 99 | fun not_disj_to_prem i thm = | |
| 59582 | 100 | if i > Thm.nprems_of thm then | 
| 41447 | 101 | thm | 
| 102 | else | |
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
58963diff
changeset | 103 | not_disj_to_prem (i+1) | 
| 70486 | 104 |           (Seq.hd (REPEAT_DETERM (resolve_tac ctxt @{thms cnf.clause2raw_not_disj} i) thm))
 | 
| 41447 | 105 | (* moves all premises to hyps, i.e. "[...] |- A1 ==> ... ==> An ==> B" *) | 
| 106 | (* becomes "[..., A1, ..., An] |- B" *) | |
| 107 | fun prems_to_hyps thm = | |
| 108 | fold (fn cprem => fn thm' => | |
| 109 | Thm.implies_elim thm' (Thm.assume cprem)) (cprems_of thm) thm | |
| 110 | in | |
| 111 | (* [...] |- ~(x1 | ... | xn) ==> False *) | |
| 70486 | 112 |     (@{thm cnf.clause2raw_notE} OF [clause])
 | 
| 41447 | 113 | (* [...] |- ~x1 ==> ... ==> ~xn ==> False *) | 
| 114 | |> not_disj_to_prem 1 | |
| 115 | (* [...] |- x1' ==> ... ==> xn' ==> False *) | |
| 70486 | 116 |     |> Seq.hd o TRYALL (resolve_tac ctxt @{thms cnf.clause2raw_not_not})
 | 
| 41447 | 117 | (* [..., x1', ..., xn'] |- False *) | 
| 118 | |> prems_to_hyps | |
| 119 | end; | |
| 17618 | 120 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 121 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 122 | (* inst_thm: instantiates a theorem with a list of terms *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 123 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 124 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 125 | fun inst_thm thy ts thm = | 
| 60801 | 126 | Thm.instantiate' [] (map (SOME o Thm.global_cterm_of thy) ts) thm; | 
| 17618 | 127 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 128 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 129 | (* Naive CNF transformation *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 130 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 131 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 132 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 133 | (* make_nnf_thm: produces a theorem of the form t = t', where t' is the *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 134 | (* negation normal form (i.e. negation only occurs in front of atoms) *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 135 | (*      of t; implications ("-->") and equivalences ("=" on bool) are        *)
 | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 136 | (* eliminated (possibly causing an exponential blowup) *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 137 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 138 | |
| 67149 | 139 | fun make_nnf_thm thy (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ x $ y) = | 
| 41447 | 140 | let | 
| 141 | val thm1 = make_nnf_thm thy x | |
| 142 | val thm2 = make_nnf_thm thy y | |
| 143 | in | |
| 70486 | 144 |         @{thm cnf.conj_cong} OF [thm1, thm2]
 | 
| 41447 | 145 | end | 
| 67149 | 146 | | make_nnf_thm thy (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ x $ y) = | 
| 41447 | 147 | let | 
| 148 | val thm1 = make_nnf_thm thy x | |
| 149 | val thm2 = make_nnf_thm thy y | |
| 150 | in | |
| 70486 | 151 |         @{thm cnf.disj_cong} OF [thm1, thm2]
 | 
| 41447 | 152 | end | 
| 67149 | 153 | | make_nnf_thm thy (Const (\<^const_name>\<open>HOL.implies\<close>, _) $ x $ y) = | 
| 41447 | 154 | let | 
| 155 | val thm1 = make_nnf_thm thy (HOLogic.Not $ x) | |
| 156 | val thm2 = make_nnf_thm thy y | |
| 157 | in | |
| 70486 | 158 |         @{thm cnf.make_nnf_imp} OF [thm1, thm2]
 | 
| 41447 | 159 | end | 
| 67149 | 160 |   | make_nnf_thm thy (Const (\<^const_name>\<open>HOL.eq\<close>, Type ("fun", \<^typ>\<open>bool\<close> :: _)) $ x $ y) =
 | 
| 41447 | 161 | let | 
| 162 | val thm1 = make_nnf_thm thy x | |
| 163 | val thm2 = make_nnf_thm thy (HOLogic.Not $ x) | |
| 164 | val thm3 = make_nnf_thm thy y | |
| 165 | val thm4 = make_nnf_thm thy (HOLogic.Not $ y) | |
| 166 | in | |
| 70486 | 167 |         @{thm cnf.make_nnf_iff} OF [thm1, thm2, thm3, thm4]
 | 
| 41447 | 168 | end | 
| 67149 | 169 | | make_nnf_thm _ (Const (\<^const_name>\<open>Not\<close>, _) $ Const (\<^const_name>\<open>False\<close>, _)) = | 
| 70486 | 170 |       @{thm cnf.make_nnf_not_false}
 | 
| 67149 | 171 | | make_nnf_thm _ (Const (\<^const_name>\<open>Not\<close>, _) $ Const (\<^const_name>\<open>True\<close>, _)) = | 
| 70486 | 172 |       @{thm cnf.make_nnf_not_true}
 | 
| 67149 | 173 | | make_nnf_thm thy (Const (\<^const_name>\<open>Not\<close>, _) $ (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ x $ y)) = | 
| 41447 | 174 | let | 
| 175 | val thm1 = make_nnf_thm thy (HOLogic.Not $ x) | |
| 176 | val thm2 = make_nnf_thm thy (HOLogic.Not $ y) | |
| 177 | in | |
| 70486 | 178 |         @{thm cnf.make_nnf_not_conj} OF [thm1, thm2]
 | 
| 41447 | 179 | end | 
| 67149 | 180 | | make_nnf_thm thy (Const (\<^const_name>\<open>Not\<close>, _) $ (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ x $ y)) = | 
| 41447 | 181 | let | 
| 182 | val thm1 = make_nnf_thm thy (HOLogic.Not $ x) | |
| 183 | val thm2 = make_nnf_thm thy (HOLogic.Not $ y) | |
| 184 | in | |
| 70486 | 185 |         @{thm cnf.make_nnf_not_disj} OF [thm1, thm2]
 | 
| 41447 | 186 | end | 
| 187 | | make_nnf_thm thy | |
| 67149 | 188 | (Const (\<^const_name>\<open>Not\<close>, _) $ (Const (\<^const_name>\<open>HOL.implies\<close>, _) $ x $ y)) = | 
| 41447 | 189 | let | 
| 190 | val thm1 = make_nnf_thm thy x | |
| 191 | val thm2 = make_nnf_thm thy (HOLogic.Not $ y) | |
| 192 | in | |
| 70486 | 193 |         @{thm cnf.make_nnf_not_imp} OF [thm1, thm2]
 | 
| 41447 | 194 | end | 
| 195 | | make_nnf_thm thy | |
| 67149 | 196 | (Const (\<^const_name>\<open>Not\<close>, _) $ | 
| 197 |         (Const (\<^const_name>\<open>HOL.eq\<close>, Type ("fun", \<^typ>\<open>bool\<close> :: _)) $ x $ y)) =
 | |
| 41447 | 198 | let | 
| 199 | val thm1 = make_nnf_thm thy x | |
| 200 | val thm2 = make_nnf_thm thy (HOLogic.Not $ x) | |
| 201 | val thm3 = make_nnf_thm thy y | |
| 202 | val thm4 = make_nnf_thm thy (HOLogic.Not $ y) | |
| 203 | in | |
| 70486 | 204 |         @{thm cnf.make_nnf_not_iff} OF [thm1, thm2, thm3, thm4]
 | 
| 41447 | 205 | end | 
| 67149 | 206 | | make_nnf_thm thy (Const (\<^const_name>\<open>Not\<close>, _) $ (Const (\<^const_name>\<open>Not\<close>, _) $ x)) = | 
| 41447 | 207 | let | 
| 208 | val thm1 = make_nnf_thm thy x | |
| 209 | in | |
| 70486 | 210 |         @{thm cnf.make_nnf_not_not} OF [thm1]
 | 
| 41447 | 211 | end | 
| 70486 | 212 |   | make_nnf_thm thy t = inst_thm thy [t] @{thm cnf.iff_refl};
 | 
| 17618 | 213 | |
| 42335 | 214 | fun make_under_quantifiers ctxt make t = | 
| 215 | let | |
| 216 | fun conv ctxt ct = | |
| 59582 | 217 | (case Thm.term_of ct of | 
| 45511 
9b0f8ca4388e
continued implementation of lambda-lifting in Metis
 blanchet parents: 
44121diff
changeset | 218 | Const _ $ Abs _ => Conv.comb_conv (conv ctxt) ct | 
| 42335 | 219 | | Abs _ => Conv.abs_conv (conv o snd) ctxt ct | 
| 220 | | Const _ => Conv.all_conv ct | |
| 67710 
cc2db3239932
added HOLogic.mk_obj_eq convenience and eliminated some clones;
 wenzelm parents: 
67149diff
changeset | 221 |       | t => make t RS @{thm eq_reflection})
 | 
| 
cc2db3239932
added HOLogic.mk_obj_eq convenience and eliminated some clones;
 wenzelm parents: 
67149diff
changeset | 222 | in HOLogic.mk_obj_eq (conv ctxt (Thm.cterm_of ctxt t)) end | 
| 42335 | 223 | |
| 224 | fun make_nnf_thm_under_quantifiers ctxt = | |
| 42361 | 225 | make_under_quantifiers ctxt (make_nnf_thm (Proof_Context.theory_of ctxt)) | 
| 42335 | 226 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 227 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 228 | (* simp_True_False_thm: produces a theorem t = t', where t' is equivalent to *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 229 | (* t, but simplified wrt. the following theorems: *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 230 | (* (True & x) = x *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 231 | (* (x & True) = x *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 232 | (* (False & x) = False *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 233 | (* (x & False) = False *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 234 | (* (True | x) = True *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 235 | (* (x | True) = True *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 236 | (* (False | x) = x *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 237 | (* (x | False) = x *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 238 | (* No simplification is performed below connectives other than & and |. *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 239 | (* Optimization: The right-hand side of a conjunction (disjunction) is *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 240 | (* simplified only if the left-hand side does not simplify to False *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 241 | (* (True, respectively). *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 242 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 243 | |
| 67149 | 244 | fun simp_True_False_thm thy (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ x $ y) = | 
| 41447 | 245 | let | 
| 246 | val thm1 = simp_True_False_thm thy x | |
| 59582 | 247 | val x'= (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) thm1 | 
| 41447 | 248 | in | 
| 67149 | 249 | if x' = \<^term>\<open>False\<close> then | 
| 70486 | 250 |           @{thm cnf.simp_TF_conj_False_l} OF [thm1]  (* (x & y) = False *)
 | 
| 41447 | 251 | else | 
| 252 | let | |
| 253 | val thm2 = simp_True_False_thm thy y | |
| 59582 | 254 | val y' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) thm2 | 
| 41447 | 255 | in | 
| 67149 | 256 | if x' = \<^term>\<open>True\<close> then | 
| 70486 | 257 |               @{thm cnf.simp_TF_conj_True_l} OF [thm1, thm2]  (* (x & y) = y' *)
 | 
| 67149 | 258 | else if y' = \<^term>\<open>False\<close> then | 
| 70486 | 259 |               @{thm cnf.simp_TF_conj_False_r} OF [thm2]  (* (x & y) = False *)
 | 
| 67149 | 260 | else if y' = \<^term>\<open>True\<close> then | 
| 70486 | 261 |               @{thm cnf.simp_TF_conj_True_r} OF [thm1, thm2]  (* (x & y) = x' *)
 | 
| 41447 | 262 | else | 
| 70486 | 263 |               @{thm cnf.conj_cong} OF [thm1, thm2]  (* (x & y) = (x' & y') *)
 | 
| 41447 | 264 | end | 
| 265 | end | |
| 67149 | 266 | | simp_True_False_thm thy (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ x $ y) = | 
| 41447 | 267 | let | 
| 268 | val thm1 = simp_True_False_thm thy x | |
| 59582 | 269 | val x' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) thm1 | 
| 41447 | 270 | in | 
| 67149 | 271 | if x' = \<^term>\<open>True\<close> then | 
| 70486 | 272 |           @{thm cnf.simp_TF_disj_True_l} OF [thm1]  (* (x | y) = True *)
 | 
| 41447 | 273 | else | 
| 274 | let | |
| 275 | val thm2 = simp_True_False_thm thy y | |
| 59582 | 276 | val y' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) thm2 | 
| 41447 | 277 | in | 
| 67149 | 278 | if x' = \<^term>\<open>False\<close> then | 
| 70486 | 279 |               @{thm cnf.simp_TF_disj_False_l} OF [thm1, thm2]  (* (x | y) = y' *)
 | 
| 67149 | 280 | else if y' = \<^term>\<open>True\<close> then | 
| 70486 | 281 |               @{thm cnf.simp_TF_disj_True_r} OF [thm2]  (* (x | y) = True *)
 | 
| 67149 | 282 | else if y' = \<^term>\<open>False\<close> then | 
| 70486 | 283 |               @{thm cnf.simp_TF_disj_False_r} OF [thm1, thm2]  (* (x | y) = x' *)
 | 
| 41447 | 284 | else | 
| 70486 | 285 |               @{thm cnf.disj_cong} OF [thm1, thm2]  (* (x | y) = (x' | y') *)
 | 
| 41447 | 286 | end | 
| 287 | end | |
| 70486 | 288 |   | simp_True_False_thm thy t = inst_thm thy [t] @{thm cnf.iff_refl};  (* t = t *)
 | 
| 17618 | 289 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 290 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 291 | (* make_cnf_thm: given any HOL term 't', produces a theorem t = t', where t' *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 292 | (* is in conjunction normal form. May cause an exponential blowup *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 293 | (* in the length of the term. *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 294 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 295 | |
| 42335 | 296 | fun make_cnf_thm ctxt t = | 
| 41447 | 297 | let | 
| 42361 | 298 | val thy = Proof_Context.theory_of ctxt | 
| 67149 | 299 | fun make_cnf_thm_from_nnf (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ x $ y) = | 
| 41447 | 300 | let | 
| 301 | val thm1 = make_cnf_thm_from_nnf x | |
| 302 | val thm2 = make_cnf_thm_from_nnf y | |
| 303 | in | |
| 70486 | 304 |             @{thm cnf.conj_cong} OF [thm1, thm2]
 | 
| 41447 | 305 | end | 
| 67149 | 306 | | make_cnf_thm_from_nnf (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ x $ y) = | 
| 41447 | 307 | let | 
| 308 | (* produces a theorem "(x' | y') = t'", where x', y', and t' are in CNF *) | |
| 67149 | 309 | fun make_cnf_disj_thm (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ x1 $ x2) y' = | 
| 41447 | 310 | let | 
| 311 | val thm1 = make_cnf_disj_thm x1 y' | |
| 312 | val thm2 = make_cnf_disj_thm x2 y' | |
| 313 | in | |
| 70486 | 314 |                     @{thm cnf.make_cnf_disj_conj_l} OF [thm1, thm2]  (* ((x1 & x2) | y') = ((x1 | y')' & (x2 | y')') *)
 | 
| 41447 | 315 | end | 
| 67149 | 316 | | make_cnf_disj_thm x' (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ y1 $ y2) = | 
| 41447 | 317 | let | 
| 318 | val thm1 = make_cnf_disj_thm x' y1 | |
| 319 | val thm2 = make_cnf_disj_thm x' y2 | |
| 320 | in | |
| 70486 | 321 |                     @{thm cnf.make_cnf_disj_conj_r} OF [thm1, thm2]  (* (x' | (y1 & y2)) = ((x' | y1)' & (x' | y2)') *)
 | 
| 41447 | 322 | end | 
| 323 | | make_cnf_disj_thm x' y' = | |
| 70486 | 324 |                   inst_thm thy [HOLogic.mk_disj (x', y')] @{thm cnf.iff_refl}  (* (x' | y') = (x' | y') *)
 | 
| 41447 | 325 | val thm1 = make_cnf_thm_from_nnf x | 
| 326 | val thm2 = make_cnf_thm_from_nnf y | |
| 59582 | 327 | val x' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) thm1 | 
| 328 | val y' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) thm2 | |
| 70486 | 329 |             val disj_thm = @{thm cnf.disj_cong} OF [thm1, thm2]  (* (x | y) = (x' | y') *)
 | 
| 41447 | 330 | in | 
| 70486 | 331 |             @{thm cnf.iff_trans} OF [disj_thm, make_cnf_disj_thm x' y']
 | 
| 41447 | 332 | end | 
| 70486 | 333 |       | make_cnf_thm_from_nnf t = inst_thm thy [t] @{thm cnf.iff_refl}
 | 
| 41447 | 334 | (* convert 't' to NNF first *) | 
| 42335 | 335 | val nnf_thm = make_nnf_thm_under_quantifiers ctxt t | 
| 336 | (*### | |
| 41447 | 337 | val nnf_thm = make_nnf_thm thy t | 
| 42335 | 338 | *) | 
| 59582 | 339 | val nnf = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) nnf_thm | 
| 41447 | 340 | (* then simplify wrt. True/False (this should preserve NNF) *) | 
| 341 | val simp_thm = simp_True_False_thm thy nnf | |
| 59582 | 342 | val simp = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) simp_thm | 
| 41447 | 343 | (* finally, convert to CNF (this should preserve the simplification) *) | 
| 42335 | 344 | val cnf_thm = make_under_quantifiers ctxt make_cnf_thm_from_nnf simp | 
| 345 | (* ### | |
| 41447 | 346 | val cnf_thm = make_cnf_thm_from_nnf simp | 
| 42335 | 347 | *) | 
| 41447 | 348 | in | 
| 70486 | 349 |     @{thm cnf.iff_trans} OF [@{thm cnf.iff_trans} OF [nnf_thm, simp_thm], cnf_thm]
 | 
| 41447 | 350 | end; | 
| 17618 | 351 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 352 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 353 | (* CNF transformation by introducing new literals *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 354 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 355 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 356 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 357 | (* make_cnfx_thm: given any HOL term 't', produces a theorem t = t', where *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 358 | (* t' is almost in conjunction normal form, except that conjunctions *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 359 | (* and existential quantifiers may be nested. (Use e.g. 'REPEAT_DETERM *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 360 | (* (etac exE i ORELSE etac conjE i)' afterwards to normalize.) May *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 361 | (* introduce new (existentially bound) literals. Note: the current *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 362 | (* implementation calls 'make_nnf_thm', causing an exponential blowup *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 363 | (* in the case of nested equivalences. *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 364 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 365 | |
| 42335 | 366 | fun make_cnfx_thm ctxt t = | 
| 41447 | 367 | let | 
| 42361 | 368 | val thy = Proof_Context.theory_of ctxt | 
| 41447 | 369 | val var_id = Unsynchronized.ref 0 (* properly initialized below *) | 
| 370 | fun new_free () = | |
| 371 |       Free ("cnfx_" ^ string_of_int (Unsynchronized.inc var_id), HOLogic.boolT)
 | |
| 67149 | 372 | fun make_cnfx_thm_from_nnf (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ x $ y) : thm = | 
| 41447 | 373 | let | 
| 374 | val thm1 = make_cnfx_thm_from_nnf x | |
| 375 | val thm2 = make_cnfx_thm_from_nnf y | |
| 376 | in | |
| 70486 | 377 |             @{thm cnf.conj_cong} OF [thm1, thm2]
 | 
| 41447 | 378 | end | 
| 67149 | 379 | | make_cnfx_thm_from_nnf (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ x $ y) = | 
| 41447 | 380 | if is_clause x andalso is_clause y then | 
| 70486 | 381 |             inst_thm thy [HOLogic.mk_disj (x, y)] @{thm cnf.iff_refl}
 | 
| 41447 | 382 | else if is_literal y orelse is_literal x then | 
| 383 | let | |
| 384 | (* produces a theorem "(x' | y') = t'", where x', y', and t' are *) | |
| 385 | (* almost in CNF, and x' or y' is a literal *) | |
| 67149 | 386 | fun make_cnfx_disj_thm (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ x1 $ x2) y' = | 
| 41447 | 387 | let | 
| 388 | val thm1 = make_cnfx_disj_thm x1 y' | |
| 389 | val thm2 = make_cnfx_disj_thm x2 y' | |
| 390 | in | |
| 70486 | 391 |                       @{thm cnf.make_cnf_disj_conj_l} OF [thm1, thm2]  (* ((x1 & x2) | y') = ((x1 | y')' & (x2 | y')') *)
 | 
| 41447 | 392 | end | 
| 67149 | 393 | | make_cnfx_disj_thm x' (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ y1 $ y2) = | 
| 41447 | 394 | let | 
| 395 | val thm1 = make_cnfx_disj_thm x' y1 | |
| 396 | val thm2 = make_cnfx_disj_thm x' y2 | |
| 397 | in | |
| 70486 | 398 |                       @{thm cnf.make_cnf_disj_conj_r} OF [thm1, thm2]  (* (x' | (y1 & y2)) = ((x' | y1)' & (x' | y2)') *)
 | 
| 41447 | 399 | end | 
| 67149 | 400 | | make_cnfx_disj_thm (\<^term>\<open>Ex :: (bool \<Rightarrow> bool) \<Rightarrow> bool\<close> $ x') y' = | 
| 41447 | 401 | let | 
| 70486 | 402 |                       val thm1 = inst_thm thy [x', y'] @{thm cnf.make_cnfx_disj_ex_l}   (* ((Ex x') | y') = (Ex (x' | y')) *)
 | 
| 41447 | 403 | val var = new_free () | 
| 404 | val thm2 = make_cnfx_disj_thm (betapply (x', var)) y' (* (x' | y') = body' *) | |
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59582diff
changeset | 405 | val thm3 = Thm.forall_intr (Thm.global_cterm_of thy var) thm2 (* !!v. (x' | y') = body' *) | 
| 41447 | 406 | val thm4 = Thm.strip_shyps (thm3 COMP allI) (* ALL v. (x' | y') = body' *) | 
| 70486 | 407 |                       val thm5 = Thm.strip_shyps (thm4 RS @{thm cnf.make_cnfx_ex_cong}) (* (EX v. (x' | y')) = (EX v. body') *)
 | 
| 41447 | 408 | in | 
| 70486 | 409 |                       @{thm cnf.iff_trans} OF [thm1, thm5]  (* ((Ex x') | y') = (Ex v. body') *)
 | 
| 41447 | 410 | end | 
| 67149 | 411 | | make_cnfx_disj_thm x' (\<^term>\<open>Ex :: (bool \<Rightarrow> bool) \<Rightarrow> bool\<close> $ y') = | 
| 41447 | 412 | let | 
| 70486 | 413 |                       val thm1 = inst_thm thy [x', y'] @{thm cnf.make_cnfx_disj_ex_r}   (* (x' | (Ex y')) = (Ex (x' | y')) *)
 | 
| 41447 | 414 | val var = new_free () | 
| 415 | val thm2 = make_cnfx_disj_thm x' (betapply (y', var)) (* (x' | y') = body' *) | |
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59582diff
changeset | 416 | val thm3 = Thm.forall_intr (Thm.global_cterm_of thy var) thm2 (* !!v. (x' | y') = body' *) | 
| 41447 | 417 | val thm4 = Thm.strip_shyps (thm3 COMP allI) (* ALL v. (x' | y') = body' *) | 
| 70486 | 418 |                       val thm5 = Thm.strip_shyps (thm4 RS @{thm cnf.make_cnfx_ex_cong}) (* (EX v. (x' | y')) = (EX v. body') *)
 | 
| 41447 | 419 | in | 
| 70486 | 420 |                       @{thm cnf.iff_trans} OF [thm1, thm5]  (* (x' | (Ex y')) = (EX v. body') *)
 | 
| 41447 | 421 | end | 
| 422 | | make_cnfx_disj_thm x' y' = | |
| 70486 | 423 |                     inst_thm thy [HOLogic.mk_disj (x', y')] @{thm cnf.iff_refl}  (* (x' | y') = (x' | y') *)
 | 
| 41447 | 424 | val thm1 = make_cnfx_thm_from_nnf x | 
| 425 | val thm2 = make_cnfx_thm_from_nnf y | |
| 59582 | 426 | val x' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) thm1 | 
| 427 | val y' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) thm2 | |
| 70486 | 428 |               val disj_thm = @{thm cnf.disj_cong} OF [thm1, thm2]  (* (x | y) = (x' | y') *)
 | 
| 41447 | 429 | in | 
| 70486 | 430 |               @{thm cnf.iff_trans} OF [disj_thm, make_cnfx_disj_thm x' y']
 | 
| 41447 | 431 | end | 
| 432 | else | |
| 433 | let (* neither 'x' nor 'y' is a literal: introduce a fresh variable *) | |
| 70486 | 434 |               val thm1 = inst_thm thy [x, y] @{thm cnf.make_cnfx_newlit}     (* (x | y) = EX v. (x | v) & (y | ~v) *)
 | 
| 41447 | 435 | val var = new_free () | 
| 436 | val body = HOLogic.mk_conj (HOLogic.mk_disj (x, var), HOLogic.mk_disj (y, HOLogic.Not $ var)) | |
| 437 | val thm2 = make_cnfx_thm_from_nnf body (* (x | v) & (y | ~v) = body' *) | |
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59582diff
changeset | 438 | val thm3 = Thm.forall_intr (Thm.global_cterm_of thy var) thm2 (* !!v. (x | v) & (y | ~v) = body' *) | 
| 41447 | 439 | val thm4 = Thm.strip_shyps (thm3 COMP allI) (* ALL v. (x | v) & (y | ~v) = body' *) | 
| 70486 | 440 |               val thm5 = Thm.strip_shyps (thm4 RS @{thm cnf.make_cnfx_ex_cong})  (* (EX v. (x | v) & (y | ~v)) = (EX v. body') *)
 | 
| 41447 | 441 | in | 
| 70486 | 442 |               @{thm cnf.iff_trans} OF [thm1, thm5]
 | 
| 41447 | 443 | end | 
| 70486 | 444 |       | make_cnfx_thm_from_nnf t = inst_thm thy [t] @{thm cnf.iff_refl}
 | 
| 41447 | 445 | (* convert 't' to NNF first *) | 
| 42335 | 446 | val nnf_thm = make_nnf_thm_under_quantifiers ctxt t | 
| 447 | (* ### | |
| 41447 | 448 | val nnf_thm = make_nnf_thm thy t | 
| 42335 | 449 | *) | 
| 59582 | 450 | val nnf = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) nnf_thm | 
| 41447 | 451 | (* then simplify wrt. True/False (this should preserve NNF) *) | 
| 452 | val simp_thm = simp_True_False_thm thy nnf | |
| 59582 | 453 | val simp = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) simp_thm | 
| 41447 | 454 | (* initialize var_id, in case the term already contains variables of the form "cnfx_<int>" *) | 
| 455 | val _ = (var_id := fold (fn free => fn max => | |
| 456 | let | |
| 457 | val (name, _) = dest_Free free | |
| 458 | val idx = | |
| 459 | if String.isPrefix "cnfx_" name then | |
| 460 | (Int.fromString o String.extract) (name, String.size "cnfx_", NONE) | |
| 461 | else | |
| 462 | NONE | |
| 463 | in | |
| 464 | Int.max (max, the_default 0 idx) | |
| 44121 | 465 | end) (Misc_Legacy.term_frees simp) 0) | 
| 41447 | 466 | (* finally, convert to definitional CNF (this should preserve the simplification) *) | 
| 42335 | 467 | val cnfx_thm = make_under_quantifiers ctxt make_cnfx_thm_from_nnf simp | 
| 468 | (*### | |
| 41447 | 469 | val cnfx_thm = make_cnfx_thm_from_nnf simp | 
| 42335 | 470 | *) | 
| 41447 | 471 | in | 
| 70486 | 472 |     @{thm cnf.iff_trans} OF [@{thm cnf.iff_trans} OF [nnf_thm, simp_thm], cnfx_thm]
 | 
| 41447 | 473 | end; | 
| 17618 | 474 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 475 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 476 | (* Tactics *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 477 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 478 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 479 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 480 | (* weakening_tac: removes the first hypothesis of the 'i'-th subgoal *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 481 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 482 | |
| 58963 
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
 wenzelm parents: 
58839diff
changeset | 483 | fun weakening_tac ctxt i = | 
| 70486 | 484 |   dresolve_tac ctxt @{thms cnf.weakening_thm} i THEN assume_tac ctxt (i+1);
 | 
| 17618 | 485 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 486 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 487 | (* cnf_rewrite_tac: converts all premises of the 'i'-th subgoal to CNF *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 488 | (* (possibly causing an exponential blowup in the length of each *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 489 | (* premise) *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 490 | (* ------------------------------------------------------------------------- *) | 
| 17618 | 491 | |
| 32232 | 492 | fun cnf_rewrite_tac ctxt i = | 
| 41447 | 493 | (* cut the CNF formulas as new premises *) | 
| 60696 | 494 |   Subgoal.FOCUS (fn {prems, context = ctxt', ...} =>
 | 
| 41447 | 495 | let | 
| 60696 | 496 | val cnf_thms = map (make_cnf_thm ctxt' o HOLogic.dest_Trueprop o Thm.prop_of) prems | 
| 70486 | 497 |       val cut_thms = map (fn (th, pr) => @{thm cnf.cnftac_eq_imp} OF [th, pr]) (cnf_thms ~~ prems)
 | 
| 41447 | 498 | in | 
| 499 | cut_facts_tac cut_thms 1 | |
| 500 | end) ctxt i | |
| 501 | (* remove the original premises *) | |
| 502 | THEN SELECT_GOAL (fn thm => | |
| 503 | let | |
| 59582 | 504 | val n = Logic.count_prems ((Term.strip_all_body o fst o Logic.dest_implies o Thm.prop_of) thm) | 
| 41447 | 505 | in | 
| 58963 
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
 wenzelm parents: 
58839diff
changeset | 506 | PRIMITIVE (funpow (n div 2) (Seq.hd o weakening_tac ctxt 1)) thm | 
| 41447 | 507 | end) i; | 
| 17618 | 508 | |
| 17809 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 509 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 510 | (* cnfx_rewrite_tac: converts all premises of the 'i'-th subgoal to CNF *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 511 | (* (possibly introducing new literals) *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 512 | (* ------------------------------------------------------------------------- *) | 
| 
195045659c06
Tactics sat and satx reimplemented, several improvements
 webertj parents: 
17618diff
changeset | 513 | |
| 32232 | 514 | fun cnfx_rewrite_tac ctxt i = | 
| 41447 | 515 | (* cut the CNF formulas as new premises *) | 
| 60696 | 516 |   Subgoal.FOCUS (fn {prems, context = ctxt', ...} =>
 | 
| 41447 | 517 | let | 
| 60696 | 518 | val cnfx_thms = map (make_cnfx_thm ctxt' o HOLogic.dest_Trueprop o Thm.prop_of) prems | 
| 70486 | 519 |       val cut_thms = map (fn (th, pr) => @{thm cnf.cnftac_eq_imp} OF [th, pr]) (cnfx_thms ~~ prems)
 | 
| 41447 | 520 | in | 
| 521 | cut_facts_tac cut_thms 1 | |
| 522 | end) ctxt i | |
| 523 | (* remove the original premises *) | |
| 524 | THEN SELECT_GOAL (fn thm => | |
| 525 | let | |
| 59582 | 526 | val n = Logic.count_prems ((Term.strip_all_body o fst o Logic.dest_implies o Thm.prop_of) thm) | 
| 41447 | 527 | in | 
| 58963 
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
 wenzelm parents: 
58839diff
changeset | 528 | PRIMITIVE (funpow (n div 2) (Seq.hd o weakening_tac ctxt 1)) thm | 
| 41447 | 529 | end) i; | 
| 17618 | 530 | |
| 41447 | 531 | end; |