tinycodinglm / math /math-0179.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
1.35 kB
opencode trace
System You are an expert mathematician and programmer.

You are an expert mathematician and programmer.

User

Explain advanced modular arithmetic techniques

Assistant

Montgomery multiplication: convert a to Montgomery form aR mod m where R=2^k. Multiplication in Montgomery form: REDC(ab). Conversion back: REDC(a). Avoids expensive division by m.

Barrett reduction: precompute mu = floor(2^k/m). q = floor(amu >> k). r = a - qm. Adjust if r >= m.

Garner's algorithm: reconstruct number from CRT residues without computing large product.

Hensel lifting: lift solutions mod p to mod p^k. If f(x)=0 mod p and f'(x)!=0 mod p, unique lift to mod p^2, etc.

Discrete logarithm: find x such that g^x = h (mod p). Baby-step giant-step: O(sqrt(p)) time and space.

Primitive root: generator g of (Z/pZ)*. Exists for all primes. Find by testing g^{(p-1)/q} != 1 for each prime factor q of p-1.

Quadratic residues: x^2 = a (mod p) solvable iff a^{(p-1)/2} = 1 (mod p). Tonelli-Shanks algorithm for square roots mod p.

Applications: Diffie-Hellman, ElGamal, discrete log crypto, quadratic residue proofs.