src/HOL/Decision_Procs/ferrante_rackoff_data.ML
author bulwahn
Thu, 08 Dec 2016 17:22:51 +0100
changeset 64543 6b13586ef1a2
parent 61476 1884c40f1539
child 69597 ff784d5a5bfb
permissions -rw-r--r--
remove typo in bij_swap_compose_bij theorem name; tune proof
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_data.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
Context data for Ferrante and Rackoff's algorithm for quantifier
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     5
elimination in dense linear orders.
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
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     8
signature FERRANTE_RACKOF_DATA =
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
     9
sig
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    10
  datatype ord = Lt | Le | Gt | Ge | Eq | NEq | Nox
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    11
  type entry
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    12
  val get: Proof.context -> (thm * entry) list
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    13
  val del: attribute
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    14
  val add: entry -> attribute 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    15
  val funs: thm -> 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    16
    {isolate_conv: morphism -> Proof.context -> cterm list -> cterm -> thm,
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    17
     whatis: morphism -> cterm -> cterm -> ord,
61089
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    18
     simpset: morphism -> Proof.context -> simpset} -> declaration
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    19
  val match: Proof.context -> cterm -> entry option
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    20
end;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    21
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    22
structure Ferrante_Rackoff_Data: FERRANTE_RACKOF_DATA = 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    23
struct
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    24
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    25
(* data *)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    26
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    27
datatype ord = Lt | Le | Gt | Ge | Eq | NEq | Nox
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    28
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    29
type entry = 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    30
  {minf: thm list, pinf: thm list, nmi: thm list, npi: thm list,  
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    31
   ld: thm list, qe: thm, atoms : cterm list} *
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    32
   {isolate_conv: Proof.context -> cterm list -> cterm -> thm, 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    33
    whatis : cterm -> cterm -> ord, 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    34
    simpset : simpset};
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    35
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    36
val eq_key = Thm.eq_thm;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    37
fun eq_data arg = eq_fst eq_key arg;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    38
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 30722
diff changeset
    39
structure Data = Generic_Data
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    40
(
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    41
  type T = (thm * entry) list;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    42
  val empty = [];
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    43
  val extend = I;
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 30722
diff changeset
    44
  fun merge data : T = AList.merge eq_key (K true) data;
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    45
);
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    46
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    47
val get = Data.get o Context.Proof;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    48
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    49
fun del_data key = remove eq_data (key, []);
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    50
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    51
val del = Thm.declaration_attribute (Data.map o del_data);
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    52
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    53
fun add entry = 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    54
    Thm.declaration_attribute (fn key => fn context => context |> Data.map 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    55
      (del_data key #> cons (key, entry)));
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    56
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    57
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    58
(* extra-logical functions *)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    59
61089
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    60
fun funs raw_key {isolate_conv = icv, whatis = wi, simpset = ss} phi context =
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    61
  context |> Data.map (fn data =>
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    62
    let
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    63
      val key = Morphism.thm phi raw_key;
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    64
      val _ = AList.defined eq_key data key orelse
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    65
        raise THM ("No data entry for structure key", 0, [key]);
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    66
      val fns =
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    67
        {isolate_conv = icv phi, whatis = wi phi, simpset = ss phi (Context.proof_of context)};
969eb24297af clarified context;
wenzelm
parents: 55792
diff changeset
    68
    in AList.map_entry eq_key key (apsnd (K fns)) data end);
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    69
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    70
fun match ctxt tm =
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    71
  let
55506
46f3e31c5a87 removed dead code;
wenzelm
parents: 37744
diff changeset
    72
    fun match_inst ({minf, pinf, nmi, npi, ld, qe, atoms}, fns) pat =
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    73
       let
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    74
        fun h instT =
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    75
          let
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    76
            val substT = Thm.instantiate (instT, []);
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    77
            val substT_cterm = Drule.cterm_rule substT;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    78
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    79
            val minf' = map substT minf
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    80
            val pinf' = map substT pinf
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    81
            val nmi' = map substT nmi
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    82
            val npi' = map substT npi
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    83
            val ld' = map substT ld
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    84
            val qe' = substT qe
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    85
            val atoms' = map substT_cterm atoms
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    86
            val result = ({minf = minf', pinf = pinf', nmi = nmi', npi = npi', 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    87
                           ld = ld', qe = qe', atoms = atoms'}, fns)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    88
          in SOME result end
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    89
      in (case try Thm.match (pat, tm) of
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    90
           NONE => NONE
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    91
         | SOME (instT, _) => h instT)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    92
      end;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    93
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    94
    fun match_struct (_,
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    95
        entry as ({atoms = atoms, ...}, _): entry) =
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    96
      get_first (match_inst entry) atoms;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    97
  in get_first match_struct (get ctxt) end;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    98
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
    99
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   100
(* concrete syntax *)
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   101
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   102
local
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   103
val minfN = "minf";
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   104
val pinfN = "pinf";
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   105
val nmiN = "nmi";
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   106
val npiN = "npi";
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   107
val lin_denseN = "lindense";
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   108
val qeN = "qe"
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   109
val atomsN = "atoms"
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   110
val simpsN = "simps"
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   111
fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ();
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   112
val any_keyword =
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   113
  keyword minfN || keyword pinfN || keyword nmiN 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   114
|| keyword npiN || keyword lin_denseN || keyword qeN 
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   115
|| keyword atomsN || keyword simpsN;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   116
61476
1884c40f1539 tuned signature;
wenzelm
parents: 61089
diff changeset
   117
val thms = Scan.repeats (Scan.unless any_keyword Attrib.multi_thm);
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   118
val terms = thms >> map Drule.dest_term;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   119
in
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   120
55792
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   121
val _ =
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   122
  Theory.setup
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   123
    (Attrib.setup @{binding ferrack}
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   124
      ((keyword minfN |-- thms)
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   125
       -- (keyword pinfN |-- thms)
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   126
       -- (keyword nmiN |-- thms)
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   127
       -- (keyword npiN |-- thms)
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   128
       -- (keyword lin_denseN |-- thms)
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   129
       -- (keyword qeN |-- thms)
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   130
       -- (keyword atomsN |-- terms) >>
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   131
         (fn ((((((minf,pinf),nmi),npi),lin_dense),qe), atoms)=> 
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   132
         if length qe = 1 then
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   133
           add ({minf = minf, pinf = pinf, nmi = nmi, npi = npi, ld = lin_dense, 
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   134
                qe = hd qe, atoms = atoms},
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   135
               {isolate_conv = undefined, whatis = undefined, simpset = HOL_ss})
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   136
         else error "only one theorem for qe!"))
687240115804 tuned whitespace;
wenzelm
parents: 55506
diff changeset
   137
      "Ferrante Rackoff data");
23466
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   138
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   139
end;
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   140
886655a150f6 moved quantifier elimination tools to Tools/Qelim/;
wenzelm
parents:
diff changeset
   141
end;