57 val Tvs = map TVar iTs; |
57 val Tvs = map TVar iTs; |
58 val (_ $ (_ $ _ $ S)) = Logic.strip_imp_concl (prop_of (hd intrs)); |
58 val (_ $ (_ $ _ $ S)) = Logic.strip_imp_concl (prop_of (hd intrs)); |
59 val (Const (s, _), ts) = strip_comb S; |
59 val (Const (s, _), ts) = strip_comb S; |
60 val params = map dest_Var ts; |
60 val params = map dest_Var ts; |
61 val tname = space_implode "_" (Sign.base_name s ^ "T" :: vs); |
61 val tname = space_implode "_" (Sign.base_name s ^ "T" :: vs); |
62 fun constr_of_intr intr = (Sign.base_name (Thm.name_of_thm intr), |
62 fun constr_of_intr intr = (Sign.base_name (Thm.get_name intr), |
63 map (Logic.unvarifyT o snd) (rev (Term.add_vars (prop_of intr) []) \\ params) @ |
63 map (Logic.unvarifyT o snd) (rev (Term.add_vars (prop_of intr) []) \\ params) @ |
64 filter_out (equal Extraction.nullT) (map |
64 filter_out (equal Extraction.nullT) (map |
65 (Logic.unvarifyT o Extraction.etype_of thy vs []) (prems_of intr)), |
65 (Logic.unvarifyT o Extraction.etype_of thy vs []) (prems_of intr)), |
66 NoSyn); |
66 NoSyn); |
67 in (map (fn a => "'" ^ a) vs @ map (fst o fst) iTs, tname, NoSyn, |
67 in (map (fn a => "'" ^ a) vs @ map (fst o fst) iTs, tname, NoSyn, |
187 | fun_of ts rts args used [] = |
187 | fun_of ts rts args used [] = |
188 let val xs = rev (rts @ ts) |
188 let val xs = rev (rts @ ts) |
189 in if conclT = Extraction.nullT |
189 in if conclT = Extraction.nullT |
190 then list_abs_free (map dest_Free xs, HOLogic.unit) |
190 then list_abs_free (map dest_Free xs, HOLogic.unit) |
191 else list_abs_free (map dest_Free xs, list_comb |
191 else list_abs_free (map dest_Free xs, list_comb |
192 (Free ("r" ^ Sign.base_name (Thm.name_of_thm intr), |
192 (Free ("r" ^ Sign.base_name (Thm.get_name intr), |
193 map fastype_of (rev args) ---> conclT), rev args)) |
193 map fastype_of (rev args) ---> conclT), rev args)) |
194 end |
194 end |
195 |
195 |
196 in fun_of args' [] (rev args) used (Logic.strip_imp_prems rule') end; |
196 in fun_of args' [] (rev args) used (Logic.strip_imp_prems rule') end; |
197 |
197 |
224 end) (rec_names ~~ concls') |
224 end) (rec_names ~~ concls') |
225 in if null rlzs then Extraction.nullt else |
225 in if null rlzs then Extraction.nullt else |
226 let |
226 let |
227 val r = foldr1 HOLogic.mk_prod rlzs; |
227 val r = foldr1 HOLogic.mk_prod rlzs; |
228 val x = Free ("x", Extraction.etype_of thy vs [] (hd (prems_of induct))); |
228 val x = Free ("x", Extraction.etype_of thy vs [] (hd (prems_of induct))); |
229 fun name_of_fn intr = "r" ^ Sign.base_name (Thm.name_of_thm intr); |
229 fun name_of_fn intr = "r" ^ Sign.base_name (Thm.get_name intr); |
230 val r' = list_abs_free (List.mapPartial (fn intr => |
230 val r' = list_abs_free (List.mapPartial (fn intr => |
231 Option.map (pair (name_of_fn intr)) (AList.lookup (op =) frees (name_of_fn intr))) intrs, |
231 Option.map (pair (name_of_fn intr)) (AList.lookup (op =) frees (name_of_fn intr))) intrs, |
232 if length concls = 1 then r $ x else r) |
232 if length concls = 1 then r $ x else r) |
233 in |
233 in |
234 if length concls = 1 then lambda x r' else r' |
234 if length concls = 1 then lambda x r' else r' |
269 if Extraction.etype_of thy vs [] prem = Extraction.nullT |
269 if Extraction.etype_of thy vs [] prem = Extraction.nullT |
270 then AbsP ("H", SOME rprem, mk_prf rs prems prf) |
270 then AbsP ("H", SOME rprem, mk_prf rs prems prf) |
271 else forall_intr_prf (Var (hd rs), AbsP ("H", SOME rprem, |
271 else forall_intr_prf (Var (hd rs), AbsP ("H", SOME rprem, |
272 mk_prf (tl rs) prems prf)); |
272 mk_prf (tl rs) prems prf)); |
273 |
273 |
274 in (Thm.name_of_thm rule, (vs, |
274 in (Thm.get_name rule, (vs, |
275 if rt = Extraction.nullt then rt else |
275 if rt = Extraction.nullt then rt else |
276 foldr (uncurry lambda) rt vs1, |
276 foldr (uncurry lambda) rt vs1, |
277 foldr forall_intr_prf (mk_prf rs prems (Proofterm.proof_combP |
277 foldr forall_intr_prf (mk_prf rs prems (Proofterm.proof_combP |
278 (prf_of rrule, map PBound (length prems - 1 downto 0)))) vs2)) |
278 (prf_of rrule, map PBound (length prems - 1 downto 0)))) vs2)) |
279 end; |
279 end; |
347 (** realizability predicate **) |
347 (** realizability predicate **) |
348 |
348 |
349 val (thy3', ind_info) = thy2 |> |
349 val (thy3', ind_info) = thy2 |> |
350 OldInductivePackage.add_inductive_i false true "" false false false |
350 OldInductivePackage.add_inductive_i false true "" false false false |
351 (map Logic.unvarify rlzsets) (map (fn (rintr, intr) => |
351 (map Logic.unvarify rlzsets) (map (fn (rintr, intr) => |
352 ((Sign.base_name (Thm.name_of_thm intr), strip_all |
352 ((Sign.base_name (Thm.get_name intr), strip_all |
353 (Logic.unvarify rintr)), [])) (rintrs ~~ intrs)) [] |>> |
353 (Logic.unvarify rintr)), [])) (rintrs ~~ intrs)) [] |>> |
354 Theory.absolute_path; |
354 Theory.absolute_path; |
355 val thy3 = PureThy.hide_thms false |
355 val thy3 = PureThy.hide_thms false |
356 (map Thm.name_of_thm (#intrs ind_info)) thy3'; |
356 (map Thm.get_name (#intrs ind_info)) thy3'; |
357 |
357 |
358 (** realizer for induction rule **) |
358 (** realizer for induction rule **) |
359 |
359 |
360 val Ps = List.mapPartial (fn _ $ M $ P => if set_of M mem rsets then |
360 val Ps = List.mapPartial (fn _ $ M $ P => if set_of M mem rsets then |
361 SOME (fst (fst (dest_Var (head_of P)))) else NONE) |
361 SOME (fst (fst (dest_Var (head_of P)))) else NONE) |
377 rewrite_goals_tac rews, |
377 rewrite_goals_tac rews, |
378 REPEAT ((resolve_tac prems THEN_ALL_NEW EVERY' |
378 REPEAT ((resolve_tac prems THEN_ALL_NEW EVERY' |
379 [K (rewrite_goals_tac rews), ObjectLogic.atomize_tac, |
379 [K (rewrite_goals_tac rews), ObjectLogic.atomize_tac, |
380 DEPTH_SOLVE_1 o FIRST' [atac, etac allE, etac impE]]) 1)]); |
380 DEPTH_SOLVE_1 o FIRST' [atac, etac allE, etac impE]]) 1)]); |
381 val (thm', thy') = PureThy.store_thm ((space_implode "_" |
381 val (thm', thy') = PureThy.store_thm ((space_implode "_" |
382 (Thm.name_of_thm induct :: vs @ Ps @ ["correctness"]), thm), []) thy |
382 (Thm.get_name induct :: vs @ Ps @ ["correctness"]), thm), []) thy |
383 in |
383 in |
384 Extraction.add_realizers_i |
384 Extraction.add_realizers_i |
385 [mk_realizer thy' (vs @ Ps) params' ((induct, thm'), r)] thy' |
385 [mk_realizer thy' (vs @ Ps) params' ((induct, thm'), r)] thy' |
386 end; |
386 end; |
387 |
387 |
425 ALLGOALS (EVERY' [etac Pair_inject, asm_simp_tac HOL_basic_ss]), |
425 ALLGOALS (EVERY' [etac Pair_inject, asm_simp_tac HOL_basic_ss]), |
426 rewrite_goals_tac rews, |
426 rewrite_goals_tac rews, |
427 REPEAT ((resolve_tac prems THEN_ALL_NEW (ObjectLogic.atomize_tac THEN' |
427 REPEAT ((resolve_tac prems THEN_ALL_NEW (ObjectLogic.atomize_tac THEN' |
428 DEPTH_SOLVE_1 o FIRST' [atac, etac allE, etac impE])) 1)]); |
428 DEPTH_SOLVE_1 o FIRST' [atac, etac allE, etac impE])) 1)]); |
429 val (thm', thy') = PureThy.store_thm ((space_implode "_" |
429 val (thm', thy') = PureThy.store_thm ((space_implode "_" |
430 (Thm.name_of_thm elim :: vs @ Ps @ ["correctness"]), thm), []) thy |
430 (Thm.get_name elim :: vs @ Ps @ ["correctness"]), thm), []) thy |
431 in |
431 in |
432 Extraction.add_realizers_i |
432 Extraction.add_realizers_i |
433 [mk_realizer thy' (vs @ Ps) params' ((elim, thm'), r)] thy' |
433 [mk_realizer thy' (vs @ Ps) params' ((elim, thm'), r)] thy' |
434 end; |
434 end; |
435 |
435 |