568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
theory IntEx2
|
672
|
2 |
imports "../QuotMain" Nat Presburger
|
604
|
3 |
(*uses
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
("Tools/numeral.ML")
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
("Tools/numeral_syntax.ML")
|
604
|
6 |
("Tools/int_arith.ML")*)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
begin
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
fun
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
intrel :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" (infix "\<approx>" 50)
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
where
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
"intrel (x, y) (u, v) = (x + v = u + y)"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
quotient int = "nat \<times> nat" / intrel
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
apply(unfold equivp_def)
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
apply(auto simp add: mem_def expand_fun_eq)
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
17 |
done
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
instantiation int :: "{zero, one, plus, minus, uminus, times, ord, abs, sgn}"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
begin
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
21 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
22 |
quotient_def
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
23 |
zero_int::"0 :: int"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
where
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
25 |
"(0::nat, 0::nat)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
27 |
quotient_def
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
28 |
one_int::"1 :: int"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
where
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
30 |
"(1::nat, 0::nat)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
fun
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
plus_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
where
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
"plus_raw (x, y) (u, v) = (x + u, y + v)"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
37 |
quotient_def
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
38 |
plus_int::"(op +) :: (int \<Rightarrow> int \<Rightarrow> int)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
39 |
where
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
40 |
"plus_raw"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
fun
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
minus_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
44 |
where
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
"minus_raw (x, y) = (y, x)"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
|
579
|
47 |
quotient_def
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
48 |
uminus_int::"(uminus :: (int \<Rightarrow> int))"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
where
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
50 |
"minus_raw"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
definition
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
53 |
minus_int_def [code del]: "z - w = z + (-w::int)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
fun
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
56 |
times_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
where
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
58 |
"times_raw (x, y) (u, v) = (x*u + y*v, x*v + y*u)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
60 |
quotient_def
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
61 |
times_int::"(op *) :: (int \<Rightarrow> int \<Rightarrow> int)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
where
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
63 |
"times_raw"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
fun
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
66 |
less_eq_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
where
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
68 |
"less_eq_raw (x, y) (u, v) = (x+v \<le> u+y)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
70 |
quotient_def
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
71 |
less_eq_int :: "(op \<le>) :: int \<Rightarrow> int \<Rightarrow> bool"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
where
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
73 |
"less_eq_raw"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
definition
|
570
|
76 |
less_int_def [code del]: "(z\<Colon>int) < w = (z \<le> w \<and> z \<noteq> w)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
77 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
78 |
definition
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
79 |
abs_int_def: "\<bar>i\<Colon>int\<bar> = (if i < 0 then - i else i)"
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
80 |
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
definition
|
672
|
82 |
sgn_int_def: "sgn (i\<Colon>int) = (if i = 0 then 0 else if 0 < i then 1 else - 1)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
instance ..
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
end
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
|
636
|
88 |
lemma plus_raw_rsp[quot_respect]:
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
shows "(op \<approx> ===> op \<approx> ===> op \<approx>) plus_raw plus_raw"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
by auto
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
|
636
|
92 |
lemma minus_raw_rsp[quot_respect]:
|
579
|
93 |
shows "(op \<approx> ===> op \<approx>) minus_raw minus_raw"
|
|
94 |
by auto
|
|
95 |
|
672
|
96 |
lemma times_raw_fst:
|
|
97 |
assumes a: "x \<approx> z"
|
|
98 |
shows "times_raw x y \<approx> times_raw z y"
|
|
99 |
using a
|
|
100 |
apply(cases x, cases y, cases z)
|
|
101 |
apply(auto simp add: times_raw.simps intrel.simps)
|
|
102 |
apply(rename_tac u v w x y z)
|
|
103 |
apply(subgoal_tac "u*w + z*w = y*w + v*w & u*x + z*x = y*x + v*x")
|
|
104 |
apply(simp add: mult_ac)
|
|
105 |
apply(simp add: add_mult_distrib [symmetric])
|
|
106 |
done
|
|
107 |
|
|
108 |
lemma times_raw_snd:
|
|
109 |
assumes a: "x \<approx> z"
|
|
110 |
shows "times_raw y x \<approx> times_raw y z"
|
|
111 |
using a
|
|
112 |
apply(cases x, cases y, cases z)
|
|
113 |
apply(auto simp add: times_raw.simps intrel.simps)
|
|
114 |
apply(rename_tac u v w x y z)
|
|
115 |
apply(subgoal_tac "u*w + z*w = y*w + v*w & u*x + z*x = y*x + v*x")
|
|
116 |
apply(simp add: mult_ac)
|
|
117 |
apply(simp add: add_mult_distrib [symmetric])
|
|
118 |
done
|
|
119 |
|
636
|
120 |
lemma mult_raw_rsp[quot_respect]:
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
121 |
shows "(op \<approx> ===> op \<approx> ===> op \<approx>) times_raw times_raw"
|
672
|
122 |
apply(simp only: fun_rel.simps)
|
|
123 |
apply(rule allI | rule impI)+
|
|
124 |
apply(rule equivp_transp[OF int_equivp])
|
|
125 |
apply(rule times_raw_fst)
|
|
126 |
apply(assumption)
|
|
127 |
apply(rule times_raw_snd)
|
|
128 |
apply(assumption)
|
|
129 |
done
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
130 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
131 |
lemma less_eq_raw_rsp[quot_respect]:
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
132 |
shows "(op \<approx> ===> op \<approx> ===> op =) less_eq_raw less_eq_raw"
|
570
|
133 |
by auto
|
|
134 |
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
135 |
lemma plus_assoc_raw:
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
136 |
shows "plus_raw (plus_raw i j) k \<approx> plus_raw i (plus_raw j k)"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
137 |
by (cases i, cases j, cases k) (simp)
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
138 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
139 |
lemma plus_sym_raw:
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
140 |
shows "plus_raw i j \<approx> plus_raw j i"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
141 |
by (cases i, cases j) (simp)
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
142 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
143 |
lemma plus_zero_raw:
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
144 |
shows "plus_raw (0, 0) i \<approx> i"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
145 |
by (cases i) (simp)
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
146 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
147 |
lemma plus_minus_zero_raw:
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
shows "plus_raw (minus_raw i) i \<approx> (0, 0)"
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
by (cases i) (simp)
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
151 |
lemma times_assoc_raw:
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
152 |
shows "times_raw (times_raw i j) k \<approx> times_raw i (times_raw j k)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
153 |
by (cases i, cases j, cases k)
|
600
|
154 |
(simp add: algebra_simps)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
155 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
156 |
lemma times_sym_raw:
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
157 |
shows "times_raw i j \<approx> times_raw j i"
|
600
|
158 |
by (cases i, cases j) (simp add: algebra_simps)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
159 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
160 |
lemma times_one_raw:
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
161 |
shows "times_raw (1, 0) i \<approx> i"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
162 |
by (cases i) (simp)
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
163 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
164 |
lemma times_plus_comm_raw:
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
165 |
shows "times_raw (plus_raw i j) k \<approx> plus_raw (times_raw i k) (times_raw j k)"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
166 |
by (cases i, cases j, cases k)
|
600
|
167 |
(simp add: algebra_simps)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
168 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
169 |
lemma one_zero_distinct:
|
579
|
170 |
shows "\<not> (0, 0) \<approx> ((1::nat), (0::nat))"
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
171 |
by simp
|
579
|
172 |
|
673
|
173 |
text{* The integers form a @{text comm_ring_1}*}
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
174 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
175 |
ML {* qconsts_lookup @{theory} @{term "op + :: int \<Rightarrow> int \<Rightarrow> int"} *}
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
176 |
ML {* dest_Type (snd (dest_Const @{term "0 :: int"})) *}
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
177 |
ML {* @{term "0 :: int"} *}
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
178 |
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
179 |
instance int :: comm_ring_1
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
180 |
proof
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
181 |
fix i j k :: int
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
182 |
show "(i + j) + k = i + (j + k)"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
183 |
by (lifting plus_assoc_raw)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
184 |
show "i + j = j + i"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
185 |
by (lifting plus_sym_raw)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
186 |
show "0 + i = (i::int)"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
187 |
by (lifting plus_zero_raw)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
188 |
show "- i + i = 0"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
189 |
by (lifting plus_minus_zero_raw)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
190 |
show "i - j = i + - j"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
191 |
by (simp add: minus_int_def)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
192 |
show "(i * j) * k = i * (j * k)"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
193 |
by (lifting times_assoc_raw)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
194 |
show "i * j = j * i"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
195 |
by (lifting times_sym_raw)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
196 |
show "1 * i = i"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
197 |
by (lifting times_one_raw)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
198 |
show "(i + j) * k = i * k + j * k"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
199 |
by (lifting times_plus_comm_raw)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
200 |
show "0 \<noteq> (1::int)"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
201 |
by (lifting one_zero_distinct)
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
202 |
qed
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
203 |
|
673
|
204 |
|
674
|
205 |
lemma plus_raw_rsp_lo:
|
|
206 |
"\<And>a b c d. a \<approx> b \<Longrightarrow> c \<approx> d \<Longrightarrow> plus_raw a c \<approx> plus_raw b d"
|
|
207 |
by auto
|
|
208 |
|
673
|
209 |
lemma add:
|
|
210 |
"(ABS_int (x,y)) + (ABS_int (u,v)) =
|
|
211 |
(ABS_int (x+u, y+v))"
|
|
212 |
apply(simp add: plus_int_def)
|
674
|
213 |
apply(fold plus_raw.simps)
|
|
214 |
apply(rule Quotient_rel_abs[OF Quotient_int])
|
|
215 |
apply(rule plus_raw_rsp_lo)
|
|
216 |
apply(simp_all add: rep_abs_rsp_left[OF Quotient_int])
|
|
217 |
done
|
570
|
218 |
|
|
219 |
lemma int_def: "of_nat m = ABS_int (m, 0)"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
220 |
apply(induct m)
|
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
221 |
apply(simp add: zero_int_def)
|
673
|
222 |
apply(simp add: one_int_def add)
|
|
223 |
done
|
570
|
224 |
|
|
225 |
lemma le_antisym_raw:
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
226 |
shows "less_eq_raw i j \<Longrightarrow> less_eq_raw j i \<Longrightarrow> i \<approx> j"
|
570
|
227 |
by (cases i, cases j) (simp)
|
|
228 |
|
|
229 |
lemma le_refl_raw:
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
230 |
shows "less_eq_raw i i"
|
570
|
231 |
by (cases i) (simp)
|
|
232 |
|
|
233 |
lemma le_trans_raw:
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
234 |
shows "less_eq_raw i j \<Longrightarrow> less_eq_raw j k \<Longrightarrow> less_eq_raw i k"
|
570
|
235 |
by (cases i, cases j, cases k) (simp)
|
|
236 |
|
|
237 |
lemma le_cases_raw:
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
238 |
shows "less_eq_raw i j \<or> less_eq_raw j i"
|
570
|
239 |
by (cases i, cases j)
|
|
240 |
(simp add: linorder_linear)
|
|
241 |
|
|
242 |
instance int :: linorder
|
|
243 |
proof
|
|
244 |
fix i j k :: int
|
|
245 |
show antisym: "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
246 |
by (lifting le_antisym_raw)
|
570
|
247 |
show "(i < j) = (i \<le> j \<and> \<not> j \<le> i)"
|
|
248 |
by (auto simp add: less_int_def dest: antisym)
|
|
249 |
show "i \<le> i"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
250 |
by (lifting le_refl_raw)
|
570
|
251 |
show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
252 |
by (lifting le_trans_raw)
|
570
|
253 |
show "i \<le> j \<or> j \<le> i"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
254 |
by (lifting le_cases_raw)
|
570
|
255 |
qed
|
|
256 |
|
|
257 |
instantiation int :: distrib_lattice
|
|
258 |
begin
|
|
259 |
|
|
260 |
definition
|
|
261 |
"(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min"
|
|
262 |
|
|
263 |
definition
|
|
264 |
"(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max"
|
|
265 |
|
|
266 |
instance
|
|
267 |
by intro_classes
|
|
268 |
(auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1)
|
|
269 |
|
|
270 |
end
|
|
271 |
|
|
272 |
lemma le_plus_raw:
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
273 |
shows "less_eq_raw i j \<Longrightarrow> less_eq_raw (plus_raw k i) (plus_raw k j)"
|
570
|
274 |
by (cases i, cases j, cases k) (simp)
|
|
275 |
|
|
276 |
|
|
277 |
instance int :: pordered_cancel_ab_semigroup_add
|
|
278 |
proof
|
|
279 |
fix i j k :: int
|
|
280 |
show "i \<le> j \<Longrightarrow> k + i \<le> k + j"
|
654
02fd9de9d45e
tuned the examples and flagged the problematic cleaning lemmas in FSet
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
281 |
by (lifting le_plus_raw)
|
570
|
282 |
qed
|
|
283 |
|
673
|
284 |
abbreviation
|
|
285 |
"less_raw i j \<equiv> less_eq_raw i j \<and> \<not>(i \<approx> j)"
|
|
286 |
|
|
287 |
|
570
|
288 |
lemma test:
|
673
|
289 |
"\<lbrakk>less_raw i j; less_raw (0, 0) k\<rbrakk>
|
|
290 |
\<Longrightarrow> less_raw (times_raw k i) (times_raw k j)"
|
570
|
291 |
apply(cases i, cases j, cases k)
|
673
|
292 |
apply(simp only: less_eq_raw.simps times_raw.simps)
|
|
293 |
apply(simp)
|
|
294 |
apply(rename_tac u v w x y z)
|
|
295 |
apply(rule conjI)
|
|
296 |
apply(subgoal_tac "y*u + y*x \<le> y*w + y*v & z*v \<le> y*v")
|
|
297 |
apply(simp add: )
|
570
|
298 |
sorry
|
|
299 |
|
|
300 |
|
|
301 |
text{*The integers form an ordered integral domain*}
|
|
302 |
instance int :: ordered_idom
|
|
303 |
proof
|
|
304 |
fix i j k :: int
|
|
305 |
show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j"
|
672
|
306 |
unfolding less_int_def by (lifting test)
|
570
|
307 |
show "\<bar>i\<bar> = (if i < 0 then -i else i)"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
308 |
by (simp only: abs_int_def)
|
570
|
309 |
show "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
310 |
by (simp only: sgn_int_def)
|
570
|
311 |
qed
|
|
312 |
|
|
313 |
instance int :: lordered_ring
|
|
314 |
proof
|
|
315 |
fix k :: int
|
|
316 |
show "abs k = sup k (- k)"
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
317 |
by (auto simp add: sup_int_def abs_int_def less_minus_self_iff [symmetric])
|
570
|
318 |
qed
|
|
319 |
|
|
320 |
lemmas int_distrib =
|
|
321 |
left_distrib [of "z1::int" "z2" "w", standard]
|
|
322 |
right_distrib [of "w::int" "z1" "z2", standard]
|
|
323 |
left_diff_distrib [of "z1::int" "z2" "w", standard]
|
|
324 |
right_diff_distrib [of "w::int" "z1" "z2", standard]
|
|
325 |
|
|
326 |
|
|
327 |
subsection {* Embedding of the Integers into any @{text ring_1}: @{text of_int}*}
|
|
328 |
|
|
329 |
(*
|
|
330 |
context ring_1
|
|
331 |
begin
|
|
332 |
|
|
333 |
|
|
334 |
definition
|
|
335 |
of_int :: "int \<Rightarrow> 'a"
|
|
336 |
where
|
|
337 |
"of_int
|
|
338 |
*)
|
|
339 |
|
|
340 |
|
|
341 |
subsection {* Binary representation *}
|
|
342 |
|
|
343 |
text {*
|
|
344 |
This formalization defines binary arithmetic in terms of the integers
|
|
345 |
rather than using a datatype. This avoids multiple representations (leading
|
|
346 |
zeroes, etc.) See @{text "ZF/Tools/twos-compl.ML"}, function @{text
|
|
347 |
int_of_binary}, for the numerical interpretation.
|
|
348 |
|
|
349 |
The representation expects that @{text "(m mod 2)"} is 0 or 1,
|
|
350 |
even if m is negative;
|
|
351 |
For instance, @{text "-5 div 2 = -3"} and @{text "-5 mod 2 = 1"}; thus
|
|
352 |
@{text "-5 = (-3)*2 + 1"}.
|
|
353 |
|
|
354 |
This two's complement binary representation derives from the paper
|
|
355 |
"An Efficient Representation of Arithmetic for Term Rewriting" by
|
|
356 |
Dave Cohen and Phil Watson, Rewriting Techniques and Applications,
|
|
357 |
Springer LNCS 488 (240-251), 1991.
|
|
358 |
*}
|
|
359 |
|
|
360 |
subsubsection {* The constructors @{term Bit0}, @{term Bit1}, @{term Pls} and @{term Min} *}
|
|
361 |
|
|
362 |
definition
|
|
363 |
Pls :: int where
|
|
364 |
[code del]: "Pls = 0"
|
|
365 |
|
|
366 |
definition
|
|
367 |
Min :: int where
|
|
368 |
[code del]: "Min = - 1"
|
|
369 |
|
|
370 |
definition
|
|
371 |
Bit0 :: "int \<Rightarrow> int" where
|
|
372 |
[code del]: "Bit0 k = k + k"
|
|
373 |
|
|
374 |
definition
|
|
375 |
Bit1 :: "int \<Rightarrow> int" where
|
|
376 |
[code del]: "Bit1 k = 1 + k + k"
|
|
377 |
|
|
378 |
class number = -- {* for numeric types: nat, int, real, \dots *}
|
|
379 |
fixes number_of :: "int \<Rightarrow> 'a"
|
|
380 |
|
600
|
381 |
(*use "~~/src/HOL/Tools/numeral.ML"
|
570
|
382 |
|
|
383 |
syntax
|
|
384 |
"_Numeral" :: "num_const \<Rightarrow> 'a" ("_")
|
|
385 |
|
|
386 |
use "~~/src/HOL/Tools/numeral_syntax.ML"
|
600
|
387 |
|
570
|
388 |
setup NumeralSyntax.setup
|
|
389 |
|
|
390 |
abbreviation
|
|
391 |
"Numeral0 \<equiv> number_of Pls"
|
|
392 |
|
|
393 |
abbreviation
|
|
394 |
"Numeral1 \<equiv> number_of (Bit1 Pls)"
|
|
395 |
|
|
396 |
lemma Let_number_of [simp]: "Let (number_of v) f = f (number_of v)"
|
|
397 |
-- {* Unfold all @{text let}s involving constants *}
|
|
398 |
unfolding Let_def ..
|
|
399 |
|
|
400 |
definition
|
|
401 |
succ :: "int \<Rightarrow> int" where
|
|
402 |
[code del]: "succ k = k + 1"
|
|
403 |
|
|
404 |
definition
|
|
405 |
pred :: "int \<Rightarrow> int" where
|
|
406 |
[code del]: "pred k = k - 1"
|
|
407 |
|
|
408 |
lemmas
|
|
409 |
max_number_of [simp] = max_def
|
|
410 |
[of "number_of u" "number_of v", standard, simp]
|
|
411 |
and
|
|
412 |
min_number_of [simp] = min_def
|
|
413 |
[of "number_of u" "number_of v", standard, simp]
|
|
414 |
-- {* unfolding @{text minx} and @{text max} on numerals *}
|
|
415 |
|
|
416 |
lemmas numeral_simps =
|
|
417 |
succ_def pred_def Pls_def Min_def Bit0_def Bit1_def
|
|
418 |
|
|
419 |
text {* Removal of leading zeroes *}
|
|
420 |
|
|
421 |
lemma Bit0_Pls [simp, code_post]:
|
|
422 |
"Bit0 Pls = Pls"
|
|
423 |
unfolding numeral_simps by simp
|
|
424 |
|
|
425 |
lemma Bit1_Min [simp, code_post]:
|
|
426 |
"Bit1 Min = Min"
|
|
427 |
unfolding numeral_simps by simp
|
|
428 |
|
|
429 |
lemmas normalize_bin_simps =
|
|
430 |
Bit0_Pls Bit1_Min
|
600
|
431 |
*)
|
601
|
432 |
|
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
433 |
end
|