src/HOL/Integ/cooper_proof.ML
changeset 23146 0bc590051d95
parent 23145 5d8faadf3ecf
child 23147 a5db2f7d7654
     1.1 --- a/src/HOL/Integ/cooper_proof.ML	Thu May 31 11:00:06 2007 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,988 +0,0 @@
     1.4 -(*  Title:      HOL/Integ/cooper_proof.ML
     1.5 -    ID:         $Id$
     1.6 -    Author:     Amine Chaieb and Tobias Nipkow, TU Muenchen
     1.7 -
     1.8 -File containing the implementation of the proof
     1.9 -generation for Cooper Algorithm
    1.10 -*)
    1.11 -
    1.12 -
    1.13 -signature COOPER_PROOF =
    1.14 -sig
    1.15 -  val qe_Not : thm
    1.16 -  val qe_conjI : thm
    1.17 -  val qe_disjI : thm
    1.18 -  val qe_impI : thm
    1.19 -  val qe_eqI : thm
    1.20 -  val qe_exI : thm
    1.21 -  val list_to_set : typ -> term list -> term
    1.22 -  val qe_get_terms : thm -> term * term
    1.23 -  val cooper_prv  : theory -> term -> term -> thm
    1.24 -  val proof_of_evalc : theory -> term -> thm
    1.25 -  val proof_of_cnnf : theory -> term -> (term -> thm) -> thm
    1.26 -  val proof_of_linform : theory -> string list -> term -> thm
    1.27 -  val proof_of_adjustcoeffeq : theory -> term -> IntInf.int -> term -> thm
    1.28 -  val prove_elementar : theory -> string -> term -> thm
    1.29 -  val thm_of : theory -> (term -> (term list * (thm list -> thm))) -> term -> thm
    1.30 -end;
    1.31 -
    1.32 -structure CooperProof : COOPER_PROOF =
    1.33 -struct
    1.34 -open CooperDec;
    1.35 -
    1.36 -val presburger_ss = simpset ()
    1.37 -  addsimps [diff_int_def] delsimps [thm "diff_int_def_symmetric"];
    1.38 -
    1.39 -val cboolT = ctyp_of HOL.thy HOLogic.boolT;
    1.40 -
    1.41 -(*Theorems that will be used later for the proofgeneration*)
    1.42 -
    1.43 -val zdvd_iff_zmod_eq_0 = thm "zdvd_iff_zmod_eq_0";
    1.44 -val unity_coeff_ex = thm "unity_coeff_ex";
    1.45 -
    1.46 -(* Theorems for proving the adjustment of the coefficients*)
    1.47 -
    1.48 -val ac_lt_eq =  thm "ac_lt_eq";
    1.49 -val ac_eq_eq = thm "ac_eq_eq";
    1.50 -val ac_dvd_eq = thm "ac_dvd_eq";
    1.51 -val ac_pi_eq = thm "ac_pi_eq";
    1.52 -
    1.53 -(* The logical compination of the sythetised properties*)
    1.54 -val qe_Not = thm "qe_Not";
    1.55 -val qe_conjI = thm "qe_conjI";
    1.56 -val qe_disjI = thm "qe_disjI";
    1.57 -val qe_impI = thm "qe_impI";
    1.58 -val qe_eqI = thm "qe_eqI";
    1.59 -val qe_exI = thm "qe_exI";
    1.60 -val qe_ALLI = thm "qe_ALLI";
    1.61 -
    1.62 -(*Modulo D property for Pminusinf an Plusinf *)
    1.63 -val fm_modd_minf = thm "fm_modd_minf";
    1.64 -val not_dvd_modd_minf = thm "not_dvd_modd_minf";
    1.65 -val dvd_modd_minf = thm "dvd_modd_minf";
    1.66 -
    1.67 -val fm_modd_pinf = thm "fm_modd_pinf";
    1.68 -val not_dvd_modd_pinf = thm "not_dvd_modd_pinf";
    1.69 -val dvd_modd_pinf = thm "dvd_modd_pinf";
    1.70 -
    1.71 -(* the minusinfinity proprty*)
    1.72 -
    1.73 -val fm_eq_minf = thm "fm_eq_minf";
    1.74 -val neq_eq_minf = thm "neq_eq_minf";
    1.75 -val eq_eq_minf = thm "eq_eq_minf";
    1.76 -val le_eq_minf = thm "le_eq_minf";
    1.77 -val len_eq_minf = thm "len_eq_minf";
    1.78 -val not_dvd_eq_minf = thm "not_dvd_eq_minf";
    1.79 -val dvd_eq_minf = thm "dvd_eq_minf";
    1.80 -
    1.81 -(* the Plusinfinity proprty*)
    1.82 -
    1.83 -val fm_eq_pinf = thm "fm_eq_pinf";
    1.84 -val neq_eq_pinf = thm "neq_eq_pinf";
    1.85 -val eq_eq_pinf = thm "eq_eq_pinf";
    1.86 -val le_eq_pinf = thm "le_eq_pinf";
    1.87 -val len_eq_pinf = thm "len_eq_pinf";
    1.88 -val not_dvd_eq_pinf = thm "not_dvd_eq_pinf";
    1.89 -val dvd_eq_pinf = thm "dvd_eq_pinf";
    1.90 -
    1.91 -(*Logical construction of the Property*)
    1.92 -val eq_minf_conjI = thm "eq_minf_conjI";
    1.93 -val eq_minf_disjI = thm "eq_minf_disjI";
    1.94 -val modd_minf_disjI = thm "modd_minf_disjI";
    1.95 -val modd_minf_conjI = thm "modd_minf_conjI";
    1.96 -
    1.97 -val eq_pinf_conjI = thm "eq_pinf_conjI";
    1.98 -val eq_pinf_disjI = thm "eq_pinf_disjI";
    1.99 -val modd_pinf_disjI = thm "modd_pinf_disjI";
   1.100 -val modd_pinf_conjI = thm "modd_pinf_conjI";
   1.101 -
   1.102 -(*Cooper Backwards...*)
   1.103 -(*Bset*)
   1.104 -val not_bst_p_fm = thm "not_bst_p_fm";
   1.105 -val not_bst_p_ne = thm "not_bst_p_ne";
   1.106 -val not_bst_p_eq = thm "not_bst_p_eq";
   1.107 -val not_bst_p_gt = thm "not_bst_p_gt";
   1.108 -val not_bst_p_lt = thm "not_bst_p_lt";
   1.109 -val not_bst_p_ndvd = thm "not_bst_p_ndvd";
   1.110 -val not_bst_p_dvd = thm "not_bst_p_dvd";
   1.111 -
   1.112 -(*Aset*)
   1.113 -val not_ast_p_fm = thm "not_ast_p_fm";
   1.114 -val not_ast_p_ne = thm "not_ast_p_ne";
   1.115 -val not_ast_p_eq = thm "not_ast_p_eq";
   1.116 -val not_ast_p_gt = thm "not_ast_p_gt";
   1.117 -val not_ast_p_lt = thm "not_ast_p_lt";
   1.118 -val not_ast_p_ndvd = thm "not_ast_p_ndvd";
   1.119 -val not_ast_p_dvd = thm "not_ast_p_dvd";
   1.120 -
   1.121 -(*Logical construction of the prop*)
   1.122 -(*Bset*)
   1.123 -val not_bst_p_conjI = thm "not_bst_p_conjI";
   1.124 -val not_bst_p_disjI = thm "not_bst_p_disjI";
   1.125 -val not_bst_p_Q_elim = thm "not_bst_p_Q_elim";
   1.126 -
   1.127 -(*Aset*)
   1.128 -val not_ast_p_conjI = thm "not_ast_p_conjI";
   1.129 -val not_ast_p_disjI = thm "not_ast_p_disjI";
   1.130 -val not_ast_p_Q_elim = thm "not_ast_p_Q_elim";
   1.131 -
   1.132 -(*Cooper*)
   1.133 -val cppi_eq = thm "cppi_eq";
   1.134 -val cpmi_eq = thm "cpmi_eq";
   1.135 -
   1.136 -(*Others*)
   1.137 -val simp_from_to = thm "simp_from_to";
   1.138 -val P_eqtrue = thm "P_eqtrue";
   1.139 -val P_eqfalse = thm "P_eqfalse";
   1.140 -
   1.141 -(*For Proving NNF*)
   1.142 -
   1.143 -val nnf_nn = thm "nnf_nn";
   1.144 -val nnf_im = thm "nnf_im";
   1.145 -val nnf_eq = thm "nnf_eq";
   1.146 -val nnf_sdj = thm "nnf_sdj";
   1.147 -val nnf_ncj = thm "nnf_ncj";
   1.148 -val nnf_nim = thm "nnf_nim";
   1.149 -val nnf_neq = thm "nnf_neq";
   1.150 -val nnf_ndj = thm "nnf_ndj";
   1.151 -
   1.152 -(*For Proving term linearizition*)
   1.153 -val linearize_dvd = thm "linearize_dvd";
   1.154 -val lf_lt = thm "lf_lt";
   1.155 -val lf_eq = thm "lf_eq";
   1.156 -val lf_dvd = thm "lf_dvd";
   1.157 -
   1.158 -
   1.159 -(* ------------------------------------------------------------------------- *)
   1.160 -(*This function norm_zero_one  replaces the occurences of Numeral1 and Numeral0*)
   1.161 -(*Respectively by their abstract representation Const(@{const_name HOL.one},..) and Const(@{const_name HOL.zero},..)*)
   1.162 -(*this is necessary because the theorems use this representation.*)
   1.163 -(* This function should be elminated in next versions...*)
   1.164 -(* ------------------------------------------------------------------------- *)
   1.165 -
   1.166 -fun norm_zero_one fm = case fm of
   1.167 -  (Const (@{const_name HOL.times},_) $ c $ t) => 
   1.168 -    if c = one then (norm_zero_one t)
   1.169 -    else if (dest_number c = ~1) 
   1.170 -         then (Const(@{const_name HOL.uminus},HOLogic.intT --> HOLogic.intT) $ (norm_zero_one t))
   1.171 -         else (HOLogic.mk_binop @{const_name HOL.times} (norm_zero_one c,norm_zero_one t))
   1.172 -  |(node $ rest) => ((norm_zero_one node)$(norm_zero_one rest))
   1.173 -  |(Abs(x,T,p)) => (Abs(x,T,(norm_zero_one p)))
   1.174 -  |_ => fm;
   1.175 -
   1.176 -(* ------------------------------------------------------------------------- *)
   1.177 -(*function list to Set, constructs a set containing all elements of a given list.*)
   1.178 -(* ------------------------------------------------------------------------- *)
   1.179 -fun list_to_set T1 l = let val T = (HOLogic.mk_setT T1) in 
   1.180 -	case l of 
   1.181 -		[] => Const ("{}",T)
   1.182 -		|(h::t) => Const("insert", T1 --> (T --> T)) $ h $(list_to_set T1 t)
   1.183 -		end;
   1.184 -		
   1.185 -(* ------------------------------------------------------------------------- *)
   1.186 -(* Returns both sides of an equvalence in the theorem*)
   1.187 -(* ------------------------------------------------------------------------- *)
   1.188 -fun qe_get_terms th = let val (_$(Const("op =",Type ("fun",[Type ("bool", []),_])) $ A $ B )) = prop_of th in (A,B) end;
   1.189 -
   1.190 -(* ------------------------------------------------------------------------- *)
   1.191 -(*This function proove elementar will be used to generate proofs at
   1.192 -  runtime*) (*It is thought to prove properties such as a dvd b
   1.193 -  (essentially) that are only to make at runtime.*)
   1.194 -(* ------------------------------------------------------------------------- *)
   1.195 -fun prove_elementar thy s fm2 =
   1.196 -  Goal.prove (ProofContext.init thy) [] [] (HOLogic.mk_Trueprop fm2) (fn _ => EVERY
   1.197 -  (case s of
   1.198 -  (*"ss" like simplification with simpset*)
   1.199 -  "ss" =>
   1.200 -    let val ss = presburger_ss addsimps [zdvd_iff_zmod_eq_0,unity_coeff_ex]
   1.201 -    in [simp_tac ss 1, TRY (simple_arith_tac 1)] end
   1.202 -
   1.203 -  (*"bl" like blast tactic*)
   1.204 -  (* Is only used in the harrisons like proof procedure *)
   1.205 -  | "bl" => [blast_tac HOL_cs 1]
   1.206 -
   1.207 -  (*"ed" like Existence disjunctions ...*)
   1.208 -  (* Is only used in the harrisons like proof procedure *)
   1.209 -  | "ed" =>
   1.210 -    let
   1.211 -      val ex_disj_tacs =
   1.212 -        let
   1.213 -          val tac1 = EVERY[REPEAT(resolve_tac [disjI1,disjI2] 1), etac exI 1]
   1.214 -          val tac2 = EVERY[etac exE 1, rtac exI 1,
   1.215 -            REPEAT(resolve_tac [disjI1,disjI2] 1), assumption 1]
   1.216 -	in [rtac iffI 1,
   1.217 -          etac exE 1, REPEAT(EVERY[etac disjE 1, tac1]), tac1,
   1.218 -          REPEAT(EVERY[etac disjE 1, tac2]), tac2]
   1.219 -        end
   1.220 -    in ex_disj_tacs end
   1.221 -
   1.222 -  | "fa" => [simple_arith_tac 1]
   1.223 -
   1.224 -  | "sa" =>
   1.225 -    let val ss = presburger_ss addsimps zadd_ac
   1.226 -    in [simp_tac ss 1, TRY (simple_arith_tac 1)] end
   1.227 -
   1.228 -  (* like Existance Conjunction *)
   1.229 -  | "ec" =>
   1.230 -    let val ss = presburger_ss addsimps zadd_ac
   1.231 -    in [simp_tac ss 1, TRY (blast_tac HOL_cs 1)] end
   1.232 -
   1.233 -  | "ac" =>
   1.234 -    let val ss = HOL_basic_ss addsimps zadd_ac
   1.235 -    in [simp_tac ss 1] end
   1.236 -
   1.237 -  | "lf" =>
   1.238 -    let val ss = presburger_ss addsimps zadd_ac
   1.239 -    in [simp_tac ss 1, TRY (simple_arith_tac 1)] end));
   1.240 -
   1.241 -(*=============================================================*)
   1.242 -(*-------------------------------------------------------------*)
   1.243 -(*              The new compact model                          *)
   1.244 -(*-------------------------------------------------------------*)
   1.245 -(*=============================================================*)
   1.246 -
   1.247 -fun thm_of sg decomp t = 
   1.248 -    let val (ts,recomb) = decomp t 
   1.249 -    in recomb (map (thm_of sg decomp) ts) 
   1.250 -    end;
   1.251 -
   1.252 -(*==================================================*)
   1.253 -(*     Compact Version for adjustcoeffeq            *)
   1.254 -(*==================================================*)
   1.255 -
   1.256 -fun decomp_adjustcoeffeq sg x l fm = case fm of
   1.257 -    (Const("Not",_)$(Const(@{const_name Orderings.less},_) $ zero $(rt as (Const (@{const_name HOL.plus}, _)$(Const (@{const_name HOL.times},_) $    c $ y ) $z )))) => 
   1.258 -     let  
   1.259 -        val m = l div (dest_number c) 
   1.260 -        val n = if (x = y) then abs (m) else 1
   1.261 -        val xtm = (HOLogic.mk_binop @{const_name HOL.times} ((mk_number ((m div n)*l) ), x)) 
   1.262 -        val rs = if (x = y) 
   1.263 -                 then (HOLogic.mk_binrel @{const_name Orderings.less} (zero,linear_sub [] (mk_number n) (HOLogic.mk_binop @{const_name HOL.plus} ( xtm ,( linear_cmul n z) )))) 
   1.264 -                 else HOLogic.mk_binrel @{const_name Orderings.less} (zero,linear_sub [] one rt )
   1.265 -        val ck = cterm_of sg (mk_number n)
   1.266 -        val cc = cterm_of sg c
   1.267 -        val ct = cterm_of sg z
   1.268 -        val cx = cterm_of sg y
   1.269 -        val pre = prove_elementar sg "lf" 
   1.270 -            (HOLogic.mk_binrel @{const_name Orderings.less} (zero, mk_number n))
   1.271 -        val th1 = (pre RS (instantiate' [] [SOME ck,SOME cc, SOME cx, SOME ct] (ac_pi_eq)))
   1.272 -        in ([], fn [] => [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   1.273 -        end
   1.274 -
   1.275 -  |(Const(p,_) $a $( Const (@{const_name HOL.plus}, _)$(Const (@{const_name HOL.times},_) $ 
   1.276 -      c $ y ) $t )) => 
   1.277 -   if (is_arith_rel fm) andalso (x = y) 
   1.278 -   then  
   1.279 -        let val m = l div (dest_number c) 
   1.280 -           val k = (if p = @{const_name Orderings.less} then abs(m) else m)  
   1.281 -           val xtm = (HOLogic.mk_binop @{const_name HOL.times} ((mk_number ((m div k)*l) ), x))
   1.282 -           val rs = (HOLogic.mk_binrel p ((linear_cmul k a),(HOLogic.mk_binop @{const_name HOL.plus} ( xtm ,( linear_cmul k t) )))) 
   1.283 -
   1.284 -           val ck = cterm_of sg (mk_number k)
   1.285 -           val cc = cterm_of sg c
   1.286 -           val ct = cterm_of sg t
   1.287 -           val cx = cterm_of sg x
   1.288 -           val ca = cterm_of sg a
   1.289 -
   1.290 -	   in 
   1.291 -	case p of
   1.292 -	  @{const_name Orderings.less} => 
   1.293 -	let val pre = prove_elementar sg "lf" 
   1.294 -	    (HOLogic.mk_binrel @{const_name Orderings.less} (zero, mk_number k))
   1.295 -            val th1 = (pre RS (instantiate' [] [SOME ck,SOME ca,SOME cc, SOME cx, SOME ct] (ac_lt_eq)))
   1.296 -	in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   1.297 -         end
   1.298 -
   1.299 -           |"op =" =>
   1.300 -	     let val pre = prove_elementar sg "lf" 
   1.301 -	    (HOLogic.Not $ (HOLogic.mk_binrel "op =" (zero, mk_number k)))
   1.302 -	         val th1 = (pre RS(instantiate' [] [SOME ck,SOME ca,SOME cc, SOME cx, SOME ct] (ac_eq_eq)))
   1.303 -	     in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   1.304 -             end
   1.305 -
   1.306 -             |"Divides.dvd" =>
   1.307 -	       let val pre = prove_elementar sg "lf" 
   1.308 -	   (HOLogic.Not $ (HOLogic.mk_binrel "op =" (zero, mk_number k)))
   1.309 -                   val th1 = (pre RS (instantiate' [] [SOME ck,SOME ca,SOME cc, SOME cx, SOME ct]) (ac_dvd_eq))
   1.310 -               in ([], fn [] => [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans)
   1.311 -                        
   1.312 -               end
   1.313 -              end
   1.314 -  else ([], fn [] => instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] refl)
   1.315 -
   1.316 - |( Const ("Not", _) $ p) => ([p], fn [th] => th RS qe_Not)
   1.317 -  |( Const ("op &",_) $ p $ q) => ([p,q], fn [th1,th2] => [th1,th2] MRS qe_conjI)
   1.318 -  |( Const ("op |",_) $ p $ q) =>([p,q], fn [th1,th2] => [th1,th2] MRS qe_disjI)
   1.319 -
   1.320 -  |_ => ([], fn [] => instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] refl);
   1.321 -
   1.322 -fun proof_of_adjustcoeffeq sg x l = thm_of sg (decomp_adjustcoeffeq sg x l);
   1.323 -
   1.324 -
   1.325 -
   1.326 -(*==================================================*)
   1.327 -(*   Finding rho for modd_minusinfinity             *)
   1.328 -(*==================================================*)
   1.329 -fun rho_for_modd_minf x dlcm sg fm1 =
   1.330 -let
   1.331 -    (*Some certified Terms*)
   1.332 -    
   1.333 -   val ctrue = cterm_of sg HOLogic.true_const
   1.334 -   val cfalse = cterm_of sg HOLogic.false_const
   1.335 -   val fm = norm_zero_one fm1
   1.336 -  in  case fm1 of 
   1.337 -      (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z))) => 
   1.338 -         if (x=y) andalso (c1= zero) andalso (c2= one) then (instantiate' [SOME cboolT] [SOME ctrue] (fm_modd_minf))
   1.339 -           else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf))
   1.340 -
   1.341 -      |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z)) =>
   1.342 -  	   if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one) 
   1.343 -	   then (instantiate' [SOME cboolT] [SOME cfalse] (fm_modd_minf))
   1.344 -	 	 else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf)) 
   1.345 -
   1.346 -      |(Const(@{const_name Orderings.less},_) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ pm1 $ y ) $ z )) =>
   1.347 -           if (y=x) andalso (c1 = zero) then 
   1.348 -            if (pm1 = one) then (instantiate' [SOME cboolT] [SOME cfalse] (fm_modd_minf)) else
   1.349 -	     (instantiate' [SOME cboolT] [SOME ctrue] (fm_modd_minf))
   1.350 -	    else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf))
   1.351 -  
   1.352 -      |Const ("Not",_) $ (Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.353 -         if y=x then  let val cz = cterm_of sg (norm_zero_one z)
   1.354 -			  val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop @{const_name Divides.mod} (dlcm,d),norm_zero_one zero)
   1.355 -	 	      in(instantiate' [] [SOME cz ] ((((prove_elementar sg "ss" fm2)) RS(((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (not_dvd_modd_minf)))
   1.356 -		      end
   1.357 -		else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf))
   1.358 -      |(Const("Divides.dvd",_)$ d $ (db as (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $
   1.359 -      c $ y ) $ z))) => 
   1.360 -         if y=x then  let val cz = cterm_of sg (norm_zero_one z)
   1.361 -			  val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop @{const_name Divides.mod} (dlcm,d),norm_zero_one zero)
   1.362 -	 	      in(instantiate' [] [SOME cz ] ((((prove_elementar sg "ss" fm2)) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (dvd_modd_minf)))
   1.363 -		      end
   1.364 -		else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf))
   1.365 -		
   1.366 -    
   1.367 -   |_ => instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_minf)
   1.368 -   end;	 
   1.369 -(*=========================================================================*)
   1.370 -(*=========================================================================*)
   1.371 -fun rho_for_eq_minf x dlcm  sg fm1 =  
   1.372 -   let
   1.373 -   val fm = norm_zero_one fm1
   1.374 -    in  case fm1 of 
   1.375 -      (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z))) => 
   1.376 -         if  (x=y) andalso (c1=zero) andalso (c2=one) 
   1.377 -	   then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (neq_eq_minf))
   1.378 -           else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf))
   1.379 -
   1.380 -      |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z)) =>
   1.381 -  	   if (is_arith_rel fm) andalso (x=y) andalso ((c1=zero) orelse (c1 = norm_zero_one zero)) andalso ((c2=one) orelse (c1 = norm_zero_one one))
   1.382 -	     then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (eq_eq_minf))
   1.383 -	     else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf)) 
   1.384 -
   1.385 -      |(Const(@{const_name Orderings.less},_) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ pm1 $ y ) $ z )) =>
   1.386 -           if (y=x) andalso (c1 =zero) then 
   1.387 -            if pm1 = one then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (le_eq_minf)) else
   1.388 -	     (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (len_eq_minf))
   1.389 -	    else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf))
   1.390 -      |Const ("Not",_) $ (Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.391 -         if y=x then  let val cd = cterm_of sg (norm_zero_one d)
   1.392 -	 		  val cz = cterm_of sg (norm_zero_one z)
   1.393 -	 	      in(instantiate' [] [SOME cd,  SOME cz] (not_dvd_eq_minf)) 
   1.394 -		      end
   1.395 -
   1.396 -		else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf))
   1.397 -		
   1.398 -      |(Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.399 -         if y=x then  let val cd = cterm_of sg (norm_zero_one d)
   1.400 -	 		  val cz = cterm_of sg (norm_zero_one z)
   1.401 -	 	      in(instantiate' [] [SOME cd, SOME cz ] (dvd_eq_minf))
   1.402 -		      end
   1.403 -		else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf))
   1.404 -
   1.405 -      		
   1.406 -    |_ => (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_minf))
   1.407 - end;
   1.408 -
   1.409 -(*=====================================================*)
   1.410 -(*=====================================================*)
   1.411 -(*=========== minf proofs with the compact version==========*)
   1.412 -fun decomp_minf_eq x dlcm sg t =  case t of
   1.413 -   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_minf_conjI)
   1.414 -   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_minf_disjI)
   1.415 -   |_ => ([],fn [] => rho_for_eq_minf x dlcm sg t);
   1.416 -
   1.417 -fun decomp_minf_modd x dlcm sg t = case t of
   1.418 -   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_minf_conjI)
   1.419 -   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_minf_disjI)
   1.420 -   |_ => ([],fn [] => rho_for_modd_minf x dlcm sg t);
   1.421 -
   1.422 -(* -------------------------------------------------------------*)
   1.423 -(*                    Finding rho for pinf_modd                 *)
   1.424 -(* -------------------------------------------------------------*)
   1.425 -fun rho_for_modd_pinf x dlcm sg fm1 = 
   1.426 -let
   1.427 -    (*Some certified Terms*)
   1.428 -    
   1.429 -  val ctrue = cterm_of sg HOLogic.true_const
   1.430 -  val cfalse = cterm_of sg HOLogic.false_const
   1.431 -  val fm = norm_zero_one fm1
   1.432 - in  case fm1 of 
   1.433 -      (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z))) => 
   1.434 -         if ((x=y) andalso (c1= zero) andalso (c2= one))
   1.435 -	 then (instantiate' [SOME cboolT] [SOME ctrue] (fm_modd_pinf))
   1.436 -         else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf))
   1.437 -
   1.438 -      |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z)) =>
   1.439 -  	if ((is_arith_rel fm) andalso (x = y) andalso (c1 = zero)  andalso (c2 = one)) 
   1.440 -	then (instantiate' [SOME cboolT] [SOME cfalse] (fm_modd_pinf))
   1.441 -	else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf))
   1.442 -
   1.443 -      |(Const(@{const_name Orderings.less},_) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ pm1 $ y ) $ z )) =>
   1.444 -        if ((y=x) andalso (c1 = zero)) then 
   1.445 -          if (pm1 = one) 
   1.446 -	  then (instantiate' [SOME cboolT] [SOME ctrue] (fm_modd_pinf)) 
   1.447 -	  else (instantiate' [SOME cboolT] [SOME cfalse] (fm_modd_pinf))
   1.448 -	else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf))
   1.449 -  
   1.450 -      |Const ("Not",_) $ (Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.451 -         if y=x then  let val cz = cterm_of sg (norm_zero_one z)
   1.452 -			  val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop @{const_name Divides.mod} (dlcm,d),norm_zero_one zero)
   1.453 -	 	      in(instantiate' [] [SOME cz ] ((((prove_elementar sg "ss" fm2)) RS(((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (not_dvd_modd_pinf)))
   1.454 -		      end
   1.455 -		else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf))
   1.456 -      |(Const("Divides.dvd",_)$ d $ (db as (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $
   1.457 -      c $ y ) $ z))) => 
   1.458 -         if y=x then  let val cz = cterm_of sg (norm_zero_one z)
   1.459 -			  val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop @{const_name Divides.mod} (dlcm,d),norm_zero_one zero)
   1.460 -	 	      in(instantiate' [] [SOME cz ] ((((prove_elementar sg "ss" fm2)) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (dvd_modd_pinf)))
   1.461 -		      end
   1.462 -		else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf))
   1.463 -		
   1.464 -    
   1.465 -   |_ => instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_modd_pinf)
   1.466 -   end;	
   1.467 -(* -------------------------------------------------------------*)
   1.468 -(*                    Finding rho for pinf_eq                 *)
   1.469 -(* -------------------------------------------------------------*)
   1.470 -fun rho_for_eq_pinf x dlcm sg fm1 = 
   1.471 -  let
   1.472 -					val fm = norm_zero_one fm1
   1.473 -    in  case fm1 of 
   1.474 -      (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z))) => 
   1.475 -         if  (x=y) andalso (c1=zero) andalso (c2=one) 
   1.476 -	   then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (neq_eq_pinf))
   1.477 -           else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf))
   1.478 -
   1.479 -      |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z)) =>
   1.480 -  	   if (is_arith_rel fm) andalso (x=y) andalso ((c1=zero) orelse (c1 = norm_zero_one zero)) andalso ((c2=one) orelse (c1 = norm_zero_one one))
   1.481 -	     then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (eq_eq_pinf))
   1.482 -	     else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf)) 
   1.483 -
   1.484 -      |(Const(@{const_name Orderings.less},_) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ pm1 $ y ) $ z )) =>
   1.485 -           if (y=x) andalso (c1 =zero) then 
   1.486 -            if pm1 = one then (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (le_eq_pinf)) else
   1.487 -	     (instantiate' [] [SOME (cterm_of sg (norm_zero_one z))] (len_eq_pinf))
   1.488 -	    else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf))
   1.489 -      |Const ("Not",_) $ (Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.490 -         if y=x then  let val cd = cterm_of sg (norm_zero_one d)
   1.491 -	 		  val cz = cterm_of sg (norm_zero_one z)
   1.492 -	 	      in(instantiate' [] [SOME cd,  SOME cz] (not_dvd_eq_pinf)) 
   1.493 -		      end
   1.494 -
   1.495 -		else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf))
   1.496 -		
   1.497 -      |(Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.498 -         if y=x then  let val cd = cterm_of sg (norm_zero_one d)
   1.499 -	 		  val cz = cterm_of sg (norm_zero_one z)
   1.500 -	 	      in(instantiate' [] [SOME cd, SOME cz ] (dvd_eq_pinf))
   1.501 -		      end
   1.502 -		else (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf))
   1.503 -
   1.504 -      		
   1.505 -    |_ => (instantiate' [SOME cboolT] [SOME (cterm_of sg fm)] (fm_eq_pinf))
   1.506 - end;
   1.507 -
   1.508 -
   1.509 -
   1.510 -fun  minf_proof_of_c sg x dlcm t =
   1.511 -  let val minf_eqth   = thm_of sg (decomp_minf_eq x dlcm sg) t
   1.512 -      val minf_moddth = thm_of sg (decomp_minf_modd x dlcm sg) t
   1.513 -  in (minf_eqth, minf_moddth)
   1.514 -end;
   1.515 -
   1.516 -(*=========== pinf proofs with the compact version==========*)
   1.517 -fun decomp_pinf_eq x dlcm sg t = case t of
   1.518 -   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_conjI)
   1.519 -   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS eq_pinf_disjI)
   1.520 -   |_ =>([],fn [] => rho_for_eq_pinf x dlcm sg t) ;
   1.521 -
   1.522 -fun decomp_pinf_modd x dlcm sg t =  case t of
   1.523 -   Const ("op &",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_conjI)
   1.524 -   |Const ("op |",_) $ p $q => ([p,q],fn [th1,th2] => [th1,th2] MRS modd_pinf_disjI)
   1.525 -   |_ => ([],fn [] => rho_for_modd_pinf x dlcm sg t);
   1.526 -
   1.527 -fun  pinf_proof_of_c sg x dlcm t =
   1.528 -  let val pinf_eqth   = thm_of sg (decomp_pinf_eq x dlcm sg) t
   1.529 -      val pinf_moddth = thm_of sg (decomp_pinf_modd x dlcm sg) t
   1.530 -  in (pinf_eqth,pinf_moddth)
   1.531 -end;
   1.532 -
   1.533 -
   1.534 -(* ------------------------------------------------------------------------- *)
   1.535 -(* Here we generate the theorem for the Bset Property in the simple direction*)
   1.536 -(* It is just an instantiation*)
   1.537 -(* ------------------------------------------------------------------------- *)
   1.538 -(*
   1.539 -fun bsetproof_of sg (x as Free(xn,xT)) fm bs dlcm   = 
   1.540 -  let
   1.541 -    val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
   1.542 -    val cdlcm = cterm_of sg dlcm
   1.543 -    val cB = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one bs))
   1.544 -  in instantiate' [] [SOME cdlcm,SOME cB, SOME cp] (bst_thm)
   1.545 -end;
   1.546 -
   1.547 -fun asetproof_of sg (x as Free(xn,xT)) fm ast dlcm = 
   1.548 -  let
   1.549 -    val cp = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
   1.550 -    val cdlcm = cterm_of sg dlcm
   1.551 -    val cA = cterm_of sg (list_to_set HOLogic.intT (map norm_zero_one ast))
   1.552 -  in instantiate' [] [SOME cdlcm,SOME cA, SOME cp] (ast_thm)
   1.553 -end;
   1.554 -*)
   1.555 -
   1.556 -(* For the generation of atomic Theorems*)
   1.557 -(* Prove the premisses on runtime and then make RS*)
   1.558 -(* ------------------------------------------------------------------------- *)
   1.559 -
   1.560 -(*========= this is rho ============*)
   1.561 -fun generate_atomic_not_bst_p sg (x as Free(xn,xT)) fm dlcm B at = 
   1.562 -  let
   1.563 -    val cdlcm = cterm_of sg dlcm
   1.564 -    val cB = cterm_of sg B
   1.565 -    val cfma = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
   1.566 -    val cat = cterm_of sg (norm_zero_one at)
   1.567 -  in
   1.568 -  case at of 
   1.569 -   (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z))) => 
   1.570 -      if  (x=y) andalso (c1=zero) andalso (c2=one) 
   1.571 -	 then let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one (linear_cmul ~1 z)) $ B)
   1.572 -	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const(@{const_name HOL.uminus},HOLogic.intT --> HOLogic.intT) $(norm_zero_one  z)))
   1.573 -        val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero ,dlcm))
   1.574 -	 in  (instantiate' [] [SOME cfma]([th3,th1,th2] MRS (not_bst_p_ne)))
   1.575 -	 end
   1.576 -         else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm))
   1.577 -
   1.578 -   |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const (@{const_name HOL.plus}, T) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z)) =>
   1.579 -     if (is_arith_rel at) andalso (x=y)
   1.580 -    then let
   1.581 -      val bst_z = norm_zero_one (linear_neg (linear_add [] z (mk_number 1)))
   1.582 -    in
   1.583 -      let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ bst_z $ B)
   1.584 -	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq (bst_z,Const(@{const_name HOL.minus},T) $ (Const(@{const_name HOL.uminus},HOLogic.intT --> HOLogic.intT) $ norm_zero_one z) $ HOLogic.mk_number HOLogic.intT 1))
   1.585 -		  val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero, dlcm))
   1.586 -	 in  (instantiate' [] [SOME cfma] ([th3,th1,th2] MRS (not_bst_p_eq)))
   1.587 -	 end
   1.588 -       end
   1.589 -         else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm))
   1.590 -
   1.591 -   |(Const(@{const_name Orderings.less},_) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ pm1 $ y ) $ z )) =>
   1.592 -        if (y=x) andalso (c1 =zero) then 
   1.593 -        if pm1 = one then 
   1.594 -	  let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one (linear_cmul ~1 z)) $ B)
   1.595 -              val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const(@{const_name HOL.uminus},HOLogic.intT --> HOLogic.intT) $(norm_zero_one z)))
   1.596 -	  in  (instantiate' [] [SOME cfma,  SOME cdlcm]([th1,th2] MRS (not_bst_p_gt)))
   1.597 -	    end
   1.598 -	 else let val th1 = prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero, dlcm))
   1.599 -	      in (instantiate' [] [SOME cfma, SOME cB,SOME (cterm_of sg (norm_zero_one z))] (th1 RS (not_bst_p_lt)))
   1.600 -	      end
   1.601 -      else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm))
   1.602 -
   1.603 -   |Const ("Not",_) $ (Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.604 -      if y=x then  
   1.605 -           let val cz = cterm_of sg (norm_zero_one z)
   1.606 -	       val th1 = (prove_elementar sg "ss"  (HOLogic.mk_binrel "op =" (HOLogic.mk_binop @{const_name Divides.mod} (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1)
   1.607 - 	     in (instantiate' []  [SOME cfma, SOME cB,SOME cz] (th1 RS (not_bst_p_ndvd)))
   1.608 -	     end
   1.609 -      else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm))
   1.610 -
   1.611 -   |(Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.612 -       if y=x then  
   1.613 -	 let val cz = cterm_of sg (norm_zero_one z)
   1.614 -	     val th1 = (prove_elementar sg "ss"  (HOLogic.mk_binrel "op =" (HOLogic.mk_binop @{const_name Divides.mod} (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1)
   1.615 - 	    in (instantiate' []  [SOME cfma,SOME cB,SOME cz] (th1 RS (not_bst_p_dvd)))
   1.616 -	  end
   1.617 -      else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm))
   1.618 -      		
   1.619 -   |_ => (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cB,SOME cat] (not_bst_p_fm))
   1.620 -      		
   1.621 -    end;
   1.622 -    
   1.623 -
   1.624 -(* ------------------------------------------------------------------------- *)    
   1.625 -(* Main interpretation function for this backwards dirction*)
   1.626 -(* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*)
   1.627 -(*Help Function*)
   1.628 -(* ------------------------------------------------------------------------- *)
   1.629 -
   1.630 -(*==================== Proof with the compact version   *)
   1.631 -
   1.632 -fun decomp_nbstp sg x dlcm B fm t = case t of 
   1.633 -   Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_bst_p_conjI )
   1.634 -  |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_bst_p_disjI)
   1.635 -  |_ => ([], fn [] => generate_atomic_not_bst_p sg x fm dlcm B t);
   1.636 -
   1.637 -fun not_bst_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm B t =
   1.638 -  let 
   1.639 -       val th =  thm_of sg (decomp_nbstp sg x dlcm (list_to_set xT (map norm_zero_one B)) fm) t
   1.640 -      val fma = absfree (xn,xT, norm_zero_one fm)
   1.641 -  in let val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
   1.642 -     in [th,th1] MRS (not_bst_p_Q_elim)
   1.643 -     end
   1.644 -  end;
   1.645 -
   1.646 -
   1.647 -(* ------------------------------------------------------------------------- *)    
   1.648 -(* Protokol interpretation function for the backwards direction for cooper's Theorem*)
   1.649 -
   1.650 -(* For the generation of atomic Theorems*)
   1.651 -(* Prove the premisses on runtime and then make RS*)
   1.652 -(* ------------------------------------------------------------------------- *)
   1.653 -(*========= this is rho ============*)
   1.654 -fun generate_atomic_not_ast_p sg (x as Free(xn,xT)) fm dlcm A at = 
   1.655 -  let
   1.656 -    val cdlcm = cterm_of sg dlcm
   1.657 -    val cA = cterm_of sg A
   1.658 -    val cfma = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
   1.659 -    val cat = cterm_of sg (norm_zero_one at)
   1.660 -  in
   1.661 -  case at of 
   1.662 -   (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z))) => 
   1.663 -      if  (x=y) andalso (c1=zero) andalso (c2=one) 
   1.664 -	 then let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one (linear_cmul ~1 z)) $ A)
   1.665 -	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const(@{const_name HOL.uminus},HOLogic.intT --> HOLogic.intT) $(norm_zero_one  z)))
   1.666 -		  val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero, dlcm))
   1.667 -	 in  (instantiate' [] [SOME cfma]([th3,th1,th2] MRS (not_ast_p_ne)))
   1.668 -	 end
   1.669 -         else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm))
   1.670 -
   1.671 -   |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const (@{const_name HOL.plus}, T) $(Const (@{const_name HOL.times},_) $ c2 $ y) $z)) =>
   1.672 -     if (is_arith_rel at) andalso (x=y)
   1.673 -	then let val ast_z = norm_zero_one (linear_sub [] one z )
   1.674 -	         val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ ast_z $ A)
   1.675 -	         val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq (ast_z,Const(@{const_name HOL.plus},T) $ (Const(@{const_name HOL.uminus},HOLogic.intT --> HOLogic.intT) $(norm_zero_one z)) $ one))
   1.676 -		 val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero, dlcm))
   1.677 -	 in  (instantiate' [] [SOME cfma] ([th3,th1,th2] MRS (not_ast_p_eq)))
   1.678 -       end
   1.679 -         else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm))
   1.680 -
   1.681 -   |(Const(@{const_name Orderings.less},_) $ c1 $(Const (@{const_name HOL.plus}, _) $(Const (@{const_name HOL.times},_) $ pm1 $ y ) $ z )) =>
   1.682 -        if (y=x) andalso (c1 =zero) then 
   1.683 -        if pm1 = (mk_number ~1) then 
   1.684 -	  let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one z) $ A)
   1.685 -              val th2 =  prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero,dlcm))
   1.686 -	  in  (instantiate' [] [SOME cfma]([th2,th1] MRS (not_ast_p_lt)))
   1.687 -	    end
   1.688 -	 else let val th1 = prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero, dlcm))
   1.689 -	      in (instantiate' [] [SOME cfma, SOME cA,SOME (cterm_of sg (norm_zero_one z))] (th1 RS (not_ast_p_gt)))
   1.690 -	      end
   1.691 -      else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm))
   1.692 -
   1.693 -   |Const ("Not",_) $ (Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.694 -      if y=x then  
   1.695 -           let val cz = cterm_of sg (norm_zero_one z)
   1.696 -	       val th1 = (prove_elementar sg "ss"  (HOLogic.mk_binrel "op =" (HOLogic.mk_binop @{const_name Divides.mod} (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1)
   1.697 - 	     in (instantiate' []  [SOME cfma, SOME cA,SOME cz] (th1 RS (not_ast_p_ndvd)))
   1.698 -	     end
   1.699 -      else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm))
   1.700 -
   1.701 -   |(Const("Divides.dvd",_)$ d $ (Const (@{const_name HOL.plus},_) $ (Const (@{const_name HOL.times},_) $ c $ y ) $ z)) => 
   1.702 -       if y=x then  
   1.703 -	 let val cz = cterm_of sg (norm_zero_one z)
   1.704 -	     val th1 = (prove_elementar sg "ss"  (HOLogic.mk_binrel "op =" (HOLogic.mk_binop @{const_name Divides.mod} (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1)
   1.705 - 	    in (instantiate' []  [SOME cfma,SOME cA,SOME cz] (th1 RS (not_ast_p_dvd)))
   1.706 -	  end
   1.707 -      else (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm))
   1.708 -      		
   1.709 -   |_ => (instantiate' [] [SOME cfma,  SOME cdlcm, SOME cA,SOME cat] (not_ast_p_fm))
   1.710 -      		
   1.711 -    end;
   1.712 -
   1.713 -(* ------------------------------------------------------------------------ *)
   1.714 -(* Main interpretation function for this backwards dirction*)
   1.715 -(* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*)
   1.716 -(*Help Function*)
   1.717 -(* ------------------------------------------------------------------------- *)
   1.718 -
   1.719 -fun decomp_nastp sg x dlcm A fm t = case t of 
   1.720 -   Const("op &",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_conjI )
   1.721 -  |Const("op |",_) $ ls $ rs => ([ls,rs],fn [th1,th2] => [th1,th2] MRS not_ast_p_disjI)
   1.722 -  |_ => ([], fn [] => generate_atomic_not_ast_p sg x fm dlcm A t);
   1.723 -
   1.724 -fun not_ast_p_proof_of_c sg (x as Free(xn,xT)) fm dlcm A t =
   1.725 -  let 
   1.726 -       val th =  thm_of sg (decomp_nastp sg x dlcm (list_to_set xT (map norm_zero_one A)) fm) t
   1.727 -      val fma = absfree (xn,xT, norm_zero_one fm)
   1.728 -  in let val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
   1.729 -     in [th,th1] MRS (not_ast_p_Q_elim)
   1.730 -     end
   1.731 -  end;
   1.732 -
   1.733 -
   1.734 -(* -------------------------------*)
   1.735 -(* Finding rho and beta for evalc *)
   1.736 -(* -------------------------------*)
   1.737 -
   1.738 -fun rho_for_evalc sg at = case at of  
   1.739 -    (Const (p,_) $ s $ t) =>(  
   1.740 -    case AList.lookup (op =) operations p of 
   1.741 -        SOME f => 
   1.742 -           ((if (f ((dest_number s),(dest_number t))) 
   1.743 -             then prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const)) 
   1.744 -             else prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const)))  
   1.745 -		   handle _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl)
   1.746 -        | _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl )
   1.747 -     |Const("Not",_)$(Const (p,_) $ s $ t) =>(  
   1.748 -       case AList.lookup (op =) operations p of 
   1.749 -         SOME f => 
   1.750 -           ((if (f ((dest_number s),(dest_number t))) 
   1.751 -             then prove_elementar sg "ss" (HOLogic.mk_eq(at, HOLogic.false_const))  
   1.752 -             else prove_elementar sg "ss" (HOLogic.mk_eq(at,HOLogic.true_const)))  
   1.753 -		      handle _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl) 
   1.754 -         | _ => instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl ) 
   1.755 -     | _ =>   instantiate' [SOME cboolT] [SOME (cterm_of sg at)] refl;
   1.756 -
   1.757 -
   1.758 -(*=========================================================*)
   1.759 -fun decomp_evalc sg t = case t of
   1.760 -   (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
   1.761 -   |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
   1.762 -   |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
   1.763 -   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
   1.764 -   |_ => ([], fn [] => rho_for_evalc sg t);
   1.765 -
   1.766 -
   1.767 -fun proof_of_evalc sg fm = thm_of sg (decomp_evalc sg) fm;
   1.768 -
   1.769 -(*==================================================*)
   1.770 -(*     Proof of linform with the compact model      *)
   1.771 -(*==================================================*)
   1.772 -
   1.773 -
   1.774 -fun decomp_linform sg vars t = case t of
   1.775 -   (Const("op &",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_conjI)
   1.776 -   |(Const("op |",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_disjI)
   1.777 -   |(Const("op -->",_)$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_impI)
   1.778 -   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => ([A,B], fn [th1,th2] => [th1,th2] MRS qe_eqI)
   1.779 -   |(Const("Not",_)$p) => ([p],fn [th] => th RS qe_Not)
   1.780 -   |(Const("Divides.dvd",_)$d$r) => 
   1.781 -     if is_number d then ([], fn [] => (prove_elementar sg "lf" (HOLogic.mk_eq (r, lint vars r))) RS (instantiate' [] [NONE , NONE, SOME (cterm_of sg d)](linearize_dvd)))
   1.782 -     else (warning "Nonlinear Term --- Non numeral leftside at dvd";
   1.783 -       raise COOPER)
   1.784 -   |_ => ([], fn [] => prove_elementar sg "lf" (HOLogic.mk_eq (t, linform vars t)));
   1.785 -
   1.786 -fun proof_of_linform sg vars f = thm_of sg (decomp_linform sg vars) f;
   1.787 -
   1.788 -(* ------------------------------------------------------------------------- *)
   1.789 -(* Interpretaion of Protocols of the cooper procedure : minusinfinity version*)
   1.790 -(* ------------------------------------------------------------------------- *)
   1.791 -fun coopermi_proof_of sg (x as Free(xn,xT)) fm B dlcm =
   1.792 -  (* Get the Bset thm*)
   1.793 -  let val (minf_eqth, minf_moddth) = minf_proof_of_c sg x dlcm fm 
   1.794 -      val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero,dlcm));
   1.795 -      val nbstpthm = not_bst_p_proof_of_c sg x fm dlcm B fm
   1.796 -  in (dpos,minf_eqth,nbstpthm,minf_moddth)
   1.797 -end;
   1.798 -
   1.799 -(* ------------------------------------------------------------------------- *)
   1.800 -(* Interpretaion of Protocols of the cooper procedure : plusinfinity version *)
   1.801 -(* ------------------------------------------------------------------------- *)
   1.802 -fun cooperpi_proof_of sg (x as Free(xn,xT)) fm A dlcm =
   1.803 -  let val (pinf_eqth,pinf_moddth) = pinf_proof_of_c sg x dlcm fm
   1.804 -      val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel @{const_name Orderings.less} (zero,dlcm));
   1.805 -      val nastpthm = not_ast_p_proof_of_c sg x fm dlcm A fm
   1.806 -  in (dpos,pinf_eqth,nastpthm,pinf_moddth)
   1.807 -end;
   1.808 -
   1.809 -(* ------------------------------------------------------------------------- *)
   1.810 -(* Interpretaion of Protocols of the cooper procedure : full version*)
   1.811 -(* ------------------------------------------------------------------------- *)
   1.812 -fun cooper_thm sg s (x as Free(xn,xT)) cfm dlcm ast bst= case s of
   1.813 -  "pi" => let val (dpsthm,pinf_eqth,nbpth,pinf_moddth) = cooperpi_proof_of sg x cfm ast dlcm 
   1.814 -	      in [dpsthm,pinf_eqth,nbpth,pinf_moddth] MRS (cppi_eq)
   1.815 -           end
   1.816 -  |"mi" => let val (dpsthm,minf_eqth,nbpth,minf_moddth) = coopermi_proof_of sg x cfm bst dlcm
   1.817 -	       in [dpsthm,minf_eqth,nbpth,minf_moddth] MRS (cpmi_eq)
   1.818 -                end
   1.819 - |_ => error "parameter error";
   1.820 -
   1.821 -(* ------------------------------------------------------------------------- *)
   1.822 -(* This function should evoluate to the end prove Procedure for one quantifier elimination for Presburger arithmetic*)
   1.823 -(* It shoud be plugged in the qfnp argument of the quantifier elimination proof function*)
   1.824 -(* ------------------------------------------------------------------------- *)
   1.825 -
   1.826 -(* val (timef:(unit->thm) -> thm,prtime,time_reset) = gen_timer();*)
   1.827 -(* val (timef2:(unit->thm) -> thm,prtime2,time_reset2) = gen_timer(); *)
   1.828 -
   1.829 -fun cooper_prv sg (x as Free(xn,xT)) efm = let 
   1.830 -   (* lfm_thm : efm = linearized form of efm*)
   1.831 -   val lfm_thm = proof_of_linform sg [xn] efm
   1.832 -   (*efm2 is the linearized form of efm *) 
   1.833 -   val efm2 = snd(qe_get_terms lfm_thm)
   1.834 -   (* l is the lcm of all coefficients of x *)
   1.835 -   val l = formlcm x efm2
   1.836 -   (*ac_thm: efm = efm2 with adjusted coefficients of x *)
   1.837 -   val ac_thm = [lfm_thm , (proof_of_adjustcoeffeq sg x l efm2)] MRS trans
   1.838 -   (* fm is efm2 with adjusted coefficients of x *)
   1.839 -   val fm = snd (qe_get_terms ac_thm)
   1.840 -  (* cfm is l dvd x & fm' where fm' is fm where l*x is replaced by x*)
   1.841 -   val  cfm = unitycoeff x fm
   1.842 -   (*afm is fm where c*x is replaced by 1*x or -1*x *)
   1.843 -   val afm = adjustcoeff x l fm
   1.844 -   (* P = %x.afm*)
   1.845 -   val P = absfree(xn,xT,afm)
   1.846 -   (* This simpset allows the elimination of the sets in bex {1..d} *)
   1.847 -   val ss = presburger_ss addsimps
   1.848 -     [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff]
   1.849 -   (* uth : EX x.P(l*x) = EX x. l dvd x & P x*)
   1.850 -   val uth = instantiate' [] [SOME (cterm_of sg P) , SOME (cterm_of sg (mk_number l))] (unity_coeff_ex)
   1.851 -   (* e_ac_thm : Ex x. efm = EX x. fm*)
   1.852 -   val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI)
   1.853 -   (* A and B set of the formula*)
   1.854 -   val A = aset x cfm
   1.855 -   val B = bset x cfm
   1.856 -   (* the divlcm (delta) of the formula*)
   1.857 -   val dlcm = mk_number (divlcm x cfm)
   1.858 -   (* Which set is smaller to generate the (hoepfully) shorter proof*)
   1.859 -   val cms = if ((length A) < (length B )) then "pi" else "mi"
   1.860 -(*   val _ = if cms = "pi" then writeln "Plusinfinity" else writeln "Minusinfinity"*)
   1.861 -   (* synthesize the proof of cooper's theorem*)
   1.862 -    (* cp_thm: EX x. cfm = Q*)
   1.863 -   val cp_thm =  cooper_thm sg cms x cfm dlcm A B
   1.864 -   (* Exxpand the right hand side to get rid of EX j : {1..d} to get a huge disjunction*)
   1.865 -   (* exp_cp_thm: EX x.cfm = Q' , where Q' is a simplified version of Q*)
   1.866 -(*
   1.867 -   val _ = prth cp_thm
   1.868 -   val _ = writeln "Expanding the bounded EX..."
   1.869 -*)
   1.870 -   val exp_cp_thm = refl RS (simplify ss (cp_thm RSN (2,trans)))
   1.871 -(*
   1.872 -   val _ = writeln "Expanded" *)
   1.873 -   (* lsuth = EX.P(l*x) ; rsuth = EX x. l dvd x & P x*)
   1.874 -   val (lsuth,rsuth) = qe_get_terms (uth)
   1.875 -   (* lseacth = EX x. efm; rseacth = EX x. fm*)
   1.876 -   val (lseacth,rseacth) = qe_get_terms(e_ac_thm)
   1.877 -   (* lscth = EX x. cfm; rscth = Q' *)
   1.878 -   val (lscth,rscth) = qe_get_terms (exp_cp_thm)
   1.879 -   (* u_c_thm: EX x. P(l*x) = Q'*)
   1.880 -   val  u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans
   1.881 -   (* result: EX x. efm = Q'*)
   1.882 - in  ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans)
   1.883 -   end
   1.884 -|cooper_prv _ _ _ =  error "Parameters format";
   1.885 -
   1.886 -(* **************************************** *)
   1.887 -(*    An Other Version of cooper proving    *)
   1.888 -(*     by giving a withness for EX          *)
   1.889 -(* **************************************** *)
   1.890 -
   1.891 -
   1.892 -
   1.893 -fun cooper_prv_w sg (x as Free(xn,xT)) efm = let 
   1.894 -   (* lfm_thm : efm = linearized form of efm*)
   1.895 -   val lfm_thm = proof_of_linform sg [xn] efm
   1.896 -   (*efm2 is the linearized form of efm *) 
   1.897 -   val efm2 = snd(qe_get_terms lfm_thm)
   1.898 -   (* l is the lcm of all coefficients of x *)
   1.899 -   val l = formlcm x efm2
   1.900 -   (*ac_thm: efm = efm2 with adjusted coefficients of x *)
   1.901 -   val ac_thm = [lfm_thm , (proof_of_adjustcoeffeq sg x l efm2)] MRS trans
   1.902 -   (* fm is efm2 with adjusted coefficients of x *)
   1.903 -   val fm = snd (qe_get_terms ac_thm)
   1.904 -  (* cfm is l dvd x & fm' where fm' is fm where l*x is replaced by x*)
   1.905 -   val  cfm = unitycoeff x fm
   1.906 -   (*afm is fm where c*x is replaced by 1*x or -1*x *)
   1.907 -   val afm = adjustcoeff x l fm
   1.908 -   (* P = %x.afm*)
   1.909 -   val P = absfree(xn,xT,afm)
   1.910 -   (* This simpset allows the elimination of the sets in bex {1..d} *)
   1.911 -   val ss = presburger_ss addsimps
   1.912 -     [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff]
   1.913 -   (* uth : EX x.P(l*x) = EX x. l dvd x & P x*)
   1.914 -   val uth = instantiate' [] [SOME (cterm_of sg P) , SOME (cterm_of sg (mk_number l))] (unity_coeff_ex)
   1.915 -   (* e_ac_thm : Ex x. efm = EX x. fm*)
   1.916 -   val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI)
   1.917 -   (* lsuth = EX.P(l*x) ; rsuth = EX x. l dvd x & P x*)
   1.918 -   val (lsuth,rsuth) = qe_get_terms (uth)
   1.919 -   (* lseacth = EX x. efm; rseacth = EX x. fm*)
   1.920 -   val (lseacth,rseacth) = qe_get_terms(e_ac_thm)
   1.921 -
   1.922 -   val (w,rs) = cooper_w [] cfm
   1.923 -   val exp_cp_thm =  case w of 
   1.924 -     (* FIXME - e_ac_thm just tipped to test syntactical correctness of the program!!!!*)
   1.925 -    SOME n =>  e_ac_thm (* Prove cfm (n) and use exI and then Eq_TrueI*)
   1.926 -   |_ => let 
   1.927 -    (* A and B set of the formula*)
   1.928 -    val A = aset x cfm
   1.929 -    val B = bset x cfm
   1.930 -    (* the divlcm (delta) of the formula*)
   1.931 -    val dlcm = mk_number (divlcm x cfm)
   1.932 -    (* Which set is smaller to generate the (hoepfully) shorter proof*)
   1.933 -    val cms = if ((length A) < (length B )) then "pi" else "mi"
   1.934 -    (* synthesize the proof of cooper's theorem*)
   1.935 -     (* cp_thm: EX x. cfm = Q*)
   1.936 -    val cp_thm = cooper_thm sg cms x cfm dlcm A B
   1.937 -     (* Exxpand the right hand side to get rid of EX j : {1..d} to get a huge disjunction*)
   1.938 -    (* exp_cp_thm: EX x.cfm = Q' , where Q' is a simplified version of Q*)
   1.939 -    in refl RS (simplify ss (cp_thm RSN (2,trans)))
   1.940 -    end
   1.941 -   (* lscth = EX x. cfm; rscth = Q' *)
   1.942 -   val (lscth,rscth) = qe_get_terms (exp_cp_thm)
   1.943 -   (* u_c_thm: EX x. P(l*x) = Q'*)
   1.944 -   val  u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans
   1.945 -   (* result: EX x. efm = Q'*)
   1.946 - in  ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans)
   1.947 -   end
   1.948 -|cooper_prv_w _ _ _ =  error "Parameters format";
   1.949 -
   1.950 -
   1.951 -
   1.952 -fun decomp_cnnf sg lfnp P = case P of 
   1.953 -     Const ("op &",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS qe_conjI )
   1.954 -   |Const ("op |",_) $ p $q => ([p,q] , fn [th1,th2] => [th1,th2] MRS  qe_disjI)
   1.955 -   |Const ("Not",_) $ (Const("Not",_) $ p) => ([p], fn [th] => th RS nnf_nn)
   1.956 -   |Const("Not",_) $ (Const(opn,T) $ p $ q) => 
   1.957 -     if opn = "op |" 
   1.958 -      then case (p,q) of 
   1.959 -         (A as (Const ("op &",_) $ r $ s),B as (Const ("op &",_) $ r1 $ t)) =>
   1.960 -          if r1 = negate r 
   1.961 -          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)
   1.962 -
   1.963 -          else ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj)
   1.964 -        |(_,_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] => [th1,th2] MRS nnf_ndj)
   1.965 -      else (
   1.966 -         case (opn,T) of 
   1.967 -           ("op &",_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_ncj )
   1.968 -           |("op -->",_) => ([p,HOLogic.Not $ q ], fn [th1,th2] =>[th1,th2] MRS nnf_nim )
   1.969 -           |("op =",Type ("fun",[Type ("bool", []),_])) => 
   1.970 -           ([HOLogic.conj $ p $ (HOLogic.Not $ q),HOLogic.conj $ (HOLogic.Not $ p) $ q], fn [th1,th2] => [th1,th2] MRS nnf_neq)
   1.971 -            |(_,_) => ([], fn [] => lfnp P)
   1.972 -)
   1.973 -
   1.974 -   |(Const ("op -->",_) $ p $ q) => ([HOLogic.Not$p,q], fn [th1,th2] => [th1,th2] MRS nnf_im)
   1.975 -
   1.976 -   |(Const ("op =", Type ("fun",[Type ("bool", []),_])) $ p $ q) =>
   1.977 -     ([HOLogic.conj $ p $ q,HOLogic.conj $ (HOLogic.Not $ p) $ (HOLogic.Not $ q) ], fn [th1,th2] =>[th1,th2] MRS nnf_eq )
   1.978 -   |_ => ([], fn [] => lfnp P);
   1.979 -
   1.980 -
   1.981 -
   1.982 -
   1.983 -fun proof_of_cnnf sg p lfnp = 
   1.984 - let val th1 = thm_of sg (decomp_cnnf sg lfnp) p
   1.985 -     val rs = snd(qe_get_terms th1)
   1.986 -     val th2 = prove_elementar sg "ss" (HOLogic.mk_eq(rs,simpl rs))
   1.987 -  in [th1,th2] MRS trans
   1.988 -  end;
   1.989 -
   1.990 -end;
   1.991 -