Skip to content

Commit 1af56fe

Browse files
authored
complex-numbers: Sync docs (#711)
* sync docs * update append file * use exercism/note for the introductory appendix note * add level-two heading in the append file
1 parent 8c2e368 commit 1af56fe

File tree

2 files changed

+97
-20
lines changed

2 files changed

+97
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Instructions append
22

3-
**Note:** The instructions ask for the exponent function because they are synced with a shared repository to maintain consistency across all language tracks.
4-
However, for this exercise in the Clojure track, you don't need to implement it.
3+
## Appendix
4+
5+
~~~~exercism/note
6+
The instructions above are synchronized with a shared repository to ensure consistency across all language tracks.
7+
This appendix provides additional clarification or modifies the instructions as needed to better align with the goals of the Clojure track.
8+
~~~~
9+
10+
For this exercise in the Clojure track, you don't need to implement the exponentiation operation.
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,100 @@
11
# Instructions
22

3-
A complex number is a number in the form `a + b * i` where `a` and `b` are real and `i` satisfies `i^2 = -1`.
3+
A **complex number** is expressed in the form `z = a + b * i`, where:
44

5-
`a` is called the real part and `b` is called the imaginary part of `z`.
6-
The conjugate of the number `a + b * i` is the number `a - b * i`.
7-
The absolute value of a complex number `z = a + b * i` is a real number `|z| = sqrt(a^2 + b^2)`. The square of the absolute value `|z|^2` is the result of multiplication of `z` by its complex conjugate.
5+
- `a` is the **real part** (a real number),
86

9-
The sum/difference of two complex numbers involves adding/subtracting their real and imaginary parts separately:
10-
`(a + i * b) + (c + i * d) = (a + c) + (b + d) * i`,
11-
`(a + i * b) - (c + i * d) = (a - c) + (b - d) * i`.
7+
- `b` is the **imaginary part** (also a real number), and
128

13-
Multiplication result is by definition
14-
`(a + i * b) * (c + i * d) = (a * c - b * d) + (b * c + a * d) * i`.
9+
- `i` is the **imaginary unit** satisfying `i^2 = -1`.
1510

16-
The reciprocal of a non-zero complex number is
17-
`1 / (a + i * b) = a/(a^2 + b^2) - b/(a^2 + b^2) * i`.
11+
## Operations on Complex Numbers
1812

19-
Dividing a complex number `a + i * b` by another `c + i * d` gives:
20-
`(a + i * b) / (c + i * d) = (a * c + b * d)/(c^2 + d^2) + (b * c - a * d)/(c^2 + d^2) * i`.
13+
### Conjugate
2114

22-
Raising e to a complex exponent can be expressed as `e^(a + i * b) = e^a * e^(i * b)`, the last term of which is given by Euler's formula `e^(i * b) = cos(b) + i * sin(b)`.
15+
The conjugate of the complex number `z = a + b * i` is given by:
2316

24-
Implement the following operations:
17+
```text
18+
zc = a - b * i
19+
```
2520

26-
- addition, subtraction, multiplication and division of two complex numbers,
27-
- conjugate, absolute value, exponent of a given complex number.
21+
### Absolute Value
2822

29-
Assume the programming language you are using does not have an implementation of complex numbers.
23+
The absolute value (or modulus) of `z` is defined as:
24+
25+
```text
26+
|z| = sqrt(a^2 + b^2)
27+
```
28+
29+
The square of the absolute value is computed as the product of `z` and its conjugate `zc`:
30+
31+
```text
32+
|z|^2 = z * zc = a^2 + b^2
33+
```
34+
35+
### Addition
36+
37+
The sum of two complex numbers `z1 = a + b * i` and `z2 = c + d * i` is computed by adding their real and imaginary parts separately:
38+
39+
```text
40+
z1 + z2 = (a + b * i) + (c + d * i)
41+
= (a + c) + (b + d) * i
42+
```
43+
44+
### Subtraction
45+
46+
The difference of two complex numbers is obtained by subtracting their respective parts:
47+
48+
```text
49+
z1 - z2 = (a + b * i) - (c + d * i)
50+
= (a - c) + (b - d) * i
51+
```
52+
53+
### Multiplication
54+
55+
The product of two complex numbers is defined as:
56+
57+
```text
58+
z1 * z2 = (a + b * i) * (c + d * i)
59+
= (a * c - b * d) + (b * c + a * d) * i
60+
```
61+
62+
### Reciprocal
63+
64+
The reciprocal of a non-zero complex number is given by:
65+
66+
```text
67+
1 / z = 1 / (a + b * i)
68+
= a / (a^2 + b^2) - b / (a^2 + b^2) * i
69+
```
70+
71+
### Division
72+
73+
The division of one complex number by another is given by:
74+
75+
```text
76+
z1 / z2 = z1 * (1 / z2)
77+
= (a + b * i) / (c + d * i)
78+
= (a * c + b * d) / (c^2 + d^2) + (b * c - a * d) / (c^2 + d^2) * i
79+
```
80+
81+
### Exponentiation
82+
83+
Raising _e_ (the base of the natural logarithm) to a complex exponent can be expressed using Euler's formula:
84+
85+
```text
86+
e^(a + b * i) = e^a * e^(b * i)
87+
= e^a * (cos(b) + i * sin(b))
88+
```
89+
90+
## Implementation Requirements
91+
92+
Given that you should not use built-in support for complex numbers, implement the following operations:
93+
94+
- **addition** of two complex numbers
95+
- **subtraction** of two complex numbers
96+
- **multiplication** of two complex numbers
97+
- **division** of two complex numbers
98+
- **conjugate** of a complex number
99+
- **absolute value** of a complex number
100+
- **exponentiation** of _e_ (the base of the natural logarithm) to a complex number

0 commit comments

Comments
 (0)