Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Complex Numbers in Scope #33

Open
sigmasternchen opened this issue Dec 12, 2024 · 6 comments
Open

Question: Complex Numbers in Scope #33

sigmasternchen opened this issue Dec 12, 2024 · 6 comments

Comments

@sigmasternchen
Copy link

Hi there. o/

I recently worked on a project that required complex numbers, but I wasn't able to find any existing library for them.

So, I wanted to ask: Are complex numbers in the scope of this project?
If so, I would be happy to contribute.

Thanks in advance,
Sigma

@NicklasXYZ
Copy link
Member

Hello :)

So, I wanted to ask: Are complex numbers in the scope of this project? If so, I would be happy to contribute.

I would say yes, it could definitely be a nice addition to the library.
I think we'd just need to figure out how to design the API and integrate the additional set of functions for complex numbers nicely with the current structure of the library.

Maybe a separate 'cmath' module could work mirroring the naming of functions in the current 'math' module? I think @hayleigh-dot-dev would probably have more expertise in this area :)

Best, Nicklas

@hayleigh-dot-dev
Copy link
Member

I think a gleam_community/maths/complex module that mirrors the api for complex numbers could be good!

@sigmasternchen
Copy link
Author

I quickly went through the maths API. The relevant functions should be:

  • weighted_sum
  • weighted_product
  • cumulative_sum
  • cumulative_product
  • exponential
  • nth_root
  • absolute_difference
  • mean
  • median
  • is_close
  • all_close
  • arange
  • linear_space
  • logarithmic_space
  • geometric_space

For the rounding functions, we could have 2 precision parameters:

  • round_to_nearest
  • round_ties_away
  • round_ties_up
  • round_to_zero
  • round_down
  • round_up

Some relevant functions that probably need a different name:

  • from_polar (instead of polar_to_cartesian)
  • to_polar (instead of cartesian_to_polar)

Relevant function where I don't know how to implement them:

  • logarithm (and related functions)
  • sign (and related functions - maybe something for quadrants?)
  • gamma (and related functions)

From the stdlib float package, this would be interesting:

  • absolute_value
  • add
  • divide
  • loosely_equals
  • multiply
  • power
  • product
  • random
  • square_root
  • subtract
  • sum
  • to_string

Some additional functions:

  • conjugate
  • argument
  • compare_real
  • compare_imaginary
  • compare_absolute_value
  • compare_argument

What do you think?

@NicklasXYZ
Copy link
Member

Thank you for spending the time going through the current API and finding the relevant functions to implement for complex numbers :)

For a start I think it could make sense to implement the functions in stages. For example, we could start with the ones that are more stright-forward to implement, then later dicuss some of the more non-trivial ones. I am thinking the following functions could be suitable to start with:

  • add
  • subtract
  • multiply
  • divide
  • power
  • square_root
  • nth_root
  • absolute_value
  • sum
  • product
  • weighted_sum
  • weighted_product
  • cumulative_sum
  • cumulative_product
  • exponential
  • absolute_difference
  • mean
  • median
  • is_close (similar to loosely_equal, but also with a relative tolerance specified)
  • all_close
  • to_polar (rename in the maths module)
  • from_polar (move from maths to the new maths/complex module)
  • compare_real
  • compare_imaginary
  • conjugate
  • argument
  • to_string

We can then later discuss and have a look at:

  • the rounding functions
  • logarithm
  • sign
  • gamma
  • random
  • compare_absolute_value
  • arrange
  • linear_space
  • logarithmic_space
  • geometric_space

@sigmasternchen
Copy link
Author

Sounds good! I'm happy to work on an initial version.

However, just to manage expectations: I'm on holiday over Christmas, so it might be a few weeks until I have something ready.

@NicklasXYZ
Copy link
Member

Sounds good! I'm happy to work on an initial version.

However, just to manage expectations: I'm on holiday over Christmas, so it might be a few weeks until I have something ready.

Awesome!
That is completely fine, no worries :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants