src/HOL/Tools/SMT2/smtlib2_isar.ML
author blanchet
Fri, 01 Aug 2014 23:29:50 +0200
changeset 57768 a63f14f1214c
parent 57767 5bc204ca27ce
permissions -rw-r--r--
fine-tuned Isar reconstruction, esp. boolean simplifications
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     1
(*  Title:      HOL/Tools/SMT2/smtlib2_isar.ML
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     3
    Author:     Mathias Fleury, ENS Rennes
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     4
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     5
General tools for Isar proof reconstruction.
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     6
*)
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     7
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     8
signature SMTLIB2_ISAR =
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
     9
sig
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    10
  val unlift_term: term list -> term -> term
57748
31f5781fa9cd tuned order of arguments
blanchet
parents: 57745
diff changeset
    11
  val postprocess_step_conclusion: theory -> thm list -> term list -> term -> term
57705
5da48dae7d03 Subproofs for the SMT solver veriT.
fleury
parents: 57704
diff changeset
    12
  val normalizing_prems : Proof.context -> term -> (string * string list) list
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    13
  val distinguish_conjecture_and_hypothesis : ''a list -> ''b -> ''b -> ''b list ->
57768
a63f14f1214c fine-tuned Isar reconstruction, esp. boolean simplifications
blanchet
parents: 57767
diff changeset
    14
    (''a * 'c) list -> 'c list -> 'c -> (ATP_Problem.atp_formula_role * 'c) option
57708
4b52c1b319ce veriT changes for lifted terms, and ite_elim rules.
fleury
parents: 57705
diff changeset
    15
  val unskolemize_names: term -> term
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    16
end;
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    17
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    18
structure SMTLIB2_Isar: SMTLIB2_ISAR =
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    19
struct
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    20
57768
a63f14f1214c fine-tuned Isar reconstruction, esp. boolean simplifications
blanchet
parents: 57767
diff changeset
    21
open ATP_Util
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    22
open ATP_Problem
57768
a63f14f1214c fine-tuned Isar reconstruction, esp. boolean simplifications
blanchet
parents: 57767
diff changeset
    23
open ATP_Proof_Reconstruct
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    24
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    25
fun unlift_term ll_defs =
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    26
  let
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    27
    val lifted = map (ATP_Util.extract_lambda_def dest_Free o ATP_Util.hol_open_form I) ll_defs
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    28
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    29
    fun un_free (t as Free (s, _)) =
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    30
       (case AList.lookup (op =) lifted s of
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    31
         SOME t => un_term t
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    32
       | NONE => t)
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    33
     | un_free t = t
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    34
    and un_term t = map_aterms un_free t
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    35
  in un_term end
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    36
57714
4856a7b8b9c3 Changing the role of rule "tmp_ite_elim" of the SMT solver veriT to Lemma.
fleury
parents: 57710
diff changeset
    37
(* It is not entirely clear why this should be necessary, especially for abstractions variables. *)
57708
4b52c1b319ce veriT changes for lifted terms, and ite_elim rules.
fleury
parents: 57705
diff changeset
    38
val unskolemize_names =
4b52c1b319ce veriT changes for lifted terms, and ite_elim rules.
fleury
parents: 57705
diff changeset
    39
  Term.map_abs_vars (perhaps (try Name.dest_skolem))
4b52c1b319ce veriT changes for lifted terms, and ite_elim rules.
fleury
parents: 57705
diff changeset
    40
  #> Term.map_aterms (perhaps (try (fn Free (s, T) => Free (Name.dest_skolem s, T))))
4b52c1b319ce veriT changes for lifted terms, and ite_elim rules.
fleury
parents: 57705
diff changeset
    41
57748
31f5781fa9cd tuned order of arguments
blanchet
parents: 57745
diff changeset
    42
fun postprocess_step_conclusion thy rewrite_rules ll_defs =
31f5781fa9cd tuned order of arguments
blanchet
parents: 57745
diff changeset
    43
  Raw_Simplifier.rewrite_term thy rewrite_rules []
31f5781fa9cd tuned order of arguments
blanchet
parents: 57745
diff changeset
    44
  #> Object_Logic.atomize_term thy
31f5781fa9cd tuned order of arguments
blanchet
parents: 57745
diff changeset
    45
  #> not (null ll_defs) ? unlift_term ll_defs
57768
a63f14f1214c fine-tuned Isar reconstruction, esp. boolean simplifications
blanchet
parents: 57767
diff changeset
    46
  #> simplify_bool
57748
31f5781fa9cd tuned order of arguments
blanchet
parents: 57745
diff changeset
    47
  #> unskolemize_names
31f5781fa9cd tuned order of arguments
blanchet
parents: 57745
diff changeset
    48
  #> HOLogic.mk_Trueprop
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    49
57705
5da48dae7d03 Subproofs for the SMT solver veriT.
fleury
parents: 57704
diff changeset
    50
fun normalizing_prems ctxt concl0 =
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    51
  SMT2_Normalize.case_bool_entry :: SMT2_Normalize.special_quant_table @
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    52
  SMT2_Normalize.abs_min_max_table
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    53
  |> map_filter (fn (c, th) =>
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    54
    if exists_Const (curry (op =) c o fst) concl0 then
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    55
      let val s = short_thm_name ctxt th in SOME (s, [s]) end
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    56
    else
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    57
      NONE)
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    58
57768
a63f14f1214c fine-tuned Isar reconstruction, esp. boolean simplifications
blanchet
parents: 57767
diff changeset
    59
fun distinguish_conjecture_and_hypothesis ss id conjecture_id prem_ids fact_helper_ts hyp_ts
a63f14f1214c fine-tuned Isar reconstruction, esp. boolean simplifications
blanchet
parents: 57767
diff changeset
    60
    concl_t =
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    61
  (case ss of
57730
d39815cdb7ba remove lambda-lifting related assumptions from generated Isar proofs
blanchet
parents: 57714
diff changeset
    62
    [s] => SOME (Axiom, the (AList.lookup (op =) fact_helper_ts s))
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    63
  | _ =>
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    64
    if id = conjecture_id then
57730
d39815cdb7ba remove lambda-lifting related assumptions from generated Isar proofs
blanchet
parents: 57714
diff changeset
    65
      SOME (Conjecture, concl_t)
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    66
    else
57730
d39815cdb7ba remove lambda-lifting related assumptions from generated Isar proofs
blanchet
parents: 57714
diff changeset
    67
     (case find_index (curry (op =) id) prem_ids of
d39815cdb7ba remove lambda-lifting related assumptions from generated Isar proofs
blanchet
parents: 57714
diff changeset
    68
       ~1 => NONE (* lambda-lifting definition *)
d39815cdb7ba remove lambda-lifting related assumptions from generated Isar proofs
blanchet
parents: 57714
diff changeset
    69
     | i => SOME (Hypothesis, nth hyp_ts i)))
57704
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    70
c0da3fc313e3 Basic support for the SMT prover veriT.
fleury
parents:
diff changeset
    71
end;