A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
authorchaieb
Wed May 19 11:23:59 2004 +0200 (2004-05-19)
changeset 14758af3b71a46a1c
parent 14757 556ce89b7d41
child 14759 c90bed2d5bdf
A new implementation for presburger arithmetic following the one suggested in technical report Chaieb Amine and Tobias Nipkow. It is generic an smaller.
the tactic has also changed and allows the abstaction over fuction occurences whose type is nat or int.
src/HOL/Integ/Presburger.thy
src/HOL/Integ/cooper_dec.ML
src/HOL/Integ/cooper_proof.ML
src/HOL/Integ/presburger.ML
src/HOL/Integ/qelim.ML
src/HOL/Presburger.thy
src/HOL/Tools/Presburger/cooper_dec.ML
src/HOL/Tools/Presburger/cooper_proof.ML
src/HOL/Tools/Presburger/presburger.ML
src/HOL/Tools/Presburger/qelim.ML
src/HOL/ex/PresburgerEx.thy
     1.1 --- a/src/HOL/Integ/Presburger.thy	Wed May 19 11:21:19 2004 +0200
     1.2 +++ b/src/HOL/Integ/Presburger.thy	Wed May 19 11:23:59 2004 +0200
     1.3 @@ -978,11 +978,11 @@
     1.4    \medskip Specific instances of congruence rules, to prevent
     1.5    simplifier from looping. *}
     1.6  
     1.7 -theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
     1.8 +theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
     1.9    by simp
    1.10  
    1.11 -theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<and> P) = (0 <= x \<and> P')"
    1.12 -  by simp
    1.13 +theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<and> P) = (0 <= x \<and> P')"
    1.14 +  by (simp cong: conj_cong)
    1.15  
    1.16  use "cooper_dec.ML"
    1.17  use "cooper_proof.ML"
     2.1 --- a/src/HOL/Integ/cooper_dec.ML	Wed May 19 11:21:19 2004 +0200
     2.2 +++ b/src/HOL/Integ/cooper_dec.ML	Wed May 19 11:23:59 2004 +0200
     2.3 @@ -29,10 +29,16 @@
     2.4    val aset : term -> term -> term list
     2.5    val linrep : string list -> term -> term -> term -> term
     2.6    val list_disj : term list -> term
     2.7 +  val list_conj : term list -> term
     2.8    val simpl : term -> term
     2.9    val fv : term -> string list
    2.10    val negate : term -> term
    2.11    val operations : (string * (int * int -> bool)) list
    2.12 +  val conjuncts : term -> term list
    2.13 +  val disjuncts : term -> term list
    2.14 +  val has_bound : term -> bool
    2.15 +  val minusinf : term -> term -> term
    2.16 +  val plusinf : term -> term -> term
    2.17  end;
    2.18  
    2.19  structure  CooperDec : COOPER_DEC =
    2.20 @@ -183,7 +189,7 @@
    2.21   
    2.22           else (warning "lint: apparent nonlinearity"; raise COOPER)
    2.23           end 
    2.24 -  |_ =>   error "lint: unknown term"; 
    2.25 +  |_ =>   (error "COOPER:lint: unknown term  ")
    2.26     
    2.27   
    2.28   
     3.1 --- a/src/HOL/Integ/cooper_proof.ML	Wed May 19 11:21:19 2004 +0200
     3.2 +++ b/src/HOL/Integ/cooper_proof.ML	Wed May 19 11:23:59 2004 +0200
     3.3 @@ -16,35 +16,25 @@
     3.4    val qe_eqI : thm
     3.5    val qe_exI : thm
     3.6    val qe_get_terms : thm -> term * term
     3.7 -  val cooper_prv : Sign.sg -> term -> term -> string list -> thm
     3.8 +  val cooper_prv : Sign.sg -> term -> term -> thm
     3.9    val proof_of_evalc : Sign.sg -> term -> thm
    3.10    val proof_of_cnnf : Sign.sg -> term -> (term -> thm) -> thm
    3.11    val proof_of_linform : Sign.sg -> string list -> term -> thm
    3.12 +  val prove_elementar : Sign.sg -> string -> term -> thm
    3.13 +  val thm_of : Sign.sg -> (term -> (term list * (thm list -> thm))) -> term -> thm
    3.14  end;
    3.15  
    3.16  structure CooperProof : COOPER_PROOF =
    3.17  struct
    3.18 -
    3.19  open CooperDec;
    3.20  
    3.21 -(*-----------------------------------------------------------------*)
    3.22 -(*-----------------------------------------------------------------*)
    3.23 -(*-----------------------------------------------------------------*)
    3.24 -(*---                                                           ---*)
    3.25 -(*---                                                           ---*)
    3.26 -(*---         Protocoling part                                  ---*)
    3.27 -(*---                                                           ---*)
    3.28 -(*---           includes the protocolling datastructure         ---*)
    3.29 -(*---                                                           ---*)
    3.30 -(*---          and the protocolling fuctions                    ---*)
    3.31 -(*---                                                           ---*)
    3.32 -(*---                                                           ---*)
    3.33 -(*-----------------------------------------------------------------*)
    3.34 -(*-----------------------------------------------------------------*)
    3.35 -(*-----------------------------------------------------------------*)
    3.36 +(*
    3.37 +val presburger_ss = simpset_of (theory "Presburger")
    3.38 +  addsimps [zdiff_def] delsimps [symmetric zdiff_def];
    3.39 +*)
    3.40  
    3.41  val presburger_ss = simpset_of (theory "Presburger")
    3.42 -  addsimps [diff_int_def] delsimps [thm"diff_int_def_symmetric"];
    3.43 +  addsimps[diff_int_def] delsimps [thm"diff_int_def_symmetric"];
    3.44  val cboolT = ctyp_of (sign_of HOL.thy) HOLogic.boolT;
    3.45  
    3.46  (*Theorems that will be used later for the proofgeneration*)
    3.47 @@ -52,7 +42,7 @@
    3.48  val zdvd_iff_zmod_eq_0 = thm "zdvd_iff_zmod_eq_0";
    3.49  val unity_coeff_ex = thm "unity_coeff_ex";
    3.50  
    3.51 -(* Theorems for proving the adjustment of the coefficients*)
    3.52 +(* Thorems for proving the adjustment of the coeffitients*)
    3.53  
    3.54  val ac_lt_eq =  thm "ac_lt_eq";
    3.55  val ac_eq_eq = thm "ac_eq_eq";
    3.56 @@ -68,7 +58,7 @@
    3.57  val qe_exI = thm "qe_exI";
    3.58  val qe_ALLI = thm "qe_ALLI";
    3.59  
    3.60 -(*Modulo D property for Pminusinf and Plusinf *)
    3.61 +(*Modulo D property for Pminusinf an Plusinf *)
    3.62  val fm_modd_minf = thm "fm_modd_minf";
    3.63  val not_dvd_modd_minf = thm "not_dvd_modd_minf";
    3.64  val dvd_modd_minf = thm "dvd_modd_minf";
    3.65 @@ -77,7 +67,7 @@
    3.66  val not_dvd_modd_pinf = thm "not_dvd_modd_pinf";
    3.67  val dvd_modd_pinf = thm "dvd_modd_pinf";
    3.68  
    3.69 -(* the minusinfinity property*)
    3.70 +(* the minusinfinity proprty*)
    3.71  
    3.72  val fm_eq_minf = thm "fm_eq_minf";
    3.73  val neq_eq_minf = thm "neq_eq_minf";
    3.74 @@ -87,7 +77,7 @@
    3.75  val not_dvd_eq_minf = thm "not_dvd_eq_minf";
    3.76  val dvd_eq_minf = thm "dvd_eq_minf";
    3.77  
    3.78 -(* the Plusinfinity property*)
    3.79 +(* the Plusinfinity proprty*)
    3.80  
    3.81  val fm_eq_pinf = thm "fm_eq_pinf";
    3.82  val neq_eq_pinf = thm "neq_eq_pinf";
    3.83 @@ -108,7 +98,6 @@
    3.84  val modd_pinf_disjI = thm "modd_pinf_disjI";
    3.85  val modd_pinf_conjI = thm "modd_pinf_conjI";
    3.86  
    3.87 -
    3.88  (*Cooper Backwards...*)
    3.89  (*Bset*)
    3.90  val not_bst_p_fm = thm "not_bst_p_fm";
    3.91 @@ -166,81 +155,6 @@
    3.92  val lf_dvd = thm "lf_dvd";
    3.93  
    3.94  
    3.95 -
    3.96 -(* ------------------------------------------------------------------------- *)
    3.97 -(*Datatatype declarations for Proofprotocol for the cooperprocedure.*)
    3.98 -(* ------------------------------------------------------------------------- *)
    3.99 -
   3.100 -
   3.101 -
   3.102 -(* ------------------------------------------------------------------------- *)
   3.103 -(*Datatatype declarations for Proofprotocol for the adjustcoeff step.*)
   3.104 -(* ------------------------------------------------------------------------- *)
   3.105 -datatype CpLog = No
   3.106 -                |Simp of term*CpLog
   3.107 -		|Blast of CpLog*CpLog
   3.108 -		|Aset of (term*term*(term list)*term)
   3.109 -		|Bset of (term*term*(term list)*term)
   3.110 -		|Minusinf of CpLog*CpLog
   3.111 -		|Cooper of term*CpLog*CpLog*CpLog
   3.112 -		|Eq_minf of term*term
   3.113 -		|Modd_minf of term*term
   3.114 -		|Eq_minf_conjI of CpLog*CpLog
   3.115 -		|Modd_minf_conjI of CpLog*CpLog	
   3.116 -		|Modd_minf_disjI of CpLog*CpLog
   3.117 -		|Eq_minf_disjI of CpLog*CpLog	
   3.118 -		|Not_bst_p of term*term*term*term*CpLog
   3.119 -		|Not_bst_p_atomic of term
   3.120 -		|Not_bst_p_conjI of CpLog*CpLog
   3.121 -		|Not_bst_p_disjI of CpLog*CpLog
   3.122 -		|Not_ast_p of term*term*term*term*CpLog
   3.123 -		|Not_ast_p_atomic of term
   3.124 -		|Not_ast_p_conjI of CpLog*CpLog
   3.125 -		|Not_ast_p_disjI of CpLog*CpLog
   3.126 -		|CpLogError;
   3.127 -
   3.128 -
   3.129 -
   3.130 -datatype ACLog = ACAt of int*term
   3.131 -                |ACPI of int*term
   3.132 -                |ACfm of term
   3.133 -                |ACNeg of ACLog
   3.134 -		|ACConst of string*ACLog*ACLog;
   3.135 -
   3.136 -
   3.137 -
   3.138 -(* ------------------------------------------------------------------------- *)
   3.139 -(*Datatatype declarations for Proofprotocol for the CNNF step.*)
   3.140 -(* ------------------------------------------------------------------------- *)
   3.141 -
   3.142 -
   3.143 -datatype NNFLog = NNFAt of term
   3.144 -                |NNFSimp of NNFLog
   3.145 -                |NNFNN of NNFLog
   3.146 -		|NNFConst of string*NNFLog*NNFLog;
   3.147 -
   3.148 -(* ------------------------------------------------------------------------- *)
   3.149 -(*Datatatype declarations for Proofprotocol for the linform  step.*)
   3.150 -(* ------------------------------------------------------------------------- *)
   3.151 -
   3.152 -
   3.153 -datatype LfLog = LfAt of term
   3.154 -                |LfAtdvd of term
   3.155 -                |Lffm of term
   3.156 -                |LfConst of string*LfLog*LfLog
   3.157 -		|LfNot of LfLog
   3.158 -		|LfQ of string*string*typ*LfLog;
   3.159 -
   3.160 -
   3.161 -(* ------------------------------------------------------------------------- *)
   3.162 -(*Datatatype declarations for Proofprotocol for the evaluation- evalc-  step.*)
   3.163 -(* ------------------------------------------------------------------------- *)
   3.164 -
   3.165 -
   3.166 -datatype EvalLog = EvalAt of term
   3.167 -                |Evalfm of term
   3.168 -		|EvalConst of string*EvalLog*EvalLog;
   3.169 -
   3.170  (* ------------------------------------------------------------------------- *)
   3.171  (*This function norm_zero_one  replaces the occurences of Numeral1 and Numeral0*)
   3.172  (*Respectively by their abstract representation Const("1",..) and COnst("0",..)*)
   3.173 @@ -258,214 +172,6 @@
   3.174    |(Abs(x,T,p)) => (Abs(x,T,(norm_zero_one p)))
   3.175    |_ => fm;
   3.176  
   3.177 -
   3.178 -(* ------------------------------------------------------------------------- *)
   3.179 -(* Intended to tell that here we changed the structure of the formula with respect to the posineq theorem : ~(0 < t) = 0 < 1-t*)
   3.180 -(* ------------------------------------------------------------------------- *)
   3.181 -fun adjustcoeffeq_wp  x l fm = 
   3.182 -    case fm of  
   3.183 -  (Const("Not",_)$(Const("op <",_) $(Const("0",_)) $(rt as (Const ("op +", _)$(Const ("op *",_) $    c $ y ) $z )))) => 
   3.184 -  if (x = y) 
   3.185 -  then let  
   3.186 -       val m = l div (dest_numeral c) 
   3.187 -       val n = abs (m)
   3.188 -       val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) 
   3.189 -       val rs = (HOLogic.mk_binrel "op <" (zero,linear_sub [] (mk_numeral n) (HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) 
   3.190 -       in (ACPI(n,fm),rs)
   3.191 -       end
   3.192 -  else  let val rs = (HOLogic.mk_binrel "op <" (zero,linear_sub [] one rt )) 
   3.193 -        in (ACPI(1,fm),rs)
   3.194 -        end
   3.195 -
   3.196 -  |(Const(p,_) $d $( Const ("op +", _)$(Const ("op *",_) $ 
   3.197 -      c $ y ) $z )) => if (is_arith_rel fm) andalso (x = y) then  
   3.198 -        let val m = l div (dest_numeral c) 
   3.199 -           val n = (if p = "op <" then abs(m) else m)  
   3.200 -           val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x))
   3.201 -           val rs = (HOLogic.mk_binrel p ((linear_cmul n d),(HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) 
   3.202 -	   in (ACAt(n,fm),rs)
   3.203 -	   end
   3.204 -        else (ACfm(fm),fm) 
   3.205 -  |( Const ("Not", _) $ p) => let val (rsp,rsr) = adjustcoeffeq_wp x l p 
   3.206 -                              in (ACNeg(rsp),HOLogic.Not $ rsr) 
   3.207 -                              end
   3.208 -  |( Const ("op &",_) $ p $ q) =>let val (rspp,rspr) = adjustcoeffeq_wp x l p
   3.209 -                                     val (rsqp,rsqr) = adjustcoeffeq_wp x l q
   3.210 -
   3.211 -                                  in (ACConst ("CJ",rspp,rsqp), HOLogic.mk_conj (rspr,rsqr)) 
   3.212 -                                  end 
   3.213 -  |( Const ("op |",_) $ p $ q) =>let val (rspp,rspr) = adjustcoeffeq_wp x l p
   3.214 -                                     val (rsqp,rsqr) = adjustcoeffeq_wp x l q
   3.215 -
   3.216 -                                  in (ACConst ("DJ",rspp,rsqp), HOLogic.mk_disj (rspr,rsqr)) 
   3.217 -                                  end
   3.218 -
   3.219 -  |_ => (ACfm(fm),fm);
   3.220 -
   3.221 -
   3.222 -(*_________________________________________*)
   3.223 -(*-----------------------------------------*)
   3.224 -(* Protocol generation for the liform step *)
   3.225 -(*_________________________________________*)
   3.226 -(*-----------------------------------------*)
   3.227 -
   3.228 -
   3.229 -fun linform_wp fm = 
   3.230 -  let fun at_linform_wp at =
   3.231 -    case at of
   3.232 -      (Const("op <=",_)$s$t) => LfAt(at)
   3.233 -      |(Const("op <",_)$s$t) => LfAt(at)
   3.234 -      |(Const("op =",_)$s$t) => LfAt(at)
   3.235 -      |(Const("Divides.op dvd",_)$s$t) => LfAtdvd(at)
   3.236 -  in
   3.237 -  if is_arith_rel fm 
   3.238 -  then at_linform_wp fm 
   3.239 -  else case fm of
   3.240 -    (Const("Not",_) $ A) => LfNot(linform_wp A)
   3.241 -   |(Const("op &",_)$ A $ B) => LfConst("CJ",linform_wp A, linform_wp B)
   3.242 -   |(Const("op |",_)$ A $ B) => LfConst("DJ",linform_wp A, linform_wp B)
   3.243 -   |(Const("op -->",_)$ A $ B) => LfConst("IM",linform_wp A, linform_wp B)
   3.244 -   |(Const("op =",Type ("fun",[Type ("bool", []),_]))$ A $ B) => LfConst("EQ",linform_wp A, linform_wp B)
   3.245 -   |Const("Ex",_)$Abs(x,T,p) => 
   3.246 -     let val (xn,p1) = variant_abs(x,T,p)
   3.247 -     in LfQ("Ex",xn,T,linform_wp p1)
   3.248 -     end 
   3.249 -   |Const("All",_)$Abs(x,T,p) => 
   3.250 -     let val (xn,p1) = variant_abs(x,T,p)
   3.251 -     in LfQ("All",xn,T,linform_wp p1)
   3.252 -     end 
   3.253 -end;
   3.254 -
   3.255 -
   3.256 -(* ------------------------------------------------------------------------- *)
   3.257 -(*For simlified formulas we just notice the original formula, for whitch we habe been
   3.258 -intendes to make the proof.*)
   3.259 -(* ------------------------------------------------------------------------- *)
   3.260 -fun simpl_wp (fm,pr) = let val fm2 = simpl fm
   3.261 -				in (fm2,Simp(fm,pr))
   3.262 -				end;
   3.263 -
   3.264 -	
   3.265 -(* ------------------------------------------------------------------------- *)
   3.266 -(*Help function for the generation of the proof EX.P_{minus \infty} --> EX. P(x) *)
   3.267 -(* ------------------------------------------------------------------------- *)
   3.268 -fun minusinf_wph x fm = let fun mk_atomar_minusinf_proof x fm = (Modd_minf(x,fm),Eq_minf(x,fm))
   3.269 -  
   3.270 -	      fun combine_minusinf_proofs opr (ppr1,ppr2) (qpr1,qpr2) = case opr of 
   3.271 -		 "CJ" => (Modd_minf_conjI(ppr1,qpr1),Eq_minf_conjI(ppr2,qpr2))
   3.272 -		|"DJ" => (Modd_minf_disjI(ppr1,qpr1),Eq_minf_disjI(ppr2,qpr2))
   3.273 -	in 
   3.274 - 
   3.275 - case fm of 
   3.276 - (Const ("Not", _) $  (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
   3.277 -     if (x=y) andalso (c1= zero) andalso (c2= one) then (HOLogic.true_const ,(mk_atomar_minusinf_proof x fm))
   3.278 -        else (fm ,(mk_atomar_minusinf_proof x fm))
   3.279 - |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
   3.280 -  	 if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one)
   3.281 -	 then (HOLogic.false_const ,(mk_atomar_minusinf_proof x fm))
   3.282 -	 				 else (fm,(mk_atomar_minusinf_proof x fm)) 
   3.283 - |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y ) $ z )) =>
   3.284 -       if (y=x) andalso (c1 = zero) then 
   3.285 -        if c2 = one then (HOLogic.false_const,(mk_atomar_minusinf_proof x fm)) else
   3.286 -	(HOLogic.true_const,(mk_atomar_minusinf_proof x fm))
   3.287 -	else (fm,(mk_atomar_minusinf_proof x fm))
   3.288 -  
   3.289 -  |(Const("Not",_)$(Const ("Divides.op dvd",_) $_ )) => (fm,mk_atomar_minusinf_proof x fm)
   3.290 -  
   3.291 -  |(Const ("Divides.op dvd",_) $_ ) => (fm,mk_atomar_minusinf_proof x fm)
   3.292 -  
   3.293 -  |(Const ("op &",_) $ p $ q) => let val (pfm,ppr) = minusinf_wph x p
   3.294 -  				    val (qfm,qpr) = minusinf_wph x q
   3.295 -				    val pr = (combine_minusinf_proofs "CJ" ppr qpr)
   3.296 -				     in 
   3.297 -				     (HOLogic.conj $ pfm $qfm , pr)
   3.298 -				     end 
   3.299 -  |(Const ("op |",_) $ p $ q) => let val (pfm,ppr) = minusinf_wph x p
   3.300 -  				     val (qfm,qpr) = minusinf_wph x q
   3.301 -				     val pr = (combine_minusinf_proofs "DJ" ppr qpr)
   3.302 -				     in 
   3.303 -				     (HOLogic.disj $ pfm $qfm , pr)
   3.304 -				     end 
   3.305 -
   3.306 -  |_ => (fm,(mk_atomar_minusinf_proof x fm))
   3.307 -  
   3.308 -  end;					 
   3.309 -(* ------------------------------------------------------------------------- *)	    (* Protokol for the Proof of the property of the minusinfinity formula*)
   3.310 -(* Just combines the to protokols *)
   3.311 -(* ------------------------------------------------------------------------- *)
   3.312 -fun minusinf_wp x fm  = let val (fm2,pr) = (minusinf_wph x fm)
   3.313 -                       in (fm2,Minusinf(pr))
   3.314 -                        end;
   3.315 -
   3.316 -(* ------------------------------------------------------------------------- *)
   3.317 -(*Help function for the generation of the proof EX.P_{plus \infty} --> EX. P(x) *)
   3.318 -(* ------------------------------------------------------------------------- *)
   3.319 -
   3.320 -fun plusinf_wph x fm = let fun mk_atomar_plusinf_proof x fm = (Modd_minf(x,fm),Eq_minf(x,fm))
   3.321 -  
   3.322 -	      fun combine_plusinf_proofs opr (ppr1,ppr2) (qpr1,qpr2) = case opr of 
   3.323 -		 "CJ" => (Modd_minf_conjI(ppr1,qpr1),Eq_minf_conjI(ppr2,qpr2))
   3.324 -		|"DJ" => (Modd_minf_disjI(ppr1,qpr1),Eq_minf_disjI(ppr2,qpr2))
   3.325 -	in 
   3.326 - 
   3.327 - case fm of 
   3.328 - (Const ("Not", _) $  (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
   3.329 -     if (x=y) andalso (c1= zero) andalso (c2= one) then (HOLogic.true_const ,(mk_atomar_plusinf_proof x fm))
   3.330 -        else (fm ,(mk_atomar_plusinf_proof x fm))
   3.331 - |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
   3.332 -  	 if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one)
   3.333 -	 then (HOLogic.false_const ,(mk_atomar_plusinf_proof x fm))
   3.334 -	 				 else (fm,(mk_atomar_plusinf_proof x fm)) 
   3.335 - |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y ) $ z )) =>
   3.336 -       if (y=x) andalso (c1 = zero) then 
   3.337 -        if c2 = one then (HOLogic.true_const,(mk_atomar_plusinf_proof x fm)) else
   3.338 -	(HOLogic.false_const,(mk_atomar_plusinf_proof x fm))
   3.339 -	else (fm,(mk_atomar_plusinf_proof x fm))
   3.340 -  
   3.341 -  |(Const("Not",_)$(Const ("Divides.op dvd",_) $_ )) => (fm,mk_atomar_plusinf_proof x fm)
   3.342 -  
   3.343 -  |(Const ("Divides.op dvd",_) $_ ) => (fm,mk_atomar_plusinf_proof x fm)
   3.344 -  
   3.345 -  |(Const ("op &",_) $ p $ q) => let val (pfm,ppr) = plusinf_wph x p
   3.346 -  				    val (qfm,qpr) = plusinf_wph x q
   3.347 -				    val pr = (combine_plusinf_proofs "CJ" ppr qpr)
   3.348 -				     in 
   3.349 -				     (HOLogic.conj $ pfm $qfm , pr)
   3.350 -				     end 
   3.351 -  |(Const ("op |",_) $ p $ q) => let val (pfm,ppr) = plusinf_wph x p
   3.352 -  				     val (qfm,qpr) = plusinf_wph x q
   3.353 -				     val pr = (combine_plusinf_proofs "DJ" ppr qpr)
   3.354 -				     in 
   3.355 -				     (HOLogic.disj $ pfm $qfm , pr)
   3.356 -				     end 
   3.357 -
   3.358 -  |_ => (fm,(mk_atomar_plusinf_proof x fm))
   3.359 -  
   3.360 -  end;					 
   3.361 -(* ------------------------------------------------------------------------- *)	    (* Protokol for the Proof of the property of the minusinfinity formula*)
   3.362 -(* Just combines the to protokols *)
   3.363 -(* ------------------------------------------------------------------------- *)
   3.364 -fun plusinf_wp x fm  = let val (fm2,pr) = (plusinf_wph x fm)
   3.365 -                       in (fm2,Minusinf(pr))
   3.366 -                        end;
   3.367 -
   3.368 -
   3.369 -(* ------------------------------------------------------------------------- *)
   3.370 -(*Protocol that we here uses Bset.*)
   3.371 -(* ------------------------------------------------------------------------- *)
   3.372 -fun bset_wp x fm = let val bs = bset x fm in
   3.373 -				(bs,Bset(x,fm,bs,mk_numeral (divlcm x fm)))
   3.374 -				end;
   3.375 -
   3.376 -(* ------------------------------------------------------------------------- *)
   3.377 -(*Protocol that we here uses Aset.*)
   3.378 -(* ------------------------------------------------------------------------- *)
   3.379 -fun aset_wp x fm = let val ast = aset x fm in
   3.380 -				(ast,Aset(x,fm,ast,mk_numeral (divlcm x fm)))
   3.381 -				end;
   3.382 - 
   3.383 -
   3.384 -
   3.385  (* ------------------------------------------------------------------------- *)
   3.386  (*function list to Set, constructs a set containing all elements of a given list.*)
   3.387  (* ------------------------------------------------------------------------- *)
   3.388 @@ -475,181 +181,11 @@
   3.389  		|(h::t) => Const("insert", T1 --> (T --> T)) $ h $(list_to_set T1 t)
   3.390  		end;
   3.391  		
   3.392 -
   3.393 -(*====================================================================*)
   3.394 -(* ------------------------------------------------------------------------- *)
   3.395 -(* ------------------------------------------------------------------------- *)
   3.396 -(*Protocol for the proof of the backward direction of the cooper theorem.*)
   3.397 -(* Helpfunction - Protokols evereything about the proof reconstruction*)
   3.398 -(* ------------------------------------------------------------------------- *)
   3.399 -fun not_bst_p_wph fm = case fm of
   3.400 -	Const("Not",_) $ R => if (is_arith_rel R) then (Not_bst_p_atomic (fm)) else CpLogError
   3.401 -	|Const("op &",_) $ ls $ rs => Not_bst_p_conjI((not_bst_p_wph ls),(not_bst_p_wph rs))
   3.402 -	|Const("op |",_) $ ls $ rs => Not_bst_p_disjI((not_bst_p_wph ls),(not_bst_p_wph rs))
   3.403 -	|_ => Not_bst_p_atomic (fm);
   3.404 -(* ------------------------------------------------------------------------- *)	
   3.405 -(* Main protocoling function for the backward direction gives the Bset and the divlcm and the Formula herself. Needed as inherited attributes for the proof reconstruction*)
   3.406 -(* ------------------------------------------------------------------------- *)
   3.407 -fun not_bst_p_wp x fm = let val prt = not_bst_p_wph fm
   3.408 -			    val D = mk_numeral (divlcm x fm)
   3.409 -			    val B = map norm_zero_one (bset x fm)
   3.410 -			in (Not_bst_p (x,fm,D,(list_to_set HOLogic.intT B) , prt))
   3.411 -			end;
   3.412 -(*====================================================================*)
   3.413 -(* ------------------------------------------------------------------------- *)
   3.414 -(* ------------------------------------------------------------------------- *)
   3.415 -(*Protocol for the proof of the backward direction of the cooper theorem.*)
   3.416 -(* Helpfunction - Protokols evereything about the proof reconstruction*)
   3.417 -(* ------------------------------------------------------------------------- *)
   3.418 -fun not_ast_p_wph fm = case fm of
   3.419 -	Const("Not",_) $ R => if (is_arith_rel R) then (Not_ast_p_atomic (fm)) else CpLogError
   3.420 -	|Const("op &",_) $ ls $ rs => Not_ast_p_conjI((not_ast_p_wph ls),(not_ast_p_wph rs))
   3.421 -	|Const("op |",_) $ ls $ rs => Not_ast_p_disjI((not_ast_p_wph ls),(not_ast_p_wph rs))
   3.422 -	|_ => Not_ast_p_atomic (fm);
   3.423 -(* ------------------------------------------------------------------------- *)	
   3.424 -(* Main protocoling function for the backward direction gives the Bset and the divlcm and the Formula herself. Needed as inherited attributes for the proof reconstruction*)
   3.425 -(* ------------------------------------------------------------------------- *)
   3.426 -fun not_ast_p_wp x fm = let val prt = not_ast_p_wph fm
   3.427 -			    val D = mk_numeral (divlcm x fm)
   3.428 -			    val B = map norm_zero_one (aset x fm)
   3.429 -			in (Not_ast_p (x,fm,D,(list_to_set HOLogic.intT B) , prt))
   3.430 -			end;
   3.431 -
   3.432 -(*======================================================*)
   3.433 -(* Protokolgeneration for the formula evaluation process*)
   3.434 -(*======================================================*)
   3.435 -
   3.436 -fun evalc_wp fm = 
   3.437 -  let fun evalc_atom_wp at =case at of  
   3.438 -    (Const (p,_) $ s $ t) =>(  
   3.439 -    case assoc (operations,p) of 
   3.440 -        Some f => ((if (f ((dest_numeral s),(dest_numeral t))) then EvalAt(HOLogic.mk_eq(at,HOLogic.true_const)) else EvalAt(HOLogic.mk_eq(at, HOLogic.false_const)))  
   3.441 -		   handle _ => Evalfm(at)) 
   3.442 -        | _ =>  Evalfm(at)) 
   3.443 -     |Const("Not",_)$(Const (p,_) $ s $ t) =>(  
   3.444 -       case assoc (operations,p) of 
   3.445 -         Some f => ((if (f ((dest_numeral s),(dest_numeral t))) then 
   3.446 -	  EvalAt(HOLogic.mk_eq(at, HOLogic.false_const))  else EvalAt(HOLogic.mk_eq(at,HOLogic.true_const)))  
   3.447 -		      handle _ => Evalfm(at)) 
   3.448 -         | _ => Evalfm(at)) 
   3.449 -     | _ => Evalfm(at)  
   3.450 - 
   3.451 -  in
   3.452 -   case fm of
   3.453 -    (Const("op &",_)$A$B) => EvalConst("CJ",evalc_wp A,evalc_wp B)
   3.454 -   |(Const("op |",_)$A$B) => EvalConst("DJ",evalc_wp A,evalc_wp B) 
   3.455 -   |(Const("op -->",_)$A$B) => EvalConst("IM",evalc_wp A,evalc_wp B) 
   3.456 -   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => EvalConst("EQ",evalc_wp A,evalc_wp B) 
   3.457 -   |_ => evalc_atom_wp fm
   3.458 -  end;
   3.459 -
   3.460 -
   3.461 -
   3.462 -(*======================================================*)
   3.463 -(* Protokolgeneration for the NNF Transformation        *)
   3.464 -(*======================================================*)
   3.465 -
   3.466 -fun cnnf_wp f = 
   3.467 -  let fun hcnnf_wp fm =
   3.468 -    case fm of
   3.469 -    (Const ("op &",_) $ p $ q) => NNFConst("CJ",hcnnf_wp p,hcnnf_wp q) 
   3.470 -    | (Const ("op |",_) $ p $ q) =>  NNFConst("DJ",hcnnf_wp p,hcnnf_wp q)
   3.471 -    | (Const ("op -->",_) $ p $q) => NNFConst("IM",hcnnf_wp (HOLogic.Not $ p),hcnnf_wp q)
   3.472 -    | (Const ("op =",Type ("fun",[Type ("bool", []),_])) $ p $ q) => NNFConst("EQ",hcnnf_wp (HOLogic.mk_conj(p,q)),hcnnf_wp (HOLogic.mk_conj((HOLogic.Not $ p), (HOLogic.Not $ q)))) 
   3.473 -
   3.474 -    | (Const ("Not",_) $ (Const("Not",_) $ p)) => NNFNN(hcnnf_wp p) 
   3.475 -    | (Const ("Not",_) $ (Const ("op &",_) $ p $ q)) => NNFConst ("NCJ",(hcnnf_wp(HOLogic.Not $ p)),(hcnnf_wp(HOLogic.Not $ q))) 
   3.476 -    | (Const ("Not",_) $(Const ("op |",_) $ (A as (Const ("op &",_) $ p $ q)) $  
   3.477 -    			(B as (Const ("op &",_) $ p1 $ r)))) => if p1 = negate p then 
   3.478 -		         NNFConst("SDJ",  
   3.479 -			   NNFConst("CJ",hcnnf_wp p,hcnnf_wp(HOLogic.Not $ q)),
   3.480 -			   NNFConst("CJ",hcnnf_wp p1,hcnnf_wp(HOLogic.Not $ r)))
   3.481 -			 else  NNFConst ("NDJ",(hcnnf_wp(HOLogic.Not $ A)),(hcnnf_wp(HOLogic.Not $ B))) 
   3.482 -
   3.483 -    | (Const ("Not",_) $ (Const ("op |",_) $ p $ q)) => NNFConst ("NDJ",(hcnnf_wp(HOLogic.Not $ p)),(hcnnf_wp(HOLogic.Not $ q))) 
   3.484 -    | (Const ("Not",_) $ (Const ("op -->",_) $ p $q)) =>  NNFConst ("NIM",(hcnnf_wp(p)),(hcnnf_wp(HOLogic.Not $ q))) 
   3.485 -    | (Const ("Not",_) $ (Const ("op =",Type ("fun",[Type ("bool", []),_]))  $ p $ q)) =>NNFConst ("NEQ",(NNFConst("CJ",hcnnf_wp p,hcnnf_wp(HOLogic.Not $ q))),(NNFConst("CJ",hcnnf_wp(HOLogic.Not $ p),hcnnf_wp q))) 
   3.486 -    | _ => NNFAt(fm)  
   3.487 -  in NNFSimp(hcnnf_wp f)
   3.488 -end; 
   3.489 -   
   3.490 -
   3.491 -
   3.492 -
   3.493 -
   3.494 -
   3.495 -(* ------------------------------------------------------------------------- *)
   3.496 -(*Cooper decision Procedure with proof protocoling*)
   3.497 -(* ------------------------------------------------------------------------- *)
   3.498 -
   3.499 -fun coopermi_wp vars fm =
   3.500 -  case fm of
   3.501 -   Const ("Ex",_) $ Abs(xo,T,po) => let 
   3.502 -    val (xn,np) = variant_abs(xo,T,po) 
   3.503 -    val x = (Free(xn , T))
   3.504 -    val p = np     (* Is this a legal proof for the P=NP Problem??*)
   3.505 -    val (p_inf,miprt) = simpl_wp (minusinf_wp x p)
   3.506 -    val (bset,bsprt) = bset_wp x p
   3.507 -    val nbst_p_prt = not_bst_p_wp x p
   3.508 -    val dlcm = divlcm x p 
   3.509 -    val js = 1 upto dlcm 
   3.510 -    fun p_element j b = linrep vars x (linear_add vars b (mk_numeral j)) p 
   3.511 -    fun stage j = list_disj (linrep vars x (mk_numeral j) p_inf :: map (p_element j) bset) 
   3.512 -   in (list_disj (map stage js),Cooper(mk_numeral dlcm,miprt,bsprt,nbst_p_prt))
   3.513 -   end
   3.514 -   
   3.515 -  | _ => (error "cooper: not an existential formula",No);
   3.516 -				
   3.517 -fun cooperpi_wp vars fm =
   3.518 -  case fm of
   3.519 -   Const ("Ex",_) $ Abs(xo,T,po) => let 
   3.520 -    val (xn,np) = variant_abs(xo,T,po) 
   3.521 -    val x = (Free(xn , T))
   3.522 -    val p = np     (* Is this a legal proof for the P=NP Problem??*)
   3.523 -    val (p_inf,piprt) = simpl_wp (plusinf_wp x p)
   3.524 -    val (aset,asprt) = aset_wp x p
   3.525 -    val nast_p_prt = not_ast_p_wp x p
   3.526 -    val dlcm = divlcm x p 
   3.527 -    val js = 1 upto dlcm 
   3.528 -    fun p_element j a = linrep vars x (linear_sub vars a (mk_numeral j)) p 
   3.529 -    fun stage j = list_disj (linrep vars x (mk_numeral j) p_inf :: map (p_element j) aset) 
   3.530 -   in (list_disj (map stage js),Cooper(mk_numeral dlcm,piprt,asprt,nast_p_prt))
   3.531 -   end
   3.532 -  | _ => (error "cooper: not an existential formula",No);
   3.533 -				
   3.534 -
   3.535 -
   3.536 -
   3.537 -
   3.538 -(*-----------------------------------------------------------------*)
   3.539 -(*-----------------------------------------------------------------*)
   3.540 -(*-----------------------------------------------------------------*)
   3.541 -(*---                                                           ---*)
   3.542 -(*---                                                           ---*)
   3.543 -(*---      Interpretation and Proofgeneration Part              ---*)
   3.544 -(*---                                                           ---*)
   3.545 -(*---      Protocole interpretation functions                   ---*)
   3.546 -(*---                                                           ---*)
   3.547 -(*---      and proofgeneration functions                        ---*)
   3.548 -(*---                                                           ---*)
   3.549 -(*---                                                           ---*)
   3.550 -(*---                                                           ---*)
   3.551 -(*---                                                           ---*)
   3.552 -(*-----------------------------------------------------------------*)
   3.553 -(*-----------------------------------------------------------------*)
   3.554 -(*-----------------------------------------------------------------*)
   3.555 -
   3.556  (* ------------------------------------------------------------------------- *)
   3.557  (* Returns both sides of an equvalence in the theorem*)
   3.558  (* ------------------------------------------------------------------------- *)
   3.559  fun qe_get_terms th = let val (_$(Const("op =",Type ("fun",[Type ("bool", []),_])) $ A $ B )) = prop_of th in (A,B) end;
   3.560  
   3.561 -
   3.562 -(*-------------------------------------------------------------*)
   3.563 -(*-------------------------------------------------------------*)
   3.564 -(*-------------------------------------------------------------*)
   3.565 -(*-------------------------------------------------------------*)
   3.566 -
   3.567  (* ------------------------------------------------------------------------- *)
   3.568  (* Modified version of the simple version with minimal amount of checking and postprocessing*)
   3.569  (* ------------------------------------------------------------------------- *)
   3.570 @@ -664,9 +200,6 @@
   3.571  
   3.572  (*-------------------------------------------------------------*)
   3.573  (*-------------------------------------------------------------*)
   3.574 -(*-------------------------------------------------------------*)
   3.575 -(*-------------------------------------------------------------*)
   3.576 -(*-------------------------------------------------------------*)
   3.577  
   3.578  fun cert_Trueprop sg t = cterm_of sg (HOLogic.mk_Trueprop t);
   3.579  
   3.580 @@ -680,7 +213,8 @@
   3.581    (*"ss" like simplification with simpset*)
   3.582    "ss" =>
   3.583      let
   3.584 -      val ss = presburger_ss addsimps [zdvd_iff_zmod_eq_0]
   3.585 +      val ss = presburger_ss addsimps
   3.586 +        [zdvd_iff_zmod_eq_0,unity_coeff_ex]
   3.587        val ct =  cert_Trueprop sg fm2
   3.588      in 
   3.589        simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
   3.590 @@ -725,6 +259,14 @@
   3.591      in 
   3.592        simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
   3.593      end
   3.594 +  (* like Existance Conjunction *)
   3.595 +  | "ec" =>
   3.596 +    let
   3.597 +      val ss = presburger_ss addsimps zadd_ac
   3.598 +      val ct = cert_Trueprop sg fm2
   3.599 +    in 
   3.600 +      simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (blast_tac HOL_cs 1)]
   3.601 +    end
   3.602  
   3.603    | "ac" =>
   3.604      let
   3.605 @@ -742,80 +284,92 @@
   3.606        simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
   3.607      end;
   3.608  
   3.609 +(*=============================================================*)
   3.610 +(*-------------------------------------------------------------*)
   3.611 +(*              The new compact model                          *)
   3.612 +(*-------------------------------------------------------------*)
   3.613 +(*=============================================================*)
   3.614  
   3.615 +fun thm_of sg decomp t = 
   3.616 +    let val (ts,recomb) = decomp t 
   3.617 +    in recomb (map (thm_of sg decomp) ts) 
   3.618 +    end;
   3.619 +
   3.620 +(*==================================================*)
   3.621 +(*     Compact Version for adjustcoeffeq            *)
   3.622 +(*==================================================*)
   3.623 +
   3.624 +fun decomp_adjustcoeffeq sg x l fm = case fm of
   3.625 +    (Const("Not",_)$(Const("op <",_) $(Const("0",_)) $(rt as (Const ("op +", _)$(Const ("op *",_) $    c $ y ) $z )))) => 
   3.626 +     let  
   3.627 +        val m = l div (dest_numeral c) 
   3.628 +        val n = if (x = y) then abs (m) else 1
   3.629 +        val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) 
   3.630 +        val rs = if (x = y) 
   3.631 +                 then (HOLogic.mk_binrel "op <" (zero,linear_sub [] (mk_numeral n) (HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) 
   3.632 +                 else HOLogic.mk_binrel "op <" (zero,linear_sub [] one rt )
   3.633 +        val ck = cterm_of sg (mk_numeral n)
   3.634 +        val cc = cterm_of sg c
   3.635 +        val ct = cterm_of sg z
   3.636 +        val cx = cterm_of sg y
   3.637 +        val pre = prove_elementar sg "lf" 
   3.638 +            (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral n)))
   3.639 +        val th1 = (pre RS (instantiate' [] [Some ck,Some cc, Some cx, Some ct] (ac_pi_eq)))
   3.640 +        in ([], fn [] => [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   3.641 +        end
   3.642  
   3.643 -(* ------------------------------------------------------------------------- *)
   3.644 -(* This function return an Isabelle proof, of the adjustcoffeq result.*)
   3.645 -(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
   3.646 -(* ------------------------------------------------------------------------- *)
   3.647 -fun proof_of_adjustcoeffeq sg (prt,rs) = case prt of
   3.648 -   ACfm fm => instantiate' [Some cboolT]
   3.649 -    [Some (cterm_of sg fm)] refl
   3.650 - | ACAt (k,at as (Const(p,_) $a $( Const ("op +", _)$(Const ("op *",_) $ 
   3.651 -      c $ x ) $t ))) => 
   3.652 -   let
   3.653 -     val ck = cterm_of sg (mk_numeral k)
   3.654 -     val cc = cterm_of sg c
   3.655 -     val ct = cterm_of sg t
   3.656 -     val cx = cterm_of sg x
   3.657 -     val ca = cterm_of sg a
   3.658 -   in case p of
   3.659 -     "op <" => let val pre = prove_elementar sg "lf" 
   3.660 -	                  (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
   3.661 -	           val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_lt_eq)))
   3.662 -		      in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
   3.663 -                   end
   3.664 -    |"op =" =>let val pre = prove_elementar sg "lf" 
   3.665 +  |(Const(p,_) $a $( Const ("op +", _)$(Const ("op *",_) $ 
   3.666 +      c $ y ) $t )) => 
   3.667 +   if (is_arith_rel fm) andalso (x = y) 
   3.668 +   then  
   3.669 +        let val m = l div (dest_numeral c) 
   3.670 +           val k = (if p = "op <" then abs(m) else m)  
   3.671 +           val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div k)*l) ), x))
   3.672 +           val rs = (HOLogic.mk_binrel p ((linear_cmul k a),(HOLogic.mk_binop "op +" ( xtm ,( linear_cmul k t) )))) 
   3.673 +
   3.674 +           val ck = cterm_of sg (mk_numeral k)
   3.675 +           val cc = cterm_of sg c
   3.676 +           val ct = cterm_of sg t
   3.677 +           val cx = cterm_of sg x
   3.678 +           val ca = cterm_of sg a
   3.679 +
   3.680 +	   in 
   3.681 +	case p of
   3.682 +	  "op <" => 
   3.683 +	let val pre = prove_elementar sg "lf" 
   3.684 +	    (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
   3.685 +            val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_lt_eq)))
   3.686 +	in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   3.687 +         end
   3.688 +
   3.689 +           |"op =" =>
   3.690 +	     let val pre = prove_elementar sg "lf" 
   3.691  	    (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k))))
   3.692 -	          in let val th1 = (pre RS(instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_eq_eq)))
   3.693 -	             in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
   3.694 -                      end
   3.695 -                  end
   3.696 -    |"Divides.op dvd" =>let val pre = prove_elementar sg "lf" 
   3.697 +	         val th1 = (pre RS(instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_eq_eq)))
   3.698 +	     in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   3.699 +             end
   3.700 +
   3.701 +             |"Divides.op dvd" =>
   3.702 +	       let val pre = prove_elementar sg "lf" 
   3.703  	   (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k))))
   3.704 -	                 val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct]) (ac_dvd_eq))
   3.705 -                         in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
   3.706 +                   val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct]) (ac_dvd_eq))
   3.707 +               in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   3.708                          
   3.709 -                          end
   3.710 -  end
   3.711 - |ACPI(k,at as (Const("Not",_)$(Const("op <",_) $a $( Const ("op +", _)$(Const ("op *",_) $ c $ x ) $t )))) => 
   3.712 -   let
   3.713 -     val ck = cterm_of sg (mk_numeral k)
   3.714 -     val cc = cterm_of sg c
   3.715 -     val ct = cterm_of sg t
   3.716 -     val cx = cterm_of sg x
   3.717 -     val pre = prove_elementar sg "lf" 
   3.718 -       (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
   3.719 -       val th1 = (pre RS (instantiate' [] [Some ck,Some cc, Some cx, Some ct] (ac_pi_eq)))
   3.720 +               end
   3.721 +              end
   3.722 +  else ([], fn [] => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl)
   3.723 +
   3.724 + |( Const ("Not", _) $ p) => ([p], fn [th] => th RS qe_Not)
   3.725 +  |( Const ("op &",_) $ p $ q) => ([p,q], fn [th1,th2] => [th1,th2] MRS qe_conjI)
   3.726 +  |( Const ("op |",_) $ p $ q) =>([p,q], fn [th1,th2] => [th1,th2] MRS qe_disjI)
   3.727  
   3.728 -         in [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
   3.729 -   end
   3.730 - |ACNeg(pr) => let val (Const("Not",_)$nrs) = rs
   3.731 -               in (proof_of_adjustcoeffeq sg (pr,nrs)) RS (qe_Not) 
   3.732 -               end
   3.733 - |ACConst(s,pr1,pr2) =>
   3.734 -   let val (Const(_,_)$rs1$rs2) = rs
   3.735 -       val th1 = proof_of_adjustcoeffeq sg (pr1,rs1)
   3.736 -       val th2 = proof_of_adjustcoeffeq sg (pr2,rs2)
   3.737 -       in case s of 
   3.738 -	 "CJ" => [th1,th2] MRS (qe_conjI)
   3.739 -         |"DJ" => [th1,th2] MRS (qe_disjI)
   3.740 -         |"IM" => [th1,th2] MRS (qe_impI)
   3.741 -         |"EQ" => [th1,th2] MRS (qe_eqI)
   3.742 -   end;
   3.743 +  |_ => ([], fn [] => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl);
   3.744  
   3.745 -
   3.746 -
   3.747 -
   3.748 -
   3.749 -
   3.750 -(* ------------------------------------------------------------------------- *)
   3.751 -(* This function return an Isabelle proof, of some properties on the atoms*)
   3.752 -(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
   3.753 -(* This function doese only instantiate the the theorems in the theory *)
   3.754 -(* ------------------------------------------------------------------------- *)
   3.755 -fun atomar_minf_proof_of sg dlcm (Modd_minf (x,fm1)) =
   3.756 -  let
   3.757 +(*==================================================*)
   3.758 +(*   Finding rho for modd_minusinfinity             *)
   3.759 +(*==================================================*)
   3.760 +fun rho_for_modd_minf x dlcm sg fm1 =
   3.761 +let
   3.762      (*Some certified Terms*)
   3.763      
   3.764     val ctrue = cterm_of sg HOLogic.true_const
   3.765 @@ -853,10 +407,11 @@
   3.766  		
   3.767      
   3.768     |_ => instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_minf)
   3.769 -   end	
   3.770 -
   3.771 - |atomar_minf_proof_of sg dlcm (Eq_minf (x,fm1)) =  let
   3.772 -       (*Some certified types*)
   3.773 +   end;	 
   3.774 +(*=========================================================================*)
   3.775 +(*=========================================================================*)
   3.776 +fun rho_for_eq_minf x dlcm  sg fm1 =  
   3.777 +   let
   3.778     val fm = norm_zero_one fm1
   3.779      in  case fm1 of 
   3.780        (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
   3.781 @@ -893,70 +448,24 @@
   3.782      |_ => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_minf))
   3.783   end;
   3.784  
   3.785 -
   3.786 -(* ------------------------------------------------------------------------- *)
   3.787 -(* This function combines proofs of some special form already synthetised from the subtrees to make*)
   3.788 -(* a new proof of the same form. The combination occures whith isabelle theorems which have been already prooved *)
   3.789 -(*these Theorems are in Presburger.thy and mostly do not relay on the arithmetic.*)
   3.790 -(* These are Theorems for the Property of P_{-infty}*)
   3.791 -(* ------------------------------------------------------------------------- *)
   3.792 -fun combine_minf_proof s pr1 pr2 = case s of
   3.793 -    "ECJ" => [pr1 , pr2] MRS (eq_minf_conjI)
   3.794 -
   3.795 -   |"EDJ" => [pr1 , pr2] MRS (eq_minf_disjI)
   3.796 -   
   3.797 -   |"MCJ" => [pr1 , pr2] MRS (modd_minf_conjI)
   3.798 -
   3.799 -   |"MDJ" => [pr1 , pr2] MRS (modd_minf_disjI);
   3.800 -
   3.801 -(* ------------------------------------------------------------------------- *)
   3.802 -(*This function return an isabelle Proof for the minusinfinity theorem*)
   3.803 -(* It interpretates the protool and gives the protokoles property of P_{...} as a theorem*)
   3.804 -(* ------------------------------------------------------------------------- *)
   3.805 -fun minf_proof_ofh sg dlcm prl = case prl of 
   3.806 +(*=====================================================*)
   3.807 +(*=====================================================*)
   3.808 +(*=========== minf proofs with the compact version==========*)
   3.809 +fun decomp_minf_eq x dlcm sg t =  case t of
   3.810 +   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_minf_conjI)
   3.811 +   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_minf_disjI)
   3.812 +   |_ => ([],fn [] => rho_for_eq_minf x dlcm sg t);
   3.813  
   3.814 -    Eq_minf (_) => atomar_minf_proof_of sg dlcm prl
   3.815 -    
   3.816 -   |Modd_minf (_) => atomar_minf_proof_of sg dlcm prl
   3.817 -   
   3.818 -   |Eq_minf_conjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
   3.819 -   				    val pr2 = minf_proof_ofh sg dlcm prl2
   3.820 -				 in (combine_minf_proof "ECJ" pr1 pr2)
   3.821 -				 end
   3.822 -				 
   3.823 -   |Eq_minf_disjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
   3.824 -   				    val pr2 = minf_proof_ofh sg dlcm prl2
   3.825 -				 in (combine_minf_proof "EDJ" pr1 pr2)
   3.826 -				 end
   3.827 -				 
   3.828 -   |Modd_minf_conjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
   3.829 -   				    val pr2 = minf_proof_ofh sg dlcm prl2
   3.830 -				 in (combine_minf_proof "MCJ" pr1 pr2)
   3.831 -				 end
   3.832 -				 
   3.833 -   |Modd_minf_disjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
   3.834 -   				    val pr2 = minf_proof_ofh sg dlcm prl2
   3.835 -				 in (combine_minf_proof "MDJ" pr1 pr2)
   3.836 -				 end;
   3.837 -(* ------------------------------------------------------------------------- *)
   3.838 -(* Main function For the rest both properies of P_{..} are needed and here both theorems are returned.*)				 
   3.839 -(* ------------------------------------------------------------------------- *)
   3.840 -fun  minf_proof_of sg dlcm (Minusinf (prl1,prl2))  = 
   3.841 -  let val pr1 = minf_proof_ofh sg dlcm prl1
   3.842 -      val pr2 = minf_proof_ofh sg dlcm prl2
   3.843 -  in (pr1, pr2)
   3.844 -end;
   3.845 -				 
   3.846 +fun decomp_minf_modd x dlcm sg t = case t of
   3.847 +   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_minf_conjI)
   3.848 +   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_minf_disjI)
   3.849 +   |_ => ([],fn [] => rho_for_modd_minf x dlcm sg t);
   3.850  
   3.851 -
   3.852 -
   3.853 -(* ------------------------------------------------------------------------- *)
   3.854 -(* This function return an Isabelle proof, of some properties on the atoms*)
   3.855 -(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
   3.856 -(* This function doese only instantiate the the theorems in the theory *)
   3.857 -(* ------------------------------------------------------------------------- *)
   3.858 -fun atomar_pinf_proof_of sg dlcm (Modd_minf (x,fm1)) =
   3.859 - let
   3.860 +(* -------------------------------------------------------------*)
   3.861 +(*                    Finding rho for pinf_modd                 *)
   3.862 +(* -------------------------------------------------------------*)
   3.863 +fun rho_for_modd_pinf x dlcm sg fm1 = 
   3.864 +let
   3.865      (*Some certified Terms*)
   3.866      
   3.867    val ctrue = cterm_of sg HOLogic.true_const
   3.868 @@ -996,9 +505,12 @@
   3.869  		
   3.870      
   3.871     |_ => instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_pinf)
   3.872 -   end	
   3.873 -
   3.874 - |atomar_pinf_proof_of sg dlcm (Eq_minf (x,fm1)) =  let
   3.875 +   end;	
   3.876 +(* -------------------------------------------------------------*)
   3.877 +(*                    Finding rho for pinf_eq                 *)
   3.878 +(* -------------------------------------------------------------*)
   3.879 +fun rho_for_eq_pinf x dlcm sg fm1 = 
   3.880 +  let
   3.881  					val fm = norm_zero_one fm1
   3.882      in  case fm1 of 
   3.883        (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
   3.884 @@ -1036,67 +548,58 @@
   3.885   end;
   3.886  
   3.887  
   3.888 -(* ------------------------------------------------------------------------- *)
   3.889 -(* This function combines proofs of some special form already synthetised from the subtrees to make*)
   3.890 -(* a new proof of the same form. The combination occures whith isabelle theorems which have been already prooved *)
   3.891 -(*these Theorems are in Presburger.thy and mostly do not relay on the arithmetic.*)
   3.892 -(* These are Theorems for the Property of P_{+infty}*)
   3.893 -(* ------------------------------------------------------------------------- *)
   3.894 -fun combine_pinf_proof s pr1 pr2 = case s of
   3.895 -    "ECJ" => [pr1 , pr2] MRS (eq_pinf_conjI)
   3.896 +
   3.897 +fun  minf_proof_of_c sg x dlcm t =
   3.898 +  let val minf_eqth   = thm_of sg (decomp_minf_eq x dlcm sg) t
   3.899 +      val minf_moddth = thm_of sg (decomp_minf_modd x dlcm sg) t
   3.900 +  in (minf_eqth, minf_moddth)
   3.901 +end;
   3.902  
   3.903 -   |"EDJ" => [pr1 , pr2] MRS (eq_pinf_disjI)
   3.904 -   
   3.905 -   |"MCJ" => [pr1 , pr2] MRS (modd_pinf_conjI)
   3.906 +(*=========== pinf proofs with the compact version==========*)
   3.907 +fun decomp_pinf_eq x dlcm sg t = case t of
   3.908 +   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_conjI)
   3.909 +   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_disjI)
   3.910 +   |_ =>([],fn [] => rho_for_eq_pinf x dlcm sg t) ;
   3.911  
   3.912 -   |"MDJ" => [pr1 , pr2] MRS (modd_pinf_disjI);
   3.913 +fun decomp_pinf_modd x dlcm sg t =  case t of
   3.914 +   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_conjI)
   3.915 +   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_disjI)
   3.916 +   |_ => ([],fn [] => rho_for_modd_pinf x dlcm sg t);
   3.917 +
   3.918 +fun  pinf_proof_of_c sg x dlcm t =
   3.919 +  let val pinf_eqth   = thm_of sg (decomp_pinf_eq x dlcm sg) t
   3.920 +      val pinf_moddth = thm_of sg (decomp_pinf_modd x dlcm sg) t
   3.921 +  in (pinf_eqth,pinf_moddth)
   3.922 +end;
   3.923 +
   3.924  
   3.925  (* ------------------------------------------------------------------------- *)
   3.926 -(*This function return an isabelle Proof for the minusinfinity theorem*)
   3.927 -(* It interpretates the protool and gives the protokoles property of P_{...} as a theorem*)
   3.928 +(* Here we generate the theorem for the Bset Property in the simple direction*)
   3.929 +(* It is just an instantiation*)
   3.930  (* ------------------------------------------------------------------------- *)
   3.931 -fun pinf_proof_ofh sg dlcm prl = case prl of 
   3.932 +(*
   3.933 +fun bsetproof_of sg (x as Free(xn,xT)) fm bs dlcm   = 
   3.934 +  let
   3.935 +    val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
   3.936 +    val cdlcm = cterm_of sg dlcm
   3.937 +    val cB = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one bs))
   3.938 +  in instantiate' [] [Some cdlcm,Some cB, Some cp] (bst_thm)
   3.939 +end;
   3.940  
   3.941 -    Eq_minf (_) => atomar_pinf_proof_of sg dlcm prl
   3.942 -    
   3.943 -   |Modd_minf (_) => atomar_pinf_proof_of sg dlcm prl
   3.944 -   
   3.945 -   |Eq_minf_conjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
   3.946 -   				    val pr2 = pinf_proof_ofh sg dlcm prl2
   3.947 -				 in (combine_pinf_proof "ECJ" pr1 pr2)
   3.948 -				 end
   3.949 -				 
   3.950 -   |Eq_minf_disjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
   3.951 -   				    val pr2 = pinf_proof_ofh sg dlcm prl2
   3.952 -				 in (combine_pinf_proof "EDJ" pr1 pr2)
   3.953 -				 end
   3.954 -				 
   3.955 -   |Modd_minf_conjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
   3.956 -   				    val pr2 = pinf_proof_ofh sg dlcm prl2
   3.957 -				 in (combine_pinf_proof "MCJ" pr1 pr2)
   3.958 -				 end
   3.959 -				 
   3.960 -   |Modd_minf_disjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
   3.961 -   				    val pr2 = pinf_proof_ofh sg dlcm prl2
   3.962 -				 in (combine_pinf_proof "MDJ" pr1 pr2)
   3.963 -				 end;
   3.964 -(* ------------------------------------------------------------------------- *)
   3.965 -(* Main function For the rest both properies of P_{..} are needed and here both theorems are returned.*)				 
   3.966 -(* ------------------------------------------------------------------------- *)
   3.967 -fun pinf_proof_of sg dlcm (Minusinf (prl1,prl2))  = 
   3.968 -  let val pr1 = pinf_proof_ofh sg dlcm prl1
   3.969 -      val pr2 = pinf_proof_ofh sg dlcm prl2
   3.970 -  in (pr1, pr2)
   3.971 +fun asetproof_of sg (x as Free(xn,xT)) fm ast dlcm = 
   3.972 +  let
   3.973 +    val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
   3.974 +    val cdlcm = cterm_of sg dlcm
   3.975 +    val cA = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one ast))
   3.976 +  in instantiate' [] [Some cdlcm,Some cA, Some cp] (ast_thm)
   3.977  end;
   3.978 -				 
   3.979 -
   3.980 -
   3.981 -(* ------------------------------------------------------------------------- *)    
   3.982 -(* Protokol interpretation function for the backwards direction for cooper's Theorem*)
   3.983 +*)
   3.984  
   3.985  (* For the generation of atomic Theorems*)
   3.986  (* Prove the premisses on runtime and then make RS*)
   3.987  (* ------------------------------------------------------------------------- *)
   3.988 +
   3.989 +(*========= this is rho ============*)
   3.990  fun generate_atomic_not_bst_p sg (x as Free(xn,xT)) fm dlcm B at = 
   3.991    let
   3.992      val cdlcm = cterm_of sg dlcm
   3.993 @@ -1157,28 +660,23 @@
   3.994        		
   3.995      end;
   3.996      
   3.997 +
   3.998  (* ------------------------------------------------------------------------- *)    
   3.999  (* Main interpretation function for this backwards dirction*)
  3.1000  (* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*)
  3.1001  (*Help Function*)
  3.1002  (* ------------------------------------------------------------------------- *)
  3.1003 -fun not_bst_p_proof_of_h sg x fm dlcm B prt = case prt of 
  3.1004 -	(Not_bst_p_atomic(fm2)) => (generate_atomic_not_bst_p sg x fm dlcm B fm2)
  3.1005 -	
  3.1006 -	|(Not_bst_p_conjI(pr1,pr2)) => 
  3.1007 -			let val th1 = (not_bst_p_proof_of_h sg x fm dlcm B pr1)
  3.1008 -			    val th2 = (not_bst_p_proof_of_h sg x fm dlcm B pr2)
  3.1009 -			    in ([th1,th2] MRS (not_bst_p_conjI))
  3.1010 -			    end
  3.1011 +
  3.1012 +(*==================== Proof with the compact version   *)
  3.1013  
  3.1014 -	|(Not_bst_p_disjI(pr1,pr2)) => 
  3.1015 -			let val th1 = (not_bst_p_proof_of_h sg x fm dlcm B pr1)
  3.1016 -			    val th2 = (not_bst_p_proof_of_h sg x fm dlcm B pr2)
  3.1017 -			    in ([th1,th2] MRS not_bst_p_disjI)
  3.1018 -			    end;
  3.1019 -(* Main function*)
  3.1020 -fun not_bst_p_proof_of sg (Not_bst_p(x as Free(xn,xT),fm,dlcm,B,prl)) =
  3.1021 -  let val th =  not_bst_p_proof_of_h sg x fm dlcm B prl
  3.1022 +fun decomp_nbstp sg x dlcm B fm t = case t of 
  3.1023 +   Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_bst_p_conjI )
  3.1024 +  |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_bst_p_disjI)
  3.1025 +  |_ => ([], fn [] => generate_atomic_not_bst_p sg x fm dlcm B t);
  3.1026 +
  3.1027 +fun not_bst_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm B t =
  3.1028 +  let 
  3.1029 +       val th =  thm_of sg (decomp_nbstp sg x dlcm (list_to_set xT (map norm_zero_one B)) fm) t
  3.1030        val fma = absfree (xn,xT, norm_zero_one fm)
  3.1031    in let val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
  3.1032       in [th,th1] MRS (not_bst_p_Q_elim)
  3.1033 @@ -1192,6 +690,7 @@
  3.1034  (* For the generation of atomic Theorems*)
  3.1035  (* Prove the premisses on runtime and then make RS*)
  3.1036  (* ------------------------------------------------------------------------- *)
  3.1037 +(*========= this is rho ============*)
  3.1038  fun generate_atomic_not_ast_p sg (x as Free(xn,xT)) fm dlcm A at = 
  3.1039    let
  3.1040      val cdlcm = cterm_of sg dlcm
  3.1041 @@ -1250,81 +749,109 @@
  3.1042     |_ => (instantiate' [] [Some cfma,  Some cdlcm, Some cA,Some cat] (not_ast_p_fm))
  3.1043        		
  3.1044      end;
  3.1045 -    
  3.1046 -(* ------------------------------------------------------------------------- *)    
  3.1047 +
  3.1048 +(* ------------------------------------------------------------------------ *)
  3.1049  (* Main interpretation function for this backwards dirction*)
  3.1050  (* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*)
  3.1051  (*Help Function*)
  3.1052  (* ------------------------------------------------------------------------- *)
  3.1053 -fun not_ast_p_proof_of_h sg x fm dlcm A prt = case prt of 
  3.1054 -	(Not_ast_p_atomic(fm2)) => (generate_atomic_not_ast_p sg x fm dlcm A fm2)
  3.1055 -	
  3.1056 -	|(Not_ast_p_conjI(pr1,pr2)) => 
  3.1057 -			let val th1 = (not_ast_p_proof_of_h sg x fm dlcm A pr1)
  3.1058 -			    val th2 = (not_ast_p_proof_of_h sg x fm dlcm A pr2)
  3.1059 -			    in ([th1,th2] MRS (not_ast_p_conjI))
  3.1060 -			    end
  3.1061 +
  3.1062 +fun decomp_nastp sg x dlcm A fm t = case t of 
  3.1063 +   Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_conjI )
  3.1064 +  |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_disjI)
  3.1065 +  |_ => ([], fn [] => generate_atomic_not_ast_p sg x fm dlcm A t);
  3.1066  
  3.1067 -	|(Not_ast_p_disjI(pr1,pr2)) => 
  3.1068 -			let val th1 = (not_ast_p_proof_of_h sg x fm dlcm A pr1)
  3.1069 -			    val th2 = (not_ast_p_proof_of_h sg x fm dlcm A pr2)
  3.1070 -			    in ([th1,th2] MRS (not_ast_p_disjI))
  3.1071 -			    end;
  3.1072 -(* Main function*)
  3.1073 -fun not_ast_p_proof_of sg (Not_ast_p(x as Free(xn,xT),fm,dlcm,A,prl)) =
  3.1074 -  let val th =  not_ast_p_proof_of_h sg x fm dlcm A prl
  3.1075 +fun not_ast_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm A t =
  3.1076 +  let 
  3.1077 +       val th =  thm_of sg (decomp_nastp sg x dlcm (list_to_set xT (map norm_zero_one A)) fm) t
  3.1078        val fma = absfree (xn,xT, norm_zero_one fm)
  3.1079 -      val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
  3.1080 -  in [th,th1] MRS (not_ast_p_Q_elim)
  3.1081 -end;
  3.1082 +  in let val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
  3.1083 +     in [th,th1] MRS (not_ast_p_Q_elim)
  3.1084 +     end
  3.1085 +  end;
  3.1086  
  3.1087  
  3.1088 +(* -------------------------------*)
  3.1089 +(* Finding rho and beta for evalc *)
  3.1090 +(* -------------------------------*)
  3.1091  
  3.1092 +fun rho_for_evalc sg at = case at of  
  3.1093 +    (Const (p,_) $ s $ t) =>(  
  3.1094 +    case assoc (operations,p) of 
  3.1095 +        Some f => 
  3.1096 +           ((if (f ((dest_numeral s),(dest_numeral t))) 
  3.1097 +             then prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const)) 
  3.1098 +             else prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const)))  
  3.1099 +		   handle _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl
  3.1100 +        | _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl )) 
  3.1101 +     |Const("Not",_)$(Const (p,_) $ s $ t) =>(  
  3.1102 +       case assoc (operations,p) of 
  3.1103 +         Some f => 
  3.1104 +           ((if (f ((dest_numeral s),(dest_numeral t))) 
  3.1105 +             then prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const))  
  3.1106 +             else prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const)))  
  3.1107 +		      handle _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl) 
  3.1108 +         | _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl ) 
  3.1109 +     | _ =>   instantiate' [Some cboolT] [Some (cterm_of sg at)] refl;
  3.1110 +
  3.1111 +
  3.1112 +(*=========================================================*)
  3.1113 +fun decomp_evalc sg t = case t of
  3.1114 +   (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
  3.1115 +   |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
  3.1116 +   |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
  3.1117 +   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
  3.1118 +   |_ => ([], fn [] => rho_for_evalc sg t);
  3.1119 +
  3.1120 +
  3.1121 +fun proof_of_evalc sg fm = thm_of sg (decomp_evalc sg) fm;
  3.1122 +
  3.1123 +(*==================================================*)
  3.1124 +(*     Proof of linform with the compact model      *)
  3.1125 +(*==================================================*)
  3.1126 +
  3.1127 +
  3.1128 +fun decomp_linform sg vars t = case t of
  3.1129 +   (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
  3.1130 +   |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
  3.1131 +   |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
  3.1132 +   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
  3.1133 +   |(Const("Not",_)$p) => ([p],fn [th] => th RS qe_Not)
  3.1134 +   |(Const("Divides.op dvd",_)$d$r) => ([], fn [] => (prove_elementar sg "lf" (HOLogic.mk_eq (r, lint vars r))) RS (instantiate' [] [None , None, Some (cterm_of sg d)](linearize_dvd)))
  3.1135 +   |_ => ([], fn [] => prove_elementar sg "lf" (HOLogic.mk_eq (t, linform vars t)));
  3.1136 +
  3.1137 +fun proof_of_linform sg vars f = thm_of sg (decomp_linform sg vars) f;
  3.1138  
  3.1139  (* ------------------------------------------------------------------------- *)
  3.1140  (* Interpretaion of Protocols of the cooper procedure : minusinfinity version*)
  3.1141  (* ------------------------------------------------------------------------- *)
  3.1142 -
  3.1143 -
  3.1144 -fun coopermi_proof_of sg x (Cooper (dlcm,Simp(fm,miprt),bsprt,nbst_p_prt)) =
  3.1145 +fun coopermi_proof_of sg (x as Free(xn,xT)) fm B dlcm =
  3.1146    (* Get the Bset thm*)
  3.1147 -  let val (mit1,mit2) = minf_proof_of sg dlcm miprt
  3.1148 -      val fm1 = norm_zero_one (simpl fm) 
  3.1149 +  let val (minf_eqth, minf_moddth) = minf_proof_of_c sg x dlcm fm 
  3.1150        val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm));
  3.1151 -      val nbstpthm = not_bst_p_proof_of sg nbst_p_prt
  3.1152 -    (* Return the four theorems needed to proove the whole Cooper Theorem*)
  3.1153 -  in (dpos,mit2,nbstpthm,mit1)
  3.1154 +      val nbstpthm = not_bst_p_proof_of_c sg x fm dlcm B fm
  3.1155 +  in (dpos,minf_eqth,nbstpthm,minf_moddth)
  3.1156  end;
  3.1157  
  3.1158 -
  3.1159  (* ------------------------------------------------------------------------- *)
  3.1160  (* Interpretaion of Protocols of the cooper procedure : plusinfinity version *)
  3.1161  (* ------------------------------------------------------------------------- *)
  3.1162 -
  3.1163 -
  3.1164 -fun cooperpi_proof_of sg x (Cooper (dlcm,Simp(fm,miprt),bsprt,nast_p_prt)) =
  3.1165 -  let val (mit1,mit2) = pinf_proof_of sg dlcm miprt
  3.1166 -      val fm1 = norm_zero_one (simpl fm) 
  3.1167 +fun cooperpi_proof_of sg (x as Free(xn,xT)) fm A dlcm =
  3.1168 +  let val (pinf_eqth,pinf_moddth) = pinf_proof_of_c sg x dlcm fm
  3.1169        val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm));
  3.1170 -      val nastpthm = not_ast_p_proof_of sg nast_p_prt
  3.1171 -  in (dpos,mit2,nastpthm,mit1)
  3.1172 +      val nastpthm = not_ast_p_proof_of_c sg x fm dlcm A fm
  3.1173 +  in (dpos,pinf_eqth,nastpthm,pinf_moddth)
  3.1174  end;
  3.1175  
  3.1176 -
  3.1177  (* ------------------------------------------------------------------------- *)
  3.1178  (* Interpretaion of Protocols of the cooper procedure : full version*)
  3.1179  (* ------------------------------------------------------------------------- *)
  3.1180 -
  3.1181 -
  3.1182 -
  3.1183 -fun cooper_thm sg s (x as Free(xn,xT)) vars cfm = case s of
  3.1184 -  "pi" => let val (rs,prt) = cooperpi_wp (xn::vars) (HOLogic.mk_exists(xn,xT,cfm))
  3.1185 -	      val (dpsthm,th1,nbpth,th3) = cooperpi_proof_of sg x prt
  3.1186 -		   in [dpsthm,th1,nbpth,th3] MRS (cppi_eq)
  3.1187 +fun cooper_thm sg s (x as Free(xn,xT)) cfm dlcm ast bst= case s of
  3.1188 +  "pi" => let val (dpsthm,pinf_eqth,nbpth,pinf_moddth) = cooperpi_proof_of sg x cfm ast dlcm 
  3.1189 +	      in [dpsthm,pinf_eqth,nbpth,pinf_moddth] MRS (cppi_eq)
  3.1190             end
  3.1191 -  |"mi" => let val (rs,prt) = coopermi_wp (xn::vars) (HOLogic.mk_exists(xn,xT,cfm))
  3.1192 -	       val (dpsthm,th1,nbpth,th3) = coopermi_proof_of sg x prt
  3.1193 -		   in [dpsthm,th1,nbpth,th3] MRS (cpmi_eq)
  3.1194 +  |"mi" => let val (dpsthm,minf_eqth,nbpth,minf_moddth) = coopermi_proof_of sg x cfm bst dlcm
  3.1195 +	       in [dpsthm,minf_eqth,nbpth,minf_moddth] MRS (cpmi_eq)
  3.1196                  end
  3.1197   |_ => error "parameter error";
  3.1198  
  3.1199 @@ -1333,9 +860,11 @@
  3.1200  (* It shoud be plugged in the qfnp argument of the quantifier elimination proof function*)
  3.1201  (* ------------------------------------------------------------------------- *)
  3.1202  
  3.1203 -fun cooper_prv sg (x as Free(xn,xT)) efm vars = let 
  3.1204 -   val l = formlcm x efm
  3.1205 -   val ac_thm = proof_of_adjustcoeffeq sg (adjustcoeffeq_wp  x l efm)
  3.1206 +fun cooper_prv sg (x as Free(xn,xT)) efm = let 
  3.1207 +   val lfm_thm = proof_of_linform sg [xn] efm
  3.1208 +   val efm2 = snd(qe_get_terms lfm_thm)
  3.1209 +   val l = formlcm x efm2
  3.1210 +   val ac_thm = [lfm_thm , (thm_of sg (decomp_adjustcoeffeq sg x l) efm2)] MRS trans
  3.1211     val fm = snd (qe_get_terms ac_thm)
  3.1212     val  cfm = unitycoeff x fm
  3.1213     val afm = adjustcoeff x l fm
  3.1214 @@ -1344,8 +873,11 @@
  3.1215       [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff]
  3.1216     val uth = instantiate' [] [Some (cterm_of sg P) , Some (cterm_of sg (mk_numeral l))] (unity_coeff_ex)
  3.1217     val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI)
  3.1218 -   val cms = if ((length (aset x cfm)) < (length (bset x cfm))) then "pi" else "mi"
  3.1219 -   val cp_thm = cooper_thm sg cms x vars cfm
  3.1220 +   val A = aset x cfm
  3.1221 +   val B = bset x cfm
  3.1222 +   val dlcm = mk_numeral (divlcm x cfm)
  3.1223 +   val cms = if ((length A) < (length B )) then "pi" else "mi"
  3.1224 +   val cp_thm = cooper_thm sg cms x cfm dlcm A B
  3.1225     val exp_cp_thm = refl RS (simplify ss (cp_thm RSN (2,trans)))
  3.1226     val (lsuth,rsuth) = qe_get_terms (uth)
  3.1227     val (lseacth,rseacth) = qe_get_terms(e_ac_thm)
  3.1228 @@ -1353,98 +885,46 @@
  3.1229     val  u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans
  3.1230   in  ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans)
  3.1231     end
  3.1232 -|cooper_prv _ _ _ _ = error "Parameters format";
  3.1233 +|cooper_prv _ _ _ =  error "Parameters format";
  3.1234 +
  3.1235  
  3.1236  
  3.1237 -(*====================================================*)
  3.1238 -(*Interpretation function for the evaluation protokol *)
  3.1239 -(*====================================================*)
  3.1240 -
  3.1241 -fun proof_of_evalc sg fm =
  3.1242 -let
  3.1243 -fun proof_of_evalch prt = case prt of
  3.1244 -  EvalAt(at) => prove_elementar sg "ss" at
  3.1245 - |Evalfm(fm) => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl
  3.1246 - |EvalConst(s,pr1,pr2) => 
  3.1247 -   let val th1 = proof_of_evalch pr1
  3.1248 -       val th2 = proof_of_evalch pr2
  3.1249 -   in case s of
  3.1250 -     "CJ" =>[th1,th2] MRS (qe_conjI)
  3.1251 -    |"DJ" =>[th1,th2] MRS (qe_disjI)
  3.1252 -    |"IM" =>[th1,th2] MRS (qe_impI)
  3.1253 -    |"EQ" =>[th1,th2] MRS (qe_eqI)
  3.1254 -    end
  3.1255 -in proof_of_evalch (evalc_wp fm)
  3.1256 -end;
  3.1257 -
  3.1258 -(*============================================================*)
  3.1259 -(*Interpretation function for the NNF-Transformation protokol *)
  3.1260 -(*============================================================*)
  3.1261 +fun decomp_cnnf sg lfnp P = case P of 
  3.1262 +     Const ("op &",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS qe_conjI )
  3.1263 +   |Const ("op |",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS  qe_disjI)
  3.1264 +   |Const ("Not",_) $ (Const("Not",_) $ p) => ([p], fn [th] => th RS nnf_nn)
  3.1265 +   |Const("Not",_) $ (Const(opn,T) $ p $ q) => 
  3.1266 +     if opn = "op |" 
  3.1267 +      then case (p,q) of 
  3.1268 +         (A as (Const ("op &",_) $ r $ s),B as (Const ("op &",_) $ r1 $ t)) =>
  3.1269 +          if r1 = negate r 
  3.1270 +          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)
  3.1271  
  3.1272 -fun proof_of_cnnf sg fm pf = 
  3.1273 -let fun proof_of_cnnfh prt pat = case prt of
  3.1274 -  NNFAt(at) => pat at
  3.1275 - |NNFSimp (pr) => let val th1 = proof_of_cnnfh pr pat
  3.1276 -                  in let val fm2 = snd (qe_get_terms th1) 
  3.1277 -		     in [th1,prove_elementar sg "ss" (HOLogic.mk_eq(fm2 ,simpl fm2))] MRS trans
  3.1278 -                     end
  3.1279 -                  end
  3.1280 - |NNFNN (pr) => (proof_of_cnnfh pr pat) RS (nnf_nn)
  3.1281 - |NNFConst (s,pr1,pr2) =>
  3.1282 -   let val th1 = proof_of_cnnfh pr1 pat
  3.1283 -       val th2 = proof_of_cnnfh pr2 pat
  3.1284 -   in case s of
  3.1285 -     "CJ" => [th1,th2] MRS (qe_conjI)
  3.1286 -    |"DJ" => [th1,th2] MRS (qe_disjI)
  3.1287 -    |"IM" => [th1,th2] MRS (nnf_im)
  3.1288 -    |"EQ" => [th1,th2] MRS (nnf_eq)
  3.1289 -    |"SDJ" => let val (Const("op &",_)$A$_) = fst (qe_get_terms th1)
  3.1290 -	          val (Const("op &",_)$C$_) = fst (qe_get_terms th2)
  3.1291 -	      in [th1,th2,prove_elementar sg "ss" (HOLogic.mk_eq (A,HOLogic.Not $ C))] MRS (nnf_sdj)
  3.1292 -	      end
  3.1293 -    |"NCJ" => [th1,th2] MRS (nnf_ncj)
  3.1294 -    |"NIM" => [th1,th2] MRS (nnf_nim)
  3.1295 -    |"NEQ" => [th1,th2] MRS (nnf_neq)
  3.1296 -    |"NDJ" => [th1,th2] MRS (nnf_ndj)
  3.1297 -   end
  3.1298 -in proof_of_cnnfh (cnnf_wp fm) pf
  3.1299 -end;
  3.1300 +          else ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj)
  3.1301 +        |(_,_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj)
  3.1302 +      else (
  3.1303 +         case (opn,T) of 
  3.1304 +           ("op &",_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_ncj )
  3.1305 +           |("op -->",_) => ([p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_nim )
  3.1306 +           |("op =",Type ("fun",[Type ("bool", []),_])) => 
  3.1307 +           ([HOLogic.conj $ p $ (HOLogic.Not $ q),HOLogic.conj $ (HOLogic.Not $ p) $ q], fn [th1,th2] => [th1,th2] MRS nnf_neq)
  3.1308 +            |(_,_) => ([], fn [] => lfnp P)
  3.1309 +)
  3.1310 +
  3.1311 +   |(Const ("op -->",_) $ p $ q) => ([HOLogic.Not$p,q], fn [th1,th2] => [th1,th2] MRS nnf_im)
  3.1312 +
  3.1313 +   |(Const ("op =", Type ("fun",[Type ("bool", []),_])) $ p $ q) =>
  3.1314 +     ([HOLogic.conj $ p $ q,HOLogic.conj $ (HOLogic.Not $ p) $ (HOLogic.Not $ q) ], fn [th1,th2] =>[th1,th2] MRS nnf_eq )
  3.1315 +   |_ => ([], fn [] => lfnp P);
  3.1316  
  3.1317  
  3.1318  
  3.1319  
  3.1320 -(*====================================================*)
  3.1321 -(* Interpretation function for the linform protokol   *)
  3.1322 -(*====================================================*)
  3.1323 -
  3.1324 -
  3.1325 -fun proof_of_linform sg vars f = 
  3.1326 -  let fun proof_of_linformh prt = 
  3.1327 -  case prt of
  3.1328 -    (LfAt (at)) =>  prove_elementar sg "lf" (HOLogic.mk_eq (at, linform vars at))
  3.1329 -   |(LfAtdvd (Const("Divides.op dvd",_)$d$t)) => (prove_elementar sg "lf" (HOLogic.mk_eq (t, lint vars t))) RS (instantiate' [] [None , None, Some (cterm_of sg d)](linearize_dvd))
  3.1330 -   |(Lffm (fm)) => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl)
  3.1331 -   |(LfConst (s,pr1,pr2)) =>
  3.1332 -     let val th1 = proof_of_linformh pr1
  3.1333 -	 val th2 = proof_of_linformh pr2
  3.1334 -     in case s of
  3.1335 -       "CJ" => [th1,th2] MRS (qe_conjI)
  3.1336 -      |"DJ" =>[th1,th2] MRS (qe_disjI)
  3.1337 -      |"IM" =>[th1,th2] MRS (qe_impI)
  3.1338 -      |"EQ" =>[th1,th2] MRS (qe_eqI)
  3.1339 -     end
  3.1340 -   |(LfNot(pr)) => 
  3.1341 -     let val th = proof_of_linformh pr
  3.1342 -     in (th RS (qe_Not))
  3.1343 -     end
  3.1344 -   |(LfQ(s,xn,xT,pr)) => 
  3.1345 -     let val th = forall_intr (cterm_of sg (Free(xn,xT)))(proof_of_linformh pr)
  3.1346 -     in if s = "Ex" 
  3.1347 -        then (th COMP(qe_exI) )
  3.1348 -        else (th COMP(qe_ALLI) )
  3.1349 -     end
  3.1350 -in
  3.1351 - proof_of_linformh (linform_wp f)
  3.1352 -end;
  3.1353 +fun proof_of_cnnf sg p lfnp = 
  3.1354 + let val th1 = thm_of sg (decomp_cnnf sg lfnp) p
  3.1355 +     val rs = snd(qe_get_terms th1)
  3.1356 +     val th2 = prove_elementar sg "ss" (HOLogic.mk_eq(rs,simpl rs))
  3.1357 +  in [th1,th2] MRS trans
  3.1358 +  end;
  3.1359  
  3.1360  end;
     4.1 --- a/src/HOL/Integ/presburger.ML	Wed May 19 11:21:19 2004 +0200
     4.2 +++ b/src/HOL/Integ/presburger.ML	Wed May 19 11:23:59 2004 +0200
     4.3 @@ -6,10 +6,13 @@
     4.4  Tactic for solving arithmetical Goals in Presburger Arithmetic
     4.5  *)
     4.6  
     4.7 +(* This version of presburger deals with occurences of functional symbols in the subgoal and abstract over them to try to prove the more general formula. It then resolves with the subgoal. To disable this feature call the procedure with the parameter no_abs
     4.8 +*)
     4.9 +
    4.10  signature PRESBURGER = 
    4.11  sig
    4.12 - val presburger_tac : bool -> int -> tactic
    4.13 - val presburger_method : bool -> int -> Proof.method
    4.14 + val presburger_tac : bool -> bool -> int -> tactic
    4.15 + val presburger_method : bool -> bool -> int -> Proof.method
    4.16   val setup : (theory -> theory) list
    4.17   val trace : bool ref
    4.18  end;
    4.19 @@ -25,19 +28,18 @@
    4.20  (* Here still only one problem : The proof for the arithmetical transformations done on the dvd atomic formulae*)
    4.21  (*-----------------------------------------------------------------*)
    4.22  
    4.23 -val presburger_ss = simpset_of (theory "Presburger");
    4.24 -
    4.25 -fun cooper_pp sg vrl (fm as e$Abs(xn,xT,p)) = 
    4.26 +fun cooper_pp sg (fm as e$Abs(xn,xT,p)) = 
    4.27    let val (xn1,p1) = variant_abs (xn,xT,p)
    4.28 -  in (CooperProof.cooper_prv sg (Free (xn1, xT)) p1 vrl) end;
    4.29 +  in (CooperProof.cooper_prv sg (Free (xn1, xT)) p1) end;
    4.30  
    4.31  fun mnnf_pp sg fm = CooperProof.proof_of_cnnf sg fm
    4.32    (CooperProof.proof_of_evalc sg);
    4.33  
    4.34 -fun mproof_of_int_qelim sg fm =
    4.35 -  Qelim.proof_of_mlift_qelim sg CooperDec.is_arith_rel
    4.36 +fun tmproof_of_int_qelim sg fm =
    4.37 +  Qelim.tproof_of_mlift_qelim sg CooperDec.is_arith_rel
    4.38      (CooperProof.proof_of_linform sg) (mnnf_pp sg) (cooper_pp sg) fm;
    4.39  
    4.40 +
    4.41  (* Theorems to be used in this tactic*)
    4.42  
    4.43  val zdvd_int = thm "zdvd_int";
    4.44 @@ -63,6 +65,19 @@
    4.45  
    4.46  fun term_typed_consts t = add_term_typed_consts(t,[]);
    4.47  
    4.48 +(* put a term into eta long beta normal form *)
    4.49 +fun eta_long Ts (Abs (s, T, t)) = Abs (s, T, eta_long (T :: Ts) t)
    4.50 +  | eta_long Ts t = (case strip_comb t of
    4.51 +      (Abs _, _) => eta_long Ts (Envir.beta_norm t)
    4.52 +    | (u, ts) => 
    4.53 +      let
    4.54 +        val Us = binder_types (fastype_of1 (Ts, t));
    4.55 +        val i = length Us
    4.56 +      in list_abs (map (pair "x") Us,
    4.57 +        list_comb (incr_boundvars i u, map (eta_long (rev Us @ Ts))
    4.58 +          (map (incr_boundvars i) ts @ map Bound (i - 1 downto 0))))
    4.59 +      end);
    4.60 +
    4.61  (* Some Types*)
    4.62  val bT = HOLogic.boolT;
    4.63  val iT = HOLogic.intT;
    4.64 @@ -94,8 +109,6 @@
    4.65     ("op *", iT --> iT --> iT), 
    4.66     ("HOL.abs", iT --> iT),
    4.67     ("uminus", iT --> iT),
    4.68 -   ("HOL.max", iT --> iT --> iT),
    4.69 -   ("HOL.min", iT --> iT --> iT),
    4.70  
    4.71     ("op <=", nT --> nT --> bT),
    4.72     ("op =", nT --> nT --> bT),
    4.73 @@ -107,8 +120,6 @@
    4.74     ("op -", nT --> nT --> nT),
    4.75     ("op *", nT --> nT --> nT), 
    4.76     ("Suc", nT --> nT),
    4.77 -   ("HOL.max", nT --> nT --> nT),
    4.78 -   ("HOL.min", nT --> nT --> nT),
    4.79  
    4.80     ("Numeral.bin.Bit", binT --> bT --> binT),
    4.81     ("Numeral.bin.Pls", binT),
    4.82 @@ -119,27 +130,89 @@
    4.83     ("0", iT),
    4.84     ("1", nT),
    4.85     ("1", iT),
    4.86 -
    4.87     ("False", bT),
    4.88     ("True", bT)];
    4.89  
    4.90 -(*returns true if the formula is relevant for presburger arithmetic tactic*)
    4.91 -fun relevant ps t = (term_typed_consts t) subset allowed_consts andalso
    4.92 -  map (fn i => snd (nth_elem (i, ps))) (loose_bnos t) @
    4.93 -  map (snd o dest_Free) (term_frees t) @ map (snd o dest_Var) (term_vars t)
    4.94 -  subset [iT, nT];
    4.95 -
    4.96  (* Preparation of the formula to be sent to the Integer quantifier *)
    4.97  (* elimination procedure                                           *)
    4.98  (* Transforms meta implications and meta quantifiers to object     *)
    4.99  (* implications and object quantifiers                             *)
   4.100  
   4.101 -fun prepare_for_presburger q fm = 
   4.102 +
   4.103 +(*==================================*)
   4.104 +(* Abstracting on subterms  ========*)
   4.105 +(*==================================*)
   4.106 +(* Returns occurences of terms that are function application of type int or nat*)
   4.107 +
   4.108 +fun getfuncs fm = case strip_comb fm of
   4.109 +    (Free (_, T), ts as _ :: _) =>
   4.110 +      if body_type T mem [iT, nT] 
   4.111 +         andalso not (ts = []) andalso forall (null o loose_bnos) ts 
   4.112 +      then [fm]
   4.113 +      else foldl op union ([], map getfuncs ts)
   4.114 +  | (Var (_, T), ts as _ :: _) =>
   4.115 +      if body_type T mem [iT, nT] 
   4.116 +         andalso not (ts = []) andalso forall (null o loose_bnos) ts then [fm]
   4.117 +      else foldl op union ([], map getfuncs ts)
   4.118 +  | (Const (s, T), ts) =>
   4.119 +      if (s, T) mem allowed_consts orelse not (body_type T mem [iT, nT])
   4.120 +      then foldl op union ([], map getfuncs ts)
   4.121 +      else [fm]
   4.122 +  | (Abs (s, T, t), _) => getfuncs t
   4.123 +  | _ => [];
   4.124 +
   4.125 +
   4.126 +fun abstract_pres sg fm = 
   4.127 +  foldr (fn (t, u) =>
   4.128 +      let val T = fastype_of t
   4.129 +      in all T $ Abs ("x", T, abstract_over (t, u)) end)
   4.130 +         (getfuncs fm, fm);
   4.131 +
   4.132 +
   4.133 +
   4.134 +(* hasfuncs_on_bounds dont care of the type of the functions applied!
   4.135 + It returns true if there is a subterm coresponding to the application of
   4.136 + a function on a bounded variable.
   4.137 +
   4.138 + Function applications are allowed only for well predefined functions a 
   4.139 + consts*)
   4.140 +
   4.141 +fun has_free_funcs fm  = case strip_comb fm of
   4.142 +    (Free (_, T), ts as _ :: _) => 
   4.143 +      if (body_type T mem [iT,nT]) andalso (not (T mem [iT,nT]))
   4.144 +      then true
   4.145 +      else exists (fn x => x) (map has_free_funcs ts)
   4.146 +  | (Var (_, T), ts as _ :: _) =>
   4.147 +      if (body_type T mem [iT,nT]) andalso not (T mem [iT,nT])
   4.148 +      then true
   4.149 +      else exists (fn x => x) (map has_free_funcs ts)
   4.150 +  | (Const (s, T), ts) =>  exists (fn x => x) (map has_free_funcs ts)
   4.151 +  | (Abs (s, T, t), _) => has_free_funcs t
   4.152 +  |_ => false;
   4.153 +
   4.154 +
   4.155 +(*returns true if the formula is relevant for presburger arithmetic tactic
   4.156 +The constants occuring in term t should be a subset of the allowed_consts
   4.157 + There also should be no occurences of application of functions on bounded 
   4.158 + variables. Whenever this function will be used, it will be ensured that t 
   4.159 + will not contain subterms with function symbols that could have been 
   4.160 + abstracted over.*)
   4.161 + 
   4.162 +fun relevant ps t = (term_typed_consts t) subset allowed_consts andalso 
   4.163 +  map (fn i => snd (nth_elem (i, ps))) (loose_bnos t) @
   4.164 +  map (snd o dest_Free) (term_frees t) @ map (snd o dest_Var) (term_vars t)
   4.165 +  subset [iT, nT]
   4.166 +  andalso not (has_free_funcs t);
   4.167 +
   4.168 +
   4.169 +fun prepare_for_presburger sg q fm = 
   4.170    let
   4.171      val ps = Logic.strip_params fm
   4.172      val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm)
   4.173      val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm)
   4.174 -    val _ = if relevant (rev ps) c then () else raise CooperDec.COOPER
   4.175 +    val _ = if relevant (rev ps) c then () 
   4.176 +               else  (trace_msg ("Conclusion is not a presburger term:\n" ^
   4.177 +             Sign.string_of_term sg c); raise CooperDec.COOPER)
   4.178      fun mk_all ((s, T), (P,n)) =
   4.179        if 0 mem loose_bnos P then
   4.180          (HOLogic.all_const T $ Abs (s, T, P), n)
   4.181 @@ -161,14 +234,20 @@
   4.182  fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp;
   4.183  
   4.184  (* the presburger tactic*)
   4.185 -fun presburger_tac q i = ObjectLogic.atomize_tac i THEN (fn st =>
   4.186 +
   4.187 +(* Parameters : q = flag for quantify ofer free variables ; 
   4.188 +                a = flag for abstracting over function occurences
   4.189 +                i = subgoal  *)
   4.190 +
   4.191 +fun presburger_tac q a i = ObjectLogic.atomize_tac i THEN (fn st =>
   4.192    let
   4.193 -    val g = BasisLibrary.List.nth (prems_of st, i - 1);
   4.194 -    val sg = sign_of_thm st;
   4.195 +    val g = BasisLibrary.List.nth (prems_of st, i - 1)
   4.196 +    val sg = sign_of_thm st
   4.197 +    (* The Abstraction step *)
   4.198 +    val g' = if a then abstract_pres sg g else g
   4.199      (* Transform the term*)
   4.200 -    val (t,np,nh) = prepare_for_presburger q g
   4.201 +    val (t,np,nh) = prepare_for_presburger sg q g'
   4.202      (* Some simpsets for dealing with mod div abs and nat*)
   4.203 -
   4.204      val simpset0 = HOL_basic_ss
   4.205        addsimps [mod_div_equality', Suc_plus1]
   4.206        addsplits [split_zdiv, split_zmod, split_div', split_min, split_max]
   4.207 @@ -183,37 +262,40 @@
   4.208        addsimps [nat_0_le, all_nat, ex_nat, number_of1, number_of2, int_0, int_1]
   4.209        addcongs [conj_le_cong, imp_le_cong]
   4.210      (* simp rules for elimination of abs *)
   4.211 -
   4.212      val simpset3 = HOL_basic_ss addsplits [abs_split]
   4.213 -	      
   4.214      val ct = cterm_of sg (HOLogic.mk_Trueprop t)
   4.215 -
   4.216      (* Theorem for the nat --> int transformation *)
   4.217      val pre_thm = Seq.hd (EVERY
   4.218 -      [simp_tac simpset0 i,
   4.219 -       TRY (simp_tac simpset1 i), TRY (simp_tac simpset2 i),
   4.220 -       TRY (simp_tac simpset3 i), TRY (simp_tac presburger_ss i)]
   4.221 +      [simp_tac simpset0 1,
   4.222 +       TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1),
   4.223 +       TRY (simp_tac simpset3 1)]
   4.224        (trivial ct))
   4.225 -
   4.226 -    fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i);
   4.227 -
   4.228 +    fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i)
   4.229      (* The result of the quantifier elimination *)
   4.230      val (th, tac) = case (prop_of pre_thm) of
   4.231          Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ =>
   4.232            (trace_msg ("calling procedure with term:\n" ^
   4.233               Sign.string_of_term sg t1);
   4.234 -           ((mproof_of_int_qelim sg (Pattern.eta_long [] t1) RS iffD2) RS pre_thm,
   4.235 +           ((tmproof_of_int_qelim sg (Pattern.eta_long [] t1) RS iffD2) RS pre_thm,
   4.236              assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i)))
   4.237        | _ => (pre_thm, assm_tac i)
   4.238 -  in (rtac (((mp_step nh) o (spec_step np)) th) i THEN tac) st
   4.239 +  in (rtac (((mp_step nh) o (spec_step np)) th) i 
   4.240 +      THEN tac) st
   4.241    end handle Subscript => no_tac st | CooperDec.COOPER => no_tac st);
   4.242  
   4.243  fun presburger_args meth =
   4.244 -  Method.simple_args (Scan.optional (Args.$$$ "no_quantify" >> K false) true)
   4.245 -    (fn q => fn _ => meth q 1);
   4.246 + let val parse_flag = 
   4.247 +         Args.$$$ "no_quantify" >> K (apfst (K false))
   4.248 +      || Args.$$$ "no_abs" >> K (apsnd (K false));
   4.249 + in
   4.250 +   Method.simple_args 
   4.251 +  (Scan.optional (Args.$$$ "(" |-- Args.list1 parse_flag --| Args.$$$ ")") [] >>
   4.252 +    curry (foldl op |>) (true, true))
   4.253 +    (fn (q,a) => fn _ => meth q a 1)
   4.254 +  end;
   4.255  
   4.256 -fun presburger_method q i = Method.METHOD (fn facts =>
   4.257 -  Method.insert_tac facts 1 THEN presburger_tac q i)
   4.258 +fun presburger_method q a i = Method.METHOD (fn facts =>
   4.259 +  Method.insert_tac facts 1 THEN presburger_tac q a i)
   4.260  
   4.261  val setup =
   4.262    [Method.add_method ("presburger",
   4.263 @@ -221,8 +303,8 @@
   4.264       "decision procedure for Presburger arithmetic"),
   4.265     ArithTheoryData.map (fn {splits, inj_consts, discrete, presburger} =>
   4.266       {splits = splits, inj_consts = inj_consts, discrete = discrete,
   4.267 -      presburger = Some (presburger_tac true)})];
   4.268 +      presburger = Some (presburger_tac true true)})];
   4.269  
   4.270  end;
   4.271  
   4.272 -val presburger_tac = Presburger.presburger_tac true;
   4.273 +val presburger_tac = Presburger.presburger_tac true true;
     5.1 --- a/src/HOL/Integ/qelim.ML	Wed May 19 11:21:19 2004 +0200
     5.2 +++ b/src/HOL/Integ/qelim.ML	Wed May 19 11:23:59 2004 +0200
     5.3 @@ -8,10 +8,11 @@
     5.4  *)
     5.5  
     5.6  signature QELIM =
     5.7 -sig
     5.8 - val proof_of_mlift_qelim: Sign.sg -> (term -> bool) ->
     5.9 + sig
    5.10 + val tproof_of_mlift_qelim: Sign.sg -> (term -> bool) ->
    5.11     (string list -> term -> thm) -> (term -> thm) ->
    5.12 -   (string list -> term -> thm) -> term -> thm
    5.13 +   (term -> thm) -> term -> thm
    5.14 +
    5.15  end;
    5.16  
    5.17  structure Qelim : QELIM =
    5.18 @@ -19,24 +20,6 @@
    5.19  open CooperDec;
    5.20  open CooperProof;
    5.21  
    5.22 -(*-----------------------------------------------------------------*)
    5.23 -(*-----------------------------------------------------------------*)
    5.24 -(*-----------------------------------------------------------------*)
    5.25 -(*---                                                           ---*)
    5.26 -(*---                                                           ---*)
    5.27 -(*---         Protocoling part                                  ---*)
    5.28 -(*---                                                           ---*)
    5.29 -(*---           includes the protocolling datastructure         ---*)
    5.30 -(*---                                                           ---*)
    5.31 -(*---          and the protocolling fuctions                    ---*)
    5.32 -(*---                                                           ---*)
    5.33 -(*---                                                           ---*)
    5.34 -(*---                                                           ---*)
    5.35 -(*-----------------------------------------------------------------*)
    5.36 -(*-----------------------------------------------------------------*)
    5.37 -(*-----------------------------------------------------------------*)
    5.38 -
    5.39 -
    5.40  val cboolT = ctyp_of (sign_of HOL.thy) HOLogic.boolT;
    5.41  
    5.42  (* List of the theorems to be used in the following*)
    5.43 @@ -46,131 +29,35 @@
    5.44  val qe_ALL = thm "qe_ALL";
    5.45  
    5.46  
    5.47 -(*Datatype declaration for the protocoling procedure.*)
    5.48 -
    5.49 -
    5.50 -datatype QeLog = AFN of term*(string list)
    5.51 -                |QFN of term*(string list)
    5.52 -                |ExConj of term*QeLog
    5.53 -                |ExDisj of (string*typ*term)*term*QeLog*QeLog
    5.54 -                |QeConst of string*QeLog*QeLog
    5.55 -                |QeNot of QeLog
    5.56 -                |QeAll of QeLog
    5.57 -                |Lift_Qelim of term*QeLog
    5.58 -		|QeUnk of term;
    5.59 -
    5.60 -datatype mQeLog = mQeProof of (string list)*mQeLog
    5.61 -		|mAFN of term
    5.62 -                |mNFN of mQeLog
    5.63 -                |mQeConst of string*mQeLog*mQeLog
    5.64 -                |mQeNot of mQeLog
    5.65 -		|mQelim of term*(string list)*mQeLog
    5.66 -		|mQeAll of mQeLog
    5.67 -		|mQefm of term;
    5.68 -
    5.69 -(* This is the protokoling my function for the quantifier elimination*)
    5.70 -fun mlift_qelim_wp isat vars = 
    5.71 -  let fun mqelift_wp vars fm = if (isat fm) then mAFN(fm)
    5.72 -    else  
    5.73 -    (case fm of 
    5.74 -     ( Const ("Not",_) $ p) => mQeNot(mqelift_wp vars p)
    5.75 -    |( Const ("op &",_) $ p $q) => mQeConst("CJ", mqelift_wp vars p,mqelift_wp vars q) 
    5.76 -
    5.77 -    |( Const ("op |",_) $ p $q) => mQeConst("DJ", mqelift_wp vars p,mqelift_wp vars q) 
    5.78 -
    5.79 -    |( Const ("op -->",_) $ p $q) => mQeConst("IM", mqelift_wp vars p,mqelift_wp vars q) 
    5.80 -
    5.81 -    |( Const ("op =",Type ("fun",[Type ("bool", []),_])) $ p $q) =>mQeConst("EQ", mqelift_wp vars p,mqelift_wp vars q) 
    5.82 -
    5.83 -    				
    5.84 -    |( Const ("All",QT) $ Abs(x,T,p)) =>mQeAll (mqelift_wp vars (Const("Ex",QT) $ Abs(x,T,(HOLogic.Not $ p))))
    5.85 -
    5.86 -    |(Const ("Ex",_) $ Abs (x,T,p))  => 
    5.87 -      let val (x1,p1) = variant_abs (x,T,p)
    5.88 -          val prt = mqelift_wp (x1::vars) p1
    5.89 -      in mQelim(Free(x1,T),vars,mNFN(prt))
    5.90 -      end
    5.91 -    | _ => mQefm(fm)
    5.92 -   ) 
    5.93 -     
    5.94 -  in (fn fm => mQeProof(vars,mNFN(mqelift_wp vars fm )))
    5.95 -  end;  
    5.96 -
    5.97 -
    5.98 +(*============= Compact version =====*)
    5.99  
   5.100  
   5.101 -(*-----------------------------------------------------------------*)
   5.102 -(*-----------------------------------------------------------------*)
   5.103 -(*-----------------------------------------------------------------*)
   5.104 -(*---                                                           ---*)
   5.105 -(*---                                                           ---*)
   5.106 -(*---      Interpretation and Proofgeneration Part              ---*)
   5.107 -(*---                                                           ---*)
   5.108 -(*---      Protocole interpretation functions                   ---*)
   5.109 -(*---                                                           ---*)
   5.110 -(*---      and proofgeneration functions                        ---*)
   5.111 -(*---                                                           ---*)
   5.112 -(*---                                                           ---*)
   5.113 -(*---                                                           ---*)
   5.114 -(*---                                                           ---*)
   5.115 -(*-----------------------------------------------------------------*)
   5.116 -(*-----------------------------------------------------------------*)
   5.117 -(*-----------------------------------------------------------------*)
   5.118 -
   5.119 -(*-----------------------------------------------------------------*)
   5.120 -(*-----------------------------------------------------------------*)
   5.121 -(*function that interpretates the protokol generated by the _wp function*)
   5.122 -
   5.123 +fun decomp_qe is_at afnp nfnp qfnp sg P = 
   5.124 +   if is_at P then ([], fn [] => afnp [] P) else 
   5.125 +   case P of
   5.126 +   (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
   5.127 +   |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
   5.128 +   |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
   5.129 +   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
   5.130 +   |(Const("Not",_)$p) => ([p],fn [th] => th RS qe_Not)
   5.131 +   |(Const("Ex",_)$Abs(xn,xT,p)) => 
   5.132 +      let val (xn1,p1) = variant_abs(xn,xT,p) 
   5.133 +      in ([p1],
   5.134 +        fn [th1_1] => 
   5.135 +          let val th2 = [th1_1,nfnp (snd (qe_get_terms th1_1))] MRS trans
   5.136 +              val eth1 = (forall_intr (cterm_of sg (Free(xn1,xT))) th2) COMP  qe_exI
   5.137 +              val th3 = qfnp (snd(qe_get_terms eth1))
   5.138 +          in [eth1,th3] MRS trans
   5.139 +          end )
   5.140 +      end
   5.141  
   5.142 -(* proof_of_lift_qelim interpretates a protokol for the quantifier elimination one some quantified formula. It uses the functions afnp nfnp and qfnp as proof functions to generate a prove for the hole quantifier elimination.*)
   5.143 -(* afnp : must retun a proof for the transformations on the atomic formalae*)
   5.144 -(* nfnp : must return a proof for the post one-quatifiers elimination process*)
   5.145 -(* qfnp mus return a proof for the one quantifier elimination (existential) *)
   5.146 -(* All these function are independent of the theory on whitch we are trying to prove quantifier elimination*)
   5.147 -(* But the following invariants mus be respected : *)
   5.148 -(* afnp : term -> string list -> thm*)
   5.149 -(*   nfnp : term -> thm*)
   5.150 -(*   qfnp : term -> string list -> thm*)
   5.151 -(*For all theorms generated by these function must hold :*)
   5.152 -(*    All of them are logical equivalences.*)
   5.153 -(*    on left side of the equivalence must appear the term exactely as ist was given as a parameter (or eventually modulo Gamma, where Gamma are the rules whitch are allowed to be used during unification ex. beta reduction.....)*)
   5.154 -(* qfnp must take as an argument for the term an existential quantified formula*)
   5.155 -(*-----------------------------------------------------------------*)
   5.156 -(*-----------------------------------------------------------------*)
   5.157 +   |(Const("All",_)$Abs(xn,xT,p)) => ([(HOLogic.exists_const xT)$Abs(xn,xT,HOLogic.Not $ p)], fn [th] => th RS qe_ALL)
   5.158 +   | _ => ([],fn [] => instantiate' [Some (ctyp_of sg (type_of P))] [Some (cterm_of sg P)] refl);
   5.159 + 
   5.160  
   5.161 -fun proof_of_mlift_qelim sg isat afnp nfnp qfnp =
   5.162 - let fun h_proof_of_mlift_qelim isat afnp nfnp qfnp prtkl vrl = 
   5.163 -   (case prtkl of 
   5.164 -   mAFN (fm) => afnp vrl fm 
   5.165 -   |mNFN (prt) => let val th1 = h_proof_of_mlift_qelim isat  afnp nfnp qfnp prt vrl 
   5.166 -                  val th2 = nfnp (snd (qe_get_terms th1)) 
   5.167 -                    in [th1,th2] MRS trans 
   5.168 -                 end 
   5.169 -   |mQeConst (s,pr1,pr2) =>  
   5.170 -     let val th1 =  h_proof_of_mlift_qelim isat afnp nfnp qfnp pr1 vrl  
   5.171 -         val th2 =  h_proof_of_mlift_qelim isat afnp nfnp qfnp pr2 vrl  
   5.172 -     in (case s of 
   5.173 -        "CJ" => [th1,th2] MRS (qe_conjI)  
   5.174 -       |"DJ" => [th1,th2] MRS (qe_disjI)  
   5.175 -       |"IM" => [th1,th2] MRS (qe_impI)  
   5.176 -       |"EQ" => [th1,th2] MRS (qe_eqI)  
   5.177 -       )  
   5.178 -    end  
   5.179 -   |mQeNot (pr) =>(h_proof_of_mlift_qelim isat afnp nfnp qfnp pr vrl ) RS (qe_Not)  
   5.180 -   |mQeAll(pr) => (h_proof_of_mlift_qelim isat afnp nfnp qfnp pr vrl ) RS (qe_ALL) 
   5.181 -   |mQelim (x as (Free(xn,xT)),vl,pr) => 
   5.182 -     let val th_1 = h_proof_of_mlift_qelim isat afnp nfnp qfnp pr vl
   5.183 -         val mQeProof(l2,pr2) = mlift_qelim_wp isat (xn::vrl) (snd(qe_get_terms th_1))
   5.184 -         val th_2 = [th_1,(h_proof_of_mlift_qelim isat afnp nfnp qfnp pr2 l2)] MRS trans
   5.185 -         val th1 = (forall_intr (cterm_of sg x) th_2) COMP (qe_exI)
   5.186 -	 val th2 = qfnp vl (snd (qe_get_terms th1)) 
   5.187 -       in [th1,th2] MRS trans 
   5.188 -       end
   5.189 -   |mQefm (fm) => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl
   5.190 -)
   5.191 -in (fn fm => let val mQeProof(vars,prt) = (mlift_qelim_wp isat (fv fm) fm)
   5.192 -                 in (h_proof_of_mlift_qelim isat afnp nfnp qfnp prt vars)
   5.193 -                 end)
   5.194 +fun tproof_of_mlift_qelim sg isat afnp nfnp qfnp p = 
   5.195 +   let val th1 = thm_of sg (decomp_qe isat afnp nfnp qfnp sg) p
   5.196 +       val th2 = nfnp (snd (qe_get_terms th1))
   5.197 +    in [th1,th2] MRS trans
   5.198 +    end;
   5.199  end;
   5.200 -
   5.201 -end;
     6.1 --- a/src/HOL/Presburger.thy	Wed May 19 11:21:19 2004 +0200
     6.2 +++ b/src/HOL/Presburger.thy	Wed May 19 11:23:59 2004 +0200
     6.3 @@ -978,11 +978,11 @@
     6.4    \medskip Specific instances of congruence rules, to prevent
     6.5    simplifier from looping. *}
     6.6  
     6.7 -theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
     6.8 +theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
     6.9    by simp
    6.10  
    6.11 -theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<and> P) = (0 <= x \<and> P')"
    6.12 -  by simp
    6.13 +theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<and> P) = (0 <= x \<and> P')"
    6.14 +  by (simp cong: conj_cong)
    6.15  
    6.16  use "cooper_dec.ML"
    6.17  use "cooper_proof.ML"
     7.1 --- a/src/HOL/Tools/Presburger/cooper_dec.ML	Wed May 19 11:21:19 2004 +0200
     7.2 +++ b/src/HOL/Tools/Presburger/cooper_dec.ML	Wed May 19 11:23:59 2004 +0200
     7.3 @@ -29,10 +29,16 @@
     7.4    val aset : term -> term -> term list
     7.5    val linrep : string list -> term -> term -> term -> term
     7.6    val list_disj : term list -> term
     7.7 +  val list_conj : term list -> term
     7.8    val simpl : term -> term
     7.9    val fv : term -> string list
    7.10    val negate : term -> term
    7.11    val operations : (string * (int * int -> bool)) list
    7.12 +  val conjuncts : term -> term list
    7.13 +  val disjuncts : term -> term list
    7.14 +  val has_bound : term -> bool
    7.15 +  val minusinf : term -> term -> term
    7.16 +  val plusinf : term -> term -> term
    7.17  end;
    7.18  
    7.19  structure  CooperDec : COOPER_DEC =
    7.20 @@ -183,7 +189,7 @@
    7.21   
    7.22           else (warning "lint: apparent nonlinearity"; raise COOPER)
    7.23           end 
    7.24 -  |_ =>   error "lint: unknown term"; 
    7.25 +  |_ =>   (error "COOPER:lint: unknown term  ")
    7.26     
    7.27   
    7.28   
     8.1 --- a/src/HOL/Tools/Presburger/cooper_proof.ML	Wed May 19 11:21:19 2004 +0200
     8.2 +++ b/src/HOL/Tools/Presburger/cooper_proof.ML	Wed May 19 11:23:59 2004 +0200
     8.3 @@ -16,35 +16,25 @@
     8.4    val qe_eqI : thm
     8.5    val qe_exI : thm
     8.6    val qe_get_terms : thm -> term * term
     8.7 -  val cooper_prv : Sign.sg -> term -> term -> string list -> thm
     8.8 +  val cooper_prv : Sign.sg -> term -> term -> thm
     8.9    val proof_of_evalc : Sign.sg -> term -> thm
    8.10    val proof_of_cnnf : Sign.sg -> term -> (term -> thm) -> thm
    8.11    val proof_of_linform : Sign.sg -> string list -> term -> thm
    8.12 +  val prove_elementar : Sign.sg -> string -> term -> thm
    8.13 +  val thm_of : Sign.sg -> (term -> (term list * (thm list -> thm))) -> term -> thm
    8.14  end;
    8.15  
    8.16  structure CooperProof : COOPER_PROOF =
    8.17  struct
    8.18 -
    8.19  open CooperDec;
    8.20  
    8.21 -(*-----------------------------------------------------------------*)
    8.22 -(*-----------------------------------------------------------------*)
    8.23 -(*-----------------------------------------------------------------*)
    8.24 -(*---                                                           ---*)
    8.25 -(*---                                                           ---*)
    8.26 -(*---         Protocoling part                                  ---*)
    8.27 -(*---                                                           ---*)
    8.28 -(*---           includes the protocolling datastructure         ---*)
    8.29 -(*---                                                           ---*)
    8.30 -(*---          and the protocolling fuctions                    ---*)
    8.31 -(*---                                                           ---*)
    8.32 -(*---                                                           ---*)
    8.33 -(*-----------------------------------------------------------------*)
    8.34 -(*-----------------------------------------------------------------*)
    8.35 -(*-----------------------------------------------------------------*)
    8.36 +(*
    8.37 +val presburger_ss = simpset_of (theory "Presburger")
    8.38 +  addsimps [zdiff_def] delsimps [symmetric zdiff_def];
    8.39 +*)
    8.40  
    8.41  val presburger_ss = simpset_of (theory "Presburger")
    8.42 -  addsimps [diff_int_def] delsimps [thm"diff_int_def_symmetric"];
    8.43 +  addsimps[diff_int_def] delsimps [thm"diff_int_def_symmetric"];
    8.44  val cboolT = ctyp_of (sign_of HOL.thy) HOLogic.boolT;
    8.45  
    8.46  (*Theorems that will be used later for the proofgeneration*)
    8.47 @@ -52,7 +42,7 @@
    8.48  val zdvd_iff_zmod_eq_0 = thm "zdvd_iff_zmod_eq_0";
    8.49  val unity_coeff_ex = thm "unity_coeff_ex";
    8.50  
    8.51 -(* Theorems for proving the adjustment of the coefficients*)
    8.52 +(* Thorems for proving the adjustment of the coeffitients*)
    8.53  
    8.54  val ac_lt_eq =  thm "ac_lt_eq";
    8.55  val ac_eq_eq = thm "ac_eq_eq";
    8.56 @@ -68,7 +58,7 @@
    8.57  val qe_exI = thm "qe_exI";
    8.58  val qe_ALLI = thm "qe_ALLI";
    8.59  
    8.60 -(*Modulo D property for Pminusinf and Plusinf *)
    8.61 +(*Modulo D property for Pminusinf an Plusinf *)
    8.62  val fm_modd_minf = thm "fm_modd_minf";
    8.63  val not_dvd_modd_minf = thm "not_dvd_modd_minf";
    8.64  val dvd_modd_minf = thm "dvd_modd_minf";
    8.65 @@ -77,7 +67,7 @@
    8.66  val not_dvd_modd_pinf = thm "not_dvd_modd_pinf";
    8.67  val dvd_modd_pinf = thm "dvd_modd_pinf";
    8.68  
    8.69 -(* the minusinfinity property*)
    8.70 +(* the minusinfinity proprty*)
    8.71  
    8.72  val fm_eq_minf = thm "fm_eq_minf";
    8.73  val neq_eq_minf = thm "neq_eq_minf";
    8.74 @@ -87,7 +77,7 @@
    8.75  val not_dvd_eq_minf = thm "not_dvd_eq_minf";
    8.76  val dvd_eq_minf = thm "dvd_eq_minf";
    8.77  
    8.78 -(* the Plusinfinity property*)
    8.79 +(* the Plusinfinity proprty*)
    8.80  
    8.81  val fm_eq_pinf = thm "fm_eq_pinf";
    8.82  val neq_eq_pinf = thm "neq_eq_pinf";
    8.83 @@ -108,7 +98,6 @@
    8.84  val modd_pinf_disjI = thm "modd_pinf_disjI";
    8.85  val modd_pinf_conjI = thm "modd_pinf_conjI";
    8.86  
    8.87 -
    8.88  (*Cooper Backwards...*)
    8.89  (*Bset*)
    8.90  val not_bst_p_fm = thm "not_bst_p_fm";
    8.91 @@ -166,81 +155,6 @@
    8.92  val lf_dvd = thm "lf_dvd";
    8.93  
    8.94  
    8.95 -
    8.96 -(* ------------------------------------------------------------------------- *)
    8.97 -(*Datatatype declarations for Proofprotocol for the cooperprocedure.*)
    8.98 -(* ------------------------------------------------------------------------- *)
    8.99 -
   8.100 -
   8.101 -
   8.102 -(* ------------------------------------------------------------------------- *)
   8.103 -(*Datatatype declarations for Proofprotocol for the adjustcoeff step.*)
   8.104 -(* ------------------------------------------------------------------------- *)
   8.105 -datatype CpLog = No
   8.106 -                |Simp of term*CpLog
   8.107 -		|Blast of CpLog*CpLog
   8.108 -		|Aset of (term*term*(term list)*term)
   8.109 -		|Bset of (term*term*(term list)*term)
   8.110 -		|Minusinf of CpLog*CpLog
   8.111 -		|Cooper of term*CpLog*CpLog*CpLog
   8.112 -		|Eq_minf of term*term
   8.113 -		|Modd_minf of term*term
   8.114 -		|Eq_minf_conjI of CpLog*CpLog
   8.115 -		|Modd_minf_conjI of CpLog*CpLog	
   8.116 -		|Modd_minf_disjI of CpLog*CpLog
   8.117 -		|Eq_minf_disjI of CpLog*CpLog	
   8.118 -		|Not_bst_p of term*term*term*term*CpLog
   8.119 -		|Not_bst_p_atomic of term
   8.120 -		|Not_bst_p_conjI of CpLog*CpLog
   8.121 -		|Not_bst_p_disjI of CpLog*CpLog
   8.122 -		|Not_ast_p of term*term*term*term*CpLog
   8.123 -		|Not_ast_p_atomic of term
   8.124 -		|Not_ast_p_conjI of CpLog*CpLog
   8.125 -		|Not_ast_p_disjI of CpLog*CpLog
   8.126 -		|CpLogError;
   8.127 -
   8.128 -
   8.129 -
   8.130 -datatype ACLog = ACAt of int*term
   8.131 -                |ACPI of int*term
   8.132 -                |ACfm of term
   8.133 -                |ACNeg of ACLog
   8.134 -		|ACConst of string*ACLog*ACLog;
   8.135 -
   8.136 -
   8.137 -
   8.138 -(* ------------------------------------------------------------------------- *)
   8.139 -(*Datatatype declarations for Proofprotocol for the CNNF step.*)
   8.140 -(* ------------------------------------------------------------------------- *)
   8.141 -
   8.142 -
   8.143 -datatype NNFLog = NNFAt of term
   8.144 -                |NNFSimp of NNFLog
   8.145 -                |NNFNN of NNFLog
   8.146 -		|NNFConst of string*NNFLog*NNFLog;
   8.147 -
   8.148 -(* ------------------------------------------------------------------------- *)
   8.149 -(*Datatatype declarations for Proofprotocol for the linform  step.*)
   8.150 -(* ------------------------------------------------------------------------- *)
   8.151 -
   8.152 -
   8.153 -datatype LfLog = LfAt of term
   8.154 -                |LfAtdvd of term
   8.155 -                |Lffm of term
   8.156 -                |LfConst of string*LfLog*LfLog
   8.157 -		|LfNot of LfLog
   8.158 -		|LfQ of string*string*typ*LfLog;
   8.159 -
   8.160 -
   8.161 -(* ------------------------------------------------------------------------- *)
   8.162 -(*Datatatype declarations for Proofprotocol for the evaluation- evalc-  step.*)
   8.163 -(* ------------------------------------------------------------------------- *)
   8.164 -
   8.165 -
   8.166 -datatype EvalLog = EvalAt of term
   8.167 -                |Evalfm of term
   8.168 -		|EvalConst of string*EvalLog*EvalLog;
   8.169 -
   8.170  (* ------------------------------------------------------------------------- *)
   8.171  (*This function norm_zero_one  replaces the occurences of Numeral1 and Numeral0*)
   8.172  (*Respectively by their abstract representation Const("1",..) and COnst("0",..)*)
   8.173 @@ -258,214 +172,6 @@
   8.174    |(Abs(x,T,p)) => (Abs(x,T,(norm_zero_one p)))
   8.175    |_ => fm;
   8.176  
   8.177 -
   8.178 -(* ------------------------------------------------------------------------- *)
   8.179 -(* Intended to tell that here we changed the structure of the formula with respect to the posineq theorem : ~(0 < t) = 0 < 1-t*)
   8.180 -(* ------------------------------------------------------------------------- *)
   8.181 -fun adjustcoeffeq_wp  x l fm = 
   8.182 -    case fm of  
   8.183 -  (Const("Not",_)$(Const("op <",_) $(Const("0",_)) $(rt as (Const ("op +", _)$(Const ("op *",_) $    c $ y ) $z )))) => 
   8.184 -  if (x = y) 
   8.185 -  then let  
   8.186 -       val m = l div (dest_numeral c) 
   8.187 -       val n = abs (m)
   8.188 -       val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) 
   8.189 -       val rs = (HOLogic.mk_binrel "op <" (zero,linear_sub [] (mk_numeral n) (HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) 
   8.190 -       in (ACPI(n,fm),rs)
   8.191 -       end
   8.192 -  else  let val rs = (HOLogic.mk_binrel "op <" (zero,linear_sub [] one rt )) 
   8.193 -        in (ACPI(1,fm),rs)
   8.194 -        end
   8.195 -
   8.196 -  |(Const(p,_) $d $( Const ("op +", _)$(Const ("op *",_) $ 
   8.197 -      c $ y ) $z )) => if (is_arith_rel fm) andalso (x = y) then  
   8.198 -        let val m = l div (dest_numeral c) 
   8.199 -           val n = (if p = "op <" then abs(m) else m)  
   8.200 -           val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x))
   8.201 -           val rs = (HOLogic.mk_binrel p ((linear_cmul n d),(HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) 
   8.202 -	   in (ACAt(n,fm),rs)
   8.203 -	   end
   8.204 -        else (ACfm(fm),fm) 
   8.205 -  |( Const ("Not", _) $ p) => let val (rsp,rsr) = adjustcoeffeq_wp x l p 
   8.206 -                              in (ACNeg(rsp),HOLogic.Not $ rsr) 
   8.207 -                              end
   8.208 -  |( Const ("op &",_) $ p $ q) =>let val (rspp,rspr) = adjustcoeffeq_wp x l p
   8.209 -                                     val (rsqp,rsqr) = adjustcoeffeq_wp x l q
   8.210 -
   8.211 -                                  in (ACConst ("CJ",rspp,rsqp), HOLogic.mk_conj (rspr,rsqr)) 
   8.212 -                                  end 
   8.213 -  |( Const ("op |",_) $ p $ q) =>let val (rspp,rspr) = adjustcoeffeq_wp x l p
   8.214 -                                     val (rsqp,rsqr) = adjustcoeffeq_wp x l q
   8.215 -
   8.216 -                                  in (ACConst ("DJ",rspp,rsqp), HOLogic.mk_disj (rspr,rsqr)) 
   8.217 -                                  end
   8.218 -
   8.219 -  |_ => (ACfm(fm),fm);
   8.220 -
   8.221 -
   8.222 -(*_________________________________________*)
   8.223 -(*-----------------------------------------*)
   8.224 -(* Protocol generation for the liform step *)
   8.225 -(*_________________________________________*)
   8.226 -(*-----------------------------------------*)
   8.227 -
   8.228 -
   8.229 -fun linform_wp fm = 
   8.230 -  let fun at_linform_wp at =
   8.231 -    case at of
   8.232 -      (Const("op <=",_)$s$t) => LfAt(at)
   8.233 -      |(Const("op <",_)$s$t) => LfAt(at)
   8.234 -      |(Const("op =",_)$s$t) => LfAt(at)
   8.235 -      |(Const("Divides.op dvd",_)$s$t) => LfAtdvd(at)
   8.236 -  in
   8.237 -  if is_arith_rel fm 
   8.238 -  then at_linform_wp fm 
   8.239 -  else case fm of
   8.240 -    (Const("Not",_) $ A) => LfNot(linform_wp A)
   8.241 -   |(Const("op &",_)$ A $ B) => LfConst("CJ",linform_wp A, linform_wp B)
   8.242 -   |(Const("op |",_)$ A $ B) => LfConst("DJ",linform_wp A, linform_wp B)
   8.243 -   |(Const("op -->",_)$ A $ B) => LfConst("IM",linform_wp A, linform_wp B)
   8.244 -   |(Const("op =",Type ("fun",[Type ("bool", []),_]))$ A $ B) => LfConst("EQ",linform_wp A, linform_wp B)
   8.245 -   |Const("Ex",_)$Abs(x,T,p) => 
   8.246 -     let val (xn,p1) = variant_abs(x,T,p)
   8.247 -     in LfQ("Ex",xn,T,linform_wp p1)
   8.248 -     end 
   8.249 -   |Const("All",_)$Abs(x,T,p) => 
   8.250 -     let val (xn,p1) = variant_abs(x,T,p)
   8.251 -     in LfQ("All",xn,T,linform_wp p1)
   8.252 -     end 
   8.253 -end;
   8.254 -
   8.255 -
   8.256 -(* ------------------------------------------------------------------------- *)
   8.257 -(*For simlified formulas we just notice the original formula, for whitch we habe been
   8.258 -intendes to make the proof.*)
   8.259 -(* ------------------------------------------------------------------------- *)
   8.260 -fun simpl_wp (fm,pr) = let val fm2 = simpl fm
   8.261 -				in (fm2,Simp(fm,pr))
   8.262 -				end;
   8.263 -
   8.264 -	
   8.265 -(* ------------------------------------------------------------------------- *)
   8.266 -(*Help function for the generation of the proof EX.P_{minus \infty} --> EX. P(x) *)
   8.267 -(* ------------------------------------------------------------------------- *)
   8.268 -fun minusinf_wph x fm = let fun mk_atomar_minusinf_proof x fm = (Modd_minf(x,fm),Eq_minf(x,fm))
   8.269 -  
   8.270 -	      fun combine_minusinf_proofs opr (ppr1,ppr2) (qpr1,qpr2) = case opr of 
   8.271 -		 "CJ" => (Modd_minf_conjI(ppr1,qpr1),Eq_minf_conjI(ppr2,qpr2))
   8.272 -		|"DJ" => (Modd_minf_disjI(ppr1,qpr1),Eq_minf_disjI(ppr2,qpr2))
   8.273 -	in 
   8.274 - 
   8.275 - case fm of 
   8.276 - (Const ("Not", _) $  (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
   8.277 -     if (x=y) andalso (c1= zero) andalso (c2= one) then (HOLogic.true_const ,(mk_atomar_minusinf_proof x fm))
   8.278 -        else (fm ,(mk_atomar_minusinf_proof x fm))
   8.279 - |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
   8.280 -  	 if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one)
   8.281 -	 then (HOLogic.false_const ,(mk_atomar_minusinf_proof x fm))
   8.282 -	 				 else (fm,(mk_atomar_minusinf_proof x fm)) 
   8.283 - |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y ) $ z )) =>
   8.284 -       if (y=x) andalso (c1 = zero) then 
   8.285 -        if c2 = one then (HOLogic.false_const,(mk_atomar_minusinf_proof x fm)) else
   8.286 -	(HOLogic.true_const,(mk_atomar_minusinf_proof x fm))
   8.287 -	else (fm,(mk_atomar_minusinf_proof x fm))
   8.288 -  
   8.289 -  |(Const("Not",_)$(Const ("Divides.op dvd",_) $_ )) => (fm,mk_atomar_minusinf_proof x fm)
   8.290 -  
   8.291 -  |(Const ("Divides.op dvd",_) $_ ) => (fm,mk_atomar_minusinf_proof x fm)
   8.292 -  
   8.293 -  |(Const ("op &",_) $ p $ q) => let val (pfm,ppr) = minusinf_wph x p
   8.294 -  				    val (qfm,qpr) = minusinf_wph x q
   8.295 -				    val pr = (combine_minusinf_proofs "CJ" ppr qpr)
   8.296 -				     in 
   8.297 -				     (HOLogic.conj $ pfm $qfm , pr)
   8.298 -				     end 
   8.299 -  |(Const ("op |",_) $ p $ q) => let val (pfm,ppr) = minusinf_wph x p
   8.300 -  				     val (qfm,qpr) = minusinf_wph x q
   8.301 -				     val pr = (combine_minusinf_proofs "DJ" ppr qpr)
   8.302 -				     in 
   8.303 -				     (HOLogic.disj $ pfm $qfm , pr)
   8.304 -				     end 
   8.305 -
   8.306 -  |_ => (fm,(mk_atomar_minusinf_proof x fm))
   8.307 -  
   8.308 -  end;					 
   8.309 -(* ------------------------------------------------------------------------- *)	    (* Protokol for the Proof of the property of the minusinfinity formula*)
   8.310 -(* Just combines the to protokols *)
   8.311 -(* ------------------------------------------------------------------------- *)
   8.312 -fun minusinf_wp x fm  = let val (fm2,pr) = (minusinf_wph x fm)
   8.313 -                       in (fm2,Minusinf(pr))
   8.314 -                        end;
   8.315 -
   8.316 -(* ------------------------------------------------------------------------- *)
   8.317 -(*Help function for the generation of the proof EX.P_{plus \infty} --> EX. P(x) *)
   8.318 -(* ------------------------------------------------------------------------- *)
   8.319 -
   8.320 -fun plusinf_wph x fm = let fun mk_atomar_plusinf_proof x fm = (Modd_minf(x,fm),Eq_minf(x,fm))
   8.321 -  
   8.322 -	      fun combine_plusinf_proofs opr (ppr1,ppr2) (qpr1,qpr2) = case opr of 
   8.323 -		 "CJ" => (Modd_minf_conjI(ppr1,qpr1),Eq_minf_conjI(ppr2,qpr2))
   8.324 -		|"DJ" => (Modd_minf_disjI(ppr1,qpr1),Eq_minf_disjI(ppr2,qpr2))
   8.325 -	in 
   8.326 - 
   8.327 - case fm of 
   8.328 - (Const ("Not", _) $  (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
   8.329 -     if (x=y) andalso (c1= zero) andalso (c2= one) then (HOLogic.true_const ,(mk_atomar_plusinf_proof x fm))
   8.330 -        else (fm ,(mk_atomar_plusinf_proof x fm))
   8.331 - |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
   8.332 -  	 if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one)
   8.333 -	 then (HOLogic.false_const ,(mk_atomar_plusinf_proof x fm))
   8.334 -	 				 else (fm,(mk_atomar_plusinf_proof x fm)) 
   8.335 - |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y ) $ z )) =>
   8.336 -       if (y=x) andalso (c1 = zero) then 
   8.337 -        if c2 = one then (HOLogic.true_const,(mk_atomar_plusinf_proof x fm)) else
   8.338 -	(HOLogic.false_const,(mk_atomar_plusinf_proof x fm))
   8.339 -	else (fm,(mk_atomar_plusinf_proof x fm))
   8.340 -  
   8.341 -  |(Const("Not",_)$(Const ("Divides.op dvd",_) $_ )) => (fm,mk_atomar_plusinf_proof x fm)
   8.342 -  
   8.343 -  |(Const ("Divides.op dvd",_) $_ ) => (fm,mk_atomar_plusinf_proof x fm)
   8.344 -  
   8.345 -  |(Const ("op &",_) $ p $ q) => let val (pfm,ppr) = plusinf_wph x p
   8.346 -  				    val (qfm,qpr) = plusinf_wph x q
   8.347 -				    val pr = (combine_plusinf_proofs "CJ" ppr qpr)
   8.348 -				     in 
   8.349 -				     (HOLogic.conj $ pfm $qfm , pr)
   8.350 -				     end 
   8.351 -  |(Const ("op |",_) $ p $ q) => let val (pfm,ppr) = plusinf_wph x p
   8.352 -  				     val (qfm,qpr) = plusinf_wph x q
   8.353 -				     val pr = (combine_plusinf_proofs "DJ" ppr qpr)
   8.354 -				     in 
   8.355 -				     (HOLogic.disj $ pfm $qfm , pr)
   8.356 -				     end 
   8.357 -
   8.358 -  |_ => (fm,(mk_atomar_plusinf_proof x fm))
   8.359 -  
   8.360 -  end;					 
   8.361 -(* ------------------------------------------------------------------------- *)	    (* Protokol for the Proof of the property of the minusinfinity formula*)
   8.362 -(* Just combines the to protokols *)
   8.363 -(* ------------------------------------------------------------------------- *)
   8.364 -fun plusinf_wp x fm  = let val (fm2,pr) = (plusinf_wph x fm)
   8.365 -                       in (fm2,Minusinf(pr))
   8.366 -                        end;
   8.367 -
   8.368 -
   8.369 -(* ------------------------------------------------------------------------- *)
   8.370 -(*Protocol that we here uses Bset.*)
   8.371 -(* ------------------------------------------------------------------------- *)
   8.372 -fun bset_wp x fm = let val bs = bset x fm in
   8.373 -				(bs,Bset(x,fm,bs,mk_numeral (divlcm x fm)))
   8.374 -				end;
   8.375 -
   8.376 -(* ------------------------------------------------------------------------- *)
   8.377 -(*Protocol that we here uses Aset.*)
   8.378 -(* ------------------------------------------------------------------------- *)
   8.379 -fun aset_wp x fm = let val ast = aset x fm in
   8.380 -				(ast,Aset(x,fm,ast,mk_numeral (divlcm x fm)))
   8.381 -				end;
   8.382 - 
   8.383 -
   8.384 -
   8.385  (* ------------------------------------------------------------------------- *)
   8.386  (*function list to Set, constructs a set containing all elements of a given list.*)
   8.387  (* ------------------------------------------------------------------------- *)
   8.388 @@ -475,181 +181,11 @@
   8.389  		|(h::t) => Const("insert", T1 --> (T --> T)) $ h $(list_to_set T1 t)
   8.390  		end;
   8.391  		
   8.392 -
   8.393 -(*====================================================================*)
   8.394 -(* ------------------------------------------------------------------------- *)
   8.395 -(* ------------------------------------------------------------------------- *)
   8.396 -(*Protocol for the proof of the backward direction of the cooper theorem.*)
   8.397 -(* Helpfunction - Protokols evereything about the proof reconstruction*)
   8.398 -(* ------------------------------------------------------------------------- *)
   8.399 -fun not_bst_p_wph fm = case fm of
   8.400 -	Const("Not",_) $ R => if (is_arith_rel R) then (Not_bst_p_atomic (fm)) else CpLogError
   8.401 -	|Const("op &",_) $ ls $ rs => Not_bst_p_conjI((not_bst_p_wph ls),(not_bst_p_wph rs))
   8.402 -	|Const("op |",_) $ ls $ rs => Not_bst_p_disjI((not_bst_p_wph ls),(not_bst_p_wph rs))
   8.403 -	|_ => Not_bst_p_atomic (fm);
   8.404 -(* ------------------------------------------------------------------------- *)	
   8.405 -(* Main protocoling function for the backward direction gives the Bset and the divlcm and the Formula herself. Needed as inherited attributes for the proof reconstruction*)
   8.406 -(* ------------------------------------------------------------------------- *)
   8.407 -fun not_bst_p_wp x fm = let val prt = not_bst_p_wph fm
   8.408 -			    val D = mk_numeral (divlcm x fm)
   8.409 -			    val B = map norm_zero_one (bset x fm)
   8.410 -			in (Not_bst_p (x,fm,D,(list_to_set HOLogic.intT B) , prt))
   8.411 -			end;
   8.412 -(*====================================================================*)
   8.413 -(* ------------------------------------------------------------------------- *)
   8.414 -(* ------------------------------------------------------------------------- *)
   8.415 -(*Protocol for the proof of the backward direction of the cooper theorem.*)
   8.416 -(* Helpfunction - Protokols evereything about the proof reconstruction*)
   8.417 -(* ------------------------------------------------------------------------- *)
   8.418 -fun not_ast_p_wph fm = case fm of
   8.419 -	Const("Not",_) $ R => if (is_arith_rel R) then (Not_ast_p_atomic (fm)) else CpLogError
   8.420 -	|Const("op &",_) $ ls $ rs => Not_ast_p_conjI((not_ast_p_wph ls),(not_ast_p_wph rs))
   8.421 -	|Const("op |",_) $ ls $ rs => Not_ast_p_disjI((not_ast_p_wph ls),(not_ast_p_wph rs))
   8.422 -	|_ => Not_ast_p_atomic (fm);
   8.423 -(* ------------------------------------------------------------------------- *)	
   8.424 -(* Main protocoling function for the backward direction gives the Bset and the divlcm and the Formula herself. Needed as inherited attributes for the proof reconstruction*)
   8.425 -(* ------------------------------------------------------------------------- *)
   8.426 -fun not_ast_p_wp x fm = let val prt = not_ast_p_wph fm
   8.427 -			    val D = mk_numeral (divlcm x fm)
   8.428 -			    val B = map norm_zero_one (aset x fm)
   8.429 -			in (Not_ast_p (x,fm,D,(list_to_set HOLogic.intT B) , prt))
   8.430 -			end;
   8.431 -
   8.432 -(*======================================================*)
   8.433 -(* Protokolgeneration for the formula evaluation process*)
   8.434 -(*======================================================*)
   8.435 -
   8.436 -fun evalc_wp fm = 
   8.437 -  let fun evalc_atom_wp at =case at of  
   8.438 -    (Const (p,_) $ s $ t) =>(  
   8.439 -    case assoc (operations,p) of 
   8.440 -        Some f => ((if (f ((dest_numeral s),(dest_numeral t))) then EvalAt(HOLogic.mk_eq(at,HOLogic.true_const)) else EvalAt(HOLogic.mk_eq(at, HOLogic.false_const)))  
   8.441 -		   handle _ => Evalfm(at)) 
   8.442 -        | _ =>  Evalfm(at)) 
   8.443 -     |Const("Not",_)$(Const (p,_) $ s $ t) =>(  
   8.444 -       case assoc (operations,p) of 
   8.445 -         Some f => ((if (f ((dest_numeral s),(dest_numeral t))) then 
   8.446 -	  EvalAt(HOLogic.mk_eq(at, HOLogic.false_const))  else EvalAt(HOLogic.mk_eq(at,HOLogic.true_const)))  
   8.447 -		      handle _ => Evalfm(at)) 
   8.448 -         | _ => Evalfm(at)) 
   8.449 -     | _ => Evalfm(at)  
   8.450 - 
   8.451 -  in
   8.452 -   case fm of
   8.453 -    (Const("op &",_)$A$B) => EvalConst("CJ",evalc_wp A,evalc_wp B)
   8.454 -   |(Const("op |",_)$A$B) => EvalConst("DJ",evalc_wp A,evalc_wp B) 
   8.455 -   |(Const("op -->",_)$A$B) => EvalConst("IM",evalc_wp A,evalc_wp B) 
   8.456 -   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => EvalConst("EQ",evalc_wp A,evalc_wp B) 
   8.457 -   |_ => evalc_atom_wp fm
   8.458 -  end;
   8.459 -
   8.460 -
   8.461 -
   8.462 -(*======================================================*)
   8.463 -(* Protokolgeneration for the NNF Transformation        *)
   8.464 -(*======================================================*)
   8.465 -
   8.466 -fun cnnf_wp f = 
   8.467 -  let fun hcnnf_wp fm =
   8.468 -    case fm of
   8.469 -    (Const ("op &",_) $ p $ q) => NNFConst("CJ",hcnnf_wp p,hcnnf_wp q) 
   8.470 -    | (Const ("op |",_) $ p $ q) =>  NNFConst("DJ",hcnnf_wp p,hcnnf_wp q)
   8.471 -    | (Const ("op -->",_) $ p $q) => NNFConst("IM",hcnnf_wp (HOLogic.Not $ p),hcnnf_wp q)
   8.472 -    | (Const ("op =",Type ("fun",[Type ("bool", []),_])) $ p $ q) => NNFConst("EQ",hcnnf_wp (HOLogic.mk_conj(p,q)),hcnnf_wp (HOLogic.mk_conj((HOLogic.Not $ p), (HOLogic.Not $ q)))) 
   8.473 -
   8.474 -    | (Const ("Not",_) $ (Const("Not",_) $ p)) => NNFNN(hcnnf_wp p) 
   8.475 -    | (Const ("Not",_) $ (Const ("op &",_) $ p $ q)) => NNFConst ("NCJ",(hcnnf_wp(HOLogic.Not $ p)),(hcnnf_wp(HOLogic.Not $ q))) 
   8.476 -    | (Const ("Not",_) $(Const ("op |",_) $ (A as (Const ("op &",_) $ p $ q)) $  
   8.477 -    			(B as (Const ("op &",_) $ p1 $ r)))) => if p1 = negate p then 
   8.478 -		         NNFConst("SDJ",  
   8.479 -			   NNFConst("CJ",hcnnf_wp p,hcnnf_wp(HOLogic.Not $ q)),
   8.480 -			   NNFConst("CJ",hcnnf_wp p1,hcnnf_wp(HOLogic.Not $ r)))
   8.481 -			 else  NNFConst ("NDJ",(hcnnf_wp(HOLogic.Not $ A)),(hcnnf_wp(HOLogic.Not $ B))) 
   8.482 -
   8.483 -    | (Const ("Not",_) $ (Const ("op |",_) $ p $ q)) => NNFConst ("NDJ",(hcnnf_wp(HOLogic.Not $ p)),(hcnnf_wp(HOLogic.Not $ q))) 
   8.484 -    | (Const ("Not",_) $ (Const ("op -->",_) $ p $q)) =>  NNFConst ("NIM",(hcnnf_wp(p)),(hcnnf_wp(HOLogic.Not $ q))) 
   8.485 -    | (Const ("Not",_) $ (Const ("op =",Type ("fun",[Type ("bool", []),_]))  $ p $ q)) =>NNFConst ("NEQ",(NNFConst("CJ",hcnnf_wp p,hcnnf_wp(HOLogic.Not $ q))),(NNFConst("CJ",hcnnf_wp(HOLogic.Not $ p),hcnnf_wp q))) 
   8.486 -    | _ => NNFAt(fm)  
   8.487 -  in NNFSimp(hcnnf_wp f)
   8.488 -end; 
   8.489 -   
   8.490 -
   8.491 -
   8.492 -
   8.493 -
   8.494 -
   8.495 -(* ------------------------------------------------------------------------- *)
   8.496 -(*Cooper decision Procedure with proof protocoling*)
   8.497 -(* ------------------------------------------------------------------------- *)
   8.498 -
   8.499 -fun coopermi_wp vars fm =
   8.500 -  case fm of
   8.501 -   Const ("Ex",_) $ Abs(xo,T,po) => let 
   8.502 -    val (xn,np) = variant_abs(xo,T,po) 
   8.503 -    val x = (Free(xn , T))
   8.504 -    val p = np     (* Is this a legal proof for the P=NP Problem??*)
   8.505 -    val (p_inf,miprt) = simpl_wp (minusinf_wp x p)
   8.506 -    val (bset,bsprt) = bset_wp x p
   8.507 -    val nbst_p_prt = not_bst_p_wp x p
   8.508 -    val dlcm = divlcm x p 
   8.509 -    val js = 1 upto dlcm 
   8.510 -    fun p_element j b = linrep vars x (linear_add vars b (mk_numeral j)) p 
   8.511 -    fun stage j = list_disj (linrep vars x (mk_numeral j) p_inf :: map (p_element j) bset) 
   8.512 -   in (list_disj (map stage js),Cooper(mk_numeral dlcm,miprt,bsprt,nbst_p_prt))
   8.513 -   end
   8.514 -   
   8.515 -  | _ => (error "cooper: not an existential formula",No);
   8.516 -				
   8.517 -fun cooperpi_wp vars fm =
   8.518 -  case fm of
   8.519 -   Const ("Ex",_) $ Abs(xo,T,po) => let 
   8.520 -    val (xn,np) = variant_abs(xo,T,po) 
   8.521 -    val x = (Free(xn , T))
   8.522 -    val p = np     (* Is this a legal proof for the P=NP Problem??*)
   8.523 -    val (p_inf,piprt) = simpl_wp (plusinf_wp x p)
   8.524 -    val (aset,asprt) = aset_wp x p
   8.525 -    val nast_p_prt = not_ast_p_wp x p
   8.526 -    val dlcm = divlcm x p 
   8.527 -    val js = 1 upto dlcm 
   8.528 -    fun p_element j a = linrep vars x (linear_sub vars a (mk_numeral j)) p 
   8.529 -    fun stage j = list_disj (linrep vars x (mk_numeral j) p_inf :: map (p_element j) aset) 
   8.530 -   in (list_disj (map stage js),Cooper(mk_numeral dlcm,piprt,asprt,nast_p_prt))
   8.531 -   end
   8.532 -  | _ => (error "cooper: not an existential formula",No);
   8.533 -				
   8.534 -
   8.535 -
   8.536 -
   8.537 -
   8.538 -(*-----------------------------------------------------------------*)
   8.539 -(*-----------------------------------------------------------------*)
   8.540 -(*-----------------------------------------------------------------*)
   8.541 -(*---                                                           ---*)
   8.542 -(*---                                                           ---*)
   8.543 -(*---      Interpretation and Proofgeneration Part              ---*)
   8.544 -(*---                                                           ---*)
   8.545 -(*---      Protocole interpretation functions                   ---*)
   8.546 -(*---                                                           ---*)
   8.547 -(*---      and proofgeneration functions                        ---*)
   8.548 -(*---                                                           ---*)
   8.549 -(*---                                                           ---*)
   8.550 -(*---                                                           ---*)
   8.551 -(*---                                                           ---*)
   8.552 -(*-----------------------------------------------------------------*)
   8.553 -(*-----------------------------------------------------------------*)
   8.554 -(*-----------------------------------------------------------------*)
   8.555 -
   8.556  (* ------------------------------------------------------------------------- *)
   8.557  (* Returns both sides of an equvalence in the theorem*)
   8.558  (* ------------------------------------------------------------------------- *)
   8.559  fun qe_get_terms th = let val (_$(Const("op =",Type ("fun",[Type ("bool", []),_])) $ A $ B )) = prop_of th in (A,B) end;
   8.560  
   8.561 -
   8.562 -(*-------------------------------------------------------------*)
   8.563 -(*-------------------------------------------------------------*)
   8.564 -(*-------------------------------------------------------------*)
   8.565 -(*-------------------------------------------------------------*)
   8.566 -
   8.567  (* ------------------------------------------------------------------------- *)
   8.568  (* Modified version of the simple version with minimal amount of checking and postprocessing*)
   8.569  (* ------------------------------------------------------------------------- *)
   8.570 @@ -664,9 +200,6 @@
   8.571  
   8.572  (*-------------------------------------------------------------*)
   8.573  (*-------------------------------------------------------------*)
   8.574 -(*-------------------------------------------------------------*)
   8.575 -(*-------------------------------------------------------------*)
   8.576 -(*-------------------------------------------------------------*)
   8.577  
   8.578  fun cert_Trueprop sg t = cterm_of sg (HOLogic.mk_Trueprop t);
   8.579  
   8.580 @@ -680,7 +213,8 @@
   8.581    (*"ss" like simplification with simpset*)
   8.582    "ss" =>
   8.583      let
   8.584 -      val ss = presburger_ss addsimps [zdvd_iff_zmod_eq_0]
   8.585 +      val ss = presburger_ss addsimps
   8.586 +        [zdvd_iff_zmod_eq_0,unity_coeff_ex]
   8.587        val ct =  cert_Trueprop sg fm2
   8.588      in 
   8.589        simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
   8.590 @@ -725,6 +259,14 @@
   8.591      in 
   8.592        simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
   8.593      end
   8.594 +  (* like Existance Conjunction *)
   8.595 +  | "ec" =>
   8.596 +    let
   8.597 +      val ss = presburger_ss addsimps zadd_ac
   8.598 +      val ct = cert_Trueprop sg fm2
   8.599 +    in 
   8.600 +      simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (blast_tac HOL_cs 1)]
   8.601 +    end
   8.602  
   8.603    | "ac" =>
   8.604      let
   8.605 @@ -742,80 +284,92 @@
   8.606        simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
   8.607      end;
   8.608  
   8.609 +(*=============================================================*)
   8.610 +(*-------------------------------------------------------------*)
   8.611 +(*              The new compact model                          *)
   8.612 +(*-------------------------------------------------------------*)
   8.613 +(*=============================================================*)
   8.614  
   8.615 +fun thm_of sg decomp t = 
   8.616 +    let val (ts,recomb) = decomp t 
   8.617 +    in recomb (map (thm_of sg decomp) ts) 
   8.618 +    end;
   8.619 +
   8.620 +(*==================================================*)
   8.621 +(*     Compact Version for adjustcoeffeq            *)
   8.622 +(*==================================================*)
   8.623 +
   8.624 +fun decomp_adjustcoeffeq sg x l fm = case fm of
   8.625 +    (Const("Not",_)$(Const("op <",_) $(Const("0",_)) $(rt as (Const ("op +", _)$(Const ("op *",_) $    c $ y ) $z )))) => 
   8.626 +     let  
   8.627 +        val m = l div (dest_numeral c) 
   8.628 +        val n = if (x = y) then abs (m) else 1
   8.629 +        val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) 
   8.630 +        val rs = if (x = y) 
   8.631 +                 then (HOLogic.mk_binrel "op <" (zero,linear_sub [] (mk_numeral n) (HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) 
   8.632 +                 else HOLogic.mk_binrel "op <" (zero,linear_sub [] one rt )
   8.633 +        val ck = cterm_of sg (mk_numeral n)
   8.634 +        val cc = cterm_of sg c
   8.635 +        val ct = cterm_of sg z
   8.636 +        val cx = cterm_of sg y
   8.637 +        val pre = prove_elementar sg "lf" 
   8.638 +            (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral n)))
   8.639 +        val th1 = (pre RS (instantiate' [] [Some ck,Some cc, Some cx, Some ct] (ac_pi_eq)))
   8.640 +        in ([], fn [] => [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   8.641 +        end
   8.642  
   8.643 -(* ------------------------------------------------------------------------- *)
   8.644 -(* This function return an Isabelle proof, of the adjustcoffeq result.*)
   8.645 -(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
   8.646 -(* ------------------------------------------------------------------------- *)
   8.647 -fun proof_of_adjustcoeffeq sg (prt,rs) = case prt of
   8.648 -   ACfm fm => instantiate' [Some cboolT]
   8.649 -    [Some (cterm_of sg fm)] refl
   8.650 - | ACAt (k,at as (Const(p,_) $a $( Const ("op +", _)$(Const ("op *",_) $ 
   8.651 -      c $ x ) $t ))) => 
   8.652 -   let
   8.653 -     val ck = cterm_of sg (mk_numeral k)
   8.654 -     val cc = cterm_of sg c
   8.655 -     val ct = cterm_of sg t
   8.656 -     val cx = cterm_of sg x
   8.657 -     val ca = cterm_of sg a
   8.658 -   in case p of
   8.659 -     "op <" => let val pre = prove_elementar sg "lf" 
   8.660 -	                  (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
   8.661 -	           val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_lt_eq)))
   8.662 -		      in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
   8.663 -                   end
   8.664 -    |"op =" =>let val pre = prove_elementar sg "lf" 
   8.665 +  |(Const(p,_) $a $( Const ("op +", _)$(Const ("op *",_) $ 
   8.666 +      c $ y ) $t )) => 
   8.667 +   if (is_arith_rel fm) andalso (x = y) 
   8.668 +   then  
   8.669 +        let val m = l div (dest_numeral c) 
   8.670 +           val k = (if p = "op <" then abs(m) else m)  
   8.671 +           val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div k)*l) ), x))
   8.672 +           val rs = (HOLogic.mk_binrel p ((linear_cmul k a),(HOLogic.mk_binop "op +" ( xtm ,( linear_cmul k t) )))) 
   8.673 +
   8.674 +           val ck = cterm_of sg (mk_numeral k)
   8.675 +           val cc = cterm_of sg c
   8.676 +           val ct = cterm_of sg t
   8.677 +           val cx = cterm_of sg x
   8.678 +           val ca = cterm_of sg a
   8.679 +
   8.680 +	   in 
   8.681 +	case p of
   8.682 +	  "op <" => 
   8.683 +	let val pre = prove_elementar sg "lf" 
   8.684 +	    (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
   8.685 +            val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_lt_eq)))
   8.686 +	in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   8.687 +         end
   8.688 +
   8.689 +           |"op =" =>
   8.690 +	     let val pre = prove_elementar sg "lf" 
   8.691  	    (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k))))
   8.692 -	          in let val th1 = (pre RS(instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_eq_eq)))
   8.693 -	             in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
   8.694 -                      end
   8.695 -                  end
   8.696 -    |"Divides.op dvd" =>let val pre = prove_elementar sg "lf" 
   8.697 +	         val th1 = (pre RS(instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_eq_eq)))
   8.698 +	     in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   8.699 +             end
   8.700 +
   8.701 +             |"Divides.op dvd" =>
   8.702 +	       let val pre = prove_elementar sg "lf" 
   8.703  	   (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k))))
   8.704 -	                 val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct]) (ac_dvd_eq))
   8.705 -                         in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
   8.706 +                   val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct]) (ac_dvd_eq))
   8.707 +               in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   8.708                          
   8.709 -                          end
   8.710 -  end
   8.711 - |ACPI(k,at as (Const("Not",_)$(Const("op <",_) $a $( Const ("op +", _)$(Const ("op *",_) $ c $ x ) $t )))) => 
   8.712 -   let
   8.713 -     val ck = cterm_of sg (mk_numeral k)
   8.714 -     val cc = cterm_of sg c
   8.715 -     val ct = cterm_of sg t
   8.716 -     val cx = cterm_of sg x
   8.717 -     val pre = prove_elementar sg "lf" 
   8.718 -       (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
   8.719 -       val th1 = (pre RS (instantiate' [] [Some ck,Some cc, Some cx, Some ct] (ac_pi_eq)))
   8.720 +               end
   8.721 +              end
   8.722 +  else ([], fn [] => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl)
   8.723 +
   8.724 + |( Const ("Not", _) $ p) => ([p], fn [th] => th RS qe_Not)
   8.725 +  |( Const ("op &",_) $ p $ q) => ([p,q], fn [th1,th2] => [th1,th2] MRS qe_conjI)
   8.726 +  |( Const ("op |",_) $ p $ q) =>([p,q], fn [th1,th2] => [th1,th2] MRS qe_disjI)
   8.727  
   8.728 -         in [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
   8.729 -   end
   8.730 - |ACNeg(pr) => let val (Const("Not",_)$nrs) = rs
   8.731 -               in (proof_of_adjustcoeffeq sg (pr,nrs)) RS (qe_Not) 
   8.732 -               end
   8.733 - |ACConst(s,pr1,pr2) =>
   8.734 -   let val (Const(_,_)$rs1$rs2) = rs
   8.735 -       val th1 = proof_of_adjustcoeffeq sg (pr1,rs1)
   8.736 -       val th2 = proof_of_adjustcoeffeq sg (pr2,rs2)
   8.737 -       in case s of 
   8.738 -	 "CJ" => [th1,th2] MRS (qe_conjI)
   8.739 -         |"DJ" => [th1,th2] MRS (qe_disjI)
   8.740 -         |"IM" => [th1,th2] MRS (qe_impI)
   8.741 -         |"EQ" => [th1,th2] MRS (qe_eqI)
   8.742 -   end;
   8.743 +  |_ => ([], fn [] => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl);
   8.744  
   8.745 -
   8.746 -
   8.747 -
   8.748 -
   8.749 -
   8.750 -(* ------------------------------------------------------------------------- *)
   8.751 -(* This function return an Isabelle proof, of some properties on the atoms*)
   8.752 -(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
   8.753 -(* This function doese only instantiate the the theorems in the theory *)
   8.754 -(* ------------------------------------------------------------------------- *)
   8.755 -fun atomar_minf_proof_of sg dlcm (Modd_minf (x,fm1)) =
   8.756 -  let
   8.757 +(*==================================================*)
   8.758 +(*   Finding rho for modd_minusinfinity             *)
   8.759 +(*==================================================*)
   8.760 +fun rho_for_modd_minf x dlcm sg fm1 =
   8.761 +let
   8.762      (*Some certified Terms*)
   8.763      
   8.764     val ctrue = cterm_of sg HOLogic.true_const
   8.765 @@ -853,10 +407,11 @@
   8.766  		
   8.767      
   8.768     |_ => instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_minf)
   8.769 -   end	
   8.770 -
   8.771 - |atomar_minf_proof_of sg dlcm (Eq_minf (x,fm1)) =  let
   8.772 -       (*Some certified types*)
   8.773 +   end;	 
   8.774 +(*=========================================================================*)
   8.775 +(*=========================================================================*)
   8.776 +fun rho_for_eq_minf x dlcm  sg fm1 =  
   8.777 +   let
   8.778     val fm = norm_zero_one fm1
   8.779      in  case fm1 of 
   8.780        (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
   8.781 @@ -893,70 +448,24 @@
   8.782      |_ => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_minf))
   8.783   end;
   8.784  
   8.785 -
   8.786 -(* ------------------------------------------------------------------------- *)
   8.787 -(* This function combines proofs of some special form already synthetised from the subtrees to make*)
   8.788 -(* a new proof of the same form. The combination occures whith isabelle theorems which have been already prooved *)
   8.789 -(*these Theorems are in Presburger.thy and mostly do not relay on the arithmetic.*)
   8.790 -(* These are Theorems for the Property of P_{-infty}*)
   8.791 -(* ------------------------------------------------------------------------- *)
   8.792 -fun combine_minf_proof s pr1 pr2 = case s of
   8.793 -    "ECJ" => [pr1 , pr2] MRS (eq_minf_conjI)
   8.794 -
   8.795 -   |"EDJ" => [pr1 , pr2] MRS (eq_minf_disjI)
   8.796 -   
   8.797 -   |"MCJ" => [pr1 , pr2] MRS (modd_minf_conjI)
   8.798 -
   8.799 -   |"MDJ" => [pr1 , pr2] MRS (modd_minf_disjI);
   8.800 -
   8.801 -(* ------------------------------------------------------------------------- *)
   8.802 -(*This function return an isabelle Proof for the minusinfinity theorem*)
   8.803 -(* It interpretates the protool and gives the protokoles property of P_{...} as a theorem*)
   8.804 -(* ------------------------------------------------------------------------- *)
   8.805 -fun minf_proof_ofh sg dlcm prl = case prl of 
   8.806 +(*=====================================================*)
   8.807 +(*=====================================================*)
   8.808 +(*=========== minf proofs with the compact version==========*)
   8.809 +fun decomp_minf_eq x dlcm sg t =  case t of
   8.810 +   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_minf_conjI)
   8.811 +   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_minf_disjI)
   8.812 +   |_ => ([],fn [] => rho_for_eq_minf x dlcm sg t);
   8.813  
   8.814 -    Eq_minf (_) => atomar_minf_proof_of sg dlcm prl
   8.815 -    
   8.816 -   |Modd_minf (_) => atomar_minf_proof_of sg dlcm prl
   8.817 -   
   8.818 -   |Eq_minf_conjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
   8.819 -   				    val pr2 = minf_proof_ofh sg dlcm prl2
   8.820 -				 in (combine_minf_proof "ECJ" pr1 pr2)
   8.821 -				 end
   8.822 -				 
   8.823 -   |Eq_minf_disjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
   8.824 -   				    val pr2 = minf_proof_ofh sg dlcm prl2
   8.825 -				 in (combine_minf_proof "EDJ" pr1 pr2)
   8.826 -				 end
   8.827 -				 
   8.828 -   |Modd_minf_conjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
   8.829 -   				    val pr2 = minf_proof_ofh sg dlcm prl2
   8.830 -				 in (combine_minf_proof "MCJ" pr1 pr2)
   8.831 -				 end
   8.832 -				 
   8.833 -   |Modd_minf_disjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
   8.834 -   				    val pr2 = minf_proof_ofh sg dlcm prl2
   8.835 -				 in (combine_minf_proof "MDJ" pr1 pr2)
   8.836 -				 end;
   8.837 -(* ------------------------------------------------------------------------- *)
   8.838 -(* Main function For the rest both properies of P_{..} are needed and here both theorems are returned.*)				 
   8.839 -(* ------------------------------------------------------------------------- *)
   8.840 -fun  minf_proof_of sg dlcm (Minusinf (prl1,prl2))  = 
   8.841 -  let val pr1 = minf_proof_ofh sg dlcm prl1
   8.842 -      val pr2 = minf_proof_ofh sg dlcm prl2
   8.843 -  in (pr1, pr2)
   8.844 -end;
   8.845 -				 
   8.846 +fun decomp_minf_modd x dlcm sg t = case t of
   8.847 +   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_minf_conjI)
   8.848 +   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_minf_disjI)
   8.849 +   |_ => ([],fn [] => rho_for_modd_minf x dlcm sg t);
   8.850  
   8.851 -
   8.852 -
   8.853 -(* ------------------------------------------------------------------------- *)
   8.854 -(* This function return an Isabelle proof, of some properties on the atoms*)
   8.855 -(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
   8.856 -(* This function doese only instantiate the the theorems in the theory *)
   8.857 -(* ------------------------------------------------------------------------- *)
   8.858 -fun atomar_pinf_proof_of sg dlcm (Modd_minf (x,fm1)) =
   8.859 - let
   8.860 +(* -------------------------------------------------------------*)
   8.861 +(*                    Finding rho for pinf_modd                 *)
   8.862 +(* -------------------------------------------------------------*)
   8.863 +fun rho_for_modd_pinf x dlcm sg fm1 = 
   8.864 +let
   8.865      (*Some certified Terms*)
   8.866      
   8.867    val ctrue = cterm_of sg HOLogic.true_const
   8.868 @@ -996,9 +505,12 @@
   8.869  		
   8.870      
   8.871     |_ => instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_pinf)
   8.872 -   end	
   8.873 -
   8.874 - |atomar_pinf_proof_of sg dlcm (Eq_minf (x,fm1)) =  let
   8.875 +   end;	
   8.876 +(* -------------------------------------------------------------*)
   8.877 +(*                    Finding rho for pinf_eq                 *)
   8.878 +(* -------------------------------------------------------------*)
   8.879 +fun rho_for_eq_pinf x dlcm sg fm1 = 
   8.880 +  let
   8.881  					val fm = norm_zero_one fm1
   8.882      in  case fm1 of 
   8.883        (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
   8.884 @@ -1036,67 +548,58 @@
   8.885   end;
   8.886  
   8.887  
   8.888 -(* ------------------------------------------------------------------------- *)
   8.889 -(* This function combines proofs of some special form already synthetised from the subtrees to make*)
   8.890 -(* a new proof of the same form. The combination occures whith isabelle theorems which have been already prooved *)
   8.891 -(*these Theorems are in Presburger.thy and mostly do not relay on the arithmetic.*)
   8.892 -(* These are Theorems for the Property of P_{+infty}*)
   8.893 -(* ------------------------------------------------------------------------- *)
   8.894 -fun combine_pinf_proof s pr1 pr2 = case s of
   8.895 -    "ECJ" => [pr1 , pr2] MRS (eq_pinf_conjI)
   8.896 +
   8.897 +fun  minf_proof_of_c sg x dlcm t =
   8.898 +  let val minf_eqth   = thm_of sg (decomp_minf_eq x dlcm sg) t
   8.899 +      val minf_moddth = thm_of sg (decomp_minf_modd x dlcm sg) t
   8.900 +  in (minf_eqth, minf_moddth)
   8.901 +end;
   8.902  
   8.903 -   |"EDJ" => [pr1 , pr2] MRS (eq_pinf_disjI)
   8.904 -   
   8.905 -   |"MCJ" => [pr1 , pr2] MRS (modd_pinf_conjI)
   8.906 +(*=========== pinf proofs with the compact version==========*)
   8.907 +fun decomp_pinf_eq x dlcm sg t = case t of
   8.908 +   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_conjI)
   8.909 +   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_disjI)
   8.910 +   |_ =>([],fn [] => rho_for_eq_pinf x dlcm sg t) ;
   8.911  
   8.912 -   |"MDJ" => [pr1 , pr2] MRS (modd_pinf_disjI);
   8.913 +fun decomp_pinf_modd x dlcm sg t =  case t of
   8.914 +   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_conjI)
   8.915 +   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_disjI)
   8.916 +   |_ => ([],fn [] => rho_for_modd_pinf x dlcm sg t);
   8.917 +
   8.918 +fun  pinf_proof_of_c sg x dlcm t =
   8.919 +  let val pinf_eqth   = thm_of sg (decomp_pinf_eq x dlcm sg) t
   8.920 +      val pinf_moddth = thm_of sg (decomp_pinf_modd x dlcm sg) t
   8.921 +  in (pinf_eqth,pinf_moddth)
   8.922 +end;
   8.923 +
   8.924  
   8.925  (* ------------------------------------------------------------------------- *)
   8.926 -(*This function return an isabelle Proof for the minusinfinity theorem*)
   8.927 -(* It interpretates the protool and gives the protokoles property of P_{...} as a theorem*)
   8.928 +(* Here we generate the theorem for the Bset Property in the simple direction*)
   8.929 +(* It is just an instantiation*)
   8.930  (* ------------------------------------------------------------------------- *)
   8.931 -fun pinf_proof_ofh sg dlcm prl = case prl of 
   8.932 +(*
   8.933 +fun bsetproof_of sg (x as Free(xn,xT)) fm bs dlcm   = 
   8.934 +  let
   8.935 +    val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
   8.936 +    val cdlcm = cterm_of sg dlcm
   8.937 +    val cB = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one bs))
   8.938 +  in instantiate' [] [Some cdlcm,Some cB, Some cp] (bst_thm)
   8.939 +end;
   8.940  
   8.941 -    Eq_minf (_) => atomar_pinf_proof_of sg dlcm prl
   8.942 -    
   8.943 -   |Modd_minf (_) => atomar_pinf_proof_of sg dlcm prl
   8.944 -   
   8.945 -   |Eq_minf_conjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
   8.946 -   				    val pr2 = pinf_proof_ofh sg dlcm prl2
   8.947 -				 in (combine_pinf_proof "ECJ" pr1 pr2)
   8.948 -				 end
   8.949 -				 
   8.950 -   |Eq_minf_disjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
   8.951 -   				    val pr2 = pinf_proof_ofh sg dlcm prl2
   8.952 -				 in (combine_pinf_proof "EDJ" pr1 pr2)
   8.953 -				 end
   8.954 -				 
   8.955 -   |Modd_minf_conjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
   8.956 -   				    val pr2 = pinf_proof_ofh sg dlcm prl2
   8.957 -				 in (combine_pinf_proof "MCJ" pr1 pr2)
   8.958 -				 end
   8.959 -				 
   8.960 -   |Modd_minf_disjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
   8.961 -   				    val pr2 = pinf_proof_ofh sg dlcm prl2
   8.962 -				 in (combine_pinf_proof "MDJ" pr1 pr2)
   8.963 -				 end;
   8.964 -(* ------------------------------------------------------------------------- *)
   8.965 -(* Main function For the rest both properies of P_{..} are needed and here both theorems are returned.*)				 
   8.966 -(* ------------------------------------------------------------------------- *)
   8.967 -fun pinf_proof_of sg dlcm (Minusinf (prl1,prl2))  = 
   8.968 -  let val pr1 = pinf_proof_ofh sg dlcm prl1
   8.969 -      val pr2 = pinf_proof_ofh sg dlcm prl2
   8.970 -  in (pr1, pr2)
   8.971 +fun asetproof_of sg (x as Free(xn,xT)) fm ast dlcm = 
   8.972 +  let
   8.973 +    val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
   8.974 +    val cdlcm = cterm_of sg dlcm
   8.975 +    val cA = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one ast))
   8.976 +  in instantiate' [] [Some cdlcm,Some cA, Some cp] (ast_thm)
   8.977  end;
   8.978 -				 
   8.979 -
   8.980 -
   8.981 -(* ------------------------------------------------------------------------- *)    
   8.982 -(* Protokol interpretation function for the backwards direction for cooper's Theorem*)
   8.983 +*)
   8.984  
   8.985  (* For the generation of atomic Theorems*)
   8.986  (* Prove the premisses on runtime and then make RS*)
   8.987  (* ------------------------------------------------------------------------- *)
   8.988 +
   8.989 +(*========= this is rho ============*)
   8.990  fun generate_atomic_not_bst_p sg (x as Free(xn,xT)) fm dlcm B at = 
   8.991    let
   8.992      val cdlcm = cterm_of sg dlcm
   8.993 @@ -1157,28 +660,23 @@
   8.994        		
   8.995      end;
   8.996      
   8.997 +
   8.998  (* ------------------------------------------------------------------------- *)    
   8.999  (* Main interpretation function for this backwards dirction*)
  8.1000  (* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*)
  8.1001  (*Help Function*)
  8.1002  (* ------------------------------------------------------------------------- *)
  8.1003 -fun not_bst_p_proof_of_h sg x fm dlcm B prt = case prt of 
  8.1004 -	(Not_bst_p_atomic(fm2)) => (generate_atomic_not_bst_p sg x fm dlcm B fm2)
  8.1005 -	
  8.1006 -	|(Not_bst_p_conjI(pr1,pr2)) => 
  8.1007 -			let val th1 = (not_bst_p_proof_of_h sg x fm dlcm B pr1)
  8.1008 -			    val th2 = (not_bst_p_proof_of_h sg x fm dlcm B pr2)
  8.1009 -			    in ([th1,th2] MRS (not_bst_p_conjI))
  8.1010 -			    end
  8.1011 +
  8.1012 +(*==================== Proof with the compact version   *)
  8.1013  
  8.1014 -	|(Not_bst_p_disjI(pr1,pr2)) => 
  8.1015 -			let val th1 = (not_bst_p_proof_of_h sg x fm dlcm B pr1)
  8.1016 -			    val th2 = (not_bst_p_proof_of_h sg x fm dlcm B pr2)
  8.1017 -			    in ([th1,th2] MRS not_bst_p_disjI)
  8.1018 -			    end;
  8.1019 -(* Main function*)
  8.1020 -fun not_bst_p_proof_of sg (Not_bst_p(x as Free(xn,xT),fm,dlcm,B,prl)) =
  8.1021 -  let val th =  not_bst_p_proof_of_h sg x fm dlcm B prl
  8.1022 +fun decomp_nbstp sg x dlcm B fm t = case t of 
  8.1023 +   Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_bst_p_conjI )
  8.1024 +  |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_bst_p_disjI)
  8.1025 +  |_ => ([], fn [] => generate_atomic_not_bst_p sg x fm dlcm B t);
  8.1026 +
  8.1027 +fun not_bst_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm B t =
  8.1028 +  let 
  8.1029 +       val th =  thm_of sg (decomp_nbstp sg x dlcm (list_to_set xT (map norm_zero_one B)) fm) t
  8.1030        val fma = absfree (xn,xT, norm_zero_one fm)
  8.1031    in let val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
  8.1032       in [th,th1] MRS (not_bst_p_Q_elim)
  8.1033 @@ -1192,6 +690,7 @@
  8.1034  (* For the generation of atomic Theorems*)
  8.1035  (* Prove the premisses on runtime and then make RS*)
  8.1036  (* ------------------------------------------------------------------------- *)
  8.1037 +(*========= this is rho ============*)
  8.1038  fun generate_atomic_not_ast_p sg (x as Free(xn,xT)) fm dlcm A at = 
  8.1039    let
  8.1040      val cdlcm = cterm_of sg dlcm
  8.1041 @@ -1250,81 +749,109 @@
  8.1042     |_ => (instantiate' [] [Some cfma,  Some cdlcm, Some cA,Some cat] (not_ast_p_fm))
  8.1043        		
  8.1044      end;
  8.1045 -    
  8.1046 -(* ------------------------------------------------------------------------- *)    
  8.1047 +
  8.1048 +(* ------------------------------------------------------------------------ *)
  8.1049  (* Main interpretation function for this backwards dirction*)
  8.1050  (* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*)
  8.1051  (*Help Function*)
  8.1052  (* ------------------------------------------------------------------------- *)
  8.1053 -fun not_ast_p_proof_of_h sg x fm dlcm A prt = case prt of 
  8.1054 -	(Not_ast_p_atomic(fm2)) => (generate_atomic_not_ast_p sg x fm dlcm A fm2)
  8.1055 -	
  8.1056 -	|(Not_ast_p_conjI(pr1,pr2)) => 
  8.1057 -			let val th1 = (not_ast_p_proof_of_h sg x fm dlcm A pr1)
  8.1058 -			    val th2 = (not_ast_p_proof_of_h sg x fm dlcm A pr2)
  8.1059 -			    in ([th1,th2] MRS (not_ast_p_conjI))
  8.1060 -			    end
  8.1061 +
  8.1062 +fun decomp_nastp sg x dlcm A fm t = case t of 
  8.1063 +   Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_conjI )
  8.1064 +  |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_disjI)
  8.1065 +  |_ => ([], fn [] => generate_atomic_not_ast_p sg x fm dlcm A t);
  8.1066  
  8.1067 -	|(Not_ast_p_disjI(pr1,pr2)) => 
  8.1068 -			let val th1 = (not_ast_p_proof_of_h sg x fm dlcm A pr1)
  8.1069 -			    val th2 = (not_ast_p_proof_of_h sg x fm dlcm A pr2)
  8.1070 -			    in ([th1,th2] MRS (not_ast_p_disjI))
  8.1071 -			    end;
  8.1072 -(* Main function*)
  8.1073 -fun not_ast_p_proof_of sg (Not_ast_p(x as Free(xn,xT),fm,dlcm,A,prl)) =
  8.1074 -  let val th =  not_ast_p_proof_of_h sg x fm dlcm A prl
  8.1075 +fun not_ast_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm A t =
  8.1076 +  let 
  8.1077 +       val th =  thm_of sg (decomp_nastp sg x dlcm (list_to_set xT (map norm_zero_one A)) fm) t
  8.1078        val fma = absfree (xn,xT, norm_zero_one fm)
  8.1079 -      val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
  8.1080 -  in [th,th1] MRS (not_ast_p_Q_elim)
  8.1081 -end;
  8.1082 +  in let val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
  8.1083 +     in [th,th1] MRS (not_ast_p_Q_elim)
  8.1084 +     end
  8.1085 +  end;
  8.1086  
  8.1087  
  8.1088 +(* -------------------------------*)
  8.1089 +(* Finding rho and beta for evalc *)
  8.1090 +(* -------------------------------*)
  8.1091  
  8.1092 +fun rho_for_evalc sg at = case at of  
  8.1093 +    (Const (p,_) $ s $ t) =>(  
  8.1094 +    case assoc (operations,p) of 
  8.1095 +        Some f => 
  8.1096 +           ((if (f ((dest_numeral s),(dest_numeral t))) 
  8.1097 +             then prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const)) 
  8.1098 +             else prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const)))  
  8.1099 +		   handle _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl
  8.1100 +        | _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl )) 
  8.1101 +     |Const("Not",_)$(Const (p,_) $ s $ t) =>(  
  8.1102 +       case assoc (operations,p) of 
  8.1103 +         Some f => 
  8.1104 +           ((if (f ((dest_numeral s),(dest_numeral t))) 
  8.1105 +             then prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const))  
  8.1106 +             else prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const)))  
  8.1107 +		      handle _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl) 
  8.1108 +         | _ => instantiate' [Some cboolT] [Some (cterm_of sg at)] refl ) 
  8.1109 +     | _ =>   instantiate' [Some cboolT] [Some (cterm_of sg at)] refl;
  8.1110 +
  8.1111 +
  8.1112 +(*=========================================================*)
  8.1113 +fun decomp_evalc sg t = case t of
  8.1114 +   (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
  8.1115 +   |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
  8.1116 +   |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
  8.1117 +   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
  8.1118 +   |_ => ([], fn [] => rho_for_evalc sg t);
  8.1119 +
  8.1120 +
  8.1121 +fun proof_of_evalc sg fm = thm_of sg (decomp_evalc sg) fm;
  8.1122 +
  8.1123 +(*==================================================*)
  8.1124 +(*     Proof of linform with the compact model      *)
  8.1125 +(*==================================================*)
  8.1126 +
  8.1127 +
  8.1128 +fun decomp_linform sg vars t = case t of
  8.1129 +   (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
  8.1130 +   |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
  8.1131 +   |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
  8.1132 +   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
  8.1133 +   |(Const("Not",_)$p) => ([p],fn [th] => th RS qe_Not)
  8.1134 +   |(Const("Divides.op dvd",_)$d$r) => ([], fn [] => (prove_elementar sg "lf" (HOLogic.mk_eq (r, lint vars r))) RS (instantiate' [] [None , None, Some (cterm_of sg d)](linearize_dvd)))
  8.1135 +   |_ => ([], fn [] => prove_elementar sg "lf" (HOLogic.mk_eq (t, linform vars t)));
  8.1136 +
  8.1137 +fun proof_of_linform sg vars f = thm_of sg (decomp_linform sg vars) f;
  8.1138  
  8.1139  (* ------------------------------------------------------------------------- *)
  8.1140  (* Interpretaion of Protocols of the cooper procedure : minusinfinity version*)
  8.1141  (* ------------------------------------------------------------------------- *)
  8.1142 -
  8.1143 -
  8.1144 -fun coopermi_proof_of sg x (Cooper (dlcm,Simp(fm,miprt),bsprt,nbst_p_prt)) =
  8.1145 +fun coopermi_proof_of sg (x as Free(xn,xT)) fm B dlcm =
  8.1146    (* Get the Bset thm*)
  8.1147 -  let val (mit1,mit2) = minf_proof_of sg dlcm miprt
  8.1148 -      val fm1 = norm_zero_one (simpl fm) 
  8.1149 +  let val (minf_eqth, minf_moddth) = minf_proof_of_c sg x dlcm fm 
  8.1150        val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm));
  8.1151 -      val nbstpthm = not_bst_p_proof_of sg nbst_p_prt
  8.1152 -    (* Return the four theorems needed to proove the whole Cooper Theorem*)
  8.1153 -  in (dpos,mit2,nbstpthm,mit1)
  8.1154 +      val nbstpthm = not_bst_p_proof_of_c sg x fm dlcm B fm
  8.1155 +  in (dpos,minf_eqth,nbstpthm,minf_moddth)
  8.1156  end;
  8.1157  
  8.1158 -
  8.1159  (* ------------------------------------------------------------------------- *)
  8.1160  (* Interpretaion of Protocols of the cooper procedure : plusinfinity version *)
  8.1161  (* ------------------------------------------------------------------------- *)
  8.1162 -
  8.1163 -
  8.1164 -fun cooperpi_proof_of sg x (Cooper (dlcm,Simp(fm,miprt),bsprt,nast_p_prt)) =
  8.1165 -  let val (mit1,mit2) = pinf_proof_of sg dlcm miprt
  8.1166 -      val fm1 = norm_zero_one (simpl fm) 
  8.1167 +fun cooperpi_proof_of sg (x as Free(xn,xT)) fm A dlcm =
  8.1168 +  let val (pinf_eqth,pinf_moddth) = pinf_proof_of_c sg x dlcm fm
  8.1169        val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm));
  8.1170 -      val nastpthm = not_ast_p_proof_of sg nast_p_prt
  8.1171 -  in (dpos,mit2,nastpthm,mit1)
  8.1172 +      val nastpthm = not_ast_p_proof_of_c sg x fm dlcm A fm
  8.1173 +  in (dpos,pinf_eqth,nastpthm,pinf_moddth)
  8.1174  end;
  8.1175  
  8.1176 -
  8.1177  (* ------------------------------------------------------------------------- *)
  8.1178  (* Interpretaion of Protocols of the cooper procedure : full version*)
  8.1179  (* ------------------------------------------------------------------------- *)
  8.1180 -
  8.1181 -
  8.1182 -
  8.1183 -fun cooper_thm sg s (x as Free(xn,xT)) vars cfm = case s of
  8.1184 -  "pi" => let val (rs,prt) = cooperpi_wp (xn::vars) (HOLogic.mk_exists(xn,xT,cfm))
  8.1185 -	      val (dpsthm,th1,nbpth,th3) = cooperpi_proof_of sg x prt
  8.1186 -		   in [dpsthm,th1,nbpth,th3] MRS (cppi_eq)
  8.1187 +fun cooper_thm sg s (x as Free(xn,xT)) cfm dlcm ast bst= case s of
  8.1188 +  "pi" => let val (dpsthm,pinf_eqth,nbpth,pinf_moddth) = cooperpi_proof_of sg x cfm ast dlcm 
  8.1189 +	      in [dpsthm,pinf_eqth,nbpth,pinf_moddth] MRS (cppi_eq)
  8.1190             end
  8.1191 -  |"mi" => let val (rs,prt) = coopermi_wp (xn::vars) (HOLogic.mk_exists(xn,xT,cfm))
  8.1192 -	       val (dpsthm,th1,nbpth,th3) = coopermi_proof_of sg x prt
  8.1193 -		   in [dpsthm,th1,nbpth,th3] MRS (cpmi_eq)
  8.1194 +  |"mi" => let val (dpsthm,minf_eqth,nbpth,minf_moddth) = coopermi_proof_of sg x cfm bst dlcm
  8.1195 +	       in [dpsthm,minf_eqth,nbpth,minf_moddth] MRS (cpmi_eq)
  8.1196                  end
  8.1197   |_ => error "parameter error";
  8.1198  
  8.1199 @@ -1333,9 +860,11 @@
  8.1200  (* It shoud be plugged in the qfnp argument of the quantifier elimination proof function*)
  8.1201  (* ------------------------------------------------------------------------- *)
  8.1202  
  8.1203 -fun cooper_prv sg (x as Free(xn,xT)) efm vars = let 
  8.1204 -   val l = formlcm x efm
  8.1205 -   val ac_thm = proof_of_adjustcoeffeq sg (adjustcoeffeq_wp  x l efm)
  8.1206 +fun cooper_prv sg (x as Free(xn,xT)) efm = let 
  8.1207 +   val lfm_thm = proof_of_linform sg [xn] efm
  8.1208 +   val efm2 = snd(qe_get_terms lfm_thm)
  8.1209 +   val l = formlcm x efm2
  8.1210 +   val ac_thm = [lfm_thm , (thm_of sg (decomp_adjustcoeffeq sg x l) efm2)] MRS trans
  8.1211     val fm = snd (qe_get_terms ac_thm)
  8.1212     val  cfm = unitycoeff x fm
  8.1213     val afm = adjustcoeff x l fm
  8.1214 @@ -1344,8 +873,11 @@
  8.1215       [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff]
  8.1216     val uth = instantiate' [] [Some (cterm_of sg P) , Some (cterm_of sg (mk_numeral l))] (unity_coeff_ex)
  8.1217     val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI)
  8.1218 -   val cms = if ((length (aset x cfm)) < (length (bset x cfm))) then "pi" else "mi"
  8.1219 -   val cp_thm = cooper_thm sg cms x vars cfm
  8.1220 +   val A = aset x cfm
  8.1221 +   val B = bset x cfm
  8.1222 +   val dlcm = mk_numeral (divlcm x cfm)
  8.1223 +   val cms = if ((length A) < (length B )) then "pi" else "mi"
  8.1224 +   val cp_thm = cooper_thm sg cms x cfm dlcm A B
  8.1225     val exp_cp_thm = refl RS (simplify ss (cp_thm RSN (2,trans)))
  8.1226     val (lsuth,rsuth) = qe_get_terms (uth)
  8.1227     val (lseacth,rseacth) = qe_get_terms(e_ac_thm)
  8.1228 @@ -1353,98 +885,46 @@
  8.1229     val  u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans
  8.1230   in  ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans)
  8.1231     end
  8.1232 -|cooper_prv _ _ _ _ = error "Parameters format";
  8.1233 +|cooper_prv _ _ _ =  error "Parameters format";
  8.1234 +
  8.1235  
  8.1236  
  8.1237 -(*====================================================*)
  8.1238 -(*Interpretation function for the evaluation protokol *)
  8.1239 -(*====================================================*)
  8.1240 -
  8.1241 -fun proof_of_evalc sg fm =
  8.1242 -let
  8.1243 -fun proof_of_evalch prt = case prt of
  8.1244 -  EvalAt(at) => prove_elementar sg "ss" at
  8.1245 - |Evalfm(fm) => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl
  8.1246 - |EvalConst(s,pr1,pr2) => 
  8.1247 -   let val th1 = proof_of_evalch pr1
  8.1248 -       val th2 = proof_of_evalch pr2
  8.1249 -   in case s of
  8.1250 -     "CJ" =>[th1,th2] MRS (qe_conjI)
  8.1251 -    |"DJ" =>[th1,th2] MRS (qe_disjI)
  8.1252 -    |"IM" =>[th1,th2] MRS (qe_impI)
  8.1253 -    |"EQ" =>[th1,th2] MRS (qe_eqI)
  8.1254 -    end
  8.1255 -in proof_of_evalch (evalc_wp fm)
  8.1256 -end;
  8.1257 -
  8.1258 -(*============================================================*)
  8.1259 -(*Interpretation function for the NNF-Transformation protokol *)
  8.1260 -(*============================================================*)
  8.1261 +fun decomp_cnnf sg lfnp P = case P of 
  8.1262 +     Const ("op &",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS qe_conjI )
  8.1263 +   |Const ("op |",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS  qe_disjI)
  8.1264 +   |Const ("Not",_) $ (Const("Not",_) $ p) => ([p], fn [th] => th RS nnf_nn)
  8.1265 +   |Const("Not",_) $ (Const(opn,T) $ p $ q) => 
  8.1266 +     if opn = "op |" 
  8.1267 +      then case (p,q) of 
  8.1268 +         (A as (Const ("op &",_) $ r $ s),B as (Const ("op &",_) $ r1 $ t)) =>
  8.1269 +          if r1 = negate r 
  8.1270 +          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)
  8.1271  
  8.1272 -fun proof_of_cnnf sg fm pf = 
  8.1273 -let fun proof_of_cnnfh prt pat = case prt of
  8.1274 -  NNFAt(at) => pat at
  8.1275 - |NNFSimp (pr) => let val th1 = proof_of_cnnfh pr pat
  8.1276 -                  in let val fm2 = snd (qe_get_terms th1) 
  8.1277 -		     in [th1,prove_elementar sg "ss" (HOLogic.mk_eq(fm2 ,simpl fm2))] MRS trans
  8.1278 -                     end
  8.1279 -                  end
  8.1280 - |NNFNN (pr) => (proof_of_cnnfh pr pat) RS (nnf_nn)
  8.1281 - |NNFConst (s,pr1,pr2) =>
  8.1282 -   let val th1 = proof_of_cnnfh pr1 pat
  8.1283 -       val th2 = proof_of_cnnfh pr2 pat
  8.1284 -   in case s of
  8.1285 -     "CJ" => [th1,th2] MRS (qe_conjI)
  8.1286 -    |"DJ" => [th1,th2] MRS (qe_disjI)
  8.1287 -    |"IM" => [th1,th2] MRS (nnf_im)
  8.1288 -    |"EQ" => [th1,th2] MRS (nnf_eq)
  8.1289 -    |"SDJ" => let val (Const("op &",_)$A$_) = fst (qe_get_terms th1)
  8.1290 -	          val (Const("op &",_)$C$_) = fst (qe_get_terms th2)
  8.1291 -	      in [th1,th2,prove_elementar sg "ss" (HOLogic.mk_eq (A,HOLogic.Not $ C))] MRS (nnf_sdj)
  8.1292 -	      end
  8.1293 -    |"NCJ" => [th1,th2] MRS (nnf_ncj)
  8.1294 -    |"NIM" => [th1,th2] MRS (nnf_nim)
  8.1295 -    |"NEQ" => [th1,th2] MRS (nnf_neq)
  8.1296 -    |"NDJ" => [th1,th2] MRS (nnf_ndj)
  8.1297 -   end
  8.1298 -in proof_of_cnnfh (cnnf_wp fm) pf
  8.1299 -end;
  8.1300 +          else ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj)
  8.1301 +        |(_,_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj)
  8.1302 +      else (
  8.1303 +         case (opn,T) of 
  8.1304 +           ("op &",_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_ncj )
  8.1305 +           |("op -->",_) => ([p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_nim )
  8.1306 +           |("op =",Type ("fun",[Type ("bool", []),_])) => 
  8.1307 +           ([HOLogic.conj $ p $ (HOLogic.Not $ q),HOLogic.conj $ (HOLogic.Not $ p) $ q], fn [th1,th2] => [th1,th2] MRS nnf_neq)
  8.1308 +            |(_,_) => ([], fn [] => lfnp P)
  8.1309 +)
  8.1310 +
  8.1311 +   |(Const ("op -->",_) $ p $ q) => ([HOLogic.Not$p,q], fn [th1,th2] => [th1,th2] MRS nnf_im)
  8.1312 +
  8.1313 +   |(Const ("op =", Type ("fun",[Type ("bool", []),_])) $ p $ q) =>
  8.1314 +     ([HOLogic.conj $ p $ q,HOLogic.conj $ (HOLogic.Not $ p) $ (HOLogic.Not $ q) ], fn [th1,th2] =>[th1,th2] MRS nnf_eq )
  8.1315 +   |_ => ([], fn [] => lfnp P);
  8.1316  
  8.1317  
  8.1318  
  8.1319  
  8.1320 -(*====================================================*)
  8.1321 -(* Interpretation function for the linform protokol   *)
  8.1322 -(*====================================================*)
  8.1323 -
  8.1324 -
  8.1325 -fun proof_of_linform sg vars f = 
  8.1326 -  let fun proof_of_linformh prt = 
  8.1327 -  case prt of
  8.1328 -    (LfAt (at)) =>  prove_elementar sg "lf" (HOLogic.mk_eq (at, linform vars at))
  8.1329 -   |(LfAtdvd (Const("Divides.op dvd",_)$d$t)) => (prove_elementar sg "lf" (HOLogic.mk_eq (t, lint vars t))) RS (instantiate' [] [None , None, Some (cterm_of sg d)](linearize_dvd))
  8.1330 -   |(Lffm (fm)) => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl)
  8.1331 -   |(LfConst (s,pr1,pr2)) =>
  8.1332 -     let val th1 = proof_of_linformh pr1
  8.1333 -	 val th2 = proof_of_linformh pr2
  8.1334 -     in case s of
  8.1335 -       "CJ" => [th1,th2] MRS (qe_conjI)
  8.1336 -      |"DJ" =>[th1,th2] MRS (qe_disjI)
  8.1337 -      |"IM" =>[th1,th2] MRS (qe_impI)
  8.1338 -      |"EQ" =>[th1,th2] MRS (qe_eqI)
  8.1339 -     end
  8.1340 -   |(LfNot(pr)) => 
  8.1341 -     let val th = proof_of_linformh pr
  8.1342 -     in (th RS (qe_Not))
  8.1343 -     end
  8.1344 -   |(LfQ(s,xn,xT,pr)) => 
  8.1345 -     let val th = forall_intr (cterm_of sg (Free(xn,xT)))(proof_of_linformh pr)
  8.1346 -     in if s = "Ex" 
  8.1347 -        then (th COMP(qe_exI) )
  8.1348 -        else (th COMP(qe_ALLI) )
  8.1349 -     end
  8.1350 -in
  8.1351 - proof_of_linformh (linform_wp f)
  8.1352 -end;
  8.1353 +fun proof_of_cnnf sg p lfnp = 
  8.1354 + let val th1 = thm_of sg (decomp_cnnf sg lfnp) p
  8.1355 +     val rs = snd(qe_get_terms th1)
  8.1356 +     val th2 = prove_elementar sg "ss" (HOLogic.mk_eq(rs,simpl rs))
  8.1357 +  in [th1,th2] MRS trans
  8.1358 +  end;
  8.1359  
  8.1360  end;
     9.1 --- a/src/HOL/Tools/Presburger/presburger.ML	Wed May 19 11:21:19 2004 +0200
     9.2 +++ b/src/HOL/Tools/Presburger/presburger.ML	Wed May 19 11:23:59 2004 +0200
     9.3 @@ -6,10 +6,13 @@
     9.4  Tactic for solving arithmetical Goals in Presburger Arithmetic
     9.5  *)
     9.6  
     9.7 +(* This version of presburger deals with occurences of functional symbols in the subgoal and abstract over them to try to prove the more general formula. It then resolves with the subgoal. To disable this feature call the procedure with the parameter no_abs
     9.8 +*)
     9.9 +
    9.10  signature PRESBURGER = 
    9.11  sig
    9.12 - val presburger_tac : bool -> int -> tactic
    9.13 - val presburger_method : bool -> int -> Proof.method
    9.14 + val presburger_tac : bool -> bool -> int -> tactic
    9.15 + val presburger_method : bool -> bool -> int -> Proof.method
    9.16   val setup : (theory -> theory) list
    9.17   val trace : bool ref
    9.18  end;
    9.19 @@ -25,19 +28,18 @@
    9.20  (* Here still only one problem : The proof for the arithmetical transformations done on the dvd atomic formulae*)
    9.21  (*-----------------------------------------------------------------*)
    9.22  
    9.23 -val presburger_ss = simpset_of (theory "Presburger");
    9.24 -
    9.25 -fun cooper_pp sg vrl (fm as e$Abs(xn,xT,p)) = 
    9.26 +fun cooper_pp sg (fm as e$Abs(xn,xT,p)) = 
    9.27    let val (xn1,p1) = variant_abs (xn,xT,p)
    9.28 -  in (CooperProof.cooper_prv sg (Free (xn1, xT)) p1 vrl) end;
    9.29 +  in (CooperProof.cooper_prv sg (Free (xn1, xT)) p1) end;
    9.30  
    9.31  fun mnnf_pp sg fm = CooperProof.proof_of_cnnf sg fm
    9.32    (CooperProof.proof_of_evalc sg);
    9.33  
    9.34 -fun mproof_of_int_qelim sg fm =
    9.35 -  Qelim.proof_of_mlift_qelim sg CooperDec.is_arith_rel
    9.36 +fun tmproof_of_int_qelim sg fm =
    9.37 +  Qelim.tproof_of_mlift_qelim sg CooperDec.is_arith_rel
    9.38      (CooperProof.proof_of_linform sg) (mnnf_pp sg) (cooper_pp sg) fm;
    9.39  
    9.40 +
    9.41  (* Theorems to be used in this tactic*)
    9.42  
    9.43  val zdvd_int = thm "zdvd_int";
    9.44 @@ -63,6 +65,19 @@
    9.45  
    9.46  fun term_typed_consts t = add_term_typed_consts(t,[]);
    9.47  
    9.48 +(* put a term into eta long beta normal form *)
    9.49 +fun eta_long Ts (Abs (s, T, t)) = Abs (s, T, eta_long (T :: Ts) t)
    9.50 +  | eta_long Ts t = (case strip_comb t of
    9.51 +      (Abs _, _) => eta_long Ts (Envir.beta_norm t)
    9.52 +    | (u, ts) => 
    9.53 +      let
    9.54 +        val Us = binder_types (fastype_of1 (Ts, t));
    9.55 +        val i = length Us
    9.56 +      in list_abs (map (pair "x") Us,
    9.57 +        list_comb (incr_boundvars i u, map (eta_long (rev Us @ Ts))
    9.58 +          (map (incr_boundvars i) ts @ map Bound (i - 1 downto 0))))
    9.59 +      end);
    9.60 +
    9.61  (* Some Types*)
    9.62  val bT = HOLogic.boolT;
    9.63  val iT = HOLogic.intT;
    9.64 @@ -94,8 +109,6 @@
    9.65     ("op *", iT --> iT --> iT), 
    9.66     ("HOL.abs", iT --> iT),
    9.67     ("uminus", iT --> iT),
    9.68 -   ("HOL.max", iT --> iT --> iT),
    9.69 -   ("HOL.min", iT --> iT --> iT),
    9.70  
    9.71     ("op <=", nT --> nT --> bT),
    9.72     ("op =", nT --> nT --> bT),
    9.73 @@ -107,8 +120,6 @@
    9.74     ("op -", nT --> nT --> nT),
    9.75     ("op *", nT --> nT --> nT), 
    9.76     ("Suc", nT --> nT),
    9.77 -   ("HOL.max", nT --> nT --> nT),
    9.78 -   ("HOL.min", nT --> nT --> nT),
    9.79  
    9.80     ("Numeral.bin.Bit", binT --> bT --> binT),
    9.81     ("Numeral.bin.Pls", binT),
    9.82 @@ -119,27 +130,89 @@
    9.83     ("0", iT),
    9.84     ("1", nT),
    9.85     ("1", iT),
    9.86 -
    9.87     ("False", bT),
    9.88     ("True", bT)];
    9.89  
    9.90 -(*returns true if the formula is relevant for presburger arithmetic tactic*)
    9.91 -fun relevant ps t = (term_typed_consts t) subset allowed_consts andalso
    9.92 -  map (fn i => snd (nth_elem (i, ps))) (loose_bnos t) @
    9.93 -  map (snd o dest_Free) (term_frees t) @ map (snd o dest_Var) (term_vars t)
    9.94 -  subset [iT, nT];
    9.95 -
    9.96  (* Preparation of the formula to be sent to the Integer quantifier *)
    9.97  (* elimination procedure                                           *)
    9.98  (* Transforms meta implications and meta quantifiers to object     *)
    9.99  (* implications and object quantifiers                             *)
   9.100  
   9.101 -fun prepare_for_presburger q fm = 
   9.102 +
   9.103 +(*==================================*)
   9.104 +(* Abstracting on subterms  ========*)
   9.105 +(*==================================*)
   9.106 +(* Returns occurences of terms that are function application of type int or nat*)
   9.107 +
   9.108 +fun getfuncs fm = case strip_comb fm of
   9.109 +    (Free (_, T), ts as _ :: _) =>
   9.110 +      if body_type T mem [iT, nT] 
   9.111 +         andalso not (ts = []) andalso forall (null o loose_bnos) ts 
   9.112 +      then [fm]
   9.113 +      else foldl op union ([], map getfuncs ts)
   9.114 +  | (Var (_, T), ts as _ :: _) =>
   9.115 +      if body_type T mem [iT, nT] 
   9.116 +         andalso not (ts = []) andalso forall (null o loose_bnos) ts then [fm]
   9.117 +      else foldl op union ([], map getfuncs ts)
   9.118 +  | (Const (s, T), ts) =>
   9.119 +      if (s, T) mem allowed_consts orelse not (body_type T mem [iT, nT])
   9.120 +      then foldl op union ([], map getfuncs ts)
   9.121 +      else [fm]
   9.122 +  | (Abs (s, T, t), _) => getfuncs t
   9.123 +  | _ => [];
   9.124 +
   9.125 +
   9.126 +fun abstract_pres sg fm = 
   9.127 +  foldr (fn (t, u) =>
   9.128 +      let val T = fastype_of t
   9.129 +      in all T $ Abs ("x", T, abstract_over (t, u)) end)
   9.130 +         (getfuncs fm, fm);
   9.131 +
   9.132 +
   9.133 +
   9.134 +(* hasfuncs_on_bounds dont care of the type of the functions applied!
   9.135 + It returns true if there is a subterm coresponding to the application of
   9.136 + a function on a bounded variable.
   9.137 +
   9.138 + Function applications are allowed only for well predefined functions a 
   9.139 + consts*)
   9.140 +
   9.141 +fun has_free_funcs fm  = case strip_comb fm of
   9.142 +    (Free (_, T), ts as _ :: _) => 
   9.143 +      if (body_type T mem [iT,nT]) andalso (not (T mem [iT,nT]))
   9.144 +      then true
   9.145 +      else exists (fn x => x) (map has_free_funcs ts)
   9.146 +  | (Var (_, T), ts as _ :: _) =>
   9.147 +      if (body_type T mem [iT,nT]) andalso not (T mem [iT,nT])
   9.148 +      then true
   9.149 +      else exists (fn x => x) (map has_free_funcs ts)
   9.150 +  | (Const (s, T), ts) =>  exists (fn x => x) (map has_free_funcs ts)
   9.151 +  | (Abs (s, T, t), _) => has_free_funcs t
   9.152 +  |_ => false;
   9.153 +
   9.154 +
   9.155 +(*returns true if the formula is relevant for presburger arithmetic tactic
   9.156 +The constants occuring in term t should be a subset of the allowed_consts
   9.157 + There also should be no occurences of application of functions on bounded 
   9.158 + variables. Whenever this function will be used, it will be ensured that t 
   9.159 + will not contain subterms with function symbols that could have been 
   9.160 + abstracted over.*)
   9.161 + 
   9.162 +fun relevant ps t = (term_typed_consts t) subset allowed_consts andalso 
   9.163 +  map (fn i => snd (nth_elem (i, ps))) (loose_bnos t) @
   9.164 +  map (snd o dest_Free) (term_frees t) @ map (snd o dest_Var) (term_vars t)
   9.165 +  subset [iT, nT]
   9.166 +  andalso not (has_free_funcs t);
   9.167 +
   9.168 +
   9.169 +fun prepare_for_presburger sg q fm = 
   9.170    let
   9.171      val ps = Logic.strip_params fm
   9.172      val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm)
   9.173      val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm)
   9.174 -    val _ = if relevant (rev ps) c then () else raise CooperDec.COOPER
   9.175 +    val _ = if relevant (rev ps) c then () 
   9.176 +               else  (trace_msg ("Conclusion is not a presburger term:\n" ^
   9.177 +             Sign.string_of_term sg c); raise CooperDec.COOPER)
   9.178      fun mk_all ((s, T), (P,n)) =
   9.179        if 0 mem loose_bnos P then
   9.180          (HOLogic.all_const T $ Abs (s, T, P), n)
   9.181 @@ -161,14 +234,20 @@
   9.182  fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp;
   9.183  
   9.184  (* the presburger tactic*)
   9.185 -fun presburger_tac q i = ObjectLogic.atomize_tac i THEN (fn st =>
   9.186 +
   9.187 +(* Parameters : q = flag for quantify ofer free variables ; 
   9.188 +                a = flag for abstracting over function occurences
   9.189 +                i = subgoal  *)
   9.190 +
   9.191 +fun presburger_tac q a i = ObjectLogic.atomize_tac i THEN (fn st =>
   9.192    let
   9.193 -    val g = BasisLibrary.List.nth (prems_of st, i - 1);
   9.194 -    val sg = sign_of_thm st;
   9.195 +    val g = BasisLibrary.List.nth (prems_of st, i - 1)
   9.196 +    val sg = sign_of_thm st
   9.197 +    (* The Abstraction step *)
   9.198 +    val g' = if a then abstract_pres sg g else g
   9.199      (* Transform the term*)
   9.200 -    val (t,np,nh) = prepare_for_presburger q g
   9.201 +    val (t,np,nh) = prepare_for_presburger sg q g'
   9.202      (* Some simpsets for dealing with mod div abs and nat*)
   9.203 -
   9.204      val simpset0 = HOL_basic_ss
   9.205        addsimps [mod_div_equality', Suc_plus1]
   9.206        addsplits [split_zdiv, split_zmod, split_div', split_min, split_max]
   9.207 @@ -183,37 +262,40 @@
   9.208        addsimps [nat_0_le, all_nat, ex_nat, number_of1, number_of2, int_0, int_1]
   9.209        addcongs [conj_le_cong, imp_le_cong]
   9.210      (* simp rules for elimination of abs *)
   9.211 -
   9.212      val simpset3 = HOL_basic_ss addsplits [abs_split]
   9.213 -	      
   9.214      val ct = cterm_of sg (HOLogic.mk_Trueprop t)
   9.215 -
   9.216      (* Theorem for the nat --> int transformation *)
   9.217      val pre_thm = Seq.hd (EVERY
   9.218 -      [simp_tac simpset0 i,
   9.219 -       TRY (simp_tac simpset1 i), TRY (simp_tac simpset2 i),
   9.220 -       TRY (simp_tac simpset3 i), TRY (simp_tac presburger_ss i)]
   9.221 +      [simp_tac simpset0 1,
   9.222 +       TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1),
   9.223 +       TRY (simp_tac simpset3 1)]
   9.224        (trivial ct))
   9.225 -
   9.226 -    fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i);
   9.227 -
   9.228 +    fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i)
   9.229      (* The result of the quantifier elimination *)
   9.230      val (th, tac) = case (prop_of pre_thm) of
   9.231          Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ =>
   9.232            (trace_msg ("calling procedure with term:\n" ^
   9.233               Sign.string_of_term sg t1);
   9.234 -           ((mproof_of_int_qelim sg (Pattern.eta_long [] t1) RS iffD2) RS pre_thm,
   9.235 +           ((tmproof_of_int_qelim sg (Pattern.eta_long [] t1) RS iffD2) RS pre_thm,
   9.236              assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i)))
   9.237        | _ => (pre_thm, assm_tac i)
   9.238 -  in (rtac (((mp_step nh) o (spec_step np)) th) i THEN tac) st
   9.239 +  in (rtac (((mp_step nh) o (spec_step np)) th) i 
   9.240 +      THEN tac) st
   9.241    end handle Subscript => no_tac st | CooperDec.COOPER => no_tac st);
   9.242  
   9.243  fun presburger_args meth =
   9.244 -  Method.simple_args (Scan.optional (Args.$$$ "no_quantify" >> K false) true)
   9.245 -    (fn q => fn _ => meth q 1);
   9.246 + let val parse_flag = 
   9.247 +         Args.$$$ "no_quantify" >> K (apfst (K false))
   9.248 +      || Args.$$$ "no_abs" >> K (apsnd (K false));
   9.249 + in
   9.250 +   Method.simple_args 
   9.251 +  (Scan.optional (Args.$$$ "(" |-- Args.list1 parse_flag --| Args.$$$ ")") [] >>
   9.252 +    curry (foldl op |>) (true, true))
   9.253 +    (fn (q,a) => fn _ => meth q a 1)
   9.254 +  end;
   9.255  
   9.256 -fun presburger_method q i = Method.METHOD (fn facts =>
   9.257 -  Method.insert_tac facts 1 THEN presburger_tac q i)
   9.258 +fun presburger_method q a i = Method.METHOD (fn facts =>
   9.259 +  Method.insert_tac facts 1 THEN presburger_tac q a i)
   9.260  
   9.261  val setup =
   9.262    [Method.add_method ("presburger",
   9.263 @@ -221,8 +303,8 @@
   9.264       "decision procedure for Presburger arithmetic"),
   9.265     ArithTheoryData.map (fn {splits, inj_consts, discrete, presburger} =>
   9.266       {splits = splits, inj_consts = inj_consts, discrete = discrete,
   9.267 -      presburger = Some (presburger_tac true)})];
   9.268 +      presburger = Some (presburger_tac true true)})];
   9.269  
   9.270  end;
   9.271  
   9.272 -val presburger_tac = Presburger.presburger_tac true;
   9.273 +val presburger_tac = Presburger.presburger_tac true true;
    10.1 --- a/src/HOL/Tools/Presburger/qelim.ML	Wed May 19 11:21:19 2004 +0200
    10.2 +++ b/src/HOL/Tools/Presburger/qelim.ML	Wed May 19 11:23:59 2004 +0200
    10.3 @@ -8,10 +8,11 @@
    10.4  *)
    10.5  
    10.6  signature QELIM =
    10.7 -sig
    10.8 - val proof_of_mlift_qelim: Sign.sg -> (term -> bool) ->
    10.9 + sig
   10.10 + val tproof_of_mlift_qelim: Sign.sg -> (term -> bool) ->
   10.11     (string list -> term -> thm) -> (term -> thm) ->
   10.12 -   (string list -> term -> thm) -> term -> thm
   10.13 +   (term -> thm) -> term -> thm
   10.14 +
   10.15  end;
   10.16  
   10.17  structure Qelim : QELIM =
   10.18 @@ -19,24 +20,6 @@
   10.19  open CooperDec;
   10.20  open CooperProof;
   10.21  
   10.22 -(*-----------------------------------------------------------------*)
   10.23 -(*-----------------------------------------------------------------*)
   10.24 -(*-----------------------------------------------------------------*)
   10.25 -(*---                                                           ---*)
   10.26 -(*---                                                           ---*)
   10.27 -(*---         Protocoling part                                  ---*)
   10.28 -(*---                                                           ---*)
   10.29 -(*---           includes the protocolling datastructure         ---*)
   10.30 -(*---                                                           ---*)
   10.31 -(*---          and the protocolling fuctions                    ---*)
   10.32 -(*---                                                           ---*)
   10.33 -(*---                                                           ---*)
   10.34 -(*---                                                           ---*)
   10.35 -(*-----------------------------------------------------------------*)
   10.36 -(*-----------------------------------------------------------------*)
   10.37 -(*-----------------------------------------------------------------*)
   10.38 -
   10.39 -
   10.40  val cboolT = ctyp_of (sign_of HOL.thy) HOLogic.boolT;
   10.41  
   10.42  (* List of the theorems to be used in the following*)
   10.43 @@ -46,131 +29,35 @@
   10.44  val qe_ALL = thm "qe_ALL";
   10.45  
   10.46  
   10.47 -(*Datatype declaration for the protocoling procedure.*)
   10.48 -
   10.49 -
   10.50 -datatype QeLog = AFN of term*(string list)
   10.51 -                |QFN of term*(string list)
   10.52 -                |ExConj of term*QeLog
   10.53 -                |ExDisj of (string*typ*term)*term*QeLog*QeLog
   10.54 -                |QeConst of string*QeLog*QeLog
   10.55 -                |QeNot of QeLog
   10.56 -                |QeAll of QeLog
   10.57 -                |Lift_Qelim of term*QeLog
   10.58 -		|QeUnk of term;
   10.59 -
   10.60 -datatype mQeLog = mQeProof of (string list)*mQeLog
   10.61 -		|mAFN of term
   10.62 -                |mNFN of mQeLog
   10.63 -                |mQeConst of string*mQeLog*mQeLog
   10.64 -                |mQeNot of mQeLog
   10.65 -		|mQelim of term*(string list)*mQeLog
   10.66 -		|mQeAll of mQeLog
   10.67 -		|mQefm of term;
   10.68 -
   10.69 -(* This is the protokoling my function for the quantifier elimination*)
   10.70 -fun mlift_qelim_wp isat vars = 
   10.71 -  let fun mqelift_wp vars fm = if (isat fm) then mAFN(fm)
   10.72 -    else  
   10.73 -    (case fm of 
   10.74 -     ( Const ("Not",_) $ p) => mQeNot(mqelift_wp vars p)
   10.75 -    |( Const ("op &",_) $ p $q) => mQeConst("CJ", mqelift_wp vars p,mqelift_wp vars q) 
   10.76 -
   10.77 -    |( Const ("op |",_) $ p $q) => mQeConst("DJ", mqelift_wp vars p,mqelift_wp vars q) 
   10.78 -
   10.79 -    |( Const ("op -->",_) $ p $q) => mQeConst("IM", mqelift_wp vars p,mqelift_wp vars q) 
   10.80 -
   10.81 -    |( Const ("op =",Type ("fun",[Type ("bool", []),_])) $ p $q) =>mQeConst("EQ", mqelift_wp vars p,mqelift_wp vars q) 
   10.82 -
   10.83 -    				
   10.84 -    |( Const ("All",QT) $ Abs(x,T,p)) =>mQeAll (mqelift_wp vars (Const("Ex",QT) $ Abs(x,T,(HOLogic.Not $ p))))
   10.85 -
   10.86 -    |(Const ("Ex",_) $ Abs (x,T,p))  => 
   10.87 -      let val (x1,p1) = variant_abs (x,T,p)
   10.88 -          val prt = mqelift_wp (x1::vars) p1
   10.89 -      in mQelim(Free(x1,T),vars,mNFN(prt))
   10.90 -      end
   10.91 -    | _ => mQefm(fm)
   10.92 -   ) 
   10.93 -     
   10.94 -  in (fn fm => mQeProof(vars,mNFN(mqelift_wp vars fm )))
   10.95 -  end;  
   10.96 -
   10.97 -
   10.98 +(*============= Compact version =====*)
   10.99  
  10.100  
  10.101 -(*-----------------------------------------------------------------*)
  10.102 -(*-----------------------------------------------------------------*)
  10.103 -(*-----------------------------------------------------------------*)
  10.104 -(*---                                                           ---*)
  10.105 -(*---                                                           ---*)
  10.106 -(*---      Interpretation and Proofgeneration Part              ---*)
  10.107 -(*---                                                           ---*)
  10.108 -(*---      Protocole interpretation functions                   ---*)
  10.109 -(*---                                                           ---*)
  10.110 -(*---      and proofgeneration functions                        ---*)
  10.111 -(*---                                                           ---*)
  10.112 -(*---                                                           ---*)
  10.113 -(*---                                                           ---*)
  10.114 -(*---                                                           ---*)
  10.115 -(*-----------------------------------------------------------------*)
  10.116 -(*-----------------------------------------------------------------*)
  10.117 -(*-----------------------------------------------------------------*)
  10.118 -
  10.119 -(*-----------------------------------------------------------------*)
  10.120 -(*-----------------------------------------------------------------*)
  10.121 -(*function that interpretates the protokol generated by the _wp function*)
  10.122 -
  10.123 +fun decomp_qe is_at afnp nfnp qfnp sg P = 
  10.124 +   if is_at P then ([], fn [] => afnp [] P) else 
  10.125 +   case P of
  10.126 +   (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
  10.127 +   |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
  10.128 +   |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
  10.129 +   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
  10.130 +   |(Const("Not",_)$p) => ([p],fn [th] => th RS qe_Not)
  10.131 +   |(Const("Ex",_)$Abs(xn,xT,p)) => 
  10.132 +      let val (xn1,p1) = variant_abs(xn,xT,p) 
  10.133 +      in ([p1],
  10.134 +        fn [th1_1] => 
  10.135 +          let val th2 = [th1_1,nfnp (snd (qe_get_terms th1_1))] MRS trans
  10.136 +              val eth1 = (forall_intr (cterm_of sg (Free(xn1,xT))) th2) COMP  qe_exI
  10.137 +              val th3 = qfnp (snd(qe_get_terms eth1))
  10.138 +          in [eth1,th3] MRS trans
  10.139 +          end )
  10.140 +      end
  10.141  
  10.142 -(* proof_of_lift_qelim interpretates a protokol for the quantifier elimination one some quantified formula. It uses the functions afnp nfnp and qfnp as proof functions to generate a prove for the hole quantifier elimination.*)
  10.143 -(* afnp : must retun a proof for the transformations on the atomic formalae*)
  10.144 -(* nfnp : must return a proof for the post one-quatifiers elimination process*)
  10.145 -(* qfnp mus return a proof for the one quantifier elimination (existential) *)
  10.146 -(* All these function are independent of the theory on whitch we are trying to prove quantifier elimination*)
  10.147 -(* But the following invariants mus be respected : *)
  10.148 -(* afnp : term -> string list -> thm*)
  10.149 -(*   nfnp : term -> thm*)
  10.150 -(*   qfnp : term -> string list -> thm*)
  10.151 -(*For all theorms generated by these function must hold :*)
  10.152 -(*    All of them are logical equivalences.*)
  10.153 -(*    on left side of the equivalence must appear the term exactely as ist was given as a parameter (or eventually modulo Gamma, where Gamma are the rules whitch are allowed to be used during unification ex. beta reduction.....)*)
  10.154 -(* qfnp must take as an argument for the term an existential quantified formula*)
  10.155 -(*-----------------------------------------------------------------*)
  10.156 -(*-----------------------------------------------------------------*)
  10.157 +   |(Const("All",_)$Abs(xn,xT,p)) => ([(HOLogic.exists_const xT)$Abs(xn,xT,HOLogic.Not $ p)], fn [th] => th RS qe_ALL)
  10.158 +   | _ => ([],fn [] => instantiate' [Some (ctyp_of sg (type_of P))] [Some (cterm_of sg P)] refl);
  10.159 + 
  10.160  
  10.161 -fun proof_of_mlift_qelim sg isat afnp nfnp qfnp =
  10.162 - let fun h_proof_of_mlift_qelim isat afnp nfnp qfnp prtkl vrl = 
  10.163 -   (case prtkl of 
  10.164 -   mAFN (fm) => afnp vrl fm 
  10.165 -   |mNFN (prt) => let val th1 = h_proof_of_mlift_qelim isat  afnp nfnp qfnp prt vrl 
  10.166 -                  val th2 = nfnp (snd (qe_get_terms th1)) 
  10.167 -                    in [th1,th2] MRS trans 
  10.168 -                 end 
  10.169 -   |mQeConst (s,pr1,pr2) =>  
  10.170 -     let val th1 =  h_proof_of_mlift_qelim isat afnp nfnp qfnp pr1 vrl  
  10.171 -         val th2 =  h_proof_of_mlift_qelim isat afnp nfnp qfnp pr2 vrl  
  10.172 -     in (case s of 
  10.173 -        "CJ" => [th1,th2] MRS (qe_conjI)  
  10.174 -       |"DJ" => [th1,th2] MRS (qe_disjI)  
  10.175 -       |"IM" => [th1,th2] MRS (qe_impI)  
  10.176 -       |"EQ" => [th1,th2] MRS (qe_eqI)  
  10.177 -       )  
  10.178 -    end  
  10.179 -   |mQeNot (pr) =>(h_proof_of_mlift_qelim isat afnp nfnp qfnp pr vrl ) RS (qe_Not)  
  10.180 -   |mQeAll(pr) => (h_proof_of_mlift_qelim isat afnp nfnp qfnp pr vrl ) RS (qe_ALL) 
  10.181 -   |mQelim (x as (Free(xn,xT)),vl,pr) => 
  10.182 -     let val th_1 = h_proof_of_mlift_qelim isat afnp nfnp qfnp pr vl
  10.183 -         val mQeProof(l2,pr2) = mlift_qelim_wp isat (xn::vrl) (snd(qe_get_terms th_1))
  10.184 -         val th_2 = [th_1,(h_proof_of_mlift_qelim isat afnp nfnp qfnp pr2 l2)] MRS trans
  10.185 -         val th1 = (forall_intr (cterm_of sg x) th_2) COMP (qe_exI)
  10.186 -	 val th2 = qfnp vl (snd (qe_get_terms th1)) 
  10.187 -       in [th1,th2] MRS trans 
  10.188 -       end
  10.189 -   |mQefm (fm) => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl
  10.190 -)
  10.191 -in (fn fm => let val mQeProof(vars,prt) = (mlift_qelim_wp isat (fv fm) fm)
  10.192 -                 in (h_proof_of_mlift_qelim isat afnp nfnp qfnp prt vars)
  10.193 -                 end)
  10.194 +fun tproof_of_mlift_qelim sg isat afnp nfnp qfnp p = 
  10.195 +   let val th1 = thm_of sg (decomp_qe isat afnp nfnp qfnp sg) p
  10.196 +       val th2 = nfnp (snd (qe_get_terms th1))
  10.197 +    in [th1,th2] MRS trans
  10.198 +    end;
  10.199  end;
  10.200 -
  10.201 -end;
    11.1 --- a/src/HOL/ex/PresburgerEx.thy	Wed May 19 11:21:19 2004 +0200
    11.2 +++ b/src/HOL/ex/PresburgerEx.thy	Wed May 19 11:23:59 2004 +0200
    11.3 @@ -39,18 +39,18 @@
    11.4    by presburger
    11.5  
    11.6  theorem "\<forall>(x::int). b < x --> a \<le> x"
    11.7 -  apply (presburger no_quantify)
    11.8 +  apply (presburger (no_quantify))
    11.9    oops
   11.10  
   11.11  theorem "\<forall>(x::int). b < x --> a \<le> x"
   11.12 -  apply (presburger no_quantify)
   11.13 +  apply (presburger (no_quantify))
   11.14    oops
   11.15  
   11.16  theorem "~ (\<exists>(x::int). False)"
   11.17    by presburger
   11.18  
   11.19  theorem "\<forall>(x::int). (a::int) < 3 * x --> b < 3 * x"
   11.20 -  apply (presburger no_quantify)
   11.21 +  apply (presburger (no_quantify))
   11.22    oops
   11.23  
   11.24  theorem "\<forall>(x::int). (2 dvd x) --> (\<exists>(y::int). x = 2*y)" by presburger