src/HOL/Tools/recdef.ML
changeset 35756 cfde251d03a5
parent 35690 863bee3a9153
child 36610 bafd82950e24
equal deleted inserted replaced
35737:19eefc0655b6 35756:cfde251d03a5
     5 *)
     5 *)
     6 
     6 
     7 signature RECDEF =
     7 signature RECDEF =
     8 sig
     8 sig
     9   val get_recdef: theory -> string
     9   val get_recdef: theory -> string
    10     -> {simps: thm list, rules: thm list list, induct: thm, tcs: term list} option
    10     -> {lhs: term, simps: thm list, rules: thm list list, induct: thm, tcs: term list} option
    11   val get_hints: Proof.context -> {simps: thm list, congs: (string * thm) list, wfs: thm list}
    11   val get_hints: Proof.context -> {simps: thm list, congs: (string * thm) list, wfs: thm list}
    12   val simp_add: attribute
    12   val simp_add: attribute
    13   val simp_del: attribute
    13   val simp_del: attribute
    14   val cong_add: attribute
    14   val cong_add: attribute
    15   val cong_del: attribute
    15   val cong_del: attribute
    16   val wf_add: attribute
    16   val wf_add: attribute
    17   val wf_del: attribute
    17   val wf_del: attribute
    18   val add_recdef: bool -> xstring -> string -> ((binding * string) * Attrib.src list) list ->
    18   val add_recdef: bool -> xstring -> string -> ((binding * string) * Attrib.src list) list ->
    19     Attrib.src option -> theory -> theory
    19     Attrib.src option -> theory -> theory
    20       * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
    20       * {lhs: term, simps: thm list, rules: thm list list, induct: thm, tcs: term list}
    21   val add_recdef_i: bool -> xstring -> term -> ((binding * term) * attribute list) list ->
    21   val add_recdef_i: bool -> xstring -> term -> ((binding * term) * attribute list) list ->
    22     theory -> theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
    22     theory -> theory * {lhs: term, simps: thm list, rules: thm list list, induct: thm, tcs: term list}
    23   val defer_recdef: xstring -> string list -> (Facts.ref * Attrib.src list) list
    23   val defer_recdef: xstring -> string list -> (Facts.ref * Attrib.src list) list
    24     -> theory -> theory * {induct_rules: thm}
    24     -> theory -> theory * {induct_rules: thm}
    25   val defer_recdef_i: xstring -> term list -> thm list -> theory -> theory * {induct_rules: thm}
    25   val defer_recdef_i: xstring -> term list -> thm list -> theory -> theory * {induct_rules: thm}
    26   val recdef_tc: bstring * Attrib.src list -> xstring -> int option -> bool ->
    26   val recdef_tc: bstring * Attrib.src list -> xstring -> int option -> bool ->
    27     local_theory -> Proof.state
    27     local_theory -> Proof.state
    82 
    82 
    83 (** global and local recdef data **)
    83 (** global and local recdef data **)
    84 
    84 
    85 (* theory data *)
    85 (* theory data *)
    86 
    86 
    87 type recdef_info = {simps: thm list, rules: thm list list, induct: thm, tcs: term list};
    87 type recdef_info = {lhs: term, simps: thm list, rules: thm list list, induct: thm, tcs: term list};
    88 
    88 
    89 structure GlobalRecdefData = Theory_Data
    89 structure GlobalRecdefData = Theory_Data
    90 (
    90 (
    91   type T = recdef_info Symtab.table * hints;
    91   type T = recdef_info Symtab.table * hints;
    92   val empty = (Symtab.empty, mk_hints ([], [], [])): T;
    92   val empty = (Symtab.empty, mk_hints ([], [], [])): T;
   196 
   196 
   197     val (cs, ss, congs, wfs) = prep_hints thy hints;
   197     val (cs, ss, congs, wfs) = prep_hints thy hints;
   198     (*We must remove imp_cong to prevent looping when the induction rule
   198     (*We must remove imp_cong to prevent looping when the induction rule
   199       is simplified. Many induction rules have nested implications that would
   199       is simplified. Many induction rules have nested implications that would
   200       give rise to looping conditional rewriting.*)
   200       give rise to looping conditional rewriting.*)
   201     val (thy, {rules = rules_idx, induct, tcs}) =
   201     val (thy, {lhs, rules = rules_idx, induct, tcs}) =
   202         tfl_fn not_permissive thy cs (ss delcongs [imp_cong])
   202         tfl_fn not_permissive thy cs (ss delcongs [imp_cong])
   203                congs wfs name R eqs;
   203                congs wfs name R eqs;
   204     val rules = (map o map) fst (partition_eq (eq_snd (op = : int * int -> bool)) rules_idx);
   204     val rules = (map o map) fst (partition_eq (eq_snd (op = : int * int -> bool)) rules_idx);
   205     val simp_att =
   205     val simp_att =
   206       if null tcs then [Simplifier.simp_add, Nitpick_Simps.add, Code.add_default_eqn_attribute]
   206       if null tcs then [Simplifier.simp_add, Nitpick_Simps.add, Code.add_default_eqn_attribute]
   209       thy
   209       thy
   210       |> Sign.add_path bname
   210       |> Sign.add_path bname
   211       |> PureThy.add_thmss
   211       |> PureThy.add_thmss
   212         (((Binding.name "simps", flat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
   212         (((Binding.name "simps", flat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
   213       ||>> PureThy.add_thms [((Binding.name "induct", induct), [])]
   213       ||>> PureThy.add_thms [((Binding.name "induct", induct), [])]
   214       ||> Spec_Rules.add_global Spec_Rules.Equational (tcs, flat rules);
   214       ||> Spec_Rules.add_global Spec_Rules.Equational ([lhs], flat rules);
   215     val result = {simps = simps', rules = rules', induct = induct', tcs = tcs};
   215     val result = {lhs = lhs, simps = simps', rules = rules', induct = induct', tcs = tcs};
   216     val thy =
   216     val thy =
   217       thy
   217       thy
   218       |> put_recdef name result
   218       |> put_recdef name result
   219       |> Sign.parent_path;
   219       |> Sign.parent_path;
   220   in (thy, result) end;
   220   in (thy, result) end;