161 let |
161 let |
162 val tvars = Term.add_tvars (Thm.prop_of thm) [] |
162 val tvars = Term.add_tvars (Thm.prop_of thm) [] |
163 val tfrees = map (fn ((t, _), s) => TFree (t, s)) tvars |
163 val tfrees = map (fn ((t, _), s) => TFree (t, s)) tvars |
164 val tvars = map TVar tvars |
164 val tvars = map TVar tvars |
165 val thy = Thm.theory_of_thm thm |
165 val thy = Thm.theory_of_thm thm |
166 fun inst ty = Thm.ctyp_of thy ty |
166 fun inst ty = Thm.global_ctyp_of thy ty |
167 in |
167 in |
168 Thm.instantiate ((map inst tvars ~~ map inst tfrees), []) thm |
168 Thm.instantiate ((map inst tvars ~~ map inst tfrees), []) thm |
169 end |
169 end |
170 |
170 |
171 fun def' constname rhs thy = |
171 fun def' constname rhs thy = |
204 val rept = Thm.dest_arg th_s |
204 val rept = Thm.dest_arg th_s |
205 val P = Thm.dest_arg cn |
205 val P = Thm.dest_arg cn |
206 val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept) |
206 val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept) |
207 in |
207 in |
208 Drule.instantiate' [SOME nty, SOME oty] [SOME rept, SOME abst, SOME P, |
208 Drule.instantiate' [SOME nty, SOME oty] [SOME rept, SOME abst, SOME P, |
209 SOME (Thm.cterm_of thy (Free ("a", Thm.typ_of nty))), |
209 SOME (Thm.global_cterm_of thy (Free ("a", Thm.typ_of nty))), |
210 SOME (Thm.cterm_of thy (Free ("r", Thm.typ_of oty)))] @{thm typedef_hol2hollight} |
210 SOME (Thm.global_cterm_of thy (Free ("r", Thm.typ_of oty)))] @{thm typedef_hol2hollight} |
211 end |
211 end |
212 |
212 |
213 fun tydef' tycname abs_name rep_name cP ct td_th thy = |
213 fun tydef' tycname abs_name rep_name cP ct td_th thy = |
214 let |
214 let |
215 val ctT = Thm.ctyp_of_cterm ct |
215 val ctT = Thm.ctyp_of_cterm ct |
231 val rept = Thm.dest_arg th_s |
231 val rept = Thm.dest_arg th_s |
232 val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept) |
232 val [nty, oty] = Thm.dest_ctyp (Thm.ctyp_of_cterm rept) |
233 val typedef_th = |
233 val typedef_th = |
234 Drule.instantiate' |
234 Drule.instantiate' |
235 [SOME nty, SOME oty] |
235 [SOME nty, SOME oty] |
236 [SOME rept, SOME abst, SOME cP, SOME (Thm.cterm_of thy' (Free ("a", aty))), |
236 [SOME rept, SOME abst, SOME cP, SOME (Thm.global_cterm_of thy' (Free ("a", aty))), |
237 SOME (Thm.cterm_of thy' (Free ("r", Thm.typ_of ctT)))] |
237 SOME (Thm.global_cterm_of thy' (Free ("r", Thm.typ_of ctT)))] |
238 @{thm typedef_hol2hollight} |
238 @{thm typedef_hol2hollight} |
239 val th4 = typedef_th OF [#type_definition (#2 typedef_info)] |
239 val th4 = typedef_th OF [#type_definition (#2 typedef_info)] |
240 in |
240 in |
241 (th4, thy') |
241 (th4, thy') |
242 end |
242 end |
264 val tys_before = Term.add_tfrees (Thm.prop_of th) [] |
264 val tys_before = Term.add_tfrees (Thm.prop_of th) [] |
265 val th1 = Thm.varifyT_global th |
265 val th1 = Thm.varifyT_global th |
266 val tys_after = Term.add_tvars (Thm.prop_of th1) [] |
266 val tys_after = Term.add_tvars (Thm.prop_of th1) [] |
267 val tyinst = map2 (fn bef => fn iS => |
267 val tyinst = map2 (fn bef => fn iS => |
268 (case try (assoc (TFree bef)) lambda of |
268 (case try (assoc (TFree bef)) lambda of |
269 SOME cty => (Thm.ctyp_of thy (TVar iS), cty) |
269 SOME cty => (Thm.global_ctyp_of thy (TVar iS), cty) |
270 | NONE => (Thm.ctyp_of thy (TVar iS), Thm.ctyp_of thy (TFree bef)) |
270 | NONE => (Thm.global_ctyp_of thy (TVar iS), Thm.global_ctyp_of thy (TFree bef)) |
271 )) tys_before tys_after |
271 )) tys_before tys_after |
272 in |
272 in |
273 Thm.instantiate (tyinst,[]) th1 |
273 Thm.instantiate (tyinst,[]) th1 |
274 end |
274 end |
275 |
275 |
331 val thm = Drule.export_without_context_open thm |
331 val thm = Drule.export_without_context_open thm |
332 val tvs = Term.add_tvars (Thm.prop_of thm) [] |
332 val tvs = Term.add_tvars (Thm.prop_of thm) [] |
333 val tns = map (fn (_, _) => "'") tvs |
333 val tns = map (fn (_, _) => "'") tvs |
334 val nms = fst (fold_map Name.variant tns (Variable.names_of (Proof_Context.init_global thy))) |
334 val nms = fst (fold_map Name.variant tns (Variable.names_of (Proof_Context.init_global thy))) |
335 val vs = map TVar ((nms ~~ (map (snd o fst) tvs)) ~~ (map snd tvs)) |
335 val vs = map TVar ((nms ~~ (map (snd o fst) tvs)) ~~ (map snd tvs)) |
336 val cvs = map (Thm.ctyp_of thy) vs |
336 val cvs = map (Thm.global_ctyp_of thy) vs |
337 val ctvs = map (Thm.ctyp_of thy) (map TVar tvs) |
337 val ctvs = map (Thm.global_ctyp_of thy) (map TVar tvs) |
338 val thm' = Thm.instantiate ((ctvs ~~ cvs), []) thm |
338 val thm' = Thm.instantiate ((ctvs ~~ cvs), []) thm |
339 in |
339 in |
340 snd (Global_Theory.add_thm ((binding, thm'), []) thy) |
340 snd (Global_Theory.add_thm ((binding, thm'), []) thy) |
341 end |
341 end |
342 |
342 |
409 in |
409 in |
410 setth th (thy, state) |
410 setth th (thy, state) |
411 end |
411 end |
412 | process (thy, state) (#"Y", [name, _, _]) = setth (mtydef name thy) (thy, state) |
412 | process (thy, state) (#"Y", [name, _, _]) = setth (mtydef name thy) (thy, state) |
413 | process (thy, state) (#"t", [n]) = |
413 | process (thy, state) (#"t", [n]) = |
414 setty (Thm.ctyp_of thy (TFree ("'" ^ (transl_qm n), @{sort type}))) (thy, state) |
414 setty (Thm.global_ctyp_of thy (TFree ("'" ^ (transl_qm n), @{sort type}))) (thy, state) |
415 | process (thy, state) (#"a", n :: l) = |
415 | process (thy, state) (#"a", n :: l) = |
416 fold_map getty l (thy, state) |>> |
416 fold_map getty l (thy, state) |>> |
417 (fn tys => Thm.ctyp_of thy (Type (gettyname n thy, map Thm.typ_of tys))) |-> setty |
417 (fn tys => Thm.global_ctyp_of thy (Type (gettyname n thy, map Thm.typ_of tys))) |-> setty |
418 | process (thy, state) (#"v", [n, ty]) = |
418 | process (thy, state) (#"v", [n, ty]) = |
419 getty ty (thy, state) |>> (fn ty => Thm.cterm_of thy (Free (transl_dot n, Thm.typ_of ty))) |-> settm |
419 getty ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (Free (transl_dot n, Thm.typ_of ty))) |-> settm |
420 | process (thy, state) (#"c", [n, ty]) = |
420 | process (thy, state) (#"c", [n, ty]) = |
421 getty ty (thy, state) |>> (fn ty => Thm.cterm_of thy (Const (getconstname n thy, Thm.typ_of ty))) |-> settm |
421 getty ty (thy, state) |>> (fn ty => Thm.global_cterm_of thy (Const (getconstname n thy, Thm.typ_of ty))) |-> settm |
422 | process tstate (#"f", [t1, t2]) = |
422 | process tstate (#"f", [t1, t2]) = |
423 gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.apply t1 t2) |-> settm |
423 gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.apply t1 t2) |-> settm |
424 | process tstate (#"l", [t1, t2]) = |
424 | process tstate (#"l", [t1, t2]) = |
425 gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.lambda t1 t2) |-> settm |
425 gettm t1 tstate ||>> gettm t2 |>> (fn (t1, t2) => Thm.lambda t1 t2) |-> settm |
426 | process (thy, state) (#"+", [s]) = |
426 | process (thy, state) (#"+", [s]) = |