src/HOL/Tools/Function/mutual.ML
changeset 59621 291934bac95e
parent 59618 e6939796717e
child 59651 7f5f0e785a44
equal deleted inserted replaced
59620:92d7d8e4f1bf 59621:291934bac95e
   156     fun inst t = subst_bounds (rev qs, t)
   156     fun inst t = subst_bounds (rev qs, t)
   157     val gs = map inst pre_gs
   157     val gs = map inst pre_gs
   158     val args = map inst pre_args
   158     val args = map inst pre_args
   159     val rhs = inst pre_rhs
   159     val rhs = inst pre_rhs
   160 
   160 
   161     val cqs = map (Proof_Context.cterm_of ctxt) qs
   161     val cqs = map (Thm.cterm_of ctxt) qs
   162     val ags = map (Thm.assume o Proof_Context.cterm_of ctxt) gs
   162     val ags = map (Thm.assume o Thm.cterm_of ctxt) gs
   163 
   163 
   164     val import = fold Thm.forall_elim cqs
   164     val import = fold Thm.forall_elim cqs
   165       #> fold Thm.elim_implies ags
   165       #> fold Thm.elim_implies ags
   166 
   166 
   167     val export = fold_rev (Thm.implies_intr o Thm.cprop_of) ags
   167     val export = fold_rev (Thm.implies_intr o Thm.cprop_of) ags
   196 
   196 
   197 fun mk_applied_form ctxt caTs thm =
   197 fun mk_applied_form ctxt caTs thm =
   198   let
   198   let
   199     val xs =
   199     val xs =
   200       map_index (fn (i, T) =>
   200       map_index (fn (i, T) =>
   201         Proof_Context.cterm_of ctxt
   201         Thm.cterm_of ctxt
   202           (Free ("x" ^ string_of_int i, T))) caTs (* FIXME: Bind xs properly *)
   202           (Free ("x" ^ string_of_int i, T))) caTs (* FIXME: Bind xs properly *)
   203   in
   203   in
   204     fold (fn x => fn thm => Thm.combination thm (Thm.reflexive x)) xs thm
   204     fold (fn x => fn thm => Thm.combination thm (Thm.reflexive x)) xs thm
   205     |> Conv.fconv_rule (Thm.beta_conversion true)
   205     |> Conv.fconv_rule (Thm.beta_conversion true)
   206     |> fold_rev Thm.forall_intr xs
   206     |> fold_rev Thm.forall_intr xs
   224 
   224 
   225     val Ps = map2 mk_P parts newPs
   225     val Ps = map2 mk_P parts newPs
   226     val case_exp = Sum_Tree.mk_sumcases HOLogic.boolT Ps
   226     val case_exp = Sum_Tree.mk_sumcases HOLogic.boolT Ps
   227 
   227 
   228     val induct_inst =
   228     val induct_inst =
   229       Thm.forall_elim (Proof_Context.cterm_of ctxt case_exp) induct
   229       Thm.forall_elim (Thm.cterm_of ctxt case_exp) induct
   230       |> full_simplify (put_simpset Sum_Tree.sumcase_split_ss ctxt)
   230       |> full_simplify (put_simpset Sum_Tree.sumcase_split_ss ctxt)
   231       |> full_simplify (put_simpset HOL_basic_ss ctxt addsimps all_f_defs)
   231       |> full_simplify (put_simpset HOL_basic_ss ctxt addsimps all_f_defs)
   232 
   232 
   233     fun project rule (MutualPart {cargTs, i, ...}) k =
   233     fun project rule (MutualPart {cargTs, i, ...}) k =
   234       let
   234       let
   235         val afs = map_index (fn (j,T) => Free ("a" ^ string_of_int (j + k), T)) cargTs (* FIXME! *)
   235         val afs = map_index (fn (j,T) => Free ("a" ^ string_of_int (j + k), T)) cargTs (* FIXME! *)
   236         val inj = Sum_Tree.mk_inj ST n i (foldr1 HOLogic.mk_prod afs)
   236         val inj = Sum_Tree.mk_inj ST n i (foldr1 HOLogic.mk_prod afs)
   237       in
   237       in
   238         (rule
   238         (rule
   239          |> Thm.forall_elim (Proof_Context.cterm_of ctxt inj)
   239          |> Thm.forall_elim (Thm.cterm_of ctxt inj)
   240          |> full_simplify (put_simpset Sum_Tree.sumcase_split_ss ctxt)
   240          |> full_simplify (put_simpset Sum_Tree.sumcase_split_ss ctxt)
   241          |> fold_rev (Thm.forall_intr o Proof_Context.cterm_of ctxt) (afs @ newPs),
   241          |> fold_rev (Thm.forall_intr o Thm.cterm_of ctxt) (afs @ newPs),
   242          k + length cargTs)
   242          k + length cargTs)
   243       end
   243       end
   244   in
   244   in
   245     fst (fold_map (project induct_inst) parts 0)
   245     fst (fold_map (project induct_inst) parts 0)
   246   end
   246   end
   256     val arg_vars = rev arg_vars
   256     val arg_vars = rev arg_vars
   257 
   257 
   258     val argsT = fastype_of (HOLogic.mk_tuple arg_vars)
   258     val argsT = fastype_of (HOLogic.mk_tuple arg_vars)
   259     val (args, name_ctxt) = mk_var "x" argsT name_ctxt
   259     val (args, name_ctxt) = mk_var "x" argsT name_ctxt
   260     
   260     
   261     val P = mk_var "P" @{typ "bool"} name_ctxt |> fst |> Proof_Context.cterm_of ctxt
   261     val P = mk_var "P" @{typ "bool"} name_ctxt |> fst |> Thm.cterm_of ctxt
   262     val sumtree_inj = Sum_Tree.mk_inj ST n i args
   262     val sumtree_inj = Sum_Tree.mk_inj ST n i args
   263 
   263 
   264     val sum_elims =
   264     val sum_elims =
   265       @{thms HOL.notE[OF Sum_Type.sum.distinct(1)] HOL.notE[OF Sum_Type.sum.distinct(2)]}
   265       @{thms HOL.notE[OF Sum_Type.sum.distinct(1)] HOL.notE[OF Sum_Type.sum.distinct(2)]}
   266 
   266 
   268       REPEAT (eresolve_tac ctxt @{thms Pair_inject Inl_inject[elim_format] Inr_inject[elim_format]} i)
   268       REPEAT (eresolve_tac ctxt @{thms Pair_inject Inl_inject[elim_format] Inr_inject[elim_format]} i)
   269       THEN REPEAT (eresolve_tac ctxt sum_elims i)
   269       THEN REPEAT (eresolve_tac ctxt sum_elims i)
   270   in
   270   in
   271     cases_rule
   271     cases_rule
   272     |> Thm.forall_elim P
   272     |> Thm.forall_elim P
   273     |> Thm.forall_elim (Proof_Context.cterm_of ctxt sumtree_inj)
   273     |> Thm.forall_elim (Thm.cterm_of ctxt sumtree_inj)
   274     |> Tactic.rule_by_tactic ctxt (ALLGOALS prep_subgoal)
   274     |> Tactic.rule_by_tactic ctxt (ALLGOALS prep_subgoal)
   275     |> Thm.forall_intr (Proof_Context.cterm_of ctxt args)
   275     |> Thm.forall_intr (Thm.cterm_of ctxt args)
   276     |> Thm.forall_intr P
   276     |> Thm.forall_intr P
   277   end
   277   end
   278 
   278 
   279 
   279 
   280 fun mk_partial_rules_mutual lthy inner_cont (m as Mutual {parts, fqgars, n, ST, ...}) proof =
   280 fun mk_partial_rules_mutual lthy inner_cont (m as Mutual {parts, fqgars, n, ST, ...}) proof =