12733
|
1 |
(* Title: HOL/Real/Complex_Numbers.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Gertrud Bauer and Markus Wenzel, TU München
|
|
4 |
License: GPL (GNU GENERAL PUBLIC LICENSE)
|
|
5 |
*)
|
|
6 |
|
|
7 |
header {* Complex numbers *}
|
|
8 |
|
|
9 |
theory Complex_Numbers = RealPow + Ring_and_Field:
|
|
10 |
|
|
11 |
subsection {* The field of real numbers *} (* FIXME move *)
|
|
12 |
|
12740
|
13 |
instance real :: field
|
|
14 |
by intro_classes (simp_all add: real_add_mult_distrib real_divide_def)
|
12733
|
15 |
|
12740
|
16 |
lemma real_power_two: "(r::real)\<twosuperior> = r * r"
|
12733
|
17 |
by (simp add: numeral_2_eq_2)
|
|
18 |
|
12740
|
19 |
lemma real_sqr_ge_zero [iff]: "0 \<le> (r::real)\<twosuperior>"
|
12733
|
20 |
by (simp add: real_power_two)
|
|
21 |
|
12740
|
22 |
lemma real_sqr_gt_zero: "(r::real) \<noteq> 0 ==> 0 < r\<twosuperior>"
|
12733
|
23 |
proof -
|
|
24 |
assume "r \<noteq> 0"
|
12740
|
25 |
hence "0 \<noteq> r\<twosuperior>" by simp
|
|
26 |
also have "0 \<le> r\<twosuperior>" by (simp add: real_sqr_ge_zero)
|
12733
|
27 |
finally show ?thesis .
|
|
28 |
qed
|
|
29 |
|
12740
|
30 |
lemma real_sqr_not_zero: "r \<noteq> 0 ==> (r::real)\<twosuperior> \<noteq> 0"
|
12733
|
31 |
by simp
|
|
32 |
|
|
33 |
|
12740
|
34 |
subsection {* Representation of complex numbers *}
|
12733
|
35 |
|
|
36 |
datatype complex = Complex real real
|
|
37 |
|
12740
|
38 |
consts Re :: "complex => real"
|
12733
|
39 |
primrec "Re (Complex x y) = x"
|
|
40 |
|
12740
|
41 |
consts Im :: "complex => real"
|
12733
|
42 |
primrec "Im (Complex x y) = y"
|
|
43 |
|
12740
|
44 |
lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
|
|
45 |
by (induct z) simp
|
12733
|
46 |
|
|
47 |
instance complex :: zero ..
|
|
48 |
instance complex :: one ..
|
|
49 |
instance complex :: number ..
|
|
50 |
instance complex :: plus ..
|
|
51 |
instance complex :: minus ..
|
|
52 |
instance complex :: times ..
|
|
53 |
instance complex :: inverse ..
|
|
54 |
|
|
55 |
defs (overloaded)
|
|
56 |
zero_complex_def: "0 == Complex 0 0"
|
|
57 |
one_complex_def: "1 == Complex 1 0"
|
|
58 |
number_of_complex_def: "number_of b == Complex (number_of b) 0"
|
|
59 |
add_complex_def: "z + w == Complex (Re z + Re w) (Im z + Im w)"
|
|
60 |
minus_complex_def: "z - w == Complex (Re z - Re w) (Im z - Im w)"
|
|
61 |
uminus_complex_def: "- z == Complex (- Re z) (- Im z)"
|
|
62 |
mult_complex_def: "z * w ==
|
|
63 |
Complex (Re z * Re w - Im z * Im w) (Re z * Im w + Im z * Re w)"
|
12740
|
64 |
inverse_complex_def: "(z::complex) \<noteq> 0 ==> inverse z ==
|
|
65 |
Complex (Re z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>)) (- Im z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>))"
|
|
66 |
divide_complex_def: "(w::complex) \<noteq> 0 ==> z / (w::complex) == z * inverse w"
|
12733
|
67 |
|
12740
|
68 |
lemma complex_equality [intro?]: "Re z = Re w ==> Im z = Im w ==> z = w"
|
12733
|
69 |
by (induct z, induct w) simp
|
|
70 |
|
|
71 |
lemma Re_zero [simp]: "Re 0 = 0"
|
|
72 |
and Im_zero [simp]: "Im 0 = 0"
|
|
73 |
by (simp_all add: zero_complex_def)
|
|
74 |
|
|
75 |
lemma Re_one [simp]: "Re 1 = 1"
|
|
76 |
and Im_one [simp]: "Im 1 = 0"
|
|
77 |
by (simp_all add: one_complex_def)
|
|
78 |
|
|
79 |
lemma Re_add [simp]: "Re (z + w) = Re z + Re w"
|
|
80 |
by (simp add: add_complex_def)
|
|
81 |
|
|
82 |
lemma Im_add [simp]: "Im (z + w) = Im z + Im w"
|
|
83 |
by (simp add: add_complex_def)
|
|
84 |
|
|
85 |
lemma Re_diff [simp]: "Re (z - w) = Re z - Re w"
|
|
86 |
by (simp add: minus_complex_def)
|
|
87 |
|
|
88 |
lemma Im_diff [simp]: "Im (z - w) = Im z - Im w"
|
|
89 |
by (simp add: minus_complex_def)
|
|
90 |
|
12740
|
91 |
lemma Re_uminus [simp]: "Re (-z) = - Re z"
|
12733
|
92 |
by (simp add: uminus_complex_def)
|
|
93 |
|
12740
|
94 |
lemma Im_uminus [simp]: "Im (-z) = - Im z"
|
12733
|
95 |
by (simp add: uminus_complex_def)
|
|
96 |
|
|
97 |
lemma Re_mult [simp]: "Re (z * w) = Re z * Re w - Im z * Im w"
|
|
98 |
by (simp add: mult_complex_def)
|
|
99 |
|
|
100 |
lemma Im_mult [simp]: "Im (z * w) = Re z * Im w + Im z * Re w"
|
|
101 |
by (simp add: mult_complex_def)
|
|
102 |
|
12740
|
103 |
lemma zero_complex_iff: "(z = 0) = (Re z = 0 \<and> Im z = 0)"
|
|
104 |
and one_complex_iff: "(z = 1) = (Re z = 1 \<and> Im z = 0)"
|
|
105 |
by (auto simp add: complex_equality)
|
12733
|
106 |
|
|
107 |
|
12740
|
108 |
subsection {* The field of complex numbers *}
|
|
109 |
|
12733
|
110 |
instance complex :: field
|
|
111 |
proof
|
|
112 |
fix z u v w :: complex
|
|
113 |
show "(u + v) + w = u + (v + w)"
|
|
114 |
by (simp add: add_complex_def)
|
|
115 |
show "z + w = w + z"
|
|
116 |
by (simp add: add_complex_def)
|
|
117 |
show "0 + z = z"
|
|
118 |
by (simp add: add_complex_def zero_complex_def)
|
12740
|
119 |
show "-z + z = 0"
|
|
120 |
by (simp add: complex_equality minus_complex_def)
|
|
121 |
show "z - w = z + -w"
|
12733
|
122 |
by (simp add: add_complex_def minus_complex_def uminus_complex_def)
|
|
123 |
show "(u * v) * w = u * (v * w)"
|
|
124 |
by (simp add: mult_complex_def ring_mult_ac ring_distrib real_diff_def) (* FIXME *)
|
|
125 |
show "z * w = w * z"
|
|
126 |
by (simp add: mult_complex_def)
|
|
127 |
show "1 * z = z"
|
|
128 |
by (simp add: one_complex_def mult_complex_def)
|
|
129 |
show "(u + v) * w = u * w + v * w"
|
|
130 |
by (simp add: add_complex_def mult_complex_def ring_distrib)
|
|
131 |
assume neq: "w \<noteq> 0"
|
12740
|
132 |
thus "z / w = z * inverse w"
|
|
133 |
by (simp add: divide_complex_def)
|
12733
|
134 |
show "inverse w * w = 1"
|
|
135 |
proof
|
|
136 |
have neq': "Re w * Re w + Im w * Im w \<noteq> 0"
|
|
137 |
proof -
|
|
138 |
have ge: "0 \<le> Re w * Re w" "0 \<le> Im w * Im w" by simp_all
|
|
139 |
from neq have "Re w \<noteq> 0 \<or> Im w \<noteq> 0" by (simp add: zero_complex_iff)
|
|
140 |
hence "Re w * Re w \<noteq> 0 \<or> Im w * Im w \<noteq> 0" by simp
|
|
141 |
thus ?thesis by rule (insert ge, arith+)
|
|
142 |
qed
|
|
143 |
with neq show "Re (inverse w * w) = Re 1"
|
|
144 |
by (simp add: inverse_complex_def real_power_two real_add_divide_distrib [symmetric])
|
|
145 |
from neq show "Im (inverse w * w) = Im 1"
|
|
146 |
by (simp add: inverse_complex_def real_power_two
|
|
147 |
real_mult_ac real_add_divide_distrib [symmetric])
|
|
148 |
qed
|
|
149 |
qed
|
|
150 |
|
|
151 |
|
12740
|
152 |
subsection {* Basic operations *}
|
|
153 |
|
|
154 |
instance complex :: power ..
|
|
155 |
primrec (power_complex)
|
|
156 |
"z ^ 0 = 1"
|
|
157 |
"z ^ Suc n = (z::complex) * (z ^ n)"
|
|
158 |
|
|
159 |
lemma complex_power_two: "z\<twosuperior> = z * (z::complex)"
|
|
160 |
by (simp add: complex_equality numeral_2_eq_2)
|
|
161 |
|
|
162 |
|
|
163 |
constdefs
|
|
164 |
im_unit :: complex ("\<i>")
|
|
165 |
"\<i> == Complex 0 1"
|
|
166 |
|
|
167 |
lemma im_unit_square: "\<i>\<twosuperior> = -1"
|
12733
|
168 |
by (simp add: im_unit_def complex_power_two mult_complex_def number_of_complex_def)
|
|
169 |
|
12740
|
170 |
|
|
171 |
constdefs
|
|
172 |
conjg :: "complex => complex"
|
|
173 |
"conjg z == Complex (Re z) (- Im z)"
|
|
174 |
|
|
175 |
lemma Re_cong [simp]: "Re (conjg z) = Re z"
|
|
176 |
by (simp add: conjg_def)
|
|
177 |
|
|
178 |
lemma Im_cong [simp]: "Im (conjg z) = - Im z"
|
|
179 |
by (simp add: conjg_def)
|
|
180 |
|
|
181 |
lemma Re_conjg_self: "Re (z * conjg z) = (Re z)\<twosuperior> + (Im z)\<twosuperior>"
|
|
182 |
by (simp add: real_power_two)
|
|
183 |
|
|
184 |
lemma Im_conjg_self: "Im (z * conjg z) = 0"
|
|
185 |
by simp
|
|
186 |
|
|
187 |
|
|
188 |
subsection {* Embedding other number domains *}
|
|
189 |
|
|
190 |
constdefs
|
|
191 |
complex :: "'a => complex"
|
|
192 |
"complex x == Complex (real x) 0";
|
|
193 |
|
|
194 |
lemma Re_complex [simp]: "Re (complex x) = real x"
|
|
195 |
by (simp add: complex_def)
|
|
196 |
|
12733
|
197 |
end
|