feat: Add complex number support to math.mod function#3566
feat: Add complex number support to math.mod function#3566Aryan2727-debug wants to merge 2 commits intojosdejong:developfrom
Conversation
|
Thanks for your interest in mathjs! First a piece of advice: if you are going to try to use AI to submit pull requests to open-source projects, you may find that it actually takes more of your time than just understanding the code base yourself and making appropriate changes. That said, if you would like to make your own personal effort to hammer this starting point into shape, here are some first things to attend to. Note you should not expect this to be a complete list; this submission is not really ready for review.
Thanks in advance for your efforts; if you prefer not to put in the personal effort to transform this initial submission into one coherent with the mathjs codebase, please just close this PR. |
|
@Aryan2727-debug have you seen the feedback from Glen? Please let me know if you have questions or need help. |
Description
This PR implements support for complex numbers in the
math.modfunction using Gaussian integer division semantics.Problem Solved
Previously,
math.modwould throw a TypeError when given complex number inputs. This prevented users from performing modular arithmetic operations with complex numbers.Implementation
Complex, Complexsignature to the mod functionw/zfor complex inputswandzr = w - z*qwherenorm(r) < norm(z)Mathematical Properties
wandz≠0, findsqandrsuch thatw = z*q + rnorm(r) < norm(z)wherenorm(a+bi) = a² + b²Examples