151 [SOME ll, SOME lr] @{lemma "(\<And>x. f x = g x) \<Longrightarrow> f = g" by (rule ext)} |
151 [SOME ll, SOME lr] @{lemma "(\<And>x. f x = g x) \<Longrightarrow> f = g" by (rule ext)} |
152 in |
152 in |
153 meta_mp i th4 |
153 meta_mp i th4 |
154 end |
154 end |
155 |
155 |
156 fun freezeT thy thm = |
156 fun freezeT thy th = |
157 let |
157 let |
158 val tvars = Term.add_tvars (Thm.prop_of thm) [] |
158 val tvars = Term.add_tvars (Thm.prop_of th) [] |
159 val tfrees = map (fn ((t, _), s) => TFree (t, s)) tvars |
159 val tfrees = map (fn ((t, _), s) => TFree (t, s)) tvars |
160 in |
160 in |
161 Thm.instantiate (TVars.make (tvars ~~ map (Thm.global_ctyp_of thy) tfrees), Vars.empty) thm |
161 Thm.instantiate (TVars.make (tvars ~~ map (Thm.global_ctyp_of thy) tfrees), Vars.empty) th |
162 end |
162 end |
163 |
163 |
164 fun def' c rhs thy = |
164 fun def' c rhs thy = |
165 let |
165 let |
166 val b = Binding.name c |
166 val b = Binding.name c |
167 val typ = type_of rhs |
167 val ty = type_of rhs |
168 val thy1 = Sign.add_consts [(b, typ, NoSyn)] thy |
168 val thy1 = Sign.add_consts [(b, ty, NoSyn)] thy |
169 val eq = Logic.mk_equals (Const (Sign.full_name thy1 b, typ), rhs) |
169 val eq = Logic.mk_equals (Const (Sign.full_name thy1 b, ty), rhs) |
170 val (thm, thy2) = Global_Theory.add_def (Binding.suffix_name "_hldef" b, eq) thy1 |
170 val (th, thy2) = Global_Theory.add_def (Binding.suffix_name "_hldef" b, eq) thy1 |
171 val def_thm = freezeT thy1 thm |
171 val def_thm = freezeT thy1 th |
172 in |
172 in |
173 (meta_eq_to_obj_eq def_thm, thy2) |
173 (meta_eq_to_obj_eq def_thm, thy2) |
174 end |
174 end |
175 |
175 |
176 fun mdef thy name = |
176 fun mdef thy name = |
324 fun setth v (thy, (tyi, tmi, thi)) = (thy, (tyi, tmi, set thi v)) |
324 fun setth v (thy, (tyi, tmi, thi)) = (thy, (tyi, tmi, set thi v)) |
325 |
325 |
326 fun last_thm (_, _, (map, no)) = |
326 fun last_thm (_, _, (map, no)) = |
327 case Inttab.lookup map no of |
327 case Inttab.lookup map no of |
328 NONE => error "Import_Rule.last_thm: lookup failed" |
328 NONE => error "Import_Rule.last_thm: lookup failed" |
329 | SOME thm => thm |
329 | SOME th => th |
330 |
330 |
331 fun list_last (x :: y :: zs) = apfst (fn t => x :: y :: t) (list_last zs) |
331 fun list_last (x :: y :: zs) = apfst (fn t => x :: y :: t) (list_last zs) |
332 | list_last [x] = ([], x) |
332 | list_last [x] = ([], x) |
333 | list_last [] = error "list_last: empty" |
333 | list_last [] = error "list_last: empty" |
334 |
334 |
335 fun pair_list (x :: y :: zs) = ((x, y) :: pair_list zs) |
335 fun pair_list (x :: y :: zs) = ((x, y) :: pair_list zs) |
336 | pair_list [] = [] |
336 | pair_list [] = [] |
337 | pair_list _ = error "pair_list: odd list length" |
337 | pair_list _ = error "pair_list: odd list length" |
338 |
338 |
339 fun store_thm binding thm thy = |
339 fun store_thm binding th0 thy = |
340 let |
340 let |
341 val ctxt = Proof_Context.init_global thy |
341 val ctxt = Proof_Context.init_global thy |
342 val thm = Drule.export_without_context_open thm |
342 val th = Drule.export_without_context_open th0 |
343 val tvs = Term.add_tvars (Thm.prop_of thm) [] |
343 val tvs = Term.add_tvars (Thm.prop_of th) [] |
344 val tns = map (fn (_, _) => "'") tvs |
344 val tns = map (fn (_, _) => "'") tvs |
345 val nms = Name.variants (Variable.names_of ctxt) tns |
345 val nms = Name.variants (Variable.names_of ctxt) tns |
346 val vs = map TVar ((nms ~~ (map (snd o fst) tvs)) ~~ (map snd tvs)) |
346 val vs = map TVar ((nms ~~ (map (snd o fst) tvs)) ~~ (map snd tvs)) |
347 val thm' = Thm.instantiate (TVars.make (tvs ~~ map (Thm.ctyp_of ctxt) vs), Vars.empty) thm |
347 val th' = Thm.instantiate (TVars.make (tvs ~~ map (Thm.ctyp_of ctxt) vs), Vars.empty) th |
348 in |
348 in |
349 snd (Global_Theory.add_thm ((binding, thm'), []) thy) |
349 snd (Global_Theory.add_thm ((binding, th'), []) thy) |
350 end |
350 end |
351 |
351 |
352 fun parse_line s = |
352 fun parse_line s = |
353 (case String.tokens (fn x => x = #"\n" orelse x = #" ") s of |
353 (case String.tokens (fn x => x = #"\n" orelse x = #" ") s of |
354 [] => error "parse_line: empty" |
354 [] => error "parse_line: empty" |
372 | process (#"D", [th1, th2]) = getth th1 ##>> getth th2 #>> uncurry deduct #-> setth |
372 | process (#"D", [th1, th2]) = getth th1 ##>> getth th2 #>> uncurry deduct #-> setth |
373 | process (#"L", [t, th]) = gettm t ##>> (fn ti => getth th ti) #>> uncurry abs #-> setth |
373 | process (#"L", [t, th]) = gettm t ##>> (fn ti => getth th ti) #>> uncurry abs #-> setth |
374 | process (#"M", [s]) = (fn (thy, state) => |
374 | process (#"M", [s]) = (fn (thy, state) => |
375 let |
375 let |
376 val ctxt = Proof_Context.init_global thy |
376 val ctxt = Proof_Context.init_global thy |
377 val thm = freezeT thy (Global_Theory.get_thm thy s) |
377 val th = freezeT thy (Global_Theory.get_thm thy s) |
378 val ((_, [th']), _) = Variable.import true [thm] ctxt |
378 val ((_, [th']), _) = Variable.import true [th] ctxt |
379 in |
379 in |
380 setth th' (thy, state) |
380 setth th' (thy, state) |
381 end) |
381 end) |
382 | process (#"Q", l) = (fn (thy, state) => |
382 | process (#"Q", l) = (fn (thy, state) => |
383 let |
383 let |