src/HOL/Library/simps_case_conv.ML
changeset 54401 f6950854855d
parent 53433 3b356b7f7cad
child 54883 dd04a8b654fc
equal deleted inserted replaced
54400:418a183fbe21 54401:f6950854855d
    20 (* Collects all type constructors in a type *)
    20 (* Collects all type constructors in a type *)
    21 fun collect_Tcons (Type (name,Ts)) = name :: maps collect_Tcons Ts
    21 fun collect_Tcons (Type (name,Ts)) = name :: maps collect_Tcons Ts
    22   | collect_Tcons (TFree _) = []
    22   | collect_Tcons (TFree _) = []
    23   | collect_Tcons (TVar _) = []
    23   | collect_Tcons (TVar _) = []
    24 
    24 
    25 fun get_split_ths thy = collect_Tcons
    25 fun get_split_ths ctxt = collect_Tcons
    26     #> distinct (op =)
    26     #> distinct (op =)
    27     #> map_filter (Datatype_Data.get_info thy)
    27     #> map_filter (Ctr_Sugar.ctr_sugar_of ctxt)
    28     #> map #split
    28     #> map #split
    29 
    29 
    30 val strip_eq = prop_of #> HOLogic.dest_Trueprop #> HOLogic.dest_eq
    30 val strip_eq = prop_of #> HOLogic.dest_Trueprop #> HOLogic.dest_eq
    31 
    31 
    32 
    32 
    78       split_pats lhss ctxt
    78       split_pats lhss ctxt
    79     val pattern = map HOLogic.mk_tuple case_patss
    79     val pattern = map HOLogic.mk_tuple case_patss
    80     val case_arg = HOLogic.mk_tuple (flat def_frees)
    80     val case_arg = HOLogic.mk_tuple (flat def_frees)
    81     val cases = Case_Translation.make_case ctxt' Case_Translation.Warning Name.context
    81     val cases = Case_Translation.make_case ctxt' Case_Translation.Warning Name.context
    82       case_arg (pattern ~~ rhss)
    82       case_arg (pattern ~~ rhss)
    83     val split_thms = get_split_ths (Proof_Context.theory_of ctxt') (fastype_of case_arg)
    83     val split_thms = get_split_ths ctxt' (fastype_of case_arg)
    84     val t = (list_comb (fun_t, def_pats), cases)
    84     val t = (list_comb (fun_t, def_pats), cases)
    85       |> HOLogic.mk_eq
    85       |> HOLogic.mk_eq
    86       |> HOLogic.mk_Trueprop
    86       |> HOLogic.mk_Trueprop
    87   in ((t, split_thms), ctxt') end
    87   in ((t, split_thms), ctxt') end
    88 
    88 
   192                  THEN (REPEAT (FIRST (map (do_split ctxt) splitthms)))) thm)
   192                  THEN (REPEAT (FIRST (map (do_split ctxt) splitthms)))) thm)
   193 
   193 
   194 fun to_simps ctxt thm =
   194 fun to_simps ctxt thm =
   195   let
   195   let
   196     val T = thm |> strip_eq |> fst |> strip_comb |> fst |> fastype_of
   196     val T = thm |> strip_eq |> fst |> strip_comb |> fst |> fastype_of
   197     val splitthms = get_split_ths (Proof_Context.theory_of ctxt) T
   197     val splitthms = get_split_ths ctxt T
   198   in gen_to_simps ctxt splitthms thm end
   198   in gen_to_simps ctxt splitthms thm end
   199 
   199 
   200 
   200 
   201 end
   201 end
   202 
   202