| author | paulson <lp15@cam.ac.uk> | 
| Wed, 02 Apr 2014 16:45:31 +0100 | |
| changeset 56366 | 0362c3bb4d02 | 
| parent 51717 | 9e7d1c139569 | 
| child 57952 | 1a9a6dfc255f | 
| 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 | |
| 33359 | 4 | Common arithmetic proof auxiliary and legacy. | 
| 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: 
30518diff
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: 
30518diff
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: 
30518diff
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: 
30518diff
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: 
30518diff
changeset | 13 | |
| 33359 | 14 | val mk_number: typ -> int -> term | 
| 15 | val mk_sum: typ -> term list -> term | |
| 16 | val long_mk_sum: typ -> term list -> term | |
| 17 | val dest_sum: term -> term list | |
| 18 | ||
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
29302diff
changeset | 19 | 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: 
29302diff
changeset | 20 | val prove_conv: tactic list -> Proof.context -> thm list -> term * term -> thm option | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 21 | val prove_conv2: tactic -> (Proof.context -> tactic) -> Proof.context -> term * term -> thm | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 22 | val simp_all_tac: thm list -> Proof.context -> tactic | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 23 | val simplify_meta_eq: thm list -> Proof.context -> thm -> thm | 
| 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: 
30518diff
changeset | 24 | |
| 
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: 
30518diff
changeset | 25 | val setup: theory -> theory | 
| 26101 | 26 | end; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 27 | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
29302diff
changeset | 28 | structure Arith_Data: ARITH_DATA = | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 29 | struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 30 | |
| 30878 | 31 | (* 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: 
30518diff
changeset | 32 | |
| 31902 | 33 | structure Arith_Facts = Named_Thms | 
| 34 | ( | |
| 45294 | 35 |   val name = @{binding arith}
 | 
| 36 | val description = "arith facts -- only ground formulas" | |
| 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: 
30518diff
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: 
30518diff
changeset | 38 | |
| 
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: 
30518diff
changeset | 39 | 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: 
30518diff
changeset | 40 | |
| 33522 | 41 | structure Arith_Tactics = Theory_Data | 
| 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: 
30518diff
changeset | 42 | ( | 
| 
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: 
30518diff
changeset | 43 | 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: 
30518diff
changeset | 44 | 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: 
30518diff
changeset | 45 | val extend = I; | 
| 33522 | 46 | fun merge data : T = AList.merge (op =) (K true) data; | 
| 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: 
30518diff
changeset | 47 | ); | 
| 
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: 
30518diff
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: 
30518diff
changeset | 49 | 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: 
30518diff
changeset | 50 | |
| 
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: 
30518diff
changeset | 51 | 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: 
30518diff
changeset | 52 | let | 
| 42361 | 53 | val tactics = Arith_Tactics.get (Proof_Context.theory_of ctxt); | 
| 49387 | 54 | fun invoke (_, (_, tac)) k st = tac verbose ctxt k st; | 
| 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: 
30518diff
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: 
30518diff
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: 
30518diff
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: 
30518diff
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: 
30518diff
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: 
30686diff
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: 
30686diff
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: 
30686diff
changeset | 62 |   Method.setup @{binding arith}
 | 
| 33554 | 63 | (Scan.succeed (fn ctxt => | 
| 64 | METHOD (fn facts => HEADGOAL (Method.insert_tac (get_arith_facts ctxt @ facts) | |
| 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: 
30686diff
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: 
30686diff
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: 
30518diff
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: 
30518diff
changeset | 68 | |
| 33359 | 69 | (* some specialized syntactic operations *) | 
| 70 | ||
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
45620diff
changeset | 71 | fun mk_number T 1 = HOLogic.numeral_const T $ HOLogic.one_const | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
45620diff
changeset | 72 | | mk_number T n = HOLogic.mk_number T n; | 
| 33359 | 73 | |
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35021diff
changeset | 74 | val mk_plus = HOLogic.mk_binop @{const_name Groups.plus};
 | 
| 33359 | 75 | |
| 50107 | 76 | fun mk_minus t = | 
| 33359 | 77 | let val T = Term.fastype_of t | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35021diff
changeset | 78 |   in Const (@{const_name Groups.uminus}, T --> T) $ t end;
 | 
| 33359 | 79 | |
| 80 | (*Thus mk_sum[t] yields t+0; longer sums don't have a trailing zero*) | |
| 44945 | 81 | fun mk_sum T [] = mk_number T 0 | 
| 82 | | mk_sum T [t, u] = mk_plus (t, u) | |
| 33359 | 83 | | mk_sum T (t :: ts) = mk_plus (t, mk_sum T ts); | 
| 84 | ||
| 85 | (*this version ALWAYS includes a trailing zero*) | |
| 44945 | 86 | fun long_mk_sum T [] = mk_number T 0 | 
| 33359 | 87 | | long_mk_sum T (t :: ts) = mk_plus (t, mk_sum T ts); | 
| 88 | ||
| 89 | (*decompose additions AND subtractions as a sum*) | |
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35021diff
changeset | 90 | fun dest_summing (pos, Const (@{const_name Groups.plus}, _) $ t $ u, ts) =
 | 
| 44945 | 91 | dest_summing (pos, t, dest_summing (pos, u, ts)) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35021diff
changeset | 92 |   | dest_summing (pos, Const (@{const_name Groups.minus}, _) $ t $ u, ts) =
 | 
| 44945 | 93 | dest_summing (pos, t, dest_summing (not pos, u, ts)) | 
| 94 | | dest_summing (pos, t, ts) = (if pos then t else mk_minus t) :: ts; | |
| 33359 | 95 | |
| 96 | fun dest_sum t = dest_summing (true, t, []); | |
| 97 | ||
| 98 | ||
| 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: 
30518diff
changeset | 99 | (* 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: 
30518diff
changeset | 100 | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
29302diff
changeset | 101 | 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: 
29302diff
changeset | 102 | if t aconv u then NONE | 
| 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
29302diff
changeset | 103 | 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: 
29302diff
changeset | 104 | in SOME (Goal.prove ctxt [] [] eq (K (EVERY tacs))) end; | 
| 26101 | 105 | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
29302diff
changeset | 106 | fun prove_conv tacs ctxt (_: thm list) = prove_conv_nohyps tacs ctxt; | 
| 26101 | 107 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 108 | fun prove_conv2 expand_tac norm_tac ctxt tu = (* FIXME avoid Drule.export_without_context *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 109 | mk_meta_eq (Drule.export_without_context (Goal.prove ctxt [] [] | 
| 26101 | 110 | (HOLogic.mk_Trueprop (HOLogic.mk_eq tu)) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 111 | (K (EVERY [expand_tac, norm_tac ctxt])))); | 
| 26101 | 112 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 113 | fun simp_all_tac rules ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 114 | ALLGOALS (safe_simp_tac (put_simpset HOL_ss ctxt addsimps rules)); | 
| 26101 | 115 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 116 | fun simplify_meta_eq rules ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 117 |   simplify (put_simpset HOL_basic_ss ctxt addsimps rules |> Simplifier.add_eqcong @{thm eq_cong2})
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50107diff
changeset | 118 | o mk_meta_eq; | 
| 30518 | 119 | |
| 24095 | 120 | end; |