src/HOL/Tools/Sledgehammer/sledgehammer_proof.ML
author smolkas
Wed, 26 Jun 2013 18:26:00 +0200
changeset 52454 b528a975b256
parent 52453 2cba5906d836
child 52556 c8357085217c
permissions -rw-r--r--
tuned: cleaned up data structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50264
a9ec48b98734 renamed sledgehammer_isar_reconstruct to sledgehammer_proof
smolkas
parents: 50263
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_proof.ML
50263
0b430064296a added comments to new source files
smolkas
parents: 50260
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
0b430064296a added comments to new source files
smolkas
parents: 50260
diff changeset
     3
    Author:     Steffen Juilf Smolka, TU Muenchen
0b430064296a added comments to new source files
smolkas
parents: 50260
diff changeset
     4
0b430064296a added comments to new source files
smolkas
parents: 50260
diff changeset
     5
Basic data structures for representing and basic methods
0b430064296a added comments to new source files
smolkas
parents: 50260
diff changeset
     6
for dealing with Isar proof texts.
0b430064296a added comments to new source files
smolkas
parents: 50260
diff changeset
     7
*)
0b430064296a added comments to new source files
smolkas
parents: 50260
diff changeset
     8
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
     9
signature SLEDGEHAMMER_PROOF =
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    10
sig
51239
67cc209493b2 eliminated hard tabs;
wenzelm
parents: 51179
diff changeset
    11
  type label = string * int
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    12
  type facts = label list * string list (* local & global facts *)
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    13
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
    14
  datatype isar_qualifier = Show | Then
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    15
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    16
  datatype fix = Fix of (string * typ) list
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    17
  datatype assms = Assume of (label * term) list
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    18
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    19
  datatype isar_proof =
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    20
    Proof of fix * assms * isar_step list
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    21
  and isar_step =
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    22
    Let of term * term |
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    23
  (* for |fix|>0, this is an obtain step; step may contain subproofs *)
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    24
  Prove of isar_qualifier list * fix * label * term * isar_proof list * byline
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    25
  and byline =
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    26
    By_Metis of facts
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    27
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    28
  val no_label : label
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    29
  val no_facts : facts
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    30
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51239
diff changeset
    31
  val string_of_label : label -> string
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    32
  val fix_of_proof : isar_proof -> fix
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    33
  val assms_of_proof : isar_proof -> assms
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    34
  val steps_of_proof : isar_proof -> isar_step list
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    35
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    36
  val label_of_step : isar_step -> label option
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    37
  val subproofs_of_step : isar_step -> isar_proof list option
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    38
  val byline_of_step : isar_step -> byline option
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    39
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    40
  val fold_isar_step : (isar_step -> 'a -> 'a) -> isar_step -> 'a -> 'a
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    41
  val fold_isar_steps :
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    42
    (isar_step -> 'a -> 'a) -> isar_step list -> 'a -> 'a
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    43
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    44
  val add_metis_steps_top_level : isar_step list -> int -> int
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    45
  val add_metis_steps : isar_step list -> int -> int
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    46
end
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    47
50672
ab5b8b5c9cbe added "obtain" to Isar proof construction data structure
blanchet
parents: 50269
diff changeset
    48
structure Sledgehammer_Proof : SLEDGEHAMMER_PROOF =
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    49
struct
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    50
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    51
type label = string * int
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    52
type facts = label list * string list (* local & global facts *)
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    53
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
    54
datatype isar_qualifier = Show | Then
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    55
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    56
datatype fix = Fix of (string * typ) list
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    57
datatype assms = Assume of (label * term) list
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    58
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    59
datatype isar_proof =
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    60
  Proof of fix * assms * isar_step list
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    61
and isar_step =
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    62
  Let of term * term |
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    63
  (* for |fix|>0, this is an obtain step; step may contain subproofs *)
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    64
  Prove of isar_qualifier list * fix * label * term * isar_proof list * byline
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    65
and byline =
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    66
  By_Metis of facts
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    67
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    68
val no_label = ("", ~1)
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    69
val no_facts = ([],[])
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    70
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51239
diff changeset
    71
fun string_of_label (s, num) = s ^ string_of_int num
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    72
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    73
fun fix_of_proof (Proof (fix, _, _)) = fix
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    74
fun assms_of_proof (Proof (_, assms, _)) = assms
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    75
fun steps_of_proof (Proof (_, _, steps)) = steps
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    76
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    77
fun label_of_step (Prove (_, _, l, _, _, _)) = SOME l
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    78
  | label_of_step _ = NONE
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
    79
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    80
fun subproofs_of_step (Prove (_, _, _, _, subproofs, _)) = SOME subproofs
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    81
  | subproofs_of_step _ = NONE
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    82
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    83
fun byline_of_step (Prove (_, _, _, _, _, byline)) = SOME byline
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    84
  | byline_of_step _ = NONE
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    85
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    86
fun fold_isar_step f step s =
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    87
  fold (steps_of_proof #> fold (fold_isar_step f))
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    88
    (the_default [] (subproofs_of_step step)) s
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    89
    |> f step
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    90
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    91
fun fold_isar_steps f = fold (fold_isar_step f)
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    92
51179
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    93
val add_metis_steps_top_level =
0d5f8812856f split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents: 51178
diff changeset
    94
  fold (byline_of_step #> (fn SOME (By_Metis _) => Integer.add 1 | _ => I))
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
    95
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    96
val add_metis_steps =
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    97
  fold_isar_steps
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    98
    (byline_of_step #> (fn SOME (By_Metis _) => Integer.add 1 | _ => I))
50260
87ddf7eddfc9 simplified isar_qualifiers and qs merging
smolkas
parents: 50259
diff changeset
    99
end