60 | SOME cargs => fst (fold (fn (xs, x) => fn (bs', cargs') => |
60 | SOME cargs => fst (fold (fn (xs, x) => fn (bs', cargs') => |
61 let val (cargs1, (u, _) :: cargs2) = chop (length xs) cargs' |
61 let val (cargs1, (u, _) :: cargs2) = chop (length xs) cargs' |
62 in (add_binders thy i u |
62 in (add_binders thy i u |
63 (fold (fn (u, T) => |
63 (fold (fn (u, T) => |
64 if exists (fn j => j < i) (loose_bnos u) then I |
64 if exists (fn j => j < i) (loose_bnos u) then I |
65 else insert (op aconv o pairself fst) |
65 else insert (op aconv o apply2 fst) |
66 (incr_boundvars (~i) u, T)) cargs1 bs'), cargs2) |
66 (incr_boundvars (~i) u, T)) cargs1 bs'), cargs2) |
67 end) cargs (bs, ts ~~ Ts)))) |
67 end) cargs (bs, ts ~~ Ts)))) |
68 | _ => fold (add_binders thy i) ts bs) |
68 | _ => fold (add_binders thy i) ts bs) |
69 | (u, ts) => add_binders thy i u (fold (add_binders thy i) ts bs)) |
69 | (u, ts) => add_binders thy i u (fold (add_binders thy i) ts bs)) |
70 | add_binders thy i (Abs (_, _, t)) bs = add_binders thy (i + 1) t bs |
70 | add_binders thy i (Abs (_, _, t)) bs = add_binders thy (i + 1) t bs |
162 val ([raw_induct'], ctxt') = Variable.import_terms false [prop_of raw_induct] ctxt; |
162 val ([raw_induct'], ctxt') = Variable.import_terms false [prop_of raw_induct] ctxt; |
163 val concls = raw_induct' |> Logic.strip_imp_concl |> HOLogic.dest_Trueprop |> |
163 val concls = raw_induct' |> Logic.strip_imp_concl |> HOLogic.dest_Trueprop |> |
164 HOLogic.dest_conj |> map (HOLogic.dest_imp ##> strip_comb); |
164 HOLogic.dest_conj |> map (HOLogic.dest_imp ##> strip_comb); |
165 val ps = map (fst o snd) concls; |
165 val ps = map (fst o snd) concls; |
166 |
166 |
167 val _ = (case duplicates (op = o pairself fst) avoids of |
167 val _ = (case duplicates (op = o apply2 fst) avoids of |
168 [] => () |
168 [] => () |
169 | xs => error ("Duplicate case names: " ^ commas_quote (map fst xs))); |
169 | xs => error ("Duplicate case names: " ^ commas_quote (map fst xs))); |
170 val _ = avoids |> forall (fn (a, xs) => null (duplicates (op =) xs) orelse |
170 val _ = avoids |> forall (fn (a, xs) => null (duplicates (op =) xs) orelse |
171 error ("Duplicate variable names for case " ^ quote a)); |
171 error ("Duplicate variable names for case " ^ quote a)); |
172 val _ = (case subtract (op =) induct_cases (map fst avoids) of |
172 val _ = (case subtract (op =) induct_cases (map fst avoids) of |
336 else pi2 |
336 else pi2 |
337 end; |
337 end; |
338 val pis'' = fold (concat_perm #> map) pis' pis; |
338 val pis'' = fold (concat_perm #> map) pis' pis; |
339 val env = Pattern.first_order_match thy (ihypt, prop_of ihyp) |
339 val env = Pattern.first_order_match thy (ihypt, prop_of ihyp) |
340 (Vartab.empty, Vartab.empty); |
340 (Vartab.empty, Vartab.empty); |
341 val ihyp' = Thm.instantiate ([], map (pairself (cterm_of thy)) |
341 val ihyp' = Thm.instantiate ([], map (apply2 (cterm_of thy)) |
342 (map (Envir.subst_term env) vs ~~ |
342 (map (Envir.subst_term env) vs ~~ |
343 map (fold_rev (NominalDatatype.mk_perm []) |
343 map (fold_rev (NominalDatatype.mk_perm []) |
344 (rev pis' @ pis)) params' @ [z])) ihyp; |
344 (rev pis' @ pis)) params' @ [z])) ihyp; |
345 fun mk_pi th = |
345 fun mk_pi th = |
346 Simplifier.simplify (put_simpset HOL_basic_ss ctxt' addsimps [@{thm id_apply}] |
346 Simplifier.simplify (put_simpset HOL_basic_ss ctxt' addsimps [@{thm id_apply}] |