-
Notifications
You must be signed in to change notification settings - Fork 3
[Model] QuadraticCongruences #536
Description
Motivation
QUADRATIC CONGRUENCES (P220) from Garey & Johnson, A7 AN1. A classical NP-complete problem in number theory: given positive integers a, b, c, determine if there exists a positive integer x < c with x² ≡ a (mod b). The problem is NP-complete due to the upper bound constraint x < c; without this bound, the problem is polynomial-time solvable given the factorization of b. This is a cornerstone result by Manders and Adleman (1978) connecting computational complexity to quadratic residuosity.
Associated reduction rules:
- R164: 3SAT → QuadraticCongruences (this model is the target)
Definition
Name: QuadraticCongruences
Reference: Garey & Johnson, Computers and Intractability, A7 AN1
Mathematical definition:
INSTANCE: Positive integers a, b, and c.
QUESTION: Is there a positive integer x with 1 ≤ x < c such that x² ≡ a (mod b)?
This is a satisfaction (feasibility) problem: Value = Or.
Variables
- Count: 1 (the unknown x)
- Per-variable domain: c − 1 (values 1, 2, …, c − 1)
- Meaning: The single variable represents the candidate integer x. The evaluate function checks whether x² mod b = a.
dims() returns [c - 1].
Note: When c is large (exponential in the input bit-length), the brute-force search space is correspondingly large. The dims() contract is satisfied (c − 1 fits in usize for representable instances), but brute-force may be impractical for large c. This is expected for an NP-complete problem — the NP-completeness arises precisely from the exponential range of c relative to input size.
Schema (data type)
Type name: QuadraticCongruences
Variants: none (operates on three positive integers)
| Field | Type | Description | Getter |
|---|---|---|---|
a |
u64 |
Target residue (x² ≡ a mod b) | a() |
b |
u64 |
Modulus | b() |
c |
u64 |
Upper bound on x (exclusive); 1 ≤ x < c | c() |
Problem type: Satisfaction (feasibility)
Value type: Or
Complexity
- Decision complexity: NP-complete (Manders & Adleman, 1978; transformation from 3SAT). Remains NP-complete even if the prime factorization of b and solutions modulo all prime powers are given.
- Best known exact algorithm: Brute-force enumeration of x ∈ {1, …, c−1}, checking x² mod b = a. Time O(c · polylog(b)), which is pseudo-polynomial.
- Complexity string for
declare_variants!:"c"(brute-force iterates over all x < c) - Special cases:
- c = ∞ (no upper bound) with factorization of b given: polynomial (CRT + Hensel lifting)
- b prime, assuming ERH: polynomial (Tonelli-Shanks algorithm)
- References:
- [Manders & Adleman, 1978] K. Manders and L. Adleman, "NP-complete decision problems for binary quadratics", JCSS 16(2), pp. 168-184, 1978.
Extra Remark
Full book text:
INSTANCE: Positive integers a, b, and c.
QUESTION: Is there a positive integer x < c such that x^2 ≡ a (mod b)?
Reference: [Manders and Adleman, 1978]. Transformation from 3SAT.
Comment: Remains NP-complete even if the instance includes a prime factorization of b and solutions to the congruence modulo all prime powers occurring in the factorization. Solvable in polynomial time if c = ∞ (i.e., there is no upper bound on x) and the prime factorization of b is given. Assuming the Extended Riemann Hypothesis, the problem is solvable in polynomial time when b is prime. The general problem is trivially solvable in pseudo-polynomial time.
How to solve
- It can be solved by (existing) bruteforce. Enumerate x from 1 to c−1; check if x² mod b = a. For small c this is fast; for large c it may be impractical.
- It can be solved by reducing to integer programming. (The constraint x² ≡ a (mod b) is quadratic, not directly expressible as a linear constraint.)
- Other: For special cases (b prime, c = ∞), polynomial-time algorithms exist (Tonelli-Shanks, CRT + Hensel lifting).
Example Instance
Positive example (YES):
a = 4, b = 15, c = 10
Question: Is there x ∈ {1, 2, …, 9} with x² ≡ 4 (mod 15)?
Solution search:
| x | x² | x² mod 15 | Match? |
|---|---|---|---|
| 1 | 1 | 1 | No |
| 2 | 4 | 4 | Yes ✓ |
| 3 | 9 | 9 | No |
| 4 | 16 | 1 | No |
| 5 | 25 | 10 | No |
| 6 | 36 | 6 | No |
| 7 | 49 | 4 | Yes ✓ |
| 8 | 64 | 4 | Yes ✓ |
| 9 | 81 | 6 | No |
Answer: Or(true). Three solutions exist: x = 2, x = 7, x = 8. Six non-solutions provide meaningful negative coverage.
Verification: 2² = 4 ≡ 4 (mod 15) ✓; 7² = 49 = 3·15 + 4 ✓; 8² = 64 = 4·15 + 4 ✓.
Negative example (NO):
a = 3, b = 7, c = 7
Quadratic residues mod 7: {1² ≡ 1, 2² ≡ 4, 3² ≡ 2, 4² ≡ 2, 5² ≡ 4, 6² ≡ 1} = {1, 2, 4}.
Since 3 ∉ {1, 2, 4}, no x satisfies x² ≡ 3 (mod 7). Answer: Or(false).
Expected outcome: Or(true) for the primary example.
Reduction Rule Crossref
- R164: Satisfiability (3SAT) → QuadraticCongruences
Metadata
Metadata
Assignees
Labels
Type
Projects
Status