src/HOL/Metis_Examples/Type_Encodings.thy
author blanchet
Mon, 22 Aug 2011 15:02:45 +0200
changeset 45267 30ea62ab4f16
parent 45261 f0bc74b9161e
child 45271 c8b847625584
permissions -rw-r--r--
made reconstruction of type tag equalities "\?x = \?x" reliable
blanchet@44038
     1
(*  Title:      HOL/Metis_Examples/Type_Encodings.thy
blanchet@44003
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@44003
     3
blanchet@44038
     4
Example that exercises Metis's (and hence Sledgehammer's) type encodings.
blanchet@44003
     5
*)
blanchet@44003
     6
blanchet@44038
     7
header {*
blanchet@44038
     8
Example that Exercises Metis's (and Hence Sledgehammer's) Type Encodings
blanchet@44038
     9
*}
blanchet@44038
    10
blanchet@44038
    11
theory Type_Encodings
blanchet@45267
    12
imports "~~/src/HOL/Sledgehammer2d"(*###*)
blanchet@44003
    13
begin
blanchet@44003
    14
blanchet@44038
    15
declare [[metis_new_skolemizer]]
blanchet@44038
    16
blanchet@44038
    17
sledgehammer_params [prover = e, blocking, timeout = 10, preplay_timeout = 0]
blanchet@44038
    18
blanchet@44038
    19
blanchet@44003
    20
text {* Setup for testing Metis exhaustively *}
blanchet@44003
    21
blanchet@44003
    22
lemma fork: "P \<Longrightarrow> P \<Longrightarrow> P" by assumption
blanchet@44003
    23
blanchet@44003
    24
ML {*
blanchet@44049
    25
(* The commented-out type systems are too incomplete for our exhaustive
blanchet@44049
    26
   tests. *)
blanchet@44493
    27
val type_encs =
blanchet@44049
    28
  ["erased",
blanchet@44860
    29
   "poly_guards",
blanchet@45261
    30
   "poly_guards_uniform",
blanchet@44049
    31
   "poly_tags",
blanchet@45261
    32
   "poly_tags_uniform",
blanchet@44049
    33
   "poly_args",
blanchet@44860
    34
   "mono_guards",
blanchet@45261
    35
   "mono_guards_uniform",
blanchet@44049
    36
   "mono_tags",
blanchet@45261
    37
   "mono_tags_uniform",
blanchet@44049
    38
   "mono_args",
blanchet@44860
    39
   "mangled_guards",
blanchet@45261
    40
   "mangled_guards_uniform",
blanchet@44049
    41
   "mangled_tags",
blanchet@45261
    42
   "mangled_tags_uniform",
blanchet@44049
    43
   "mangled_args",
blanchet@44049
    44
   "simple",
blanchet@44860
    45
   "poly_guards?",
blanchet@45261
    46
   "poly_guards_uniform?",
blanchet@44496
    47
   "poly_tags?",
blanchet@45261
    48
(* "poly_tags_uniform?", *)
blanchet@44860
    49
   "mono_guards?",
blanchet@45261
    50
   "mono_guards_uniform?",
blanchet@44049
    51
   "mono_tags?",
blanchet@45261
    52
   "mono_tags_uniform?",
blanchet@44860
    53
   "mangled_guards?",
blanchet@45261
    54
   "mangled_guards_uniform?",
blanchet@44049
    55
   "mangled_tags?",
blanchet@45261
    56
   "mangled_tags_uniform?",
blanchet@44049
    57
   "simple?",
blanchet@44860
    58
   "poly_guards!",
blanchet@45261
    59
   "poly_guards_uniform!",
blanchet@44049
    60
(* "poly_tags!", *)
blanchet@45261
    61
   "poly_tags_uniform!",
blanchet@44860
    62
   "mono_guards!",
blanchet@45261
    63
   "mono_guards_uniform!",
blanchet@44049
    64
   "mono_tags!",
blanchet@45261
    65
   "mono_tags_uniform!",
blanchet@44860
    66
   "mangled_guards!",
blanchet@45261
    67
   "mangled_guards_uniform!",
blanchet@44049
    68
   "mangled_tags!",
blanchet@45261
    69
   "mangled_tags_uniform!",
blanchet@44049
    70
   "simple!"]
blanchet@44003
    71
blanchet@44053
    72
fun metis_exhaust_tac ctxt ths =
blanchet@44003
    73
  let
blanchet@44013
    74
    fun tac [] st = all_tac st
blanchet@44493
    75
      | tac (type_enc :: type_encs) st =
blanchet@44493
    76
        st (* |> tap (fn _ => tracing (PolyML.makestring type_enc)) *)
blanchet@44493
    77
           |> ((if null type_encs then all_tac else rtac @{thm fork} 1)
blanchet@44493
    78
               THEN Metis_Tactics.metis_tac [type_enc] ctxt ths 1
blanchet@44013
    79
               THEN COND (has_fewer_prems 2) all_tac no_tac
blanchet@44493
    80
               THEN tac type_encs)
blanchet@44003
    81
  in tac end
blanchet@44003
    82
*}
blanchet@44003
    83
blanchet@44053
    84
method_setup metis_exhaust = {*
blanchet@44003
    85
  Attrib.thms >>
blanchet@44493
    86
    (fn ths => fn ctxt => SIMPLE_METHOD (metis_exhaust_tac ctxt ths type_encs))
blanchet@44003
    87
*} "exhaustively run the new Metis with all type encodings"
blanchet@44003
    88
blanchet@44003
    89
blanchet@44038
    90
text {* Miscellaneous tests *}
blanchet@44003
    91
blanchet@44003
    92
lemma "x = y \<Longrightarrow> y = x"
blanchet@44053
    93
by metis_exhaust
blanchet@44003
    94
blanchet@44003
    95
lemma "[a] = [1 + 1] \<Longrightarrow> a = 1 + (1::int)"
blanchet@44053
    96
by (metis_exhaust last.simps)
blanchet@44003
    97
blanchet@44003
    98
lemma "map Suc [0] = [Suc 0]"
blanchet@44053
    99
by (metis_exhaust map.simps)
blanchet@44003
   100
blanchet@44003
   101
lemma "map Suc [1 + 1] = [Suc 2]"
blanchet@44053
   102
by (metis_exhaust map.simps nat_1_add_1)
blanchet@44003
   103
blanchet@44003
   104
lemma "map Suc [2] = [Suc (1 + 1)]"
blanchet@44053
   105
by (metis_exhaust map.simps nat_1_add_1)
blanchet@44003
   106
blanchet@44003
   107
definition "null xs = (xs = [])"
blanchet@44003
   108
blanchet@44003
   109
lemma "P (null xs) \<Longrightarrow> null xs \<Longrightarrow> xs = []"
blanchet@44053
   110
by (metis_exhaust null_def)
blanchet@44003
   111
blanchet@44003
   112
lemma "(0::nat) + 0 = 0"
blanchet@44053
   113
by (metis_exhaust arithmetic_simps(38))
blanchet@44003
   114
blanchet@44003
   115
end