src/ZF/Tools/inductive_package.ML
changeset 17314 04e21a27c0ad
parent 17057 0934ac31985f
child 17892 62c397c17d18
equal deleted inserted replaced
17313:7d97f60293ae 17314:04e21a27c0ad
   298      (*Used to make induction rules;
   298      (*Used to make induction rules;
   299         ind_alist = [(rec_tm1,pred1),...] associates predicates with rec ops
   299         ind_alist = [(rec_tm1,pred1),...] associates predicates with rec ops
   300         prem is a premise of an intr rule*)
   300         prem is a premise of an intr rule*)
   301      fun add_induct_prem ind_alist (prem as Const("Trueprop",_) $
   301      fun add_induct_prem ind_alist (prem as Const("Trueprop",_) $
   302                       (Const("op :",_)$t$X), iprems) =
   302                       (Const("op :",_)$t$X), iprems) =
   303           (case gen_assoc (op aconv) (ind_alist, X) of
   303           (case AList.lookup (op aconv) ind_alist X of
   304                SOME pred => prem :: FOLogic.mk_Trueprop (pred $ t) :: iprems
   304                SOME pred => prem :: FOLogic.mk_Trueprop (pred $ t) :: iprems
   305              | NONE => (*possibly membership in M(rec_tm), for M monotone*)
   305              | NONE => (*possibly membership in M(rec_tm), for M monotone*)
   306                  let fun mk_sb (rec_tm,pred) =
   306                  let fun mk_sb (rec_tm,pred) =
   307                              (rec_tm, Ind_Syntax.Collect_const$rec_tm$pred)
   307                              (rec_tm, Ind_Syntax.Collect_const$rec_tm$pred)
   308                  in  subst_free (map mk_sb ind_alist) prem :: iprems  end)
   308                  in  subst_free (map mk_sb ind_alist) prem :: iprems  end)
   312      fun induct_prem ind_alist intr =
   312      fun induct_prem ind_alist intr =
   313        let val quantfrees = map dest_Free (term_frees intr \\ rec_params)
   313        let val quantfrees = map dest_Free (term_frees intr \\ rec_params)
   314            val iprems = foldr (add_induct_prem ind_alist) []
   314            val iprems = foldr (add_induct_prem ind_alist) []
   315                               (Logic.strip_imp_prems intr)
   315                               (Logic.strip_imp_prems intr)
   316            val (t,X) = Ind_Syntax.rule_concl intr
   316            val (t,X) = Ind_Syntax.rule_concl intr
   317            val (SOME pred) = gen_assoc (op aconv) (ind_alist, X)
   317            val (SOME pred) = AList.lookup (op aconv) ind_alist X
   318            val concl = FOLogic.mk_Trueprop (pred $ t)
   318            val concl = FOLogic.mk_Trueprop (pred $ t)
   319        in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end
   319        in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end
   320        handle Bind => error"Recursion term not found in conclusion";
   320        handle Bind => error"Recursion term not found in conclusion";
   321 
   321 
   322      (*Minimizes backtracking by delivering the correct premise to each goal.
   322      (*Minimizes backtracking by delivering the correct premise to each goal.