src/HOL/Import/replay.ML
author wenzelm
Sat Oct 17 14:43:18 2009 +0200 (2009-10-17)
changeset 32960 69916a850301
parent 31723 f5cafe803b55
child 32966 5b21661fe618
permissions -rw-r--r--
eliminated hard tabulators, guessing at each author's individual tab-width;
tuned headers;
skalberg@14620
     1
(*  Title:      HOL/Import/replay.ML
skalberg@14620
     2
    Author:     Sebastian Skalberg (TU Muenchen)
skalberg@14620
     3
*)
skalberg@14620
     4
skalberg@14516
     5
structure Replay =
skalberg@14516
     6
struct
skalberg@14516
     7
skalberg@14516
     8
structure P = ProofKernel
skalberg@14516
     9
skalberg@14516
    10
open ProofKernel
obua@19064
    11
open ImportRecorder
skalberg@14516
    12
skalberg@14516
    13
exception REPLAY of string * string
skalberg@14516
    14
fun ERR f mesg = REPLAY (f,mesg)
skalberg@14516
    15
fun NY f = raise ERR f "NOT YET!"
skalberg@14516
    16
skalberg@14516
    17
fun replay_proof int_thms thyname thmname prf thy =
skalberg@14516
    18
    let
wenzelm@32960
    19
        val _ = ImportRecorder.start_replay_proof thyname thmname 
wenzelm@32960
    20
        fun rp (PRefl tm) thy = P.REFL tm thy
wenzelm@32960
    21
          | rp (PInstT(p,lambda)) thy =
wenzelm@32960
    22
            let
wenzelm@32960
    23
                val (thy',th) = rp' p thy
wenzelm@32960
    24
            in
wenzelm@32960
    25
                P.INST_TYPE lambda th thy'
wenzelm@32960
    26
            end
wenzelm@32960
    27
          | rp (PSubst(prfs,ctxt,prf)) thy =
wenzelm@32960
    28
            let
wenzelm@32960
    29
                val (thy',ths) = fold_rev (fn p => fn (thy, ths) =>
wenzelm@32960
    30
                                           let
wenzelm@32960
    31
                                               val (thy',th) = rp' p thy
wenzelm@32960
    32
                                           in
wenzelm@32960
    33
                                               (thy',th::ths)
wenzelm@32960
    34
                                           end) prfs (thy,[])
wenzelm@32960
    35
                val (thy'',th) = rp' prf thy'
wenzelm@32960
    36
            in
wenzelm@32960
    37
                P.SUBST ths ctxt th thy''
wenzelm@32960
    38
            end
wenzelm@32960
    39
          | rp (PAbs(prf,v)) thy =
wenzelm@32960
    40
            let
wenzelm@32960
    41
                val (thy',th) = rp' prf thy
wenzelm@32960
    42
            in
wenzelm@32960
    43
                P.ABS v th thy'
wenzelm@32960
    44
            end
wenzelm@32960
    45
          | rp (PDisch(prf,tm)) thy =
wenzelm@32960
    46
            let
wenzelm@32960
    47
                val (thy',th) = rp' prf thy
wenzelm@32960
    48
            in
wenzelm@32960
    49
                P.DISCH tm th thy'
wenzelm@32960
    50
            end
wenzelm@32960
    51
          | rp (PMp(prf1,prf2)) thy =
wenzelm@32960
    52
            let
wenzelm@32960
    53
                val (thy1,th1) = rp' prf1 thy
wenzelm@32960
    54
                val (thy2,th2) = rp' prf2 thy1
wenzelm@32960
    55
            in
wenzelm@32960
    56
                P.MP th1 th2 thy2
wenzelm@32960
    57
            end
wenzelm@32960
    58
          | rp (PHyp tm) thy = P.ASSUME tm thy
wenzelm@32960
    59
          | rp (PDef(seg,name,rhs)) thy =
wenzelm@32960
    60
            (case P.get_def seg name rhs thy of
wenzelm@32960
    61
                 (thy',SOME res) => (thy',res)
wenzelm@32960
    62
               | (thy',NONE) => 
wenzelm@32960
    63
                 if seg = thyname
wenzelm@32960
    64
                 then P.new_definition seg name rhs thy'
wenzelm@32960
    65
                 else raise ERR "replay_proof" ("Too late for term definition: "^seg^" != "^thyname))
wenzelm@32960
    66
          | rp (POracle(tg,asl,c)) thy = (*P.mk_oracle_thm tg (map be_contract asl,c)*) NY "ORACLE"
wenzelm@32960
    67
          | rp (PSpec(prf,tm)) thy =
wenzelm@32960
    68
            let
wenzelm@32960
    69
                val (thy',th) = rp' prf thy
wenzelm@32960
    70
            in
wenzelm@32960
    71
                P.SPEC tm th thy'
wenzelm@32960
    72
            end
wenzelm@32960
    73
          | rp (PInst(prf,theta)) thy =
wenzelm@32960
    74
            let
wenzelm@32960
    75
                val (thy',th) = rp' prf thy
wenzelm@32960
    76
            in
wenzelm@32960
    77
                P.INST theta th thy'
wenzelm@32960
    78
            end
wenzelm@32960
    79
          | rp (PGen(prf,v)) thy =
wenzelm@32960
    80
            let
wenzelm@32960
    81
                val (thy',th) = rp' prf thy
wenzelm@32960
    82
                val p = P.GEN v th thy'
wenzelm@32960
    83
            in
wenzelm@32960
    84
                p
wenzelm@32960
    85
            end
wenzelm@32960
    86
          | rp (PGenAbs(prf,opt,vl)) thy =
wenzelm@32960
    87
            let
wenzelm@32960
    88
                val (thy',th) = rp' prf thy
wenzelm@32960
    89
            in
wenzelm@32960
    90
                P.GEN_ABS opt vl th thy'
wenzelm@32960
    91
            end
wenzelm@32960
    92
          | rp (PImpAS(prf1,prf2)) thy =
wenzelm@32960
    93
            let
wenzelm@32960
    94
                val (thy1,th1) = rp' prf1 thy
wenzelm@32960
    95
                val (thy2,th2) = rp' prf2 thy1
wenzelm@32960
    96
            in
wenzelm@32960
    97
                P.IMP_ANTISYM th1 th2 thy2
wenzelm@32960
    98
            end
wenzelm@32960
    99
          | rp (PSym prf) thy =
wenzelm@32960
   100
            let
wenzelm@32960
   101
                val (thy1,th) = rp' prf thy
wenzelm@32960
   102
            in
wenzelm@32960
   103
                P.SYM th thy1
wenzelm@32960
   104
            end
wenzelm@32960
   105
          | rp (PTrans(prf1,prf2)) thy =
wenzelm@32960
   106
            let
wenzelm@32960
   107
                val (thy1,th1) = rp' prf1 thy
wenzelm@32960
   108
                val (thy2,th2) = rp' prf2 thy1
wenzelm@32960
   109
            in
wenzelm@32960
   110
                P.TRANS th1 th2 thy2
wenzelm@32960
   111
            end
wenzelm@32960
   112
          | rp (PComb(prf1,prf2)) thy =
wenzelm@32960
   113
            let
wenzelm@32960
   114
                val (thy1,th1) = rp' prf1 thy
wenzelm@32960
   115
                val (thy2,th2) = rp' prf2 thy1
wenzelm@32960
   116
            in
wenzelm@32960
   117
                P.COMB th1 th2 thy2
wenzelm@32960
   118
            end
wenzelm@32960
   119
          | rp (PEqMp(prf1,prf2)) thy =
wenzelm@32960
   120
            let
wenzelm@32960
   121
                val (thy1,th1) = rp' prf1 thy
wenzelm@32960
   122
                val (thy2,th2) = rp' prf2 thy1
wenzelm@32960
   123
            in
wenzelm@32960
   124
                P.EQ_MP th1 th2 thy2
wenzelm@32960
   125
            end
wenzelm@32960
   126
          | rp (PEqImp prf) thy =
wenzelm@32960
   127
            let
wenzelm@32960
   128
                val (thy',th) = rp' prf thy
wenzelm@32960
   129
            in
wenzelm@32960
   130
                P.EQ_IMP_RULE th thy'
wenzelm@32960
   131
            end
wenzelm@32960
   132
          | rp (PExists(prf,ex,wit)) thy =
wenzelm@32960
   133
            let
wenzelm@32960
   134
                val (thy',th) = rp' prf thy
wenzelm@32960
   135
            in
wenzelm@32960
   136
                P.EXISTS ex wit th thy'
wenzelm@32960
   137
            end
wenzelm@32960
   138
          | rp (PChoose(v,prf1,prf2)) thy =
wenzelm@32960
   139
            let
wenzelm@32960
   140
                val (thy1,th1) = rp' prf1 thy
wenzelm@32960
   141
                val (thy2,th2) = rp' prf2 thy1
wenzelm@32960
   142
            in
wenzelm@32960
   143
                P.CHOOSE v th1 th2 thy2
wenzelm@32960
   144
            end
wenzelm@32960
   145
          | rp (PConj(prf1,prf2)) thy =
wenzelm@32960
   146
            let
wenzelm@32960
   147
                val (thy1,th1) = rp' prf1 thy
wenzelm@32960
   148
                val (thy2,th2) = rp' prf2 thy1
wenzelm@32960
   149
            in
wenzelm@32960
   150
                P.CONJ th1 th2 thy2
wenzelm@32960
   151
            end
wenzelm@32960
   152
          | rp (PConjunct1 prf) thy =
wenzelm@32960
   153
            let
wenzelm@32960
   154
                val (thy',th) = rp' prf thy
wenzelm@32960
   155
            in
wenzelm@32960
   156
                P.CONJUNCT1 th thy'
wenzelm@32960
   157
            end
wenzelm@32960
   158
          | rp (PConjunct2 prf) thy =
wenzelm@32960
   159
            let
wenzelm@32960
   160
                val (thy',th) = rp' prf thy
wenzelm@32960
   161
            in
wenzelm@32960
   162
                P.CONJUNCT2 th thy'
wenzelm@32960
   163
            end
wenzelm@32960
   164
          | rp (PDisj1(prf,tm)) thy =
wenzelm@32960
   165
            let
wenzelm@32960
   166
                val (thy',th) = rp' prf thy
wenzelm@32960
   167
            in
wenzelm@32960
   168
                P.DISJ1 th tm thy'
wenzelm@32960
   169
            end
wenzelm@32960
   170
          | rp (PDisj2(prf,tm)) thy =
wenzelm@32960
   171
            let
wenzelm@32960
   172
                val (thy',th) = rp' prf thy
wenzelm@32960
   173
            in
wenzelm@32960
   174
                P.DISJ2 tm th thy'
wenzelm@32960
   175
            end
wenzelm@32960
   176
          | rp (PDisjCases(prf,prf1,prf2)) thy =
wenzelm@32960
   177
            let
wenzelm@32960
   178
                val (thy',th)  = rp' prf  thy
wenzelm@32960
   179
                val (thy1,th1) = rp' prf1 thy'
wenzelm@32960
   180
                val (thy2,th2) = rp' prf2 thy1
wenzelm@32960
   181
            in
wenzelm@32960
   182
                P.DISJ_CASES th th1 th2 thy2
wenzelm@32960
   183
            end
wenzelm@32960
   184
          | rp (PNotI prf) thy =
wenzelm@32960
   185
            let
wenzelm@32960
   186
                val (thy',th) = rp' prf thy
wenzelm@32960
   187
            in
wenzelm@32960
   188
                P.NOT_INTRO th thy'
wenzelm@32960
   189
            end
wenzelm@32960
   190
          | rp (PNotE prf) thy =
wenzelm@32960
   191
            let
wenzelm@32960
   192
                val (thy',th) = rp' prf thy
wenzelm@32960
   193
            in
wenzelm@32960
   194
                P.NOT_ELIM th thy'
wenzelm@32960
   195
            end
wenzelm@32960
   196
          | rp (PContr(prf,tm)) thy =
wenzelm@32960
   197
            let
wenzelm@32960
   198
                val (thy',th) = rp' prf thy
wenzelm@32960
   199
            in
wenzelm@32960
   200
                P.CCONTR tm th thy'
wenzelm@32960
   201
            end
wenzelm@32960
   202
          | rp (PTmSpec _) _ = raise ERR "rp" "Shouldn't reach here (PTmSpec)"
wenzelm@32960
   203
          | rp (PTyDef _) _ = raise ERR "rp" "Shouldn't reach here (PTyDef)"
wenzelm@32960
   204
          | rp (PTyIntro _) _ = raise ERR "rp" "Shouldn't reach here (PTyIntro)"
wenzelm@32960
   205
          | rp PDisk _ = raise ERR "rp" "Shouldn't reach here (PDisk)"
wenzelm@32960
   206
          | rp _ _ = raise ERR "rp" "What the hell is this? Which case did I forget?"
wenzelm@32960
   207
        and rp' p thy =
wenzelm@32960
   208
            let
wenzelm@32960
   209
                val pc = content_of p
wenzelm@32960
   210
            in
wenzelm@32960
   211
                case pc of
wenzelm@32960
   212
                    PDisk => (case disk_info_of p of
wenzelm@32960
   213
                                  SOME(thyname',thmname) =>
wenzelm@32960
   214
                                  (case Int.fromString thmname of
wenzelm@32960
   215
                                       SOME i =>
wenzelm@32960
   216
                                       if thyname' = thyname
wenzelm@32960
   217
                                       then
wenzelm@32960
   218
                                           (case Array.sub(int_thms,i-1) of
wenzelm@32960
   219
                                                NONE =>
wenzelm@32960
   220
                                                let
wenzelm@32960
   221
                                                    val (thy',th) = rp' (snd (import_proof thyname' thmname thy) thy) thy
wenzelm@32960
   222
                                                    val _ = Array.update(int_thms,i-1,SOME th)
wenzelm@32960
   223
                                                in
wenzelm@32960
   224
                                                    (thy',th)
wenzelm@32960
   225
                                                end
wenzelm@32960
   226
                                              | SOME th => (thy,th))
wenzelm@32960
   227
                                       else raise ERR "replay_proof" ("Library " ^ thyname' ^ " should be built before " ^ thyname ^ " (" ^ thmname ^ ")")
wenzelm@32960
   228
                                     | NONE => 
wenzelm@32960
   229
                                       (case P.get_thm thyname' thmname thy of
wenzelm@32960
   230
                                            (thy',SOME res) => (thy',res)
wenzelm@32960
   231
                                          | (thy',NONE) => 
wenzelm@32960
   232
                                            if thyname' = thyname
wenzelm@32960
   233
                                            then
wenzelm@32960
   234
                                                let
wenzelm@32960
   235
                                                    val _ = writeln ("Found no " ^ thmname ^ " theorem, replaying...")
wenzelm@32960
   236
                                                    val (f_opt,prf) = import_proof thyname' thmname thy'
wenzelm@32960
   237
                                                    val prf = prf thy'
wenzelm@32960
   238
                                                    val (thy',th) = replay_proof int_thms thyname' thmname prf thy'
obua@17322
   239
                                                    val _ = writeln ("Successfully finished replaying "^thmname^" !")
wenzelm@32960
   240
                                                in
wenzelm@32960
   241
                                                    case content_of prf of
wenzelm@32960
   242
                                                        PTmSpec _ => (thy',th)
wenzelm@32960
   243
                                                      | PTyDef  _ => (thy',th)
wenzelm@32960
   244
                                                      | PTyIntro _ => (thy',th)
wenzelm@32960
   245
                                                      | _ => P.store_thm thyname' thmname th thy'
wenzelm@32960
   246
                                                end
wenzelm@32960
   247
                                            else raise ERR "replay_proof" ("Library " ^ thyname' ^ " should be built before " ^ thyname ^ " (" ^ thmname ^ ")")))
wenzelm@32960
   248
                                | NONE => raise ERR "rp'.PDisk" "Not enough information")
wenzelm@32960
   249
                  | PAxm(name,c) =>
wenzelm@32960
   250
                    (case P.get_axiom thyname name thy of
wenzelm@32960
   251
                            (thy',SOME res) => (thy',res)
wenzelm@32960
   252
                          | (thy',NONE) => P.new_axiom name c thy')
wenzelm@32960
   253
                  | PTmSpec(seg,names,prf') =>
wenzelm@32960
   254
                    let
wenzelm@32960
   255
                        val (thy',th) = rp' prf' thy
wenzelm@32960
   256
                    in
wenzelm@32960
   257
                        P.new_specification seg thmname names th thy'
wenzelm@32960
   258
                    end
wenzelm@32960
   259
                  | PTyDef(seg,name,prf') =>
wenzelm@32960
   260
                    let
wenzelm@32960
   261
                        val (thy',th) = rp' prf' thy
wenzelm@32960
   262
                    in
wenzelm@32960
   263
                        P.new_type_definition seg thmname name th thy'
wenzelm@32960
   264
                    end
wenzelm@32960
   265
                  | PTyIntro(seg,name,abs_name,rep_name,P,t,prf') =>
wenzelm@32960
   266
                    let
wenzelm@32960
   267
                        val (thy',th) = rp' prf' thy
wenzelm@32960
   268
                    in
wenzelm@32960
   269
                        P.type_introduction seg thmname name abs_name rep_name (P,t) th thy'
wenzelm@32960
   270
                    end
wenzelm@32960
   271
                  | _ => rp pc thy
wenzelm@32960
   272
            end
skalberg@14516
   273
    in
wenzelm@32960
   274
        let
wenzelm@32960
   275
            val x = rp' prf thy handle e => (writeln "Exception in replay_proof"; OldGoals.print_exn e)
wenzelm@32960
   276
            val _ = ImportRecorder.stop_replay_proof thyname thmname
wenzelm@32960
   277
        in
wenzelm@32960
   278
            x
wenzelm@32960
   279
        end
obua@19064
   280
    end handle x => (ImportRecorder.abort_replay_proof thyname thmname; raise x)
skalberg@14516
   281
skalberg@14516
   282
fun setup_int_thms thyname thy =
skalberg@14516
   283
    let
wenzelm@32960
   284
        val fname =
wenzelm@32960
   285
            case P.get_proof_dir thyname thy of
wenzelm@32960
   286
                SOME p => OS.Path.joinDirFile {dir=p,file=OS.Path.joinBaseExt{base = "facts",ext=SOME "lst"}}
wenzelm@32960
   287
              | NONE => error "Cannot find proof files"
wenzelm@32960
   288
        val is = TextIO.openIn fname
wenzelm@32960
   289
        val (num_int_thms,facts) =
wenzelm@32960
   290
            let
wenzelm@32960
   291
                fun get_facts facts =
wenzelm@32960
   292
                    case TextIO.inputLine is of
wenzelm@32960
   293
                        NONE => (case facts of
wenzelm@32960
   294
                                   i::facts => (valOf (Int.fromString i),map P.protect_factname (rev facts))
wenzelm@32960
   295
                                 | _ => raise ERR "replay_thm" "Bad facts.lst file")
wenzelm@32960
   296
                      | SOME fact => get_facts ((String.substring(fact,0,String.size fact -1 ))::facts)
wenzelm@32960
   297
            in
wenzelm@32960
   298
                get_facts []
wenzelm@32960
   299
            end
wenzelm@32960
   300
        val _ = TextIO.closeIn is
wenzelm@32960
   301
        val int_thms = Array.array(num_int_thms,NONE:thm option)
skalberg@14516
   302
    in
wenzelm@32960
   303
        (int_thms,facts)
skalberg@14516
   304
    end
skalberg@14516
   305
skalberg@14516
   306
fun import_single_thm thyname int_thms thmname thy =
skalberg@14516
   307
    let
wenzelm@32960
   308
        fun replay_fact (thmname,thy) =
wenzelm@32960
   309
            let
wenzelm@32960
   310
                val prf = mk_proof PDisk
wenzelm@32960
   311
                val _ = set_disk_info_of prf thyname thmname
obua@17594
   312
                val _ = writeln ("Replaying "^thmname^" ...")
wenzelm@32960
   313
                val p = fst (replay_proof int_thms thyname thmname prf thy)
wenzelm@32960
   314
            in
wenzelm@32960
   315
                p
wenzelm@32960
   316
            end
skalberg@14516
   317
    in
wenzelm@32960
   318
        replay_fact (thmname,thy)
skalberg@14516
   319
    end
skalberg@14516
   320
obua@19064
   321
fun replay_chached_thm int_thms thyname thmname =
obua@19064
   322
    let
wenzelm@32960
   323
        fun th_of thy = setmp quick_and_dirty true (SkipProof.make_thm thy)
wenzelm@32960
   324
        fun err msg = raise ERR "replay_cached_thm" msg
wenzelm@32960
   325
        val _ = writeln ("Replaying (from cache) "^thmname^" ...")
wenzelm@32960
   326
        fun rps [] thy = thy
wenzelm@32960
   327
          | rps (t::ts) thy = rps ts (rp t thy)
wenzelm@32960
   328
        and rp (ThmEntry (thyname', thmname', aborted, History history)) thy = rps history thy      
wenzelm@32960
   329
          | rp (DeltaEntry ds) thy = fold delta ds thy
wenzelm@32960
   330
        and delta (Specification (names, th)) thy = 
wenzelm@32960
   331
            fst (Choice_Specification.add_specification NONE names (thy,th_of thy th))
wenzelm@32960
   332
          | delta (Hol_mapping (thyname, thmname, isaname)) thy = 
wenzelm@32960
   333
            add_hol4_mapping thyname thmname isaname thy
wenzelm@32960
   334
          | delta (Hol_pending (thyname, thmname, th)) thy = 
wenzelm@32960
   335
            add_hol4_pending thyname thmname ([], th_of thy th) thy
wenzelm@32960
   336
          | delta (Consts cs) thy = Sign.add_consts_i (map (fn (c, T, mx) => (Binding.name c, T, mx)) cs) thy
wenzelm@32960
   337
          | delta (Hol_const_mapping (thyname, constname, fullcname)) thy = 
wenzelm@32960
   338
            add_hol4_const_mapping thyname constname true fullcname thy
wenzelm@32960
   339
          | delta (Hol_move (fullname, moved_thmname)) thy = 
wenzelm@32960
   340
            add_hol4_move fullname moved_thmname thy
wenzelm@32960
   341
          | delta (Defs (thmname, eq)) thy =
wenzelm@32960
   342
            snd (PureThy.add_defs false [((Binding.name thmname, eq), [])] thy)
wenzelm@32960
   343
          | delta (Hol_theorem (thyname, thmname, th)) thy =
wenzelm@32960
   344
            add_hol4_theorem thyname thmname ([], th_of thy th) thy
wenzelm@32960
   345
          | delta (Typedef (thmname, (t, vs, mx), c, repabs, th)) thy = 
wenzelm@32960
   346
            snd (Typedef.add_typedef false (Option.map Binding.name thmname) (Binding.name t, vs, mx) c
wenzelm@30346
   347
        (Option.map (pairself Binding.name) repabs) (rtac (th_of thy th) 1) thy)
wenzelm@32960
   348
          | delta (Hol_type_mapping (thyname, tycname, fulltyname)) thy =  
wenzelm@32960
   349
            add_hol4_type_mapping thyname tycname true fulltyname thy
wenzelm@32960
   350
          | delta (Indexed_theorem (i, th)) thy = 
wenzelm@32960
   351
            (Array.update (int_thms,i-1,SOME (P.to_hol_thm (th_of thy th))); thy)                   
obua@19068
   352
          | delta (Protect_varname (s,t)) thy = (P.replay_protect_varname s t; thy)
wenzelm@32960
   353
          | delta (Dump s) thy = P.replay_add_dump s thy
obua@19064
   354
    in
wenzelm@32960
   355
        rps
obua@19064
   356
    end
obua@19064
   357
skalberg@14516
   358
fun import_thms thyname int_thms thmnames thy =
skalberg@14516
   359
    let
wenzelm@32960
   360
        fun zip names [] = ([], names)
wenzelm@32960
   361
          | zip [] _ = ([], [])
wenzelm@32960
   362
          | zip (thmname::names) ((ThmEntry (entry as (thyname',thmname',aborted,History history)))::ys) = 
wenzelm@32960
   363
            if thyname = thyname' andalso thmname = thmname' then
wenzelm@32960
   364
                (if aborted then ([], thmname::names) else 
wenzelm@32960
   365
                 let
wenzelm@32960
   366
                     val _ = writeln ("theorem is in-sync: "^thmname)
wenzelm@32960
   367
                     val (cached,normal) = zip names ys
wenzelm@32960
   368
                 in
wenzelm@32960
   369
                     (entry::cached, normal)
wenzelm@32960
   370
                 end)
wenzelm@32960
   371
            else
wenzelm@32960
   372
                let
wenzelm@32960
   373
                    val _ = writeln ("cached theorems are not in-sync,  expected: "^thmname^", found: "^thmname')
wenzelm@32960
   374
                    val _ = writeln ("proceeding with next uncached theorem...")
wenzelm@32960
   375
                in
wenzelm@32960
   376
                    ([], thmname::names)
wenzelm@32960
   377
                end
wenzelm@32960
   378
        (*      raise ERR "import_thms" ("cached theorems are not in-sync, expected: "^thmname^", found: "^thmname')*)
wenzelm@32960
   379
          | zip (thmname::_) (DeltaEntry _ :: _) = 
wenzelm@32960
   380
            raise ERR "import_thms" ("expected theorem '"^thmname^"', but found a delta")
wenzelm@32960
   381
        fun zip' xs (History ys) = 
wenzelm@32960
   382
            let
wenzelm@32960
   383
                val _ = writeln ("length of xs: "^(string_of_int (length xs)))
wenzelm@32960
   384
                val _ = writeln ("length of history: "^(string_of_int (length ys)))
wenzelm@32960
   385
            in
wenzelm@32960
   386
                zip xs ys
wenzelm@32960
   387
            end
wenzelm@32960
   388
        fun replay_fact thmname thy = 
wenzelm@32960
   389
            let
wenzelm@32960
   390
                val prf = mk_proof PDisk        
wenzelm@32960
   391
                val _ = set_disk_info_of prf thyname thmname
obua@17594
   392
                val _ = writeln ("Replaying "^thmname^" ...")
wenzelm@32960
   393
                val p = fst (replay_proof int_thms thyname thmname prf thy)
wenzelm@32960
   394
            in
wenzelm@32960
   395
                p
wenzelm@32960
   396
            end
wenzelm@32960
   397
        fun replay_cache (_,thmname, _, History history) thy = replay_chached_thm int_thms thyname thmname history thy
wenzelm@32960
   398
        val (cached, normal) = zip' thmnames (ImportRecorder.get_history ())
wenzelm@32960
   399
        val _ = ImportRecorder.set_history (History (map ThmEntry cached))
wenzelm@32960
   400
        val res_thy = fold replay_fact normal (fold replay_cache cached thy)
skalberg@14516
   401
    in
wenzelm@32960
   402
        res_thy
skalberg@14516
   403
    end
skalberg@14516
   404
skalberg@14516
   405
fun import_thm thyname thmname thy =
skalberg@14516
   406
    let
wenzelm@32960
   407
        val int_thms = fst (setup_int_thms thyname thy)
wenzelm@32960
   408
        fun replay_fact (thmname,thy) =
wenzelm@32960
   409
            let
wenzelm@32960
   410
                val prf = mk_proof PDisk        
wenzelm@32960
   411
                val _ = set_disk_info_of prf thyname thmname        
obua@17594
   412
                val _ = writeln ("Replaying "^thmname^" ...")
wenzelm@32960
   413
                val p = fst (replay_proof int_thms thyname thmname prf thy)
wenzelm@32960
   414
            in 
wenzelm@32960
   415
                p
wenzelm@32960
   416
            end
skalberg@14516
   417
    in
wenzelm@32960
   418
        replay_fact (thmname,thy)
skalberg@14516
   419
    end
skalberg@14516
   420
wenzelm@17959
   421
end