| author | wenzelm | 
| Thu, 16 Jun 2005 20:30:37 +0200 | |
| changeset 16414 | cad2cf55c851 | 
| parent 16389 | 48832eba5b1e | 
| child 17485 | c39871c52977 | 
| permissions | -rw-r--r-- | 
| 13876 | 1 | (* Title: HOL/Integ/cooper_proof.ML | 
| 2 | ID: $Id$ | |
| 3 | Author: Amine Chaieb and Tobias Nipkow, TU Muenchen | |
| 4 | ||
| 5 | File containing the implementation of the proof | |
| 6 | generation for Cooper Algorithm | |
| 7 | *) | |
| 8 | ||
| 14920 
a7525235e20f
An oracle is built in. The tactic will not generate any proofs any more, if the quick_and_dirty flag is set on.
 chaieb parents: 
14877diff
changeset | 9 | |
| 13876 | 10 | signature COOPER_PROOF = | 
| 11 | sig | |
| 12 | val qe_Not : thm | |
| 13 | val qe_conjI : thm | |
| 14 | val qe_disjI : thm | |
| 15 | val qe_impI : thm | |
| 16 | val qe_eqI : thm | |
| 17 | val qe_exI : thm | |
| 14877 | 18 | val list_to_set : typ -> term list -> term | 
| 13876 | 19 | val qe_get_terms : thm -> term * term | 
| 15122 | 20 | val cooper_prv : Sign.sg -> term -> term -> thm | 
| 13876 | 21 | val proof_of_evalc : Sign.sg -> term -> thm | 
| 22 | val proof_of_cnnf : Sign.sg -> term -> (term -> thm) -> thm | |
| 23 | val proof_of_linform : Sign.sg -> string list -> term -> thm | |
| 16389 | 24 | val proof_of_adjustcoeffeq : Sign.sg -> term -> IntInf.int -> term -> thm | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 25 | val prove_elementar : Sign.sg -> string -> term -> thm | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 26 | val thm_of : Sign.sg -> (term -> (term list * (thm list -> thm))) -> term -> thm | 
| 13876 | 27 | end; | 
| 28 | ||
| 29 | structure CooperProof : COOPER_PROOF = | |
| 30 | struct | |
| 31 | open CooperDec; | |
| 32 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 33 | (* | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 34 | val presburger_ss = simpset_of (theory "Presburger") | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 35 | addsimps [zdiff_def] delsimps [symmetric zdiff_def]; | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 36 | *) | 
| 13876 | 37 | |
| 38 | val presburger_ss = simpset_of (theory "Presburger") | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 39 | addsimps[diff_int_def] delsimps [thm"diff_int_def_symmetric"]; | 
| 13876 | 40 | val cboolT = ctyp_of (sign_of HOL.thy) HOLogic.boolT; | 
| 41 | ||
| 42 | (*Theorems that will be used later for the proofgeneration*) | |
| 43 | ||
| 44 | val zdvd_iff_zmod_eq_0 = thm "zdvd_iff_zmod_eq_0"; | |
| 45 | val unity_coeff_ex = thm "unity_coeff_ex"; | |
| 46 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 47 | (* Thorems for proving the adjustment of the coeffitients*) | 
| 13876 | 48 | |
| 49 | val ac_lt_eq = thm "ac_lt_eq"; | |
| 50 | val ac_eq_eq = thm "ac_eq_eq"; | |
| 51 | val ac_dvd_eq = thm "ac_dvd_eq"; | |
| 52 | val ac_pi_eq = thm "ac_pi_eq"; | |
| 53 | ||
| 54 | (* The logical compination of the sythetised properties*) | |
| 55 | val qe_Not = thm "qe_Not"; | |
| 56 | val qe_conjI = thm "qe_conjI"; | |
| 57 | val qe_disjI = thm "qe_disjI"; | |
| 58 | val qe_impI = thm "qe_impI"; | |
| 59 | val qe_eqI = thm "qe_eqI"; | |
| 60 | val qe_exI = thm "qe_exI"; | |
| 61 | val qe_ALLI = thm "qe_ALLI"; | |
| 62 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 63 | (*Modulo D property for Pminusinf an Plusinf *) | 
| 13876 | 64 | val fm_modd_minf = thm "fm_modd_minf"; | 
| 65 | val not_dvd_modd_minf = thm "not_dvd_modd_minf"; | |
| 66 | val dvd_modd_minf = thm "dvd_modd_minf"; | |
| 67 | ||
| 68 | val fm_modd_pinf = thm "fm_modd_pinf"; | |
| 69 | val not_dvd_modd_pinf = thm "not_dvd_modd_pinf"; | |
| 70 | val dvd_modd_pinf = thm "dvd_modd_pinf"; | |
| 71 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 72 | (* the minusinfinity proprty*) | 
| 13876 | 73 | |
| 74 | val fm_eq_minf = thm "fm_eq_minf"; | |
| 75 | val neq_eq_minf = thm "neq_eq_minf"; | |
| 76 | val eq_eq_minf = thm "eq_eq_minf"; | |
| 77 | val le_eq_minf = thm "le_eq_minf"; | |
| 78 | val len_eq_minf = thm "len_eq_minf"; | |
| 79 | val not_dvd_eq_minf = thm "not_dvd_eq_minf"; | |
| 80 | val dvd_eq_minf = thm "dvd_eq_minf"; | |
| 81 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 82 | (* the Plusinfinity proprty*) | 
| 13876 | 83 | |
| 84 | val fm_eq_pinf = thm "fm_eq_pinf"; | |
| 85 | val neq_eq_pinf = thm "neq_eq_pinf"; | |
| 86 | val eq_eq_pinf = thm "eq_eq_pinf"; | |
| 87 | val le_eq_pinf = thm "le_eq_pinf"; | |
| 88 | val len_eq_pinf = thm "len_eq_pinf"; | |
| 89 | val not_dvd_eq_pinf = thm "not_dvd_eq_pinf"; | |
| 90 | val dvd_eq_pinf = thm "dvd_eq_pinf"; | |
| 91 | ||
| 92 | (*Logical construction of the Property*) | |
| 93 | val eq_minf_conjI = thm "eq_minf_conjI"; | |
| 94 | val eq_minf_disjI = thm "eq_minf_disjI"; | |
| 95 | val modd_minf_disjI = thm "modd_minf_disjI"; | |
| 96 | val modd_minf_conjI = thm "modd_minf_conjI"; | |
| 97 | ||
| 98 | val eq_pinf_conjI = thm "eq_pinf_conjI"; | |
| 99 | val eq_pinf_disjI = thm "eq_pinf_disjI"; | |
| 100 | val modd_pinf_disjI = thm "modd_pinf_disjI"; | |
| 101 | val modd_pinf_conjI = thm "modd_pinf_conjI"; | |
| 102 | ||
| 103 | (*Cooper Backwards...*) | |
| 104 | (*Bset*) | |
| 105 | val not_bst_p_fm = thm "not_bst_p_fm"; | |
| 106 | val not_bst_p_ne = thm "not_bst_p_ne"; | |
| 107 | val not_bst_p_eq = thm "not_bst_p_eq"; | |
| 108 | val not_bst_p_gt = thm "not_bst_p_gt"; | |
| 109 | val not_bst_p_lt = thm "not_bst_p_lt"; | |
| 110 | val not_bst_p_ndvd = thm "not_bst_p_ndvd"; | |
| 111 | val not_bst_p_dvd = thm "not_bst_p_dvd"; | |
| 112 | ||
| 113 | (*Aset*) | |
| 114 | val not_ast_p_fm = thm "not_ast_p_fm"; | |
| 115 | val not_ast_p_ne = thm "not_ast_p_ne"; | |
| 116 | val not_ast_p_eq = thm "not_ast_p_eq"; | |
| 117 | val not_ast_p_gt = thm "not_ast_p_gt"; | |
| 118 | val not_ast_p_lt = thm "not_ast_p_lt"; | |
| 119 | val not_ast_p_ndvd = thm "not_ast_p_ndvd"; | |
| 120 | val not_ast_p_dvd = thm "not_ast_p_dvd"; | |
| 121 | ||
| 122 | (*Logical construction of the prop*) | |
| 123 | (*Bset*) | |
| 124 | val not_bst_p_conjI = thm "not_bst_p_conjI"; | |
| 125 | val not_bst_p_disjI = thm "not_bst_p_disjI"; | |
| 126 | val not_bst_p_Q_elim = thm "not_bst_p_Q_elim"; | |
| 127 | ||
| 128 | (*Aset*) | |
| 129 | val not_ast_p_conjI = thm "not_ast_p_conjI"; | |
| 130 | val not_ast_p_disjI = thm "not_ast_p_disjI"; | |
| 131 | val not_ast_p_Q_elim = thm "not_ast_p_Q_elim"; | |
| 132 | ||
| 133 | (*Cooper*) | |
| 134 | val cppi_eq = thm "cppi_eq"; | |
| 135 | val cpmi_eq = thm "cpmi_eq"; | |
| 136 | ||
| 137 | (*Others*) | |
| 138 | val simp_from_to = thm "simp_from_to"; | |
| 139 | val P_eqtrue = thm "P_eqtrue"; | |
| 140 | val P_eqfalse = thm "P_eqfalse"; | |
| 141 | ||
| 142 | (*For Proving NNF*) | |
| 143 | ||
| 144 | val nnf_nn = thm "nnf_nn"; | |
| 145 | val nnf_im = thm "nnf_im"; | |
| 146 | val nnf_eq = thm "nnf_eq"; | |
| 147 | val nnf_sdj = thm "nnf_sdj"; | |
| 148 | val nnf_ncj = thm "nnf_ncj"; | |
| 149 | val nnf_nim = thm "nnf_nim"; | |
| 150 | val nnf_neq = thm "nnf_neq"; | |
| 151 | val nnf_ndj = thm "nnf_ndj"; | |
| 152 | ||
| 153 | (*For Proving term linearizition*) | |
| 154 | val linearize_dvd = thm "linearize_dvd"; | |
| 155 | val lf_lt = thm "lf_lt"; | |
| 156 | val lf_eq = thm "lf_eq"; | |
| 157 | val lf_dvd = thm "lf_dvd"; | |
| 158 | ||
| 159 | ||
| 160 | (* ------------------------------------------------------------------------- *) | |
| 161 | (*This function norm_zero_one replaces the occurences of Numeral1 and Numeral0*) | |
| 162 | (*Respectively by their abstract representation Const("1",..) and COnst("0",..)*)
 | |
| 163 | (*this is necessary because the theorems use this representation.*) | |
| 164 | (* This function should be elminated in next versions...*) | |
| 165 | (* ------------------------------------------------------------------------- *) | |
| 166 | ||
| 167 | fun norm_zero_one fm = case fm of | |
| 168 |   (Const ("op *",_) $ c $ t) => 
 | |
| 169 | if c = one then (norm_zero_one t) | |
| 170 | else if (dest_numeral c = ~1) | |
| 171 |          then (Const("uminus",HOLogic.intT --> HOLogic.intT) $ (norm_zero_one t))
 | |
| 172 | else (HOLogic.mk_binop "op *" (norm_zero_one c,norm_zero_one t)) | |
| 173 | |(node $ rest) => ((norm_zero_one node)$(norm_zero_one rest)) | |
| 174 | |(Abs(x,T,p)) => (Abs(x,T,(norm_zero_one p))) | |
| 175 | |_ => fm; | |
| 176 | ||
| 177 | (* ------------------------------------------------------------------------- *) | |
| 178 | (*function list to Set, constructs a set containing all elements of a given list.*) | |
| 179 | (* ------------------------------------------------------------------------- *) | |
| 180 | fun list_to_set T1 l = let val T = (HOLogic.mk_setT T1) in | |
| 181 | case l of | |
| 182 | 		[] => Const ("{}",T)
 | |
| 183 | 		|(h::t) => Const("insert", T1 --> (T --> T)) $ h $(list_to_set T1 t)
 | |
| 184 | end; | |
| 185 | ||
| 186 | (* ------------------------------------------------------------------------- *) | |
| 187 | (* Returns both sides of an equvalence in the theorem*) | |
| 188 | (* ------------------------------------------------------------------------- *) | |
| 189 | fun qe_get_terms th = let val (_$(Const("op =",Type ("fun",[Type ("bool", []),_])) $ A $ B )) = prop_of th in (A,B) end;
 | |
| 190 | ||
| 191 | (* ------------------------------------------------------------------------- *) | |
| 192 | (* Modified version of the simple version with minimal amount of checking and postprocessing*) | |
| 193 | (* ------------------------------------------------------------------------- *) | |
| 194 | ||
| 195 | fun simple_prove_goal_cterm2 G tacs = | |
| 196 | let | |
| 15531 | 197 | fun check NONE = error "prove_goal: tactic failed" | 
| 198 | | check (SOME (thm, _)) = (case nprems_of thm of | |
| 13876 | 199 | 0 => thm | 
| 200 | | i => !result_error_fn thm (string_of_int i ^ " unsolved goals!")) | |
| 201 | in check (Seq.pull (EVERY tacs (trivial G))) end; | |
| 202 | ||
| 203 | (*-------------------------------------------------------------*) | |
| 204 | (*-------------------------------------------------------------*) | |
| 205 | ||
| 206 | fun cert_Trueprop sg t = cterm_of sg (HOLogic.mk_Trueprop t); | |
| 207 | ||
| 208 | (* ------------------------------------------------------------------------- *) | |
| 209 | (*This function proove elementar will be used to generate proofs at runtime*) | |
| 210 | (*It is is based on the isabelle function proove_goalw_cterm and is thought to *) | |
| 211 | (*prove properties such as a dvd b (essentially) that are only to make at | |
| 212 | runtime.*) | |
| 213 | (* ------------------------------------------------------------------------- *) | |
| 214 | fun prove_elementar sg s fm2 = case s of | |
| 215 | (*"ss" like simplification with simpset*) | |
| 216 | "ss" => | |
| 217 | let | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 218 | val ss = presburger_ss addsimps | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 219 | [zdvd_iff_zmod_eq_0,unity_coeff_ex] | 
| 13876 | 220 | val ct = cert_Trueprop sg fm2 | 
| 221 | in | |
| 15107 | 222 | simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)] | 
| 223 | ||
| 13876 | 224 | end | 
| 225 | ||
| 226 | (*"bl" like blast tactic*) | |
| 227 | (* Is only used in the harrisons like proof procedure *) | |
| 228 | | "bl" => | |
| 229 | let val ct = cert_Trueprop sg fm2 | |
| 230 | in | |
| 231 | simple_prove_goal_cterm2 ct [blast_tac HOL_cs 1] | |
| 232 | end | |
| 233 | ||
| 234 | (*"ed" like Existence disjunctions ...*) | |
| 235 | (* Is only used in the harrisons like proof procedure *) | |
| 236 | | "ed" => | |
| 237 | let | |
| 238 | val ex_disj_tacs = | |
| 239 | let | |
| 240 | val tac1 = EVERY[REPEAT(resolve_tac [disjI1,disjI2] 1), etac exI 1] | |
| 241 | val tac2 = EVERY[etac exE 1, rtac exI 1, | |
| 242 | REPEAT(resolve_tac [disjI1,disjI2] 1), assumption 1] | |
| 243 | in [rtac iffI 1, | |
| 244 | etac exE 1, REPEAT(EVERY[etac disjE 1, tac1]), tac1, | |
| 245 | REPEAT(EVERY[etac disjE 1, tac2]), tac2] | |
| 246 | end | |
| 247 | ||
| 248 | val ct = cert_Trueprop sg fm2 | |
| 249 | in | |
| 250 | simple_prove_goal_cterm2 ct ex_disj_tacs | |
| 251 | end | |
| 252 | ||
| 253 | | "fa" => | |
| 254 | let val ct = cert_Trueprop sg fm2 | |
| 15107 | 255 | in simple_prove_goal_cterm2 ct [simple_arith_tac 1] | 
| 256 | ||
| 13876 | 257 | end | 
| 258 | ||
| 259 | | "sa" => | |
| 260 | let | |
| 261 | val ss = presburger_ss addsimps zadd_ac | |
| 262 | val ct = cert_Trueprop sg fm2 | |
| 263 | in | |
| 15107 | 264 | simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)] | 
| 265 | ||
| 13876 | 266 | end | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 267 | (* like Existance Conjunction *) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 268 | | "ec" => | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 269 | let | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 270 | val ss = presburger_ss addsimps zadd_ac | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 271 | val ct = cert_Trueprop sg fm2 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 272 | in | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 273 | simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (blast_tac HOL_cs 1)] | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 274 | end | 
| 13876 | 275 | |
| 276 | | "ac" => | |
| 277 | let | |
| 278 | val ss = HOL_basic_ss addsimps zadd_ac | |
| 279 | val ct = cert_Trueprop sg fm2 | |
| 280 | in | |
| 281 | simple_prove_goal_cterm2 ct [simp_tac ss 1] | |
| 282 | end | |
| 283 | ||
| 284 | | "lf" => | |
| 285 | let | |
| 286 | val ss = presburger_ss addsimps zadd_ac | |
| 287 | val ct = cert_Trueprop sg fm2 | |
| 288 | in | |
| 15107 | 289 | simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)] | 
| 290 | ||
| 13876 | 291 | end; | 
| 292 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 293 | (*=============================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 294 | (*-------------------------------------------------------------*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 295 | (* The new compact model *) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 296 | (*-------------------------------------------------------------*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 297 | (*=============================================================*) | 
| 13876 | 298 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 299 | fun thm_of sg decomp t = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 300 | let val (ts,recomb) = decomp t | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 301 | in recomb (map (thm_of sg decomp) ts) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 302 | end; | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 303 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 304 | (*==================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 305 | (* Compact Version for adjustcoeffeq *) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 306 | (*==================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 307 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 308 | fun decomp_adjustcoeffeq sg x l fm = case fm of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 309 |     (Const("Not",_)$(Const("op <",_) $(Const("0",_)) $(rt as (Const ("op +", _)$(Const ("op *",_) $    c $ y ) $z )))) => 
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 310 | let | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 311 | val m = l div (dest_numeral c) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 312 | val n = if (x = y) then abs (m) else 1 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 313 | val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 314 | val rs = if (x = y) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 315 | then (HOLogic.mk_binrel "op <" (zero,linear_sub [] (mk_numeral n) (HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 316 | else HOLogic.mk_binrel "op <" (zero,linear_sub [] one rt ) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 317 | val ck = cterm_of sg (mk_numeral n) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 318 | val cc = cterm_of sg c | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 319 | val ct = cterm_of sg z | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 320 | val cx = cterm_of sg y | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 321 | val pre = prove_elementar sg "lf" | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 322 |             (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral n)))
 | 
| 15531 | 323 | val th1 = (pre RS (instantiate' [] [SOME ck,SOME cc, SOME cx, SOME ct] (ac_pi_eq))) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 324 | in ([], fn [] => [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 325 | end | 
| 13876 | 326 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 327 |   |(Const(p,_) $a $( Const ("op +", _)$(Const ("op *",_) $ 
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 328 | c $ y ) $t )) => | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 329 | if (is_arith_rel fm) andalso (x = y) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 330 | then | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 331 | let val m = l div (dest_numeral c) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 332 | val k = (if p = "op <" then abs(m) else m) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 333 | val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div k)*l) ), x)) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 334 | val rs = (HOLogic.mk_binrel p ((linear_cmul k a),(HOLogic.mk_binop "op +" ( xtm ,( linear_cmul k t) )))) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 335 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 336 | val ck = cterm_of sg (mk_numeral k) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 337 | val cc = cterm_of sg c | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 338 | val ct = cterm_of sg t | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 339 | val cx = cterm_of sg x | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 340 | val ca = cterm_of sg a | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 341 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 342 | in | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 343 | case p of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 344 | "op <" => | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 345 | let val pre = prove_elementar sg "lf" | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 346 | 	    (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
 | 
| 15531 | 347 | val th1 = (pre RS (instantiate' [] [SOME ck,SOME ca,SOME cc, SOME cx, SOME ct] (ac_lt_eq))) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 348 | in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 349 | end | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 350 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 351 | |"op =" => | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 352 | let val pre = prove_elementar sg "lf" | 
| 13876 | 353 | 	    (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k))))
 | 
| 15531 | 354 | val th1 = (pre RS(instantiate' [] [SOME ck,SOME ca,SOME cc, SOME cx, SOME ct] (ac_eq_eq))) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 355 | in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 356 | end | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 357 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 358 | |"Divides.op dvd" => | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 359 | let val pre = prove_elementar sg "lf" | 
| 13876 | 360 | 	   (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k))))
 | 
| 15531 | 361 | val th1 = (pre RS (instantiate' [] [SOME ck,SOME ca,SOME cc, SOME cx, SOME ct]) (ac_dvd_eq)) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 362 | in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans) | 
| 13876 | 363 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 364 | end | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 365 | end | 
| 15531 | 366 | else ([], fn [] => instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] refl) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 367 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 368 |  |( Const ("Not", _) $ p) => ([p], fn [th] => th RS qe_Not)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 369 |   |( Const ("op &",_) $ p $ q) => ([p,q], fn [th1,th2] => [th1,th2] MRS qe_conjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 370 |   |( Const ("op |",_) $ p $ q) =>([p,q], fn [th1,th2] => [th1,th2] MRS qe_disjI)
 | 
| 13876 | 371 | |
| 15531 | 372 | |_ => ([], fn [] => instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] refl); | 
| 13876 | 373 | |
| 14877 | 374 | fun proof_of_adjustcoeffeq sg x l = thm_of sg (decomp_adjustcoeffeq sg x l); | 
| 375 | ||
| 376 | ||
| 377 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 378 | (*==================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 379 | (* Finding rho for modd_minusinfinity *) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 380 | (*==================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 381 | fun rho_for_modd_minf x dlcm sg fm1 = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 382 | let | 
| 15661 
9ef583b08647
reverted renaming of Some/None in comments and strings;
 wenzelm parents: 
15531diff
changeset | 383 | (*Some certified Terms*) | 
| 13876 | 384 | |
| 385 | val ctrue = cterm_of sg HOLogic.true_const | |
| 386 | val cfalse = cterm_of sg HOLogic.false_const | |
| 387 | val fm = norm_zero_one fm1 | |
| 388 | in case fm1 of | |
| 389 |       (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
 | |
| 15531 | 390 | if (x=y) andalso (c1= zero) andalso (c2= one) then (instantiate' [SOME cboolT] [SOME ctrue] (fm_modd_minf)) | 
| 391 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf)) | |
| 13876 | 392 | |
| 393 |       |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
 | |
| 394 | if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one) | |
| 15531 | 395 | then (instantiate' [SOME cboolT] [SOME cfalse] (fm_modd_minf)) | 
| 396 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf)) | |
| 13876 | 397 | |
| 398 |       |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
 | |
| 399 | if (y=x) andalso (c1 = zero) then | |
| 15531 | 400 | if (pm1 = one) then (instantiate' [SOME cboolT] [SOME cfalse] (fm_modd_minf)) else | 
| 401 | (instantiate' [SOME cboolT] [SOME ctrue] (fm_modd_minf)) | |
| 402 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf)) | |
| 13876 | 403 | |
| 404 |       |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | |
| 405 | if y=x then let val cz = cterm_of sg (norm_zero_one z) | |
| 406 | val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero) | |
| 15531 | 407 | in(instantiate' [] [SOME cz ] ((((prove_elementar sg "ss" fm2)) RS(((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (not_dvd_modd_minf))) | 
| 13876 | 408 | end | 
| 15531 | 409 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf)) | 
| 13876 | 410 |       |(Const("Divides.op dvd",_)$ d $ (db as (Const ("op +",_) $ (Const ("op *",_) $
 | 
| 411 | c $ y ) $ z))) => | |
| 412 | if y=x then let val cz = cterm_of sg (norm_zero_one z) | |
| 413 | val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero) | |
| 15531 | 414 | in(instantiate' [] [SOME cz ] ((((prove_elementar sg "ss" fm2)) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (dvd_modd_minf))) | 
| 13876 | 415 | end | 
| 15531 | 416 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf)) | 
| 13876 | 417 | |
| 418 | ||
| 15531 | 419 | |_ => instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 420 | end; | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 421 | (*=========================================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 422 | (*=========================================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 423 | fun rho_for_eq_minf x dlcm sg fm1 = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 424 | let | 
| 13876 | 425 | val fm = norm_zero_one fm1 | 
| 426 | in case fm1 of | |
| 427 |       (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
 | |
| 428 | if (x=y) andalso (c1=zero) andalso (c2=one) | |
| 15531 | 429 | then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (neq_eq_minf)) | 
| 430 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf)) | |
| 13876 | 431 | |
| 432 |       |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
 | |
| 433 | if (is_arith_rel fm) andalso (x=y) andalso ((c1=zero) orelse (c1 = norm_zero_one zero)) andalso ((c2=one) orelse (c1 = norm_zero_one one)) | |
| 15531 | 434 | then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (eq_eq_minf)) | 
| 435 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf)) | |
| 13876 | 436 | |
| 437 |       |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
 | |
| 438 | if (y=x) andalso (c1 =zero) then | |
| 15531 | 439 | if pm1 = one then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (le_eq_minf)) else | 
| 440 | (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (len_eq_minf)) | |
| 441 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf)) | |
| 13876 | 442 |       |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | 
| 443 | if y=x then let val cd = cterm_of sg (norm_zero_one d) | |
| 444 | val cz = cterm_of sg (norm_zero_one z) | |
| 15531 | 445 | in(instantiate' [] [SOME cd, SOME cz] (not_dvd_eq_minf)) | 
| 13876 | 446 | end | 
| 447 | ||
| 15531 | 448 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf)) | 
| 13876 | 449 | |
| 450 |       |(Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | |
| 451 | if y=x then let val cd = cterm_of sg (norm_zero_one d) | |
| 452 | val cz = cterm_of sg (norm_zero_one z) | |
| 15531 | 453 | in(instantiate' [] [SOME cd, SOME cz ] (dvd_eq_minf)) | 
| 13876 | 454 | end | 
| 15531 | 455 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf)) | 
| 13876 | 456 | |
| 457 | ||
| 15531 | 458 | |_ => (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf)) | 
| 13876 | 459 | end; | 
| 460 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 461 | (*=====================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 462 | (*=====================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 463 | (*=========== minf proofs with the compact version==========*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 464 | fun decomp_minf_eq x dlcm sg t = case t of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 465 |    Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_minf_conjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 466 |    |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_minf_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 467 | |_ => ([],fn [] => rho_for_eq_minf x dlcm sg t); | 
| 13876 | 468 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 469 | fun decomp_minf_modd x dlcm sg t = case t of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 470 |    Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_minf_conjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 471 |    |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_minf_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 472 | |_ => ([],fn [] => rho_for_modd_minf x dlcm sg t); | 
| 13876 | 473 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 474 | (* -------------------------------------------------------------*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 475 | (* Finding rho for pinf_modd *) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 476 | (* -------------------------------------------------------------*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 477 | fun rho_for_modd_pinf x dlcm sg fm1 = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 478 | let | 
| 15661 
9ef583b08647
reverted renaming of Some/None in comments and strings;
 wenzelm parents: 
15531diff
changeset | 479 | (*Some certified Terms*) | 
| 13876 | 480 | |
| 481 | val ctrue = cterm_of sg HOLogic.true_const | |
| 482 | val cfalse = cterm_of sg HOLogic.false_const | |
| 483 | val fm = norm_zero_one fm1 | |
| 484 | in case fm1 of | |
| 485 |       (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
 | |
| 486 | if ((x=y) andalso (c1= zero) andalso (c2= one)) | |
| 15531 | 487 | then (instantiate' [SOME cboolT] [SOME ctrue] (fm_modd_pinf)) | 
| 488 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf)) | |
| 13876 | 489 | |
| 490 |       |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
 | |
| 491 | if ((is_arith_rel fm) andalso (x = y) andalso (c1 = zero) andalso (c2 = one)) | |
| 15531 | 492 | then (instantiate' [SOME cboolT] [SOME cfalse] (fm_modd_pinf)) | 
| 493 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf)) | |
| 13876 | 494 | |
| 495 |       |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
 | |
| 496 | if ((y=x) andalso (c1 = zero)) then | |
| 497 | if (pm1 = one) | |
| 15531 | 498 | then (instantiate' [SOME cboolT] [SOME ctrue] (fm_modd_pinf)) | 
| 499 | else (instantiate' [SOME cboolT] [SOME cfalse] (fm_modd_pinf)) | |
| 500 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf)) | |
| 13876 | 501 | |
| 502 |       |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | |
| 503 | if y=x then let val cz = cterm_of sg (norm_zero_one z) | |
| 504 | val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero) | |
| 15531 | 505 | in(instantiate' [] [SOME cz ] ((((prove_elementar sg "ss" fm2)) RS(((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (not_dvd_modd_pinf))) | 
| 13876 | 506 | end | 
| 15531 | 507 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf)) | 
| 13876 | 508 |       |(Const("Divides.op dvd",_)$ d $ (db as (Const ("op +",_) $ (Const ("op *",_) $
 | 
| 509 | c $ y ) $ z))) => | |
| 510 | if y=x then let val cz = cterm_of sg (norm_zero_one z) | |
| 511 | val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero) | |
| 15531 | 512 | in(instantiate' [] [SOME cz ] ((((prove_elementar sg "ss" fm2)) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (dvd_modd_pinf))) | 
| 13876 | 513 | end | 
| 15531 | 514 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf)) | 
| 13876 | 515 | |
| 516 | ||
| 15531 | 517 | |_ => instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 518 | end; | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 519 | (* -------------------------------------------------------------*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 520 | (* Finding rho for pinf_eq *) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 521 | (* -------------------------------------------------------------*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 522 | fun rho_for_eq_pinf x dlcm sg fm1 = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 523 | let | 
| 13876 | 524 | val fm = norm_zero_one fm1 | 
| 525 | in case fm1 of | |
| 526 |       (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
 | |
| 527 | if (x=y) andalso (c1=zero) andalso (c2=one) | |
| 15531 | 528 | then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (neq_eq_pinf)) | 
| 529 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf)) | |
| 13876 | 530 | |
| 531 |       |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
 | |
| 532 | if (is_arith_rel fm) andalso (x=y) andalso ((c1=zero) orelse (c1 = norm_zero_one zero)) andalso ((c2=one) orelse (c1 = norm_zero_one one)) | |
| 15531 | 533 | then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (eq_eq_pinf)) | 
| 534 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf)) | |
| 13876 | 535 | |
| 536 |       |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
 | |
| 537 | if (y=x) andalso (c1 =zero) then | |
| 15531 | 538 | if pm1 = one then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (le_eq_pinf)) else | 
| 539 | (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (len_eq_pinf)) | |
| 540 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf)) | |
| 13876 | 541 |       |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | 
| 542 | if y=x then let val cd = cterm_of sg (norm_zero_one d) | |
| 543 | val cz = cterm_of sg (norm_zero_one z) | |
| 15531 | 544 | in(instantiate' [] [SOME cd, SOME cz] (not_dvd_eq_pinf)) | 
| 13876 | 545 | end | 
| 546 | ||
| 15531 | 547 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf)) | 
| 13876 | 548 | |
| 549 |       |(Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | |
| 550 | if y=x then let val cd = cterm_of sg (norm_zero_one d) | |
| 551 | val cz = cterm_of sg (norm_zero_one z) | |
| 15531 | 552 | in(instantiate' [] [SOME cd, SOME cz ] (dvd_eq_pinf)) | 
| 13876 | 553 | end | 
| 15531 | 554 | else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf)) | 
| 13876 | 555 | |
| 556 | ||
| 15531 | 557 | |_ => (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf)) | 
| 13876 | 558 | end; | 
| 559 | ||
| 560 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 561 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 562 | fun minf_proof_of_c sg x dlcm t = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 563 | let val minf_eqth = thm_of sg (decomp_minf_eq x dlcm sg) t | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 564 | val minf_moddth = thm_of sg (decomp_minf_modd x dlcm sg) t | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 565 | in (minf_eqth, minf_moddth) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 566 | end; | 
| 13876 | 567 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 568 | (*=========== pinf proofs with the compact version==========*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 569 | fun decomp_pinf_eq x dlcm sg t = case t of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 570 |    Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_conjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 571 |    |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 572 | |_ =>([],fn [] => rho_for_eq_pinf x dlcm sg t) ; | 
| 13876 | 573 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 574 | fun decomp_pinf_modd x dlcm sg t = case t of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 575 |    Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_conjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 576 |    |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 577 | |_ => ([],fn [] => rho_for_modd_pinf x dlcm sg t); | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 578 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 579 | fun pinf_proof_of_c sg x dlcm t = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 580 | let val pinf_eqth = thm_of sg (decomp_pinf_eq x dlcm sg) t | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 581 | val pinf_moddth = thm_of sg (decomp_pinf_modd x dlcm sg) t | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 582 | in (pinf_eqth,pinf_moddth) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 583 | end; | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 584 | |
| 13876 | 585 | |
| 586 | (* ------------------------------------------------------------------------- *) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 587 | (* Here we generate the theorem for the Bset Property in the simple direction*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 588 | (* It is just an instantiation*) | 
| 13876 | 589 | (* ------------------------------------------------------------------------- *) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 590 | (* | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 591 | fun bsetproof_of sg (x as Free(xn,xT)) fm bs dlcm = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 592 | let | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 593 | val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm))) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 594 | val cdlcm = cterm_of sg dlcm | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 595 | val cB = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one bs)) | 
| 15531 | 596 | in instantiate' [] [SOME cdlcm,SOME cB, SOME cp] (bst_thm) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 597 | end; | 
| 13876 | 598 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 599 | fun asetproof_of sg (x as Free(xn,xT)) fm ast dlcm = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 600 | let | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 601 | val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm))) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 602 | val cdlcm = cterm_of sg dlcm | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 603 | val cA = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one ast)) | 
| 15531 | 604 | in instantiate' [] [SOME cdlcm,SOME cA, SOME cp] (ast_thm) | 
| 13876 | 605 | end; | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 606 | *) | 
| 13876 | 607 | |
| 608 | (* For the generation of atomic Theorems*) | |
| 609 | (* Prove the premisses on runtime and then make RS*) | |
| 610 | (* ------------------------------------------------------------------------- *) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 611 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 612 | (*========= this is rho ============*) | 
| 13876 | 613 | fun generate_atomic_not_bst_p sg (x as Free(xn,xT)) fm dlcm B at = | 
| 614 | let | |
| 615 | val cdlcm = cterm_of sg dlcm | |
| 616 | val cB = cterm_of sg B | |
| 617 | val cfma = cterm_of sg (absfree (xn,xT,(norm_zero_one fm))) | |
| 618 | val cat = cterm_of sg (norm_zero_one at) | |
| 619 | in | |
| 620 | case at of | |
| 621 |    (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
 | |
| 622 | if (x=y) andalso (c1=zero) andalso (c2=one) | |
| 623 | 	 then let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one (linear_cmul ~1 z)) $ B)
 | |
| 624 | 	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one  z)))
 | |
| 625 | 		  val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
 | |
| 15531 | 626 | in (instantiate' [] [SOME cfma]([th3,th1,th2] MRS (not_bst_p_ne))) | 
| 13876 | 627 | end | 
| 15531 | 628 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm)) | 
| 13876 | 629 | |
| 630 |    |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", T) $(Const ("op *",_) $ c2 $ y) $z)) =>
 | |
| 631 | if (is_arith_rel at) andalso (x=y) | |
| 632 | then let val bst_z = norm_zero_one (linear_neg (linear_add [] z (mk_numeral 1))) | |
| 633 | 	         in let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ bst_z $ B)
 | |
| 634 | 	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq (bst_z,Const("op -",T) $ (Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one z)) $ (Const("1",HOLogic.intT))))
 | |
| 635 | 		  val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
 | |
| 15531 | 636 | in (instantiate' [] [SOME cfma] ([th3,th1,th2] MRS (not_bst_p_eq))) | 
| 13876 | 637 | end | 
| 638 | end | |
| 15531 | 639 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm)) | 
| 13876 | 640 | |
| 641 |    |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
 | |
| 642 | if (y=x) andalso (c1 =zero) then | |
| 643 | if pm1 = one then | |
| 644 | 	  let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one (linear_cmul ~1 z)) $ B)
 | |
| 645 |               val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one z)))
 | |
| 15531 | 646 | in (instantiate' [] [SOME cfma, SOME cdlcm]([th1,th2] MRS (not_bst_p_gt))) | 
| 13876 | 647 | end | 
| 648 | 	 else let val th1 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
 | |
| 15531 | 649 | in (instantiate' [] [SOME cfma, SOME cB,SOME (cterm_of sg (norm_zero_one z))] (th1 RS (not_bst_p_lt))) | 
| 13876 | 650 | end | 
| 15531 | 651 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm)) | 
| 13876 | 652 | |
| 653 |    |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | |
| 654 | if y=x then | |
| 655 | let val cz = cterm_of sg (norm_zero_one z) | |
| 656 | val th1 = (prove_elementar sg "ss" (HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) | |
| 15531 | 657 | in (instantiate' [] [SOME cfma, SOME cB,SOME cz] (th1 RS (not_bst_p_ndvd))) | 
| 13876 | 658 | end | 
| 15531 | 659 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm)) | 
| 13876 | 660 | |
| 661 |    |(Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | |
| 662 | if y=x then | |
| 663 | let val cz = cterm_of sg (norm_zero_one z) | |
| 664 | val th1 = (prove_elementar sg "ss" (HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) | |
| 15531 | 665 | in (instantiate' [] [SOME cfma,SOME cB,SOME cz] (th1 RS (not_bst_p_dvd))) | 
| 13876 | 666 | end | 
| 15531 | 667 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm)) | 
| 13876 | 668 | |
| 15531 | 669 | |_ => (instantiate' [] [SOME cfma, SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm)) | 
| 13876 | 670 | |
| 671 | end; | |
| 672 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 673 | |
| 13876 | 674 | (* ------------------------------------------------------------------------- *) | 
| 675 | (* Main interpretation function for this backwards dirction*) | |
| 676 | (* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*) | |
| 677 | (*Help Function*) | |
| 678 | (* ------------------------------------------------------------------------- *) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 679 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 680 | (*==================== Proof with the compact version *) | 
| 13876 | 681 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 682 | fun decomp_nbstp sg x dlcm B fm t = case t of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 683 |    Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_bst_p_conjI )
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 684 |   |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_bst_p_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 685 | |_ => ([], fn [] => generate_atomic_not_bst_p sg x fm dlcm B t); | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 686 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 687 | fun not_bst_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm B t = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 688 | let | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 689 | val th = thm_of sg (decomp_nbstp sg x dlcm (list_to_set xT (map norm_zero_one B)) fm) t | 
| 13876 | 690 | val fma = absfree (xn,xT, norm_zero_one fm) | 
| 691 | in let val th1 = prove_elementar sg "ss" (HOLogic.mk_eq (fma,fma)) | |
| 692 | in [th,th1] MRS (not_bst_p_Q_elim) | |
| 693 | end | |
| 694 | end; | |
| 695 | ||
| 696 | ||
| 697 | (* ------------------------------------------------------------------------- *) | |
| 698 | (* Protokol interpretation function for the backwards direction for cooper's Theorem*) | |
| 699 | ||
| 700 | (* For the generation of atomic Theorems*) | |
| 701 | (* Prove the premisses on runtime and then make RS*) | |
| 702 | (* ------------------------------------------------------------------------- *) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 703 | (*========= this is rho ============*) | 
| 13876 | 704 | fun generate_atomic_not_ast_p sg (x as Free(xn,xT)) fm dlcm A at = | 
| 705 | let | |
| 706 | val cdlcm = cterm_of sg dlcm | |
| 707 | val cA = cterm_of sg A | |
| 708 | val cfma = cterm_of sg (absfree (xn,xT,(norm_zero_one fm))) | |
| 709 | val cat = cterm_of sg (norm_zero_one at) | |
| 710 | in | |
| 711 | case at of | |
| 712 |    (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
 | |
| 713 | if (x=y) andalso (c1=zero) andalso (c2=one) | |
| 714 | 	 then let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one (linear_cmul ~1 z)) $ A)
 | |
| 715 | 	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one  z)))
 | |
| 716 | 		  val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
 | |
| 15531 | 717 | in (instantiate' [] [SOME cfma]([th3,th1,th2] MRS (not_ast_p_ne))) | 
| 13876 | 718 | end | 
| 15531 | 719 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm)) | 
| 13876 | 720 | |
| 721 |    |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", T) $(Const ("op *",_) $ c2 $ y) $z)) =>
 | |
| 722 | if (is_arith_rel at) andalso (x=y) | |
| 723 | then let val ast_z = norm_zero_one (linear_sub [] one z ) | |
| 724 | 	         val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ ast_z $ A)
 | |
| 725 | 	         val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq (ast_z,Const("op +",T) $ (Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one z)) $ (Const("1",HOLogic.intT))))
 | |
| 726 | 		 val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
 | |
| 15531 | 727 | in (instantiate' [] [SOME cfma] ([th3,th1,th2] MRS (not_ast_p_eq))) | 
| 13876 | 728 | end | 
| 15531 | 729 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm)) | 
| 13876 | 730 | |
| 731 |    |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
 | |
| 732 | if (y=x) andalso (c1 =zero) then | |
| 733 | if pm1 = (mk_numeral ~1) then | |
| 734 | 	  let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one z) $ A)
 | |
| 735 | val th2 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm)) | |
| 15531 | 736 | in (instantiate' [] [SOME cfma]([th2,th1] MRS (not_ast_p_lt))) | 
| 13876 | 737 | end | 
| 738 | 	 else let val th1 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
 | |
| 15531 | 739 | in (instantiate' [] [SOME cfma, SOME cA,SOME (cterm_of sg (norm_zero_one z))] (th1 RS (not_ast_p_gt))) | 
| 13876 | 740 | end | 
| 15531 | 741 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm)) | 
| 13876 | 742 | |
| 743 |    |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | |
| 744 | if y=x then | |
| 745 | let val cz = cterm_of sg (norm_zero_one z) | |
| 746 | val th1 = (prove_elementar sg "ss" (HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) | |
| 15531 | 747 | in (instantiate' [] [SOME cfma, SOME cA,SOME cz] (th1 RS (not_ast_p_ndvd))) | 
| 13876 | 748 | end | 
| 15531 | 749 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm)) | 
| 13876 | 750 | |
| 751 |    |(Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
 | |
| 752 | if y=x then | |
| 753 | let val cz = cterm_of sg (norm_zero_one z) | |
| 754 | val th1 = (prove_elementar sg "ss" (HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) | |
| 15531 | 755 | in (instantiate' [] [SOME cfma,SOME cA,SOME cz] (th1 RS (not_ast_p_dvd))) | 
| 13876 | 756 | end | 
| 15531 | 757 | else (instantiate' [] [SOME cfma, SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm)) | 
| 13876 | 758 | |
| 15531 | 759 | |_ => (instantiate' [] [SOME cfma, SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm)) | 
| 13876 | 760 | |
| 761 | end; | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 762 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 763 | (* ------------------------------------------------------------------------ *) | 
| 13876 | 764 | (* Main interpretation function for this backwards dirction*) | 
| 765 | (* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*) | |
| 766 | (*Help Function*) | |
| 767 | (* ------------------------------------------------------------------------- *) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 768 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 769 | fun decomp_nastp sg x dlcm A fm t = case t of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 770 |    Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_conjI )
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 771 |   |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 772 | |_ => ([], fn [] => generate_atomic_not_ast_p sg x fm dlcm A t); | 
| 13876 | 773 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 774 | fun not_ast_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm A t = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 775 | let | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 776 | val th = thm_of sg (decomp_nastp sg x dlcm (list_to_set xT (map norm_zero_one A)) fm) t | 
| 13876 | 777 | val fma = absfree (xn,xT, norm_zero_one fm) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 778 | in let val th1 = prove_elementar sg "ss" (HOLogic.mk_eq (fma,fma)) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 779 | in [th,th1] MRS (not_ast_p_Q_elim) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 780 | end | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 781 | end; | 
| 13876 | 782 | |
| 783 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 784 | (* -------------------------------*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 785 | (* Finding rho and beta for evalc *) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 786 | (* -------------------------------*) | 
| 13876 | 787 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 788 | fun rho_for_evalc sg at = case at of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 789 | (Const (p,_) $ s $ t) =>( | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 790 | case assoc (operations,p) of | 
| 15531 | 791 | SOME f => | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 792 | ((if (f ((dest_numeral s),(dest_numeral t))) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 793 | then prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const)) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 794 | else prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const))) | 
| 15531 | 795 | handle _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl) | 
| 796 | | _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl ) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 797 |      |Const("Not",_)$(Const (p,_) $ s $ t) =>(  
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 798 | case assoc (operations,p) of | 
| 15531 | 799 | SOME f => | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 800 | ((if (f ((dest_numeral s),(dest_numeral t))) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 801 | then prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const)) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 802 | else prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const))) | 
| 15531 | 803 | handle _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl) | 
| 804 | | _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl ) | |
| 805 | | _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl; | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 806 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 807 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 808 | (*=========================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 809 | fun decomp_evalc sg t = case t of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 810 |    (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 811 |    |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 812 |    |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 813 |    |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 814 | |_ => ([], fn [] => rho_for_evalc sg t); | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 815 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 816 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 817 | fun proof_of_evalc sg fm = thm_of sg (decomp_evalc sg) fm; | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 818 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 819 | (*==================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 820 | (* Proof of linform with the compact model *) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 821 | (*==================================================*) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 822 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 823 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 824 | fun decomp_linform sg vars t = case t of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 825 |    (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 826 |    |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 827 |    |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 828 |    |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 829 |    |(Const("Not",_)$p) => ([p],fn [th] => th RS qe_Not)
 | 
| 15164 | 830 |    |(Const("Divides.op dvd",_)$d$r) => 
 | 
| 15531 | 831 | if is_numeral d then ([], fn [] => (prove_elementar sg "lf" (HOLogic.mk_eq (r, lint vars r))) RS (instantiate' [] [NONE , NONE, SOME (cterm_of sg d)](linearize_dvd))) | 
| 15164 | 832 | else (warning "Nonlinear Term --- Non numeral leftside at dvd"; | 
| 833 | raise COOPER) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 834 | |_ => ([], fn [] => prove_elementar sg "lf" (HOLogic.mk_eq (t, linform vars t))); | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 835 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 836 | fun proof_of_linform sg vars f = thm_of sg (decomp_linform sg vars) f; | 
| 13876 | 837 | |
| 838 | (* ------------------------------------------------------------------------- *) | |
| 839 | (* Interpretaion of Protocols of the cooper procedure : minusinfinity version*) | |
| 840 | (* ------------------------------------------------------------------------- *) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 841 | fun coopermi_proof_of sg (x as Free(xn,xT)) fm B dlcm = | 
| 13876 | 842 | (* Get the Bset thm*) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 843 | let val (minf_eqth, minf_moddth) = minf_proof_of_c sg x dlcm fm | 
| 13876 | 844 | val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm)); | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 845 | val nbstpthm = not_bst_p_proof_of_c sg x fm dlcm B fm | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 846 | in (dpos,minf_eqth,nbstpthm,minf_moddth) | 
| 13876 | 847 | end; | 
| 848 | ||
| 849 | (* ------------------------------------------------------------------------- *) | |
| 850 | (* Interpretaion of Protocols of the cooper procedure : plusinfinity version *) | |
| 851 | (* ------------------------------------------------------------------------- *) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 852 | fun cooperpi_proof_of sg (x as Free(xn,xT)) fm A dlcm = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 853 | let val (pinf_eqth,pinf_moddth) = pinf_proof_of_c sg x dlcm fm | 
| 13876 | 854 | val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm)); | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 855 | val nastpthm = not_ast_p_proof_of_c sg x fm dlcm A fm | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 856 | in (dpos,pinf_eqth,nastpthm,pinf_moddth) | 
| 13876 | 857 | end; | 
| 858 | ||
| 859 | (* ------------------------------------------------------------------------- *) | |
| 860 | (* Interpretaion of Protocols of the cooper procedure : full version*) | |
| 861 | (* ------------------------------------------------------------------------- *) | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 862 | fun cooper_thm sg s (x as Free(xn,xT)) cfm dlcm ast bst= case s of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 863 | "pi" => let val (dpsthm,pinf_eqth,nbpth,pinf_moddth) = cooperpi_proof_of sg x cfm ast dlcm | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 864 | in [dpsthm,pinf_eqth,nbpth,pinf_moddth] MRS (cppi_eq) | 
| 13876 | 865 | end | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 866 | |"mi" => let val (dpsthm,minf_eqth,nbpth,minf_moddth) = coopermi_proof_of sg x cfm bst dlcm | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 867 | in [dpsthm,minf_eqth,nbpth,minf_moddth] MRS (cpmi_eq) | 
| 13876 | 868 | end | 
| 869 | |_ => error "parameter error"; | |
| 870 | ||
| 871 | (* ------------------------------------------------------------------------- *) | |
| 872 | (* This function should evoluate to the end prove Procedure for one quantifier elimination for Presburger arithmetic*) | |
| 873 | (* It shoud be plugged in the qfnp argument of the quantifier elimination proof function*) | |
| 874 | (* ------------------------------------------------------------------------- *) | |
| 875 | ||
| 15165 | 876 | (* val (timef:(unit->thm) -> thm,prtime,time_reset) = gen_timer();*) | 
| 877 | (* val (timef2:(unit->thm) -> thm,prtime2,time_reset2) = gen_timer(); *) | |
| 15164 | 878 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 879 | fun cooper_prv sg (x as Free(xn,xT)) efm = let | 
| 14877 | 880 | (* lfm_thm : efm = linearized form of efm*) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 881 | val lfm_thm = proof_of_linform sg [xn] efm | 
| 14877 | 882 | (*efm2 is the linearized form of efm *) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 883 | val efm2 = snd(qe_get_terms lfm_thm) | 
| 14877 | 884 | (* l is the lcm of all coefficients of x *) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 885 | val l = formlcm x efm2 | 
| 14877 | 886 | (*ac_thm: efm = efm2 with adjusted coefficients of x *) | 
| 887 | val ac_thm = [lfm_thm , (proof_of_adjustcoeffeq sg x l efm2)] MRS trans | |
| 888 | (* fm is efm2 with adjusted coefficients of x *) | |
| 13876 | 889 | val fm = snd (qe_get_terms ac_thm) | 
| 14877 | 890 | (* cfm is l dvd x & fm' where fm' is fm where l*x is replaced by x*) | 
| 13876 | 891 | val cfm = unitycoeff x fm | 
| 14877 | 892 | (*afm is fm where c*x is replaced by 1*x or -1*x *) | 
| 13876 | 893 | val afm = adjustcoeff x l fm | 
| 14877 | 894 | (* P = %x.afm*) | 
| 13876 | 895 | val P = absfree(xn,xT,afm) | 
| 14877 | 896 |    (* This simpset allows the elimination of the sets in bex {1..d} *)
 | 
| 13876 | 897 | val ss = presburger_ss addsimps | 
| 898 | [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff] | |
| 14877 | 899 | (* uth : EX x.P(l*x) = EX x. l dvd x & P x*) | 
| 15531 | 900 | val uth = instantiate' [] [SOME (cterm_of sg P) , SOME (cterm_of sg (mk_numeral l))] (unity_coeff_ex) | 
| 14877 | 901 | (* e_ac_thm : Ex x. efm = EX x. fm*) | 
| 13876 | 902 | val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI) | 
| 14877 | 903 | (* A and B set of the formula*) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 904 | val A = aset x cfm | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 905 | val B = bset x cfm | 
| 14877 | 906 | (* the divlcm (delta) of the formula*) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 907 | val dlcm = mk_numeral (divlcm x cfm) | 
| 14877 | 908 | (* Which set is smaller to generate the (hoepfully) shorter proof*) | 
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 909 | val cms = if ((length A) < (length B )) then "pi" else "mi" | 
| 15165 | 910 | (* val _ = if cms = "pi" then writeln "Plusinfinity" else writeln "Minusinfinity"*) | 
| 14877 | 911 | (* synthesize the proof of cooper's theorem*) | 
| 912 | (* cp_thm: EX x. cfm = Q*) | |
| 15165 | 913 | val cp_thm = cooper_thm sg cms x cfm dlcm A B | 
| 14877 | 914 |    (* Exxpand the right hand side to get rid of EX j : {1..d} to get a huge disjunction*)
 | 
| 915 | (* exp_cp_thm: EX x.cfm = Q' , where Q' is a simplified version of Q*) | |
| 15165 | 916 | (* | 
| 15164 | 917 | val _ = prth cp_thm | 
| 918 | val _ = writeln "Expanding the bounded EX..." | |
| 15165 | 919 | *) | 
| 920 | val exp_cp_thm = refl RS (simplify ss (cp_thm RSN (2,trans))) | |
| 921 | (* | |
| 922 | val _ = writeln "Expanded" *) | |
| 14877 | 923 | (* lsuth = EX.P(l*x) ; rsuth = EX x. l dvd x & P x*) | 
| 13876 | 924 | val (lsuth,rsuth) = qe_get_terms (uth) | 
| 14877 | 925 | (* lseacth = EX x. efm; rseacth = EX x. fm*) | 
| 13876 | 926 | val (lseacth,rseacth) = qe_get_terms(e_ac_thm) | 
| 14877 | 927 | (* lscth = EX x. cfm; rscth = Q' *) | 
| 13876 | 928 | val (lscth,rscth) = qe_get_terms (exp_cp_thm) | 
| 14877 | 929 | (* u_c_thm: EX x. P(l*x) = Q'*) | 
| 13876 | 930 | val u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans | 
| 14877 | 931 | (* result: EX x. efm = Q'*) | 
| 13876 | 932 | in ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans) | 
| 933 | end | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 934 | |cooper_prv _ _ _ = error "Parameters format"; | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 935 | |
| 15107 | 936 | (* **************************************** *) | 
| 937 | (* An Other Version of cooper proving *) | |
| 938 | (* by giving a withness for EX *) | |
| 939 | (* **************************************** *) | |
| 940 | ||
| 941 | ||
| 942 | ||
| 943 | fun cooper_prv_w sg (x as Free(xn,xT)) efm = let | |
| 944 | (* lfm_thm : efm = linearized form of efm*) | |
| 945 | val lfm_thm = proof_of_linform sg [xn] efm | |
| 946 | (*efm2 is the linearized form of efm *) | |
| 947 | val efm2 = snd(qe_get_terms lfm_thm) | |
| 948 | (* l is the lcm of all coefficients of x *) | |
| 949 | val l = formlcm x efm2 | |
| 950 | (*ac_thm: efm = efm2 with adjusted coefficients of x *) | |
| 951 | val ac_thm = [lfm_thm , (proof_of_adjustcoeffeq sg x l efm2)] MRS trans | |
| 952 | (* fm is efm2 with adjusted coefficients of x *) | |
| 953 | val fm = snd (qe_get_terms ac_thm) | |
| 954 | (* cfm is l dvd x & fm' where fm' is fm where l*x is replaced by x*) | |
| 955 | val cfm = unitycoeff x fm | |
| 956 | (*afm is fm where c*x is replaced by 1*x or -1*x *) | |
| 957 | val afm = adjustcoeff x l fm | |
| 958 | (* P = %x.afm*) | |
| 959 | val P = absfree(xn,xT,afm) | |
| 960 |    (* This simpset allows the elimination of the sets in bex {1..d} *)
 | |
| 961 | val ss = presburger_ss addsimps | |
| 962 | [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff] | |
| 963 | (* uth : EX x.P(l*x) = EX x. l dvd x & P x*) | |
| 15531 | 964 | val uth = instantiate' [] [SOME (cterm_of sg P) , SOME (cterm_of sg (mk_numeral l))] (unity_coeff_ex) | 
| 15107 | 965 | (* e_ac_thm : Ex x. efm = EX x. fm*) | 
| 966 | val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI) | |
| 967 | (* lsuth = EX.P(l*x) ; rsuth = EX x. l dvd x & P x*) | |
| 968 | val (lsuth,rsuth) = qe_get_terms (uth) | |
| 969 | (* lseacth = EX x. efm; rseacth = EX x. fm*) | |
| 970 | val (lseacth,rseacth) = qe_get_terms(e_ac_thm) | |
| 971 | ||
| 972 | val (w,rs) = cooper_w [] cfm | |
| 973 | val exp_cp_thm = case w of | |
| 974 | (* FIXME - e_ac_thm just tipped to test syntactical correctness of the program!!!!*) | |
| 15531 | 975 | SOME n => e_ac_thm (* Prove cfm (n) and use exI and then Eq_TrueI*) | 
| 15107 | 976 | |_ => let | 
| 977 | (* A and B set of the formula*) | |
| 978 | val A = aset x cfm | |
| 979 | val B = bset x cfm | |
| 980 | (* the divlcm (delta) of the formula*) | |
| 981 | val dlcm = mk_numeral (divlcm x cfm) | |
| 982 | (* Which set is smaller to generate the (hoepfully) shorter proof*) | |
| 983 | val cms = if ((length A) < (length B )) then "pi" else "mi" | |
| 984 | (* synthesize the proof of cooper's theorem*) | |
| 985 | (* cp_thm: EX x. cfm = Q*) | |
| 986 | val cp_thm = cooper_thm sg cms x cfm dlcm A B | |
| 987 |      (* Exxpand the right hand side to get rid of EX j : {1..d} to get a huge disjunction*)
 | |
| 988 | (* exp_cp_thm: EX x.cfm = Q' , where Q' is a simplified version of Q*) | |
| 989 | in refl RS (simplify ss (cp_thm RSN (2,trans))) | |
| 990 | end | |
| 991 | (* lscth = EX x. cfm; rscth = Q' *) | |
| 992 | val (lscth,rscth) = qe_get_terms (exp_cp_thm) | |
| 993 | (* u_c_thm: EX x. P(l*x) = Q'*) | |
| 994 | val u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans | |
| 995 | (* result: EX x. efm = Q'*) | |
| 996 | in ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans) | |
| 997 | end | |
| 998 | |cooper_prv_w _ _ _ = error "Parameters format"; | |
| 999 | ||
| 1000 | ||
| 13876 | 1001 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1002 | fun decomp_cnnf sg lfnp P = case P of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1003 |      Const ("op &",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS qe_conjI )
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1004 |    |Const ("op |",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS  qe_disjI)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1005 |    |Const ("Not",_) $ (Const("Not",_) $ p) => ([p], fn [th] => th RS nnf_nn)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1006 |    |Const("Not",_) $ (Const(opn,T) $ p $ q) => 
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1007 | if opn = "op |" | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1008 | then case (p,q) of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1009 |          (A as (Const ("op &",_) $ r $ s),B as (Const ("op &",_) $ r1 $ t)) =>
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1010 | if r1 = negate r | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1011 | then ([r,HOLogic.Not$s,r1,HOLogic.Not$t],fn [th1_1,th1_2,th2_1,th2_2] => [[th1_1,th1_1] MRS qe_conjI,[th2_1,th2_2] MRS qe_conjI] MRS nnf_sdj) | 
| 13876 | 1012 | |
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1013 | else ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1014 | |(_,_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1015 | else ( | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1016 | case (opn,T) of | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1017 |            ("op &",_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_ncj )
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1018 |            |("op -->",_) => ([p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_nim )
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1019 |            |("op =",Type ("fun",[Type ("bool", []),_])) => 
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1020 | ([HOLogic.conj $ p $ (HOLogic.Not $ q),HOLogic.conj $ (HOLogic.Not $ p) $ q], fn [th1,th2] => [th1,th2] MRS nnf_neq) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1021 | |(_,_) => ([], fn [] => lfnp P) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1022 | ) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1023 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1024 |    |(Const ("op -->",_) $ p $ q) => ([HOLogic.Not$p,q], fn [th1,th2] => [th1,th2] MRS nnf_im)
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1025 | |
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1026 |    |(Const ("op =", Type ("fun",[Type ("bool", []),_])) $ p $ q) =>
 | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1027 | ([HOLogic.conj $ p $ q,HOLogic.conj $ (HOLogic.Not $ p) $ (HOLogic.Not $ q) ], fn [th1,th2] =>[th1,th2] MRS nnf_eq ) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1028 | |_ => ([], fn [] => lfnp P); | 
| 13876 | 1029 | |
| 1030 | ||
| 1031 | ||
| 1032 | ||
| 14758 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1033 | fun proof_of_cnnf sg p lfnp = | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1034 | let val th1 = thm_of sg (decomp_cnnf sg lfnp) p | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1035 | val rs = snd(qe_get_terms th1) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1036 | val th2 = prove_elementar sg "ss" (HOLogic.mk_eq(rs,simpl rs)) | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1037 | in [th1,th2] MRS trans | 
| 
af3b71a46a1c
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
 chaieb parents: 
14479diff
changeset | 1038 | end; | 
| 13876 | 1039 | |
| 1040 | end; | |
| 14920 
a7525235e20f
An oracle is built in. The tactic will not generate any proofs any more, if the quick_and_dirty flag is set on.
 chaieb parents: 
14877diff
changeset | 1041 |