Explore diophantine equations

From pjt222/agent-almanac · View interactive version

Explore diophantine equations is an AI agent skill from the GitHub repository pjt222/agent-almanac. Solve Diophantine equations (integer-only solutions) including linear, quadratic, and Pell equations. Covers the extended Euclidean algorithm, descent methods, and existence proofs. Use when finding all integer solutions to ax + by = c, solving Pell's equation, generating Pythagorean triples, provin

How to use this skill

Skill file

Explore Diophantine Equations

Solve Diophantine equations — polynomial w/ integer-only solutions. Classify by type, test solvability, find particular + general, generate families. Linear, Pell, Pythagorean, general quadratic.

Use When

In

Do

Step 1: Classify

Determine structure → select method.

  1. Linear: ax + by = c (a, b, c integers, x, y unknown).
  1. Pell: x^2 - Dy^2 = 1 (or -1, or N) (D positive non-square).
  1. Pythagorean: x^2 + y^2 = z^2.
  1. General quadratic: ax^2 + bxy + cy^2 + dx + ey + f = 0.
  1. Higher-order/special: Fermat-type (x^n + y^n = z^n, n > 2), sum of squares, other.

Record classification + method.

→ Precise classification + strategy.

If err: no standard type → try substitution/transformation to known form. x^2 + y^2 + z^2 = n via Legendre's 3-square. No reduction → modular (Step 4).

Step 2: Linear Diophantine (if linear)

Solve ax + by = c for integer x, y.

  1. Compute g = gcd(a, b) via Euclidean.
  1. Test: Solutions iff g | c.
  1. Simplify: Divide by g → (a/g)x + (b/g)y = c/g, gcd(a/g, b/g) = 1.
  1. Particular via extended Euclidean:
  1. General:
  1. Apply constraints (positive solutions):

Example (15x + 21y = 39):

gcd(15, 21) = 3. Does 3 | 39? Yes.
Simplify: 5x + 7y = 13.
Extended Euclidean: 1 = 3*5 - 2*7.
Multiply by 13: 13 = 39*5 - 26*7.
Particular: x0 = 39, y0 = -26.
General: x = 39 + 7k, y = -26 - 5k, k in Z.
Check (k=0): 5*39 + 7*(-26) = 195 - 182 = 13. Correct.

→ General family (x, y) parameterized by k + verified particular.

If err: particular wrong → re-check extended Euclidean back-sub step-by-step. Common: sign mistake. Verify: a * x0 + b * y0 = c exactly (not modulo).

Step 3: Pell (if Pell)

Solve x^2 - Dy^2 = 1 (D positive non-square).

  1. Verify D non-square: D = k^2 → x^2 - k^2*y^2 = (x - ky)(x + ky) = 1 → x - ky = x + ky = ±1 → y = 0, x = ±1 (trivial). Only interesting non-square D.
  1. Continued fraction sqrt(D):
  1. Fundamental from convergents:
  1. Further solutions from (x1, y1):
  1. Present fundamental + recurrence.

Fundamentals small D:

| D | (x1, y1) | D | (x1, y1) | D | (x1, y1) |

|---|---|---|---|---|---|

| 2 | (3, 2) | 7 | (8, 3) | 13 | (649, 180) |

| 3 | (2, 1) | 8 | (3, 1) | 14 | (15, 4) |

| 5 | (9, 4) | 10 | (19, 6) | 15 | (4, 1) |

| 6 | (5, 2) | 11 | (10, 3) | 17 | (33, 8) |

→ Fundamental (x1, y1) verified by substitution + recurrence.

If err: continued fraction no converge to period → check iteration. Period r can be large (D = 61 → r = 11, fundamental (1766319049, 226153980)). Large D → computational tools not manual.

Step 4: Modular Constraints (general quadratic/higher)

Prove no integer solutions via modular obstruction.

  1. Choose modulus m (typ 2, 3, 4, 5, 7, 8, 16).
  1. Enumerate residues: Compute LHS mod m for all possible var residues.
  1. Check combination gives RHS mod m.
  1. Common obstructions:
  1. No obstruction found → modular can't prove non-existence. Solutions may or may not → constructive or descent.

Quadratic residues ref:

| Mod | Squares (residues) |

|---|---|

| 3 | {0, 1} |

| 4 | {0, 1} |

| 5 | {0, 1, 4} |

| 7 | {0, 1, 2, 4} |

| 8 | {0, 1, 4} |

| 11 | {0, 1, 3, 4, 5, 9} |

| 13 | {0, 1, 3, 4, 9, 10, 12} |

| 16 | {0, 1, 4, 9} |

→ Proof non-existence or statement no obstruction at tested moduli.

If err: modular inconclusive → infinite descent: assume solution, derive strictly smaller, repeat → contradict positivity. Classic for x^4 + y^4 = z^2 no non-trivial.

Step 5: Generate Families

Express all solutions via fundamental + integer params.

  1. Linear: x = x0 + (b/g)k, y = y0 - (a/g)k (Step 2).
  1. Pell: Recurrence Step 3 → first several:

```text

(x1, y1), (x2, y2), (x3, y3), ...

```

List ≥3-5 as sanity check.

  1. Pythagorean: Primitive triples from m > n > 0, gcd(m, n) = 1, m - n odd:
  1. General: Parametric if possible. Curve genus 0 → rational parametrization. Genus ≥1 → may be finitely many (Faltings for genus ≥ 2).
  1. Verify ≥3 family members by substitution.

Example (Pell, D = 2):

Fundamental: (x1, y1) = (3, 2). Check: 9 - 2*4 = 1. Correct.
(x2, y2) = (3*3 + 2*2*2, 3*2 + 2*3) = (17, 12). Check: 289 - 2*144 = 1.
(x3, y3) = (3*17 + 2*2*12, 3*12 + 2*17) = (99, 70). Check: 9801 - 2*4900 = 1.

→ Parametric/recursive all solutions + ≥3 verified.

If err: generated fail verification → fundamental or recurrence wrong. Pell → re-derive fundamental from continued fraction. Linear → re-check extended Euclidean.

Check

Traps

→

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.