src/HOL/Metis_Examples/Type_Encodings.thy
author blanchet
Fri, 01 Jul 2011 15:53:38 +0200
changeset 43629 030610b1e5a8
parent 43626 a867ebb12209
child 43989 eb763b3ff9ed
permissions -rw-r--r--
test a few more type encodings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
     1
(*  Title:      HOL/Metis_Examples/Type_Encodings.thy
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
     3
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
     4
Example that exercises Metis's (and hence Sledgehammer's) type encodings.
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
     5
*)
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
     6
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
     7
header {*
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
     8
Example that Exercises Metis's (and Hence Sledgehammer's) Type Encodings
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
     9
*}
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
    10
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
    11
theory Type_Encodings
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    12
imports Main
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    13
begin
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    14
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
    15
declare [[metis_new_skolemizer]]
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
    16
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
    17
sledgehammer_params [prover = e, blocking, timeout = 10, preplay_timeout = 0]
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
    18
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
    19
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    20
text {* Setup for testing Metis exhaustively *}
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    21
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    22
lemma fork: "P \<Longrightarrow> P \<Longrightarrow> P" by assumption
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    23
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    24
ML {*
43208
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    25
(* The commented-out type systems are too incomplete for our exhaustive
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    26
   tests. *)
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43212
diff changeset
    27
val type_encs =
43208
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    28
  ["erased",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    29
   "poly_preds",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    30
   "poly_preds_heavy",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    31
   "poly_tags",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    32
   "poly_tags_heavy",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    33
   "poly_args",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    34
   "mono_preds",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    35
   "mono_preds_heavy",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    36
   "mono_tags",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    37
   "mono_tags_heavy",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    38
   "mono_args",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    39
   "mangled_preds",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    40
   "mangled_preds_heavy",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    41
   "mangled_tags",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    42
   "mangled_tags_heavy",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    43
   "mangled_args",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    44
   "simple",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    45
   "poly_preds?",
43629
030610b1e5a8 test a few more type encodings
blanchet
parents: 43626
diff changeset
    46
   "poly_preds_heavy?",
030610b1e5a8 test a few more type encodings
blanchet
parents: 43626
diff changeset
    47
   "poly_tags?",
43208
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    48
(* "poly_tags_heavy?", *)
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    49
   "mono_preds?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    50
   "mono_preds_heavy?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    51
   "mono_tags?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    52
   "mono_tags_heavy?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    53
   "mangled_preds?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    54
   "mangled_preds_heavy?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    55
   "mangled_tags?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    56
   "mangled_tags_heavy?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    57
   "simple?",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    58
   "poly_preds!",
43629
030610b1e5a8 test a few more type encodings
blanchet
parents: 43626
diff changeset
    59
   "poly_preds_heavy!",
43208
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    60
(* "poly_tags!", *)
43629
030610b1e5a8 test a few more type encodings
blanchet
parents: 43626
diff changeset
    61
   "poly_tags_heavy!",
43208
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    62
   "mono_preds!",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    63
   "mono_preds_heavy!",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    64
   "mono_tags!",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    65
   "mono_tags_heavy!",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    66
   "mangled_preds!",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    67
   "mangled_preds_heavy!",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    68
   "mangled_tags!",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    69
   "mangled_tags_heavy!",
acfc370df64b compile
blanchet
parents: 43205
diff changeset
    70
   "simple!"]
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    71
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
    72
fun metis_exhaust_tac ctxt ths =
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    73
  let
43172
blanchet
parents: 43162
diff changeset
    74
    fun tac [] st = all_tac st
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43212
diff changeset
    75
      | tac (type_enc :: type_encs) st =
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43212
diff changeset
    76
        st (* |> tap (fn _ => tracing (PolyML.makestring type_enc)) *)
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43212
diff changeset
    77
           |> ((if null type_encs then all_tac else rtac @{thm fork} 1)
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43212
diff changeset
    78
               THEN Metis_Tactics.metis_tac [type_enc] ctxt ths 1
43172
blanchet
parents: 43162
diff changeset
    79
               THEN COND (has_fewer_prems 2) all_tac no_tac
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43212
diff changeset
    80
               THEN tac type_encs)
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    81
  in tac end
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    82
*}
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    83
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
    84
method_setup metis_exhaust = {*
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    85
  Attrib.thms >>
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43212
diff changeset
    86
    (fn ths => fn ctxt => SIMPLE_METHOD (metis_exhaust_tac ctxt ths type_encs))
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    87
*} "exhaustively run the new Metis with all type encodings"
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    88
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    89
43197
c71657bbdbc0 tuned Metis examples
blanchet
parents: 43196
diff changeset
    90
text {* Miscellaneous tests *}
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    91
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    92
lemma "x = y \<Longrightarrow> y = x"
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
    93
by metis_exhaust
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    94
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    95
lemma "[a] = [1 + 1] \<Longrightarrow> a = 1 + (1::int)"
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
    96
by (metis_exhaust last.simps)
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    97
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
    98
lemma "map Suc [0] = [Suc 0]"
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
    99
by (metis_exhaust map.simps)
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   100
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   101
lemma "map Suc [1 + 1] = [Suc 2]"
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
   102
by (metis_exhaust map.simps nat_1_add_1)
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   103
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   104
lemma "map Suc [2] = [Suc (1 + 1)]"
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
   105
by (metis_exhaust map.simps nat_1_add_1)
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   106
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   107
definition "null xs = (xs = [])"
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   108
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   109
lemma "P (null xs) \<Longrightarrow> null xs \<Longrightarrow> xs = []"
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
   110
by (metis_exhaust null_def)
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   111
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   112
lemma "(0::nat) + 0 = 0"
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43208
diff changeset
   113
by (metis_exhaust arithmetic_simps(38))
43162
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   114
9a8acc5adfa3 added Metis examples to test the new type encodings
blanchet
parents:
diff changeset
   115
end