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