src/HOL/Decision_Procs/ferrante_rackoff.ML
author haftmann
Fri, 27 Aug 2010 10:56:46 +0200
changeset 38795 848be46708dc
parent 38786 e46e7a9cb622
child 38864 4abe644fcea5
permissions -rw-r--r--
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37744
3daaf23b9ab4 tuned titles
haftmann
parents: 37120
diff changeset
     1
(* Title:      HOL/Decision_Procs/ferrante_rackoff.ML
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     2
   Author:     Amine Chaieb, TU Muenchen
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     3
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     4
Ferrante and Rackoff's algorithm for quantifier elimination in dense
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     5
linear orders.  Proof-synthesis and tactic.
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     6
*)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     7
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
     8
signature FERRANTE_RACKOFF =
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     9
sig
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    10
  val dlo_conv: Proof.context -> conv
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    11
  val dlo_tac: Proof.context -> int -> tactic
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    12
end;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    13
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    14
structure FerranteRackoff: FERRANTE_RACKOFF =
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    15
struct
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    16
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    17
open Ferrante_Rackoff_Data;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    18
open Conv;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    19
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    20
type entry = {minf: thm list, pinf: thm list, nmi: thm list, npi: thm list,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    21
   ld: thm list, qe: thm, atoms : cterm list} *
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    22
  {isolate_conv: cterm list -> cterm -> thm,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    23
                 whatis : cterm -> cterm -> ord,
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    24
                 simpset : simpset};
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    25
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    26
fun get_p1 th =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    27
  funpow 2 (Thm.dest_arg o snd o Thm.dest_abs NONE)
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    28
    (funpow 2 Thm.dest_arg (cprop_of th)) |> Thm.dest_arg
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    29
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    30
fun ferrack_conv
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    31
   (entr as ({minf = minf, pinf = pinf, nmi = nmi, npi = npi,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    32
              ld = ld, qe = qe, atoms = atoms},
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    33
             {isolate_conv = icv, whatis = wi, simpset = simpset}):entry) =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    34
let
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    35
 fun uset (vars as (x::vs)) p = case term_of p of
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
    36
   Const(@{const_name HOL.conj}, _)$ _ $ _ =>
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    37
     let
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    38
       val ((b,l),r) = Thm.dest_comb p |>> Thm.dest_comb
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    39
       val (lS,lth) = uset vars l  val (rS, rth) = uset vars r
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    40
     in (lS@rS, Drule.binop_cong_rule b lth rth) end
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
    41
 |  Const(@{const_name HOL.disj}, _)$ _ $ _ =>
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    42
     let
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    43
       val ((b,l),r) = Thm.dest_comb p |>> Thm.dest_comb
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    44
       val (lS,lth) = uset vars l  val (rS, rth) = uset vars r
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    45
     in (lS@rS, Drule.binop_cong_rule b lth rth) end
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    46
 | _ =>
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    47
    let
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    48
      val th = icv vars p
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    49
      val p' = Thm.rhs_of th
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    50
      val c = wi x p'
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    51
      val S = (if member (op =) [Lt, Le, Eq] c then single o Thm.dest_arg
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    52
               else if member (op =) [Gt, Ge] c then single o Thm.dest_arg1
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    53
               else if c = NEq then single o Thm.dest_arg o Thm.dest_arg
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    54
               else K []) p'
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    55
    in (S,th) end
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    56
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    57
 val ((p1_v,p2_v),(mp1_v,mp2_v)) =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    58
   funpow 2 (Thm.dest_arg o snd o Thm.dest_abs NONE)
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    59
     (funpow 4 Thm.dest_arg (cprop_of (hd minf)))
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    60
   |> Thm.dest_binop |> pairself Thm.dest_binop |> apfst (pairself Thm.dest_fun)
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    61
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    62
 fun myfwd (th1, th2, th3, th4, th5) p1 p2
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    63
      [(th_1,th_2,th_3,th_4,th_5), (th_1',th_2',th_3',th_4',th_5')] =
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    64
  let
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    65
   val (mp1, mp2) = (get_p1 th_1, get_p1 th_1')
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    66
   val (pp1, pp2) = (get_p1 th_2, get_p1 th_2')
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    67
   fun fw mi th th' th'' =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    68
     let
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    69
      val th0 = if mi then
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    70
           instantiate ([],[(p1_v, p1),(p2_v, p2),(mp1_v, mp1), (mp2_v, mp2)]) th
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    71
        else instantiate ([],[(p1_v, p1),(p2_v, p2),(mp1_v, pp1), (mp2_v, pp2)]) th
36945
9bec62c10714 less pervasive names from structure Thm;
wenzelm
parents: 36862
diff changeset
    72
     in Thm.implies_elim (Thm.implies_elim th0 th') th'' end
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    73
  in (fw true th1 th_1 th_1', fw false th2 th_2 th_2',
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    74
      fw true th3 th_3 th_3', fw false th4 th_4 th_4', fw true th5 th_5 th_5')
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    75
  end
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    76
 val U_v = (Thm.dest_arg o Thm.dest_arg o Thm.dest_arg1) (cprop_of qe)
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    77
 fun main vs p =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    78
  let
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    79
   val ((xn,ce),(x,fm)) = (case term_of p of
38558
32ad17fe2b9c tuned quotes
haftmann
parents: 38549
diff changeset
    80
                   Const(@{const_name Ex},_)$Abs(xn,xT,_) =>
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    81
                        Thm.dest_comb p ||> Thm.dest_abs (SOME xn) |>> pair xn
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    82
                 | _ => raise CTERM ("main QE only treats existential quantifiers!", [p]))
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    83
   val cT = ctyp_of_term x
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    84
   val (u,nth) = uset (x::vs) fm |>> distinct (op aconvc)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    85
   val nthx = Thm.abstract_rule xn x nth
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    86
   val q = Thm.rhs_of nth
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    87
   val qx = Thm.rhs_of nthx
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    88
   val enth = Drule.arg_cong_rule ce nthx
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    89
   val [th0,th1] = map (instantiate' [SOME cT] []) @{thms "finite.intros"}
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    90
   fun ins x th =
36945
9bec62c10714 less pervasive names from structure Thm;
wenzelm
parents: 36862
diff changeset
    91
      Thm.implies_elim (instantiate' [] [(SOME o Thm.dest_arg o Thm.dest_arg)
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    92
                                       (Thm.cprop_of th), SOME x] th1) th
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    93
   val fU = fold ins u th0
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    94
   val cU = funpow 2 Thm.dest_arg (Thm.cprop_of fU)
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    95
   local
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    96
     val insI1 = instantiate' [SOME cT] [] @{thm "insertI1"}
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    97
     val insI2 = instantiate' [SOME cT] [] @{thm "insertI2"}
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    98
   in
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
    99
    fun provein x S =
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   100
     case term_of S of
32264
0be31453f698 Set.UNIV and Set.empty are mere abbreviations for top and bot
haftmann
parents: 32149
diff changeset
   101
        Const(@{const_name Orderings.bot}, _) => raise CTERM ("provein : not a member!", [S])
30304
d8e4cd2ac2a1 set operations Int, Un, INTER, UNION, Inter, Union, empty, UNIV are now proper qualified constants with authentic syntax
haftmann
parents: 24584
diff changeset
   102
      | Const(@{const_name insert}, _) $ y $_ =>
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   103
         let val (cy,S') = Thm.dest_binop S
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   104
         in if term_of x aconv y then instantiate' [] [SOME x, SOME S'] insI1
36945
9bec62c10714 less pervasive names from structure Thm;
wenzelm
parents: 36862
diff changeset
   105
         else Thm.implies_elim (instantiate' [] [SOME x, SOME S', SOME cy] insI2)
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   106
                           (provein x S')
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   107
         end
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   108
   end
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   109
   val tabU = fold (fn t => fn tab => Termtab.update (term_of t, provein t cU) tab)
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   110
                   u Termtab.empty
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   111
   val U = the o Termtab.lookup tabU o term_of
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   112
   val [minf_conj, minf_disj, minf_eq, minf_neq, minf_lt,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   113
        minf_le, minf_gt, minf_ge, minf_P] = minf
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   114
   val [pinf_conj, pinf_disj, pinf_eq, pinf_neq, pinf_lt,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   115
        pinf_le, pinf_gt, pinf_ge, pinf_P] = pinf
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   116
   val [nmi_conj, nmi_disj, nmi_eq, nmi_neq, nmi_lt,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   117
        nmi_le, nmi_gt, nmi_ge, nmi_P] = map (instantiate ([],[(U_v,cU)])) nmi
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   118
   val [npi_conj, npi_disj, npi_eq, npi_neq, npi_lt,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   119
        npi_le, npi_gt, npi_ge, npi_P] = map (instantiate ([],[(U_v,cU)])) npi
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   120
   val [ld_conj, ld_disj, ld_eq, ld_neq, ld_lt,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   121
        ld_le, ld_gt, ld_ge, ld_P] = map (instantiate ([],[(U_v,cU)])) ld
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   122
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   123
   fun decomp_mpinf fm =
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   124
     case term_of fm of
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   125
       Const(@{const_name HOL.conj},_)$_$_ =>
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   126
        let val (p,q) = Thm.dest_binop fm
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   127
        in ([p,q], myfwd (minf_conj,pinf_conj, nmi_conj, npi_conj,ld_conj)
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   128
                         (Thm.cabs x p) (Thm.cabs x q))
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   129
        end
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   130
     | Const(@{const_name HOL.disj},_)$_$_ =>
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   131
        let val (p,q) = Thm.dest_binop fm
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   132
        in ([p,q],myfwd (minf_disj, pinf_disj, nmi_disj, npi_disj,ld_disj)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   133
                         (Thm.cabs x p) (Thm.cabs x q))
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   134
        end
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   135
     | _ =>
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   136
        (let val c = wi x fm
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   137
             val t = (if c=Nox then I
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   138
                      else if member (op =) [Lt, Le, Eq] c then Thm.dest_arg
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   139
                      else if member (op =) [Gt, Ge] c then Thm.dest_arg1
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   140
                      else if c = NEq then (Thm.dest_arg o Thm.dest_arg)
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   141
                      else sys_error "decomp_mpinf: Impossible case!!") fm
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   142
             val [mi_th, pi_th, nmi_th, npi_th, ld_th] =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   143
               if c = Nox then map (instantiate' [] [SOME fm])
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   144
                                    [minf_P, pinf_P, nmi_P, npi_P, ld_P]
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   145
               else
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   146
                let val [mi_th,pi_th,nmi_th,npi_th,ld_th] =
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   147
                 map (instantiate' [] [SOME t])
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   148
                 (case c of Lt => [minf_lt, pinf_lt, nmi_lt, npi_lt, ld_lt]
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   149
                          | Le => [minf_le, pinf_le, nmi_le, npi_le, ld_le]
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   150
                          | Gt => [minf_gt, pinf_gt, nmi_gt, npi_gt, ld_gt]
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   151
                          | Ge => [minf_ge, pinf_ge, nmi_ge, npi_ge, ld_ge]
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   152
                          | Eq => [minf_eq, pinf_eq, nmi_eq, npi_eq, ld_eq]
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   153
                          | NEq => [minf_neq, pinf_neq, nmi_neq, npi_neq, ld_neq])
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   154
                    val tU = U t
36945
9bec62c10714 less pervasive names from structure Thm;
wenzelm
parents: 36862
diff changeset
   155
                    fun Ufw th = Thm.implies_elim th tU
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   156
                 in [mi_th, pi_th, Ufw nmi_th, Ufw npi_th, Ufw ld_th]
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   157
                 end
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   158
         in ([], K (mi_th, pi_th, nmi_th, npi_th, ld_th)) end)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   159
   val (minf_th, pinf_th, nmi_th, npi_th, ld_th) = divide_and_conquer decomp_mpinf q
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   160
   val qe_th = Drule.implies_elim_list
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   161
                  ((fconv_rule (Thm.beta_conversion true))
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   162
                   (instantiate' [] (map SOME [cU, qx, get_p1 minf_th, get_p1 pinf_th])
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   163
                        qe))
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   164
                  [fU, ld_th, nmi_th, npi_th, minf_th, pinf_th]
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   165
    val bex_conv =
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   166
      Simplifier.rewrite (HOL_basic_ss addsimps simp_thms@(@{thms "bex_simps" (1-5)}))
36945
9bec62c10714 less pervasive names from structure Thm;
wenzelm
parents: 36862
diff changeset
   167
    val result_th = fconv_rule (arg_conv bex_conv) (Thm.transitive enth qe_th)
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   168
   in result_th
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   169
   end
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   170
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   171
in main
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   172
end;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   173
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   174
val grab_atom_bop =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   175
 let
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   176
  fun h bounds tm =
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   177
   (case term_of tm of
38549
d0385f2764d8 use antiquotations for remaining unqualified constants in HOL
haftmann
parents: 37744
diff changeset
   178
     Const (@{const_name "op ="}, T) $ _ $ _ =>
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   179
       if domain_type T = HOLogic.boolT then find_args bounds tm
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   180
       else Thm.dest_fun2 tm
38558
32ad17fe2b9c tuned quotes
haftmann
parents: 38549
diff changeset
   181
   | Const (@{const_name Not}, _) $ _ => h bounds (Thm.dest_arg tm)
32ad17fe2b9c tuned quotes
haftmann
parents: 38549
diff changeset
   182
   | Const (@{const_name All}, _) $ _ => find_body bounds (Thm.dest_arg tm)
32ad17fe2b9c tuned quotes
haftmann
parents: 38549
diff changeset
   183
   | Const (@{const_name Ex}, _) $ _ => find_body bounds (Thm.dest_arg tm)
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   184
   | Const (@{const_name HOL.conj}, _) $ _ $ _ => find_args bounds tm
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   185
   | Const (@{const_name HOL.disj}, _) $ _ $ _ => find_args bounds tm
38786
e46e7a9cb622 formerly unnamed infix impliciation now named HOL.implies
haftmann
parents: 38558
diff changeset
   186
   | Const (@{const_name HOL.implies}, _) $ _ $ _ => find_args bounds tm
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   187
   | Const ("==>", _) $ _ $ _ => find_args bounds tm
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   188
   | Const ("==", _) $ _ $ _ => find_args bounds tm
36099
7e1f972df25f added missing case: meta universal quantifier
boehmes
parents: 35625
diff changeset
   189
   | Const ("all", _) $ _ => find_body bounds (Thm.dest_arg tm)
38558
32ad17fe2b9c tuned quotes
haftmann
parents: 38549
diff changeset
   190
   | Const (@{const_name Trueprop}, _) $ _ => h bounds (Thm.dest_arg tm)
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   191
   | _ => Thm.dest_fun2 tm)
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   192
  and find_args bounds tm =
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   193
           (h bounds (Thm.dest_arg tm) handle CTERM _ => Thm.dest_arg1 tm)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   194
 and find_body bounds b =
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   195
   let val (_, b') = Thm.dest_abs (SOME (Name.bound bounds)) b
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   196
   in h (bounds + 1) b' end;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   197
in h end;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   198
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   199
fun raw_ferrack_qe_conv ctxt (thy, {isolate_conv, whatis, simpset}) tm =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   200
 let
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   201
   val ss = simpset
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   202
   val ss' =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   203
     merge_ss (HOL_basic_ss addsimps (simp_thms @ ex_simps @ all_simps)
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   204
              @ [not_all,@{thm "all_not_ex"}, ex_disj_distrib], ss)
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   205
     |> Simplifier.inherit_context ss
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   206
   val pcv = Simplifier.rewrite ss'     
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   207
   val postcv = Simplifier.rewrite ss
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   208
   val nnf = K (nnf_conv then_conv postcv)
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   209
   val qe_conv = Qelim.gen_qelim_conv pcv postcv pcv cons (Thm.add_cterm_frees tm [])
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   210
                  (isolate_conv ctxt) nnf
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   211
                  (fn vs => ferrack_conv (thy,{isolate_conv = isolate_conv ctxt,
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   212
                                               whatis = whatis, simpset = simpset}) vs
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   213
                   then_conv postcv)
23486
4a6506fade73 Thm.add_cterm_frees;
wenzelm
parents: 23466
diff changeset
   214
 in (Simplifier.rewrite ss then_conv qe_conv) tm end;
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   215
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   216
fun dlo_instance ctxt tm =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   217
  Ferrante_Rackoff_Data.match ctxt (grab_atom_bop 0 tm);
23486
4a6506fade73 Thm.add_cterm_frees;
wenzelm
parents: 23466
diff changeset
   218
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   219
fun dlo_conv ctxt tm =
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   220
  (case dlo_instance ctxt tm of
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   221
    NONE => raise CTERM ("ferrackqe_conv: no corresponding instance in context!", [tm])
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   222
  | SOME instance => raw_ferrack_qe_conv ctxt instance tm);
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   223
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   224
fun dlo_tac ctxt = CSUBGOAL (fn (p, i) =>
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   225
  (case dlo_instance ctxt p of
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   226
    NONE => no_tac
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   227
  | SOME instance =>
35625
9c818cab0dd0 modernized structure Object_Logic;
wenzelm
parents: 32264
diff changeset
   228
      Object_Logic.full_atomize_tac i THEN
23567
28c6a0118818 export dlo_conv;
wenzelm
parents: 23524
diff changeset
   229
      simp_tac (#simpset (snd instance)) i THEN  (* FIXME already part of raw_ferrack_qe_conv? *)
35625
9c818cab0dd0 modernized structure Object_Logic;
wenzelm
parents: 32264
diff changeset
   230
      CONVERSION (Object_Logic.judgment_conv (raw_ferrack_qe_conv ctxt instance)) i THEN
32149
ef59550a55d3 renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 30304
diff changeset
   231
      simp_tac (simpset_of ctxt) i));  (* FIXME really? *)
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   232
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   233
end;