author | wenzelm |
Tue, 03 Jan 2023 17:21:24 +0100 | |
changeset 76887 | d8cdddf7b9a5 |
parent 70356 | 4a327c061870 |
child 78808 | 64973b03b778 |
permissions | -rw-r--r-- |
31068
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents:
31024
diff
changeset
|
1 |
(* Author: Tobias Nipkow |
30802 | 2 |
|
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
3 |
A special simproc for the instantiation of the generic linear arithmetic package for int. |
23164 | 4 |
*) |
5 |
||
31068
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents:
31024
diff
changeset
|
6 |
signature INT_ARITH = |
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents:
31024
diff
changeset
|
7 |
sig |
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
8 |
val zero_one_idom_simproc: simproc |
31068
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents:
31024
diff
changeset
|
9 |
end |
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents:
31024
diff
changeset
|
10 |
|
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents:
31024
diff
changeset
|
11 |
structure Int_Arith : INT_ARITH = |
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29269
diff
changeset
|
12 |
struct |
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29269
diff
changeset
|
13 |
|
23164 | 14 |
(* Update parameters of arithmetic prover *) |
15 |
||
24266
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
16 |
(* reduce contradictory =/</<= to False *) |
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
17 |
|
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
18 |
(* Evaluation of terms of the form "m R n" where R is one of "=", "<=" or "<", |
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
19 |
and m and n are ground terms over rings (roughly speaking). |
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
20 |
That is, m and n consist only of 1s combined with "+", "-" and "*". |
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
21 |
*) |
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29269
diff
changeset
|
22 |
|
61144 | 23 |
val zeroth = Thm.symmetric (mk_meta_eq @{thm of_int_0}); |
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29269
diff
changeset
|
24 |
|
24266
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
25 |
val zero_to_of_int_zero_simproc = |
69593 | 26 |
Simplifier.make_simproc \<^context> "zero_to_of_int_zero_simproc" |
67149 | 27 |
{lhss = [\<^term>\<open>0::'a::ring\<close>], |
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
28 |
proc = fn _ => fn _ => fn ct => |
61144 | 29 |
let val T = Thm.ctyp_of_cterm ct in |
67149 | 30 |
if Thm.typ_of T = \<^typ>\<open>int\<close> then NONE |
61144 | 31 |
else SOME (Thm.instantiate' [SOME T] [] zeroth) |
62913 | 32 |
end}; |
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29269
diff
changeset
|
33 |
|
61144 | 34 |
val oneth = Thm.symmetric (mk_meta_eq @{thm of_int_1}); |
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29269
diff
changeset
|
35 |
|
24266
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
36 |
val one_to_of_int_one_simproc = |
69593 | 37 |
Simplifier.make_simproc \<^context> "one_to_of_int_one_simproc" |
67149 | 38 |
{lhss = [\<^term>\<open>1::'a::ring_1\<close>], |
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
39 |
proc = fn _ => fn _ => fn ct => |
61144 | 40 |
let val T = Thm.ctyp_of_cterm ct in |
67149 | 41 |
if Thm.typ_of T = \<^typ>\<open>int\<close> then NONE |
61144 | 42 |
else SOME (Thm.instantiate' [SOME T] [] oneth) |
62913 | 43 |
end}; |
24266
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
44 |
|
67149 | 45 |
fun check (Const (\<^const_name>\<open>Groups.one\<close>, \<^typ>\<open>int\<close>)) = false |
46 |
| check (Const (\<^const_name>\<open>Groups.one\<close>, _)) = true |
|
47 |
| check (Const (s, _)) = member (op =) [\<^const_name>\<open>HOL.eq\<close>, |
|
48 |
\<^const_name>\<open>Groups.times\<close>, \<^const_name>\<open>Groups.uminus\<close>, |
|
49 |
\<^const_name>\<open>Groups.minus\<close>, \<^const_name>\<open>Groups.plus\<close>, |
|
50 |
\<^const_name>\<open>Groups.zero\<close>, |
|
51 |
\<^const_name>\<open>Orderings.less\<close>, \<^const_name>\<open>Orderings.less_eq\<close>] s |
|
31100 | 52 |
| check (a $ b) = check a andalso check b |
53 |
| check _ = false; |
|
24266
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
54 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
47209
diff
changeset
|
55 |
val conv_ss = |
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
56 |
\<^context> |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
57 |
|> put_simpset HOL_basic_ss |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
58 |
|> fold (Simplifier.add_simp o (fn th => th RS sym)) |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
59 |
@{thms of_int_add of_int_mult |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
60 |
of_int_diff of_int_minus of_int_less_iff |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
61 |
of_int_le_iff of_int_eq_iff} |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
62 |
|> (fn ss => ss addsimprocs [zero_to_of_int_zero_simproc, one_to_of_int_one_simproc]) |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69593
diff
changeset
|
63 |
|> simpset_of; |
24266
bdb48fd8fbdd
extended linear arith capabilities with code by Amine
nipkow
parents:
24196
diff
changeset
|
64 |
|
61144 | 65 |
val zero_one_idom_simproc = |
69593 | 66 |
Simplifier.make_simproc \<^context> "zero_one_idom_simproc" |
61144 | 67 |
{lhss = |
67149 | 68 |
[\<^term>\<open>(x::'a::ring_char_0) = y\<close>, |
69 |
\<^term>\<open>(x::'a::linordered_idom) < y\<close>, |
|
70 |
\<^term>\<open>(x::'a::linordered_idom) \<le> y\<close>], |
|
61144 | 71 |
proc = fn _ => fn ctxt => fn ct => |
72 |
if check (Thm.term_of ct) |
|
73 |
then SOME (Simplifier.rewrite (put_simpset conv_ss ctxt) ct) |
|
62913 | 74 |
else NONE}; |
30496
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents:
29269
diff
changeset
|
75 |
|
31100 | 76 |
end; |