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

Create modular multiplicative inverse and exponentiation components #141

Open
rogness opened this issue Apr 8, 2024 · 1 comment
Open

Comments

@rogness
Copy link

rogness commented Apr 8, 2024

We have the <mod> component, which calls the mod command from math.js. In DoenetML,

<mod>8 3</mod>

is mapped (I presume?) to math.mod(8,3) in math.js, and returns 1.

This request is implement the `math.invmod(a,b)' command in DoenetML as well. The component

<invmod>7 13</invmod>

would call math.invmod(7,13) and return 2.

(I don't have strong feelings about whether the component is named <invmod> or <modinv> or something else. -- I used <invmod> above for consistency with math.js.)

@rogness rogness changed the title Create Modular Multiplicative Inverse Component Create modular multiplicative inverse and exponentiation components Apr 8, 2024
@rogness
Copy link
Author

rogness commented Apr 8, 2024

...and while I'm asking, it would be really helpful to have fast modular exponentiation implemented. That's slightly more involved, because (surprisingly?) it doesn't exist in math.js. However, there are short javascript implementations of various algorithms all over the place, e.g.

https://stackoverflow.com/questions/66459806/javascript-number-too-big-for-modulo

https://umaranis.com/2018/07/12/calculate-modular-exponentiation-powermod-in-javascript-ap-n/

Following the syntax of the <mod> component, I'd imagine something like <PowerMod>999 17 23</PowerMod> to compute 999^17 % 23. (Theoretically I suppose the exponent and modulus could be defined via attributes or children, as well, but that would be a shift from the existing syntax?)

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

1 participant