src/HOL/Tools/SMT/lethe_proof.ML
author haftmann
Sat, 19 Jul 2025 18:41:55 +0200
changeset 82886 8d1e295aab70
parent 78177 ea7a3cc64df5
permissions -rw-r--r--
clarified name and status of auxiliary operation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
76183
8089593a364a proper file headers;
wenzelm
parents: 75956
diff changeset
     1
(*  Title:      HOL/Tools/SMT/lethe_proof.ML
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
     2
    Author:     Mathias Fleury, ENS Rennes
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
     3
    Author:     Sascha Boehme, TU Muenchen
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
     4
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
     5
Lethe proofs: parsing and abstract syntax tree.
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
     6
*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
     7
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
     8
signature LETHE_PROOF =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
     9
sig
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    10
  (*proofs*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    11
  datatype lethe_step = Lethe_Step of {
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    12
    id: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    13
    rule: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    14
    prems: string list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    15
    proof_ctxt: term list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    16
    concl: term,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    17
    fixes: string list}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    18
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    19
  datatype lethe_replay_node = Lethe_Replay_Node of {
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    20
    id: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    21
    rule: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    22
    args: term list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    23
    prems: string list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    24
    proof_ctxt: term list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    25
    concl: term,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    26
    bounds: (string * typ) list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    27
    declarations: (string * term) list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    28
    insts: term Symtab.table,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    29
    subproof: (string * typ) list * term list * term list * lethe_replay_node list}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    30
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    31
  val mk_replay_node: string -> string -> term list -> string list -> term list ->
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    32
     term -> (string * typ) list -> term Symtab.table -> (string * term) list ->
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    33
     (string * typ) list * term list * term list * lethe_replay_node list -> lethe_replay_node
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    34
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    35
datatype raw_lethe_node = Raw_Lethe_Node of {
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    36
  id: string,
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    37
  rule: string,
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    38
  args: SMTLIB.tree,
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    39
  prems: string list,
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    40
  concl: SMTLIB.tree,
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    41
  declarations: (string * SMTLIB.tree) list,
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    42
  subproof: raw_lethe_node list}
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    43
 val parse_raw_proof_steps: string option -> SMTLIB.tree list -> SMTLIB_Proof.name_bindings -> int ->
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    44
 raw_lethe_node list * SMTLIB.tree list * SMTLIB_Proof.name_bindings
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    45
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    46
  (*proof parser*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    47
  val parse: typ Symtab.table -> term Symtab.table -> string list ->
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    48
    Proof.context -> lethe_step list * Proof.context
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    49
  val parse_replay: typ Symtab.table -> term Symtab.table -> string list ->
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    50
    Proof.context -> lethe_replay_node list * Proof.context
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    51
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    52
  val step_prefix : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    53
  val input_rule: string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    54
  val keep_app_symbols: string -> bool
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    55
  val keep_raw_lifting: string -> bool
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    56
  val normalized_input_rule: string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    57
  val la_generic_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    58
  val rewrite_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    59
  val simp_arith_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    60
  val lethe_deep_skolemize_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    61
  val lethe_def : string
75956
1e2a9d2251b0 remove duplicate parsing for alethe; fix skolemization;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 75561
diff changeset
    62
  val is_lethe_def : string -> bool
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    63
  val subproof_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    64
  val local_input_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    65
  val not_not_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    66
  val contract_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    67
  val ite_intro_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    68
  val eq_congruent_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    69
  val eq_congruent_pred_rule : string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    70
  val skolemization_steps : string list
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    71
  val theory_resolution2_rule: string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    72
  val equiv_pos2_rule: string
75561
b6239ed66b94 fix veriT reconstruction for and_pos and lambda-lifting
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 75299
diff changeset
    73
  val and_pos_rule: string
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
    74
  val hole: string
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    75
  val th_resolution_rule: string
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    76
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    77
  val is_skolemization: string -> bool
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    78
  val is_skolemization_step: lethe_replay_node -> bool
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    79
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    80
  val number_of_steps: lethe_replay_node list -> int
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    81
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    82
end;
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    83
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    84
structure Lethe_Proof: LETHE_PROOF =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    85
struct
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    86
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    87
open SMTLIB_Proof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    88
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    89
datatype raw_lethe_node = Raw_Lethe_Node of {
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    90
  id: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    91
  rule: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    92
  args: SMTLIB.tree,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    93
  prems: string list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    94
  concl: SMTLIB.tree,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    95
  declarations: (string * SMTLIB.tree) list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    96
  subproof: raw_lethe_node list}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    97
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    98
fun mk_raw_node id rule args prems declarations concl subproof =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
    99
  Raw_Lethe_Node {id = id, rule = rule, args = args, prems = prems, declarations = declarations,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   100
    concl = concl, subproof = subproof}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   101
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   102
datatype lethe_node = Lethe_Node of {
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   103
  id: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   104
  rule: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   105
  prems: string list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   106
  proof_ctxt: term list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   107
  concl: term}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   108
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   109
fun mk_node id rule prems proof_ctxt concl =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   110
  Lethe_Node {id = id, rule = rule, prems = prems, proof_ctxt = proof_ctxt, concl = concl}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   111
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   112
datatype lethe_replay_node = Lethe_Replay_Node of {
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   113
  id: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   114
  rule: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   115
  args: term list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   116
  prems: string list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   117
  proof_ctxt: term list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   118
  concl: term,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   119
  bounds: (string * typ) list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   120
  insts: term Symtab.table,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   121
  declarations: (string * term) list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   122
  subproof: (string * typ) list * term list * term list * lethe_replay_node list}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   123
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   124
fun mk_replay_node id rule args prems proof_ctxt concl bounds insts declarations subproof =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   125
  Lethe_Replay_Node {id = id, rule = rule, args = args, prems = prems, proof_ctxt = proof_ctxt,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   126
    concl = concl, bounds = bounds, insts = insts, declarations = declarations,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   127
    subproof = subproof}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   128
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   129
datatype lethe_step = Lethe_Step of {
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   130
  id: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   131
  rule: string,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   132
  prems: string list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   133
  proof_ctxt: term list,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   134
  concl: term,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   135
  fixes: string list}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   136
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   137
fun mk_step id rule prems proof_ctxt concl fixes =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   138
  Lethe_Step {id = id, rule = rule, prems = prems, proof_ctxt = proof_ctxt, concl = concl,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   139
    fixes = fixes}
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   140
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   141
val step_prefix = ".c"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   142
val input_rule = "input"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   143
val la_generic_rule = "la_generic"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   144
val normalized_input_rule = "__normalized_input" (*arbitrary*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   145
val rewrite_rule = "__rewrite" (*arbitrary*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   146
val subproof_rule = "subproof"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   147
val local_input_rule = "__local_input" (*arbitrary*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   148
val simp_arith_rule = "simp_arith"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   149
val lethe_def = "__skolem_definition" (*arbitrary*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   150
val not_not_rule = "not_not"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   151
val contract_rule = "contraction"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   152
val eq_congruent_pred_rule = "eq_congruent_pred"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   153
val eq_congruent_rule = "eq_congruent"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   154
val ite_intro_rule = "ite_intro"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   155
val default_skolem_rule = "sko_forall" (*arbitrary, but must be one of the skolems*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   156
val theory_resolution2_rule = "__theory_resolution2" (*arbitrary*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   157
val equiv_pos2_rule = "equiv_pos2"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   158
val th_resolution_rule = "th_resolution"
75561
b6239ed66b94 fix veriT reconstruction for and_pos and lambda-lifting
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 75299
diff changeset
   159
val and_pos_rule = "and_pos"
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   160
val hole = "hole"
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   161
75956
1e2a9d2251b0 remove duplicate parsing for alethe; fix skolemization;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 75561
diff changeset
   162
val is_lethe_def = String.isSuffix lethe_def
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   163
val skolemization_steps = ["sko_forall", "sko_ex"]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   164
val is_skolemization = member (op =) skolemization_steps
75561
b6239ed66b94 fix veriT reconstruction for and_pos and lambda-lifting
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 75299
diff changeset
   165
val keep_app_symbols = member (op =) [eq_congruent_pred_rule, eq_congruent_rule, ite_intro_rule, and_pos_rule]
b6239ed66b94 fix veriT reconstruction for and_pos and lambda-lifting
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 75299
diff changeset
   166
val keep_raw_lifting = member (op =) [eq_congruent_pred_rule, eq_congruent_rule, ite_intro_rule, and_pos_rule]
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   167
val is_SH_trivial = member (op =) [not_not_rule, contract_rule]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   168
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   169
fun is_skolemization_step (Lethe_Replay_Node {id, ...}) = is_skolemization id
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   170
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   171
(* Even the lethe developers do not know if the following rule can still appear in proofs: *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   172
val lethe_deep_skolemize_rule = "deep_skolemize"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   173
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   174
fun number_of_steps [] = 0
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   175
  | number_of_steps ((Lethe_Replay_Node {subproof = (_, _, _, subproof), ...}) :: pf) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   176
      1 + number_of_steps subproof + number_of_steps pf
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   177
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   178
(* proof parser *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   179
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   180
fun node_of p cx =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   181
  ([], cx)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   182
  ||>> `(with_fresh_names (term_of p))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   183
  |>> snd
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   184
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   185
fun synctactic_var_subst old_name new_name (u $ v) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   186
    (synctactic_var_subst old_name new_name u $ synctactic_var_subst old_name new_name v)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   187
  | synctactic_var_subst old_name new_name (Abs (v, T, u)) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   188
    Abs (if String.isPrefix old_name v then new_name else v, T,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   189
      synctactic_var_subst old_name new_name u)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   190
  | synctactic_var_subst old_name new_name (Free (v, T)) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   191
     if String.isPrefix old_name v then Free (new_name, T) else Free (v, T)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   192
  | synctactic_var_subst _ _ t = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   193
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   194
fun synctatic_rew_in_lhs_subst old_name new_name (Const(\<^const_name>\<open>HOL.eq\<close>, T) $ t1 $ t2) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   195
     Const(\<^const_name>\<open>HOL.eq\<close>, T) $ synctactic_var_subst old_name new_name t1 $ t2
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   196
  | synctatic_rew_in_lhs_subst old_name new_name (Const(\<^const_name>\<open>Trueprop\<close>, T) $ t1) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   197
     Const(\<^const_name>\<open>Trueprop\<close>, T) $ (synctatic_rew_in_lhs_subst old_name new_name t1)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   198
  | synctatic_rew_in_lhs_subst _ _ t = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   199
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   200
fun add_bound_variables_to_ctxt cx =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   201
  fold (update_binding o
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   202
    (fn (s, SOME typ) => (s, Term (Free (s, type_of cx typ)))))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   203
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   204
local
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   205
  fun extract_symbols bds =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   206
    bds
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   207
    |> map (fn (SMTLIB.S [SMTLIB.Sym "=", SMTLIB.Sym x, SMTLIB.Sym y], typ) => [([x, y], typ)]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   208
           | t => raise (Fail ("match error " ^ @{make_string} t)))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   209
    |> flat
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   210
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   211
  (* onepoint can bind a variable to another variable or to a constant *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   212
  fun extract_qnt_symbols cx bds =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   213
    bds
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   214
    |> map (fn (SMTLIB.S [SMTLIB.Sym "=", SMTLIB.Sym x, SMTLIB.Sym y], typ) =>
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   215
                (case node_of (SMTLIB.Sym y) cx of
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   216
                  ((_, []), _) => [([x], typ)]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   217
                | _ => [([x, y], typ)])
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   218
             | (SMTLIB.S (SMTLIB.Sym "=" :: SMTLIB.S [SMTLIB.Sym x, typ] :: SMTLIB.Sym y :: []), _) => [([x, y], SOME typ)]
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   219
             | (SMTLIB.S (SMTLIB.Sym "=" :: SMTLIB.Sym x :: _), typ) => [([x], typ)]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   220
             |  t => raise (Fail ("match error " ^ @{make_string} t)))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   221
    |> flat
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   222
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   223
  fun extract_symbols_map bds =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   224
    bds
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   225
    |> map (fn (SMTLIB.S [SMTLIB.Sym "=", SMTLIB.Sym x, _], typ) => [([x], typ)])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   226
    |> flat
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   227
in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   228
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   229
fun declared_csts _ "__skolem_definition" [(SMTLIB.S [SMTLIB.Sym x, typ, _], _)] = [(x, typ)]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   230
  | declared_csts _ "__skolem_definition" t = raise (Fail ("unrecognized skolem_definition " ^ @{make_string} t))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   231
  | declared_csts _ _ _ = []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   232
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   233
fun skolems_introduced_by_rule (SMTLIB.S bds) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   234
  fold (fn (SMTLIB.S [SMTLIB.Sym "=", _, SMTLIB.Sym y]) => curry (op ::) y) bds []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   235
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   236
(*FIXME there is probably a way to use the information given by onepoint*)
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   237
fun bound_vars_by_rule _ "bind" bds = extract_symbols bds
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   238
  | bound_vars_by_rule cx "onepoint" bds = extract_qnt_symbols cx bds
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   239
  | bound_vars_by_rule _ "sko_forall" bds = extract_symbols_map bds
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   240
  | bound_vars_by_rule _ "sko_ex" bds = extract_symbols_map bds
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   241
  | bound_vars_by_rule _ "__skolem_definition" [(SMTLIB.S [SMTLIB.Sym x, typ, _], _)] = [([x], SOME typ)]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   242
  | bound_vars_by_rule _ "__skolem_definition" [(SMTLIB.S [_, SMTLIB.Sym x, _], _)] = [([x], NONE)]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   243
  | bound_vars_by_rule _ _ _ = []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   244
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   245
(* Lethe adds "?" before some variables. *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   246
fun remove_all_qm (SMTLIB.Sym v :: l) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   247
    SMTLIB.Sym (perhaps (try (unprefix "?")) v) :: remove_all_qm l
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   248
  | remove_all_qm (SMTLIB.S l :: l') = SMTLIB.S (remove_all_qm l) :: remove_all_qm l'
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   249
  | remove_all_qm (SMTLIB.Key v :: l) = SMTLIB.Key v :: remove_all_qm l
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   250
  | remove_all_qm (v :: l) = v :: remove_all_qm l
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   251
  | remove_all_qm [] = []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   252
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   253
fun remove_all_qm2 (SMTLIB.Sym v) = SMTLIB.Sym (perhaps (try (unprefix "?")) v)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   254
  | remove_all_qm2 (SMTLIB.S l) = SMTLIB.S (remove_all_qm l)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   255
  | remove_all_qm2 (SMTLIB.Key v) = SMTLIB.Key v
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   256
  | remove_all_qm2 v = v
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   257
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   258
end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   259
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   260
datatype step_kind = ASSUME | ASSERT | ANCHOR | NO_STEP | NORMAL_STEP | SKOLEM
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   261
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   262
fun parse_raw_proof_steps (limit : string option) (ls : SMTLIB.tree list) (cx : name_bindings) (assms_nbr : int):
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   263
     (raw_lethe_node list * SMTLIB.tree list * name_bindings) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   264
  let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   265
    fun rotate_pair (a, (b, c)) = ((a, b), c)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   266
    fun step_kind [] = (NO_STEP, SMTLIB.S [], [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   267
      | step_kind ((p as SMTLIB.S (SMTLIB.Sym "anchor" :: _)) :: l) = (ANCHOR, p, l)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   268
      | step_kind ((p as SMTLIB.S (SMTLIB.Sym "assume" :: _)) :: l) = (ASSUME, p, l)
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   269
      | step_kind ((p as SMTLIB.S (SMTLIB.Sym "assert" :: _)) :: l) = (ASSERT, p, l)
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   270
      | step_kind ((p as SMTLIB.S (SMTLIB.Sym "step" :: _)) :: l) = (NORMAL_STEP, p, l)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   271
      | step_kind ((p as SMTLIB.S (SMTLIB.Sym "define-fun" :: _)) :: l) = (SKOLEM, p, l)
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   272
      | step_kind ((p as SMTLIB.S (SMTLIB.Sym "declare-fun" :: _)) :: l) = (SKOLEM, p, l)
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   273
      | step_kind p = raise (Fail ("step_kind unrec: " ^ @{make_string} p))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   274
    fun parse_skolem (SMTLIB.S [SMTLIB.Sym "define-fun", SMTLIB.Sym id,  _, typ,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   275
           SMTLIB.S (SMTLIB.Sym "!" :: t :: [SMTLIB.Key _, SMTLIB.Sym name])]) cx =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   276
         (*replace the name binding by the constant instead of the full term in order to reduce
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   277
           the size of the generated terms and therefore the reconstruction time*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   278
         let val (l, cx) = (fst oo SMTLIB_Proof.extract_and_update_name_bindings) t cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   279
            |> apsnd (SMTLIB_Proof.update_name_binding (name, SMTLIB.Sym id))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   280
         in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   281
           (mk_raw_node (id ^ lethe_def) lethe_def (SMTLIB.S [SMTLIB.Sym id, typ, l]) [] []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   282
              (SMTLIB.S [SMTLIB.Sym "=", SMTLIB.Sym id, l]) [], cx)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   283
         end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   284
      | parse_skolem (SMTLIB.S [SMTLIB.Sym "define-fun", SMTLIB.Sym id,  _, typ, SMTLIB.S l]) cx =
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   285
         let val (l, cx) = (fst oo SMTLIB_Proof.extract_and_update_name_bindings) (SMTLIB.S l) cx
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   286
         in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   287
           (mk_raw_node (id ^ lethe_def) lethe_def (SMTLIB.S [SMTLIB.Sym id, typ, l]) [] []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   288
              (SMTLIB.S [SMTLIB.Sym "=", SMTLIB.Sym id, l]) [], cx)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   289
         end
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   290
      | parse_skolem (SMTLIB.S [SMTLIB.Sym "declare-fun", SMTLIB.Sym id, typ, def]) cx =
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   291
         (*replace the name binding by the constant instead of the full term in order to reduce
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   292
           the size of the generated terms and therefore the reconstruction time*)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   293
         let val (l, cx) = (fst oo SMTLIB_Proof.extract_and_update_name_bindings) def cx
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   294
         in
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   295
           (mk_raw_node (id ^ lethe_def) lethe_def (SMTLIB.S [SMTLIB.Sym id, typ, l]) [] []
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   296
              (SMTLIB.S [SMTLIB.Sym "=", SMTLIB.Sym id, def]) [], cx)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   297
         end
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   298
      | parse_skolem t _ = raise Fail ("unrecognized Lethe proof " ^ \<^make_string> t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   299
    fun get_id_cx (SMTLIB.S ((SMTLIB.Sym _) :: (SMTLIB.Sym id) :: l), cx) = (id, (l, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   300
      | get_id_cx t = raise Fail ("unrecognized Lethe proof " ^ \<^make_string> t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   301
    fun get_id (SMTLIB.S ((SMTLIB.Sym _) :: (SMTLIB.Sym id) :: l)) = (id, l)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   302
      | get_id t = raise Fail ("unrecognized Lethe proof " ^ \<^make_string> t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   303
    fun parse_source (SMTLIB.Key "premises" :: SMTLIB.S source ::l, cx) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   304
        (SOME (map (fn (SMTLIB.Sym id) => id) source), (l, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   305
      | parse_source (l, cx) = (NONE, (l, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   306
    fun parse_rule (SMTLIB.Key "rule" :: SMTLIB.Sym r :: l, cx) = (r, (l, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   307
      | parse_rule t = raise Fail ("unrecognized Lethe proof " ^ \<^make_string> t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   308
    fun parse_anchor_step (SMTLIB.S (SMTLIB.Sym "anchor" :: SMTLIB.Key "step" :: SMTLIB.Sym r :: l), cx) = (r, (l, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   309
      | parse_anchor_step t = raise Fail ("unrecognized Lethe proof " ^ \<^make_string> t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   310
    fun parse_args (SMTLIB.Key "args" :: args :: l, cx) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   311
          let val ((args, cx), _) = SMTLIB_Proof.extract_and_update_name_bindings args cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   312
          in (args, (l, cx)) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   313
      | parse_args (l, cx) = (SMTLIB.S [], (l, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   314
    fun parse_and_clausify_conclusion (SMTLIB.S (SMTLIB.Sym "cl" :: []) :: l, cx) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   315
          (SMTLIB.Sym "false", (l, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   316
      | parse_and_clausify_conclusion (SMTLIB.S (SMTLIB.Sym "cl" :: concl) :: l, cx) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   317
          let val (concl, cx) = fold_map (fst oo SMTLIB_Proof.extract_and_update_name_bindings) concl cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   318
          in (SMTLIB.S (SMTLIB.Sym "or" :: concl), (l, cx)) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   319
      | parse_and_clausify_conclusion t = raise Fail ("unrecognized Lethe proof " ^ \<^make_string> t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   320
    val parse_normal_step =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   321
        get_id_cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   322
        ##> parse_and_clausify_conclusion
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   323
        #> rotate_pair
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   324
        ##> parse_rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   325
        #> rotate_pair
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   326
        ##> parse_source
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   327
        #> rotate_pair
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   328
        ##> parse_args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   329
        #> rotate_pair
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   330
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   331
    fun to_raw_node subproof ((((id, concl), rule), prems), args) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   332
        mk_raw_node id rule args (the_default [] prems) [] concl subproof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   333
    fun at_discharge NONE _ = false
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   334
      | at_discharge (SOME id) p = p |> get_id |> fst |> (fn id2 => id = id2)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   335
  in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   336
    case step_kind ls of
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   337
        (NO_STEP, _, _) => ([],[], cx)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   338
      | (NORMAL_STEP, p, l) =>
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   339
          if at_discharge limit p then ([], ls, cx) else
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   340
            let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   341
             (*ignores content of "discharge": Isabelle is keeping track of it via the context*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   342
              val (s, (_, cx)) =  (p, cx)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   343
                |> parse_normal_step
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   344
                |>>  (to_raw_node [])
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   345
              val (rp, rl, cx) = parse_raw_proof_steps limit l cx assms_nbr
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   346
          in (s :: rp, rl, cx) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   347
      | (ASSUME, p, l) =>
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   348
          let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   349
            val (id, t :: []) = p
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   350
              |> get_id
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   351
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   352
            val ((t, cx), _) = SMTLIB_Proof.extract_and_update_name_bindings t cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   353
            val s = mk_raw_node id input_rule (SMTLIB.S []) [] [] t []
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   354
            (*Recursive call to parse rest of the steps.*)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   355
            val (rp, rl, cx) = parse_raw_proof_steps limit l cx (assms_nbr + 1)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   356
          in (s :: rp, rl, cx) end
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   357
      | (ASSERT, p, l) => 
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   358
          let
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   359
            val (id, term) = (case p of
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   360
                SMTLIB.S [SMTLIB.Sym "assert", SMTLIB.S [SMTLIB.Sym "!", term, SMTLIB.Key "named", SMTLIB.Sym id]] => (id, term)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   361
              | SMTLIB.S [SMTLIB.Sym "assert", term] => (Int.toString assms_nbr, term))
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   362
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   363
            val ((t, cx), _) = SMTLIB_Proof.extract_and_update_name_bindings term cx
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   364
            val s = mk_raw_node id input_rule (SMTLIB.S []) [] [] t []
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   365
            (*Recursive call to parse rest of the steps.*)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   366
            val (rp, rl, cx) = parse_raw_proof_steps limit l cx (assms_nbr+1)
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   367
          in (s :: rp, rl, cx) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   368
      | (ANCHOR, p, l) =>
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   369
          let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   370
            val (anchor_id, (anchor_args, (_, cx))) = (p, cx) |> (parse_anchor_step ##> parse_args)
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   371
            val (subproof, discharge_step :: remaining_proof, cx) = parse_raw_proof_steps (SOME anchor_id) l cx assms_nbr
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   372
            val (curss, (_, cx)) = parse_normal_step (discharge_step, cx)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   373
            val s = to_raw_node subproof (fst curss, anchor_args)
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   374
            val (rp, rl, cx) = parse_raw_proof_steps limit remaining_proof cx assms_nbr
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   375
          in (s :: rp, rl, cx) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   376
      | (SKOLEM, p, l) =>
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   377
          let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   378
            val (s, cx) = parse_skolem p cx
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   379
            val (rp, rl, cx) = parse_raw_proof_steps limit l cx (assms_nbr)
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   380
          in (s :: rp, rl, cx) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   381
  end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   382
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   383
fun proof_ctxt_of_rule "bind" t = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   384
  | proof_ctxt_of_rule "sko_forall" t = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   385
  | proof_ctxt_of_rule "sko_ex" t = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   386
  | proof_ctxt_of_rule "let" t = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   387
  | proof_ctxt_of_rule "onepoint" t = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   388
  | proof_ctxt_of_rule _ _ = []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   389
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   390
fun args_of_rule "bind" t = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   391
  | args_of_rule "la_generic" t = t
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   392
  | args_of_rule "all_simplify" t = t
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   393
  | args_of_rule _ _ = []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   394
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   395
fun insts_of_forall_inst "forall_inst" t = map (fn SMTLIB.S [_, SMTLIB.Sym x, a] => (x, a)) t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   396
  | insts_of_forall_inst _ _ = []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   397
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   398
fun id_of_last_step prems =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   399
  if null prems then []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   400
  else
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   401
    let val Lethe_Replay_Node {id, ...} = List.last prems in [id] end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   402
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   403
fun extract_assumptions_from_subproof subproof =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   404
  let fun extract_assumptions_from_subproof (Lethe_Replay_Node {rule, concl, ...}) assms =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   405
    if rule = local_input_rule then concl :: assms else assms
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   406
  in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   407
    fold extract_assumptions_from_subproof subproof []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   408
  end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   409
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   410
fun normalized_rule_name id rule =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   411
  (case (rule = input_rule, can SMTLIB_Interface.role_and_index_of_assert_name id) of
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   412
    (true, true) => normalized_input_rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   413
  | (true, _) => local_input_rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   414
  | _ => rule)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   415
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   416
fun is_assm_repetition id rule =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   417
  rule = input_rule andalso can SMTLIB_Interface.role_and_index_of_assert_name id
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   418
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   419
fun extract_skolem ([SMTLIB.Sym var, typ, choice]) = (var, typ, choice)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   420
  | extract_skolem t = raise Fail ("fail to parse type" ^ @{make_string} t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   421
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   422
(* The preprocessing takes care of:
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   423
     1. unfolding the shared terms
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   424
     2. extract the declarations of skolems to make sure that there are not unfolded
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   425
*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   426
fun preprocess compress step =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   427
  let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   428
    fun expand_assms cs =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   429
      map (fn t => case AList.lookup (op =) cs t of NONE => t | SOME a => a)
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   430
    fun match_typing_arguments (SMTLIB.S [SMTLIB.Sym var, typ as SMTLIB.Sym _] :: SMTLIB.S [SMTLIB.Sym "=", SMTLIB.Sym x1, x2] :: xs) =
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   431
       if var = x1 then (*CVC5*)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   432
         SMTLIB.S [SMTLIB.Sym "=", SMTLIB.S [SMTLIB.Sym x1, typ], x2] :: match_typing_arguments xs
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   433
       else
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   434
         SMTLIB.S [SMTLIB.Sym var, typ] :: match_typing_arguments (SMTLIB.S [SMTLIB.Sym "=", SMTLIB.Sym x1, x2] :: xs)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   435
     | match_typing_arguments (a :: xs) = a :: match_typing_arguments xs
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   436
     | match_typing_arguments [] = []
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   437
    fun expand_lonely_arguments (args as SMTLIB.S [SMTLIB.Sym "=", _, _]) = [args]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   438
      | expand_lonely_arguments (x as SMTLIB.S [SMTLIB.Sym var, _]) = [SMTLIB.S [SMTLIB.Sym "=", x, SMTLIB.Sym var]]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   439
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   440
    fun preprocess (Raw_Lethe_Node {id, rule, args, prems, concl, subproof, ...}) (cx, remap_assms)  =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   441
      let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   442
        val (skolem_names, stripped_args) = args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   443
          |> (fn SMTLIB.S args => args)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   444
          |> map
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   445
              (fn SMTLIB.S [SMTLIB.Key "=", x, y] => SMTLIB.S [SMTLIB.Sym "=", x, y]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   446
              | x => x)
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   447
          |> (rule = "bind" orelse rule = "onepoint") ? flat o (map expand_lonely_arguments) o match_typing_arguments
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   448
          |> `(if rule = lethe_def then single o extract_skolem else K [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   449
          ||> SMTLIB.S
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   450
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   451
        val (subproof, (cx, _)) = fold_map preprocess subproof (cx, remap_assms) |> apfst flat
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   452
        val remap_assms = (if rule = "or" then (id, hd prems) :: remap_assms else remap_assms)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   453
        (* declare variables in the context *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   454
        val declarations =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   455
           if rule = lethe_def
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   456
           then skolem_names |> map (fn (name, _, choice) => (name, choice))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   457
           else []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   458
      in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   459
        if compress andalso rule = "or"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   460
        then ([], (cx, remap_assms))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   461
        else ([Raw_Lethe_Node {id = id, rule = rule, args = stripped_args,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   462
           prems = expand_assms remap_assms prems, declarations = declarations, concl = concl, subproof = subproof}],
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   463
          (cx, remap_assms))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   464
      end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   465
  in preprocess step end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   466
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   467
fun filter_split _ [] = ([], [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   468
  | filter_split f (a :: xs) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   469
     (if f a then apfst (curry op :: a) else apsnd (curry op :: a)) (filter_split f xs)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   470
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   471
fun extract_types_of_args (SMTLIB.S [var, typ, t as SMTLIB.S [SMTLIB.Sym "choice", _, _]]) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   472
    (SMTLIB.S [var, typ, t], SOME typ)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   473
    |> single
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   474
 | extract_types_of_args (SMTLIB.S t) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   475
  let
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   476
    fun extract_types_of_arg (SMTLIB.S [eq as SMTLIB.Sym "=", SMTLIB.S [var, typ], t]) = (SMTLIB.S [eq, var, t], SOME typ)
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   477
      | extract_types_of_arg t = (t, NONE)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   478
  in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   479
    t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   480
    |> map extract_types_of_arg
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   481
  end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   482
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   483
fun collect_skolem_defs (Raw_Lethe_Node {rule, subproof = subproof, args, ...}) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   484
  (if is_skolemization rule then map (fn id => id ^ lethe_def) (skolems_introduced_by_rule args) else []) @
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   485
  flat (map collect_skolem_defs subproof)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   486
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   487
val desymbolize = Name.desymbolize (SOME false) o perhaps (try (unprefix "?"))
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   488
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   489
(*The postprocessing does:
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   490
  1. translate the terms to Isabelle syntax, taking care of free variables
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   491
  2. remove the ambiguity in the proof terms:
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   492
       x \<leadsto> y |- x = x
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   493
    means y = x. To remove ambiguity, we use the fact that y is a free variable and replace the term
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   494
    by:
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   495
      xy \<leadsto> y |- xy = x.
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   496
    This is now does not have an ambiguity and we can safely move the "xy \<leadsto> y" to the proof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   497
    assumptions.
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   498
*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   499
fun postprocess_proof compress ctxt step cx =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   500
  let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   501
    fun postprocess (Raw_Lethe_Node {id, rule, args, prems, declarations, concl, subproof}) (cx, rew) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   502
    let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   503
      val args = extract_types_of_args args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   504
      val globally_bound_vars = declared_csts cx rule args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   505
      val cx = fold (update_binding o (fn (s, typ) => (s, Term (Free (s, type_of cx typ)))))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   506
           globally_bound_vars cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   507
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   508
      (*find rebound variables specific to the LHS of the equivalence symbol*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   509
      val bound_vars = bound_vars_by_rule cx rule args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   510
      val bound_vars_no_typ = map fst bound_vars
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   511
      val rhs_vars =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   512
        fold (fn [t', t] => t <> t' ? (curry (op ::) t) | _ => fn x => x) bound_vars_no_typ []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   513
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   514
      fun not_already_bound cx t = SMTLIB_Proof.lookup_binding cx t = None andalso
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   515
          not (member (op =) rhs_vars t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   516
      val (shadowing_vars, rebound_lhs_vars) = bound_vars
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   517
        |> filter_split (fn ([t, _], typ) => not_already_bound cx t | _ => true)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   518
        |>> map (apfst (hd))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   519
        |>> (fn vars => vars @ flat (map (fn ([_, t], typ) => [(t, typ)] | _ => []) bound_vars))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   520
      val subproof_rew = fold (fn [t, t'] => curry (op ::) (t, t ^ t'))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   521
        (map fst rebound_lhs_vars) rew
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   522
      val subproof_rewriter = fold (fn (t, t') => synctatic_rew_in_lhs_subst t t')
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   523
         subproof_rew
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   524
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   525
      val ((concl, bounds), cx') = node_of concl cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   526
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   527
      val extra_lhs_vars = map (fn ([a,b], typ) => (a, a^b, typ)) rebound_lhs_vars
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   528
      val old_lhs_vars = map (fn (a, _, typ) => (a, typ)) extra_lhs_vars
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   529
      val new_lhs_vars = map (fn (_, newvar, typ) => (newvar, typ)) extra_lhs_vars
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   530
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   531
      (* postprocess conclusion *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   532
      val concl = SMTLIB_Isar.unskolemize_names ctxt (subproof_rewriter concl)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   533
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   534
      fun give_proper_type (s, SOME typ) = (s, type_of cx typ)
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   535
       | give_proper_type (s, NONE) = raise (Fail ("could not find type of var " ^ @{make_string} s ^ " in step " ^ id ^ " in " ^  @{make_string} concl))
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   536
      val bound_tvars = map give_proper_type (shadowing_vars @ new_lhs_vars)
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   537
      val subproof_cx =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   538
         add_bound_variables_to_ctxt cx (shadowing_vars @ new_lhs_vars) cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   539
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   540
      fun could_unify (Bound i, Bound j) = i = j
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   541
        | could_unify (Var v, Var v') = v = v'
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   542
        | could_unify (Free v, Free v') = v = v'
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   543
        | could_unify (Const (v, ty), Const (v', ty')) = v = v' andalso ty = ty'
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   544
        | could_unify (Abs (_, ty, bdy), Abs (_, ty', bdy')) = ty = ty' andalso could_unify (bdy, bdy')
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   545
        | could_unify (u $ v, u' $ v') = could_unify (u, u') andalso could_unify (v, v')
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   546
        | could_unify _ = false
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   547
      fun is_alpha_renaming t =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   548
          t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   549
          |> HOLogic.dest_Trueprop
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   550
          |> HOLogic.dest_eq
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   551
          |> could_unify
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   552
        handle TERM _ => false
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   553
      val alpha_conversion = rule = "bind" andalso is_alpha_renaming concl
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   554
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   555
      val can_remove_subproof =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   556
        compress andalso (is_skolemization rule orelse alpha_conversion)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   557
      val (fixed_subproof : lethe_replay_node list, _) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   558
         fold_map postprocess (if can_remove_subproof then [] else subproof)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   559
           (subproof_cx, subproof_rew)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   560
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   561
      val unsk_and_rewrite = SMTLIB_Isar.unskolemize_names ctxt o subproof_rewriter
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   562
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   563
      (* postprocess assms *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   564
      val stripped_args = map fst args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   565
      val sanitized_args = proof_ctxt_of_rule rule stripped_args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   566
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   567
      val arg_cx = add_bound_variables_to_ctxt cx (shadowing_vars @ old_lhs_vars) subproof_cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   568
      val (termified_args, _) = fold_map node_of sanitized_args arg_cx |> apfst (map fst)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   569
      val normalized_args = map unsk_and_rewrite termified_args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   570
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   571
      val subproof_assms = proof_ctxt_of_rule rule normalized_args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   572
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   573
      (* postprocess arguments *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   574
      val rule_args = args_of_rule rule stripped_args
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   575
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   576
      val (termified_args, _) = fold_map term_of rule_args subproof_cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   577
      val normalized_args = map unsk_and_rewrite termified_args
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   578
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   579
      val rule_args = map subproof_rewriter normalized_args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   580
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   581
      val raw_insts = insts_of_forall_inst rule stripped_args
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   582
      fun termify_term (x, t) cx = let val (t, cx) = term_of t cx in ((x, t), cx) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   583
      val (termified_args, _) = fold_map termify_term raw_insts subproof_cx
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   584
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   585
      val insts = Symtab.empty
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   586
        |> fold (fn (x, t) => fn insts => Symtab.update_new (desymbolize x, t) insts) termified_args
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   587
        |> Symtab.map (K unsk_and_rewrite)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   588
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   589
      (* declarations *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   590
      val (declarations, _) = fold_map termify_term declarations cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   591
        |> apfst (map (apsnd unsk_and_rewrite))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   592
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   593
      (* fix step *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   594
      val _ = if bounds <> [] then raise (Fail "found dangling variable in concl") else ()
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   595
      val skolem_defs = (if is_skolemization rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   596
         then map (fn id => id ^ lethe_def) (skolems_introduced_by_rule (SMTLIB.S (map fst args))) else [])
75956
1e2a9d2251b0 remove duplicate parsing for alethe; fix skolemization;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 75561
diff changeset
   597
      val skolems_of_subproof = (if compress andalso is_skolemization rule
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   598
         then flat (map collect_skolem_defs subproof) else [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   599
      val fixed_prems =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   600
        prems @ (if is_assm_repetition id rule then [id] else []) @
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   601
        skolem_defs @ skolems_of_subproof @ (id_of_last_step fixed_subproof)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   602
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   603
      (* fix subproof *)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   604
      val normalized_rule = normalized_rule_name id rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   605
        |> (if compress andalso alpha_conversion then K "refl" else I)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   606
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   607
      val extra_assms2 =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   608
        (if rule = subproof_rule then extract_assumptions_from_subproof fixed_subproof else [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   609
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   610
      val step = mk_replay_node id normalized_rule rule_args fixed_prems subproof_assms concl
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   611
        [] insts declarations (bound_tvars, subproof_assms, extra_assms2, fixed_subproof)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   612
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   613
    in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   614
       (step, (cx', rew))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   615
    end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   616
  in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   617
    postprocess step (cx, [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   618
    |> (fn (step, (cx, _)) => (step, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   619
  end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   620
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   621
fun combine_proof_steps ((step1 : lethe_replay_node) :: step2 :: steps) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   622
      let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   623
        val (Lethe_Replay_Node {id = id1, rule = rule1, args = args1, prems = prems1,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   624
            proof_ctxt = proof_ctxt1, concl = concl1, bounds = bounds1, insts = insts1,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   625
            declarations = declarations1,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   626
            subproof = (bound_sub1, assms_sub1, assms_extra1, subproof1)}) = step1
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   627
        val (Lethe_Replay_Node {id = id2, rule = rule2, args = args2, prems = prems2,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   628
            proof_ctxt = proof_ctxt2, concl = concl2, bounds = bounds2, insts = insts2,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   629
            declarations = declarations2,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   630
            subproof = (bound_sub2, assms_sub2, assms_extra2, subproof2)}) = step2
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   631
        val goals1 =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   632
          (case concl1 of
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   633
            _ $ (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ _ $
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   634
                  (Const (\<^const_name>\<open>HOL.disj\<close>, _) $ (Const (\<^const_name>\<open>HOL.Not\<close>, _) $a) $ b)) => [a,b]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   635
          | _ => [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   636
        val goal2 = (case concl2 of _ $ a => a)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   637
      in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   638
        if rule1 = equiv_pos2_rule andalso rule2 = th_resolution_rule andalso member (op =) prems2 id1
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   639
          andalso member (op =) goals1 goal2
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   640
        then
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   641
          mk_replay_node id2 theory_resolution2_rule args2 (filter_out (curry (op =) id1) prems2)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   642
            proof_ctxt2 concl2 bounds2 insts2 declarations2
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   643
            (bound_sub2, assms_sub2, assms_extra2, combine_proof_steps subproof2) ::
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   644
          combine_proof_steps steps
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   645
        else
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   646
          mk_replay_node id1 rule1 args1 prems1
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   647
            proof_ctxt1 concl1 bounds1 insts1 declarations1
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   648
            (bound_sub1, assms_sub1, assms_extra1, combine_proof_steps subproof1) ::
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   649
          combine_proof_steps (step2 :: steps)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   650
      end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   651
  | combine_proof_steps steps = steps
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   652
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   653
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   654
val linearize_proof =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   655
  let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   656
    fun map_node_concl f (Lethe_Node {id, rule, prems, proof_ctxt, concl}) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   657
       mk_node id rule prems proof_ctxt (f concl)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   658
    fun linearize (Lethe_Replay_Node {id = id, rule = rule, args = _, prems = prems,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   659
        proof_ctxt = proof_ctxt, concl = concl, bounds = bounds, insts = _, declarations = _,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   660
        subproof = (bounds', assms, inputs, subproof)}) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   661
      let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   662
        val bounds = distinct (op =) bounds
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   663
        val bounds' = distinct (op =) bounds'
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   664
        fun mk_prop_of_term concl =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   665
          concl |> fastype_of concl = \<^typ>\<open>bool\<close> ? curry (op $) \<^term>\<open>Trueprop\<close>
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   666
        fun remove_assumption_id assumption_id prems =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   667
          filter_out (curry (op =) assumption_id) prems
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   668
        fun add_assumption assumption concl =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   669
          \<^Const>\<open>Pure.imp for \<open>mk_prop_of_term assumption\<close> \<open>mk_prop_of_term concl\<close>\<close>
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   670
        fun inline_assumption assumption assumption_id
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   671
            (Lethe_Node {id, rule, prems, proof_ctxt, concl}) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   672
          mk_node id rule (remove_assumption_id assumption_id prems) proof_ctxt
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   673
            (add_assumption assumption concl)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   674
        fun find_input_steps_and_inline [] = []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   675
          | find_input_steps_and_inline
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   676
              (Lethe_Node {id = id', rule, prems, concl, ...} :: steps) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   677
            if rule = input_rule then
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   678
              find_input_steps_and_inline (map (inline_assumption concl id') steps)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   679
            else
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   680
              mk_node (id') rule prems [] concl :: find_input_steps_and_inline steps
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   681
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   682
        fun free_bounds bounds (concl) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   683
          fold (fn (var, typ) => fn t => Logic.all (Free (var, typ)) t) bounds concl
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   684
        val subproof = subproof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   685
          |> flat o map linearize
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   686
          |> map (map_node_concl (fold add_assumption (assms @ inputs)))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   687
          |> map (map_node_concl (free_bounds (bounds @ bounds')))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   688
          |> find_input_steps_and_inline
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   689
        val concl = free_bounds bounds concl
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   690
      in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   691
        subproof @ [mk_node id rule prems proof_ctxt concl]
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   692
      end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   693
  in linearize end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   694
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   695
fun rule_of (Lethe_Replay_Node {rule,...}) = rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   696
fun subproof_of (Lethe_Replay_Node {subproof = (_, _, _, subproof),...}) = subproof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   697
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   698
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   699
(* Massage Skolems for Sledgehammer.
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   700
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   701
We have to make sure that there is an "arrow" in the graph for skolemization steps.
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   702
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   703
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   704
A. The normal easy case
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   705
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   706
This function detects the steps of the form
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   707
  P \<longleftrightarrow> Q :skolemization
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   708
  Q       :resolution with P
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   709
and replace them by
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   710
  Q       :skolemization
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   711
Throwing away the step "P \<longleftrightarrow> Q" completely. This throws away a lot of information, but it does not
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   712
matter too much for Sledgehammer.
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   713
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   714
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   715
B. Skolems in subproofs
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   716
Supporting this is more or less hopeless as long as the Isar reconstruction of Sledgehammer
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   717
does not support more features like definitions. lethe is able to generate proofs with skolemization
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   718
happening in subproofs inside the formula.
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   719
  (assume "A \<or> P"
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   720
   ...
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   721
   P \<longleftrightarrow> Q :skolemization in the subproof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   722
   ...)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   723
  hence A \<or> P \<longrightarrow> A \<or> Q :lemma
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   724
  ...
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   725
  R :something with some rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   726
and replace them by
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   727
  R :skolemization with some rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   728
Without any subproof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   729
*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   730
fun remove_skolem_definitions_proof steps =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   731
  let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   732
    fun replace_equivalent_by_imp (judgement $ ((Const(\<^const_name>\<open>HOL.eq\<close>, typ) $ arg1) $ arg2)) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   733
       judgement $ ((Const(\<^const_name>\<open>HOL.implies\<close>, typ) $ arg1) $ arg2)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   734
     | replace_equivalent_by_imp a = a (*This case is probably wrong*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   735
    fun remove_skolem_definitions (Lethe_Replay_Node {id = id, rule = rule, args = args,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   736
         prems = prems,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   737
        proof_ctxt = proof_ctxt, concl = concl, bounds = bounds, insts = insts,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   738
        declarations = declarations,
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   739
        subproof = (vars, assms', extra_assms', subproof)}) (prems_to_remove, skolems) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   740
    let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   741
      val prems = prems
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   742
        |> filter_out (member (op =) prems_to_remove)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   743
      val trivial_step = is_SH_trivial rule
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   744
      fun has_skolem_substep st NONE = if is_skolemization (rule_of st) then SOME (rule_of st)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   745
             else fold has_skolem_substep (subproof_of st) NONE
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   746
        | has_skolem_substep _ a = a
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   747
      val promote_to_skolem = exists (fn t => member (op =) skolems t) prems
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   748
      val promote_from_assms = fold has_skolem_substep subproof NONE <> NONE
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   749
      val promote_step = promote_to_skolem orelse promote_from_assms
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   750
      val skolem_step_to_skip = is_skolemization rule orelse
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   751
        (promote_from_assms andalso length prems > 1)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   752
      val is_skolem = is_skolemization rule orelse promote_step
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   753
      val prems = prems
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   754
        |> filter_out (fn t => member (op =) skolems t)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   755
        |> is_skolem ? filter_out (String.isPrefix id)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   756
      val rule = (if promote_step then default_skolem_rule else rule)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   757
      val subproof = subproof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   758
        |> (is_skolem ? K []) (*subproofs of skolemization steps are useless for SH*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   759
        |> map (fst o (fn st => remove_skolem_definitions st (prems_to_remove, skolems)))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   760
             (*no new definitions in subproofs*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   761
        |> flat
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   762
      val concl = concl
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   763
        |> is_skolem ? replace_equivalent_by_imp
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   764
      val step = (if skolem_step_to_skip orelse rule = lethe_def orelse trivial_step then []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   765
        else mk_replay_node id rule args prems proof_ctxt concl bounds insts declarations
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   766
            (vars, assms', extra_assms', subproof)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   767
          |> single)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   768
      val defs = (if rule = lethe_def orelse trivial_step then id :: prems_to_remove
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   769
         else prems_to_remove)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   770
      val skolems = (if skolem_step_to_skip then id :: skolems else skolems)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   771
    in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   772
      (step, (defs, skolems))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   773
    end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   774
  in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   775
    fold_map remove_skolem_definitions steps ([], [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   776
    |> fst
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   777
    |> flat
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   778
  end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   779
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   780
local
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   781
  (*TODO useful?*)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   782
  fun remove_pattern (SMTLIB.S (SMTLIB.Sym "!" :: t :: [SMTLIB.Key _, SMTLIB.S _])) = t
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   783
    | remove_pattern (SMTLIB.S xs) = SMTLIB.S (map remove_pattern xs)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   784
    | remove_pattern p = p
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   785
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   786
  fun import_proof_and_post_process typs funs lines ctxt =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   787
    let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   788
      val compress = SMT_Config.compress_verit_proofs ctxt
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   789
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   790
      val smtlib_lines_without_qm =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   791
        lines
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   792
        |> filter_out (fn x => x = "")
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   793
        |> map single
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   794
        |> map SMTLIB.parse
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   795
        |> map remove_all_qm2
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   796
        |> map remove_pattern
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   797
      val (raw_steps, _, _) =
78177
ea7a3cc64df5 early inclusion of cvc5 proof reconstruction; slightly reorganize smt/z3_reals;
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 76183
diff changeset
   798
        parse_raw_proof_steps NONE smtlib_lines_without_qm SMTLIB_Proof.empty_name_binding 0
75299
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   799
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   800
      fun process step (cx, cx') =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   801
        let fun postprocess step (cx, cx') =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   802
          let val (step, cx) = postprocess_proof compress ctxt step cx
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   803
          in (step, (cx, cx')) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   804
        in uncurry (fold_map postprocess) (preprocess compress step (cx, cx')) end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   805
      val step =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   806
        (empty_context ctxt typs funs, [])
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   807
        |> fold_map process raw_steps
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   808
        |> (fn (steps, (cx, _)) => (flat steps, cx))
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   809
        |> compress? apfst combine_proof_steps
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   810
    in step end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   811
in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   812
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   813
fun parse typs funs lines ctxt =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   814
  let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   815
    val (u, env) = import_proof_and_post_process typs funs lines ctxt
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   816
    val t = u
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   817
       |> remove_skolem_definitions_proof
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   818
       |> flat o (map linearize_proof)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   819
    fun node_to_step (Lethe_Node {id, rule, prems, concl, ...}) =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   820
      mk_step id rule prems [] concl []
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   821
  in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   822
    (map node_to_step t, ctxt_of env)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   823
  end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   824
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   825
fun parse_replay typs funs lines ctxt =
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   826
  let
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   827
    val (u, env) = import_proof_and_post_process typs funs lines ctxt
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   828
  in
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   829
    (u, ctxt_of env)
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   830
  end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   831
end
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   832
da591621d6ae split veriT reconstruction into Lethe and veriT part
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
diff changeset
   833
end;