author | bulwahn |
Mon, 11 May 2009 09:18:42 +0200 | |
changeset 31106 | 9a1178204dc0 |
parent 30878 | 309bfab064e9 |
child 31902 | 862ae16a799d |
permissions | -rw-r--r-- |
30878 | 1 |
(* Title: HOL/Tools/arith_data.ML |
24095 | 2 |
Author: Markus Wenzel, Stefan Berghofer, and Tobias Nipkow |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
3 |
|
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
4 |
Common arithmetic proof auxiliary. |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
5 |
*) |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
6 |
|
26101 | 7 |
signature ARITH_DATA = |
8 |
sig |
|
30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
9 |
val arith_tac: Proof.context -> int -> tactic |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
10 |
val verbose_arith_tac: Proof.context -> int -> tactic |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
11 |
val add_tactic: string -> (bool -> Proof.context -> int -> tactic) -> theory -> theory |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
12 |
val get_arith_facts: Proof.context -> thm list |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
13 |
|
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
14 |
val prove_conv_nohyps: tactic list -> Proof.context -> term * term -> thm option |
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
15 |
val prove_conv: tactic list -> Proof.context -> thm list -> term * term -> thm option |
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
16 |
val prove_conv2: tactic -> (simpset -> tactic) -> simpset -> term * term -> thm |
29302 | 17 |
val simp_all_tac: thm list -> simpset -> tactic |
30518 | 18 |
val simplify_meta_eq: thm list -> simpset -> thm -> thm |
19 |
val trans_tac: thm option -> tactic |
|
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
20 |
val prep_simproc: string * string list * (theory -> simpset -> term -> thm option) |
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
21 |
-> simproc |
30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
22 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
23 |
val setup: theory -> theory |
26101 | 24 |
end; |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
25 |
|
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
26 |
structure Arith_Data: ARITH_DATA = |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
27 |
struct |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
28 |
|
30878 | 29 |
(* slots for plugging in arithmetic facts and tactics *) |
30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
30 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
31 |
structure Arith_Facts = NamedThmsFun( |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
32 |
val name = "arith" |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
33 |
val description = "arith facts - only ground formulas" |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
34 |
); |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
35 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
36 |
val get_arith_facts = Arith_Facts.get; |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
37 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
38 |
structure Arith_Tactics = TheoryDataFun |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
39 |
( |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
40 |
type T = (serial * (string * (bool -> Proof.context -> int -> tactic))) list; |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
41 |
val empty = []; |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
42 |
val copy = I; |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
43 |
val extend = I; |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
44 |
fun merge _ = AList.merge (op =) (K true); |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
45 |
); |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
46 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
47 |
fun add_tactic name tac = Arith_Tactics.map (cons (serial (), (name, tac))); |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
48 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
49 |
fun gen_arith_tac verbose ctxt = |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
50 |
let |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
51 |
val tactics = (Arith_Tactics.get o ProofContext.theory_of) ctxt |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
52 |
fun invoke (_, (name, tac)) k st = (if verbose |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
53 |
then warning ("Trying " ^ name ^ "...") else (); |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
54 |
tac verbose ctxt k st); |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
55 |
in FIRST' (map invoke (rev tactics)) end; |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
56 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
57 |
val arith_tac = gen_arith_tac false; |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
58 |
val verbose_arith_tac = gen_arith_tac true; |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
59 |
|
30722
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30686
diff
changeset
|
60 |
val setup = |
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30686
diff
changeset
|
61 |
Arith_Facts.setup #> |
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30686
diff
changeset
|
62 |
Method.setup @{binding arith} |
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30686
diff
changeset
|
63 |
(Args.bang_facts >> (fn prems => fn ctxt => |
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30686
diff
changeset
|
64 |
METHOD (fn facts => HEADGOAL (Method.insert_tac (prems @ get_arith_facts ctxt @ facts) |
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30686
diff
changeset
|
65 |
THEN' verbose_arith_tac ctxt)))) |
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30686
diff
changeset
|
66 |
"various arithmetic decision procedures"; |
30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
67 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
68 |
|
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
69 |
(* various auxiliary and legacy *) |
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
haftmann
parents:
30518
diff
changeset
|
70 |
|
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
71 |
fun prove_conv_nohyps tacs ctxt (t, u) = |
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
72 |
if t aconv u then NONE |
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
73 |
else let val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u)) |
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
74 |
in SOME (Goal.prove ctxt [] [] eq (K (EVERY tacs))) end; |
26101 | 75 |
|
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
76 |
fun prove_conv tacs ctxt (_: thm list) = prove_conv_nohyps tacs ctxt; |
26101 | 77 |
|
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
78 |
fun prove_conv2 expand_tac norm_tac ss tu = (*FIXME avoid standard*) |
26101 | 79 |
mk_meta_eq (standard (Goal.prove (Simplifier.the_context ss) [] [] |
80 |
(HOLogic.mk_Trueprop (HOLogic.mk_eq tu)) |
|
81 |
(K (EVERY [expand_tac, norm_tac ss])))); |
|
82 |
||
83 |
fun simp_all_tac rules = |
|
84 |
let val ss0 = HOL_ss addsimps rules |
|
85 |
in fn ss => ALLGOALS (simp_tac (Simplifier.inherit_context ss ss0)) end; |
|
86 |
||
30518 | 87 |
fun simplify_meta_eq rules = |
88 |
let val ss0 = HOL_basic_ss addeqcongs [eq_cong2] addsimps rules |
|
89 |
in fn ss => simplify (Simplifier.inherit_context ss ss0) o mk_meta_eq end |
|
90 |
||
91 |
fun trans_tac NONE = all_tac |
|
92 |
| trans_tac (SOME th) = ALLGOALS (rtac (th RS trans)); |
|
93 |
||
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
94 |
fun prep_simproc (name, pats, proc) = (*FIXME avoid the_context*) |
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29302
diff
changeset
|
95 |
Simplifier.simproc (the_context ()) name pats proc; |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
96 |
|
24095 | 97 |
end; |