Motivation
QUADRATIC DIOPHANTINE EQUATIONS (P227) from Garey & Johnson, A7 AN8. An NP-complete number-theoretic problem: given positive integers a, b, c, determine whether there exist positive integers x and y such that ax^2 + by = c. This result by Manders and Adleman (1978) is a landmark in computational complexity, showing that even simple Diophantine equations with just two unknowns and degree two are NP-complete. This contrasts with the polynomial-time solvability of purely linear Diophantine equations (sum of a_ix_i = c) and pure power equations (ax^k = c). The general Diophantine problem (arbitrary polynomial, arbitrary many variables) is undecidable (Matiyasevich's theorem, extending MRDP), but restricting to a single nonlinear variable keeps the problem in NP.
Associated reduction rules:
Definition
Name: QuadraticDiophantineEquations
Reference: Garey & Johnson, Computers and Intractability, A7 AN8
Mathematical definition:
INSTANCE: Positive integers a, b, and c.
QUESTION: Are there positive integers x and y such that ax^2 + by = c?
Variables
- Count: 1 (the quadratic unknown x; the linear unknown y is determined by x)
- Per-variable domain:
- x: {1, 2, ..., floor(sqrt(c/a))} -- since ax^2 <= c, x is bounded by sqrt(c/a)
- Meaning: x is the variable appearing quadratically in the equation. Given x, the linear variable y = (c - ax^2) / b is uniquely determined; a configuration is feasible iff (c - ax^2) > 0 and (c - a*x^2) mod b == 0 (yielding a positive integer y).
dims() implementation: vec![floor(sqrt(c / a)) as usize] -- config [i] maps to x = i + 1 (1-indexed). The brute-force solver enumerates only x; y is derived, not searched.
Schema (data type)
Type name: QuadraticDiophantineEquations
Variants: none (operates on three positive integers)
| Field |
Type |
Description |
a |
u64 |
Coefficient of x^2 |
b |
u64 |
Coefficient of y |
c |
u64 |
Right-hand side constant |
Size fields (getters): a, b, c -- the three coefficients are the natural size parameters. Reduction overhead expressions reference these directly (e.g., rule #560 derives bit_length_b = O(n log n) from the product of n primes encoded in b).
Complexity
- Best known exact algorithm: For each candidate x in {1, ..., floor(sqrt(c/a))}, check if (c - ax^2) is positive and divisible by b, yielding y = (c - ax^2)/b. This runs in O(sqrt(c/a) * polylog(c)) time, which is pseudo-polynomial. The problem is NP-complete because c (and hence sqrt(c/a)) can be exponential in the input bit-length. Purely linear Diophantine equations are solvable in polynomial time using the extended Euclidean algorithm. The NP-hardness comes from the interaction of the quadratic term with the linear term and the positivity constraints. [Manders and Adleman, JCSS 16:168-184, 1978.]
- Complexity string:
"sqrt(c)"
Extra Remark
Full book text:
INSTANCE: Positive integers a, b, and c.
QUESTION: Are there positive integers x and y such that ax^2 + by = c?
Reference: [Manders and Adleman, 1978]. Transformation from 3SAT.
Comment: Diophantine equations of the forms ax^k = c and Sigma_{i=1}^{k} a_i*x_i = c are solvable in polynomial time for arbitrary values of k. The general Diophantine problem, "Given a polynomial with integer coefficients in k variables, does it have an integer solution?" is undecidable, even for k = 13 [Matijasevic and Robinson, 1975]. However, the given problem can be generalized considerably (to simultaneous equations in many variables) while remaining in NP, so long as only one variable enters into the equations in a non-linear way (see [Gurari and Ibarra, 1978]).
How to solve
Example Instance
Input:
a = 3, b = 5, c = 53
Question: Are there positive integers x, y with 3x^2 + 5y = 53?
Solution search:
- dims() = [floor(sqrt(53/3))] = [4], so x ranges from 1 to 4 (config indices 0..3).
- x = 1 (config [0]): 3*1 + 5y = 53 => 5y = 50 => y = 10. YES! (x=1, y=10)
- x = 2 (config [1]): 3*4 + 5y = 53 => 5y = 41 => y = 8.2. Not integer.
- x = 3 (config [2]): 3*9 + 5y = 53 => 5y = 26 => y = 5.2. Not integer.
- x = 4 (config [3]): 3*16 + 5y = 53 => 5y = 5 => y = 1. YES! (x=4, y=1)
Answer: YES. Two solutions: (x=1, y=10) and (x=4, y=1).
Verification of (x=4, y=1): 3*(4^2) + 5*1 = 48 + 5 = 53 = c.
Negative example:
a = 3, b = 5, c = 10
- dims() = [floor(sqrt(10/3))] = [1], so x = 1 only.
- x = 1: 3 + 5y = 10 => 5y = 7 => y = 1.4. Not integer.
- No solution exists. Answer: NO.
Motivation
QUADRATIC DIOPHANTINE EQUATIONS (P227) from Garey & Johnson, A7 AN8. An NP-complete number-theoretic problem: given positive integers a, b, c, determine whether there exist positive integers x and y such that ax^2 + by = c. This result by Manders and Adleman (1978) is a landmark in computational complexity, showing that even simple Diophantine equations with just two unknowns and degree two are NP-complete. This contrasts with the polynomial-time solvability of purely linear Diophantine equations (sum of a_ix_i = c) and pure power equations (ax^k = c). The general Diophantine problem (arbitrary polynomial, arbitrary many variables) is undecidable (Matiyasevich's theorem, extending MRDP), but restricting to a single nonlinear variable keeps the problem in NP.
Associated reduction rules:
Definition
Name:
QuadraticDiophantineEquationsReference: Garey & Johnson, Computers and Intractability, A7 AN8
Mathematical definition:
INSTANCE: Positive integers a, b, and c.
QUESTION: Are there positive integers x and y such that ax^2 + by = c?
Variables
dims()implementation:vec![floor(sqrt(c / a)) as usize]-- config[i]maps to x = i + 1 (1-indexed). The brute-force solver enumerates only x; y is derived, not searched.Schema (data type)
Type name:
QuadraticDiophantineEquationsVariants: none (operates on three positive integers)
au64bu64cu64Size fields (getters):
a,b,c-- the three coefficients are the natural size parameters. Reduction overhead expressions reference these directly (e.g., rule #560 derivesbit_length_b = O(n log n)from the product of n primes encoded inb).Complexity
"sqrt(c)"Extra Remark
Full book text:
INSTANCE: Positive integers a, b, and c.
QUESTION: Are there positive integers x and y such that ax^2 + by = c?
Reference: [Manders and Adleman, 1978]. Transformation from 3SAT.
Comment: Diophantine equations of the forms ax^k = c and Sigma_{i=1}^{k} a_i*x_i = c are solvable in polynomial time for arbitrary values of k. The general Diophantine problem, "Given a polynomial with integer coefficients in k variables, does it have an integer solution?" is undecidable, even for k = 13 [Matijasevic and Robinson, 1975]. However, the given problem can be generalized considerably (to simultaneous equations in many variables) while remaining in NP, so long as only one variable enters into the equations in a non-linear way (see [Gurari and Ibarra, 1978]).
How to solve
Example Instance
Input:
a = 3, b = 5, c = 53
Question: Are there positive integers x, y with 3x^2 + 5y = 53?
Solution search:
Answer: YES. Two solutions: (x=1, y=10) and (x=4, y=1).
Verification of (x=4, y=1): 3*(4^2) + 5*1 = 48 + 5 = 53 = c.
Negative example:
a = 3, b = 5, c = 10