author | wenzelm |
Wed, 04 Mar 2015 19:53:18 +0100 | |
changeset 59582 | 0fbed69ff081 |
parent 58993 | 302104d8366b |
child 59618 | e6939796717e |
permissions | -rw-r--r-- |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
1 |
(* Title: HOL/Tools/Function/fun_cases.ML |
53609 | 2 |
Author: Manuel Eberl, TU Muenchen |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
3 |
|
53993 | 4 |
The fun_cases command for generating specialised elimination rules for |
5 |
function package functions. |
|
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
6 |
*) |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
7 |
|
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
8 |
signature FUN_CASES = |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
9 |
sig |
53993 | 10 |
val mk_fun_cases: Proof.context -> term -> thm |
11 |
val fun_cases: (Attrib.binding * term list) list -> local_theory -> |
|
53995 | 12 |
(string * thm list) list * local_theory |
53993 | 13 |
val fun_cases_cmd: (Attrib.binding * string list) list -> local_theory -> |
53995 | 14 |
(string * thm list) list * local_theory |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
15 |
end; |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
16 |
|
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
17 |
structure Fun_Cases : FUN_CASES = |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
18 |
struct |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
19 |
|
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
20 |
fun mk_fun_cases ctxt prop = |
53992 | 21 |
let |
22 |
val thy = Proof_Context.theory_of ctxt; |
|
23 |
fun err () = |
|
24 |
error (Pretty.string_of (Pretty.block |
|
25 |
[Pretty.str "Proposition is not a function equation:", |
|
26 |
Pretty.fbrk, Syntax.pretty_term ctxt prop])); |
|
27 |
val ((f, _), _) = |
|
28 |
Function_Elims.dest_funprop (HOLogic.dest_Trueprop prop) |
|
29 |
handle TERM _ => err (); |
|
30 |
val info = Function.get_info ctxt f handle List.Empty => err (); |
|
31 |
val {elims, pelims, is_partial, ...} = info; |
|
32 |
val elims = if is_partial then pelims else the elims; |
|
59582 | 33 |
val cprop = Thm.cterm_of thy prop; |
53992 | 34 |
fun mk_elim rl = |
53994 | 35 |
Thm.implies_intr cprop |
36 |
(Tactic.rule_by_tactic ctxt (Inductive.mk_cases_tac ctxt) (Thm.assume cprop RS rl)) |
|
53992 | 37 |
|> singleton (Variable.export (Variable.auto_fixes prop ctxt) ctxt); |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
38 |
in |
53992 | 39 |
(case get_first (try mk_elim) (flat elims) of |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
40 |
SOME r => r |
53992 | 41 |
| NONE => err ()) |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
42 |
end; |
53666 | 43 |
|
53991
d8f7f3d998de
provide regular ML interface and use plain Syntax.read_prop/Syntax.check_prop (update by Manuel Eberl);
wenzelm
parents:
53670
diff
changeset
|
44 |
fun gen_fun_cases prep_att prep_prop args lthy = |
53667
0aefb31e27e0
distinguish Proof.context vs. local_theory semantically, with corresponding naming conventions;
wenzelm
parents:
53666
diff
changeset
|
45 |
let |
53991
d8f7f3d998de
provide regular ML interface and use plain Syntax.read_prop/Syntax.check_prop (update by Manuel Eberl);
wenzelm
parents:
53670
diff
changeset
|
46 |
val thmss = |
d8f7f3d998de
provide regular ML interface and use plain Syntax.read_prop/Syntax.check_prop (update by Manuel Eberl);
wenzelm
parents:
53670
diff
changeset
|
47 |
map snd args |
58993
302104d8366b
prefer independent parallel map where user input is processed -- avoid non-deterministic feedback in error situations;
wenzelm
parents:
55997
diff
changeset
|
48 |
|> burrow (grouped 10 Par_List.map_independent (mk_fun_cases lthy o prep_prop lthy)); |
53991
d8f7f3d998de
provide regular ML interface and use plain Syntax.read_prop/Syntax.check_prop (update by Manuel Eberl);
wenzelm
parents:
53670
diff
changeset
|
49 |
val facts = |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
53995
diff
changeset
|
50 |
map2 (fn ((a, atts), _) => fn thms => ((a, map (prep_att lthy) atts), [(thms, [])])) |
53991
d8f7f3d998de
provide regular ML interface and use plain Syntax.read_prop/Syntax.check_prop (update by Manuel Eberl);
wenzelm
parents:
53670
diff
changeset
|
51 |
args thmss; |
53995 | 52 |
in lthy |> Local_Theory.notes facts end; |
53670 | 53 |
|
53993 | 54 |
val fun_cases = gen_fun_cases (K I) Syntax.check_prop; |
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
53995
diff
changeset
|
55 |
val fun_cases_cmd = gen_fun_cases Attrib.check_src Syntax.read_prop; |
53667
0aefb31e27e0
distinguish Proof.context vs. local_theory semantically, with corresponding naming conventions;
wenzelm
parents:
53666
diff
changeset
|
56 |
|
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
57 |
val _ = |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
58 |
Outer_Syntax.local_theory @{command_spec "fun_cases"} |
53995 | 59 |
"create simplified instances of elimination rules for function equations" |
53993 | 60 |
(Parse.and_list1 Parse_Spec.specs >> (snd oo fun_cases_cmd)); |
53666 | 61 |
|
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
62 |
end; |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
diff
changeset
|
63 |