author | paulson <lp15@cam.ac.uk> |
Tue, 18 Mar 2025 18:11:58 +0000 | |
changeset 82302 | 19ada02fa486 |
parent 80914 | d97fdabd9e2b |
permissions | -rw-r--r-- |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
1 |
(* Title: HOL/Quotient_Examples/Quotient_Int.thy |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Cezary Kaliszyk |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
3 |
Author: Christian Urban |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
4 |
|
41467 | 5 |
Integers based on Quotients, based on an older version by Larry |
6 |
Paulson. |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
7 |
*) |
41467 | 8 |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
9 |
theory Quotient_Int |
68660 | 10 |
imports "HOL-Library.Quotient_Product" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
11 |
begin |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
12 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
13 |
fun |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
69597
diff
changeset
|
14 |
intrel :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" (infix \<open>\<approx>\<close> 50) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
15 |
where |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
16 |
"intrel (x, y) (u, v) = (x + v = u + y)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
17 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
18 |
quotient_type int = "nat \<times> nat" / intrel |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
19 |
by (auto simp add: equivp_def fun_eq_iff) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
20 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
21 |
instantiation int :: "{zero, one, plus, uminus, minus, times, ord, abs, sgn}" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
22 |
begin |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
23 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
24 |
quotient_definition |
61076 | 25 |
"0 :: int" is "(0::nat, 0::nat)" done |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
26 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
27 |
quotient_definition |
61076 | 28 |
"1 :: int" is "(1::nat, 0::nat)" done |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
29 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
30 |
fun |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
31 |
plus_int_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
32 |
where |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
33 |
"plus_int_raw (x, y) (u, v) = (x + u, y + v)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
34 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
35 |
quotient_definition |
67399 | 36 |
"(+) :: (int \<Rightarrow> int \<Rightarrow> int)" is "plus_int_raw" by auto |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
37 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
38 |
fun |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
39 |
uminus_int_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
40 |
where |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
41 |
"uminus_int_raw (x, y) = (y, x)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
42 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
43 |
quotient_definition |
61076 | 44 |
"(uminus :: (int \<Rightarrow> int))" is "uminus_int_raw" by auto |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
45 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
46 |
definition |
61076 | 47 |
minus_int_def: "z - w = z + (-w::int)" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
48 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
49 |
fun |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
50 |
times_int_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> (nat \<times> nat)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
51 |
where |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
52 |
"times_int_raw (x, y) (u, v) = (x*u + y*v, x*v + y*u)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
53 |
|
82302 | 54 |
lemma times_int_raw: |
55 |
assumes "x \<approx> z" |
|
56 |
shows "times_int_raw x y \<approx> times_int_raw z y \<and> times_int_raw y x \<approx> times_int_raw y z" |
|
57 |
proof (cases x, cases y, cases z) |
|
58 |
fix a a' b b' c c' |
|
59 |
assume \<section>: "x = (a, a')" "y = (b, b')" "z = (c, c')" |
|
60 |
then obtain "a*b + c'*b = c*b + a'*b" "a*b' + c'*b' = c*b' + a'*b'" |
|
61 |
by (metis add_mult_distrib assms intrel.simps) |
|
62 |
then show ?thesis |
|
63 |
by (simp add: \<section> algebra_simps) |
|
64 |
qed |
|
47092 | 65 |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
66 |
quotient_definition |
69064
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents:
68660
diff
changeset
|
67 |
"((*)) :: (int \<Rightarrow> int \<Rightarrow> int)" is "times_int_raw" |
82302 | 68 |
by (metis Quotient_Int.int.abs_eq_iff times_int_raw) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
69 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
70 |
fun |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
71 |
le_int_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
72 |
where |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
73 |
"le_int_raw (x, y) (u, v) = (x+v \<le> u+y)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
74 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
75 |
quotient_definition |
67399 | 76 |
le_int_def: "(\<le>) :: int \<Rightarrow> int \<Rightarrow> bool" is "le_int_raw" by auto |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
77 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
78 |
definition |
61076 | 79 |
less_int_def: "(z::int) < w = (z \<le> w \<and> z \<noteq> w)" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
80 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
81 |
definition |
61076 | 82 |
zabs_def: "\<bar>i::int\<bar> = (if i < 0 then - i else i)" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
83 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
84 |
definition |
61076 | 85 |
zsgn_def: "sgn (i::int) = (if i = 0 then 0 else if 0 < i then 1 else - 1)" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
86 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
87 |
instance .. |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
88 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
89 |
end |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
90 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
91 |
|
63167 | 92 |
text\<open>The integers form a \<open>comm_ring_1\<close>\<close> |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
93 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
94 |
instance int :: comm_ring_1 |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
95 |
proof |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
96 |
fix i j k :: int |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
97 |
show "(i + j) + k = i + (j + k)" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
98 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
99 |
show "i + j = j + i" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
100 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
101 |
show "0 + i = (i::int)" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
102 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
103 |
show "- i + i = 0" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
104 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
105 |
show "i - j = i + - j" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
106 |
by (simp add: minus_int_def) |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
107 |
show "(i * j) * k = i * (j * k)" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
108 |
by (descending) (auto simp add: algebra_simps) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
109 |
show "i * j = j * i" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
110 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
111 |
show "1 * i = i" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
112 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
113 |
show "(i + j) * k = i * k + j * k" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
114 |
by (descending) (auto simp add: algebra_simps) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
115 |
show "0 \<noteq> (1::int)" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
116 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
117 |
qed |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
118 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
119 |
lemma plus_int_raw_rsp_aux: |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
120 |
assumes a: "a \<approx> b" "c \<approx> d" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
121 |
shows "plus_int_raw a c \<approx> plus_int_raw b d" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
122 |
using a |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
123 |
by (cases a, cases b, cases c, cases d) |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
124 |
(simp) |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
125 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
126 |
lemma add_abs_int: |
82302 | 127 |
"(abs_int (x,y)) + (abs_int (u,v)) = (abs_int (x + u, y + v))" |
128 |
proof - |
|
129 |
have "abs_int (plus_int_raw (rep_int (abs_int (x, y))) (rep_int (abs_int (u, v)))) |
|
130 |
= abs_int (plus_int_raw (x, y) (u, v))" |
|
131 |
by (meson Quotient3_abs_rep Quotient3_int int.abs_eq_iff plus_int_raw_rsp_aux) |
|
132 |
then show ?thesis |
|
133 |
by (simp add: Quotient_Int.plus_int_def) |
|
134 |
qed |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
135 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
136 |
definition int_of_nat_raw: |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
137 |
"int_of_nat_raw m = (m :: nat, 0 :: nat)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
138 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
139 |
quotient_definition |
47092 | 140 |
"int_of_nat :: nat \<Rightarrow> int" is "int_of_nat_raw" done |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
141 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
142 |
lemma int_of_nat: |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
143 |
shows "of_nat m = int_of_nat m" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
144 |
by (induct m) |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
145 |
(simp_all add: zero_int_def one_int_def int_of_nat_def int_of_nat_raw add_abs_int) |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
146 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
147 |
instance int :: linorder |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
148 |
proof |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
149 |
fix i j k :: int |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
150 |
show antisym: "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
151 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
152 |
show "(i < j) = (i \<le> j \<and> \<not> j \<le> i)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
153 |
by (auto simp add: less_int_def dest: antisym) |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
154 |
show "i \<le> i" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
155 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
156 |
show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
157 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
158 |
show "i \<le> j \<or> j \<le> i" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
159 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
160 |
qed |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
161 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
162 |
instantiation int :: distrib_lattice |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
163 |
begin |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
164 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
165 |
definition |
61076 | 166 |
"(inf :: int \<Rightarrow> int \<Rightarrow> int) = min" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
167 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
168 |
definition |
61076 | 169 |
"(sup :: int \<Rightarrow> int \<Rightarrow> int) = max" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
170 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
171 |
instance |
61169 | 172 |
by standard (auto simp add: inf_int_def sup_int_def max_min_distrib2) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
173 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
174 |
end |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
175 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
176 |
instance int :: ordered_cancel_ab_semigroup_add |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
177 |
proof |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
178 |
fix i j k :: int |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
179 |
show "i \<le> j \<Longrightarrow> k + i \<le> k + j" |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
180 |
by (descending) (auto) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
181 |
qed |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
182 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
183 |
abbreviation |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
184 |
"less_int_raw i j \<equiv> le_int_raw i j \<and> \<not>(i \<approx> j)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
185 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
186 |
lemma zmult_zless_mono2_lemma: |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
187 |
fixes i j::int |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
188 |
and k::nat |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
189 |
shows "i < j \<Longrightarrow> 0 < k \<Longrightarrow> of_nat k * i < of_nat k * j" |
82302 | 190 |
proof (induction "k") |
191 |
case 0 |
|
192 |
then show ?case by simp |
|
193 |
next |
|
194 |
case (Suc k) |
|
195 |
then show ?case |
|
196 |
by (cases "k = 0"; simp add: distrib_right add_strict_mono) |
|
197 |
qed |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
198 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
199 |
lemma zero_le_imp_eq_int_raw: |
82302 | 200 |
assumes "less_int_raw (0, 0) u" |
201 |
shows "(\<exists>n > 0. u \<approx> int_of_nat_raw n)" |
|
202 |
proof - |
|
203 |
have "\<And>a b::nat. \<lbrakk>b \<le> a; b \<noteq> a\<rbrakk> \<Longrightarrow> \<exists>n>0. a = n + b" |
|
204 |
by (metis add.comm_neutral add.commute gr0I le_iff_add) |
|
205 |
with assms show ?thesis |
|
206 |
by (cases u) (simp add:int_of_nat_raw) |
|
207 |
qed |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
208 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
209 |
lemma zero_le_imp_eq_int: |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
210 |
fixes k::int |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
211 |
shows "0 < k \<Longrightarrow> \<exists>n > 0. k = of_nat n" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
212 |
unfolding less_int_def int_of_nat |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
213 |
by (descending) (rule zero_le_imp_eq_int_raw) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
214 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
215 |
lemma zmult_zless_mono2: |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
216 |
fixes i j k::int |
82302 | 217 |
assumes "i < j" "0 < k" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
218 |
shows "k * i < k * j" |
82302 | 219 |
using assms zmult_zless_mono2_lemma [of i j] |
220 |
using Quotient_Int.zero_le_imp_eq_int by blast |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
221 |
|
63167 | 222 |
text\<open>The integers form an ordered integral domain\<close> |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
223 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
224 |
instance int :: linordered_idom |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
225 |
proof |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
226 |
fix i j k :: int |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
227 |
show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
228 |
by (rule zmult_zless_mono2) |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
229 |
show "\<bar>i\<bar> = (if i < 0 then -i else i)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
230 |
by (simp only: zabs_def) |
61076 | 231 |
show "sgn (i::int) = (if i=0 then 0 else if 0<i then 1 else - 1)" |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
232 |
by (simp only: zsgn_def) |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
233 |
qed |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
234 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
235 |
lemmas int_distrib = |
49962
a8cc904a6820
Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents:
47308
diff
changeset
|
236 |
distrib_right [of z1 z2 w] |
a8cc904a6820
Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents:
47308
diff
changeset
|
237 |
distrib_left [of w z1 z2] |
45605 | 238 |
left_diff_distrib [of z1 z2 w] |
239 |
right_diff_distrib [of w z1 z2] |
|
240 |
minus_add_distrib[of z1 z2] |
|
241 |
for z1 z2 w :: int |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
242 |
|
47304 | 243 |
lemma int_induct2: |
244 |
assumes "P 0 0" |
|
245 |
and "\<And>n m. P n m \<Longrightarrow> P (Suc n) m" |
|
246 |
and "\<And>n m. P n m \<Longrightarrow> P n (Suc m)" |
|
247 |
shows "P n m" |
|
248 |
using assms |
|
249 |
by (induction_schema) (pat_completeness, lexicographic_order) |
|
250 |
||
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
251 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
252 |
lemma int_induct: |
47304 | 253 |
fixes j :: int |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
254 |
assumes a: "P 0" |
47304 | 255 |
and b: "\<And>i::int. P i \<Longrightarrow> P (i + 1)" |
256 |
and c: "\<And>i::int. P i \<Longrightarrow> P (i - 1)" |
|
257 |
shows "P j" |
|
258 |
using a b c |
|
259 |
unfolding minus_int_def |
|
260 |
by (descending) (auto intro: int_induct2) |
|
261 |
||
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
262 |
|
69597 | 263 |
text \<open>Magnitide of an Integer, as a Natural Number: \<^term>\<open>nat\<close>\<close> |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
264 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
265 |
definition |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
266 |
"int_to_nat_raw \<equiv> \<lambda>(x, y).x - (y::nat)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
267 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
268 |
quotient_definition |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
269 |
"int_to_nat::int \<Rightarrow> nat" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
270 |
is |
47304 | 271 |
"int_to_nat_raw" |
272 |
unfolding int_to_nat_raw_def by auto |
|
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
273 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
274 |
lemma nat_le_eq_zle: |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
275 |
fixes w z::"int" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
276 |
shows "0 < w \<or> 0 \<le> z \<Longrightarrow> (int_to_nat w \<le> int_to_nat z) = (w \<le> z)" |
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
277 |
unfolding less_int_def |
37594
32ad67684ee7
cosmetics: avoided statement of raw theorems, used the method descending instead
Christian Urban <urbanc@in.tum.de>
parents:
36524
diff
changeset
|
278 |
by (descending) (auto simp add: int_to_nat_raw_def) |
36524
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
279 |
|
3909002beca5
Tuning the quotient examples
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
280 |
end |