author | Christian Urban <urbanc@in.tum.de> |
Mon, 07 Dec 2009 02:34:24 +0100 | |
changeset 590 | 951681538e3f |
parent 588 | 2c95d0436a2b |
permissions | -rw-r--r-- |
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 |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
imports QuotMain |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
uses |
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") |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
("Tools/int_arith.ML") |
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 |
|
578
070161f1996a
updated Isabelle and deleted mono rules
Christian Urban <urbanc@in.tum.de>
parents:
570
diff
changeset
|
9 |
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
fun |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
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
|
12 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
"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
|
14 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
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
|
16 |
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
|
17 |
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
|
18 |
done |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
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
|
21 |
begin |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
quotient_def |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
zero_qnt::"int" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
"zero_qnt \<equiv> (0::nat, 0::nat)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
27 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
definition Zero_int_def[code del]: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
29 |
"0 = zero_qnt" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
quotient_def |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
one_qnt::"int" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
"one_qnt \<equiv> (1::nat, 0::nat)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
definition One_int_def[code del]: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
37 |
"1 = one_qnt" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
38 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
39 |
fun |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
40 |
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
|
41 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
"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
|
43 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
44 |
quotient_def |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
plus_qnt::"int \<Rightarrow> int \<Rightarrow> int" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
"plus_qnt \<equiv> plus_raw" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
definition add_int_def[code del]: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
"z + w = plus_qnt z w" |
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 |
fun |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
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
|
54 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
"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
|
56 |
|
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
57 |
quotient_def |
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
minus_qnt::"int \<Rightarrow> int" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
"minus_qnt \<equiv> minus_raw" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
definition minus_int_def [code del]: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
"- z = minus_qnt z" |
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 |
definition |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
66 |
diff_int_def [code del]: "z - w = z + (-w::int)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
fun |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
mult_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
|
70 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
71 |
"mult_raw (x, y) (u, v) = (x*u + y*v, x*v + y*u)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
quotient_def |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
mult_qnt::"int \<Rightarrow> int \<Rightarrow> int" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
76 |
"mult_qnt \<equiv> mult_raw" |
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 |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
mult_int_def [code del]: "z * w = mult_qnt z w" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
fun |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
le_raw :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
84 |
"le_raw (x, y) (u, v) = (x+v \<le> u+y)" |
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 |
quotient_def |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
le_qnt :: "int \<Rightarrow> int \<Rightarrow> bool" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
where |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
"le_qnt \<equiv> le_raw" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
definition |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
le_int_def [code del]: |
570 | 93 |
"z \<le> w = le_qnt z w" |
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
definition |
570 | 96 |
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
|
97 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
definition |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
zabs_def: "\<bar>i\<Colon>int\<bar> = (if i < 0 then - i else i)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
101 |
definition |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
102 |
zsgn_def: "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
103 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
instance .. |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
106 |
end |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
107 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
108 |
thm add_assoc |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
109 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
lemma plus_raw_rsp[quotient_rsp]: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
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
|
112 |
by auto |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
113 |
|
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
114 |
lemma minus_raw_rsp[quotient_rsp]: |
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
115 |
shows "(op \<approx> ===> op \<approx>) minus_raw minus_raw" |
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
116 |
by auto |
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
117 |
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
118 |
lemma mult_raw_rsp[quotient_rsp]: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
119 |
shows "(op \<approx> ===> op \<approx> ===> op \<approx>) mult_raw mult_raw" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
apply(auto) |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
apply(simp add: mult algebra_simps) |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
122 |
sorry |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
123 |
|
570 | 124 |
lemma le_raw_rsp[quotient_rsp]: |
125 |
shows "(op \<approx> ===> op \<approx> ===> op =) le_raw le_raw" |
|
126 |
by auto |
|
127 |
||
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
144 |
lemma mult_assoc_raw: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
145 |
shows "mult_raw (mult_raw i j) k \<approx> mult_raw i (mult_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
|
146 |
by (cases i, cases j, cases k) |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
147 |
(simp add: mult algebra_simps) |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
lemma mult_sym_raw: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
shows "mult_raw i j \<approx> mult_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
|
151 |
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
|
152 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
153 |
lemma mult_one_raw: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
154 |
shows "mult_raw (1, 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
|
155 |
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
|
156 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
157 |
lemma mult_plus_comm_raw: |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
158 |
shows "mult_raw (plus_raw i j) k \<approx> plus_raw (mult_raw i k) (mult_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
|
159 |
by (cases i, cases j, cases k) |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
160 |
(simp add: mult algebra_simps) |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
161 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
162 |
lemma one_zero_distinct: |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
163 |
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
|
164 |
by simp |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
165 |
|
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
166 |
text{*The integers form a @{text 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
|
167 |
|
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 |
ML {* val qty = @{typ "int"} *} |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
170 |
ML {* val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data @{context} qty *} |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
171 |
ML {* val (trans2, reps_same, absrep, quot) = lookup_quot_thms @{context} "int" *} |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
172 |
|
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
173 |
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
|
174 |
proof |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
175 |
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
|
176 |
show "(i + j) + k = i + (j + k)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
177 |
unfolding add_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
178 |
apply(tactic {* lift_tac @{context} @{thm plus_assoc_raw} 1 *}) |
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
179 |
done |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
180 |
show "i + j = j + i" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
181 |
unfolding add_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
182 |
apply(tactic {* lift_tac @{context} @{thm plus_sym_raw} 1 *}) |
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
183 |
done |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
184 |
show "0 + i = (i::int)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
185 |
unfolding add_int_def Zero_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
186 |
apply(tactic {* lift_tac @{context} @{thm plus_zero_raw} 1 *}) |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
187 |
done |
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" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
189 |
unfolding add_int_def minus_int_def Zero_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
190 |
apply(tactic {* lift_tac @{context} @{thm plus_minus_zero_raw} 1 *}) |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
191 |
done |
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 = i + - j" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
193 |
by (simp add: diff_int_def) |
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) * k = i * (j * k)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
195 |
unfolding mult_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
196 |
apply(tactic {* lift_tac @{context} @{thm mult_assoc_raw} 1 *}) |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
197 |
done |
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 = j * i" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
199 |
unfolding mult_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
200 |
apply(tactic {* lift_tac @{context} @{thm mult_sym_raw} 1 *}) |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
201 |
done |
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
202 |
show "1 * i = i" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
203 |
unfolding mult_int_def One_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
204 |
apply(tactic {* lift_tac @{context} @{thm mult_one_raw} 1 *}) |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
205 |
done |
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
206 |
show "(i + j) * k = i * k + j * k" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
207 |
unfolding mult_int_def add_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
208 |
apply(tactic {* lift_tac @{context} @{thm mult_plus_comm_raw} 1 *}) |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
209 |
done |
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
210 |
show "0 \<noteq> (1::int)" |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
211 |
unfolding Zero_int_def One_int_def |
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
212 |
apply(tactic {* lift_tac @{context} @{thm one_zero_distinct} 1 *}) |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
213 |
done |
568
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
214 |
qed |
0384e039b7f2
added new example for Ints; regularise does not work in all instances
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
215 |
|
570 | 216 |
term of_nat |
217 |
thm of_nat_def |
|
218 |
||
219 |
lemma int_def: "of_nat m = ABS_int (m, 0)" |
|
220 |
apply(induct m) |
|
221 |
apply(simp add: Zero_int_def zero_qnt_def) |
|
222 |
apply(simp) |
|
223 |
apply(simp add: add_int_def One_int_def) |
|
224 |
apply(simp add: plus_qnt_def one_qnt_def) |
|
225 |
oops |
|
226 |
||
227 |
lemma le_antisym_raw: |
|
228 |
shows "le_raw i j \<Longrightarrow> le_raw j i \<Longrightarrow> i \<approx> j" |
|
229 |
by (cases i, cases j) (simp) |
|
230 |
||
231 |
lemma le_refl_raw: |
|
232 |
shows "le_raw i i" |
|
233 |
by (cases i) (simp) |
|
234 |
||
235 |
lemma le_trans_raw: |
|
236 |
shows "le_raw i j \<Longrightarrow> le_raw j k \<Longrightarrow> le_raw i k" |
|
237 |
by (cases i, cases j, cases k) (simp) |
|
238 |
||
239 |
lemma le_cases_raw: |
|
240 |
shows "le_raw i j \<or> le_raw j i" |
|
241 |
by (cases i, cases j) |
|
242 |
(simp add: linorder_linear) |
|
243 |
||
244 |
instance int :: linorder |
|
245 |
proof |
|
246 |
fix i j k :: int |
|
247 |
show antisym: "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j" |
|
248 |
unfolding le_int_def |
|
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
249 |
apply(tactic {* lift_tac @{context} @{thm le_antisym_raw} 1 *}) |
570 | 250 |
done |
251 |
show "(i < j) = (i \<le> j \<and> \<not> j \<le> i)" |
|
252 |
by (auto simp add: less_int_def dest: antisym) |
|
253 |
show "i \<le> i" |
|
254 |
unfolding le_int_def |
|
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
255 |
apply(tactic {* lift_tac @{context} @{thm le_refl_raw} 1 *}) |
570 | 256 |
done |
257 |
show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k" |
|
258 |
unfolding le_int_def |
|
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
259 |
apply(tactic {* lift_tac @{context} @{thm le_trans_raw} 1 *}) |
570 | 260 |
done |
261 |
show "i \<le> j \<or> j \<le> i" |
|
262 |
unfolding le_int_def |
|
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
263 |
apply(tactic {* lift_tac @{context} @{thm le_cases_raw} 1 *}) |
570 | 264 |
done |
265 |
qed |
|
266 |
||
267 |
instantiation int :: distrib_lattice |
|
268 |
begin |
|
269 |
||
270 |
definition |
|
271 |
"(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min" |
|
272 |
||
273 |
definition |
|
274 |
"(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max" |
|
275 |
||
276 |
instance |
|
277 |
by intro_classes |
|
278 |
(auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1) |
|
279 |
||
280 |
end |
|
281 |
||
282 |
lemma le_plus_raw: |
|
283 |
shows "le_raw i j \<Longrightarrow> le_raw (plus_raw k i) (plus_raw k j)" |
|
284 |
by (cases i, cases j, cases k) (simp) |
|
285 |
||
286 |
||
287 |
instance int :: pordered_cancel_ab_semigroup_add |
|
288 |
proof |
|
289 |
fix i j k :: int |
|
290 |
show "i \<le> j \<Longrightarrow> k + i \<le> k + j" |
|
291 |
unfolding le_int_def add_int_def |
|
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
292 |
apply(tactic {* lift_tac @{context} @{thm le_plus_raw} 1 *}) |
570 | 293 |
done |
294 |
qed |
|
295 |
||
296 |
lemma test: |
|
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
297 |
"\<lbrakk>le_raw i j \<and> \<not>i \<approx> j; le_raw (0, 0) k \<and> \<not>(0, 0) \<approx> k\<rbrakk> |
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
298 |
\<Longrightarrow> le_raw (mult_raw k i) (mult_raw k j) \<and> \<not>mult_raw k i \<approx> mult_raw k j" |
570 | 299 |
apply(cases i, cases j, cases k) |
300 |
apply(auto simp add: mult algebra_simps) |
|
301 |
sorry |
|
302 |
||
303 |
||
304 |
text{*The integers form an ordered integral domain*} |
|
305 |
instance int :: ordered_idom |
|
306 |
proof |
|
307 |
fix i j k :: int |
|
308 |
show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j" |
|
309 |
unfolding mult_int_def le_int_def less_int_def Zero_int_def |
|
585
b16cac0b7c88
Fix IntEx2 for equiv_list
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
584
diff
changeset
|
310 |
apply(tactic {* lift_tac @{context} @{thm test} 1 *}) |
579
eac2662a21ec
Solved all quotient goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
570
diff
changeset
|
311 |
done |
570 | 312 |
show "\<bar>i\<bar> = (if i < 0 then -i else i)" |
313 |
by (simp only: zabs_def) |
|
314 |
show "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)" |
|
315 |
by (simp only: zsgn_def) |
|
316 |
qed |
|
317 |
||
318 |
instance int :: lordered_ring |
|
319 |
proof |
|
320 |
fix k :: int |
|
321 |
show "abs k = sup k (- k)" |
|
322 |
by (auto simp add: sup_int_def zabs_def less_minus_self_iff [symmetric]) |
|
323 |
qed |
|
324 |
||
325 |
lemmas int_distrib = |
|
326 |
left_distrib [of "z1::int" "z2" "w", standard] |
|
327 |
right_distrib [of "w::int" "z1" "z2", standard] |
|
328 |
left_diff_distrib [of "z1::int" "z2" "w", standard] |
|
329 |
right_diff_distrib [of "w::int" "z1" "z2", standard] |
|
330 |
||
331 |
||
332 |
subsection {* Embedding of the Integers into any @{text ring_1}: @{text of_int}*} |
|
333 |
||
334 |
(* |
|
335 |
context ring_1 |
|
336 |
begin |
|
337 |
||
338 |
||
339 |
definition |
|
340 |
of_int :: "int \<Rightarrow> 'a" |
|
341 |
where |
|
342 |
"of_int |
|
343 |
*) |
|
344 |
||
345 |
||
346 |
subsection {* Binary representation *} |
|
347 |
||
348 |
text {* |
|
349 |
This formalization defines binary arithmetic in terms of the integers |
|
350 |
rather than using a datatype. This avoids multiple representations (leading |
|
351 |
zeroes, etc.) See @{text "ZF/Tools/twos-compl.ML"}, function @{text |
|
352 |
int_of_binary}, for the numerical interpretation. |
|
353 |
||
354 |
The representation expects that @{text "(m mod 2)"} is 0 or 1, |
|
355 |
even if m is negative; |
|
356 |
For instance, @{text "-5 div 2 = -3"} and @{text "-5 mod 2 = 1"}; thus |
|
357 |
@{text "-5 = (-3)*2 + 1"}. |
|
358 |
||
359 |
This two's complement binary representation derives from the paper |
|
360 |
"An Efficient Representation of Arithmetic for Term Rewriting" by |
|
361 |
Dave Cohen and Phil Watson, Rewriting Techniques and Applications, |
|
362 |
Springer LNCS 488 (240-251), 1991. |
|
363 |
*} |
|
364 |
||
365 |
subsubsection {* The constructors @{term Bit0}, @{term Bit1}, @{term Pls} and @{term Min} *} |
|
366 |
||
367 |
definition |
|
368 |
Pls :: int where |
|
369 |
[code del]: "Pls = 0" |
|
370 |
||
371 |
definition |
|
372 |
Min :: int where |
|
373 |
[code del]: "Min = - 1" |
|
374 |
||
375 |
definition |
|
376 |
Bit0 :: "int \<Rightarrow> int" where |
|
377 |
[code del]: "Bit0 k = k + k" |
|
378 |
||
379 |
definition |
|
380 |
Bit1 :: "int \<Rightarrow> int" where |
|
381 |
[code del]: "Bit1 k = 1 + k + k" |
|
382 |
||
383 |
class number = -- {* for numeric types: nat, int, real, \dots *} |
|
384 |
fixes number_of :: "int \<Rightarrow> 'a" |
|
385 |
||
386 |
use "~~/src/HOL/Tools/numeral.ML" |
|
387 |
||
388 |
syntax |
|
389 |
"_Numeral" :: "num_const \<Rightarrow> 'a" ("_") |
|
390 |
||
391 |
use "~~/src/HOL/Tools/numeral_syntax.ML" |
|
588
2c95d0436a2b
removed usage of HOL_basic_ss by using a slighly extended version of empty_ss
Christian Urban <urbanc@in.tum.de>
parents:
585
diff
changeset
|
392 |
(* |
570 | 393 |
setup NumeralSyntax.setup |
394 |
||
395 |
abbreviation |
|
396 |
"Numeral0 \<equiv> number_of Pls" |
|
397 |
||
398 |
abbreviation |
|
399 |
"Numeral1 \<equiv> number_of (Bit1 Pls)" |
|
400 |
||
401 |
lemma Let_number_of [simp]: "Let (number_of v) f = f (number_of v)" |
|
402 |
-- {* Unfold all @{text let}s involving constants *} |
|
403 |
unfolding Let_def .. |
|
404 |
||
405 |
definition |
|
406 |
succ :: "int \<Rightarrow> int" where |
|
407 |
[code del]: "succ k = k + 1" |
|
408 |
||
409 |
definition |
|
410 |
pred :: "int \<Rightarrow> int" where |
|
411 |
[code del]: "pred k = k - 1" |
|
412 |
||
413 |
lemmas |
|
414 |
max_number_of [simp] = max_def |
|
415 |
[of "number_of u" "number_of v", standard, simp] |
|
416 |
and |
|
417 |
min_number_of [simp] = min_def |
|
418 |
[of "number_of u" "number_of v", standard, simp] |
|
419 |
-- {* unfolding @{text minx} and @{text max} on numerals *} |
|
420 |
||
421 |
lemmas numeral_simps = |
|
422 |
succ_def pred_def Pls_def Min_def Bit0_def Bit1_def |
|
423 |
||
424 |
text {* Removal of leading zeroes *} |
|
425 |
||
426 |
lemma Bit0_Pls [simp, code_post]: |
|
427 |
"Bit0 Pls = Pls" |
|
428 |
unfolding numeral_simps by simp |
|
429 |
||
430 |
lemma Bit1_Min [simp, code_post]: |
|
431 |
"Bit1 Min = Min" |
|
432 |
unfolding numeral_simps by simp |
|
433 |
||
434 |
lemmas normalize_bin_simps = |
|
435 |
Bit0_Pls Bit1_Min |
|
588
2c95d0436a2b
removed usage of HOL_basic_ss by using a slighly extended version of empty_ss
Christian Urban <urbanc@in.tum.de>
parents:
585
diff
changeset
|
436 |
*) |