11 imports "../Hyperreal/Transcendental" |
11 imports "../Hyperreal/Transcendental" |
12 begin |
12 begin |
13 |
13 |
14 datatype complex = Complex real real |
14 datatype complex = Complex real real |
15 |
15 |
16 instance complex :: "{zero, one, plus, times, minus, inverse, power}" .. |
16 definition |
17 |
|
18 consts |
|
19 "ii" :: complex ("\<i>") |
17 "ii" :: complex ("\<i>") |
|
18 where |
|
19 i_def: "ii == Complex 0 1" |
20 |
20 |
21 consts Re :: "complex => real" |
21 consts Re :: "complex => real" |
22 primrec Re: "Re (Complex x y) = x" |
22 primrec Re: "Re (Complex x y) = x" |
23 |
23 |
24 consts Im :: "complex => real" |
24 consts Im :: "complex => real" |
25 primrec Im: "Im (Complex x y) = y" |
25 primrec Im: "Im (Complex x y) = y" |
26 |
26 |
27 lemma complex_surj [simp]: "Complex (Re z) (Im z) = z" |
27 lemma complex_surj [simp]: "Complex (Re z) (Im z) = z" |
28 by (induct z) simp |
28 by (induct z) simp |
29 |
29 |
30 defs (overloaded) |
30 instance complex :: zero |
31 |
|
32 complex_zero_def: |
31 complex_zero_def: |
33 "0 == Complex 0 0" |
32 "0 == Complex 0 0" .. |
34 |
33 |
|
34 instance complex :: one |
35 complex_one_def: |
35 complex_one_def: |
36 "1 == Complex 1 0" |
36 "1 == Complex 1 0" .. |
37 |
37 |
38 i_def: "ii == Complex 0 1" |
38 instance complex :: plus |
39 |
39 complex_add_def: |
|
40 "z + w == Complex (Re z + Re w) (Im z + Im w)" .. |
|
41 |
|
42 instance complex :: minus |
40 complex_minus_def: "- z == Complex (- Re z) (- Im z)" |
43 complex_minus_def: "- z == Complex (- Re z) (- Im z)" |
41 |
44 complex_diff_def: |
|
45 "z - w == z + - (w::complex)" .. |
|
46 |
|
47 instance complex :: times |
|
48 complex_mult_def: |
|
49 "z * w == Complex (Re z * Re w - Im z * Im w) (Re z * Im w + Im z * Re w)" .. |
|
50 |
|
51 instance complex :: inverse |
42 complex_inverse_def: |
52 complex_inverse_def: |
43 "inverse z == |
53 "inverse z == |
44 Complex (Re z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>)) (- Im z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>))" |
54 Complex (Re z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>)) (- Im z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>))" |
45 |
55 complex_divide_def: "w / (z::complex) == w * inverse z" .. |
46 complex_add_def: |
|
47 "z + w == Complex (Re z + Re w) (Im z + Im w)" |
|
48 |
|
49 complex_diff_def: |
|
50 "z - w == z + - (w::complex)" |
|
51 |
|
52 complex_mult_def: |
|
53 "z * w == Complex (Re z * Re w - Im z * Im w) (Re z * Im w + Im z * Re w)" |
|
54 |
|
55 complex_divide_def: "w / (z::complex) == w * inverse z" |
|
56 |
56 |
57 |
57 |
58 lemma complex_equality [intro?]: "Re z = Re w ==> Im z = Im w ==> z = w" |
58 lemma complex_equality [intro?]: "Re z = Re w ==> Im z = Im w ==> z = w" |
59 by (induct z, induct w) simp |
59 by (induct z, induct w) simp |
60 |
60 |