src/HOL/Integ/cooper_proof.ML
author paulson
Tue Nov 18 11:01:52 2003 +0100 (2003-11-18)
changeset 14259 79f7d3451b1e
parent 14139 ca3dd7ed5ac5
child 14479 0eca4aabf371
permissions -rw-r--r--
conversion of ML to Isar scripts
berghofe@13876
     1
(*  Title:      HOL/Integ/cooper_proof.ML
berghofe@13876
     2
    ID:         $Id$
berghofe@13876
     3
    Author:     Amine Chaieb and Tobias Nipkow, TU Muenchen
berghofe@13876
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
berghofe@13876
     5
berghofe@13876
     6
File containing the implementation of the proof
berghofe@13876
     7
generation for Cooper Algorithm
berghofe@13876
     8
*)
berghofe@13876
     9
berghofe@13876
    10
signature COOPER_PROOF =
berghofe@13876
    11
sig
berghofe@13876
    12
  val qe_Not : thm
berghofe@13876
    13
  val qe_conjI : thm
berghofe@13876
    14
  val qe_disjI : thm
berghofe@13876
    15
  val qe_impI : thm
berghofe@13876
    16
  val qe_eqI : thm
berghofe@13876
    17
  val qe_exI : thm
berghofe@13876
    18
  val qe_get_terms : thm -> term * term
berghofe@13876
    19
  val cooper_prv : Sign.sg -> term -> term -> string list -> thm
berghofe@13876
    20
  val proof_of_evalc : Sign.sg -> term -> thm
berghofe@13876
    21
  val proof_of_cnnf : Sign.sg -> term -> (term -> thm) -> thm
berghofe@13876
    22
  val proof_of_linform : Sign.sg -> string list -> term -> thm
berghofe@13876
    23
end;
berghofe@13876
    24
berghofe@13876
    25
structure CooperProof : COOPER_PROOF =
berghofe@13876
    26
struct
berghofe@13876
    27
berghofe@13876
    28
open CooperDec;
berghofe@13876
    29
berghofe@13876
    30
(*-----------------------------------------------------------------*)
berghofe@13876
    31
(*-----------------------------------------------------------------*)
berghofe@13876
    32
(*-----------------------------------------------------------------*)
berghofe@13876
    33
(*---                                                           ---*)
berghofe@13876
    34
(*---                                                           ---*)
berghofe@13876
    35
(*---         Protocoling part                                  ---*)
berghofe@13876
    36
(*---                                                           ---*)
berghofe@13876
    37
(*---           includes the protocolling datastructure         ---*)
berghofe@13876
    38
(*---                                                           ---*)
berghofe@13876
    39
(*---          and the protocolling fuctions                    ---*)
berghofe@13876
    40
(*---                                                           ---*)
berghofe@13876
    41
(*---                                                           ---*)
berghofe@13876
    42
(*-----------------------------------------------------------------*)
berghofe@13876
    43
(*-----------------------------------------------------------------*)
berghofe@13876
    44
(*-----------------------------------------------------------------*)
berghofe@13876
    45
berghofe@13876
    46
val presburger_ss = simpset_of (theory "Presburger")
paulson@14259
    47
  addsimps [zdiff_def] delsimps [thm"zdiff_def_symmetric"];
berghofe@13876
    48
val cboolT = ctyp_of (sign_of HOL.thy) HOLogic.boolT;
berghofe@13876
    49
berghofe@13876
    50
(*Theorems that will be used later for the proofgeneration*)
berghofe@13876
    51
berghofe@13876
    52
val zdvd_iff_zmod_eq_0 = thm "zdvd_iff_zmod_eq_0";
berghofe@13876
    53
val unity_coeff_ex = thm "unity_coeff_ex";
berghofe@13876
    54
paulson@14259
    55
(* Theorems for proving the adjustment of the coefficients*)
berghofe@13876
    56
berghofe@13876
    57
val ac_lt_eq =  thm "ac_lt_eq";
berghofe@13876
    58
val ac_eq_eq = thm "ac_eq_eq";
berghofe@13876
    59
val ac_dvd_eq = thm "ac_dvd_eq";
berghofe@13876
    60
val ac_pi_eq = thm "ac_pi_eq";
berghofe@13876
    61
berghofe@13876
    62
(* The logical compination of the sythetised properties*)
berghofe@13876
    63
val qe_Not = thm "qe_Not";
berghofe@13876
    64
val qe_conjI = thm "qe_conjI";
berghofe@13876
    65
val qe_disjI = thm "qe_disjI";
berghofe@13876
    66
val qe_impI = thm "qe_impI";
berghofe@13876
    67
val qe_eqI = thm "qe_eqI";
berghofe@13876
    68
val qe_exI = thm "qe_exI";
berghofe@13876
    69
val qe_ALLI = thm "qe_ALLI";
berghofe@13876
    70
paulson@14259
    71
(*Modulo D property for Pminusinf and Plusinf *)
berghofe@13876
    72
val fm_modd_minf = thm "fm_modd_minf";
berghofe@13876
    73
val not_dvd_modd_minf = thm "not_dvd_modd_minf";
berghofe@13876
    74
val dvd_modd_minf = thm "dvd_modd_minf";
berghofe@13876
    75
berghofe@13876
    76
val fm_modd_pinf = thm "fm_modd_pinf";
berghofe@13876
    77
val not_dvd_modd_pinf = thm "not_dvd_modd_pinf";
berghofe@13876
    78
val dvd_modd_pinf = thm "dvd_modd_pinf";
berghofe@13876
    79
paulson@14259
    80
(* the minusinfinity property*)
berghofe@13876
    81
berghofe@13876
    82
val fm_eq_minf = thm "fm_eq_minf";
berghofe@13876
    83
val neq_eq_minf = thm "neq_eq_minf";
berghofe@13876
    84
val eq_eq_minf = thm "eq_eq_minf";
berghofe@13876
    85
val le_eq_minf = thm "le_eq_minf";
berghofe@13876
    86
val len_eq_minf = thm "len_eq_minf";
berghofe@13876
    87
val not_dvd_eq_minf = thm "not_dvd_eq_minf";
berghofe@13876
    88
val dvd_eq_minf = thm "dvd_eq_minf";
berghofe@13876
    89
paulson@14259
    90
(* the Plusinfinity property*)
berghofe@13876
    91
berghofe@13876
    92
val fm_eq_pinf = thm "fm_eq_pinf";
berghofe@13876
    93
val neq_eq_pinf = thm "neq_eq_pinf";
berghofe@13876
    94
val eq_eq_pinf = thm "eq_eq_pinf";
berghofe@13876
    95
val le_eq_pinf = thm "le_eq_pinf";
berghofe@13876
    96
val len_eq_pinf = thm "len_eq_pinf";
berghofe@13876
    97
val not_dvd_eq_pinf = thm "not_dvd_eq_pinf";
berghofe@13876
    98
val dvd_eq_pinf = thm "dvd_eq_pinf";
berghofe@13876
    99
berghofe@13876
   100
(*Logical construction of the Property*)
berghofe@13876
   101
val eq_minf_conjI = thm "eq_minf_conjI";
berghofe@13876
   102
val eq_minf_disjI = thm "eq_minf_disjI";
berghofe@13876
   103
val modd_minf_disjI = thm "modd_minf_disjI";
berghofe@13876
   104
val modd_minf_conjI = thm "modd_minf_conjI";
berghofe@13876
   105
berghofe@13876
   106
val eq_pinf_conjI = thm "eq_pinf_conjI";
berghofe@13876
   107
val eq_pinf_disjI = thm "eq_pinf_disjI";
berghofe@13876
   108
val modd_pinf_disjI = thm "modd_pinf_disjI";
berghofe@13876
   109
val modd_pinf_conjI = thm "modd_pinf_conjI";
berghofe@13876
   110
berghofe@13876
   111
berghofe@13876
   112
(*Cooper Backwards...*)
berghofe@13876
   113
(*Bset*)
berghofe@13876
   114
val not_bst_p_fm = thm "not_bst_p_fm";
berghofe@13876
   115
val not_bst_p_ne = thm "not_bst_p_ne";
berghofe@13876
   116
val not_bst_p_eq = thm "not_bst_p_eq";
berghofe@13876
   117
val not_bst_p_gt = thm "not_bst_p_gt";
berghofe@13876
   118
val not_bst_p_lt = thm "not_bst_p_lt";
berghofe@13876
   119
val not_bst_p_ndvd = thm "not_bst_p_ndvd";
berghofe@13876
   120
val not_bst_p_dvd = thm "not_bst_p_dvd";
berghofe@13876
   121
berghofe@13876
   122
(*Aset*)
berghofe@13876
   123
val not_ast_p_fm = thm "not_ast_p_fm";
berghofe@13876
   124
val not_ast_p_ne = thm "not_ast_p_ne";
berghofe@13876
   125
val not_ast_p_eq = thm "not_ast_p_eq";
berghofe@13876
   126
val not_ast_p_gt = thm "not_ast_p_gt";
berghofe@13876
   127
val not_ast_p_lt = thm "not_ast_p_lt";
berghofe@13876
   128
val not_ast_p_ndvd = thm "not_ast_p_ndvd";
berghofe@13876
   129
val not_ast_p_dvd = thm "not_ast_p_dvd";
berghofe@13876
   130
berghofe@13876
   131
(*Logical construction of the prop*)
berghofe@13876
   132
(*Bset*)
berghofe@13876
   133
val not_bst_p_conjI = thm "not_bst_p_conjI";
berghofe@13876
   134
val not_bst_p_disjI = thm "not_bst_p_disjI";
berghofe@13876
   135
val not_bst_p_Q_elim = thm "not_bst_p_Q_elim";
berghofe@13876
   136
berghofe@13876
   137
(*Aset*)
berghofe@13876
   138
val not_ast_p_conjI = thm "not_ast_p_conjI";
berghofe@13876
   139
val not_ast_p_disjI = thm "not_ast_p_disjI";
berghofe@13876
   140
val not_ast_p_Q_elim = thm "not_ast_p_Q_elim";
berghofe@13876
   141
berghofe@13876
   142
(*Cooper*)
berghofe@13876
   143
val cppi_eq = thm "cppi_eq";
berghofe@13876
   144
val cpmi_eq = thm "cpmi_eq";
berghofe@13876
   145
berghofe@13876
   146
(*Others*)
berghofe@13876
   147
val simp_from_to = thm "simp_from_to";
berghofe@13876
   148
val P_eqtrue = thm "P_eqtrue";
berghofe@13876
   149
val P_eqfalse = thm "P_eqfalse";
berghofe@13876
   150
berghofe@13876
   151
(*For Proving NNF*)
berghofe@13876
   152
berghofe@13876
   153
val nnf_nn = thm "nnf_nn";
berghofe@13876
   154
val nnf_im = thm "nnf_im";
berghofe@13876
   155
val nnf_eq = thm "nnf_eq";
berghofe@13876
   156
val nnf_sdj = thm "nnf_sdj";
berghofe@13876
   157
val nnf_ncj = thm "nnf_ncj";
berghofe@13876
   158
val nnf_nim = thm "nnf_nim";
berghofe@13876
   159
val nnf_neq = thm "nnf_neq";
berghofe@13876
   160
val nnf_ndj = thm "nnf_ndj";
berghofe@13876
   161
berghofe@13876
   162
(*For Proving term linearizition*)
berghofe@13876
   163
val linearize_dvd = thm "linearize_dvd";
berghofe@13876
   164
val lf_lt = thm "lf_lt";
berghofe@13876
   165
val lf_eq = thm "lf_eq";
berghofe@13876
   166
val lf_dvd = thm "lf_dvd";
berghofe@13876
   167
berghofe@13876
   168
berghofe@13876
   169
berghofe@13876
   170
(* ------------------------------------------------------------------------- *)
berghofe@13876
   171
(*Datatatype declarations for Proofprotocol for the cooperprocedure.*)
berghofe@13876
   172
(* ------------------------------------------------------------------------- *)
berghofe@13876
   173
berghofe@13876
   174
berghofe@13876
   175
berghofe@13876
   176
(* ------------------------------------------------------------------------- *)
berghofe@13876
   177
(*Datatatype declarations for Proofprotocol for the adjustcoeff step.*)
berghofe@13876
   178
(* ------------------------------------------------------------------------- *)
berghofe@13876
   179
datatype CpLog = No
berghofe@13876
   180
                |Simp of term*CpLog
berghofe@13876
   181
		|Blast of CpLog*CpLog
berghofe@13876
   182
		|Aset of (term*term*(term list)*term)
berghofe@13876
   183
		|Bset of (term*term*(term list)*term)
berghofe@13876
   184
		|Minusinf of CpLog*CpLog
berghofe@13876
   185
		|Cooper of term*CpLog*CpLog*CpLog
berghofe@13876
   186
		|Eq_minf of term*term
berghofe@13876
   187
		|Modd_minf of term*term
berghofe@13876
   188
		|Eq_minf_conjI of CpLog*CpLog
berghofe@13876
   189
		|Modd_minf_conjI of CpLog*CpLog	
berghofe@13876
   190
		|Modd_minf_disjI of CpLog*CpLog
berghofe@13876
   191
		|Eq_minf_disjI of CpLog*CpLog	
berghofe@13876
   192
		|Not_bst_p of term*term*term*term*CpLog
berghofe@13876
   193
		|Not_bst_p_atomic of term
berghofe@13876
   194
		|Not_bst_p_conjI of CpLog*CpLog
berghofe@13876
   195
		|Not_bst_p_disjI of CpLog*CpLog
berghofe@13876
   196
		|Not_ast_p of term*term*term*term*CpLog
berghofe@13876
   197
		|Not_ast_p_atomic of term
berghofe@13876
   198
		|Not_ast_p_conjI of CpLog*CpLog
berghofe@13876
   199
		|Not_ast_p_disjI of CpLog*CpLog
berghofe@13876
   200
		|CpLogError;
berghofe@13876
   201
berghofe@13876
   202
berghofe@13876
   203
berghofe@13876
   204
datatype ACLog = ACAt of int*term
berghofe@13876
   205
                |ACPI of int*term
berghofe@13876
   206
                |ACfm of term
berghofe@13876
   207
                |ACNeg of ACLog
berghofe@13876
   208
		|ACConst of string*ACLog*ACLog;
berghofe@13876
   209
berghofe@13876
   210
berghofe@13876
   211
berghofe@13876
   212
(* ------------------------------------------------------------------------- *)
berghofe@13876
   213
(*Datatatype declarations for Proofprotocol for the CNNF step.*)
berghofe@13876
   214
(* ------------------------------------------------------------------------- *)
berghofe@13876
   215
berghofe@13876
   216
berghofe@13876
   217
datatype NNFLog = NNFAt of term
berghofe@13876
   218
                |NNFSimp of NNFLog
berghofe@13876
   219
                |NNFNN of NNFLog
berghofe@13876
   220
		|NNFConst of string*NNFLog*NNFLog;
berghofe@13876
   221
berghofe@13876
   222
(* ------------------------------------------------------------------------- *)
berghofe@13876
   223
(*Datatatype declarations for Proofprotocol for the linform  step.*)
berghofe@13876
   224
(* ------------------------------------------------------------------------- *)
berghofe@13876
   225
berghofe@13876
   226
berghofe@13876
   227
datatype LfLog = LfAt of term
berghofe@13876
   228
                |LfAtdvd of term
berghofe@13876
   229
                |Lffm of term
berghofe@13876
   230
                |LfConst of string*LfLog*LfLog
berghofe@13876
   231
		|LfNot of LfLog
berghofe@13876
   232
		|LfQ of string*string*typ*LfLog;
berghofe@13876
   233
berghofe@13876
   234
berghofe@13876
   235
(* ------------------------------------------------------------------------- *)
berghofe@13876
   236
(*Datatatype declarations for Proofprotocol for the evaluation- evalc-  step.*)
berghofe@13876
   237
(* ------------------------------------------------------------------------- *)
berghofe@13876
   238
berghofe@13876
   239
berghofe@13876
   240
datatype EvalLog = EvalAt of term
berghofe@13876
   241
                |Evalfm of term
berghofe@13876
   242
		|EvalConst of string*EvalLog*EvalLog;
berghofe@13876
   243
berghofe@13876
   244
(* ------------------------------------------------------------------------- *)
berghofe@13876
   245
(*This function norm_zero_one  replaces the occurences of Numeral1 and Numeral0*)
berghofe@13876
   246
(*Respectively by their abstract representation Const("1",..) and COnst("0",..)*)
berghofe@13876
   247
(*this is necessary because the theorems use this representation.*)
berghofe@13876
   248
(* This function should be elminated in next versions...*)
berghofe@13876
   249
(* ------------------------------------------------------------------------- *)
berghofe@13876
   250
berghofe@13876
   251
fun norm_zero_one fm = case fm of
berghofe@13876
   252
  (Const ("op *",_) $ c $ t) => 
berghofe@13876
   253
    if c = one then (norm_zero_one t)
berghofe@13876
   254
    else if (dest_numeral c = ~1) 
berghofe@13876
   255
         then (Const("uminus",HOLogic.intT --> HOLogic.intT) $ (norm_zero_one t))
berghofe@13876
   256
         else (HOLogic.mk_binop "op *" (norm_zero_one c,norm_zero_one t))
berghofe@13876
   257
  |(node $ rest) => ((norm_zero_one node)$(norm_zero_one rest))
berghofe@13876
   258
  |(Abs(x,T,p)) => (Abs(x,T,(norm_zero_one p)))
berghofe@13876
   259
  |_ => fm;
berghofe@13876
   260
berghofe@13876
   261
berghofe@13876
   262
(* ------------------------------------------------------------------------- *)
berghofe@13876
   263
(* Intended to tell that here we changed the structure of the formula with respect to the posineq theorem : ~(0 < t) = 0 < 1-t*)
berghofe@13876
   264
(* ------------------------------------------------------------------------- *)
berghofe@13876
   265
fun adjustcoeffeq_wp  x l fm = 
berghofe@13876
   266
    case fm of  
berghofe@13876
   267
  (Const("Not",_)$(Const("op <",_) $(Const("0",_)) $(rt as (Const ("op +", _)$(Const ("op *",_) $    c $ y ) $z )))) => 
berghofe@13876
   268
  if (x = y) 
berghofe@13876
   269
  then let  
berghofe@13876
   270
       val m = l div (dest_numeral c) 
berghofe@13876
   271
       val n = abs (m)
berghofe@13876
   272
       val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x)) 
berghofe@13905
   273
       val rs = (HOLogic.mk_binrel "op <" (zero,linear_sub [] (mk_numeral n) (HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) 
berghofe@13876
   274
       in (ACPI(n,fm),rs)
berghofe@13876
   275
       end
berghofe@13876
   276
  else  let val rs = (HOLogic.mk_binrel "op <" (zero,linear_sub [] one rt )) 
berghofe@13876
   277
        in (ACPI(1,fm),rs)
berghofe@13876
   278
        end
berghofe@13876
   279
berghofe@13876
   280
  |(Const(p,_) $d $( Const ("op +", _)$(Const ("op *",_) $ 
berghofe@13876
   281
      c $ y ) $z )) => if (is_arith_rel fm) andalso (x = y) then  
berghofe@13876
   282
        let val m = l div (dest_numeral c) 
berghofe@13876
   283
           val n = (if p = "op <" then abs(m) else m)  
berghofe@13876
   284
           val xtm = (HOLogic.mk_binop "op *" ((mk_numeral ((m div n)*l) ), x))
berghofe@13876
   285
           val rs = (HOLogic.mk_binrel p ((linear_cmul n d),(HOLogic.mk_binop "op +" ( xtm ,( linear_cmul n z) )))) 
berghofe@13876
   286
	   in (ACAt(n,fm),rs)
berghofe@13876
   287
	   end
berghofe@13876
   288
        else (ACfm(fm),fm) 
berghofe@13876
   289
  |( Const ("Not", _) $ p) => let val (rsp,rsr) = adjustcoeffeq_wp x l p 
berghofe@13876
   290
                              in (ACNeg(rsp),HOLogic.Not $ rsr) 
berghofe@13876
   291
                              end
berghofe@13876
   292
  |( Const ("op &",_) $ p $ q) =>let val (rspp,rspr) = adjustcoeffeq_wp x l p
berghofe@13876
   293
                                     val (rsqp,rsqr) = adjustcoeffeq_wp x l q
berghofe@13876
   294
berghofe@13876
   295
                                  in (ACConst ("CJ",rspp,rsqp), HOLogic.mk_conj (rspr,rsqr)) 
berghofe@13876
   296
                                  end 
berghofe@13876
   297
  |( Const ("op |",_) $ p $ q) =>let val (rspp,rspr) = adjustcoeffeq_wp x l p
berghofe@13876
   298
                                     val (rsqp,rsqr) = adjustcoeffeq_wp x l q
berghofe@13876
   299
berghofe@13876
   300
                                  in (ACConst ("DJ",rspp,rsqp), HOLogic.mk_disj (rspr,rsqr)) 
berghofe@13876
   301
                                  end
berghofe@13876
   302
berghofe@13876
   303
  |_ => (ACfm(fm),fm);
berghofe@13876
   304
berghofe@13876
   305
berghofe@13876
   306
(*_________________________________________*)
berghofe@13876
   307
(*-----------------------------------------*)
berghofe@13876
   308
(* Protocol generation for the liform step *)
berghofe@13876
   309
(*_________________________________________*)
berghofe@13876
   310
(*-----------------------------------------*)
berghofe@13876
   311
berghofe@13876
   312
berghofe@13876
   313
fun linform_wp fm = 
berghofe@13876
   314
  let fun at_linform_wp at =
berghofe@13876
   315
    case at of
berghofe@13876
   316
      (Const("op <=",_)$s$t) => LfAt(at)
berghofe@13876
   317
      |(Const("op <",_)$s$t) => LfAt(at)
berghofe@13876
   318
      |(Const("op =",_)$s$t) => LfAt(at)
berghofe@13876
   319
      |(Const("Divides.op dvd",_)$s$t) => LfAtdvd(at)
berghofe@13876
   320
  in
berghofe@13876
   321
  if is_arith_rel fm 
berghofe@13876
   322
  then at_linform_wp fm 
berghofe@13876
   323
  else case fm of
berghofe@13876
   324
    (Const("Not",_) $ A) => LfNot(linform_wp A)
berghofe@13876
   325
   |(Const("op &",_)$ A $ B) => LfConst("CJ",linform_wp A, linform_wp B)
berghofe@13876
   326
   |(Const("op |",_)$ A $ B) => LfConst("DJ",linform_wp A, linform_wp B)
berghofe@13876
   327
   |(Const("op -->",_)$ A $ B) => LfConst("IM",linform_wp A, linform_wp B)
berghofe@13876
   328
   |(Const("op =",Type ("fun",[Type ("bool", []),_]))$ A $ B) => LfConst("EQ",linform_wp A, linform_wp B)
berghofe@13876
   329
   |Const("Ex",_)$Abs(x,T,p) => 
berghofe@13876
   330
     let val (xn,p1) = variant_abs(x,T,p)
berghofe@13876
   331
     in LfQ("Ex",xn,T,linform_wp p1)
berghofe@13876
   332
     end 
berghofe@13876
   333
   |Const("All",_)$Abs(x,T,p) => 
berghofe@13876
   334
     let val (xn,p1) = variant_abs(x,T,p)
berghofe@13876
   335
     in LfQ("All",xn,T,linform_wp p1)
berghofe@13876
   336
     end 
berghofe@13876
   337
end;
berghofe@13876
   338
berghofe@13876
   339
berghofe@13876
   340
(* ------------------------------------------------------------------------- *)
berghofe@13876
   341
(*For simlified formulas we just notice the original formula, for whitch we habe been
berghofe@13876
   342
intendes to make the proof.*)
berghofe@13876
   343
(* ------------------------------------------------------------------------- *)
berghofe@13876
   344
fun simpl_wp (fm,pr) = let val fm2 = simpl fm
berghofe@13876
   345
				in (fm2,Simp(fm,pr))
berghofe@13876
   346
				end;
berghofe@13876
   347
berghofe@13876
   348
	
berghofe@13876
   349
(* ------------------------------------------------------------------------- *)
berghofe@13876
   350
(*Help function for the generation of the proof EX.P_{minus \infty} --> EX. P(x) *)
berghofe@13876
   351
(* ------------------------------------------------------------------------- *)
berghofe@13876
   352
fun minusinf_wph x fm = let fun mk_atomar_minusinf_proof x fm = (Modd_minf(x,fm),Eq_minf(x,fm))
berghofe@13876
   353
  
berghofe@13876
   354
	      fun combine_minusinf_proofs opr (ppr1,ppr2) (qpr1,qpr2) = case opr of 
berghofe@13876
   355
		 "CJ" => (Modd_minf_conjI(ppr1,qpr1),Eq_minf_conjI(ppr2,qpr2))
berghofe@13876
   356
		|"DJ" => (Modd_minf_disjI(ppr1,qpr1),Eq_minf_disjI(ppr2,qpr2))
berghofe@13876
   357
	in 
berghofe@13876
   358
 
berghofe@13876
   359
 case fm of 
berghofe@13876
   360
 (Const ("Not", _) $  (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
berghofe@13876
   361
     if (x=y) andalso (c1= zero) andalso (c2= one) then (HOLogic.true_const ,(mk_atomar_minusinf_proof x fm))
berghofe@13876
   362
        else (fm ,(mk_atomar_minusinf_proof x fm))
berghofe@13876
   363
 |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
berghofe@13876
   364
  	 if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one)
berghofe@13876
   365
	 then (HOLogic.false_const ,(mk_atomar_minusinf_proof x fm))
berghofe@13876
   366
	 				 else (fm,(mk_atomar_minusinf_proof x fm)) 
berghofe@13876
   367
 |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y ) $ z )) =>
berghofe@13876
   368
       if (y=x) andalso (c1 = zero) then 
berghofe@13876
   369
        if c2 = one then (HOLogic.false_const,(mk_atomar_minusinf_proof x fm)) else
berghofe@13876
   370
	(HOLogic.true_const,(mk_atomar_minusinf_proof x fm))
berghofe@13876
   371
	else (fm,(mk_atomar_minusinf_proof x fm))
berghofe@13876
   372
  
berghofe@13876
   373
  |(Const("Not",_)$(Const ("Divides.op dvd",_) $_ )) => (fm,mk_atomar_minusinf_proof x fm)
berghofe@13876
   374
  
berghofe@13876
   375
  |(Const ("Divides.op dvd",_) $_ ) => (fm,mk_atomar_minusinf_proof x fm)
berghofe@13876
   376
  
berghofe@13876
   377
  |(Const ("op &",_) $ p $ q) => let val (pfm,ppr) = minusinf_wph x p
berghofe@13876
   378
  				    val (qfm,qpr) = minusinf_wph x q
berghofe@13876
   379
				    val pr = (combine_minusinf_proofs "CJ" ppr qpr)
berghofe@13876
   380
				     in 
berghofe@13876
   381
				     (HOLogic.conj $ pfm $qfm , pr)
berghofe@13876
   382
				     end 
berghofe@13876
   383
  |(Const ("op |",_) $ p $ q) => let val (pfm,ppr) = minusinf_wph x p
berghofe@13876
   384
  				     val (qfm,qpr) = minusinf_wph x q
berghofe@13876
   385
				     val pr = (combine_minusinf_proofs "DJ" ppr qpr)
berghofe@13876
   386
				     in 
berghofe@13876
   387
				     (HOLogic.disj $ pfm $qfm , pr)
berghofe@13876
   388
				     end 
berghofe@13876
   389
berghofe@13876
   390
  |_ => (fm,(mk_atomar_minusinf_proof x fm))
berghofe@13876
   391
  
berghofe@13876
   392
  end;					 
berghofe@13876
   393
(* ------------------------------------------------------------------------- *)	    (* Protokol for the Proof of the property of the minusinfinity formula*)
berghofe@13876
   394
(* Just combines the to protokols *)
berghofe@13876
   395
(* ------------------------------------------------------------------------- *)
berghofe@13876
   396
fun minusinf_wp x fm  = let val (fm2,pr) = (minusinf_wph x fm)
berghofe@13876
   397
                       in (fm2,Minusinf(pr))
berghofe@13876
   398
                        end;
berghofe@13876
   399
berghofe@13876
   400
(* ------------------------------------------------------------------------- *)
berghofe@13876
   401
(*Help function for the generation of the proof EX.P_{plus \infty} --> EX. P(x) *)
berghofe@13876
   402
(* ------------------------------------------------------------------------- *)
berghofe@13876
   403
berghofe@13876
   404
fun plusinf_wph x fm = let fun mk_atomar_plusinf_proof x fm = (Modd_minf(x,fm),Eq_minf(x,fm))
berghofe@13876
   405
  
berghofe@13876
   406
	      fun combine_plusinf_proofs opr (ppr1,ppr2) (qpr1,qpr2) = case opr of 
berghofe@13876
   407
		 "CJ" => (Modd_minf_conjI(ppr1,qpr1),Eq_minf_conjI(ppr2,qpr2))
berghofe@13876
   408
		|"DJ" => (Modd_minf_disjI(ppr1,qpr1),Eq_minf_disjI(ppr2,qpr2))
berghofe@13876
   409
	in 
berghofe@13876
   410
 
berghofe@13876
   411
 case fm of 
berghofe@13876
   412
 (Const ("Not", _) $  (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
berghofe@13876
   413
     if (x=y) andalso (c1= zero) andalso (c2= one) then (HOLogic.true_const ,(mk_atomar_plusinf_proof x fm))
berghofe@13876
   414
        else (fm ,(mk_atomar_plusinf_proof x fm))
berghofe@13876
   415
 |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
berghofe@13876
   416
  	 if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one)
berghofe@13876
   417
	 then (HOLogic.false_const ,(mk_atomar_plusinf_proof x fm))
berghofe@13876
   418
	 				 else (fm,(mk_atomar_plusinf_proof x fm)) 
berghofe@13876
   419
 |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y ) $ z )) =>
berghofe@13876
   420
       if (y=x) andalso (c1 = zero) then 
berghofe@13876
   421
        if c2 = one then (HOLogic.true_const,(mk_atomar_plusinf_proof x fm)) else
berghofe@13876
   422
	(HOLogic.false_const,(mk_atomar_plusinf_proof x fm))
berghofe@13876
   423
	else (fm,(mk_atomar_plusinf_proof x fm))
berghofe@13876
   424
  
berghofe@13876
   425
  |(Const("Not",_)$(Const ("Divides.op dvd",_) $_ )) => (fm,mk_atomar_plusinf_proof x fm)
berghofe@13876
   426
  
berghofe@13876
   427
  |(Const ("Divides.op dvd",_) $_ ) => (fm,mk_atomar_plusinf_proof x fm)
berghofe@13876
   428
  
berghofe@13876
   429
  |(Const ("op &",_) $ p $ q) => let val (pfm,ppr) = plusinf_wph x p
berghofe@13876
   430
  				    val (qfm,qpr) = plusinf_wph x q
berghofe@13876
   431
				    val pr = (combine_plusinf_proofs "CJ" ppr qpr)
berghofe@13876
   432
				     in 
berghofe@13876
   433
				     (HOLogic.conj $ pfm $qfm , pr)
berghofe@13876
   434
				     end 
berghofe@13876
   435
  |(Const ("op |",_) $ p $ q) => let val (pfm,ppr) = plusinf_wph x p
berghofe@13876
   436
  				     val (qfm,qpr) = plusinf_wph x q
berghofe@13876
   437
				     val pr = (combine_plusinf_proofs "DJ" ppr qpr)
berghofe@13876
   438
				     in 
berghofe@13876
   439
				     (HOLogic.disj $ pfm $qfm , pr)
berghofe@13876
   440
				     end 
berghofe@13876
   441
berghofe@13876
   442
  |_ => (fm,(mk_atomar_plusinf_proof x fm))
berghofe@13876
   443
  
berghofe@13876
   444
  end;					 
berghofe@13876
   445
(* ------------------------------------------------------------------------- *)	    (* Protokol for the Proof of the property of the minusinfinity formula*)
berghofe@13876
   446
(* Just combines the to protokols *)
berghofe@13876
   447
(* ------------------------------------------------------------------------- *)
berghofe@13876
   448
fun plusinf_wp x fm  = let val (fm2,pr) = (plusinf_wph x fm)
berghofe@13876
   449
                       in (fm2,Minusinf(pr))
berghofe@13876
   450
                        end;
berghofe@13876
   451
berghofe@13876
   452
berghofe@13876
   453
(* ------------------------------------------------------------------------- *)
berghofe@13876
   454
(*Protocol that we here uses Bset.*)
berghofe@13876
   455
(* ------------------------------------------------------------------------- *)
berghofe@13876
   456
fun bset_wp x fm = let val bs = bset x fm in
berghofe@13876
   457
				(bs,Bset(x,fm,bs,mk_numeral (divlcm x fm)))
berghofe@13876
   458
				end;
berghofe@13876
   459
berghofe@13876
   460
(* ------------------------------------------------------------------------- *)
berghofe@13876
   461
(*Protocol that we here uses Aset.*)
berghofe@13876
   462
(* ------------------------------------------------------------------------- *)
berghofe@13876
   463
fun aset_wp x fm = let val ast = aset x fm in
berghofe@13876
   464
				(ast,Aset(x,fm,ast,mk_numeral (divlcm x fm)))
berghofe@13876
   465
				end;
berghofe@13876
   466
 
berghofe@13876
   467
berghofe@13876
   468
berghofe@13876
   469
(* ------------------------------------------------------------------------- *)
berghofe@13876
   470
(*function list to Set, constructs a set containing all elements of a given list.*)
berghofe@13876
   471
(* ------------------------------------------------------------------------- *)
berghofe@13876
   472
fun list_to_set T1 l = let val T = (HOLogic.mk_setT T1) in 
berghofe@13876
   473
	case l of 
berghofe@13876
   474
		[] => Const ("{}",T)
berghofe@13876
   475
		|(h::t) => Const("insert", T1 --> (T --> T)) $ h $(list_to_set T1 t)
berghofe@13876
   476
		end;
berghofe@13876
   477
		
berghofe@13876
   478
berghofe@13876
   479
(*====================================================================*)
berghofe@13876
   480
(* ------------------------------------------------------------------------- *)
berghofe@13876
   481
(* ------------------------------------------------------------------------- *)
berghofe@13876
   482
(*Protocol for the proof of the backward direction of the cooper theorem.*)
berghofe@13876
   483
(* Helpfunction - Protokols evereything about the proof reconstruction*)
berghofe@13876
   484
(* ------------------------------------------------------------------------- *)
berghofe@13876
   485
fun not_bst_p_wph fm = case fm of
berghofe@13876
   486
	Const("Not",_) $ R => if (is_arith_rel R) then (Not_bst_p_atomic (fm)) else CpLogError
berghofe@13876
   487
	|Const("op &",_) $ ls $ rs => Not_bst_p_conjI((not_bst_p_wph ls),(not_bst_p_wph rs))
berghofe@13876
   488
	|Const("op |",_) $ ls $ rs => Not_bst_p_disjI((not_bst_p_wph ls),(not_bst_p_wph rs))
berghofe@13876
   489
	|_ => Not_bst_p_atomic (fm);
berghofe@13876
   490
(* ------------------------------------------------------------------------- *)	
berghofe@13876
   491
(* 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*)
berghofe@13876
   492
(* ------------------------------------------------------------------------- *)
berghofe@13876
   493
fun not_bst_p_wp x fm = let val prt = not_bst_p_wph fm
berghofe@13876
   494
			    val D = mk_numeral (divlcm x fm)
berghofe@13876
   495
			    val B = map norm_zero_one (bset x fm)
berghofe@13876
   496
			in (Not_bst_p (x,fm,D,(list_to_set HOLogic.intT B) , prt))
berghofe@13876
   497
			end;
berghofe@13876
   498
(*====================================================================*)
berghofe@13876
   499
(* ------------------------------------------------------------------------- *)
berghofe@13876
   500
(* ------------------------------------------------------------------------- *)
berghofe@13876
   501
(*Protocol for the proof of the backward direction of the cooper theorem.*)
berghofe@13876
   502
(* Helpfunction - Protokols evereything about the proof reconstruction*)
berghofe@13876
   503
(* ------------------------------------------------------------------------- *)
berghofe@13876
   504
fun not_ast_p_wph fm = case fm of
berghofe@13876
   505
	Const("Not",_) $ R => if (is_arith_rel R) then (Not_ast_p_atomic (fm)) else CpLogError
berghofe@13876
   506
	|Const("op &",_) $ ls $ rs => Not_ast_p_conjI((not_ast_p_wph ls),(not_ast_p_wph rs))
berghofe@13876
   507
	|Const("op |",_) $ ls $ rs => Not_ast_p_disjI((not_ast_p_wph ls),(not_ast_p_wph rs))
berghofe@13876
   508
	|_ => Not_ast_p_atomic (fm);
berghofe@13876
   509
(* ------------------------------------------------------------------------- *)	
berghofe@13876
   510
(* 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*)
berghofe@13876
   511
(* ------------------------------------------------------------------------- *)
berghofe@13876
   512
fun not_ast_p_wp x fm = let val prt = not_ast_p_wph fm
berghofe@13876
   513
			    val D = mk_numeral (divlcm x fm)
berghofe@13876
   514
			    val B = map norm_zero_one (aset x fm)
berghofe@13876
   515
			in (Not_ast_p (x,fm,D,(list_to_set HOLogic.intT B) , prt))
berghofe@13876
   516
			end;
berghofe@13876
   517
berghofe@13876
   518
(*======================================================*)
berghofe@13876
   519
(* Protokolgeneration for the formula evaluation process*)
berghofe@13876
   520
(*======================================================*)
berghofe@13876
   521
berghofe@13876
   522
fun evalc_wp fm = 
berghofe@13876
   523
  let fun evalc_atom_wp at =case at of  
berghofe@13876
   524
    (Const (p,_) $ s $ t) =>(  
berghofe@13876
   525
    case assoc (operations,p) of 
berghofe@13876
   526
        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)))  
berghofe@13876
   527
		   handle _ => Evalfm(at)) 
berghofe@13876
   528
        | _ =>  Evalfm(at)) 
berghofe@13876
   529
     |Const("Not",_)$(Const (p,_) $ s $ t) =>(  
berghofe@13876
   530
       case assoc (operations,p) of 
berghofe@13876
   531
         Some f => ((if (f ((dest_numeral s),(dest_numeral t))) then 
berghofe@13876
   532
	  EvalAt(HOLogic.mk_eq(at, HOLogic.false_const))  else EvalAt(HOLogic.mk_eq(at,HOLogic.true_const)))  
berghofe@13876
   533
		      handle _ => Evalfm(at)) 
berghofe@13876
   534
         | _ => Evalfm(at)) 
berghofe@13876
   535
     | _ => Evalfm(at)  
berghofe@13876
   536
 
berghofe@13876
   537
  in
berghofe@13876
   538
   case fm of
berghofe@13876
   539
    (Const("op &",_)$A$B) => EvalConst("CJ",evalc_wp A,evalc_wp B)
berghofe@13876
   540
   |(Const("op |",_)$A$B) => EvalConst("DJ",evalc_wp A,evalc_wp B) 
berghofe@13876
   541
   |(Const("op -->",_)$A$B) => EvalConst("IM",evalc_wp A,evalc_wp B) 
berghofe@13876
   542
   |(Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => EvalConst("EQ",evalc_wp A,evalc_wp B) 
berghofe@13876
   543
   |_ => evalc_atom_wp fm
berghofe@13876
   544
  end;
berghofe@13876
   545
berghofe@13876
   546
berghofe@13876
   547
berghofe@13876
   548
(*======================================================*)
berghofe@13876
   549
(* Protokolgeneration for the NNF Transformation        *)
berghofe@13876
   550
(*======================================================*)
berghofe@13876
   551
berghofe@13876
   552
fun cnnf_wp f = 
berghofe@13876
   553
  let fun hcnnf_wp fm =
berghofe@13876
   554
    case fm of
berghofe@13876
   555
    (Const ("op &",_) $ p $ q) => NNFConst("CJ",hcnnf_wp p,hcnnf_wp q) 
berghofe@13876
   556
    | (Const ("op |",_) $ p $ q) =>  NNFConst("DJ",hcnnf_wp p,hcnnf_wp q)
berghofe@13876
   557
    | (Const ("op -->",_) $ p $q) => NNFConst("IM",hcnnf_wp (HOLogic.Not $ p),hcnnf_wp q)
berghofe@13876
   558
    | (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)))) 
berghofe@13876
   559
berghofe@13876
   560
    | (Const ("Not",_) $ (Const("Not",_) $ p)) => NNFNN(hcnnf_wp p) 
berghofe@13876
   561
    | (Const ("Not",_) $ (Const ("op &",_) $ p $ q)) => NNFConst ("NCJ",(hcnnf_wp(HOLogic.Not $ p)),(hcnnf_wp(HOLogic.Not $ q))) 
berghofe@13876
   562
    | (Const ("Not",_) $(Const ("op |",_) $ (A as (Const ("op &",_) $ p $ q)) $  
berghofe@13876
   563
    			(B as (Const ("op &",_) $ p1 $ r)))) => if p1 = negate p then 
berghofe@13876
   564
		         NNFConst("SDJ",  
berghofe@13876
   565
			   NNFConst("CJ",hcnnf_wp p,hcnnf_wp(HOLogic.Not $ q)),
berghofe@13876
   566
			   NNFConst("CJ",hcnnf_wp p1,hcnnf_wp(HOLogic.Not $ r)))
berghofe@13876
   567
			 else  NNFConst ("NDJ",(hcnnf_wp(HOLogic.Not $ A)),(hcnnf_wp(HOLogic.Not $ B))) 
berghofe@13876
   568
berghofe@13876
   569
    | (Const ("Not",_) $ (Const ("op |",_) $ p $ q)) => NNFConst ("NDJ",(hcnnf_wp(HOLogic.Not $ p)),(hcnnf_wp(HOLogic.Not $ q))) 
berghofe@13876
   570
    | (Const ("Not",_) $ (Const ("op -->",_) $ p $q)) =>  NNFConst ("NIM",(hcnnf_wp(p)),(hcnnf_wp(HOLogic.Not $ q))) 
berghofe@13876
   571
    | (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))) 
berghofe@13876
   572
    | _ => NNFAt(fm)  
berghofe@13876
   573
  in NNFSimp(hcnnf_wp f)
berghofe@13876
   574
end; 
berghofe@13876
   575
   
berghofe@13876
   576
berghofe@13876
   577
berghofe@13876
   578
berghofe@13876
   579
berghofe@13876
   580
berghofe@13876
   581
(* ------------------------------------------------------------------------- *)
berghofe@13876
   582
(*Cooper decision Procedure with proof protocoling*)
berghofe@13876
   583
(* ------------------------------------------------------------------------- *)
berghofe@13876
   584
berghofe@13876
   585
fun coopermi_wp vars fm =
berghofe@13876
   586
  case fm of
berghofe@13876
   587
   Const ("Ex",_) $ Abs(xo,T,po) => let 
berghofe@13876
   588
    val (xn,np) = variant_abs(xo,T,po) 
berghofe@13876
   589
    val x = (Free(xn , T))
berghofe@13876
   590
    val p = np     (* Is this a legal proof for the P=NP Problem??*)
berghofe@13876
   591
    val (p_inf,miprt) = simpl_wp (minusinf_wp x p)
berghofe@13876
   592
    val (bset,bsprt) = bset_wp x p
berghofe@13876
   593
    val nbst_p_prt = not_bst_p_wp x p
berghofe@13876
   594
    val dlcm = divlcm x p 
berghofe@13876
   595
    val js = 1 upto dlcm 
berghofe@13876
   596
    fun p_element j b = linrep vars x (linear_add vars b (mk_numeral j)) p 
berghofe@13876
   597
    fun stage j = list_disj (linrep vars x (mk_numeral j) p_inf :: map (p_element j) bset) 
berghofe@13876
   598
   in (list_disj (map stage js),Cooper(mk_numeral dlcm,miprt,bsprt,nbst_p_prt))
berghofe@13876
   599
   end
berghofe@13876
   600
   
berghofe@13876
   601
  | _ => (error "cooper: not an existential formula",No);
berghofe@13876
   602
				
berghofe@13876
   603
fun cooperpi_wp vars fm =
berghofe@13876
   604
  case fm of
berghofe@13876
   605
   Const ("Ex",_) $ Abs(xo,T,po) => let 
berghofe@13876
   606
    val (xn,np) = variant_abs(xo,T,po) 
berghofe@13876
   607
    val x = (Free(xn , T))
berghofe@13876
   608
    val p = np     (* Is this a legal proof for the P=NP Problem??*)
berghofe@13876
   609
    val (p_inf,piprt) = simpl_wp (plusinf_wp x p)
berghofe@13876
   610
    val (aset,asprt) = aset_wp x p
berghofe@13876
   611
    val nast_p_prt = not_ast_p_wp x p
berghofe@13876
   612
    val dlcm = divlcm x p 
berghofe@13876
   613
    val js = 1 upto dlcm 
berghofe@13876
   614
    fun p_element j a = linrep vars x (linear_sub vars a (mk_numeral j)) p 
berghofe@13876
   615
    fun stage j = list_disj (linrep vars x (mk_numeral j) p_inf :: map (p_element j) aset) 
berghofe@13876
   616
   in (list_disj (map stage js),Cooper(mk_numeral dlcm,piprt,asprt,nast_p_prt))
berghofe@13876
   617
   end
berghofe@13876
   618
  | _ => (error "cooper: not an existential formula",No);
berghofe@13876
   619
				
berghofe@13876
   620
berghofe@13876
   621
berghofe@13876
   622
berghofe@13876
   623
berghofe@13876
   624
(*-----------------------------------------------------------------*)
berghofe@13876
   625
(*-----------------------------------------------------------------*)
berghofe@13876
   626
(*-----------------------------------------------------------------*)
berghofe@13876
   627
(*---                                                           ---*)
berghofe@13876
   628
(*---                                                           ---*)
berghofe@13876
   629
(*---      Interpretation and Proofgeneration Part              ---*)
berghofe@13876
   630
(*---                                                           ---*)
berghofe@13876
   631
(*---      Protocole interpretation functions                   ---*)
berghofe@13876
   632
(*---                                                           ---*)
berghofe@13876
   633
(*---      and proofgeneration functions                        ---*)
berghofe@13876
   634
(*---                                                           ---*)
berghofe@13876
   635
(*---                                                           ---*)
berghofe@13876
   636
(*---                                                           ---*)
berghofe@13876
   637
(*---                                                           ---*)
berghofe@13876
   638
(*-----------------------------------------------------------------*)
berghofe@13876
   639
(*-----------------------------------------------------------------*)
berghofe@13876
   640
(*-----------------------------------------------------------------*)
berghofe@13876
   641
berghofe@13876
   642
(* ------------------------------------------------------------------------- *)
berghofe@13876
   643
(* Returns both sides of an equvalence in the theorem*)
berghofe@13876
   644
(* ------------------------------------------------------------------------- *)
berghofe@13876
   645
fun qe_get_terms th = let val (_$(Const("op =",Type ("fun",[Type ("bool", []),_])) $ A $ B )) = prop_of th in (A,B) end;
berghofe@13876
   646
berghofe@13876
   647
berghofe@13876
   648
(*-------------------------------------------------------------*)
berghofe@13876
   649
(*-------------------------------------------------------------*)
berghofe@13876
   650
(*-------------------------------------------------------------*)
berghofe@13876
   651
(*-------------------------------------------------------------*)
berghofe@13876
   652
berghofe@13876
   653
(* ------------------------------------------------------------------------- *)
berghofe@13876
   654
(* Modified version of the simple version with minimal amount of checking and postprocessing*)
berghofe@13876
   655
(* ------------------------------------------------------------------------- *)
berghofe@13876
   656
berghofe@13876
   657
fun simple_prove_goal_cterm2 G tacs =
berghofe@13876
   658
  let
berghofe@13876
   659
    fun check None = error "prove_goal: tactic failed"
berghofe@13876
   660
      | check (Some (thm, _)) = (case nprems_of thm of
berghofe@13876
   661
            0 => thm
berghofe@13876
   662
          | i => !result_error_fn thm (string_of_int i ^ " unsolved goals!"))
berghofe@13876
   663
  in check (Seq.pull (EVERY tacs (trivial G))) end;
berghofe@13876
   664
berghofe@13876
   665
(*-------------------------------------------------------------*)
berghofe@13876
   666
(*-------------------------------------------------------------*)
berghofe@13876
   667
(*-------------------------------------------------------------*)
berghofe@13876
   668
(*-------------------------------------------------------------*)
berghofe@13876
   669
(*-------------------------------------------------------------*)
berghofe@13876
   670
berghofe@13876
   671
fun cert_Trueprop sg t = cterm_of sg (HOLogic.mk_Trueprop t);
berghofe@13876
   672
berghofe@13876
   673
(* ------------------------------------------------------------------------- *)
berghofe@13876
   674
(*This function proove elementar will be used to generate proofs at runtime*)
berghofe@13876
   675
(*It is is based on the isabelle function proove_goalw_cterm and is thought to *)
berghofe@13876
   676
(*prove properties such as a dvd b (essentially) that are only to make at
berghofe@13876
   677
runtime.*)
berghofe@13876
   678
(* ------------------------------------------------------------------------- *)
berghofe@13876
   679
fun prove_elementar sg s fm2 = case s of 
berghofe@13876
   680
  (*"ss" like simplification with simpset*)
berghofe@13876
   681
  "ss" =>
berghofe@13876
   682
    let
nipkow@14139
   683
      val ss = presburger_ss addsimps [zdvd_iff_zmod_eq_0]
berghofe@13876
   684
      val ct =  cert_Trueprop sg fm2
berghofe@13876
   685
    in 
berghofe@13876
   686
      simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
berghofe@13876
   687
    end
berghofe@13876
   688
berghofe@13876
   689
  (*"bl" like blast tactic*)
berghofe@13876
   690
  (* Is only used in the harrisons like proof procedure *)
berghofe@13876
   691
  | "bl" =>
berghofe@13876
   692
     let val ct = cert_Trueprop sg fm2
berghofe@13876
   693
     in
berghofe@13876
   694
       simple_prove_goal_cterm2 ct [blast_tac HOL_cs 1]
berghofe@13876
   695
     end
berghofe@13876
   696
berghofe@13876
   697
  (*"ed" like Existence disjunctions ...*)
berghofe@13876
   698
  (* Is only used in the harrisons like proof procedure *)
berghofe@13876
   699
  | "ed" =>
berghofe@13876
   700
    let
berghofe@13876
   701
      val ex_disj_tacs =
berghofe@13876
   702
        let
berghofe@13876
   703
          val tac1 = EVERY[REPEAT(resolve_tac [disjI1,disjI2] 1), etac exI 1]
berghofe@13876
   704
          val tac2 = EVERY[etac exE 1, rtac exI 1,
berghofe@13876
   705
            REPEAT(resolve_tac [disjI1,disjI2] 1), assumption 1]
berghofe@13876
   706
	in [rtac iffI 1,
berghofe@13876
   707
          etac exE 1, REPEAT(EVERY[etac disjE 1, tac1]), tac1,
berghofe@13876
   708
          REPEAT(EVERY[etac disjE 1, tac2]), tac2]
berghofe@13876
   709
        end
berghofe@13876
   710
berghofe@13876
   711
      val ct = cert_Trueprop sg fm2
berghofe@13876
   712
    in 
berghofe@13876
   713
      simple_prove_goal_cterm2 ct ex_disj_tacs
berghofe@13876
   714
    end
berghofe@13876
   715
berghofe@13876
   716
  | "fa" =>
berghofe@13876
   717
    let val ct = cert_Trueprop sg fm2
berghofe@13876
   718
    in simple_prove_goal_cterm2 ct [simple_arith_tac 1]
berghofe@13876
   719
    end
berghofe@13876
   720
berghofe@13876
   721
  | "sa" =>
berghofe@13876
   722
    let
berghofe@13876
   723
      val ss = presburger_ss addsimps zadd_ac
berghofe@13876
   724
      val ct = cert_Trueprop sg fm2
berghofe@13876
   725
    in 
berghofe@13876
   726
      simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
berghofe@13876
   727
    end
berghofe@13876
   728
berghofe@13876
   729
  | "ac" =>
berghofe@13876
   730
    let
berghofe@13876
   731
      val ss = HOL_basic_ss addsimps zadd_ac
berghofe@13876
   732
      val ct = cert_Trueprop sg fm2
berghofe@13876
   733
    in 
berghofe@13876
   734
      simple_prove_goal_cterm2 ct [simp_tac ss 1]
berghofe@13876
   735
    end
berghofe@13876
   736
berghofe@13876
   737
  | "lf" =>
berghofe@13876
   738
    let
berghofe@13876
   739
      val ss = presburger_ss addsimps zadd_ac
berghofe@13876
   740
      val ct = cert_Trueprop sg fm2
berghofe@13876
   741
    in 
berghofe@13876
   742
      simple_prove_goal_cterm2 ct [simp_tac ss 1, TRY (simple_arith_tac 1)]
berghofe@13876
   743
    end;
berghofe@13876
   744
berghofe@13876
   745
berghofe@13876
   746
berghofe@13876
   747
(* ------------------------------------------------------------------------- *)
berghofe@13876
   748
(* This function return an Isabelle proof, of the adjustcoffeq result.*)
berghofe@13876
   749
(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
berghofe@13876
   750
(* ------------------------------------------------------------------------- *)
berghofe@13876
   751
fun proof_of_adjustcoeffeq sg (prt,rs) = case prt of
berghofe@13876
   752
   ACfm fm => instantiate' [Some cboolT]
berghofe@13876
   753
    [Some (cterm_of sg fm)] refl
berghofe@13876
   754
 | ACAt (k,at as (Const(p,_) $a $( Const ("op +", _)$(Const ("op *",_) $ 
berghofe@13876
   755
      c $ x ) $t ))) => 
berghofe@13876
   756
   let
berghofe@13876
   757
     val ck = cterm_of sg (mk_numeral k)
berghofe@13876
   758
     val cc = cterm_of sg c
berghofe@13876
   759
     val ct = cterm_of sg t
berghofe@13876
   760
     val cx = cterm_of sg x
berghofe@13876
   761
     val ca = cterm_of sg a
berghofe@13876
   762
   in case p of
berghofe@13905
   763
     "op <" => let val pre = prove_elementar sg "lf" 
berghofe@13876
   764
	                  (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
berghofe@13876
   765
	           val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_lt_eq)))
berghofe@13905
   766
		      in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
berghofe@13876
   767
                   end
berghofe@13905
   768
    |"op =" =>let val pre = prove_elementar sg "lf" 
berghofe@13876
   769
	    (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k))))
berghofe@13876
   770
	          in let val th1 = (pre RS(instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct] (ac_eq_eq)))
berghofe@13905
   771
	             in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
berghofe@13876
   772
                      end
berghofe@13876
   773
                  end
berghofe@13905
   774
    |"Divides.op dvd" =>let val pre = prove_elementar sg "lf" 
berghofe@13876
   775
	   (HOLogic.Not $ (HOLogic.mk_binrel "op =" (Const("0",HOLogic.intT),(mk_numeral k))))
berghofe@13876
   776
	                 val th1 = (pre RS (instantiate' [] [Some ck,Some ca,Some cc, Some cx, Some ct]) (ac_dvd_eq))
berghofe@13905
   777
                         in [th1,(prove_elementar sg "lf" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
berghofe@13876
   778
                        
berghofe@13876
   779
                          end
berghofe@13876
   780
  end
berghofe@13876
   781
 |ACPI(k,at as (Const("Not",_)$(Const("op <",_) $a $( Const ("op +", _)$(Const ("op *",_) $ c $ x ) $t )))) => 
berghofe@13876
   782
   let
berghofe@13876
   783
     val ck = cterm_of sg (mk_numeral k)
berghofe@13876
   784
     val cc = cterm_of sg c
berghofe@13876
   785
     val ct = cterm_of sg t
berghofe@13876
   786
     val cx = cterm_of sg x
berghofe@13905
   787
     val pre = prove_elementar sg "lf" 
berghofe@13876
   788
       (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),(mk_numeral k)))
berghofe@13876
   789
       val th1 = (pre RS (instantiate' [] [Some ck,Some cc, Some cx, Some ct] (ac_pi_eq)))
berghofe@13876
   790
berghofe@13876
   791
         in [th1,(prove_elementar sg "sa" (HOLogic.mk_eq (snd (qe_get_terms th1) ,rs)))] MRS trans
berghofe@13876
   792
   end
berghofe@13876
   793
 |ACNeg(pr) => let val (Const("Not",_)$nrs) = rs
berghofe@13876
   794
               in (proof_of_adjustcoeffeq sg (pr,nrs)) RS (qe_Not) 
berghofe@13876
   795
               end
berghofe@13876
   796
 |ACConst(s,pr1,pr2) =>
berghofe@13876
   797
   let val (Const(_,_)$rs1$rs2) = rs
berghofe@13876
   798
       val th1 = proof_of_adjustcoeffeq sg (pr1,rs1)
berghofe@13876
   799
       val th2 = proof_of_adjustcoeffeq sg (pr2,rs2)
berghofe@13876
   800
       in case s of 
berghofe@13876
   801
	 "CJ" => [th1,th2] MRS (qe_conjI)
berghofe@13876
   802
         |"DJ" => [th1,th2] MRS (qe_disjI)
berghofe@13876
   803
         |"IM" => [th1,th2] MRS (qe_impI)
berghofe@13876
   804
         |"EQ" => [th1,th2] MRS (qe_eqI)
berghofe@13876
   805
   end;
berghofe@13876
   806
berghofe@13876
   807
berghofe@13876
   808
berghofe@13876
   809
berghofe@13876
   810
berghofe@13876
   811
berghofe@13876
   812
(* ------------------------------------------------------------------------- *)
berghofe@13876
   813
(* This function return an Isabelle proof, of some properties on the atoms*)
berghofe@13876
   814
(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
berghofe@13876
   815
(* This function doese only instantiate the the theorems in the theory *)
berghofe@13876
   816
(* ------------------------------------------------------------------------- *)
berghofe@13876
   817
fun atomar_minf_proof_of sg dlcm (Modd_minf (x,fm1)) =
berghofe@13876
   818
  let
berghofe@13876
   819
    (*Some certified Terms*)
berghofe@13876
   820
    
berghofe@13876
   821
   val ctrue = cterm_of sg HOLogic.true_const
berghofe@13876
   822
   val cfalse = cterm_of sg HOLogic.false_const
berghofe@13876
   823
   val fm = norm_zero_one fm1
berghofe@13876
   824
  in  case fm1 of 
berghofe@13876
   825
      (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
berghofe@13876
   826
         if (x=y) andalso (c1= zero) andalso (c2= one) then (instantiate' [Some cboolT] [Some ctrue] (fm_modd_minf))
berghofe@13876
   827
           else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_minf))
berghofe@13876
   828
berghofe@13876
   829
      |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
berghofe@13876
   830
  	   if (is_arith_rel fm) andalso (x=y) andalso (c1= zero) andalso (c2= one) 
berghofe@13876
   831
	   then (instantiate' [Some cboolT] [Some cfalse] (fm_modd_minf))
berghofe@13876
   832
	 	 else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_minf)) 
berghofe@13876
   833
berghofe@13876
   834
      |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
berghofe@13876
   835
           if (y=x) andalso (c1 = zero) then 
berghofe@13876
   836
            if (pm1 = one) then (instantiate' [Some cboolT] [Some cfalse] (fm_modd_minf)) else
berghofe@13876
   837
	     (instantiate' [Some cboolT] [Some ctrue] (fm_modd_minf))
berghofe@13876
   838
	    else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_minf))
berghofe@13876
   839
  
berghofe@13876
   840
      |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
   841
         if y=x then  let val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
   842
			  val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero)
berghofe@13876
   843
	 	      in(instantiate' [] [Some cz ] ((((prove_elementar sg "ss" fm2)) RS(((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (not_dvd_modd_minf)))
berghofe@13876
   844
		      end
berghofe@13876
   845
		else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_minf))
berghofe@13876
   846
      |(Const("Divides.op dvd",_)$ d $ (db as (Const ("op +",_) $ (Const ("op *",_) $
berghofe@13876
   847
      c $ y ) $ z))) => 
berghofe@13876
   848
         if y=x then  let val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
   849
			  val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero)
berghofe@13876
   850
	 	      in(instantiate' [] [Some cz ] ((((prove_elementar sg "ss" fm2)) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (dvd_modd_minf)))
berghofe@13876
   851
		      end
berghofe@13876
   852
		else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_minf))
berghofe@13876
   853
		
berghofe@13876
   854
    
berghofe@13876
   855
   |_ => instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_minf)
berghofe@13876
   856
   end	
berghofe@13876
   857
berghofe@13876
   858
 |atomar_minf_proof_of sg dlcm (Eq_minf (x,fm1)) =  let
berghofe@13876
   859
       (*Some certified types*)
berghofe@13876
   860
   val fm = norm_zero_one fm1
berghofe@13876
   861
    in  case fm1 of 
berghofe@13876
   862
      (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
berghofe@13876
   863
         if  (x=y) andalso (c1=zero) andalso (c2=one) 
berghofe@13876
   864
	   then (instantiate' [] [Some (cterm_of sg (norm_zero_one z))] (neq_eq_minf))
berghofe@13876
   865
           else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_minf))
berghofe@13876
   866
berghofe@13876
   867
      |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
berghofe@13876
   868
  	   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))
berghofe@13876
   869
	     then (instantiate' [] [Some (cterm_of sg (norm_zero_one z))] (eq_eq_minf))
berghofe@13876
   870
	     else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_minf)) 
berghofe@13876
   871
berghofe@13876
   872
      |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
berghofe@13876
   873
           if (y=x) andalso (c1 =zero) then 
berghofe@13876
   874
            if pm1 = one then (instantiate' [] [Some (cterm_of sg (norm_zero_one z))] (le_eq_minf)) else
berghofe@13876
   875
	     (instantiate' [] [Some (cterm_of sg (norm_zero_one z))] (len_eq_minf))
berghofe@13876
   876
	    else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_minf))
berghofe@13876
   877
      |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
   878
         if y=x then  let val cd = cterm_of sg (norm_zero_one d)
berghofe@13876
   879
	 		  val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
   880
	 	      in(instantiate' [] [Some cd,  Some cz] (not_dvd_eq_minf)) 
berghofe@13876
   881
		      end
berghofe@13876
   882
berghofe@13876
   883
		else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_minf))
berghofe@13876
   884
		
berghofe@13876
   885
      |(Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
   886
         if y=x then  let val cd = cterm_of sg (norm_zero_one d)
berghofe@13876
   887
	 		  val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
   888
	 	      in(instantiate' [] [Some cd, Some cz ] (dvd_eq_minf))
berghofe@13876
   889
		      end
berghofe@13876
   890
		else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_minf))
berghofe@13876
   891
berghofe@13876
   892
      		
berghofe@13876
   893
    |_ => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_minf))
berghofe@13876
   894
 end;
berghofe@13876
   895
berghofe@13876
   896
berghofe@13876
   897
(* ------------------------------------------------------------------------- *)
berghofe@13876
   898
(* This function combines proofs of some special form already synthetised from the subtrees to make*)
berghofe@13876
   899
(* a new proof of the same form. The combination occures whith isabelle theorems which have been already prooved *)
berghofe@13876
   900
(*these Theorems are in Presburger.thy and mostly do not relay on the arithmetic.*)
berghofe@13876
   901
(* These are Theorems for the Property of P_{-infty}*)
berghofe@13876
   902
(* ------------------------------------------------------------------------- *)
berghofe@13876
   903
fun combine_minf_proof s pr1 pr2 = case s of
berghofe@13876
   904
    "ECJ" => [pr1 , pr2] MRS (eq_minf_conjI)
berghofe@13876
   905
berghofe@13876
   906
   |"EDJ" => [pr1 , pr2] MRS (eq_minf_disjI)
berghofe@13876
   907
   
berghofe@13876
   908
   |"MCJ" => [pr1 , pr2] MRS (modd_minf_conjI)
berghofe@13876
   909
berghofe@13876
   910
   |"MDJ" => [pr1 , pr2] MRS (modd_minf_disjI);
berghofe@13876
   911
berghofe@13876
   912
(* ------------------------------------------------------------------------- *)
berghofe@13876
   913
(*This function return an isabelle Proof for the minusinfinity theorem*)
berghofe@13876
   914
(* It interpretates the protool and gives the protokoles property of P_{...} as a theorem*)
berghofe@13876
   915
(* ------------------------------------------------------------------------- *)
berghofe@13876
   916
fun minf_proof_ofh sg dlcm prl = case prl of 
berghofe@13876
   917
berghofe@13876
   918
    Eq_minf (_) => atomar_minf_proof_of sg dlcm prl
berghofe@13876
   919
    
berghofe@13876
   920
   |Modd_minf (_) => atomar_minf_proof_of sg dlcm prl
berghofe@13876
   921
   
berghofe@13876
   922
   |Eq_minf_conjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
berghofe@13876
   923
   				    val pr2 = minf_proof_ofh sg dlcm prl2
berghofe@13876
   924
				 in (combine_minf_proof "ECJ" pr1 pr2)
berghofe@13876
   925
				 end
berghofe@13876
   926
				 
berghofe@13876
   927
   |Eq_minf_disjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
berghofe@13876
   928
   				    val pr2 = minf_proof_ofh sg dlcm prl2
berghofe@13876
   929
				 in (combine_minf_proof "EDJ" pr1 pr2)
berghofe@13876
   930
				 end
berghofe@13876
   931
				 
berghofe@13876
   932
   |Modd_minf_conjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
berghofe@13876
   933
   				    val pr2 = minf_proof_ofh sg dlcm prl2
berghofe@13876
   934
				 in (combine_minf_proof "MCJ" pr1 pr2)
berghofe@13876
   935
				 end
berghofe@13876
   936
				 
berghofe@13876
   937
   |Modd_minf_disjI (prl1,prl2) => let val pr1 = minf_proof_ofh sg dlcm prl1
berghofe@13876
   938
   				    val pr2 = minf_proof_ofh sg dlcm prl2
berghofe@13876
   939
				 in (combine_minf_proof "MDJ" pr1 pr2)
berghofe@13876
   940
				 end;
berghofe@13876
   941
(* ------------------------------------------------------------------------- *)
berghofe@13876
   942
(* Main function For the rest both properies of P_{..} are needed and here both theorems are returned.*)				 
berghofe@13876
   943
(* ------------------------------------------------------------------------- *)
berghofe@13876
   944
fun  minf_proof_of sg dlcm (Minusinf (prl1,prl2))  = 
berghofe@13876
   945
  let val pr1 = minf_proof_ofh sg dlcm prl1
berghofe@13876
   946
      val pr2 = minf_proof_ofh sg dlcm prl2
berghofe@13876
   947
  in (pr1, pr2)
berghofe@13876
   948
end;
berghofe@13876
   949
				 
berghofe@13876
   950
berghofe@13876
   951
berghofe@13876
   952
berghofe@13876
   953
(* ------------------------------------------------------------------------- *)
berghofe@13876
   954
(* This function return an Isabelle proof, of some properties on the atoms*)
berghofe@13876
   955
(* The proofs are in Presburger.thy and are generally based on the arithmetic *)
berghofe@13876
   956
(* This function doese only instantiate the the theorems in the theory *)
berghofe@13876
   957
(* ------------------------------------------------------------------------- *)
berghofe@13876
   958
fun atomar_pinf_proof_of sg dlcm (Modd_minf (x,fm1)) =
berghofe@13876
   959
 let
berghofe@13876
   960
    (*Some certified Terms*)
berghofe@13876
   961
    
berghofe@13876
   962
  val ctrue = cterm_of sg HOLogic.true_const
berghofe@13876
   963
  val cfalse = cterm_of sg HOLogic.false_const
berghofe@13876
   964
  val fm = norm_zero_one fm1
berghofe@13876
   965
 in  case fm1 of 
berghofe@13876
   966
      (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
berghofe@13876
   967
         if ((x=y) andalso (c1= zero) andalso (c2= one))
berghofe@13876
   968
	 then (instantiate' [Some cboolT] [Some ctrue] (fm_modd_pinf))
berghofe@13876
   969
         else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_pinf))
berghofe@13876
   970
berghofe@13876
   971
      |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
berghofe@13876
   972
  	if ((is_arith_rel fm) andalso (x = y) andalso (c1 = zero)  andalso (c2 = one)) 
berghofe@13876
   973
	then (instantiate' [Some cboolT] [Some cfalse] (fm_modd_pinf))
berghofe@13876
   974
	else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_pinf))
berghofe@13876
   975
berghofe@13876
   976
      |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
berghofe@13876
   977
        if ((y=x) andalso (c1 = zero)) then 
berghofe@13876
   978
          if (pm1 = one) 
berghofe@13876
   979
	  then (instantiate' [Some cboolT] [Some ctrue] (fm_modd_pinf)) 
berghofe@13876
   980
	  else (instantiate' [Some cboolT] [Some cfalse] (fm_modd_pinf))
berghofe@13876
   981
	else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_pinf))
berghofe@13876
   982
  
berghofe@13876
   983
      |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
   984
         if y=x then  let val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
   985
			  val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero)
berghofe@13876
   986
	 	      in(instantiate' [] [Some cz ] ((((prove_elementar sg "ss" fm2)) RS(((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (not_dvd_modd_pinf)))
berghofe@13876
   987
		      end
berghofe@13876
   988
		else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_pinf))
berghofe@13876
   989
      |(Const("Divides.op dvd",_)$ d $ (db as (Const ("op +",_) $ (Const ("op *",_) $
berghofe@13876
   990
      c $ y ) $ z))) => 
berghofe@13876
   991
         if y=x then  let val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
   992
			  val fm2 = HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero)
berghofe@13876
   993
	 	      in(instantiate' [] [Some cz ] ((((prove_elementar sg "ss" fm2)) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1) ) RS (dvd_modd_pinf)))
berghofe@13876
   994
		      end
berghofe@13876
   995
		else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_pinf))
berghofe@13876
   996
		
berghofe@13876
   997
    
berghofe@13876
   998
   |_ => instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_modd_pinf)
berghofe@13876
   999
   end	
berghofe@13876
  1000
berghofe@13876
  1001
 |atomar_pinf_proof_of sg dlcm (Eq_minf (x,fm1)) =  let
berghofe@13876
  1002
					val fm = norm_zero_one fm1
berghofe@13876
  1003
    in  case fm1 of 
berghofe@13876
  1004
      (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
berghofe@13876
  1005
         if  (x=y) andalso (c1=zero) andalso (c2=one) 
berghofe@13876
  1006
	   then (instantiate' [] [Some (cterm_of sg (norm_zero_one z))] (neq_eq_pinf))
berghofe@13876
  1007
           else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_pinf))
berghofe@13876
  1008
berghofe@13876
  1009
      |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z)) =>
berghofe@13876
  1010
  	   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))
berghofe@13876
  1011
	     then (instantiate' [] [Some (cterm_of sg (norm_zero_one z))] (eq_eq_pinf))
berghofe@13876
  1012
	     else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_pinf)) 
berghofe@13876
  1013
berghofe@13876
  1014
      |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
berghofe@13876
  1015
           if (y=x) andalso (c1 =zero) then 
berghofe@13876
  1016
            if pm1 = one then (instantiate' [] [Some (cterm_of sg (norm_zero_one z))] (le_eq_pinf)) else
berghofe@13876
  1017
	     (instantiate' [] [Some (cterm_of sg (norm_zero_one z))] (len_eq_pinf))
berghofe@13876
  1018
	    else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_pinf))
berghofe@13876
  1019
      |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
  1020
         if y=x then  let val cd = cterm_of sg (norm_zero_one d)
berghofe@13876
  1021
	 		  val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
  1022
	 	      in(instantiate' [] [Some cd,  Some cz] (not_dvd_eq_pinf)) 
berghofe@13876
  1023
		      end
berghofe@13876
  1024
berghofe@13876
  1025
		else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_pinf))
berghofe@13876
  1026
		
berghofe@13876
  1027
      |(Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
  1028
         if y=x then  let val cd = cterm_of sg (norm_zero_one d)
berghofe@13876
  1029
	 		  val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
  1030
	 	      in(instantiate' [] [Some cd, Some cz ] (dvd_eq_pinf))
berghofe@13876
  1031
		      end
berghofe@13876
  1032
		else (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_pinf))
berghofe@13876
  1033
berghofe@13876
  1034
      		
berghofe@13876
  1035
    |_ => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] (fm_eq_pinf))
berghofe@13876
  1036
 end;
berghofe@13876
  1037
berghofe@13876
  1038
berghofe@13876
  1039
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1040
(* This function combines proofs of some special form already synthetised from the subtrees to make*)
berghofe@13876
  1041
(* a new proof of the same form. The combination occures whith isabelle theorems which have been already prooved *)
berghofe@13876
  1042
(*these Theorems are in Presburger.thy and mostly do not relay on the arithmetic.*)
berghofe@13876
  1043
(* These are Theorems for the Property of P_{+infty}*)
berghofe@13876
  1044
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1045
fun combine_pinf_proof s pr1 pr2 = case s of
berghofe@13876
  1046
    "ECJ" => [pr1 , pr2] MRS (eq_pinf_conjI)
berghofe@13876
  1047
berghofe@13876
  1048
   |"EDJ" => [pr1 , pr2] MRS (eq_pinf_disjI)
berghofe@13876
  1049
   
berghofe@13876
  1050
   |"MCJ" => [pr1 , pr2] MRS (modd_pinf_conjI)
berghofe@13876
  1051
berghofe@13876
  1052
   |"MDJ" => [pr1 , pr2] MRS (modd_pinf_disjI);
berghofe@13876
  1053
berghofe@13876
  1054
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1055
(*This function return an isabelle Proof for the minusinfinity theorem*)
berghofe@13876
  1056
(* It interpretates the protool and gives the protokoles property of P_{...} as a theorem*)
berghofe@13876
  1057
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1058
fun pinf_proof_ofh sg dlcm prl = case prl of 
berghofe@13876
  1059
berghofe@13876
  1060
    Eq_minf (_) => atomar_pinf_proof_of sg dlcm prl
berghofe@13876
  1061
    
berghofe@13876
  1062
   |Modd_minf (_) => atomar_pinf_proof_of sg dlcm prl
berghofe@13876
  1063
   
berghofe@13876
  1064
   |Eq_minf_conjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
berghofe@13876
  1065
   				    val pr2 = pinf_proof_ofh sg dlcm prl2
berghofe@13876
  1066
				 in (combine_pinf_proof "ECJ" pr1 pr2)
berghofe@13876
  1067
				 end
berghofe@13876
  1068
				 
berghofe@13876
  1069
   |Eq_minf_disjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
berghofe@13876
  1070
   				    val pr2 = pinf_proof_ofh sg dlcm prl2
berghofe@13876
  1071
				 in (combine_pinf_proof "EDJ" pr1 pr2)
berghofe@13876
  1072
				 end
berghofe@13876
  1073
				 
berghofe@13876
  1074
   |Modd_minf_conjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
berghofe@13876
  1075
   				    val pr2 = pinf_proof_ofh sg dlcm prl2
berghofe@13876
  1076
				 in (combine_pinf_proof "MCJ" pr1 pr2)
berghofe@13876
  1077
				 end
berghofe@13876
  1078
				 
berghofe@13876
  1079
   |Modd_minf_disjI (prl1,prl2) => let val pr1 = pinf_proof_ofh sg dlcm prl1
berghofe@13876
  1080
   				    val pr2 = pinf_proof_ofh sg dlcm prl2
berghofe@13876
  1081
				 in (combine_pinf_proof "MDJ" pr1 pr2)
berghofe@13876
  1082
				 end;
berghofe@13876
  1083
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1084
(* Main function For the rest both properies of P_{..} are needed and here both theorems are returned.*)				 
berghofe@13876
  1085
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1086
fun pinf_proof_of sg dlcm (Minusinf (prl1,prl2))  = 
berghofe@13876
  1087
  let val pr1 = pinf_proof_ofh sg dlcm prl1
berghofe@13876
  1088
      val pr2 = pinf_proof_ofh sg dlcm prl2
berghofe@13876
  1089
  in (pr1, pr2)
berghofe@13876
  1090
end;
berghofe@13876
  1091
				 
berghofe@13876
  1092
berghofe@13876
  1093
berghofe@13876
  1094
(* ------------------------------------------------------------------------- *)    
berghofe@13876
  1095
(* Protokol interpretation function for the backwards direction for cooper's Theorem*)
berghofe@13876
  1096
berghofe@13876
  1097
(* For the generation of atomic Theorems*)
berghofe@13876
  1098
(* Prove the premisses on runtime and then make RS*)
berghofe@13876
  1099
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1100
fun generate_atomic_not_bst_p sg (x as Free(xn,xT)) fm dlcm B at = 
berghofe@13876
  1101
  let
berghofe@13876
  1102
    val cdlcm = cterm_of sg dlcm
berghofe@13876
  1103
    val cB = cterm_of sg B
berghofe@13876
  1104
    val cfma = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
berghofe@13876
  1105
    val cat = cterm_of sg (norm_zero_one at)
berghofe@13876
  1106
  in
berghofe@13876
  1107
  case at of 
berghofe@13876
  1108
   (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
berghofe@13876
  1109
      if  (x=y) andalso (c1=zero) andalso (c2=one) 
berghofe@13876
  1110
	 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)
berghofe@13876
  1111
	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one  z)))
berghofe@13876
  1112
		  val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
berghofe@13876
  1113
	 in  (instantiate' [] [Some cfma]([th3,th1,th2] MRS (not_bst_p_ne)))
berghofe@13876
  1114
	 end
berghofe@13876
  1115
         else (instantiate' [] [Some cfma,  Some cdlcm, Some cB,Some cat] (not_bst_p_fm))
berghofe@13876
  1116
berghofe@13876
  1117
   |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", T) $(Const ("op *",_) $ c2 $ y) $z)) =>
berghofe@13876
  1118
     if (is_arith_rel at) andalso (x=y)
berghofe@13876
  1119
	then let val bst_z = norm_zero_one (linear_neg (linear_add [] z (mk_numeral 1)))
berghofe@13876
  1120
	         in let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ bst_z $ B)
berghofe@13876
  1121
	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq (bst_z,Const("op -",T) $ (Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one z)) $ (Const("1",HOLogic.intT))))
berghofe@13876
  1122
		  val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
berghofe@13876
  1123
	 in  (instantiate' [] [Some cfma] ([th3,th1,th2] MRS (not_bst_p_eq)))
berghofe@13876
  1124
	 end
berghofe@13876
  1125
       end
berghofe@13876
  1126
         else (instantiate' [] [Some cfma,  Some cdlcm, Some cB,Some cat] (not_bst_p_fm))
berghofe@13876
  1127
berghofe@13876
  1128
   |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
berghofe@13876
  1129
        if (y=x) andalso (c1 =zero) then 
berghofe@13876
  1130
        if pm1 = one then 
berghofe@13876
  1131
	  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)
berghofe@13876
  1132
              val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one z)))
berghofe@13876
  1133
	  in  (instantiate' [] [Some cfma,  Some cdlcm]([th1,th2] MRS (not_bst_p_gt)))
berghofe@13876
  1134
	    end
berghofe@13876
  1135
	 else let val th1 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
berghofe@13876
  1136
	      in (instantiate' [] [Some cfma, Some cB,Some (cterm_of sg (norm_zero_one z))] (th1 RS (not_bst_p_lt)))
berghofe@13876
  1137
	      end
berghofe@13876
  1138
      else (instantiate' [] [Some cfma,  Some cdlcm, Some cB,Some cat] (not_bst_p_fm))
berghofe@13876
  1139
berghofe@13876
  1140
   |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
  1141
      if y=x then  
berghofe@13876
  1142
           let val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
  1143
	       val th1 = (prove_elementar sg "ss"  (HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1)
berghofe@13876
  1144
 	     in (instantiate' []  [Some cfma, Some cB,Some cz] (th1 RS (not_bst_p_ndvd)))
berghofe@13876
  1145
	     end
berghofe@13876
  1146
      else (instantiate' [] [Some cfma,  Some cdlcm, Some cB,Some cat] (not_bst_p_fm))
berghofe@13876
  1147
berghofe@13876
  1148
   |(Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
  1149
       if y=x then  
berghofe@13876
  1150
	 let val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
  1151
	     val th1 = (prove_elementar sg "ss"  (HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1)
berghofe@13876
  1152
 	    in (instantiate' []  [Some cfma,Some cB,Some cz] (th1 RS (not_bst_p_dvd)))
berghofe@13876
  1153
	  end
berghofe@13876
  1154
      else (instantiate' [] [Some cfma,  Some cdlcm, Some cB,Some cat] (not_bst_p_fm))
berghofe@13876
  1155
      		
berghofe@13876
  1156
   |_ => (instantiate' [] [Some cfma,  Some cdlcm, Some cB,Some cat] (not_bst_p_fm))
berghofe@13876
  1157
      		
berghofe@13876
  1158
    end;
berghofe@13876
  1159
    
berghofe@13876
  1160
(* ------------------------------------------------------------------------- *)    
berghofe@13876
  1161
(* Main interpretation function for this backwards dirction*)
berghofe@13876
  1162
(* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*)
berghofe@13876
  1163
(*Help Function*)
berghofe@13876
  1164
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1165
fun not_bst_p_proof_of_h sg x fm dlcm B prt = case prt of 
berghofe@13876
  1166
	(Not_bst_p_atomic(fm2)) => (generate_atomic_not_bst_p sg x fm dlcm B fm2)
berghofe@13876
  1167
	
berghofe@13876
  1168
	|(Not_bst_p_conjI(pr1,pr2)) => 
berghofe@13876
  1169
			let val th1 = (not_bst_p_proof_of_h sg x fm dlcm B pr1)
berghofe@13876
  1170
			    val th2 = (not_bst_p_proof_of_h sg x fm dlcm B pr2)
berghofe@13876
  1171
			    in ([th1,th2] MRS (not_bst_p_conjI))
berghofe@13876
  1172
			    end
berghofe@13876
  1173
berghofe@13876
  1174
	|(Not_bst_p_disjI(pr1,pr2)) => 
berghofe@13876
  1175
			let val th1 = (not_bst_p_proof_of_h sg x fm dlcm B pr1)
berghofe@13876
  1176
			    val th2 = (not_bst_p_proof_of_h sg x fm dlcm B pr2)
berghofe@13876
  1177
			    in ([th1,th2] MRS not_bst_p_disjI)
berghofe@13876
  1178
			    end;
berghofe@13876
  1179
(* Main function*)
berghofe@13876
  1180
fun not_bst_p_proof_of sg (Not_bst_p(x as Free(xn,xT),fm,dlcm,B,prl)) =
berghofe@13876
  1181
  let val th =  not_bst_p_proof_of_h sg x fm dlcm B prl
berghofe@13876
  1182
      val fma = absfree (xn,xT, norm_zero_one fm)
berghofe@13876
  1183
  in let val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
berghofe@13876
  1184
     in [th,th1] MRS (not_bst_p_Q_elim)
berghofe@13876
  1185
     end
berghofe@13876
  1186
  end;
berghofe@13876
  1187
berghofe@13876
  1188
berghofe@13876
  1189
(* ------------------------------------------------------------------------- *)    
berghofe@13876
  1190
(* Protokol interpretation function for the backwards direction for cooper's Theorem*)
berghofe@13876
  1191
berghofe@13876
  1192
(* For the generation of atomic Theorems*)
berghofe@13876
  1193
(* Prove the premisses on runtime and then make RS*)
berghofe@13876
  1194
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1195
fun generate_atomic_not_ast_p sg (x as Free(xn,xT)) fm dlcm A at = 
berghofe@13876
  1196
  let
berghofe@13876
  1197
    val cdlcm = cterm_of sg dlcm
berghofe@13876
  1198
    val cA = cterm_of sg A
berghofe@13876
  1199
    val cfma = cterm_of sg (absfree (xn,xT,(norm_zero_one fm)))
berghofe@13876
  1200
    val cat = cterm_of sg (norm_zero_one at)
berghofe@13876
  1201
  in
berghofe@13876
  1202
  case at of 
berghofe@13876
  1203
   (Const ("Not", _) $ (Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $ (Const ("op +", _) $(Const ("op *",_) $ c2 $ y) $z))) => 
berghofe@13876
  1204
      if  (x=y) andalso (c1=zero) andalso (c2=one) 
berghofe@13876
  1205
	 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)
berghofe@13876
  1206
	          val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq ((norm_zero_one (linear_cmul ~1 z)),Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one  z)))
berghofe@13876
  1207
		  val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
berghofe@13876
  1208
	 in  (instantiate' [] [Some cfma]([th3,th1,th2] MRS (not_ast_p_ne)))
berghofe@13876
  1209
	 end
berghofe@13876
  1210
         else (instantiate' [] [Some cfma,  Some cdlcm, Some cA,Some cat] (not_ast_p_fm))
berghofe@13876
  1211
berghofe@13876
  1212
   |(Const("op =",Type ("fun",[Type ("IntDef.int", []),_])) $ c1 $(Const ("op +", T) $(Const ("op *",_) $ c2 $ y) $z)) =>
berghofe@13876
  1213
     if (is_arith_rel at) andalso (x=y)
berghofe@13876
  1214
	then let val ast_z = norm_zero_one (linear_sub [] one z )
berghofe@13876
  1215
	         val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ ast_z $ A)
berghofe@13876
  1216
	         val th2 =  prove_elementar sg "ss" (HOLogic.mk_eq (ast_z,Const("op +",T) $ (Const("uminus",HOLogic.intT --> HOLogic.intT) $(norm_zero_one z)) $ (Const("1",HOLogic.intT))))
berghofe@13876
  1217
		 val th3 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
berghofe@13876
  1218
	 in  (instantiate' [] [Some cfma] ([th3,th1,th2] MRS (not_ast_p_eq)))
berghofe@13876
  1219
       end
berghofe@13876
  1220
         else (instantiate' [] [Some cfma,  Some cdlcm, Some cA,Some cat] (not_ast_p_fm))
berghofe@13876
  1221
berghofe@13876
  1222
   |(Const("op <",_) $ c1 $(Const ("op +", _) $(Const ("op *",_) $ pm1 $ y ) $ z )) =>
berghofe@13876
  1223
        if (y=x) andalso (c1 =zero) then 
berghofe@13876
  1224
        if pm1 = (mk_numeral ~1) then 
berghofe@13876
  1225
	  let val th1 = prove_elementar sg "ss" (Const ("op :",HOLogic.intT --> (HOLogic.mk_setT HOLogic.intT) --> HOLogic.boolT) $ (norm_zero_one z) $ A)
berghofe@13876
  1226
              val th2 =  prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm))
berghofe@13876
  1227
	  in  (instantiate' [] [Some cfma]([th2,th1] MRS (not_ast_p_lt)))
berghofe@13876
  1228
	    end
berghofe@13876
  1229
	 else let val th1 = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (Const("0",HOLogic.intT),dlcm))
berghofe@13876
  1230
	      in (instantiate' [] [Some cfma, Some cA,Some (cterm_of sg (norm_zero_one z))] (th1 RS (not_ast_p_gt)))
berghofe@13876
  1231
	      end
berghofe@13876
  1232
      else (instantiate' [] [Some cfma,  Some cdlcm, Some cA,Some cat] (not_ast_p_fm))
berghofe@13876
  1233
berghofe@13876
  1234
   |Const ("Not",_) $ (Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
  1235
      if y=x then  
berghofe@13876
  1236
           let val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
  1237
	       val th1 = (prove_elementar sg "ss"  (HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1)
berghofe@13876
  1238
 	     in (instantiate' []  [Some cfma, Some cA,Some cz] (th1 RS (not_ast_p_ndvd)))
berghofe@13876
  1239
	     end
berghofe@13876
  1240
      else (instantiate' [] [Some cfma,  Some cdlcm, Some cA,Some cat] (not_ast_p_fm))
berghofe@13876
  1241
berghofe@13876
  1242
   |(Const("Divides.op dvd",_)$ d $ (Const ("op +",_) $ (Const ("op *",_) $ c $ y ) $ z)) => 
berghofe@13876
  1243
       if y=x then  
berghofe@13876
  1244
	 let val cz = cterm_of sg (norm_zero_one z)
berghofe@13876
  1245
	     val th1 = (prove_elementar sg "ss"  (HOLogic.mk_binrel "op =" (HOLogic.mk_binop "Divides.op mod" (dlcm,d),norm_zero_one zero))) RS (((zdvd_iff_zmod_eq_0)RS sym) RS iffD1)
berghofe@13876
  1246
 	    in (instantiate' []  [Some cfma,Some cA,Some cz] (th1 RS (not_ast_p_dvd)))
berghofe@13876
  1247
	  end
berghofe@13876
  1248
      else (instantiate' [] [Some cfma,  Some cdlcm, Some cA,Some cat] (not_ast_p_fm))
berghofe@13876
  1249
      		
berghofe@13876
  1250
   |_ => (instantiate' [] [Some cfma,  Some cdlcm, Some cA,Some cat] (not_ast_p_fm))
berghofe@13876
  1251
      		
berghofe@13876
  1252
    end;
berghofe@13876
  1253
    
berghofe@13876
  1254
(* ------------------------------------------------------------------------- *)    
berghofe@13876
  1255
(* Main interpretation function for this backwards dirction*)
berghofe@13876
  1256
(* if atomic do generate atomis formulae else Construct theorems and then make RS with the construction theorems*)
berghofe@13876
  1257
(*Help Function*)
berghofe@13876
  1258
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1259
fun not_ast_p_proof_of_h sg x fm dlcm A prt = case prt of 
berghofe@13876
  1260
	(Not_ast_p_atomic(fm2)) => (generate_atomic_not_ast_p sg x fm dlcm A fm2)
berghofe@13876
  1261
	
berghofe@13876
  1262
	|(Not_ast_p_conjI(pr1,pr2)) => 
berghofe@13876
  1263
			let val th1 = (not_ast_p_proof_of_h sg x fm dlcm A pr1)
berghofe@13876
  1264
			    val th2 = (not_ast_p_proof_of_h sg x fm dlcm A pr2)
berghofe@13876
  1265
			    in ([th1,th2] MRS (not_ast_p_conjI))
berghofe@13876
  1266
			    end
berghofe@13876
  1267
berghofe@13876
  1268
	|(Not_ast_p_disjI(pr1,pr2)) => 
berghofe@13876
  1269
			let val th1 = (not_ast_p_proof_of_h sg x fm dlcm A pr1)
berghofe@13876
  1270
			    val th2 = (not_ast_p_proof_of_h sg x fm dlcm A pr2)
berghofe@13876
  1271
			    in ([th1,th2] MRS (not_ast_p_disjI))
berghofe@13876
  1272
			    end;
berghofe@13876
  1273
(* Main function*)
berghofe@13876
  1274
fun not_ast_p_proof_of sg (Not_ast_p(x as Free(xn,xT),fm,dlcm,A,prl)) =
berghofe@13876
  1275
  let val th =  not_ast_p_proof_of_h sg x fm dlcm A prl
berghofe@13876
  1276
      val fma = absfree (xn,xT, norm_zero_one fm)
berghofe@13876
  1277
      val th1 =  prove_elementar sg "ss"  (HOLogic.mk_eq (fma,fma))
berghofe@13876
  1278
  in [th,th1] MRS (not_ast_p_Q_elim)
berghofe@13876
  1279
end;
berghofe@13876
  1280
berghofe@13876
  1281
berghofe@13876
  1282
berghofe@13876
  1283
berghofe@13876
  1284
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1285
(* Interpretaion of Protocols of the cooper procedure : minusinfinity version*)
berghofe@13876
  1286
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1287
berghofe@13876
  1288
berghofe@13876
  1289
fun coopermi_proof_of sg x (Cooper (dlcm,Simp(fm,miprt),bsprt,nbst_p_prt)) =
berghofe@13876
  1290
  (* Get the Bset thm*)
nipkow@14139
  1291
  let val (mit1,mit2) = minf_proof_of sg dlcm miprt
berghofe@13876
  1292
      val fm1 = norm_zero_one (simpl fm) 
berghofe@13876
  1293
      val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm));
berghofe@13876
  1294
      val nbstpthm = not_bst_p_proof_of sg nbst_p_prt
berghofe@13876
  1295
    (* Return the four theorems needed to proove the whole Cooper Theorem*)
nipkow@14139
  1296
  in (dpos,mit2,nbstpthm,mit1)
berghofe@13876
  1297
end;
berghofe@13876
  1298
berghofe@13876
  1299
berghofe@13876
  1300
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1301
(* Interpretaion of Protocols of the cooper procedure : plusinfinity version *)
berghofe@13876
  1302
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1303
berghofe@13876
  1304
berghofe@13876
  1305
fun cooperpi_proof_of sg x (Cooper (dlcm,Simp(fm,miprt),bsprt,nast_p_prt)) =
nipkow@14139
  1306
  let val (mit1,mit2) = pinf_proof_of sg dlcm miprt
berghofe@13876
  1307
      val fm1 = norm_zero_one (simpl fm) 
berghofe@13876
  1308
      val dpos = prove_elementar sg "ss" (HOLogic.mk_binrel "op <" (zero,dlcm));
berghofe@13876
  1309
      val nastpthm = not_ast_p_proof_of sg nast_p_prt
nipkow@14139
  1310
  in (dpos,mit2,nastpthm,mit1)
berghofe@13876
  1311
end;
berghofe@13876
  1312
berghofe@13876
  1313
berghofe@13876
  1314
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1315
(* Interpretaion of Protocols of the cooper procedure : full version*)
berghofe@13876
  1316
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1317
berghofe@13876
  1318
berghofe@13876
  1319
berghofe@13876
  1320
fun cooper_thm sg s (x as Free(xn,xT)) vars cfm = case s of
berghofe@13876
  1321
  "pi" => let val (rs,prt) = cooperpi_wp (xn::vars) (HOLogic.mk_exists(xn,xT,cfm))
nipkow@14139
  1322
	      val (dpsthm,th1,nbpth,th3) = cooperpi_proof_of sg x prt
nipkow@14139
  1323
		   in [dpsthm,th1,nbpth,th3] MRS (cppi_eq)
berghofe@13876
  1324
           end
berghofe@13876
  1325
  |"mi" => let val (rs,prt) = coopermi_wp (xn::vars) (HOLogic.mk_exists(xn,xT,cfm))
nipkow@14139
  1326
	       val (dpsthm,th1,nbpth,th3) = coopermi_proof_of sg x prt
nipkow@14139
  1327
		   in [dpsthm,th1,nbpth,th3] MRS (cpmi_eq)
berghofe@13876
  1328
                end
berghofe@13876
  1329
 |_ => error "parameter error";
berghofe@13876
  1330
berghofe@13876
  1331
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1332
(* This function should evoluate to the end prove Procedure for one quantifier elimination for Presburger arithmetic*)
berghofe@13876
  1333
(* It shoud be plugged in the qfnp argument of the quantifier elimination proof function*)
berghofe@13876
  1334
(* ------------------------------------------------------------------------- *)
berghofe@13876
  1335
berghofe@13876
  1336
fun cooper_prv sg (x as Free(xn,xT)) efm vars = let 
berghofe@13876
  1337
   val l = formlcm x efm
berghofe@13876
  1338
   val ac_thm = proof_of_adjustcoeffeq sg (adjustcoeffeq_wp  x l efm)
berghofe@13876
  1339
   val fm = snd (qe_get_terms ac_thm)
berghofe@13876
  1340
   val  cfm = unitycoeff x fm
berghofe@13876
  1341
   val afm = adjustcoeff x l fm
berghofe@13876
  1342
   val P = absfree(xn,xT,afm)
berghofe@13876
  1343
   val ss = presburger_ss addsimps
berghofe@13876
  1344
     [simp_from_to] delsimps [P_eqtrue, P_eqfalse, bex_triv, insert_iff]
berghofe@13876
  1345
   val uth = instantiate' [] [Some (cterm_of sg P) , Some (cterm_of sg (mk_numeral l))] (unity_coeff_ex)
berghofe@13876
  1346
   val e_ac_thm = (forall_intr (cterm_of sg x) ac_thm) COMP (qe_exI)
berghofe@13876
  1347
   val cms = if ((length (aset x cfm)) < (length (bset x cfm))) then "pi" else "mi"
berghofe@13876
  1348
   val cp_thm = cooper_thm sg cms x vars cfm
berghofe@13876
  1349
   val exp_cp_thm = refl RS (simplify ss (cp_thm RSN (2,trans)))
berghofe@13876
  1350
   val (lsuth,rsuth) = qe_get_terms (uth)
berghofe@13876
  1351
   val (lseacth,rseacth) = qe_get_terms(e_ac_thm)
berghofe@13876
  1352
   val (lscth,rscth) = qe_get_terms (exp_cp_thm)
berghofe@13876
  1353
   val  u_c_thm = [([uth,prove_elementar sg "ss" (HOLogic.mk_eq (rsuth,lscth))] MRS trans),exp_cp_thm] MRS trans
berghofe@13876
  1354
 in  ([e_ac_thm,[(prove_elementar sg "ss" (HOLogic.mk_eq (rseacth,lsuth))),u_c_thm] MRS trans] MRS trans)
berghofe@13876
  1355
   end
berghofe@13876
  1356
|cooper_prv _ _ _ _ = error "Parameters format";
berghofe@13876
  1357
berghofe@13876
  1358
berghofe@13876
  1359
(*====================================================*)
berghofe@13876
  1360
(*Interpretation function for the evaluation protokol *)
berghofe@13876
  1361
(*====================================================*)
berghofe@13876
  1362
berghofe@13876
  1363
fun proof_of_evalc sg fm =
berghofe@13876
  1364
let
berghofe@13876
  1365
fun proof_of_evalch prt = case prt of
berghofe@13876
  1366
  EvalAt(at) => prove_elementar sg "ss" at
berghofe@13876
  1367
 |Evalfm(fm) => instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl
berghofe@13876
  1368
 |EvalConst(s,pr1,pr2) => 
berghofe@13876
  1369
   let val th1 = proof_of_evalch pr1
berghofe@13876
  1370
       val th2 = proof_of_evalch pr2
berghofe@13876
  1371
   in case s of
berghofe@13876
  1372
     "CJ" =>[th1,th2] MRS (qe_conjI)
berghofe@13876
  1373
    |"DJ" =>[th1,th2] MRS (qe_disjI)
berghofe@13876
  1374
    |"IM" =>[th1,th2] MRS (qe_impI)
berghofe@13876
  1375
    |"EQ" =>[th1,th2] MRS (qe_eqI)
berghofe@13876
  1376
    end
berghofe@13876
  1377
in proof_of_evalch (evalc_wp fm)
berghofe@13876
  1378
end;
berghofe@13876
  1379
berghofe@13876
  1380
(*============================================================*)
berghofe@13876
  1381
(*Interpretation function for the NNF-Transformation protokol *)
berghofe@13876
  1382
(*============================================================*)
berghofe@13876
  1383
berghofe@13876
  1384
fun proof_of_cnnf sg fm pf = 
berghofe@13876
  1385
let fun proof_of_cnnfh prt pat = case prt of
berghofe@13876
  1386
  NNFAt(at) => pat at
berghofe@13876
  1387
 |NNFSimp (pr) => let val th1 = proof_of_cnnfh pr pat
berghofe@13876
  1388
                  in let val fm2 = snd (qe_get_terms th1) 
berghofe@13876
  1389
		     in [th1,prove_elementar sg "ss" (HOLogic.mk_eq(fm2 ,simpl fm2))] MRS trans
berghofe@13876
  1390
                     end
berghofe@13876
  1391
                  end
berghofe@13876
  1392
 |NNFNN (pr) => (proof_of_cnnfh pr pat) RS (nnf_nn)
berghofe@13876
  1393
 |NNFConst (s,pr1,pr2) =>
berghofe@13876
  1394
   let val th1 = proof_of_cnnfh pr1 pat
berghofe@13876
  1395
       val th2 = proof_of_cnnfh pr2 pat
berghofe@13876
  1396
   in case s of
berghofe@13876
  1397
     "CJ" => [th1,th2] MRS (qe_conjI)
berghofe@13876
  1398
    |"DJ" => [th1,th2] MRS (qe_disjI)
berghofe@13876
  1399
    |"IM" => [th1,th2] MRS (nnf_im)
berghofe@13876
  1400
    |"EQ" => [th1,th2] MRS (nnf_eq)
berghofe@13876
  1401
    |"SDJ" => let val (Const("op &",_)$A$_) = fst (qe_get_terms th1)
berghofe@13876
  1402
	          val (Const("op &",_)$C$_) = fst (qe_get_terms th2)
berghofe@13876
  1403
	      in [th1,th2,prove_elementar sg "ss" (HOLogic.mk_eq (A,HOLogic.Not $ C))] MRS (nnf_sdj)
berghofe@13876
  1404
	      end
berghofe@13876
  1405
    |"NCJ" => [th1,th2] MRS (nnf_ncj)
berghofe@13876
  1406
    |"NIM" => [th1,th2] MRS (nnf_nim)
berghofe@13876
  1407
    |"NEQ" => [th1,th2] MRS (nnf_neq)
berghofe@13876
  1408
    |"NDJ" => [th1,th2] MRS (nnf_ndj)
berghofe@13876
  1409
   end
berghofe@13876
  1410
in proof_of_cnnfh (cnnf_wp fm) pf
berghofe@13876
  1411
end;
berghofe@13876
  1412
berghofe@13876
  1413
berghofe@13876
  1414
berghofe@13876
  1415
berghofe@13876
  1416
(*====================================================*)
berghofe@13876
  1417
(* Interpretation function for the linform protokol   *)
berghofe@13876
  1418
(*====================================================*)
berghofe@13876
  1419
berghofe@13876
  1420
berghofe@13876
  1421
fun proof_of_linform sg vars f = 
berghofe@13876
  1422
  let fun proof_of_linformh prt = 
berghofe@13876
  1423
  case prt of
berghofe@13876
  1424
    (LfAt (at)) =>  prove_elementar sg "lf" (HOLogic.mk_eq (at, linform vars at))
berghofe@13876
  1425
   |(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))
berghofe@13876
  1426
   |(Lffm (fm)) => (instantiate' [Some cboolT] [Some (cterm_of sg fm)] refl)
berghofe@13876
  1427
   |(LfConst (s,pr1,pr2)) =>
berghofe@13876
  1428
     let val th1 = proof_of_linformh pr1
berghofe@13876
  1429
	 val th2 = proof_of_linformh pr2
berghofe@13876
  1430
     in case s of
berghofe@13876
  1431
       "CJ" => [th1,th2] MRS (qe_conjI)
berghofe@13876
  1432
      |"DJ" =>[th1,th2] MRS (qe_disjI)
berghofe@13876
  1433
      |"IM" =>[th1,th2] MRS (qe_impI)
berghofe@13876
  1434
      |"EQ" =>[th1,th2] MRS (qe_eqI)
berghofe@13876
  1435
     end
berghofe@13876
  1436
   |(LfNot(pr)) => 
berghofe@13876
  1437
     let val th = proof_of_linformh pr
berghofe@13876
  1438
     in (th RS (qe_Not))
berghofe@13876
  1439
     end
berghofe@13876
  1440
   |(LfQ(s,xn,xT,pr)) => 
berghofe@13876
  1441
     let val th = forall_intr (cterm_of sg (Free(xn,xT)))(proof_of_linformh pr)
berghofe@13876
  1442
     in if s = "Ex" 
berghofe@13876
  1443
        then (th COMP(qe_exI) )
berghofe@13876
  1444
        else (th COMP(qe_ALLI) )
berghofe@13876
  1445
     end
berghofe@13876
  1446
in
berghofe@13876
  1447
 proof_of_linformh (linform_wp f)
berghofe@13876
  1448
end;
berghofe@13876
  1449
berghofe@13876
  1450
end;