Skip to content

[Rule] MultivariateQuadratic to Satisfiability #132

@QingyunQian

Description

@QingyunQian

Source: MultivariateQuadratic (over F₂)
Target: Satisfiability (SAT)
Motivation: Enables solving MQ instances over F₂ using highly optimized SAT solvers (MiniSat, CryptoMiniSat, etc.). Together with the reverse reduction (issue #131), this establishes polynomial-time equivalence between boolean MQ and SAT. Depends on model issue #129.
Reference:

Reduction Algorithm

Notation:

  • Source: MQ instance over F₂ with num_variables Boolean variables x₁, ..., x_n and num_equations polynomial equations
  • Let num_distinct_cross_terms = P be the number of distinct quadratic cross terms x_i x_j (i < j) appearing in the system
  • Let num_terms = the total number of non-zero monomials across all equations (counting each quadratic term, linear term, and constant term in each equation)
  • Target: Satisfiability instance

Variable mapping:

  1. Original variables: Each MQ variable x_i ∈ F₂ maps directly to SAT variable x_i.
  2. Product variables (Tseitin transformation): For each distinct product term x_i x_j appearing in the polynomials, introduce auxiliary SAT variable y_{ij} representing x_i ∧ x_j.

Constraint transformation:

For each MQ equation f_k(x) = Σ_{i<j} a_{ij} x_i x_j + Σ_i b_i x_i + c = 0 (mod 2):

Step 1: Convert to XOR form.
Replace each product x_i x_j with its auxiliary variable y_{ij}. The equation becomes a XOR of boolean variables:

y_{ij_1} ⊕ y_{ij_2} ⊕ ... ⊕ x_{l_1} ⊕ x_{l_2} ⊕ ... ⊕ c = 0

where the y's correspond to quadratic terms with coefficient 1, the x's to linear terms with coefficient 1, and c is the constant.

Step 2: Tseitin encoding for product variables.
For each product variable y_{ij}, add 3 CNF clauses enforcing y_{ij} ↔ (x_i ∧ x_j):

(¬y_{ij} ∨ x_i) ∧ (¬y_{ij} ∨ x_j) ∧ (y_{ij} ∨ ¬x_i ∨ ¬x_j)

Step 3: XOR-to-CNF chain encoding.
Convert each XOR constraint to CNF using chaining variables:

  • Base case (k = 2 terms): u ⊕ v = 0 is encoded as 2 clauses:

    (u ∨ ¬v) ∧ (¬u ∨ v)
    
  • General case (k ≥ 3 terms): For ℓ₁ ⊕ ℓ₂ ⊕ ... ⊕ ℓ_k = 0, introduce chaining variables s₂, ..., s_{k-1}:

    • s₂ ↔ (ℓ₁ ⊕ ℓ₂): 4 clauses
    • s₃ ↔ (s₂ ⊕ ℓ₃): 4 clauses
    • ...
    • s_{k-1} ↔ (s_{k-2} ⊕ ℓ_{k-1}): 4 clauses
    • Final: s_{k-1} = ℓ_k: 2 clauses

    Each equivalence u ↔ (v ⊕ w) is encoded by 4 CNF clauses:

    (¬u ∨ ¬v ∨ ¬w) ∧ (¬u ∨ v ∨ w) ∧ (u ∨ ¬v ∨ w) ∧ (u ∨ v ∨ ¬w)
    

    Total for k-term XOR: (k - 2) chain variables, 4(k - 2) + 2 clauses.

  • Constant term c = 1: If the equation has c = 1 (i.e., XOR = 1 instead of 0), flip the final enforcement: use s_{k-1} = ¬ℓ_k. For k = 2: u ⊕ v = 1 becomes (u ∨ v) ∧ (¬u ∨ ¬v).

Solution extraction:

Extract values of original variables x₁, ..., x_n from the SAT solution. Auxiliary variables (product y_{ij} and chain s_i) are discarded.

Size Overhead

Target metric (code name) Formula
num_vars num_variables + num_distinct_cross_terms + num_terms - 2 * num_equations
num_clauses 3 * num_distinct_cross_terms + 4 * num_terms - 6 * num_equations

Where:

  • num_variables — source Boolean variables
  • num_distinct_cross_terms — distinct quadratic products in the system (P)
  • num_terms — total non-zero monomials across all equations
  • num_equations — number of source equations

Detailed breakdown (assuming each equation has ≥ 2 terms after substitution):

  • Original variables: num_variables
  • Product auxiliary variables: num_distinct_cross_terms
  • Chain auxiliary variables: for an equation with T_k terms, (T_k - 2) chain vars; total = num_terms - 2 * num_equations
  • Total SAT variables: num_variables + num_distinct_cross_terms + num_terms - 2 * num_equations
  • Tseitin clauses: 3 * num_distinct_cross_terms
  • Chain clauses: for an equation with T_k terms, 4(T_k - 2) + 2 clauses; total = 4 * num_terms - 6 * num_equations
  • Total SAT clauses: 3 * num_distinct_cross_terms + 4 * num_terms - 6 * num_equations

Note: The num_terms getter needs to be added to the MultivariateQuadratic model (issue #129). It counts the total number of non-zero monomial entries (quadratic terms + linear terms + constants) across all equations.

Validation Method

  • Build a closed-loop test on small MultivariateQuadratic instances over F₂.
  • Reduce the source MQ instance to a Satisfiability instance.
  • Solve the SAT instance with brute-force search.
  • Extract the x_i assignment from the SAT solution and verify that every source equation evaluates to 0 mod 2.
  • Cross-check against exhaustive search on the source problem to confirm the SAT instance is satisfiable iff the MQ instance is satisfiable.

Example

Source MQ instance (F₂):

Field: F₂ = {0, 1}
Variables: x₁, x₂, x₃
Equations:
  f₁: x₁·x₂ + x₃ = 0
  f₂: x₂·x₃ + x₁ = 0

Step 1: Identify product terms and introduce auxiliaries.

  • y₁₂ represents x₁·x₂
  • y₂₃ represents x₂·x₃

Step 2: Rewrite equations as XOR.

  • f₁: y₁₂ ⊕ x₃ = 0 (2 terms)
  • f₂: y₂₃ ⊕ x₁ = 0 (2 terms)

Step 3: Generate CNF clauses.

Target SAT instance:

Variables: x₁, x₂, x₃, y₁₂, y₂₃

Clauses:
  # Tseitin for y₁₂ ↔ (x₁ ∧ x₂):
  (¬y₁₂ ∨ x₁)
  (¬y₁₂ ∨ x₂)
  (y₁₂ ∨ ¬x₁ ∨ ¬x₂)

  # Tseitin for y₂₃ ↔ (x₂ ∧ x₃):
  (¬y₂₃ ∨ x₂)
  (¬y₂₃ ∨ x₃)
  (y₂₃ ∨ ¬x₂ ∨ ¬x₃)

  # XOR for f₁: y₁₂ ⊕ x₃ = 0 (base case, 2 clauses):
  (y₁₂ ∨ ¬x₃)
  (¬y₁₂ ∨ x₃)

  # XOR for f₂: y₂₃ ⊕ x₁ = 0 (base case, 2 clauses):
  (y₂₃ ∨ ¬x₁)
  (¬y₂₃ ∨ x₁)

Total: 5 variables, 10 clauses

Solution:

  • MQ solution: x₁=0, x₂=0, x₃=0 (satisfies both equations: 0·0+0=0, 0·0+0=0)
  • SAT extension: y₁₂=0, y₂₃=0
  • All 10 clauses verified satisfied.

Overhead verification:

  • Source: num_variables=3, num_equations=2, num_distinct_cross_terms=2, num_terms=4 (f₁ has 2 terms, f₂ has 2 terms)
  • num_vars = 3 + 2 + 4 - 2×2 = 5 ✓
  • num_clauses = 3×2 + 4×4 - 6×2 = 6 + 16 - 12 = 10 ✓

Notes

  • Both MQ(F₂) and SAT are NP-complete; this reduction runs in polynomial time.
  • For sparse MQ systems (few terms per equation), the CNF encoding is efficient. For dense systems, SAT solvers with native XOR support (e.g., CryptoMiniSat) may be more practical since they can handle XOR constraints directly without the chain encoding overhead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoodAn issue passed all checks.ruleA new reduction rule to be added.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions