src/HOL/Import/import.ML
author wenzelm
Sun Nov 08 18:43:42 2009 +0100 (2009-11-08)
changeset 33522 737589bb9bb8
parent 32970 fbd2bb2489a8
child 36945 9bec62c10714
permissions -rw-r--r--
adapted Theory_Data;
tuned;
haftmann@31723
     1
(*  Title:      HOL/Import/import.ML
skalberg@14620
     2
    Author:     Sebastian Skalberg (TU Muenchen)
skalberg@14620
     3
*)
skalberg@14620
     4
haftmann@31723
     5
signature IMPORT =
skalberg@14516
     6
sig
wenzelm@32740
     7
    val debug      : bool Unsynchronized.ref
wenzelm@31241
     8
    val import_tac : Proof.context -> string * string -> tactic
wenzelm@18708
     9
    val setup      : theory -> theory
skalberg@14516
    10
end
skalberg@14516
    11
wenzelm@33522
    12
structure ImportData = Theory_Data
wenzelm@22846
    13
(
wenzelm@33522
    14
  type T = ProofKernel.thm option array option  (* FIXME mutable array !??!!! *)
wenzelm@22846
    15
  val empty = NONE
wenzelm@22846
    16
  val extend = I
wenzelm@33522
    17
  fun merge _ = NONE
wenzelm@22846
    18
)
skalberg@14620
    19
haftmann@31723
    20
structure Import :> IMPORT =
skalberg@14516
    21
struct
skalberg@14516
    22
wenzelm@32740
    23
val debug = Unsynchronized.ref false
skalberg@14516
    24
fun message s = if !debug then writeln s else ()
skalberg@14516
    25
wenzelm@31241
    26
fun import_tac ctxt (thyname, thmname) =
wenzelm@17370
    27
    if ! quick_and_dirty
wenzelm@32970
    28
    then Skip_Proof.cheat_tac (ProofContext.theory_of ctxt)
skalberg@14516
    29
    else
skalberg@14516
    30
     fn th =>
wenzelm@21590
    31
        let
wenzelm@31241
    32
            val thy = ProofContext.theory_of ctxt
wenzelm@21590
    33
            val prem = hd (prems_of th)
wenzelm@31241
    34
            val _ = message ("Import_tac: thyname=" ^ thyname ^ ", thmname=" ^ thmname)
wenzelm@31241
    35
            val _ = message ("Import trying to prove " ^ Syntax.string_of_term ctxt prem)
wenzelm@21590
    36
            val int_thms = case ImportData.get thy of
wenzelm@21590
    37
                               NONE => fst (Replay.setup_int_thms thyname thy)
wenzelm@21590
    38
                             | SOME a => a
wenzelm@21590
    39
            val proof = snd (ProofKernel.import_proof thyname thmname thy) thy
wenzelm@21590
    40
            val hol4thm = snd (Replay.replay_proof int_thms thyname thmname proof thy)
wenzelm@21590
    41
            val thm = snd (ProofKernel.to_isa_thm hol4thm)
wenzelm@21590
    42
            val rew = ProofKernel.rewrite_hol4_term (concl_of thm) thy
wenzelm@21590
    43
            val thm = equal_elim rew thm
wenzelm@21590
    44
            val prew = ProofKernel.rewrite_hol4_term prem thy
wenzelm@21590
    45
            val prem' = #2 (Logic.dest_equals (prop_of prew))
wenzelm@32091
    46
            val _ = message ("Import proved " ^ Display.string_of_thm ctxt thm)
wenzelm@17657
    47
            val thm = ProofKernel.disambiguate_frees thm
wenzelm@32091
    48
            val _ = message ("Disambiguate: " ^ Display.string_of_thm ctxt thm)
wenzelm@21590
    49
        in
wenzelm@21590
    50
            case Shuffler.set_prop thy prem' [("",thm)] of
wenzelm@21590
    51
                SOME (_,thm) =>
wenzelm@21590
    52
                let
wenzelm@21590
    53
                    val _ = if prem' aconv (prop_of thm)
wenzelm@21590
    54
                            then message "import: Terms match up"
wenzelm@21590
    55
                            else message "import: Terms DO NOT match up"
wenzelm@21590
    56
                    val thm' = equal_elim (symmetric prew) thm
wenzelm@31945
    57
                    val res = Thm.bicompose true (false,thm',0) 1 th
wenzelm@21590
    58
                in
wenzelm@21590
    59
                    res
wenzelm@21590
    60
                end
wenzelm@21590
    61
              | NONE => (message "import: set_prop didn't succeed"; no_tac th)
wenzelm@21590
    62
        end
wenzelm@21590
    63
wenzelm@31241
    64
val setup = Method.setup @{binding import}
wenzelm@31241
    65
  (Scan.lift (Args.name -- Args.name) >>
wenzelm@31241
    66
    (fn arg => fn ctxt => SIMPLE_METHOD (import_tac ctxt arg)))
wenzelm@31241
    67
  "import HOL4 theorem"
skalberg@14516
    68
skalberg@14516
    69
end
wenzelm@15707
    70