src/HOL/Tools/Sledgehammer/sledgehammer_proof.ML
author blanchet
Mon, 16 Dec 2013 09:48:26 +0100
changeset 54764 1c9ef5c834e8
parent 54761 0ef52f40d419
child 54765 b05b0ea06306
permissions -rw-r--r--
added 'meson' to the mix
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
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    16
  datatype isar_proof =
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    17
    Proof of (string * typ) list * (label * term) list * isar_step list
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
    18
  and isar_step =
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    19
    Let of term * term |
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    20
    Prove of isar_qualifier list * (string * typ) list * label * term * isar_proof list *
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    21
      (facts * proof_method)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    22
  and proof_method =
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    23
    MetisM |
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    24
    SimpM |
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    25
    AutoM |
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    26
    FastforceM |
52629
d6f2a7c196f7 added blast, force
smolkas
parents: 52627
diff changeset
    27
    ForceM |
d6f2a7c196f7 added blast, force
smolkas
parents: 52627
diff changeset
    28
    ArithM |
54764
1c9ef5c834e8 added 'meson' to the mix
blanchet
parents: 54761
diff changeset
    29
    BlastM |
1c9ef5c834e8 added 'meson' to the mix
blanchet
parents: 54761
diff changeset
    30
    MesonM
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    31
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 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
    33
  val no_facts : facts
50268
5d6494332b0b added signature
smolkas
parents: 50267
diff changeset
    34
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    35
  val label_ord : label * label -> order
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    36
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    37
  val dummy_isar_step : isar_step
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    38
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51239
diff changeset
    39
  val string_of_label : label -> string
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    40
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    41
  val fix_of_proof : isar_proof -> (string * typ) list
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    42
  val assms_of_proof : isar_proof -> (label * term) list
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
    43
  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
    44
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 label_of_step : isar_step -> label option
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    46
  val subproofs_of_step : isar_step -> isar_proof list option
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    47
  val byline_of_step : isar_step -> (facts * proof_method) option
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    48
  val proof_method_of_step : isar_step -> proof_method option
54761
0ef52f40d419 use consistent condition for setting 'metis_new_skolem' (in preplaying and in output printing) + tuning
blanchet
parents: 54700
diff changeset
    49
  val use_metis_new_skolem : isar_step -> bool
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
    50
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    51
  val fold_isar_step : (isar_step -> 'a -> 'a) -> isar_step -> 'a -> 'a
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    52
  val fold_isar_steps :
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    53
    (isar_step -> 'a -> 'a) -> isar_step list -> 'a -> 'a
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    54
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    55
  val map_isar_steps : (isar_step -> isar_step) -> isar_proof -> isar_proof
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    56
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    57
  val add_proof_steps : isar_step list -> int -> int
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    58
54534
blanchet
parents: 54504
diff changeset
    59
  (** canonical proof labels: 1, 2, 3, ... in postorder **)
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    60
  val canonical_label_ord : (label * label) -> order
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    61
  val relabel_proof_canonically : isar_proof -> isar_proof
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    62
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    63
  structure Canonical_Lbl_Tab : TABLE
54504
blanchet
parents: 54503
diff changeset
    64
end;
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    65
50672
ab5b8b5c9cbe added "obtain" to Isar proof construction data structure
blanchet
parents: 50269
diff changeset
    66
structure Sledgehammer_Proof : SLEDGEHAMMER_PROOF =
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    67
struct
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    68
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    69
type label = string * int
54534
blanchet
parents: 54504
diff changeset
    70
type facts = label list * string list (* local and global facts *)
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    71
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
    72
datatype isar_qualifier = Show | Then
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    73
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
    74
datatype isar_proof =
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    75
  Proof of (string * typ) list * (label * term) list * isar_step list
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
    76
and isar_step =
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    77
  Let of term * term |
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    78
  Prove of isar_qualifier list * (string * typ) list * label * term * isar_proof list *
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
    79
    (facts * proof_method)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    80
and proof_method =
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    81
  MetisM |
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    82
  SimpM |
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    83
  AutoM |
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    84
  FastforceM |
52629
d6f2a7c196f7 added blast, force
smolkas
parents: 52627
diff changeset
    85
  ForceM |
d6f2a7c196f7 added blast, force
smolkas
parents: 52627
diff changeset
    86
  ArithM |
54764
1c9ef5c834e8 added 'meson' to the mix
blanchet
parents: 54761
diff changeset
    87
  BlastM |
1c9ef5c834e8 added 'meson' to the mix
blanchet
parents: 54761
diff changeset
    88
  MesonM
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    89
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
    90
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
    91
val no_facts = ([],[])
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    92
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
    93
val label_ord = pairself swap #> prod_ord int_ord fast_string_ord
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    94
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    95
val dummy_isar_step = Let (Term.dummy, Term.dummy)
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
    96
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51239
diff changeset
    97
fun string_of_label (s, num) = s ^ string_of_int num
50259
9c64a52ae499 put shrink in own structure
smolkas
parents:
diff changeset
    98
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
    99
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
   100
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
   101
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
   102
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
   103
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
   104
  | label_of_step _ = NONE
51178
06689dbfe072 simplified byline, isar_qualifier
smolkas
parents: 51147
diff changeset
   105
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
   106
fun subproofs_of_step (Prove (_, _, _, _, subproofs, _)) = SOME subproofs
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
   107
  | subproofs_of_step _ = NONE
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
   108
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
   109
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
   110
  | 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
   111
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
   112
fun proof_method_of_step (Prove (_, _, _, _, _, (_, method))) = SOME method
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   113
  | proof_method_of_step _ = NONE
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   114
54761
0ef52f40d419 use consistent condition for setting 'metis_new_skolem' (in preplaying and in output printing) + tuning
blanchet
parents: 54700
diff changeset
   115
fun use_metis_new_skolem (Prove (_, xs, _, _, _, (_, meth))) =
0ef52f40d419 use consistent condition for setting 'metis_new_skolem' (in preplaying and in output printing) + tuning
blanchet
parents: 54700
diff changeset
   116
    meth = MetisM andalso exists (fn (_, T) => length (binder_types T) > 1) xs
0ef52f40d419 use consistent condition for setting 'metis_new_skolem' (in preplaying and in output printing) + tuning
blanchet
parents: 54700
diff changeset
   117
  | use_metis_new_skolem _ = false
0ef52f40d419 use consistent condition for setting 'metis_new_skolem' (in preplaying and in output printing) + tuning
blanchet
parents: 54700
diff changeset
   118
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   119
fun fold_isar_steps f = fold (fold_isar_step f)
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   120
and fold_isar_step f step s =
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   121
  fold (steps_of_proof #> fold_isar_steps f)
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   122
       (these (subproofs_of_step step)) s
52454
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
   123
    |> f step
b528a975b256 tuned: cleaned up data structure
smolkas
parents: 52453
diff changeset
   124
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   125
fun map_isar_steps f proof =
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   126
  let
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
   127
    fun do_proof (Proof (fix, assms, steps)) = Proof (fix, assms, map do_step steps)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   128
    and do_step (step as Let _) = f step
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   129
      | do_step (Prove (qs, xs, l, t, subproofs, by)) =
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
   130
        f (Prove (qs, xs, l, t, map do_proof subproofs, by))
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   131
  in
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   132
    do_proof proof
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   133
  end
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   134
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   135
val add_proof_steps = fold_isar_steps (fn Prove _ => Integer.add 1 | _ => I)
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   136
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   137
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   138
(** canonical proof labels: 1, 2, 3, ... in post traversal order **)
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   139
52557
92ed2926596d made SML/NJ happy
smolkas
parents: 52556
diff changeset
   140
fun canonical_label_ord (((_, i1), (_, i2)) : label * label) = int_ord (i1, i2)
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   141
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   142
structure Canonical_Lbl_Tab = Table(
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   143
  type key = label
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   144
  val ord = canonical_label_ord)
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   145
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   146
fun relabel_proof_canonically proof =
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   147
  let
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   148
    fun next_label l (next, subst) =
54534
blanchet
parents: 54504
diff changeset
   149
      let val l' = ("", next) in (l', (next + 1, (l, l') :: subst)) end
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   150
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
   151
    fun do_byline by (_, subst) = apfst (apfst (map (AList.lookup (op =) subst #> the))) by
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   152
    handle Option.Option =>
52627
smolkas
parents: 52592
diff changeset
   153
      raise Fail "Sledgehammer_Proof: relabel_proof_canonically"
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   154
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   155
    fun do_assm (l, t) state =
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   156
      let
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   157
        val (l, state) = next_label l state
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   158
      in ((l, t), state) end
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   159
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
   160
    fun do_proof (Proof (fix, assms, steps)) state =
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   161
      let
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   162
        val (assms, state) = fold_map do_assm assms state
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   163
        val (steps, state) = fold_map do_step steps state
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   164
      in
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54534
diff changeset
   165
        (Proof (fix, assms, steps), state)
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   166
      end
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   167
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   168
    and do_step (step as Let _) state = (step, state)
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   169
      | do_step (Prove (qs, fix, l, t, subproofs, by)) state=
54534
blanchet
parents: 54504
diff changeset
   170
        let
blanchet
parents: 54504
diff changeset
   171
          val by = do_byline by state
blanchet
parents: 54504
diff changeset
   172
          val (subproofs, state) = fold_map do_proof subproofs state
blanchet
parents: 54504
diff changeset
   173
          val (l, state) = next_label l state
blanchet
parents: 54504
diff changeset
   174
        in
blanchet
parents: 54504
diff changeset
   175
          (Prove (qs, fix, l, t, subproofs, by), state)
blanchet
parents: 54504
diff changeset
   176
        end
52556
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   177
  in
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   178
    fst (do_proof proof (0, []))
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   179
  end
c8357085217c completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents: 52454
diff changeset
   180
54504
blanchet
parents: 54503
diff changeset
   181
end;