src/HOL/Real/ferrante_rackoff_proof.ML
author wenzelm
Sat, 08 Jul 2006 12:54:37 +0200
changeset 20049 f48c4a3a34bc
parent 19640 40ec89317425
child 20194 c9dbce9a23a1
permissions -rw-r--r--
Goal.prove: context;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     1
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     3
    Author:     Amine Chaieb, TU Muenchen
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     4
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     5
LCF proof synthesis for Ferrante and Rackoff.
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     6
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     7
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     8
structure Ferrante_Rackoff_Proof:
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
     9
sig
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    10
  val qelim: cterm -> thm
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    11
  exception FAILURE of string
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    12
end =
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    13
struct
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    14
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    15
    (* Some certified types *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    16
val cbT = ctyp_of (the_context()) HOLogic.boolT;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    17
val rT = Type("RealDef.real",[]);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    18
val crT = ctyp_of (the_context()) (Type("RealDef.real",[]));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    19
    (* Normalization*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    20
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    21
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    22
        (* Computation of uset *)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    23
fun uset x fm = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    24
    case fm of
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    25
        Const("op &",_)$p$q => (uset x p) union (uset x q)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    26
      | Const("op |",_)$p$q => (uset x p) union (uset x q)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    27
      | Const("Orderings.less",_)$s$t => if s=x then [t] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    28
                               else if t = x then [s]
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    29
                               else []
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    30
      | Const("Orderings.less_eq",_)$s$t => if s=x then [t] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    31
                               else if t = x then [s]
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    32
                               else []
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    33
      | Const("op =",_)$s$t => if s=x then [t] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    34
                               else []
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    35
      | Const("Not",_)$ (Const("op =",_)$s$t) => if s=x then [t] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    36
                                                 else []
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    37
      | _ => [];
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    38
val rsT = Type("set",[rT]);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    39
fun holrealset [] = Const("{}",rsT)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    40
  | holrealset (x::xs) = Const("insert",[rT,rsT] ---> rsT)$x$(holrealset xs);
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    41
fun prove_bysimp thy ss t = Goal.prove (ProofContext.init thy) [] [] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    42
                       (HOLogic.mk_Trueprop t) (fn _ => simp_tac ss 1);
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    43
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    44
fun inusetthms sg x fm = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    45
    let val U = uset x fm
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    46
        val hU = holrealset U
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    47
        fun inC T = Const("op :",[T,Type("set",[T])] ---> HOLogic.boolT);
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    48
        val ss = simpset_of sg
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    49
        fun proveinU t = prove_bysimp sg ss ((inC rT)$t$hU)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    50
        val uf = prove_bysimp sg ss ((inC rsT)$hU$Const("Finite_Set.Finites",Type("set",[rsT])))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    51
    in (U,cterm_of sg hU,map proveinU U,uf)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    52
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    53
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    54
        (* Theorems for minus/plusinfinity *)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    55
val [minf_lt,minf_gt,minf_le,minf_ge,minf_eq,minf_neq,minf_fm,minf_conj,minf_disj] = thms"minf";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    56
val [pinf_lt,pinf_gt,pinf_le,pinf_ge,pinf_eq,pinf_neq,pinf_fm,pinf_conj,pinf_disj] = thms"pinf";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    57
    (* Theorems for boundedness from below/above *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    58
val [nmilbnd_lt,nmilbnd_gt,nmilbnd_le,nmilbnd_ge,nmilbnd_eq,nmilbnd_neq,nmilbnd_fm,nmilbnd_conj,nmilbnd_disj] = thms"nmilbnd";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    59
val [npiubnd_lt,npiubnd_gt,npiubnd_le,npiubnd_ge,npiubnd_eq,npiubnd_neq,npiubnd_fm,npiubnd_conj,npiubnd_disj] = thms"npiubnd";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    60
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    61
    (* Theorems for no changes over smallest intervals in U *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    62
val lin_dense_lt = thm "lin_dense_lt";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    63
val lin_dense_le = thm "lin_dense_le";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    64
val lin_dense_gt = thm "lin_dense_gt";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    65
val lin_dense_ge = thm "lin_dense_ge";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    66
val lin_dense_eq = thm "lin_dense_eq";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    67
val lin_dense_neq = thm "lin_dense_neq";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    68
val lin_dense_conj = thm "lin_dense_conj";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    69
val lin_dense_disj = thm "lin_dense_disj";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    70
val lin_dense_fm = thm "lin_dense_fm";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    71
val fr_eq = thm "fr_eq";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    72
val fr_simps = thms "fr_simps";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    73
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    74
fun dest5 [] = ([],[],[],[],[])
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    75
  | dest5 ((x,y,z,w,v)::xs) = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    76
    let val (x',y',z',w',v') = dest5 xs 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    77
    in (x::x',y::y',z::z',w::w',v::v') end ;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    78
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    79
fun dest2 [] = ([],[])
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    80
  | dest2 ((x,y)::xs) = let val (x',y') = dest2 xs 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    81
                            in (x::x',y::y') end ;
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    82
fun myfwd (th1,th2,th3,th4,th5) xs =
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    83
    let val (ths1,ths2,ths3,ths4,ths5) = dest5 xs
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    84
    in (ths1 MRS th1,ths2 MRS th2,ths3 MRS th3,ths4 MRS th4, ths5 MRS th5)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    85
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    86
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    87
fun myfwd2 (th1,th2) xs =
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    88
    let val (ths1,ths2) = dest2 xs
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    89
    in (ths1 MRS th1,ths2 MRS th2)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    90
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    91
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    92
fun decomp_mpinf sg x (U,CU,uths) fm = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
    93
    let val cx = cterm_of sg x in
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    94
        (case fm of
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    95
            Const("op &",_)$p$q => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    96
            ([p,q],myfwd (minf_conj,pinf_conj, nmilbnd_conj, npiubnd_conj,lin_dense_conj))      
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    97
          | Const("op |",_)$p$q => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    98
            ([p,q],myfwd (minf_disj,pinf_disj, nmilbnd_disj,npiubnd_disj,lin_dense_disj))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
    99
          | Const("Orderings.less",_)$s$t => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   100
            if s= x then 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   101
                let val ct = cterm_of sg t
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   102
                    val tinU = nth uths (find_index (fn a => a=t) U)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   103
                    val mith = instantiate' [] [SOME ct] minf_lt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   104
                    val pith = instantiate' [] [SOME ct] pinf_lt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   105
                    val nmilth = tinU RS nmilbnd_lt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   106
                    val npiuth = tinU RS npiubnd_lt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   107
                    val lindth = tinU RS lin_dense_lt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   108
                in ([],myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   109
                end 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   110
            else if t = x then 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   111
                let val ct = cterm_of sg s
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   112
                    val tinU = nth uths (find_index (fn a => a=s) U)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   113
                    val mith = instantiate' [] [SOME ct] minf_gt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   114
                    val pith = instantiate' [] [SOME ct] pinf_gt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   115
                    val nmilth = tinU RS nmilbnd_gt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   116
                    val npiuth = tinU RS npiubnd_gt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   117
                    val lindth = tinU RS lin_dense_gt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   118
                in ([],myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   119
                end 
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   120
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   121
            else
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   122
                let val cfm = cterm_of sg fm 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   123
                    val mith = instantiate' [] [SOME cfm] minf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   124
                    val pith = instantiate' [] [SOME cfm] pinf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   125
                    val nmilth = instantiate' [] [SOME cfm, SOME CU] nmilbnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   126
                    val npiuth = instantiate' [] [SOME cfm, SOME CU] npiubnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   127
                    val lindth = instantiate' [] [SOME CU, SOME cfm] lin_dense_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   128
                in ([], myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   129
                end
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   130
          | Const("Orderings.less_eq",_)$s$t => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   131
            if s= x then 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   132
                let val ct = cterm_of sg t
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   133
                    val tinU = nth uths (find_index (fn a => a=t) U)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   134
                    val mith = instantiate' [] [SOME ct] minf_le
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   135
                    val pith = instantiate' [] [SOME ct] pinf_le
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   136
                    val nmilth = tinU RS nmilbnd_le
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   137
                    val npiuth = tinU RS npiubnd_le
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   138
                    val lindth = tinU RS lin_dense_le
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   139
                in ([],myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   140
                end 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   141
            else if t = x then 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   142
                let val ct = cterm_of sg s
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   143
                    val tinU = nth uths (find_index (fn a => a=s) U)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   144
                    val mith = instantiate' [] [SOME ct] minf_ge
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   145
                    val pith = instantiate' [] [SOME ct] pinf_ge
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   146
                    val nmilth = tinU RS nmilbnd_ge
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   147
                    val npiuth = tinU RS npiubnd_ge
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   148
                    val lindth = tinU RS lin_dense_ge
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   149
                in ([],myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   150
                end 
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   151
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   152
            else
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   153
                let val cfm = cterm_of sg fm 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   154
                    val mith = instantiate' [] [SOME cfm] minf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   155
                    val pith = instantiate' [] [SOME cfm] pinf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   156
                    val nmilth = instantiate' [] [SOME cfm, SOME CU] nmilbnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   157
                    val npiuth = instantiate' [] [SOME cfm, SOME CU] npiubnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   158
                    val lindth = instantiate' [] [SOME CU, SOME cfm] lin_dense_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   159
                in ([], myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   160
                end
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   161
          | Const("op =",_)$s$t => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   162
            if s= x then 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   163
                let val ct = cterm_of sg t
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   164
                    val tinU = nth uths (find_index (fn a => a=t) U)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   165
                    val mith = instantiate' [] [SOME ct] minf_eq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   166
                    val pith = instantiate' [] [SOME ct] pinf_eq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   167
                    val nmilth = tinU RS nmilbnd_eq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   168
                    val npiuth = tinU RS npiubnd_eq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   169
                    val lindth = tinU RS lin_dense_eq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   170
                in ([],myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   171
                end 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   172
            else
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   173
                let val cfm = cterm_of sg fm 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   174
                    val mith = instantiate' [] [SOME cfm] minf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   175
                    val pith = instantiate' [] [SOME cfm] pinf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   176
                    val nmilth = instantiate' [] [SOME cfm, SOME CU] nmilbnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   177
                    val npiuth = instantiate' [] [SOME cfm, SOME CU] npiubnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   178
                    val lindth = instantiate' [] [SOME CU, SOME cfm] lin_dense_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   179
                in ([], myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   180
                end
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   181
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   182
          | Const("Not",_)$(Const("op =",_)$s$t) => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   183
            if s= x then 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   184
                let val ct = cterm_of sg t
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   185
                    val tinU = nth uths (find_index (fn a => a=t) U)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   186
                    val mith = instantiate' [] [SOME ct] minf_neq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   187
                    val pith = instantiate' [] [SOME ct] pinf_neq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   188
                    val nmilth = tinU RS nmilbnd_neq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   189
                    val npiuth = tinU RS npiubnd_neq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   190
                    val lindth = tinU RS lin_dense_neq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   191
                in ([],myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   192
                end 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   193
            else
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   194
                let val cfm = cterm_of sg fm 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   195
                    val mith = instantiate' [] [SOME cfm] minf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   196
                    val pith = instantiate' [] [SOME cfm] pinf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   197
                    val nmilth = instantiate' [] [SOME cfm, SOME CU] nmilbnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   198
                    val npiuth = instantiate' [] [SOME cfm, SOME CU] npiubnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   199
                    val lindth = instantiate' [] [SOME CU, SOME cfm] lin_dense_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   200
                in ([], myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   201
                end
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   202
          | _ => let val cfm = cterm_of sg fm 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   203
                     val mith = instantiate' [] [SOME cfm] minf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   204
                     val pith = instantiate' [] [SOME cfm] pinf_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   205
                     val nmilth = instantiate' [] [SOME cfm, SOME CU] nmilbnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   206
                     val npiuth = instantiate' [] [SOME cfm, SOME CU] npiubnd_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   207
                     val lindth = instantiate' [] [SOME CU, SOME cfm] lin_dense_fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   208
                 in ([], myfwd (mith,pith,nmilth,npiuth,lindth))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   209
                 end)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   210
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   211
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   212
fun ferrack_eq thy p = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   213
    case p of
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   214
        Const("Ex",_)$Abs(x1,T,p1) => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   215
        let val (xn,fm) = variant_abs(x1,T,p1)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   216
            val x = Free(xn,T)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   217
            val (u,cu,uths,uf) = inusetthms thy x fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   218
            val (mi,pi,nmi,npi,lind) = divide_and_conquer (decomp_mpinf thy x (u,cu,uths)) fm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   219
            val frth = [uf,lind,nmi,npi,mi,pi] MRS fr_eq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   220
            val (cTp,ceq) = Thm.dest_comb (cprop_of frth)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   221
            val qth = (Simplifier.rewrite (HOL_basic_ss addsimps fr_simps addsimps [refl]) 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   222
                                          (snd (Thm.dest_comb ceq))) RS meta_eq_to_obj_eq
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   223
        in [frth,qth] MRS trans
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   224
        end
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   225
      | _ => instantiate' [SOME cbT] [SOME (cterm_of thy p)] refl;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   226
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   227
(* Code for normalization of terms and Formulae *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   228
    (* For NNF reuse the CooperProof methods*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   229
    (*FIXME:: This is copied from cooper_proof.ML *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   230
val FWD = fn th => fn ths => ths MRS th;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   231
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   232
val qe_Not = thm "qe_Not";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   233
val qe_conjI = thm "qe_conjI";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   234
val qe_disjI = thm "qe_disjI";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   235
val qe_impI = thm "qe_impI";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   236
val qe_eqI = thm "qe_eqI";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   237
val qe_exI = thm "qe_exI";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   238
val qe_ALLI = thm "qe_ALLI";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   239
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   240
val nnf_nn = thm "nnf_nn";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   241
val nnf_im = thm "nnf_im";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   242
val nnf_eq = thm "nnf_eq";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   243
val nnf_sdj = thm "nnf_sdj";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   244
val nnf_ncj = thm "nnf_ncj";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   245
val nnf_nim = thm "nnf_nim";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   246
val nnf_neq = thm "nnf_neq";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   247
val nnf_ndj = thm "nnf_ndj";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   248
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   249
fun decomp_cnnf lfnp P = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   250
    case P of 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   251
        Const ("op &",_) $ p $q => ([p,q] , FWD qe_conjI )
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   252
      | Const ("op |",_) $ p $q => ([p,q] , FWD qe_disjI)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   253
      | Const ("Not",_) $ (Const("Not",_) $ p) => ([p], FWD nnf_nn)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   254
      | Const("Not",_) $ (Const(opn,T) $ p $ q) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   255
        if opn = "op |" 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   256
        then 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   257
            (case (p,q) of 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   258
                 (A as (Const ("op &",_) $ r $ s),B as (Const ("op &",_) $ r1 $ t)) =>
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   259
                 if r1 = CooperDec.negate r 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   260
                 then  ([r,HOLogic.Not$s,r1,HOLogic.Not$t],
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   261
                        fn [th1_1,th1_2,th2_1,th2_2] => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   262
                           [[th1_1,th1_1] MRS qe_conjI,[th2_1,th2_2] MRS qe_conjI] MRS nnf_sdj)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   263
                       
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   264
                 else ([HOLogic.Not $ p,HOLogic.Not $ q ], FWD nnf_ndj)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   265
               | (_,_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], FWD nnf_ndj))
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   266
        else (
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   267
              case (opn,T) of 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   268
                  ("op &",_) => ([HOLogic.Not $ p,HOLogic.Not $ q ], FWD nnf_ncj )
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   269
                | ("op -->",_) => ([p,HOLogic.Not $ q ], FWD nnf_nim )
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   270
                | ("op =",Type ("fun",[Type ("bool", []),_])) => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   271
                  ([HOLogic.conj $ p $ (HOLogic.Not $ q),HOLogic.conj $ (HOLogic.Not $ p) $ q], 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   272
                   FWD nnf_neq)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   273
                | (_,_) => ([], fn [] => lfnp P))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   274
      | (Const ("op -->",_) $ p $ q) => ([HOLogic.Not$p,q], FWD nnf_im)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   275
      | (Const ("op =", Type ("fun",[Type ("bool", []),_])) $ p $ q) =>
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   276
        ([HOLogic.conj $ p $ q,HOLogic.conj $ (HOLogic.Not $ p) $ (HOLogic.Not $ q) ], FWD nnf_eq )
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   277
      | _ => ([], fn [] => lfnp P);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   278
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   279
fun nnfp afnp vs p = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   280
    let val th = divide_and_conquer (decomp_cnnf (afnp vs)) p
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   281
        val Pth = (Simplifier.rewrite 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   282
                       (HOL_basic_ss addsimps fr_simps addsimps [refl]) 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   283
                       (snd(Thm.dest_comb(snd(Thm.dest_comb (cprop_of th))))))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   284
                      RS meta_eq_to_obj_eq
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   285
    in [th,Pth] MRS trans
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   286
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   287
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   288
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   289
    (* Normalization of arithmetical expressions *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   290
val rzero = Const("0",rT);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   291
val rone = Const("1",rT);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   292
fun mk_real i = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   293
    case i of 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   294
        0 => rzero
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   295
      | 1 => rone
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   296
      | _ => (HOLogic.number_of_const rT)$(HOLogic.mk_binum i); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   297
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   298
fun dest_real (Const("0",_)) = 0
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   299
  | dest_real (Const("1",_)) = 1
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   300
  | dest_real (Const("Numeral.number_of",_)$b) = HOLogic.dest_binum b;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   301
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   302
        (* Normal form for terms is: 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   303
         (c0*x0 + ... + cn*xn + k) / c , where ci!=0 and x0<..<xn ordered according to vs*)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   304
        (* functions to prove trivial properties about numbers *)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   305
fun proveq thy n m = prove_bysimp thy (simpset_of thy) (HOLogic.mk_eq(mk_real n,mk_real m));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   306
fun provenz thy n = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   307
    prove_bysimp thy (simpset_of thy) (HOLogic.Not$(HOLogic.mk_eq(mk_real n,rzero)));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   308
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   309
fun proveprod thy m n = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   310
    prove_bysimp thy (simpset_of thy) 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   311
                 (HOLogic.mk_eq(HOLogic.mk_binop "HOL.times" (mk_real m,mk_real n),mk_real (m*n)));
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   312
fun proveadd thy m n = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   313
    prove_bysimp thy (simpset_of thy) 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   314
                 (HOLogic.mk_eq(HOLogic.mk_binop "HOL.plus" (mk_real m,mk_real n),mk_real (m+n)));
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   315
fun provediv thy m n = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   316
    let val g = gcd (m,n) 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   317
        val m' = m div g
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   318
        val n'= n div g
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   319
    in
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   320
        (prove_bysimp thy (simpset_of thy) 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   321
                     (HOLogic.mk_eq(HOLogic.mk_binop "HOL.divide" (mk_real m,mk_real n),
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   322
                                    HOLogic.mk_binop "HOL.divide" 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   323
                                                     (mk_real m',mk_real n'))),m')
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   324
    end;
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   325
                 (* Multiplication of a normal term by a constant *)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   326
val ncmul_congh = thm "ncmul_congh";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   327
val ncmul_cong = thm "ncmul_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   328
fun decomp_ncmulh thy c t = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   329
    if c = 0 then ([],fn _ => instantiate' [SOME crT] [SOME (cterm_of thy t)] mult_zero_left) else 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   330
    case t of 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   331
        Const("HOL.plus",_)$(Const("HOL.times",_)$c'$v)$b => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   332
        ([b],FWD (instantiate' [] [NONE, NONE, SOME (cterm_of thy v)] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   333
                               ((proveprod thy c (dest_real c')) RS ncmul_congh)))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   334
      | _ => ([],fn _ => proveprod thy c (dest_real t));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   335
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   336
fun prove_ncmulh thy c = divide_and_conquer (decomp_ncmulh thy c);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   337
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   338
    (* prove_ncmul thy n t n = a theorem : "c*(t/n) = (t'/n')*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   339
fun prove_ncmul thy c (t,m) = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   340
    let val (eq1,c') = provediv thy c m
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   341
        val tt' = prove_ncmulh thy c' t
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   342
    in [eq1,tt'] MRS ncmul_cong
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   343
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   344
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   345
    (* prove_nneg returns "-(t/n) = t'/n'" ; normally t'=t and n' = -n*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   346
val nneg_cong = thm "nneg_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   347
fun prove_nneg thy (t,m) = (prove_ncmul thy ~1 (t, m)) RS nneg_cong;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   348
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   349
(* Addition of 2 expressions in normal form*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   350
val naddh_cong_same = thm "naddh_cong_same";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   351
val naddh_cong_same0 = thm "naddh_cong_same0";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   352
val naddh_cong_ts = thm "naddh_cong_ts";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   353
val naddh_cong_st = thm "naddh_cong_st";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   354
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   355
fun earlier [] x y = false 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   356
  | earlier (h::t) x y =
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   357
    if h = y then false 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   358
    else if h = x then true 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   359
    else earlier t x y ; 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   360
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   361
fun decomp_naddh thy vs (t,s) = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   362
    case (t,s) of 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   363
        (Const("HOL.plus",_)$(ctv as Const("HOL.times",_)$tc$tv)$tr, 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   364
         Const("HOL.plus",_)$(csv as Const("HOL.times",_)$sc$sv)$sr) =>
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   365
        if tv = sv then 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   366
            let val ntc = dest_real tc
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   367
                val nsc = dest_real sc
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   368
                val addth = proveadd thy ntc nsc
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   369
            in if ntc + nsc = 0 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   370
               then ([(tr,sr)], FWD (instantiate' [] [NONE,NONE,NONE,SOME (cterm_of thy tv)] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   371
                                                  (addth RS naddh_cong_same0)))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   372
               else ([(tr,sr)], FWD (instantiate' [] [NONE,NONE,NONE,SOME (cterm_of thy tv)] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   373
                                                  (addth RS naddh_cong_same)))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   374
            end
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   375
        else if earlier vs tv sv 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   376
        then ([(tr,s)],FWD (instantiate' [] [NONE,NONE,NONE,SOME(cterm_of thy ctv)] naddh_cong_ts))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   377
        else ([(t,sr)],FWD (instantiate' [] [NONE,NONE,NONE,SOME(cterm_of thy csv)] naddh_cong_st))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   378
      | (Const("HOL.plus",_)$(ctv as Const("HOL.times",_)$tc$tv)$tr,_) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   379
        ([(tr,s)],FWD (instantiate' [] [NONE,NONE,NONE,SOME(cterm_of thy ctv)] naddh_cong_ts))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   380
      | (_,Const("HOL.plus",_)$(csv as Const("HOL.times",_)$sc$sv)$sr) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   381
        ([(t,sr)],FWD (instantiate' [] [NONE,NONE,NONE,SOME(cterm_of thy csv)] naddh_cong_st))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   382
      | (_,_) => ([], fn _ => proveadd thy (dest_real t) (dest_real s));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   383
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   384
    (* prove_naddh returns "t + s = t'*) 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   385
fun prove_naddh thy vs = divide_and_conquer (decomp_naddh thy vs);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   386
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   387
val nadd_cong_same = thm "nadd_cong_same";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   388
val nadd_cong = thm "nadd_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   389
val plus_cong = thm "plus_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   390
    (* prove_nadd resturns: "t/m + s/n = t'/m'"*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   391
fun prove_nadd thy vs (t,m) (s,n) = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   392
    if n=m then 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   393
        let val nm = proveq thy n m
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   394
            val ts = prove_naddh thy vs (t,s)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   395
        in [nm,ts] MRS nadd_cong_same
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   396
        end
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   397
    else let val l = lcm (m,n)
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   398
             val m' = l div m
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   399
             val n' = l div n
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   400
             val mml = proveprod thy m' m
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   401
             val nnl = proveprod thy n' n
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   402
             val mnz = provenz thy m
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   403
             val nnz = provenz thy n
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   404
             val lnz = provenz thy l
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   405
             val mt = prove_ncmulh thy m' t
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   406
             val ns = prove_ncmulh thy n' s
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   407
             val _$(_$_$t') = prop_of mt
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   408
             val _$(_$_$s') = prop_of ns
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   409
         in [mml,nnl,mnz,nnz,lnz,[mt,ns,prove_naddh thy vs (t',s')] MRS plus_cong] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   410
                MRS nadd_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   411
         end;
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   412
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   413
    (* prove_nsub returns: "t/m - s/n = t'/m'"*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   414
val nsub_cong = thm "nsub_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   415
fun prove_nsub thy vs (t,m) (s,n) = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   416
    let val nsm = prove_nneg thy (s,n)
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   417
        val _$(_$_$(_$s'$n')) = prop_of nsm
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   418
        val ts = prove_nadd thy vs (t,m) (s',dest_real n')
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   419
    in [nsm,ts] MRS nsub_cong
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   420
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   421
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   422
val ndivide_cong = thm "ndivide_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   423
fun prove_ndivide thy (t,m) n = instantiate' [] [SOME(cterm_of thy t)] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   424
                                             ((proveprod thy m n) RS ndivide_cong);
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   425
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   426
exception FAILURE of string;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   427
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   428
val divide_cong = thm"divide_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   429
val diff_cong = thm"diff_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   430
val uminus_cong = thm"uminus_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   431
val mult_cong = thm"mult_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   432
val mult_cong2 = thm"mult_cong2";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   433
val normalizeh_var = thm "normalizeh_var";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   434
val nrefl = thm "nrefl";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   435
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   436
fun decomp_normalizeh thy vs t =
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   437
    case t of
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   438
        Free _ => ([], fn _ => instantiate' [] [SOME(cterm_of thy t)] normalizeh_var)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   439
      | Const("HOL.uminus",_)$a => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   440
        ([a], 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   441
         fn [tha] => let val _$(_$_$(_$a'$n')) = prop_of tha
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   442
                         in [tha,prove_nneg thy (a',dest_real n')] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   443
                                MRS uminus_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   444
                         end )
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   445
      | Const("HOL.plus",_)$a$b => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   446
        ([a,b], 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   447
         fn [tha,thb] => let val _$(_$_$(_$a'$n')) = prop_of tha
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   448
                             val _$(_$_$(_$b'$m')) = prop_of thb
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   449
                         in [tha,thb,prove_nadd thy vs (a',dest_real n') (b',dest_real m')] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   450
                                MRS plus_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   451
                         end )
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   452
      | Const("HOL.minus",_)$a$b => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   453
        ([a,b], 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   454
         fn [tha,thb] => let val _$(_$_$(_$a'$n')) = prop_of tha
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   455
                             val _$(_$_$(_$b'$m')) = prop_of thb
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   456
                         in [tha,thb,prove_nsub thy vs (a',dest_real n') (b',dest_real m')] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   457
                                MRS diff_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   458
                         end )
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   459
      | Const("HOL.times",_)$a$b => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   460
        if can dest_real a 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   461
        then ([b], fn [thb] => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   462
                      let val _$(_$_$(_$b'$m')) = prop_of thb
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   463
                      in [thb, prove_ncmul thy (dest_real a) (b',dest_real m')] MRS mult_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   464
                      end )
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   465
        else if can dest_real b
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   466
        then ([a], fn [tha] => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   467
                      let val _$(_$_$(_$a'$m')) = prop_of tha
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   468
                      in [tha, prove_ncmul thy (dest_real b) (a',dest_real m')] MRS mult_cong2
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   469
                      end )
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   470
        else raise FAILURE "decomp_normalizeh: non linear term"
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   471
      | Const("HOL.divide",_)$a$b => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   472
        if can dest_real b
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   473
        then ([a], fn [tha] => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   474
                      let val _$(_$_$(_$a'$m')) = prop_of tha
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   475
                      in [tha, prove_ndivide thy (a',dest_real m') (dest_real b)] MRS divide_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   476
                      end )
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   477
        else raise FAILURE "decomp_normalizeh: non linear term"
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   478
      | _ => ([], fn _ => instantiate' [] [SOME (cterm_of thy t)] nrefl);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   479
fun prove_normalizeh thy vs = divide_and_conquer (decomp_normalizeh thy vs);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   480
fun dest_xth vs th = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   481
    let val _$(_$_$(_$t$n)) = prop_of th
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   482
    in (case t of 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   483
            Const("HOL.plus",_)$(Const("HOL.times",_)$c$y)$r => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   484
            if vs = [] then (0,t,dest_real n)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   485
            else if hd vs = y then (dest_real c, r,dest_real n)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   486
            else (0,t,dest_real n)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   487
          | _ => (0,t,dest_real n))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   488
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   489
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   490
fun prove_strictsign thy n = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   491
    prove_bysimp thy (simpset_of thy) 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   492
                 (HOLogic.mk_binrel "Orderings.less" 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   493
                                    (if n > 0 then (rzero, mk_real n) else (mk_real n, rzero))); 
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   494
fun prove_fracsign thy (m,n) = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   495
    let val mn = HOLogic.mk_binop "HOL.divide" (mk_real m, mk_real n)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   496
    in prove_bysimp thy (simpset_of thy) 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   497
                 (HOLogic.mk_binrel "Orderings.less" 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   498
                                    (if m*n > 0 then (rzero, mn) else (mn, rzero)))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   499
    end; 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   500
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   501
fun holbool_of true = HOLogic.true_const
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   502
  | holbool_of false = HOLogic.false_const;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   503
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   504
fun prove_fracsign_eq thy s (m,n) = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   505
    let fun f s = the (AList.lookup (op =) [("Orderings.less", op <),("Orderings.less_eq", op <=),("op =", op =)] s)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   506
    in 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   507
    prove_bysimp thy (simpset_of thy) (HOLogic.mk_eq
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   508
                 (HOLogic.mk_binrel s 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   509
                                    (HOLogic.mk_binop "HOL.divide" (mk_real m, mk_real n),rzero), 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   510
                                    holbool_of (f s (m*n,0))))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   511
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   512
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   513
fun proveq_eq thy n m = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   514
    prove_bysimp thy (simpset_of thy) 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   515
                 (HOLogic.mk_eq 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   516
                      (HOLogic.mk_eq(mk_real n, mk_real m),holbool_of (n = m)));
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   517
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   518
val sum_of_same_denoms = thm "sum_of_same_denoms";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   519
val sum_of_opposite_denoms = thm "sum_of_opposite_denoms";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   520
val trivial_sum_of_opposites = thm "trivial_sum_of_opposites";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   521
val normalize_ltground_cong = thm "normalize_ltground_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   522
val normalize_ltnoxpos_cong = thm "normalize_ltnoxpos_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   523
val normalize_ltnoxneg_cong = thm "normalize_ltnoxneg_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   524
val normalize_ltxpos_cong = thm "normalize_ltxpos_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   525
val normalize_ltxneg_cong = thm "normalize_ltxneg_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   526
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   527
val normalize_leground_cong = thm "normalize_leground_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   528
val normalize_lenoxpos_cong = thm "normalize_lenoxpos_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   529
val normalize_lenoxneg_cong = thm "normalize_lenoxneg_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   530
val normalize_lexpos_cong = thm "normalize_lexpos_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   531
val normalize_lexneg_cong = thm "normalize_lexneg_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   532
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   533
val normalize_eqground_cong = thm "normalize_eqground_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   534
val normalize_eqnox_cong = thm "normalize_eqnox_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   535
val normalize_eqxpos_cong = thm "normalize_eqxpos_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   536
val normalize_eqxneg_cong = thm "normalize_eqxneg_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   537
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   538
val normalize_not_lt = thm "normalize_not_lt";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   539
val normalize_not_le = thm "normalize_not_le";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   540
val normalize_not_eq = thm "normalize_not_eq";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   541
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   542
fun prove_normalize thy vs at = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   543
    case at of 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   544
        Const("Orderings.less",_)$s$t => 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   545
        let val smtth = prove_normalizeh thy vs (HOLogic.mk_binop "HOL.minus" (s,t))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   546
            val (cx,r,n) = dest_xth vs smtth
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   547
        in if cx = 0 then if can dest_real r 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   548
                          then [smtth, prove_fracsign_eq thy "Orderings.less" (dest_real r, n)]
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   549
                                   MRS normalize_ltground_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   550
                          else [smtth, prove_strictsign thy n] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   551
                                   MRS (if n > 0 then normalize_ltnoxpos_cong 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   552
                                        else normalize_ltnoxneg_cong)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   553
           else let val srn = prove_fracsign thy (n,cx)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   554
                    val rr' = if cx < 0 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   555
                              then instantiate' [] [SOME (cterm_of thy r)]
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   556
                                                ((proveadd thy cx (~cx)) RS sum_of_opposite_denoms)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   557
                              else instantiate' [] [SOME (cterm_of thy (mk_real cx))] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   558
                                                (((prove_ncmulh thy ~1 r) RS nneg_cong) 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   559
                                                           RS sum_of_same_denoms)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   560
                in [smtth,srn,rr'] MRS (if n*cx < 0 then normalize_ltxneg_cong 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   561
                                        else normalize_ltxpos_cong)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   562
                end
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   563
        end
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   564
      | Const("Orderings.less_eq",_)$s$t => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   565
        let val smtth = prove_normalizeh thy vs (HOLogic.mk_binop "HOL.minus" (s,t))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   566
            val (cx,r,n) = dest_xth vs smtth
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   567
        in if cx = 0 then if can dest_real r 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   568
                          then [smtth, prove_fracsign_eq thy "Orderings.less_eq" (dest_real r, n)]
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   569
                                   MRS normalize_leground_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   570
                          else [smtth, prove_strictsign thy n] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   571
                                   MRS (if n > 0 then normalize_lenoxpos_cong 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   572
                                        else normalize_lenoxneg_cong)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   573
           else let val srn = prove_fracsign thy (n,cx)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   574
                    val rr' = if cx < 0 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   575
                              then instantiate' [] [SOME (cterm_of thy r)]
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   576
                                                ((proveadd thy cx (~cx)) RS sum_of_opposite_denoms)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   577
                              else instantiate' [] [SOME (cterm_of thy (mk_real cx))] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   578
                                                (((prove_ncmulh thy ~1 r) RS nneg_cong) 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   579
                                                           RS sum_of_same_denoms)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   580
                in [smtth,srn,rr'] MRS (if n*cx < 0 then normalize_lexneg_cong 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   581
                                        else normalize_lexpos_cong)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   582
                end
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   583
        end
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   584
      | Const("op =",_)$s$t => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   585
        let val smtth = prove_normalizeh thy vs (HOLogic.mk_binop "HOL.minus" (s,t))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   586
            val (cx,r,n) = dest_xth vs smtth
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   587
        in if cx = 0 then if can dest_real r 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   588
                          then [smtth, provenz thy n, 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   589
                                proveq_eq thy (dest_real r) 0]
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   590
                                   MRS normalize_eqground_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   591
                          else [smtth, provenz thy n] 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   592
                                   MRS normalize_eqnox_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   593
           else let val scx = prove_strictsign thy cx
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   594
                    val nnz = provenz thy n
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   595
                    val rr' = if cx < 0 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   596
                              then proveadd thy cx (~cx)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   597
                              else ((prove_ncmulh thy ~1 r) RS nneg_cong) 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   598
                                       RS trivial_sum_of_opposites
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   599
                in [smtth,scx,nnz,rr'] MRS (if cx < 0 then normalize_eqxneg_cong 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   600
                                        else normalize_eqxpos_cong)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   601
                end
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   602
        end
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   603
      | Const("Not",_)$(Const("Orderings.less",T)$s$t) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   604
        (prove_normalize thy vs (Const("Orderings.less_eq",T)$t$s)) RS normalize_not_lt
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   605
      | Const("Not",_)$(Const("Orderings.less_eq",T)$s$t) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   606
        (prove_normalize thy vs (Const("Orderings.less",T)$t$s)) RS normalize_not_le
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   607
      | (nt as Const("Not",_))$(Const("op =",T)$s$t) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   608
        (prove_normalize thy vs (Const("op =",T)$s$t)) RS qe_Not
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   609
      | _ => instantiate' [SOME cbT] [SOME (cterm_of thy at)] refl;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   610
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   611
     (* Generic quantifier elimination *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   612
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   613
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   614
val qe_ex_conj = thm "qe_ex_conj";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   615
val qe_ex_nconj = thm "qe_ex_nconj";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   616
val qe_ALL = thm "qe_ALL";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   617
val ex_eq_cong = thm "ex_eq_cong";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   618
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   619
fun decomp_genqelim thy afnp nfnp qfnp (P,vs) = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   620
    case P of
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   621
        (Const("op &",_)$A$B) => ([(A,vs),(B,vs)], fn [th1,th2] => [th1,th2] MRS qe_conjI)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   622
      | (Const("op |",_)$A$B) => ([(A,vs),(B,vs)], fn [th1,th2] => [th1,th2] MRS qe_disjI)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   623
      | (Const("op -->",_)$A$B) => ([(A,vs),(B,vs)], fn [th1,th2] => [th1,th2] MRS qe_impI)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   624
      | (Const("op =", Type ("fun",[Type ("bool", []),_]))$A$B) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   625
        ([(A,vs),(B,vs)], fn [th1,th2] => [th1,th2] MRS qe_eqI)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   626
      | (Const("Not",_)$p) => ([(p,vs)],fn [th] => th RS qe_Not)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   627
      | (Const("Ex",_)$Abs(xn,xT,p)) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   628
        let val (xn1,p1) = variant_abs(xn,xT,p)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   629
            val x= Free(xn1,xT)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   630
        in ([(p1,x::vs)],
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   631
            fn [th1_1] => 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   632
               let val th2 = [th1_1,nfnp (x::vs) (snd (CooperProof.qe_get_terms th1_1))] MRS trans
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   633
                   val eth1 = (forall_intr (cterm_of thy (Free(xn1,xT))) th2) COMP  ex_eq_cong
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   634
                   val th3 = qfnp (snd(CooperProof.qe_get_terms eth1))
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   635
               in [eth1,th3] MRS trans
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   636
               end )
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   637
        end
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   638
      | (Const("All",_)$Abs(xn,xT,p)) => 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   639
        ([((HOLogic.exists_const xT)$Abs(xn,xT,HOLogic.Not $ p),vs)], fn [th] => th RS qe_ALL)
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   640
      | _ => ([], fn [] => afnp vs P);
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   641
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   642
val fr_prepqelim = thms "fr_prepqelim";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   643
val prepare_qelim_ss = HOL_basic_ss 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   644
                           addsimps simp_thms 
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   645
                           addsimps (List.take(ex_simps,4))
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   646
                           addsimps fr_prepqelim
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   647
                           addsimps [not_all,ex_disj_distrib];
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   648
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   649
fun prove_genqelim thy afnp nfnp qfnp P = 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   650
    let val thP = (Simplifier.rewrite prepare_qelim_ss P) RS meta_eq_to_obj_eq
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   651
        val _$(_$_$P') = prop_of thP
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   652
        val vs = term_frees P'
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   653
        val qeth = divide_and_conquer (decomp_genqelim thy afnp nfnp qfnp) (Pattern.eta_long [] P',vs)
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   654
        val _$(_$_$p'') = prop_of qeth
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   655
        val thp' = nfnp vs p''
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   656
    in [[thP, qeth] MRS trans, thp'] MRS trans
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   657
    end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   658
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   659
fun qelim P =
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   660
  let val {thy, ...} = Thm.rep_cterm P
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   661
  in prove_genqelim thy (prove_normalize thy) (nnfp (prove_normalize thy)) (ferrack_eq thy) P end;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   662
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   663
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   664
    (* Just for testing!! *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   665
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   666
val thy = the_context();
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   667
fun parseb s = term_of (read_cterm thy (s,HOLogic.boolT));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   668
fun parser s = term_of (read_cterm thy (s,rT));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   669
val fm = parseb "(x::real) < y + t & (y - 5 < x | 34 < y + t) & (x = s + 3*y) | (x ~= y - s)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   670
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   671
provediv thy 4 2;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   672
provediv thy ~4 2;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   673
provediv thy 4 ~2;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   674
provediv thy 44 32;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   675
provediv thy ~34 20000;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   676
provediv thy ~4000000 ~27676;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   677
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   678
val vs = [Free("x",rT),Free("y",rT),Free("z",rT)] ;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   679
prove_nsub thy vs
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   680
                    (parser "4*(x::real) + (3*y + 5)" ,54) (parser "3*(y::real) + (4*z + 5)",9);
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   681
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   682
prove_ndivide thy (parser "4*(x::real) + (3*y + 5)" ,5) 4;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   683
prove_normalizeh thy [Free("x",rT),Free("y",rT),Free("z",rT)] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   684
                    (parser "4*(x::real) + 3* ((3*y + 5) + x)");
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   685
prove_normalizeh thy [Free("x",rT),Free("y",rT),Free("z",rT)] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   686
                    (parser "4*(x::real) - 3* ((3*y + 5)*9 + x)");
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   687
prove_normalizeh thy [Free("x",rT),Free("y",rT),Free("z",rT)] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   688
                    (parser "- x");
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   689
prove_normalizeh thy [Free("x",rT),Free("y",rT),Free("z",rT)] 
20049
f48c4a3a34bc Goal.prove: context;
wenzelm
parents: 19640
diff changeset
   690
                    (parser "4*(x::real) +3* ((3*y + 5) / 3 - (- x))");
19640
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   691
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   692
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   693
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   694
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   695
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   696
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   697
fun test xn s = ferrack_eq thy (parseb ("EX (" ^ xn ^ "::real)." ^ s));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   698
test "x" "(x::real) < y + t & (y - 5 < x | 34 < y + t) & (x = s + 3*y) | (x ~= y - s) & (x::real) <= y + t & (y - 5 <= x)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   699
test "x" "(x::real) < y + t & y - 5 < x & (x ~= y - s)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   700
test "x" "(x::real) < y + t";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   701
test "x" "(x::real) > y + t";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   702
test "x" "(x::real) = y + t";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   703
test "x" "(x::real) ~= y + t";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   704
test "x" "34 < y + (t::real)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   705
test "x" "(x::real) ~= y + t & 34 < y + (t::real)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   706
test "x" "(x::real) ~= y + t & (x::real) < y + t";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   707
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   708
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 <= x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   709
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 <= 3*x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   710
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 <= (-1)*x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   711
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 <= x + 3 + 4* (y - 15*z) / 3 "); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   712
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   713
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 < x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   714
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 < 3*x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   715
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 < (-1)*x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   716
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 < x + 3 + 4* (y - 15*z) / 3 "); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   717
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   718
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 = x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   719
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 = 3*x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   720
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 = (-1)*x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   721
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 = x + 3 + 4* (y - 15*z) / 3 "); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   722
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   723
prove_normalize thy vs (parseb "~ ((x::real) + 4* (y - 15*z) / 3 <= x + y)"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   724
prove_normalize thy vs (parseb "~ ((x::real) + 4* (y - 15*z) / 3 <= 3*x + y)"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   725
prove_normalize thy vs (parseb "~ ((x::real) + 4* (y - 15*z) / 3 <= (-1)*x + y)"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   726
prove_normalize thy vs (parseb "~ ((x::real) + 4* (y - 15*z) / 3 <= x + 3 + 4* (y - 15*z) / 3 )"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   727
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   728
prove_normalize thy vs (parseb "~((x::real) + 4* (y - 15*z) / 3 < x + y)"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   729
prove_normalize thy vs (parseb "~((x::real) + 4* (y - 15*z) / 3 < 3*x + y)"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   730
prove_normalize thy vs (parseb "~((x::real) + 4* (y - 15*z) / 3 < (-1)*x + y)"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   731
prove_normalize thy vs (parseb "~((x::real) + 4* (y - 15*z) / 3 < x + 3 + 4* (y - 15*z) / 3 )"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   732
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   733
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 ~= x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   734
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 ~= 3*x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   735
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 ~= (-1)*x + y"); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   736
prove_normalize thy vs (parseb "(x::real) + 4* (y - 15*z) / 3 ~= x + 3 + 4* (y - 15*z) / 3 "); 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   737
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   738
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   739
nnfp (prove_normalize thy) vs
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   740
     (parseb "~((x::real) + 4* (y - 15*z) / 3 ~= x + 3 + 4* (y - 15*z) / 3 | (~ (~((x::real) + 4* (y - 15*z) / 3 < x + 3 + 4* (y - 15*z) / 3 ) & (x::real) + 4* (y - 15*z) / 3 <= x + y)))");
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   741
nnfp (prove_normalize thy) vs
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   742
     (parseb "~ ~((x::real) + 4* (y - 15*z) / 3 ~= x + 3 + 4* (y - 15*z) / 3 | (~ (~((x::real) + 4* (y - 15*z) / 3 < x + 3 + 4* (y - 15*z) / 3 ) & (x::real) + 4* (y - 15*z) / 3 <= x + y)))");
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   743
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   744
fun frtest s = frqelim thy (read_cterm thy (s,HOLogic.boolT));
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   745
frtest "~ (ALL (x::real) y. x < y --> 10*x < 11*y)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   746
frtest "ALL (x::real) y. x < y --> (10*(x + 5*y + -1) < 60*y)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   747
frtest "EX (x::real) y. x ~= y --> x < y";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   748
frtest "EX (x::real) y. (x ~= y & 10*x ~= 9*y & 10*x < y) --> x < y";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   749
frtest "ALL (x::real) y. (x ~= y & 5*x <= y) --> 500*x <= 100*y";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   750
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   751
  (* 1 Alternations *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   752
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   753
frtest "ALL (x::real). (EX (y::real). 4*x + 3*y <= 0 & 4*x + 3*y >= -1)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   754
frtest "ALL (x::real) < 0. (EX (y::real) > 0. 7*x + y > 0 & x - y <= 9)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   755
frtest "EX (x::real). (0 < x & x < 1) --> (ALL y > 1. x + y ~= 1)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   756
frtest "EX (x::real). 0 < x & x < 1 & (ALL y. (1 < y & y < 2) --> (1 < 2*(y - x) & 2*(y - x) <3))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   757
frtest "ALL (x::real). x < 10 | x > 20 | (EX y. y>= 0 & y <= 10 & x+y = 20)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   758
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   759
    (* Formulae with 3 quantifiers *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   760
  (* 0 Alternations *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   761
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   762
frtest "ALL (x::real) y z. x + y < z --> y >= z --> x < 0";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   763
frtest "EX (x::real) y z. x + 7*y < 5* z & 5*y >= 7*z & x < 0";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   764
frtest "ALL (x::real) y z. abs (x + y) <= z --> (abs z = z)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   765
frtest "EX (x::real) y z. x + 7*y - 5* z < 0 & 5*y + 7*z + 3*x < 0";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   766
frtest "ALL (x::real) y z. (abs (5*x+3*y+z) <= 5*x+3*y+z & abs (5*x+3*y+z) >= - (5*x+3*y+z)) | (abs (5*x+3*y+z) >= 5*x+3*y+z & abs (5*x+3*y+z) <= - (5*x+3*y+z))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   767
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   768
  (* 1 Alternations *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   769
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   770
frtest "ALL (x::real) y. x < y --> (EX z>0. x+z = y)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   771
frtest "ALL (x::real) y. (EX z>0. abs (x - y) <= z )";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   772
frtest "EX (x::real) y. (ALL z>0. (z < x --> z <= 5) & (z > y --> z >= x))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   773
frtest "EX (x::real) y. (ALL z<0. (z < x --> z <= y) & (z > y --> z >= x))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   774
frtest "EX (x::real) y. (ALL z>0. abs (3*x - 7*y) >= 5 & abs (3*x+7*y) <= 2*z + 1)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   775
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   776
  (* 2 Alternations *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   777
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   778
frtest "EX (x::real)>0. (ALL y >0. (EX z>7. 5*x - 3*y <= 7*z))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   779
frtest "EX (x::real). abs x < 4 & (ALL y > 0. (EX z. 5*x - 3*y <= 7*z))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   780
frtest "ALL (x::real). (EX y > x. (ALL z < y. x+z < 2*y))" ;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   781
frtest "ALL (x::real). (EX y<(3*x - 1). (ALL z >= (3*x - 1). x - y + z > x ))" ;
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   782
frtest "EX (x::real). abs x < 100 & (ALL y > x. (EX z<2*y - x. 5*x - 3*y <= 7*z))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   783
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   784
    (* Formulae with 4 quantifiers *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   785
    (* 0 Alternations *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   786
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   787
frtest "ALL (x::real) y z w. 7*x<3*y --> 5*y < 7*z --> z < 2*w --> 7*(2*w-x) > 2*y";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   788
frtest "ALL (x::real) y. ALL z >x. ALL w > y. abs (z-x) + abs (y-w + x) <= z - x + w-y+abs x";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   789
frtest "EX (x::real) y z w. 5*x + 3*z - 17*w + abs (y - 8*x + z) <= 89";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   790
frtest "EX (x::real) y z w. abs (5*x + 3*z - 17*w) + 7* abs (y - 8*x + z) <= max y (7*z - x + w)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   791
frtest "EX (x::real) y z w. min (5*x + 3*z) (17*w) + 5* abs (y - 8*x + z) <= max y (7*z - x + w)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   792
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   793
    (* 1 Alternations *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   794
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   795
frtest "ALL (x::real) y z. (EX w >= abs (x+y+z). w <= abs x + abs y + abs z)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   796
frtest "ALL (x::real). (EX y z w. x< y & x < z & x> w & 3*x < w + y)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   797
frtest "ALL (x::real) y. (EX z w. abs (x-y) = abs (z-w) & z < x & w ~= y)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   798
frtest "ALL (x::real). (EX y z w. min (5*x + 3*z) (17*w) + 5* abs (y - 8*x + z) <= max y (7*z - x + w))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   799
frtest "EX (x::real) y z. (ALL w >= abs (x+y+z). w >= abs x + abs y + abs z)";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   800
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   801
    (* 2 Alternations *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   802
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   803
frtest "EX z. (ALL (x::real) y. (EX w >= abs (x+y+z). w <= abs x + abs y + abs z))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   804
frtest "EX z. (ALL (x::real) < z. (EX y w. x< y & x < z & x> w & 3*x < w + y))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   805
frtest "ALL (x::real) y. (EX z. (ALL w. abs (x-y) = abs (z-w) --> z < x & w ~= y))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   806
frtest "EX y. (ALL (x::real). (EX z w. min (5*x + 3*z) (17*w) + 5* abs (y - 8*x + z) <= max y (7*z - x + w)))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   807
frtest "EX (x::real) z. (ALL w >= abs (x+z). (EX y. w >= abs x + abs y + abs z))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   808
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   809
    (* 3 Alternations *)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   810
(*
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   811
frtest "EX (x::real). (ALL y < x. (EX z > (x+y). (ALL w. 5*w + 10*x - z >= y --> w + 7*x + 3*z >= 2*y)))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   812
frtest "EX (x::real). (ALL y < 3*x. (EX z > max x y. 
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   813
  (ALL w . abs w < 13 --> w + 10*x - z >= y --> 5*w + 7*x + 13*z >= 2*y)))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   814
frtest "ALL (x::real). (EX y. (ALL z>19. y <= x + z & (EX w. abs (y - x) < w)))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   815
frtest "ALL (x::real). (EX y. (ALL z>19. abs (y) <= abs (x + z) & (EX w. abs (x + z) < w - y)))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   816
frtest "ALL (x::real). (EX y. abs y ~= abs x & (ALL z> max x y. (EX w. w ~= y & w ~= z & 3*w - z >= x + y)))";
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   817
*)
40ec89317425 added Ferrante and Rackoff Algorithm -- by Amine Chaieb;
wenzelm
parents:
diff changeset
   818
end