Guidance Needed for Adding New Test Cases for Complex Number Exercise

Yup, the methods should also be removed from the stub file. Also, yes, you’ll get reputation points once the PR is accepted if you link your GitHub account.

Thank you so much for guiding me through this!

I’ll go ahead and work on the PR. Meanwhile, could you let me know how I can help improve the instructions writeup for this exercise, or any others in the future? I assume this involves writing in Markdown, but please correct me if I’m wrong, and I’d appreciate any tips on how to get started.

Edit: I have successfully located the instructions.md file in the docs folder of the Complex Number exercise in the Java track. However, I understand that changing and submitting a PR for this exercise will only update the instructions for this track. Should I focus solely on these changes, or do you have any suggestions for making updates that would apply across all tracks?

I have successfully completed the changes and submitted the pull request.

Thank you for your invaluable guidance throughout this process!

Thanks for raising the PR @jagdishdrp! I’ll take a look at the PR in a little while. In regards to the instructions.md, what is the proposed change?

instructions.md file is synced across tracks in the problem specifications and we generally encourage a discussion for changes there. However, tracks can also add track specific notes in an instructions.append.md.

Thanks for checking the PR, @kahgoh!

I’m proposing the following changes to instructions.md to improve readability and compatibility, especially on platforms like GitHub where LaTeX syntax isn’t consistently rendered. Here’s the updated markdown:

Instructions

A complex number is expressed in the form:

z = a + b * i

where:

  • a is the real part,
  • b is the imaginary part, and
  • i is the imaginary unit satisfying i^2 = -1.

Key Properties

  1. Conjugate: The conjugate of the complex number z = a + b * i is given by:
z̅ = a - b * i
  1. Absolute Value: The absolute value (or modulus) of z is defined as:
|z| = sqrt(a^2 + b^2)

The square of the absolute value, |z|², can be computed as the product of z and its conjugate:

|z|² = z * z̅ = a² + b²

Operations on Complex Numbers

  1. Addition: The sum of two complex numbers z₁ = a + b * i and z₂ = c + d * i is computed by adding their real and imaginary parts separately:
z₁ + z₂ = (a + c) + (b + d) * i
  1. Subtraction: The difference of two complex numbers is obtained by subtracting their respective parts:
z₁ - z₂ = (a - c) + (b - d) * i
  1. Multiplication: The product of two complex numbers is defined as:
z₁ * z₂ = (a + b * i) * (c + d * i) = (a * c - b * d) + (b * c + a * d) * i
  1. Division: Dividing one complex number by another involves multiplying the numerator and denominator by the conjugate of the denominator:
z₁ / z₂ = (a + b * i) / (c + d * i) = (a * c + b * d) / (c² + d²) + (b * c - a * d) / (c² + d²) * i
  1. Reciprocal: The reciprocal of a non-zero complex number is given by:
1 / z = 1 / (a + b * i) = a / (a² + b²) - b / (a² + b²) * i
  1. Exponentiation: Raising e to a complex exponent can be expressed using Euler’s formula:
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.
  • Calculation of the conjugate of a complex number.
  • Calculation of the absolute value of a complex number.
  • Calculation of the exponent of a given complex number.

This update doesn’t introduce new content; it primarily refines the formatting to make it more consistent and visually accessible across different platforms. I’m not suggesting that the current version is lacking in quality—it’s quite effective as-is. I simply wanted to offer these improvements as a way to give back to Exercism, keeping user experience in mind.

This looks fine to me, but there are a few things I would change:

  • It should mention that a and b are real numbers.
  • e needs clarification, as neither the old nor the new instructions explain what it is.

Edit: The coloring is also a bit inconsistent; I’m not sure what’s up with that.

Sure, I’ll incorporate your suggestions ASAP!

Regarding the coloring, it is not visible in the instructions tab for actual exercises, so it should be acceptable!

Instructions

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.

Key Properties

  1. Conjugate: The conjugate of the complex number z = a + b * i is given by:
z̅ = a - b * i
  1. Absolute Value: The absolute value (or modulus) of z is defined as:
|z| = sqrt(a^2 + b^2)

The square of the absolute value, |z|², can be computed as the product of z and its conjugate:

|z|² = z * z̅ = a² + b²

Operations on Complex Numbers

  1. Addition: The sum of two complex numbers z₁ = a + b * i and z₂ = c + d * i is computed by adding their real and imaginary parts separately:
z₁ + z₂ = (a + c) + (b + d) * i
  1. Subtraction: The difference of two complex numbers is obtained by subtracting their respective parts:
z₁ - z₂ = (a - c) + (b - d) * i
  1. Multiplication: The product of two complex numbers is defined as:
z₁ * z₂ = (a + b * i) * (c + d * i) = (a * c - b * d) + (b * c + a * d) * i
  1. Division: The division of one complex number by another is given by:
z₁ / z₂ = (a + b * i) / (c + d * i) = (a * c + b * d) / (c² + d²) + (b * c - a * d) / (c² + d²) * i
  1. Reciprocal: The reciprocal of a non-zero complex number is given by:
1 / z = 1 / (a + b * i) = a / (a² + b²) - b / (a² + b²) * i
  1. Exponentiation: Raising e (the base of the natural logarithm) to a complex exponent can be expressed using Euler’s formula:
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.
  • Calculation of the conjugate of a complex number.
  • Calculation of the absolute value of a complex number.
  • Calculation of the exponent of a given complex number.

I hope this version reflects your suggestions, @tasx. Since the coloring should not appear in the actual instructions tab, I believe everything is in order!

I would leave out the “approximately equal to 2.71828” since people tend to hardcode numbers. Probably not what we want here.

@mods: Could you please move all posts related to the proposed changes to the instructions into a separate thread? (first one is Guidance Needed for Adding New Test Cases for Complex Number Exercise - #13 by jagdishdrp)

@tasx I’ve made edits to the message based on your suggestion. What do you think of the changes now?

I think the parentheses around e are a bit much. It should look just fine without them, as e is widely recognized. Adding (the base of the natural logarithm) provides extra clarification, which is why I proposed it. You can, however, surround e with underscores to italicize it:

Raising e (the base of the natural logarithm) to a…

I’ve implemented the changes you suggested and edited the file accordingly. Could you please review it once more? How should I proceed with the request to change this? Should I raise a PR in the Java repository, and what about the other tracks?

Sure, I’ll review it one more time.

In the meantime, let’s give everyone else some time to catch up.

Hi @tasx,

I hope you’re doing well! I just wanted to follow up regarding my proposed changes to the Instructions.md file. Since it’s been about 14 hours, I was wondering if you had a chance to review it yet or if there are any updates on the process for raising a PR in the Java repository and the other tracks.

Thank you for your attention to this matter, and I appreciate your help!

One last change I would make is to leave out ‘multiplying the numerator and denominator by the conjugate of the denominator’ and simply mention the formula. This detail isn’t included in the original instructions and delves into unnecessary math. It’s probably best to keep it simple for now.

I’d still wait until the posts related to the instruction edits are moved to a separate thread by the staff. Here are three reasons for this:

  1. The original thread began with changes to the complex numbers tests, which turned out to be specific to the Java track. Now, the thread has shifted to discussing instruction changes not just for the Java track, but for all tracks, making it completely off-topic.
  2. For the above reason, it’s likely that some maintainers are no longer following the thread and may not see the proposed changes.
  3. The PR would need to be submitted to the problem-specifications repo with a link to the corresponding forum thread. Maintainers will likely propose additional changes on GitHub. If approved and merged, track maintainers can then sync the changes to their respective tracks.
1 Like

Thank you @tasx for your feedback on the proposed changes to the Instructions.md file. I’ve made the adjustments you suggested and would like to share a few additional thoughts:

  1. I’ve decided to leave out the detail about “multiplying the numerator and denominator by the conjugate of the denominator” from the division section.
  2. I understand the importance of giving staff (@mods) time to organize the discussion threads. I’ll wait until the posts related to the instruction edits are moved to a separate thread before proceeding further.

I appreciate your guidance through this process, and I look forward to hearing your thoughts!

Additionally, I would like to request your feedback on the other topic threads that I’ve created recently whenever you have time. I am also eager to explore any other ways I could contribute to Exercism, particularly using my current fluency in technologies like Java, HTML, CSS, JavaScript, and he Markdown features I’ve used for creating the Instructions.md file.

1 Like