src/HOL/Tools/Sledgehammer/sledgehammer_proof.ML
author smolkas
Mon, 18 Feb 2013 12:16:27 +0100
changeset 52316 0d5f8812856f
parent 52315 06689dbfe072
child 52376 67cc209493b2
permissions -rw-r--r--
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
     1 (*  Title:      HOL/Tools/Sledgehammer/sledgehammer_proof.ML
     2     Author:     Jasmin Blanchette, TU Muenchen
     3     Author:     Steffen Juilf Smolka, TU Muenchen
     4 
     5 Basic data structures for representing and basic methods
     6 for dealing with Isar proof texts.
     7 *)
     8 
     9 signature SLEDGEHAMMER_PROOF =
    10 sig
    11 	type label = string * int
    12   type facts = label list * string list
    13 
    14   datatype isar_qualifier = Show | Then
    15 
    16   datatype fix = Fix of (string * typ) list
    17   datatype assms = Assume of (label * term) list
    18 
    19   datatype isar_proof = 
    20     Proof of fix * assms * isar_step list
    21   and isar_step =
    22     Let of term * term |
    23     Prove of isar_qualifier list * label * term * byline |
    24     Obtain of isar_qualifier list * fix * label * term * byline
    25   and byline =
    26     By_Metis of isar_proof list * facts
    27 
    28   val no_label : label
    29   val no_facts : facts
    30 
    31   val string_for_label : label -> string
    32   val fix_of_proof : isar_proof -> fix
    33   val assms_of_proof : isar_proof -> assms
    34   val steps_of_proof : isar_proof -> isar_step list
    35 
    36   val label_of_step : isar_step -> label option
    37   val byline_of_step : isar_step -> byline option
    38 
    39   val add_metis_steps_top_level : isar_step list -> int -> int
    40   val add_metis_steps : isar_step list -> int -> int
    41 end
    42 
    43 structure Sledgehammer_Proof : SLEDGEHAMMER_PROOF =
    44 struct
    45 
    46 type label = string * int
    47 type facts = label list * string list
    48 
    49 datatype isar_qualifier = Show | Then
    50 
    51 datatype fix = Fix of (string * typ) list
    52 datatype assms = Assume of (label * term) list
    53 
    54 datatype isar_proof = 
    55   Proof of fix * assms * isar_step list
    56 and isar_step =
    57   Let of term * term |
    58   Prove of isar_qualifier list * label * term * byline |
    59   Obtain of isar_qualifier list * fix * label * term * byline
    60 and byline =
    61   By_Metis of isar_proof list * facts
    62 
    63 val no_label = ("", ~1)
    64 val no_facts = ([],[])
    65 
    66 fun string_for_label (s, num) = s ^ string_of_int num
    67 
    68 fun fix_of_proof (Proof (fix, _, _)) = fix
    69 fun assms_of_proof (Proof (_, assms, _)) = assms
    70 fun steps_of_proof (Proof (_, _, steps)) = steps
    71 (*fun map_steps_of_proof f (Proof (fix, assms, steps)) =
    72   Proof(fix, assms, f steps)*)
    73 
    74 fun label_of_step (Obtain (_, _, l, _, _)) = SOME l
    75   | label_of_step (Prove (_, l, _, _)) = SOME l
    76   | label_of_step _ = NONE
    77 
    78 fun byline_of_step (Obtain (_, _, _, _, byline)) = SOME byline
    79   | byline_of_step (Prove (_, _, _, byline)) = SOME byline
    80   | byline_of_step _ = NONE
    81 
    82 val add_metis_steps_top_level =
    83   fold (byline_of_step #> (fn SOME (By_Metis _) => Integer.add 1 | _ => I))
    84 
    85 fun add_metis_steps steps =
    86   fold (byline_of_step 
    87         #> (fn SOME (By_Metis (subproofs, _)) =>
    88                 Integer.add 1 #> add_substeps subproofs
    89              | _ => I)) steps
    90 and add_substeps subproofs = fold (steps_of_proof #> add_metis_steps) subproofs
    91 
    92 end