From 63a01d6bf136625a6760ea87db6fc171328b604c Mon Sep 17 00:00:00 2001 From: Jegors Cemisovs Date: Fri, 25 Apr 2025 18:02:27 +0300 Subject: [PATCH 1/2] Refine and expand complex number operation instructions Expanded the instructions for complex number operations by providing detailed explanations and examples for addition, subtraction, multiplication, division, conjugate, absolute value, and exponentiation. Clarified implementation requirements and emphasized the use of manual calculations without built-in library support. --- .../complex-numbers/.docs/instructions.md | 105 +++++++++++++++--- 1 file changed, 87 insertions(+), 18 deletions(-) diff --git a/exercises/practice/complex-numbers/.docs/instructions.md b/exercises/practice/complex-numbers/.docs/instructions.md index 50b19aed..0f98cc61 100644 --- a/exercises/practice/complex-numbers/.docs/instructions.md +++ b/exercises/practice/complex-numbers/.docs/instructions.md @@ -1,29 +1,98 @@ # Instructions -A complex number is a number in the form `a + b * i` where `a` and `b` are real and `i` satisfies `i^2 = -1`. +A **complex number** is expressed in the form `z = a + b * i`, where: -`a` is called the real part and `b` is called the imaginary part of `z`. -The conjugate of the number `a + b * i` is the number `a - b * i`. -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. +- `a` is the **real part** (a real number), +- `b` is the **imaginary part** (also a real number), and +- `i` is the **imaginary unit** satisfying `i^2 = -1`. -The sum/difference of two complex numbers involves adding/subtracting their real and imaginary parts separately: -`(a + i * b) + (c + i * d) = (a + c) + (b + d) * i`, -`(a + i * b) - (c + i * d) = (a - c) + (b - d) * i`. +## Operations on Complex Numbers -Multiplication result is by definition -`(a + i * b) * (c + i * d) = (a * c - b * d) + (b * c + a * d) * i`. +### Conjugate -The reciprocal of a non-zero complex number is -`1 / (a + i * b) = a/(a^2 + b^2) - b/(a^2 + b^2) * i`. +The conjugate of the complex number `z = a + b * i` is given by: -Dividing a complex number `a + i * b` by another `c + i * d` gives: -`(a + i * b) / (c + i * d) = (a * c + b * d)/(c^2 + d^2) + (b * c - a * d)/(c^2 + d^2) * i`. +```text +zc = a - b * i +``` -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)`. +### Absolute Value -Implement the following operations: +The absolute value (or modulus) of `z` is defined as: -- addition, subtraction, multiplication and division of two complex numbers, -- conjugate, absolute value, exponent of a given complex number. +```text +|z| = sqrt(a^2 + b^2) +``` -Assume the programming language you are using does not have an implementation of complex numbers. +The square of the absolute value is computed as the product of `z` and its conjugate `zc`: + +```text +|z|^2 = z * zc = a^2 + b^2 +``` + +### Addition + +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: + +```text +z1 + z2 = (a + b * i) + (c + d * i) + = (a + c) + (b + d) * i +``` + +### Subtraction + +The difference of two complex numbers is obtained by subtracting their respective parts: + +```text +z1 - z2 = (a + b * i) - (c + d * i) + = (a - c) + (b - d) * i +``` + +### Multiplication + +The product of two complex numbers is defined as: + +```text +z1 * z2 = (a + b * i) * (c + d * i) + = (a * c - b * d) + (b * c + a * d) * i +``` + +### Reciprocal + +The reciprocal of a non-zero complex number is given by: + +```text +1 / z = 1 / (a + b * i) + = a / (a^2 + b^2) - b / (a^2 + b^2) * i +``` + +### Division + +The division of one complex number by another is given by: + +```text +z1 / z2 = z1 * (1 / z2) + = (a + b * i) / (c + d * i) + = (a * c + b * d) / (c^2 + d^2) + (b * c - a * d) / (c^2 + d^2) * i +``` + +### Exponentiation + +Raising _e_ (the base of the natural logarithm) to a complex exponent can be expressed using Euler's formula: + +```text +e^(a + b * i) = e^a * e^(b * i) + = e^a * (cos(b) + i * sin(b)) +``` + +## Implementation Requirements + +Given that you should not use built-in support for complex numbers, implement the following operations: + +- **addition** of two complex numbers +- **subtraction** of two complex numbers +- **multiplication** of two complex numbers +- **division** of two complex numbers +- **conjugate** of a complex number +- **absolute value** of a complex number +- **exponentiation** of _e_ (the base of the natural logarithm) to a complex number \ No newline at end of file From 372782a9a71883e74644e7d1b32422f96541aa50 Mon Sep 17 00:00:00 2001 From: Jegors Cemisovs Date: Sun, 27 Apr 2025 16:43:56 +0300 Subject: [PATCH 2/2] Clarify formatting in complex numbers instructions Added spacing for better readability in the list describing complex number components. This enhances the clarity of the instructions for users. --- exercises/practice/complex-numbers/.docs/instructions.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exercises/practice/complex-numbers/.docs/instructions.md b/exercises/practice/complex-numbers/.docs/instructions.md index 0f98cc61..2b8a7a49 100644 --- a/exercises/practice/complex-numbers/.docs/instructions.md +++ b/exercises/practice/complex-numbers/.docs/instructions.md @@ -3,7 +3,9 @@ A **complex number** is expressed in the form `z = a + b * i`, where: - `a` is the **real part** (a real number), + - `b` is the **imaginary part** (also a real number), and + - `i` is the **imaginary unit** satisfying `i^2 = -1`. ## Operations on Complex Numbers @@ -95,4 +97,4 @@ Given that you should not use built-in support for complex numbers, implement th - **division** of two complex numbers - **conjugate** of a complex number - **absolute value** of a complex number -- **exponentiation** of _e_ (the base of the natural logarithm) to a complex number \ No newline at end of file +- **exponentiation** of _e_ (the base of the natural logarithm) to a complex number