src/ZF/Tools/inductive_package.ML
changeset 30190 479806475f3c
parent 29579 cb520b766e00
child 30223 24d975352879
equal deleted inserted replaced
30189:3633f560f4c3 30190:479806475f3c
    97   val dummy = assert_all is_Free rec_params
    97   val dummy = assert_all is_Free rec_params
    98       (fn t => "Param in recursion term not a free variable: " ^
    98       (fn t => "Param in recursion term not a free variable: " ^
    99                Syntax.string_of_term ctxt t);
    99                Syntax.string_of_term ctxt t);
   100 
   100 
   101   (*** Construct the fixedpoint definition ***)
   101   (*** Construct the fixedpoint definition ***)
   102   val mk_variant = Name.variant (foldr OldTerm.add_term_names [] intr_tms);
   102   val mk_variant = Name.variant (List.foldr OldTerm.add_term_names [] intr_tms);
   103 
   103 
   104   val z' = mk_variant"z" and X' = mk_variant"X" and w' = mk_variant"w";
   104   val z' = mk_variant"z" and X' = mk_variant"X" and w' = mk_variant"w";
   105 
   105 
   106   fun dest_tprop (Const("Trueprop",_) $ P) = P
   106   fun dest_tprop (Const("Trueprop",_) $ P) = P
   107     | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^
   107     | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^
   111   fun fp_part intr = (*quantify over rule's free vars except parameters*)
   111   fun fp_part intr = (*quantify over rule's free vars except parameters*)
   112     let val prems = map dest_tprop (Logic.strip_imp_prems intr)
   112     let val prems = map dest_tprop (Logic.strip_imp_prems intr)
   113         val dummy = List.app (fn rec_hd => List.app (chk_prem rec_hd) prems) rec_hds
   113         val dummy = List.app (fn rec_hd => List.app (chk_prem rec_hd) prems) rec_hds
   114         val exfrees = OldTerm.term_frees intr \\ rec_params
   114         val exfrees = OldTerm.term_frees intr \\ rec_params
   115         val zeq = FOLogic.mk_eq (Free(z',iT), #1 (rule_concl intr))
   115         val zeq = FOLogic.mk_eq (Free(z',iT), #1 (rule_concl intr))
   116     in foldr FOLogic.mk_exists
   116     in List.foldr FOLogic.mk_exists
   117              (BalancedTree.make FOLogic.mk_conj (zeq::prems)) exfrees
   117              (BalancedTree.make FOLogic.mk_conj (zeq::prems)) exfrees
   118     end;
   118     end;
   119 
   119 
   120   (*The Part(A,h) terms -- compose injections to make h*)
   120   (*The Part(A,h) terms -- compose injections to make h*)
   121   fun mk_Part (Bound 0) = Free(X',iT) (*no mutual rec, no Part needed*)
   121   fun mk_Part (Bound 0) = Free(X',iT) (*no mutual rec, no Part needed*)
   301        | add_induct_prem ind_alist (prem,iprems) = prem :: iprems;
   301        | add_induct_prem ind_alist (prem,iprems) = prem :: iprems;
   302 
   302 
   303      (*Make a premise of the induction rule.*)
   303      (*Make a premise of the induction rule.*)
   304      fun induct_prem ind_alist intr =
   304      fun induct_prem ind_alist intr =
   305        let val quantfrees = map dest_Free (OldTerm.term_frees intr \\ rec_params)
   305        let val quantfrees = map dest_Free (OldTerm.term_frees intr \\ rec_params)
   306            val iprems = foldr (add_induct_prem ind_alist) []
   306            val iprems = List.foldr (add_induct_prem ind_alist) []
   307                               (Logic.strip_imp_prems intr)
   307                               (Logic.strip_imp_prems intr)
   308            val (t,X) = Ind_Syntax.rule_concl intr
   308            val (t,X) = Ind_Syntax.rule_concl intr
   309            val (SOME pred) = AList.lookup (op aconv) ind_alist X
   309            val (SOME pred) = AList.lookup (op aconv) ind_alist X
   310            val concl = FOLogic.mk_Trueprop (pred $ t)
   310            val concl = FOLogic.mk_Trueprop (pred $ t)
   311        in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end
   311        in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end
   378      fun mk_predpair rec_tm =
   378      fun mk_predpair rec_tm =
   379        let val rec_name = (#1 o dest_Const o head_of) rec_tm
   379        let val rec_name = (#1 o dest_Const o head_of) rec_tm
   380            val pfree = Free(pred_name ^ "_" ^ Sign.base_name rec_name,
   380            val pfree = Free(pred_name ^ "_" ^ Sign.base_name rec_name,
   381                             elem_factors ---> FOLogic.oT)
   381                             elem_factors ---> FOLogic.oT)
   382            val qconcl =
   382            val qconcl =
   383              foldr FOLogic.mk_all
   383              List.foldr FOLogic.mk_all
   384                (FOLogic.imp $
   384                (FOLogic.imp $
   385                 (@{const mem} $ elem_tuple $ rec_tm)
   385                 (@{const mem} $ elem_tuple $ rec_tm)
   386                       $ (list_comb (pfree, elem_frees))) elem_frees
   386                       $ (list_comb (pfree, elem_frees))) elem_frees
   387        in  (CP.ap_split elem_type FOLogic.oT pfree,
   387        in  (CP.ap_split elem_type FOLogic.oT pfree,
   388             qconcl)
   388             qconcl)