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