src/HOLCF/Tools/fixrec.ML
author huffman
Tue Nov 03 17:03:21 2009 -0800 (2009-11-03)
changeset 33425 7e4f3c66190d
parent 33401 fc43fa403a69
child 33427 3182812d33ed
permissions -rw-r--r--
add fixrec_simp attribute and method (eventually to replace fixpat)
     1 (*  Title:      HOLCF/Tools/fixrec.ML
     2     Author:     Amber Telfer and Brian Huffman
     3 
     4 Recursive function definition package for HOLCF.
     5 *)
     6 
     7 signature FIXREC =
     8 sig
     9   val add_fixrec: bool -> (binding * typ option * mixfix) list
    10     -> (Attrib.binding * term) list -> local_theory -> local_theory
    11   val add_fixrec_cmd: bool -> (binding * string option * mixfix) list
    12     -> (Attrib.binding * string) list -> local_theory -> local_theory
    13   val add_fixpat: Thm.binding * term list -> theory -> theory
    14   val add_fixpat_cmd: Attrib.binding * string list -> theory -> theory
    15   val add_matchers: (string * string) list -> theory -> theory
    16   val add_fixrec_simp: Thm.attribute
    17   val del_fixrec_simp: Thm.attribute
    18   val fixrec_simp_tac: Proof.context -> int -> tactic
    19   val setup: theory -> theory
    20 end;
    21 
    22 structure Fixrec :> FIXREC =
    23 struct
    24 
    25 val def_cont_fix_eq = @{thm def_cont_fix_eq};
    26 val def_cont_fix_ind = @{thm def_cont_fix_ind};
    27 
    28 
    29 fun fixrec_err s = error ("fixrec definition error:\n" ^ s);
    30 fun fixrec_eq_err thy s eq =
    31   fixrec_err (s ^ "\nin\n" ^ quote (Syntax.string_of_term_global thy eq));
    32 
    33 (*************************************************************************)
    34 (***************************** building types ****************************)
    35 (*************************************************************************)
    36 
    37 (* ->> is taken from holcf_logic.ML *)
    38 fun cfunT (T, U) = Type(@{type_name "->"}, [T, U]);
    39 
    40 infixr 6 ->>; val (op ->>) = cfunT;
    41 
    42 fun dest_cfunT (Type(@{type_name "->"}, [T, U])) = (T, U)
    43   | dest_cfunT T = raise TYPE ("dest_cfunT", [T], []);
    44 
    45 fun maybeT T = Type(@{type_name "maybe"}, [T]);
    46 
    47 fun dest_maybeT (Type(@{type_name "maybe"}, [T])) = T
    48   | dest_maybeT T = raise TYPE ("dest_maybeT", [T], []);
    49 
    50 fun tupleT [] = HOLogic.unitT
    51   | tupleT [T] = T
    52   | tupleT (T :: Ts) = HOLogic.mk_prodT (T, tupleT Ts);
    53 
    54 local
    55 
    56 fun binder_cfun (Type(@{type_name "->"},[T, U])) = T :: binder_cfun U
    57   | binder_cfun (Type(@{type_name "fun"},[T, U])) = T :: binder_cfun U
    58   | binder_cfun _   =  [];
    59 
    60 fun body_cfun (Type(@{type_name "->"},[T, U])) = body_cfun U
    61   | body_cfun (Type(@{type_name "fun"},[T, U])) = body_cfun U
    62   | body_cfun T   =  T;
    63 
    64 fun strip_cfun T : typ list * typ =
    65   (binder_cfun T, body_cfun T);
    66 
    67 fun cfunsT (Ts, U) = List.foldr cfunT U Ts;
    68 
    69 in
    70 
    71 fun matchT (T, U) =
    72   body_cfun T ->> cfunsT (binder_cfun T, U) ->> U;
    73 
    74 end
    75 
    76 (*************************************************************************)
    77 (***************************** building terms ****************************)
    78 (*************************************************************************)
    79 
    80 val mk_trp = HOLogic.mk_Trueprop;
    81 
    82 (* splits a cterm into the right and lefthand sides of equality *)
    83 fun dest_eqs t = HOLogic.dest_eq (HOLogic.dest_Trueprop t);
    84 
    85 (* similar to Thm.head_of, but for continuous application *)
    86 fun chead_of (Const(@{const_name Rep_CFun},_)$f$t) = chead_of f
    87   | chead_of u = u;
    88 
    89 fun capply_const (S, T) =
    90   Const(@{const_name Rep_CFun}, (S ->> T) --> (S --> T));
    91 
    92 fun cabs_const (S, T) =
    93   Const(@{const_name Abs_CFun}, (S --> T) --> (S ->> T));
    94 
    95 fun mk_cabs t =
    96   let val T = Term.fastype_of t
    97   in cabs_const (Term.domain_type T, Term.range_type T) $ t end
    98 
    99 fun mk_capply (t, u) =
   100   let val (S, T) =
   101     case Term.fastype_of t of
   102         Type(@{type_name "->"}, [S, T]) => (S, T)
   103       | _ => raise TERM ("mk_capply " ^ ML_Syntax.print_list ML_Syntax.print_term [t, u], [t, u]);
   104   in capply_const (S, T) $ t $ u end;
   105 
   106 infix 0 ==;  val (op ==) = Logic.mk_equals;
   107 infix 1 ===; val (op ===) = HOLogic.mk_eq;
   108 infix 9 `  ; val (op `) = mk_capply;
   109 
   110 (* builds the expression (LAM v. rhs) *)
   111 fun big_lambda v rhs =
   112   cabs_const (Term.fastype_of v, Term.fastype_of rhs) $ Term.lambda v rhs;
   113 
   114 (* builds the expression (LAM v1 v2 .. vn. rhs) *)
   115 fun big_lambdas [] rhs = rhs
   116   | big_lambdas (v::vs) rhs = big_lambda v (big_lambdas vs rhs);
   117 
   118 fun mk_return t =
   119   let val T = Term.fastype_of t
   120   in Const(@{const_name Fixrec.return}, T ->> maybeT T) ` t end;
   121 
   122 fun mk_bind (t, u) =
   123   let val (T, mU) = dest_cfunT (Term.fastype_of u);
   124       val bindT = maybeT T ->> (T ->> mU) ->> mU;
   125   in Const(@{const_name Fixrec.bind}, bindT) ` t ` u end;
   126 
   127 fun mk_mplus (t, u) =
   128   let val mT = Term.fastype_of t
   129   in Const(@{const_name Fixrec.mplus}, mT ->> mT ->> mT) ` t ` u end;
   130 
   131 fun mk_run t =
   132   let val mT = Term.fastype_of t
   133       val T = dest_maybeT mT
   134   in Const(@{const_name Fixrec.run}, mT ->> T) ` t end;
   135 
   136 fun mk_fix t =
   137   let val (T, _) = dest_cfunT (Term.fastype_of t)
   138   in Const(@{const_name fix}, (T ->> T) ->> T) ` t end;
   139 
   140 fun mk_cont t =
   141   let val T = Term.fastype_of t
   142   in Const(@{const_name cont}, T --> HOLogic.boolT) $ t end;
   143 
   144 val mk_fst = HOLogic.mk_fst
   145 val mk_snd = HOLogic.mk_snd
   146 
   147 (* builds the expression (v1,v2,..,vn) *)
   148 fun mk_tuple [] = HOLogic.unit
   149 |   mk_tuple (t::[]) = t
   150 |   mk_tuple (t::ts) = HOLogic.mk_prod (t, mk_tuple ts);
   151 
   152 (* builds the expression (%(v1,v2,..,vn). rhs) *)
   153 fun lambda_tuple [] rhs = Term.lambda (Free("unit", HOLogic.unitT)) rhs
   154   | lambda_tuple (v::[]) rhs = Term.lambda v rhs
   155   | lambda_tuple (v::vs) rhs =
   156       HOLogic.mk_split (Term.lambda v (lambda_tuple vs rhs));
   157 
   158 
   159 (*************************************************************************)
   160 (************* fixed-point definitions and unfolding theorems ************)
   161 (*************************************************************************)
   162 
   163 structure FixrecUnfoldData = GenericDataFun (
   164   type T = thm Symtab.table;
   165   val empty = Symtab.empty;
   166   val copy = I;
   167   val extend = I;
   168   val merge = K (Symtab.merge (K true));
   169 );
   170 
   171 local
   172 
   173 fun name_of (Const (n, T)) = n
   174   | name_of (Free (n, T)) = n
   175   | name_of _ = fixrec_err "name_of"
   176 
   177 val lhs_name =
   178   name_of o fst o HOLogic.dest_eq o HOLogic.dest_Trueprop o prop_of;
   179 
   180 in
   181 
   182 val add_unfold : Thm.attribute =
   183   Thm.declaration_attribute
   184     (fn th => FixrecUnfoldData.map (Symtab.insert (K true) (lhs_name th, th)));
   185 
   186 end
   187 
   188 fun add_fixdefs
   189   (fixes : ((binding * typ) * mixfix) list)
   190   (spec : (Attrib.binding * term) list)
   191   (lthy : local_theory) =
   192   let
   193     val thy = ProofContext.theory_of lthy;
   194     val names = map (Binding.name_of o fst o fst) fixes;
   195     val all_names = space_implode "_" names;
   196     val (lhss, rhss) = ListPair.unzip (map (dest_eqs o snd) spec);
   197     val functional = lambda_tuple lhss (mk_tuple rhss);
   198     val fixpoint = mk_fix (mk_cabs functional);
   199     
   200     val cont_thm =
   201       Goal.prove lthy [] [] (mk_trp (mk_cont functional))
   202         (K (simp_tac (simpset_of lthy) 1));
   203 
   204     fun one_def (l as Free(n,_)) r =
   205           let val b = Long_Name.base_name n
   206           in ((Binding.name (b^"_def"), []), r) end
   207       | one_def _ _ = fixrec_err "fixdefs: lhs not of correct form";
   208     fun defs [] _ = []
   209       | defs (l::[]) r = [one_def l r]
   210       | defs (l::ls) r = one_def l (mk_fst r) :: defs ls (mk_snd r);
   211     val fixdefs = defs lhss fixpoint;
   212     val define_all = fold_map (LocalTheory.define Thm.definitionK);
   213     val (fixdef_thms : (term * (string * thm)) list, lthy') = lthy
   214       |> define_all (map (apfst fst) fixes ~~ fixdefs);
   215     fun pair_equalI (thm1, thm2) = @{thm Pair_equalI} OF [thm1, thm2];
   216     val tuple_fixdef_thm = foldr1 pair_equalI (map (snd o snd) fixdef_thms);
   217     val P = Var (("P", 0), map Term.fastype_of lhss ---> HOLogic.boolT);
   218     val predicate = lambda_tuple lhss (list_comb (P, lhss));
   219     val tuple_induct_thm = (def_cont_fix_ind OF [tuple_fixdef_thm, cont_thm])
   220       |> Drule.instantiate' [] [SOME (Thm.cterm_of thy predicate)]
   221       |> LocalDefs.unfold lthy @{thms split_paired_all split_conv split_strict};
   222     val tuple_unfold_thm = (def_cont_fix_eq OF [tuple_fixdef_thm, cont_thm])
   223       |> LocalDefs.unfold lthy' @{thms split_conv};
   224     fun unfolds [] thm = []
   225       | unfolds (n::[]) thm = [(n, thm)]
   226       | unfolds (n::ns) thm = let
   227           val thmL = thm RS @{thm Pair_eqD1};
   228           val thmR = thm RS @{thm Pair_eqD2};
   229         in (n, thmL) :: unfolds ns thmR end;
   230     val unfold_thms = unfolds names tuple_unfold_thm;
   231     val induct_note : Attrib.binding * Thm.thm list =
   232       let
   233         val thm_name = Binding.name (all_names ^ "_induct");
   234       in
   235         ((thm_name, []), [tuple_induct_thm])
   236       end;
   237     fun unfold_note (name, thm) : Attrib.binding * Thm.thm list =
   238       let
   239         val thm_name = Binding.name (name ^ "_unfold");
   240         val src = Attrib.internal (K add_unfold);
   241       in
   242         ((thm_name, [src]), [thm])
   243       end;
   244     val (thmss, lthy'') = lthy'
   245       |> fold_map (LocalTheory.note Thm.generatedK)
   246         (induct_note :: map unfold_note unfold_thms);
   247   in
   248     (lthy'', names, fixdef_thms, map snd unfold_thms)
   249   end;
   250 
   251 (*************************************************************************)
   252 (*********** monadic notation and pattern matching compilation ***********)
   253 (*************************************************************************)
   254 
   255 structure FixrecMatchData = TheoryDataFun (
   256   type T = string Symtab.table;
   257   val empty = Symtab.empty;
   258   val copy = I;
   259   val extend = I;
   260   val merge = K (Symtab.merge (K true));
   261 );
   262 
   263 (* associate match functions with pattern constants *)
   264 fun add_matchers ms = FixrecMatchData.map (fold Symtab.update ms);
   265 
   266 fun taken_names (t : term) : bstring list =
   267   let
   268     fun taken (Const(a,_), bs) = insert (op =) (Long_Name.base_name a) bs
   269       | taken (Free(a,_) , bs) = insert (op =) a bs
   270       | taken (f $ u     , bs) = taken (f, taken (u, bs))
   271       | taken (Abs(a,_,t), bs) = taken (t, insert (op =) a bs)
   272       | taken (_         , bs) = bs;
   273   in
   274     taken (t, [])
   275   end;
   276 
   277 (* builds a monadic term for matching a constructor pattern *)
   278 fun pre_build match_name pat rhs vs taken =
   279   case pat of
   280     Const(@{const_name Rep_CFun},_)$f$(v as Free(n,T)) =>
   281       pre_build match_name f rhs (v::vs) taken
   282   | Const(@{const_name Rep_CFun},_)$f$x =>
   283       let val (rhs', v, taken') = pre_build match_name x rhs [] taken;
   284       in pre_build match_name f rhs' (v::vs) taken' end
   285   | f$(v as Free(n,T)) =>
   286       pre_build match_name f rhs (v::vs) taken
   287   | f$x =>
   288       let val (rhs', v, taken') = pre_build match_name x rhs [] taken;
   289       in pre_build match_name f rhs' (v::vs) taken' end
   290   | Const(c,T) =>
   291       let
   292         val n = Name.variant taken "v";
   293         fun result_type (Type(@{type_name "->"},[_,T])) (x::xs) = result_type T xs
   294           | result_type (Type (@{type_name "fun"},[_,T])) (x::xs) = result_type T xs
   295           | result_type T _ = T;
   296         val v = Free(n, result_type T vs);
   297         val m = Const(match_name c, matchT (T, fastype_of rhs));
   298         val k = big_lambdas vs rhs;
   299       in
   300         (m`v`k, v, n::taken)
   301       end
   302   | Free(n,_) => fixrec_err ("expected constructor, found free variable " ^ quote n)
   303   | _ => fixrec_err "pre_build: invalid pattern";
   304 
   305 (* builds a monadic term for matching a function definition pattern *)
   306 (* returns (name, arity, matcher) *)
   307 fun building match_name pat rhs vs taken =
   308   case pat of
   309     Const(@{const_name Rep_CFun}, _)$f$(v as Free(n,T)) =>
   310       building match_name f rhs (v::vs) taken
   311   | Const(@{const_name Rep_CFun}, _)$f$x =>
   312       let val (rhs', v, taken') = pre_build match_name x rhs [] taken;
   313       in building match_name f rhs' (v::vs) taken' end
   314   | Free(_,_) => ((pat, length vs), big_lambdas vs rhs)
   315   | Const(_,_) => ((pat, length vs), big_lambdas vs rhs)
   316   | _ => fixrec_err ("function is not declared as constant in theory: "
   317                     ^ ML_Syntax.print_term pat);
   318 
   319 fun strip_alls t =
   320   if Logic.is_all t then strip_alls (snd (Logic.dest_all t)) else t;
   321 
   322 fun match_eq match_name eq =
   323   let
   324     val (lhs,rhs) = dest_eqs (Logic.strip_imp_concl (strip_alls eq));
   325   in
   326     building match_name lhs (mk_return rhs) [] (taken_names eq)
   327   end;
   328 
   329 (* returns the sum (using +++) of the terms in ms *)
   330 (* also applies "run" to the result! *)
   331 fun fatbar arity ms =
   332   let
   333     fun LAM_Ts 0 t = ([], Term.fastype_of t)
   334       | LAM_Ts n (_ $ Abs(_,T,t)) =
   335           let val (Ts, U) = LAM_Ts (n-1) t in (T::Ts, U) end
   336       | LAM_Ts _ _ = fixrec_err "fatbar: internal error, not enough LAMs";
   337     fun unLAM 0 t = t
   338       | unLAM n (_$Abs(_,_,t)) = unLAM (n-1) t
   339       | unLAM _ _ = fixrec_err "fatbar: internal error, not enough LAMs";
   340     fun reLAM ([], U) t = t
   341       | reLAM (T::Ts, U) t = reLAM (Ts, T ->> U) (cabs_const(T,U)$Abs("",T,t));
   342     val msum = foldr1 mk_mplus (map (unLAM arity) ms);
   343     val (Ts, U) = LAM_Ts arity (hd ms)
   344   in
   345     reLAM (rev Ts, dest_maybeT U) (mk_run msum)
   346   end;
   347 
   348 (* this is the pattern-matching compiler function *)
   349 fun compile_pats match_name eqs =
   350   let
   351     val (((n::names),(a::arities)),mats) =
   352       apfst ListPair.unzip (ListPair.unzip (map (match_eq match_name) eqs));
   353     val cname = if forall (fn x => n=x) names then n
   354           else fixrec_err "all equations in block must define the same function";
   355     val arity = if forall (fn x => a=x) arities then a
   356           else fixrec_err "all equations in block must have the same arity";
   357     val rhs = fatbar arity mats;
   358   in
   359     mk_trp (cname === rhs)
   360   end;
   361 
   362 (*************************************************************************)
   363 (********************** Proving associated theorems **********************)
   364 (*************************************************************************)
   365 
   366 structure FixrecSimpData = GenericDataFun (
   367   type T = simpset;
   368   val empty =
   369     HOL_basic_ss
   370       addsimps simp_thms
   371       addsimps [@{thm beta_cfun}]
   372       addsimprocs [@{simproc cont_proc}];
   373   val copy = I;
   374   val extend = I;
   375   val merge = K merge_ss;
   376 );
   377 
   378 fun fixrec_simp_tac ctxt =
   379   let
   380     val tab = FixrecUnfoldData.get (Context.Proof ctxt);
   381     val ss = FixrecSimpData.get (Context.Proof ctxt);
   382     (* TODO: fail gracefully if t has the wrong form *)
   383     fun concl t =
   384       if Logic.is_all t then concl (snd (Logic.dest_all t))
   385       else HOLogic.dest_Trueprop (Logic.strip_imp_concl t);
   386     fun unfold_thm t =
   387       case chead_of (fst (HOLogic.dest_eq (concl t))) of
   388         Const (c, T) => Symtab.lookup tab c
   389       | t => NONE;
   390     fun tac (t, i) =
   391       case unfold_thm t of
   392         SOME thm => rtac (thm RS @{thm ssubst_lhs}) i THEN
   393                          asm_simp_tac ss i
   394       | NONE => asm_simp_tac ss i;
   395   in
   396     SUBGOAL tac
   397   end;
   398 
   399 val add_fixrec_simp : Thm.attribute =
   400   Thm.declaration_attribute
   401     (fn th => FixrecSimpData.map (fn ss => ss addsimps [th]));
   402 
   403 val del_fixrec_simp : Thm.attribute =
   404   Thm.declaration_attribute
   405     (fn th => FixrecSimpData.map (fn ss => ss delsimps [th]));
   406 
   407 (* proves a block of pattern matching equations as theorems, using unfold *)
   408 fun make_simps ctxt (unfold_thm, eqns : (Attrib.binding * term) list) =
   409   let
   410     val tacs =
   411       [rtac (unfold_thm RS @{thm ssubst_lhs}) 1,
   412        asm_simp_tac (simpset_of ctxt) 1];
   413     fun prove_term t = Goal.prove ctxt [] [] t (K (EVERY tacs));
   414     fun prove_eqn (bind, eqn_t) = (bind, prove_term eqn_t);
   415   in
   416     map prove_eqn eqns
   417   end;
   418 
   419 (*************************************************************************)
   420 (************************* Main fixrec function **************************)
   421 (*************************************************************************)
   422 
   423 local
   424 (* code adapted from HOL/Tools/primrec.ML *)
   425 
   426 fun gen_fixrec
   427   (set_group : bool)
   428   prep_spec
   429   (strict : bool)
   430   raw_fixes
   431   raw_spec
   432   (lthy : local_theory) =
   433   let
   434     val (fixes : ((binding * typ) * mixfix) list,
   435          spec : (Attrib.binding * term) list) =
   436           fst (prep_spec raw_fixes raw_spec lthy);
   437     val chead_of_spec =
   438       chead_of o fst o dest_eqs o Logic.strip_imp_concl o strip_alls o snd;
   439     fun name_of (Free (n, _)) = n
   440       | name_of t = fixrec_err ("unknown term");
   441     val all_names = map (name_of o chead_of_spec) spec;
   442     val names = distinct (op =) all_names;
   443     fun block_of_name n =
   444       map_filter
   445         (fn (m,eq) => if m = n then SOME eq else NONE)
   446         (all_names ~~ spec);
   447     val blocks = map block_of_name names;
   448 
   449     val matcher_tab = FixrecMatchData.get (ProofContext.theory_of lthy);
   450     fun match_name c =
   451       case Symtab.lookup matcher_tab c of SOME m => m
   452         | NONE => fixrec_err ("unknown pattern constructor: " ^ c);
   453 
   454     val matches = map (compile_pats match_name) (map (map snd) blocks);
   455     val spec' = map (pair Attrib.empty_binding) matches;
   456     val (lthy', cnames, fixdef_thms, unfold_thms) =
   457       add_fixdefs fixes spec' lthy;
   458   in
   459     if strict then let (* only prove simp rules if strict = true *)
   460       val simps : (Attrib.binding * thm) list list =
   461         map (make_simps lthy') (unfold_thms ~~ blocks);
   462       fun mk_bind n : Attrib.binding =
   463        (Binding.name (n ^ "_simps"),
   464          [Attrib.internal (K Simplifier.simp_add)]);
   465       val simps1 : (Attrib.binding * thm list) list =
   466         map (fn (n,xs) => (mk_bind n, map snd xs)) (names ~~ simps);
   467       val simps2 : (Attrib.binding * thm list) list =
   468         map (apsnd (fn thm => [thm])) (flat simps);
   469       val (_, lthy'') = lthy'
   470         |> fold_map (LocalTheory.note Thm.generatedK) (simps1 @ simps2);
   471     in
   472       lthy''
   473     end
   474     else lthy'
   475   end;
   476 
   477 in
   478 
   479 val add_fixrec = gen_fixrec false Specification.check_spec;
   480 val add_fixrec_cmd = gen_fixrec true Specification.read_spec;
   481 
   482 end; (* local *)
   483 
   484 (*************************************************************************)
   485 (******************************** Fixpat *********************************)
   486 (*************************************************************************)
   487 
   488 fun fix_pat thy t = 
   489   let
   490     val T = fastype_of t;
   491     val eq = mk_trp (HOLogic.eq_const T $ t $ Var (("x",0),T));
   492     val cname = case chead_of t of Const(c,_) => c | _ =>
   493               fixrec_err "function is not declared as constant in theory";
   494     val unfold_thm = PureThy.get_thm thy (cname^"_unfold");
   495     val simp = Goal.prove_global thy [] [] eq
   496           (fn _ => EVERY [stac unfold_thm 1, simp_tac (global_simpset_of thy) 1]);
   497   in simp end;
   498 
   499 fun gen_add_fixpat prep_term prep_attrib ((name, srcs), strings) thy =
   500   let
   501     val atts = map (prep_attrib thy) srcs;
   502     val ts = map (prep_term thy) strings;
   503     val simps = map (fix_pat thy) ts;
   504   in
   505     (snd o PureThy.add_thmss [((name, simps), atts)]) thy
   506   end;
   507 
   508 val add_fixpat = gen_add_fixpat Sign.cert_term (K I);
   509 val add_fixpat_cmd = gen_add_fixpat Syntax.read_term_global Attrib.attribute;
   510 
   511 
   512 (*************************************************************************)
   513 (******************************** Parsers ********************************)
   514 (*************************************************************************)
   515 
   516 local structure P = OuterParse and K = OuterKeyword in
   517 
   518 val _ = OuterSyntax.local_theory "fixrec" "define recursive functions (HOLCF)" K.thy_decl
   519   ((P.opt_keyword "permissive" >> not) -- P.fixes -- SpecParse.where_alt_specs
   520     >> (fn ((strict, fixes), specs) => add_fixrec_cmd strict fixes specs));
   521 
   522 val _ = OuterSyntax.command "fixpat" "define rewrites for fixrec functions" K.thy_decl
   523   (SpecParse.specs >> (Toplevel.theory o add_fixpat_cmd));
   524 
   525 end;
   526 
   527 val setup =
   528   FixrecMatchData.init
   529   #> Attrib.setup @{binding fixrec_simp}
   530                      (Attrib.add_del add_fixrec_simp del_fixrec_simp)
   531                      "declaration of fixrec simp rule"
   532   #> Method.setup @{binding fixrec_simp}
   533                      (Scan.succeed (SIMPLE_METHOD' o fixrec_simp_tac))
   534                      "pattern prover for fixrec constants";
   535 
   536 end;