src/HOL/Tools/Sledgehammer/sledgehammer_proof.ML
author wenzelm
Fri, 22 Feb 2013 14:38:52 +0100
changeset 51239 67cc209493b2
parent 51179 0d5f8812856f
child 51998 f732a674db1b
permissions -rw-r--r--
eliminated hard tabs;
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
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    12
  type facts = label list * string list
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
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
    19
  datatype isar_proof = 
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 |
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
    23
    Prove of isar_qualifier list * label * term * byline |
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
    24
    Obtain of isar_qualifier list * fix * label * term * byline
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    25
  and 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
    26
    By_Metis of isar_proof list * facts
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
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    31
  val string_for_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
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
    37
  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
    38
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
  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
    40
  val add_metis_steps : isar_step list -> int -> int
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    41
end
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    42
50672
ab5b8b5c9cbe added "obtain" to Isar proof construction data structure
blanchet
parents: 50269
diff changeset
    43
structure Sledgehammer_Proof : SLEDGEHAMMER_PROOF =
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    44
struct
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    45
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    46
type label = string * int
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    47
type facts = label list * string list
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    48
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
    49
datatype isar_qualifier = Show | Then
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    50
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
    51
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
    52
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
    53
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
    54
datatype isar_proof = 
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
    55
  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
    56
and isar_step =
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    57
  Let of term * term |
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
    58
  Prove of isar_qualifier list * label * term * byline |
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
    59
  Obtain of isar_qualifier list * fix * label * term * byline
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    60
and 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
    61
  By_Metis of isar_proof list * facts
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
    62
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
    63
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
    64
val no_facts = ([],[])
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    65
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    66
fun string_for_label (s, num) = s ^ string_of_int num
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    67
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
    68
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
    69
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
    70
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
    71
(*fun map_steps_of_proof f (Proof (fix, assms, 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
    72
  Proof(fix, assms, f 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
    73
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 label_of_step (Obtain (_, _, l, _, _)) = SOME l
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
  | label_of_step (Prove (_, l, _, _)) = SOME l
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
  | label_of_step _ = NONE
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
    77
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
fun byline_of_step (Obtain (_, _, _, _, byline)) = SOME byline
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
    79
  | byline_of_step (Prove (_, _, _, byline)) = SOME byline
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
    80
  | 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
    81
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
    82
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
    83
  fold (byline_of_step #> (fn SOME (By_Metis _) => Integer.add 1 | _ => I))
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
    84
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
    85
fun add_metis_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
    86
  fold (byline_of_step 
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
    87
        #> (fn SOME (By_Metis (subproofs, _)) =>
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
    88
                Integer.add 1 #> add_substeps subproofs
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
    89
             | _ => I)) 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
    90
and add_substeps subproofs = fold (steps_of_proof #> add_metis_steps) subproofs
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    91
50260
87ddf7eddfc9 simplified isar_qualifiers and qs merging
smolkas
parents: 50259
diff changeset
    92
end