330 val atom = single (distinct (op aconv) funcs) |
328 val atom = single (distinct (op aconv) funcs) |
331 val (fname,ftype) = dest_atom atom |
329 val (fname,ftype) = dest_atom atom |
332 val dummy = map (no_repeat_vars thy) pats |
330 val dummy = map (no_repeat_vars thy) pats |
333 val rows = ListPair.zip (map (fn x => ([]:term list,[x])) pats, |
331 val rows = ListPair.zip (map (fn x => ([]:term list,[x])) pats, |
334 map (fn (t,i) => (t,(i,true))) (enumerate R)) |
332 map (fn (t,i) => (t,(i,true))) (enumerate R)) |
335 val names = foldr add_term_names [] R |
333 val names = foldr OldTerm.add_term_names [] R |
336 val atype = type_of(hd pats) |
334 val atype = type_of(hd pats) |
337 and aname = Name.variant names "a" |
335 and aname = Name.variant names "a" |
338 val a = Free(aname,atype) |
336 val a = Free(aname,atype) |
339 val ty_info = Thry.match_info thy |
337 val ty_info = Thry.match_info thy |
340 val ty_match = Thry.match_type thy |
338 val ty_match = Thry.match_type thy |
492 else () |
490 else () |
493 val (case_rewrites,context_congs) = extraction_thms thy |
491 val (case_rewrites,context_congs) = extraction_thms thy |
494 val tych = Thry.typecheck thy |
492 val tych = Thry.typecheck thy |
495 val WFREC_THM0 = R.ISPEC (tych functional) Thms.WFREC_COROLLARY |
493 val WFREC_THM0 = R.ISPEC (tych functional) Thms.WFREC_COROLLARY |
496 val Const("All",_) $ Abs(Rname,Rtype,_) = concl WFREC_THM0 |
494 val Const("All",_) $ Abs(Rname,Rtype,_) = concl WFREC_THM0 |
497 val R = Free (Name.variant (foldr add_term_names [] eqns) Rname, |
495 val R = Free (Name.variant (foldr OldTerm.add_term_names [] eqns) Rname, |
498 Rtype) |
496 Rtype) |
499 val WFREC_THM = R.ISPECL [tych R, tych g] WFREC_THM0 |
497 val WFREC_THM = R.ISPECL [tych R, tych g] WFREC_THM0 |
500 val ([proto_def, WFR],_) = S.strip_imp(concl WFREC_THM) |
498 val ([proto_def, WFR],_) = S.strip_imp(concl WFREC_THM) |
501 val dummy = |
499 val dummy = |
502 if !trace then |
500 if !trace then |
690 |
688 |
691 fun complete_cases thy = |
689 fun complete_cases thy = |
692 let val tych = Thry.typecheck thy |
690 let val tych = Thry.typecheck thy |
693 val ty_info = Thry.induct_info thy |
691 val ty_info = Thry.induct_info thy |
694 in fn pats => |
692 in fn pats => |
695 let val names = foldr add_term_names [] pats |
693 let val names = foldr OldTerm.add_term_names [] pats |
696 val T = type_of (hd pats) |
694 val T = type_of (hd pats) |
697 val aname = Name.variant names "a" |
695 val aname = Name.variant names "a" |
698 val vname = Name.variant (aname::names) "v" |
696 val vname = Name.variant (aname::names) "v" |
699 val a = Free (aname, T) |
697 val a = Free (aname, T) |
700 val v = Free (vname, T) |
698 val v = Free (vname, T) |
843 let val tych = Thry.typecheck thy |
841 let val tych = Thry.typecheck thy |
844 val Sinduction = R.UNDISCH (R.ISPEC (tych R) Thms.WF_INDUCTION_THM) |
842 val Sinduction = R.UNDISCH (R.ISPEC (tych R) Thms.WF_INDUCTION_THM) |
845 val (pats,TCsl) = ListPair.unzip pat_TCs_list |
843 val (pats,TCsl) = ListPair.unzip pat_TCs_list |
846 val case_thm = complete_cases thy pats |
844 val case_thm = complete_cases thy pats |
847 val domain = (type_of o hd) pats |
845 val domain = (type_of o hd) pats |
848 val Pname = Name.variant (foldr (Library.foldr add_term_names) |
846 val Pname = Name.variant (foldr (Library.foldr OldTerm.add_term_names) |
849 [] (pats::TCsl)) "P" |
847 [] (pats::TCsl)) "P" |
850 val P = Free(Pname, domain --> HOLogic.boolT) |
848 val P = Free(Pname, domain --> HOLogic.boolT) |
851 val Sinduct = R.SPEC (tych P) Sinduction |
849 val Sinduct = R.SPEC (tych P) Sinduction |
852 val Sinduct_assumf = S.rand ((#ant o S.dest_imp o concl) Sinduct) |
850 val Sinduct_assumf = S.rand ((#ant o S.dest_imp o concl) Sinduct) |
853 val Rassums_TCl' = map (build_ih fconst (P,SV)) pat_TCs_list |
851 val Rassums_TCl' = map (build_ih fconst (P,SV)) pat_TCs_list |
854 val (Rassums,TCl') = ListPair.unzip Rassums_TCl' |
852 val (Rassums,TCl') = ListPair.unzip Rassums_TCl' |
855 val Rinduct_assum = R.ASSUME (tych (S.list_mk_conj Rassums)) |
853 val Rinduct_assum = R.ASSUME (tych (S.list_mk_conj Rassums)) |
856 val cases = map (fn pat => Term.betapply (Sinduct_assumf, pat)) pats |
854 val cases = map (fn pat => Term.betapply (Sinduct_assumf, pat)) pats |
857 val tasks = U.zip3 cases TCl' (R.CONJUNCTS Rinduct_assum) |
855 val tasks = U.zip3 cases TCl' (R.CONJUNCTS Rinduct_assum) |
858 val proved_cases = map (prove_case fconst thy) tasks |
856 val proved_cases = map (prove_case fconst thy) tasks |
859 val v = Free (Name.variant (foldr add_term_names [] (map concl proved_cases)) |
857 val v = Free (Name.variant (foldr OldTerm.add_term_names [] (map concl proved_cases)) |
860 "v", |
858 "v", |
861 domain) |
859 domain) |
862 val vtyped = tych v |
860 val vtyped = tych v |
863 val substs = map (R.SYM o R.ASSUME o tych o (curry HOLogic.mk_eq v)) pats |
861 val substs = map (R.SYM o R.ASSUME o tych o (curry HOLogic.mk_eq v)) pats |
864 val proved_cases1 = ListPair.map (fn (th,th') => R.SUBS[th]th') |
862 val proved_cases1 = ListPair.map (fn (th,th') => R.SUBS[th]th') |