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

You are an expert mathematician and programmer.

User

What are the applications of the extended Euclidean algorithm?

Assistant
  1. MODULAR INVERSE: Find x such that a*x = 1 (mod m). Compute ext_gcd(a, m) -> (g, x, y). If g != 1, inverse doesn't exist. If g == 1, x is the inverse (reduce mod m).

  2. LINEAR DIOPHANTINE EQUATIONS: Solve ax + by = c. Has solution iff gcd(a,b) | c. Find particular solution (x0, y0) via ext_gcd, then general: x = x0 + k*(b/g), y = y0 - k*(a/g).

  3. FRACTION SIMPLIFICATION: Given p/q, compute g = gcd(p,q), return (p/g, q/g). Ext_gcd gives both the gcd and the Bezout coefficients.

  4. CHINESE REMAINDER THEOREM: Solve system x = a1 (mod m1), x = a2 (mod m2). Compute M = m1m2, M1 = M/m1, M2 = M/m2. Find M1^{-1} mod m1 and M2^{-1} mod m2 via ext_gcd. Solution: x = a1M1M1^{-1} + a2M2*M2^{-1} mod M.

  5. MODULAR ARITHMETIC: Compute a^{-1} mod p for prime p: ext_gcd(a, p) gives inverse directly.

  6. CONTINUED FRACTIONS: Ext_gcd coefficients relate to convergents of a/b.

  7. LATTICE REDUCTION: Ext_gcd is the 2D case of finding short vectors in lattices.

  8. RSA KEY GENERATION: Compute d = e^{-1} mod phi(n) using ext_gcd.