add readme

This commit is contained in:
filifa 2025-12-11 23:49:35 -05:00
parent b02774e725
commit b7aae4b1f1
1 changed files with 27 additions and 0 deletions

27
README.md Normal file
View File

@ -0,0 +1,27 @@
# mcalc
mcalc is a calculator for modular arithmetic.
## Quirks
### Why can't exponents be expressions? Why do they have to be integers?
This is easiest to explain with an example: what should `2^(3+4)` evaluate to
modulo 7? In my opinion, it should be 2, since `2^7 = 2 (mod 7)`. However,
because all the operators in the calculator are implemented as modular
operators, it will first evaluate `(3+4)` as 0, leading to `2^0 = 1 (mod 7)`. I
saw three options:
1. Leave this behavior in, even if it's not what I think most people would expect.
2. Complicate the code by handling exponent expressions non-modularly.
3. Simply don't let exponents be expressions.
I chose 3.
### Why can't I compute square roots for a composite modulus?
It is certainly possible to compute modular square roots with a composite
modulus, and I would like to add the capability at some point, but as
implemented, the calculator only supports a prime modulus.
### Why is the `ord()` function so slow when the modulus is large?
Partly because computing [multiplicative
order](https://en.wikipedia.org/wiki/Multiplicative_order) is a hard problem,
and partly because I'm too lazy at the moment to implement a slightly more
efficient algorithm.