src/HOL/Tools/Function/partial_function.ML
author wenzelm
Tue, 04 Jun 2019 20:01:02 +0200
changeset 70325 9bf04a8f211f
parent 70324 005c1cdbfd3f
child 71179 592e2afdd50c
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
     1
(*  Title:      HOL/Tools/Function/partial_function.ML
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
     2
    Author:     Alexander Krauss, TU Muenchen
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
     3
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
     4
Partial function definitions based on least fixed points in ccpos.
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
     5
*)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
     6
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
     7
signature PARTIAL_FUNCTION =
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
     8
sig
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
     9
  val init: string -> term -> term -> thm -> thm -> thm option -> declaration
52727
ce51d6eb8f3d export mono_thm
krauss
parents: 52521
diff changeset
    10
  val mono_tac: Proof.context -> int -> tactic
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    11
  val add_partial_function: string -> (binding * typ option * mixfix) list ->
66653
52bf9f67a3c9 clarified signature: proper result;
wenzelm
parents: 63285
diff changeset
    12
    Attrib.binding * term -> local_theory -> (term * thm) * local_theory
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    13
  val add_partial_function_cmd: string -> (binding * string option * mixfix) list ->
66653
52bf9f67a3c9 clarified signature: proper result;
wenzelm
parents: 63285
diff changeset
    14
    Attrib.binding * string -> local_theory -> (term * thm) * local_theory
69829
3bfa28b3a5b2 streamlined specification interfaces
haftmann
parents: 69593
diff changeset
    15
  val transform_result: morphism -> term * thm -> term * thm
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    16
end;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    17
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    18
structure Partial_Function: PARTIAL_FUNCTION =
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    19
struct
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    20
63005
d743bb1b6c23 clarified bindings;
wenzelm
parents: 63003
diff changeset
    21
open Function_Lib
d743bb1b6c23 clarified bindings;
wenzelm
parents: 63003
diff changeset
    22
d743bb1b6c23 clarified bindings;
wenzelm
parents: 63003
diff changeset
    23
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    24
(*** Context Data ***)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    25
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    26
datatype setup_data = Setup_Data of
43080
73a1d6a7ef1d also manage induction rule;
krauss
parents: 42949
diff changeset
    27
 {fixp: term,
73a1d6a7ef1d also manage induction rule;
krauss
parents: 42949
diff changeset
    28
  mono: term,
73a1d6a7ef1d also manage induction rule;
krauss
parents: 42949
diff changeset
    29
  fixp_eq: thm,
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
    30
  fixp_induct: thm,
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
    31
  fixp_induct_user: thm option};
43080
73a1d6a7ef1d also manage induction rule;
krauss
parents: 42949
diff changeset
    32
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    33
fun transform_setup_data phi (Setup_Data {fixp, mono, fixp_eq, fixp_induct, fixp_induct_user}) =
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    34
  let
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    35
    val term = Morphism.term phi;
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    36
    val thm = Morphism.thm phi;
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    37
  in
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    38
    Setup_Data
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    39
     {fixp = term fixp, mono = term mono, fixp_eq = thm fixp_eq,
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    40
      fixp_induct = thm fixp_induct, fixp_induct_user = Option.map thm fixp_induct_user}
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    41
  end;
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    42
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    43
structure Modes = Generic_Data
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    44
(
43080
73a1d6a7ef1d also manage induction rule;
krauss
parents: 42949
diff changeset
    45
  type T = setup_data Symtab.table;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    46
  val empty = Symtab.empty;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    47
  val extend = I;
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41117
diff changeset
    48
  fun merge data = Symtab.merge (K true) data;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    49
)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    50
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
    51
fun init mode fixp mono fixp_eq fixp_induct fixp_induct_user phi =
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    52
  let
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    53
    val data' =
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    54
      Setup_Data
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    55
       {fixp = fixp, mono = mono, fixp_eq = fixp_eq,
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    56
        fixp_induct = fixp_induct, fixp_induct_user = fixp_induct_user}
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    57
      |> transform_setup_data (phi $> Morphism.trim_context_morphism);
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    58
  in Modes.map (Symtab.update (mode, data')) end;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    59
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    60
val known_modes = Symtab.keys o Modes.get o Context.Proof;
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    61
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    62
fun lookup_mode ctxt =
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
    63
  Symtab.lookup (Modes.get (Context.Proof ctxt))
67664
ad2b3e330c27 tuned signature;
wenzelm
parents: 67149
diff changeset
    64
  #> Option.map (transform_setup_data (Morphism.transfer_morphism' ctxt));
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    65
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    66
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    67
(*** Automated monotonicity proofs ***)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    68
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    69
(*rewrite conclusion with k-th assumtion*)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    70
fun rewrite_with_asm_tac ctxt k =
45403
wenzelm
parents: 45294
diff changeset
    71
  Subgoal.FOCUS (fn {context = ctxt', prems, ...} =>
63170
eae6549dbea2 tuned proofs, to allow unfold_abs_def;
wenzelm
parents: 63064
diff changeset
    72
    Local_Defs.unfold0_tac ctxt' [nth prems k]) ctxt;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    73
54405
88f6d5b1422f ported 'partial_function' to 'Ctr_Sugar' abstraction
blanchet
parents: 52728
diff changeset
    74
fun dest_case ctxt t =
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    75
  case strip_comb t of
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    76
    (Const (case_comb, _), args) =>
54405
88f6d5b1422f ported 'partial_function' to 'Ctr_Sugar' abstraction
blanchet
parents: 52728
diff changeset
    77
      (case Ctr_Sugar.ctr_sugar_of_case ctxt case_comb of
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    78
         NONE => NONE
54405
88f6d5b1422f ported 'partial_function' to 'Ctr_Sugar' abstraction
blanchet
parents: 52728
diff changeset
    79
       | SOME {case_thms, ...} =>
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    80
           let
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59580
diff changeset
    81
             val lhs = Thm.prop_of (hd case_thms)
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    82
               |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> fst;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    83
             val arity = length (snd (strip_comb lhs));
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    84
             val conv = funpow (length args - arity) Conv.fun_conv
54405
88f6d5b1422f ported 'partial_function' to 'Ctr_Sugar' abstraction
blanchet
parents: 52728
diff changeset
    85
               (Conv.rewrs_conv (map mk_meta_eq case_thms));
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    86
           in
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    87
             SOME (nth args (arity - 1), conv)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    88
           end)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    89
  | _ => NONE;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    90
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    91
(*split on case expressions*)
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58839
diff changeset
    92
val split_cases_tac = Subgoal.FOCUS_PARAMS (fn {context = ctxt, ...} =>
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    93
  SUBGOAL (fn (t, i) => case t of
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    94
    _ $ (_ $ Abs (_, _, body)) =>
54405
88f6d5b1422f ported 'partial_function' to 'Ctr_Sugar' abstraction
blanchet
parents: 52728
diff changeset
    95
      (case dest_case ctxt body of
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    96
         NONE => no_tac
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    97
       | SOME (arg, conv) =>
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
    98
           let open Conv in
42083
e1209fc7ecdc added Term.is_open and Term.is_dependent convenience, to cover common situations of loose bounds;
wenzelm
parents: 41472
diff changeset
    99
              if Term.is_open arg then no_tac
61844
007d3b34080f tuned signature;
wenzelm
parents: 61841
diff changeset
   100
              else ((DETERM o Induct.cases_tac ctxt false [[SOME arg]] NONE [])
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   101
                THEN_ALL_NEW (rewrite_with_asm_tac ctxt 0)
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58839
diff changeset
   102
                THEN_ALL_NEW eresolve_tac ctxt @{thms thin_rl}
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   103
                THEN_ALL_NEW (CONVERSION
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   104
                  (params_conv ~1 (fn ctxt' =>
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   105
                    arg_conv (arg_conv (abs_conv (K conv) ctxt'))) ctxt))) i
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   106
           end)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   107
  | _ => no_tac) 1);
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   108
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   109
(*monotonicity proof: apply rules + split case expressions*)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   110
fun mono_tac ctxt =
63170
eae6549dbea2 tuned proofs, to allow unfold_abs_def;
wenzelm
parents: 63064
diff changeset
   111
  K (Local_Defs.unfold0_tac ctxt [@{thm curry_def}])
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   112
  THEN' (TRY o REPEAT_ALL_NEW
67149
e61557884799 prefer control symbol antiquotations;
wenzelm
parents: 66653
diff changeset
   113
   (resolve_tac ctxt (rev (Named_Theorems.get ctxt \<^named_theorems>\<open>partial_function_mono\<close>))
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   114
     ORELSE' split_cases_tac ctxt));
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   115
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   116
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   117
(*** Auxiliary functions ***)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   118
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   119
(*Returns t $ u, but instantiates the type of t to make the
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   120
application type correct*)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   121
fun apply_inst ctxt t u =
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   122
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42083
diff changeset
   123
    val thy = Proof_Context.theory_of ctxt;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   124
    val T = domain_type (fastype_of t);
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   125
    val T' = fastype_of u;
42388
a44b0fdaa6c2 standardized aliases of operations on tsig;
wenzelm
parents: 42361
diff changeset
   126
    val subst = Sign.typ_match thy (T, T') Vartab.empty
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   127
      handle Type.TYPE_MATCH => raise TYPE ("apply_inst", [T, T'], [t, u])
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   128
  in
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   129
    map_types (Envir.norm_type subst) t $ u
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   130
  end;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   131
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   132
fun head_conv cv ct =
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   133
  if can Thm.dest_comb ct then Conv.fun_conv (head_conv cv) ct else cv ct;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   134
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   135
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   136
(*** currying transformation ***)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   137
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   138
fun curry_const (A, B, C) =
67149
e61557884799 prefer control symbol antiquotations;
wenzelm
parents: 66653
diff changeset
   139
  Const (\<^const_name>\<open>Product_Type.curry\<close>,
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   140
    [HOLogic.mk_prodT (A, B) --> C, A, B] ---> C);
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   141
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   142
fun mk_curry f =
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   143
  case fastype_of f of
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   144
    Type ("fun", [Type (_, [S, T]), U]) =>
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   145
      curry_const (S, T, U) $ f
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   146
  | T => raise TYPE ("mk_curry", [T], [f]);
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   147
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   148
(* iterated versions. Nonstandard left-nested tuples arise naturally
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   149
from "split o split o split"*)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   150
fun curry_n arity = funpow (arity - 1) mk_curry;
61424
c3658c18b7bc prod_case as canonical name for product type eliminator
haftmann
parents: 61121
diff changeset
   151
fun uncurry_n arity = funpow (arity - 1) HOLogic.mk_case_prod;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   152
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51484
diff changeset
   153
val curry_uncurry_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67664
diff changeset
   154
  simpset_of (put_simpset HOL_basic_ss \<^context>
61424
c3658c18b7bc prod_case as canonical name for product type eliminator
haftmann
parents: 61121
diff changeset
   155
    addsimps [@{thm Product_Type.curry_case_prod}, @{thm Product_Type.case_prod_curry}])
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   156
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51484
diff changeset
   157
val split_conv_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67664
diff changeset
   158
  simpset_of (put_simpset HOL_basic_ss \<^context>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51484
diff changeset
   159
    addsimps [@{thm Product_Type.split_conv}]);
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   160
54630
9061af4d5ebc restrict admissibility to non-empty chains to allow more syntax-directed proof rules
Andreas Lochbihler
parents: 54405
diff changeset
   161
val curry_K_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 67664
diff changeset
   162
  simpset_of (put_simpset HOL_basic_ss \<^context>
54630
9061af4d5ebc restrict admissibility to non-empty chains to allow more syntax-directed proof rules
Andreas Lochbihler
parents: 54405
diff changeset
   163
    addsimps [@{thm Product_Type.curry_K}]);
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   164
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   165
(* instantiate generic fixpoint induction and eliminate the canonical assumptions;
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   166
  curry induction predicate *)
70325
wenzelm
parents: 70324
diff changeset
   167
fun specialize_fixp_induct ctxt fT fT_uc curry uncurry mono_thm f_def rule =
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   168
  let
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   169
    val ([P], ctxt') = Variable.variant_fixes ["P"] ctxt
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   170
    val P_inst = Abs ("f", fT_uc, Free (P, fT --> HOLogic.boolT) $ (curry $ Bound 0))
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
   171
  in
70324
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   172
    (* FIXME ctxt vs. ctxt' (!?) *)
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   173
    rule
70324
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   174
    |> infer_instantiate' ctxt
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   175
      ((map o Option.map) (Thm.cterm_of ctxt) [SOME uncurry, NONE, SOME curry, NONE, SOME P_inst])
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   176
    |> Tactic.rule_by_tactic ctxt
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   177
      (Simplifier.simp_tac (put_simpset curry_uncurry_ss ctxt) 3 (* discharge U (C f) = f *)
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   178
       THEN Simplifier.simp_tac (put_simpset curry_K_ss ctxt) 4 (* simplify bot case *)
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   179
       THEN Simplifier.full_simp_tac (put_simpset curry_uncurry_ss ctxt) 5) (* simplify induction step *)
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   180
    |> (fn thm => thm OF [mono_thm, f_def])
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   181
    |> Conv.fconv_rule (Conv.concl_conv ~1    (* simplify conclusion *)
70324
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   182
         (Raw_Simplifier.rewrite ctxt false [mk_meta_eq @{thm Product_Type.curry_case_prod}]))
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   183
    |> singleton (Variable.export ctxt' ctxt)
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   184
  end
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   185
52727
ce51d6eb8f3d export mono_thm
krauss
parents: 52521
diff changeset
   186
fun mk_curried_induct args ctxt inst_rule =
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   187
  let
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59582
diff changeset
   188
    val cert = Thm.cterm_of ctxt
70325
wenzelm
parents: 70324
diff changeset
   189
    (* FIXME ctxt vs. ctxt' (!?) *)
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   190
    val ([P], ctxt') = Variable.variant_fixes ["P"] ctxt
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   191
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   192
    val split_paired_all_conv =
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   193
      Conv.every_conv (replicate (length args - 1) (Conv.rewr_conv @{thm split_paired_all}))
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   194
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
   195
    val split_params_conv =
70325
wenzelm
parents: 70324
diff changeset
   196
      Conv.params_conv ~1 (fn _ => Conv.implies_conv split_paired_all_conv Conv.all_conv)
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   197
52521
a1c4f586e372 more robust instantiation: extract vars from conclusion instead of relying on fixed overall ordering
krauss
parents: 52087
diff changeset
   198
    val (P_var, x_var) =
51484
49eb8d73ae10 allow induction predicates with arbitrary arity (not just binary)
krauss
parents: 46961
diff changeset
   199
       Thm.prop_of inst_rule |> Logic.strip_imp_concl |> HOLogic.dest_Trueprop
52521
a1c4f586e372 more robust instantiation: extract vars from conclusion instead of relying on fixed overall ordering
krauss
parents: 52087
diff changeset
   200
      |> strip_comb |> apsnd hd
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 59936
diff changeset
   201
      |> apply2 dest_Var
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 59936
diff changeset
   202
    val P_rangeT = range_type (snd P_var)
51484
49eb8d73ae10 allow induction predicates with arbitrary arity (not just binary)
krauss
parents: 46961
diff changeset
   203
    val PT = map (snd o dest_Free) args ---> P_rangeT
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   204
    val x_inst = cert (foldl1 HOLogic.mk_prod args)
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   205
    val P_inst = cert (uncurry_n (length args) (Free (P, PT)))
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   206
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   207
    val inst_rule' = inst_rule
70324
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   208
      |> Tactic.rule_by_tactic ctxt
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   209
        (Simplifier.simp_tac (put_simpset curry_uncurry_ss ctxt) 4
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   210
         THEN Simplifier.simp_tac (put_simpset curry_uncurry_ss ctxt) 3
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   211
         THEN CONVERSION (split_params_conv ctxt
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   212
           then_conv (Conv.forall_conv (K split_paired_all_conv) ctxt)) 3)
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 59936
diff changeset
   213
      |> Thm.instantiate ([], [(P_var, P_inst), (x_var, x_inst)])
70324
005c1cdbfd3f backout 34bc296374ee -- affects the raw_induct rule, e.g. relevant for AFP/Imperative_Insertion_Sort;
wenzelm
parents: 70319
diff changeset
   214
      |> Simplifier.full_simplify (put_simpset split_conv_ss ctxt)
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   215
      |> singleton (Variable.export ctxt' ctxt)
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   216
  in
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   217
    inst_rule'
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   218
  end;
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
   219
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   220
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   221
(*** partial_function definition ***)
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   222
69829
3bfa28b3a5b2 streamlined specification interfaces
haftmann
parents: 69593
diff changeset
   223
fun transform_result phi (t, thm) = (Morphism.term phi t, Morphism.thm phi thm);
3bfa28b3a5b2 streamlined specification interfaces
haftmann
parents: 69593
diff changeset
   224
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   225
fun gen_add_partial_function prep mode fixes_raw eqn_raw lthy =
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   226
  let
43080
73a1d6a7ef1d also manage induction rule;
krauss
parents: 42949
diff changeset
   227
    val setup_data = the (lookup_mode lthy mode)
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   228
      handle Option.Option => error (cat_lines ["Unknown mode " ^ quote mode ^ ".",
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   229
        "Known modes are " ^ commas_quote (known_modes lthy) ^ "."]);
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   230
    val Setup_Data {fixp, mono, fixp_eq, fixp_induct, fixp_induct_user} = setup_data;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   231
63182
b065b4833092 allow 'for' fixes for multi_specs;
wenzelm
parents: 63170
diff changeset
   232
    val ((fixes, [(eq_abinding, eqn)]), _) = prep fixes_raw [(eqn_raw, [], [])] lthy;
60695
757549b4bbe6 Variable.focus etc.: optional bindings provided by user;
wenzelm
parents: 60642
diff changeset
   233
    val ((_, plain_eqn), args_ctxt) = Variable.focus NONE eqn lthy;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   234
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   235
    val ((f_binding, fT), mixfix) = the_single fixes;
62997
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   236
    val f_bname = Binding.name_of f_binding;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   237
62998
36d7e7f1805c clarified reported positions;
wenzelm
parents: 62997
diff changeset
   238
    fun note_qualified (name, thms) =
63005
d743bb1b6c23 clarified bindings;
wenzelm
parents: 63003
diff changeset
   239
      Local_Theory.note ((derived_name f_binding name, []), thms) #> snd
62998
36d7e7f1805c clarified reported positions;
wenzelm
parents: 62997
diff changeset
   240
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   241
    val (lhs, rhs) = HOLogic.dest_eq (HOLogic.dest_Trueprop plain_eqn);
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   242
    val (head, args) = strip_comb lhs;
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   243
    val argnames = map (fst o dest_Free) args;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   244
    val F = fold_rev lambda (head :: args) rhs;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   245
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   246
    val arity = length args;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   247
    val (aTs, bTs) = chop arity (binder_types fT);
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   248
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   249
    val tupleT = foldl1 HOLogic.mk_prodT aTs;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   250
    val fT_uc = tupleT :: bTs ---> body_type fT;
62997
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   251
    val f_uc = Var ((f_bname, 0), fT_uc);
63008
b577a13a15f3 avoid clash with function called "x";
wenzelm
parents: 63005
diff changeset
   252
    val x_uc = Var (("x", 1), tupleT);
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   253
    val uncurry = lambda head (uncurry_n arity head);
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   254
    val curry = lambda f_uc (curry_n arity f_uc);
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   255
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   256
    val F_uc =
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   257
      lambda f_uc (uncurry_n arity (F $ curry_n arity f_uc));
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   258
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   259
    val mono_goal = apply_inst lthy mono (lambda f_uc (F_uc $ f_uc $ x_uc))
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   260
      |> HOLogic.mk_Trueprop
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   261
      |> Logic.all x_uc;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   262
60784
4f590c08fd5d updated to infer_instantiate;
wenzelm
parents: 60695
diff changeset
   263
    val mono_thm = Goal.prove_internal lthy [] (Thm.cterm_of lthy mono_goal)
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   264
        (K (mono_tac lthy 1))
60784
4f590c08fd5d updated to infer_instantiate;
wenzelm
parents: 60695
diff changeset
   265
    val inst_mono_thm = Thm.forall_elim (Thm.cterm_of lthy x_uc) mono_thm
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   266
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   267
    val f_def_rhs = curry_n arity (apply_inst lthy fixp F_uc);
61121
efe8b18306b7 do not expose low-level "_def" facts of 'function' definitions, to avoid potential confusion with the situation of plain 'definition';
wenzelm
parents: 61113
diff changeset
   268
    val f_def_binding =
62997
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   269
      Thm.make_def_binding (Config.get lthy Function_Lib.function_internals) f_binding
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   270
    val ((f, (_, f_def)), lthy') =
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   271
      Local_Theory.define ((f_binding, mixfix), ((f_def_binding, []), f_def_rhs)) lthy;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   272
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   273
    val eqn = HOLogic.mk_eq (list_comb (f, args),
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   274
        Term.betapplys (F, f :: args))
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   275
      |> HOLogic.mk_Trueprop;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   276
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   277
    val unfold =
60784
4f590c08fd5d updated to infer_instantiate;
wenzelm
parents: 60695
diff changeset
   278
      (infer_instantiate' lthy' (map (SOME o Thm.cterm_of lthy') [uncurry, F, curry]) fixp_eq
52727
ce51d6eb8f3d export mono_thm
krauss
parents: 52521
diff changeset
   279
        OF [inst_mono_thm, f_def])
52087
f3075fc4f5f6 more precise treatment of theory vs. Proof.context;
wenzelm
parents: 51717
diff changeset
   280
      |> Tactic.rule_by_tactic lthy' (Simplifier.simp_tac (put_simpset curry_uncurry_ss lthy') 1);
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   281
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
   282
    val specialized_fixp_induct =
70325
wenzelm
parents: 70324
diff changeset
   283
      specialize_fixp_induct lthy' fT fT_uc curry uncurry inst_mono_thm f_def fixp_induct
62997
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   284
      |> Drule.rename_bvars' (map SOME (f_bname :: f_bname :: argnames));
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   285
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   286
    val mk_raw_induct =
60784
4f590c08fd5d updated to infer_instantiate;
wenzelm
parents: 60695
diff changeset
   287
      infer_instantiate' args_ctxt
4f590c08fd5d updated to infer_instantiate;
wenzelm
parents: 60695
diff changeset
   288
        ((map o Option.map) (Thm.cterm_of args_ctxt) [SOME uncurry, NONE, SOME curry])
52727
ce51d6eb8f3d export mono_thm
krauss
parents: 52521
diff changeset
   289
      #> mk_curried_induct args args_ctxt
52087
f3075fc4f5f6 more precise treatment of theory vs. Proof.context;
wenzelm
parents: 51717
diff changeset
   290
      #> singleton (Variable.export args_ctxt lthy')
60784
4f590c08fd5d updated to infer_instantiate;
wenzelm
parents: 60695
diff changeset
   291
      #> (fn thm => infer_instantiate' lthy'
4f590c08fd5d updated to infer_instantiate;
wenzelm
parents: 60695
diff changeset
   292
          [SOME (Thm.cterm_of lthy' F)] thm OF [inst_mono_thm, f_def])
62997
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   293
      #> Drule.rename_bvars' (map SOME (f_bname :: argnames @ argnames))
43083
df41a5762c3d generate raw induction rule as instance of generic rule with careful treatment of currying
krauss
parents: 43080
diff changeset
   294
52728
470b579f35d2 derive specialized version of full fixpoint induction (with admissibility)
krauss
parents: 52727
diff changeset
   295
    val raw_induct = Option.map mk_raw_induct fixp_induct_user
62997
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   296
    val rec_rule =
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   297
      let open Conv in
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   298
        Goal.prove lthy' (map (fst o dest_Free) args) [] eqn (fn _ =>
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   299
          CONVERSION ((arg_conv o arg1_conv o head_conv o rewr_conv) (mk_meta_eq unfold)) 1
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   300
          THEN resolve_tac lthy' @{thms refl} 1)
dd987efa5df3 operate on proper binding;
wenzelm
parents: 62969
diff changeset
   301
      end;
66653
52bf9f67a3c9 clarified signature: proper result;
wenzelm
parents: 63285
diff changeset
   302
    val ((_, [rec_rule']), lthy'') = lthy' |> Local_Theory.note (eq_abinding, [rec_rule])
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   303
  in
66653
52bf9f67a3c9 clarified signature: proper result;
wenzelm
parents: 63285
diff changeset
   304
    lthy''
69992
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69829
diff changeset
   305
    |> Spec_Rules.add Spec_Rules.equational_recdef ([f], [rec_rule'])
66653
52bf9f67a3c9 clarified signature: proper result;
wenzelm
parents: 63285
diff changeset
   306
    |> note_qualified ("simps", [rec_rule'])
62998
36d7e7f1805c clarified reported positions;
wenzelm
parents: 62997
diff changeset
   307
    |> note_qualified ("mono", [mono_thm])
36d7e7f1805c clarified reported positions;
wenzelm
parents: 62997
diff changeset
   308
    |> (case raw_induct of NONE => I | SOME thm => note_qualified ("raw_induct", [thm]))
36d7e7f1805c clarified reported positions;
wenzelm
parents: 62997
diff changeset
   309
    |> note_qualified ("fixp_induct", [specialized_fixp_induct])
66653
52bf9f67a3c9 clarified signature: proper result;
wenzelm
parents: 63285
diff changeset
   310
    |> pair (f, rec_rule')
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   311
  end;
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   312
63064
2f18172214c8 support 'assumes' in specifications, e.g. 'definition', 'inductive';
wenzelm
parents: 63008
diff changeset
   313
val add_partial_function = gen_add_partial_function Specification.check_multi_specs;
2f18172214c8 support 'assumes' in specifications, e.g. 'definition', 'inductive';
wenzelm
parents: 63008
diff changeset
   314
val add_partial_function_cmd = gen_add_partial_function Specification.read_multi_specs;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   315
67149
e61557884799 prefer control symbol antiquotations;
wenzelm
parents: 66653
diff changeset
   316
val mode = \<^keyword>\<open>(\<close> |-- Parse.name --| \<^keyword>\<open>)\<close>;
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   317
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46949
diff changeset
   318
val _ =
67149
e61557884799 prefer control symbol antiquotations;
wenzelm
parents: 66653
diff changeset
   319
  Outer_Syntax.local_theory \<^command_keyword>\<open>partial_function\<close> "define partial function"
63285
e9c777bfd78c clarified syntax;
wenzelm
parents: 63182
diff changeset
   320
    ((mode -- (Parse.vars -- (Parse.where_ |-- Parse_Spec.simple_spec)))
66653
52bf9f67a3c9 clarified signature: proper result;
wenzelm
parents: 63285
diff changeset
   321
      >> (fn (mode, (vars, spec)) => add_partial_function_cmd mode vars spec #> #2));
40107
374f3ef9f940 first version of partial_function package
krauss
parents:
diff changeset
   322
61113
86049d52155c trim context for persistent storage;
wenzelm
parents: 60784
diff changeset
   323
end;