As Close as It Gets

  • Mike Behrisch
  • Miki Hermann
  • Stefan Mengel
  • Gernot Salzer
Part of the Lecture Notes in Computer Science book series (LNCS, volume 9627)


We study the minimum Hamming distance between distinct satisfying assignments of a conjunctive input formula over a given set of Boolean relations (\(\mathsf {MinSolutionDistance}\), \(\mathsf {MSD}\)). We present a complete classification of the complexity of this optimization problem with respect to the relations admitted in the formula. We give polynomial time algorithms for several classes of constraint languages. For all other cases we prove hardness or completeness with respect to \(\text {poly-APX}\), or \(\mathrm {NPO}\), or equivalence to a well-known hard optimization problem.

1 Introduction

We study the following optimization problem related to Boolean constraint satisfaction problems (CSPs): Given a formula built from atomic constraint relations by means of conjunction and variable identification, the task is to produce two satisfying assignments having minimal Hamming distance among all distinct pairs in the solution space of the CSP instance represented by the formula (\(\mathsf {MinSolutionDistance}\), \(\mathsf {MSD}\)). Note that the dual problem \(\mathsf {MaxHammingDistance}\) has been studied in [9].

As usual our problem is parametrized by the set of atomic constraints allowed to occur in the conjunctive formulas. With respect to this parametrization we completely classify the complexity of the minimization problem \(\mathsf {MSD}\): It turns out that it is either polynomial-time solvable, or that it is complete for a well-known optimization class, or else equivalent to some classical hard optimization problem.

Restricting the allowed relations to affine Boolean relations, our problem \(\mathsf {MSD}\) becomes the well-known problem \(\mathsf {MinDistance}\) of computing the minimum distance of a linear code. As this quantity determines the number of errors such a code can detect and correct, it is of central importance in coding theory. Our work can thus be seen as a generalization of these questions from affine to arbitrary relations.

In the course of investigations it appears that \(\mathsf {MSD}\) lacks compatibility with existential quantification, preventing classical clone theory from being applicable. Consequently, we are lead to weak co-clones that need only be closed under conjunction and equality. To deal with such structures we make use of the theory established in [15], as well as the minimal weak bases of Boolean co-clones described in [13].

This paper is part of a more general program to understand the Hamming distance between solutions of constraint satisfaction problems. The results of this program up to now, including those from this paper and some on other problems, can be found in [4, 5].

2 Preliminaries

An n-ary Boolean relation R is a subset of \(\{0,1\}^n\); its elements \((b_1, \ldots , b_n)\) are also written as \(b_1 \cdots b_n\). Let \(\mathcal V\) be a set of variables. An atomic constraint, or an atom, is an expression \(R(\mathbf {x})\), where R is an n-ary relation and \(\mathbf {x}\) is an n-tuple of variables from \(\mathcal V\). Let \(\mathfrak {L}\) be the collection of all non-empty finite sets of Boolean relations, also called constraint languages. A (conjunctive) \(\varGamma \)-formula is a finite conjunction of atoms \(R_1(\mathbf {x_1}) \wedge \cdots \wedge R_k(\mathbf {x_k})\), where the \(R_i\) are relations from \(\varGamma \in \mathfrak {L}\) and the \(\mathbf {x_i}\) are variable tuples of suitable arity.

An assignment is a mapping \(m:\mathcal V\rightarrow \{0,1\}\) assigning a Boolean value m(x) to each variable \(x \in \mathcal V\). If we arrange the variables in some arbitrary but fixed order, say as a vector \((x_1, \ldots , x_n)\), then the assignments can be identified with vectors from \(\{0,1\}^n\). The i-th component of a vector m is denoted by m[i] and corresponds to the value of the i-th variable, i.e., \(m[i]=m(x_i)\). The Hamming weight \({{\mathrm{hw}}}(m) = \left| \{i\mid m[i]=1\}\right| \) of m is the number of 1s in the vector m. The Hamming distance \({{\mathrm{hd}}}(m,m') = \left| \{i\mid m[i] \ne m'[i]\}\right| \) of m and \(m'\) is the number of coordinates on which the vectors disagree. The complement \(\overline{m}\) of a vector m is its pointwise complement, \(\overline{m}[i] = 1- m[i]\).
Table 1.

Some relevant Boolean co-clones with bases

\(\mathrm {iD}_2\)

\(\{x \oplus y, x \rightarrow y\}\)

\(\mathrm {iN}\)


\(\mathrm {iL}\)


\(\mathrm {iN}_2\)


\(\mathrm {iL}_2\)

\(\{{{\mathrm{even}}}^4, \lnot x, x\}\)

\(\mathrm {iI}\)

\(\{{{\mathrm{even}}}^4, x \rightarrow y\}\)

\(\mathrm {iV}_2\)

\(\{x \vee y \vee \lnot z, \lnot x, x\}\)

\(\mathrm {iI}_0\)

\(\{{{\mathrm{even}}}^4, x \rightarrow y, \lnot x\}\)

\(\mathrm {iE}_2\)

\(\{\lnot x \vee \lnot y \vee z, \lnot x, x\}\)

\(\mathrm {iI}_1\)

\(\{{{\mathrm{even}}}^4, x \rightarrow y, x\}\)

An assignment m satisfies the constraint \(R(x_1,\ldots ,x_n)\) if \((m(x_1), \ldots , m(x_n))\in R\) holds. It satisfies the formula \(\varphi \) if it satisfies all of its atoms; m is said to be a model or solution of \(\varphi \) in this case. We use \([\varphi ]\) to denote the Boolean relation containing all models of \(\varphi \). In sets of relations represented this way we usually omit the brackets. A literal is a variable v, or its negation \(\lnot v\). Assignments m are extended to literals by defining \(m(\lnot v)=1-m(v)\).

The following Boolean functions and relations are of particular relevance to us: we write \(x\oplus y\) for addition modulo 2 and \(x\equiv y\) for \(x\oplus y\oplus 1\). Further, we define the relations \({{\mathrm{nae}}}^3 := \{0,1\}^3 \backslash \{000,111\}\), \({{\mathrm{dup}}}^3 := \{0,1\}^3 \backslash \{010, 101\}\) and \({{\mathrm{even}}}^4 := \{(a_1, a_2, a_3, a_4) \in \{0,1\}^4 \mid \oplus _{i=1}^4 a_i = 0\}\).

Throughout the text we refer to different types of Boolean constraint relations following Schaefer’s terminology [14] (see also [6, 8]). A Boolean relation R is (1) 1-valid if \(1 \cdots 1 \in R\) and it is 0-valid if \(0 \cdots 0 \in R\), (2) Horn (dual Horn) if R can be represented by a formula in conjunctive normal form (CNF) having at most one unnegated (negated) variable in each clause, (3) monotone if it is both Horn and dual Horn, (4) bijunctive if it can be represented by a CNF having at most two variables in each clause, (5) affine if it can be represented by an affine system of equations \(Ax=b\) over \({\mathbb Z}_2\), (6) complementive if for each \(m \in R\) also \(\overline{m} \in R\). A set \(\varGamma \) of Boolean relations is called 0-valid (1-valid, Horn, dual Horn, monotone, affine, bijunctive, complementive) if every relation in \(\varGamma \) has the respective property.

We denote by \(\langle \varGamma \rangle \) the set of all relations that can be expressed using relations from \(\varGamma \cup \{=\}\), conjunction, variable identification (and permutation), cylindrification and existential quantification. The set \(\langle \varGamma \rangle \) is called the co-clone generated by \(\varGamma \). A base of a co-clone \(\mathcal B\) is a set of relations \(\varGamma \) such that \(\langle \varGamma \rangle = \mathcal B\). The set of all co-clones constitutes a lattice with regard to set inclusion. Their bases were studied in [7]; those relevant in this paper are listed in Table 1. In particular the sets of relations being 0-valid, 1-valid, complementive, Horn, dual Horn, affine, and bijunctive each form a co-clone denoted by \(\mathrm {iI}_0\), \(\mathrm {iI}_1\), \(\mathrm {iN}_2\), \(\mathrm {iE}_2\), \(\mathrm {iV}_2\), \(\mathrm {iL}_2\), and \(\mathrm {iD}_2\), respectively.

We will also use a weaker closure than \(\langle \varGamma \rangle \), called conjunctive closure and denoted by \(\langle \varGamma \rangle _{\wedge }\), where the constraint language \(\varGamma \) is closed under conjunctive definitions, but not under existential quantification or addition of explicit equality constraints.

Minimal weak bases of co-clones are bases with certain additional properties. Since we rely on only some of them, we shall not define this notion but refer the reader to [13, 15].

Theorem 1

(Schnoor & Schnoor [15]). If \(\varGamma \) is a minimal weak base of a co-clone, then \(\varGamma \subseteq \langle \varGamma '\rangle _{\wedge }\) for any base \(\varGamma '\).

Lagerkvist computed minimal weak bases for all Boolean co-clones in [13]. From there we infer that \(\{[{{\mathrm{even}}}_4(x_1,x_2,x_3,x_4)\wedge (x_1\wedge x_4\equiv x_2\wedge x_3)]\}\) constitutes a minimal weak base of the co-clone \(\mathrm {iN}\); likewise \(\{[(x_1 \equiv x_2 \wedge x_3) \wedge (\lnot x_4 \equiv \lnot x_2 \wedge \lnot x_3)]\}\) is one of \(\mathrm {iI}\).

We assume that the reader has a basic knowledge of approximation algorithms and complexity theory, see e.g. [2, 8]. For reductions among decision problems we use polynomial-time many-one reduction denoted by \(\le _{\mathrm m}\). Many-one equivalence between decision problems is written as \(\equiv _{\mathrm m}\). For reductions among optimization problems we employ approximation preserving reductions (\({\mathrm {AP}}\)-reductions), represented by \(\le _{\mathrm {AP}}\), while \({\mathrm {AP}}\)-equivalence of optimization problems is stated as \(\equiv _{\mathrm {AP}}\). Besides, the following approximation complexity classes in the hierarchy \(\mathrm {PO}\subseteq \mathrm {APX}\subseteq \text {poly-APX}\subseteq \mathrm {NPO}\) occur.

An optimization problem \(\mathcal {P}_1\) \({\mathrm {AP}}\)-reduces to another optimization problem \(\mathcal {P}_2\) if there are two polynomial-time computable functions f, g, and a constant \(\alpha \ge 1\) such that for all \(r>1\) on any input x for \(\mathcal {P}_1\) the following holds:
  • f(x) is an instance of \(\mathcal {P}_2\);

  • for any solution y of f(x), the result g(xy) is a solution of x;

  • if y is an r-approximate solution for the instance f(x), then the solution g(xy) is \((1+(r-1)\alpha + {\mathrm o}(1))\)-approximate for x.

If \(\mathcal {P}_1\) \({\mathrm {AP}}\)-reduces to \(\mathcal {P}_2\) with constant \(\alpha \ge 1\) and \(\mathcal {P}_2\) has an f(n)-approximation algorithm, then there is an \(\alpha f(n)\)-approximation algorithm for \(\mathcal {P}_1\).

To relate our problem to well-known optimization problems we make the following convention: For optimization problems \(\mathcal P\) and \(\mathcal Q\) we say that \(\mathcal P\) is \(\mathcal Q\)-complete if \(\mathcal P\equiv _{\mathrm {AP}}\mathcal Q\). We use this notion in particular with respect to the following well-studied problem.

Problem \(\mathsf {MinDistance}\). Given a matrix \(A\in {\mathbb Z}_2^{k\times l}\) any non-zero vector \(x\in {\mathbb Z}_2^l\) with \(Ax=0\) is considered a solution. The objective is to minimize the Hamming weight \({{\mathrm{hw}}}(x)\).

\(\mathsf {MinDistance}\) is known to be \(\mathrm {NP}\)-hard to approximate within a factor \(2^{{\mathrm \Omega }(\log ^{1-\varepsilon }(n))}\) for every \(\varepsilon >0\), see [10]. Thus if a problem \(\mathcal P\) is equivalent to it, then \(\mathcal P \notin \mathrm {APX}\) unless \(\mathrm {P}=\mathrm {NP}\).

We also use the classic satisfiability problem \(\mathsf {SAT}(\varGamma )\), asking for a conjunctive formula \(\varphi \) over a constraint language \(\varGamma \), if \(\varphi \) is satisfiable. Schaefer presented in [14] a complete classification of complexity for \(\mathsf {SAT}\). His dichotomy theorem proves that \(\mathsf {SAT}(\varGamma )\) is polynomial-time decidable if \(\varGamma \) is 0-valid \((\varGamma \subseteq \mathrm {iI}_0)\), 1-valid \((\varGamma \subseteq \mathrm {iI}_1)\), Horn \((\varGamma \subseteq \mathrm {iE}_2)\), dual Horn \((\varGamma \subseteq \mathrm {iV}_2)\), bijunctive \((\varGamma \subseteq \mathrm {iD}_2)\), or affine \((\varGamma \subseteq \mathrm {iL}_2)\); otherwise it is \(\mathrm {NP}\)-complete. Moreover, we need the decision problem \(\mathsf {AnotherSAT}(\varGamma )\), whose complexity was completely classified in [12]. Given a conjunctive formula \(\varphi \) and a satisfying assignment m, it asks if there exists another satisfying assignment \(m'\ne m\) for \(\varphi \).

3 Results

The input to our problem is a conjunctive formula over a constraint language. The satisfying assignments of the formula, being its solutions, constitute the codewords of the associated code. The minimization target is the distance of any two distinct solutions.

Problem \(\mathsf {MinSolutionDistance}(\varGamma )\), \(\mathsf {MSD}(\varGamma )\)

Input: A conjunctive formula \(\varphi \) over relations from \(\varGamma \).

Solution: Two satisfying truth assignments \(m\ne m'\) to the variables occurring in \(\varphi \).

Objective: Minimum Hamming distance \({{\mathrm{hd}}}(m,m')\).

Theorem 2

For any constraint language \(\varGamma \) the optimization problem \(\mathsf {MSD}(\varGamma )\) is
  1. (i)
    in \(\mathrm {PO}\) if \(\varGamma \) is
    1. (a)

      bijunctive \((\varGamma \subseteq \mathrm {iD}_2)\) or

    2. (b)

      Horn \((\varGamma \subseteq \mathrm {iE}_2)\) or

    3. (c)

      dual Horn \((\varGamma \subseteq \mathrm {iV}_2)\);

  2. (ii)

    \(\mathsf {MinDistance}\)-complete if \(\varGamma \) is exactly affine \((\mathrm {iL}\subseteq \langle \varGamma \rangle \subseteq \mathrm {iL}_2)\);

  3. (iii)

    in \(\text {poly-APX}\) if \(\varGamma \) is both 0-valid and 1-valid, but does not contain an affine relation \((\mathrm {iN}\subseteq \langle \varGamma \rangle \subseteq \mathrm {iI})\), where \(\mathsf {MSD}(\varGamma )\) is n-approximable but not \((n^{1{-}\varepsilon })\)-approximable unless \(\mathrm {P}=\mathrm {NP}\); and

  4. (iv)

    \(\mathrm {NPO}\)-complete otherwise \((\mathrm {iN}_2\subseteq \langle \varGamma \rangle \) or \(\mathrm {iI}_0\subseteq \langle \varGamma \rangle \) or \(\mathrm {iI}_1\subseteq \langle \varGamma \rangle )\).



The proof is split into several propositions presented in the remainder of the paper.

  1. (i)

    See Propositions 7 and 8.

  2. (ii)

    See Proposition 14.

  3. (iii)

    For \(\varGamma \subseteq \mathrm {iI}\), every formula \(\varphi \) over \(\varGamma \) has at least two solutions since it is both 0-valid and 1-valid. Thus \(\mathsf{2SolutionSAT}(\varGamma )\) is in \(\mathrm {P}\), and Proposition 13 yields that \(\mathsf {MSD}(\varGamma )\) is n-approximable. By Proposition 18 this approximation is indeed tight.

  4. (iv)

    According to [12], \(\mathsf {AnotherSAT}(\varGamma )\) is \(\mathrm {NP}\)-hard for \(\mathrm {iI}_0\subseteq \langle \varGamma \rangle \), or \(\mathrm {iI}_1\subseteq \langle \varGamma \rangle \). By Lemma 10 it follows that \(\mathsf{2SolutionSAT}(\varGamma )\) is \(\mathrm {NP}\)-hard, too. For \(\mathrm {iN}_2\subseteq \langle \varGamma \rangle \) we can reduce the \(\mathrm {NP}\)-hard problem \(\mathsf {SAT}(\varGamma )\) to \(\mathsf{2SolutionSAT}(\varGamma )\). Hence \(\mathsf {MSD}(\varGamma )\) is \(\mathrm {NPO}\)-complete in all three cases.    \(\square \)


The optimization problem can be transformed into a decision problem \(\mathsf {MSD}^{\mathrm d}\) by adding a bound \(k \in {\mathbb N}\) to the input and asking if \({{\mathrm{hd}}}(m,m') \le k\). We obtain the following dichotomy:

Corollary 3

\(\mathsf {MSD}^{\mathrm d}(\varGamma )\) is in \(\mathrm {P}\) if \(\varGamma \in \mathfrak {L}\) is bijunctive, Horn, or dual-Horn, and it is \(\mathrm {NP}\)-complete otherwise.


This follows immediately from Theorem 2: All cases in \(\mathrm {PO}\) become polynomial-time decidable, whereas the other cases, which are \(\mathrm {APX}\)-hard, become \(\mathrm {NP}\)-complete. According to Post’s lattice this classification covers all finite sets \(\varGamma \) of relations.    \(\square \)

4 Duality and Inapplicability of Clone Closure

As the optimization problem \(\mathsf {MSD}\) is not compatible with existential quantification, we cannot prove an \({\mathrm {AP}}\)-equivalence result between any two \(\mathsf {MSD}\) parametrized by constraint languages generating the same co-clone. Yet, similar results hold for weak co-clones.

Proposition 4

We have \(\mathsf {MSD}^{\mathrm d}(\varGamma ')\le _{\mathrm m}\mathsf {MSD}^{\mathrm d}(\varGamma )\) and \(\mathsf {MSD}(\varGamma ')\le _{\mathrm {AP}}\mathsf {MSD}(\varGamma )\) for \(\varGamma ,\varGamma '\in \mathfrak {L}\) satisfying \(\varGamma '\subseteq \langle \varGamma \rangle _{\wedge }\).


For similarity it suffices to prove that \(\varGamma '\subseteq \langle \varGamma \rangle _{\wedge }\) implies \(\mathsf {MSD}(\varGamma ')\le _{\mathrm {AP}}\mathsf {MSD}(\varGamma )\).

Let a \(\varGamma '\)-formula \(\varphi \) be an instance of \(\mathsf {MSD}(\varGamma ')\). Since \(\varGamma ' \subseteq \langle \varGamma \rangle _{\wedge }\), every constraint \(R(x_1, \ldots , x_k)\) of \(\varphi \) can be written as a conjunction of constraints upon relations from \(\varGamma \). Substitute the latter into \(\varphi \), obtaining \(\varphi '\). Now \(\varphi '\) is an instance of \(\mathsf {MSD}(\varGamma )\), where \(\varphi '\) is only polynomially larger than \(\varphi \). As \(\varphi \) and \(\varphi '\) have the same variables and hence the same models, also the closest distinct models of \(\varphi \) and \(\varphi '\) are the same.    \(\square \)

For a relation \(R \subseteq \{0,1\}^n\), its dual relation is \({{\mathrm{dual}}}(R) = \{\overline{m}\mid m \in R\}\), i.e., the relation containing the complements of tuples from R. We naturally extend this to sets of relations \(\varGamma \) by putting \({{\mathrm{dual}}}(\varGamma ) = \{{{\mathrm{dual}}}(R) \mid R \in \varGamma \}\). Since taking complements is involutive, duality is a symmetric relation. By inspecting the bases of co-clones in Table 1, we deduce that many co-clones are duals of each other, e.g. \(\mathrm {iE}_2\) and \(\mathrm {iV}_2\).

We now show that it suffices to consider only one half of Post’s lattice of co-clones.

Lemma 5

For any set \(\varGamma \) of Boolean relations we have \(\mathsf {MSD}^{\mathrm d}(\varGamma )\equiv _{\mathrm m}\mathsf {MSD}^{\mathrm d}({{\mathrm{dual}}}(\varGamma ))\) and \(\mathsf {MSD}(\varGamma )\equiv _{\mathrm {AP}}\mathsf {MSD}({{\mathrm{dual}}}(\varGamma ))\).


For a \(\varGamma \)-formula \(\varphi \) and an assignment m to \(\varphi \) we construct a \({{\mathrm{dual}}}(\varGamma )\)-formula \(\varphi '\) by substitution of every atom \(R(\mathbf {x})\) by \({{\mathrm{dual}}}(R)(\mathbf {x})\). Then m satisfies \(\varphi \) if and only if \(\overline{m}\) satisfies \(\varphi '\), \(\overline{m}\) being the complement of m. Moreover, \({{\mathrm{hd}}}(m, m') = {{\mathrm{hd}}}(\overline{m}, \overline{m}')\).    \(\square \)

5 Finding the Minimal Distance Between Solutions

5.1 Polynomial-Time Cases

We use the following result based on a previous theorem of Baker and Pixley [3], showing that it suffices to consider binary relations when studying bijunctive constraint languages.

Proposition 6

(Jeavons et al. [11]). Any bijunctive constraint \(R(x_1, \ldots , x_n)\) is equivalent to \(\bigwedge _{1 \le i \le j\le n} R_{ij}(x_i,x_j)\), where \(R_{ij}\) is the projection of R to the coordinates i and j.

Proposition 7

If \(\varGamma \) is bijunctive \((\varGamma \subseteq \mathrm {iD}_2)\) then \(\mathsf {MSD}(\varGamma )\) is polynomial-time solvable.

By Proposition 6, an algorithm for bijunctive \(\varGamma \) can be restricted to at most binary clauses. We extend the algorithm of Aspvall, Plass, and Tarjan [1].


Input: An \(\mathrm {iD}_2\)-formula \(\varphi \) viewed as a collection of one- or two-element sets of literals.

Output:\(\le 1\) model” or the minimal Hamming distance of any two distinct models of \(\varphi \).

Method: Let \(\mathcal V\) be the set of variables occurring in \(\varphi \), let \(\mathcal L= \{v,\lnot v \mid v\in \mathcal V\}\) be the set of corresponding literals, and let \(\bar{u}\) denote the complementary literal to \(u\in \mathcal L\).

  • Construct the relation \(R:=\{(\bar{u},v),(u,\bar{v})\mid \{u,v\}\in \varphi \}\cup \{(\bar{u},u)\mid \{u\}\in \varphi \}\).

    Let \(\le \) be the reflexive and transitive closure of R, i.e. the least preorder on \(\mathcal L\) extending R.

    Let \({\sim }:= \{(u,v)\in \mathcal L^2\mid u\le v \wedge v\le u\}\) be the associated equivalence relation.

    If \(v\sim \lnot v\) holds for some variable v, then return “\(\le 1\) model” (\(\varphi \) is unsatisfiable).

  • Otherwise, let \(\mathcal V_0:= \{v\in \mathcal V\mid v\le \lnot v\}\) and \(\mathcal V_1:= \{v\in \mathcal V\mid \lnot v\le v\}\) be sets of variables being false and true, respectively, in every model of \(\varphi \).

    If \(\mathcal V_0\cup \mathcal V_1 = \mathcal V\) holds, then return “\(\le 1\) model” (\(\varphi \) has only one model).

  • Otherwise, construct the sets

    \(F_0 := \{L\in \mathcal L/{\sim }\mid \exists v\in \mathcal V_0:L\le [v]_{\sim }\} \cup \{L\in \mathcal L/{\sim }\mid \exists v\in \mathcal V_1:L\le [\lnot v]_{\sim }\}\) and

    \(F_1 := \{L\in \mathcal L/{\sim }\mid \exists v\in \mathcal V_0:[\lnot v]_{\sim }\le L\} \cup \{L\in \mathcal L/{\sim }\mid \exists v\in \mathcal V_1:[v]_{\sim }\le L\}\).

    \(F_0\) (\(F_1\)) is the set of equivalence classes of literals whose value is forced to false (to true) by backward and forward propagation from variables in \(\mathcal V_0\) and \(\mathcal V_1\).

    Let \(P:= (\mathcal L/{\sim })\backslash (F_0\cup F_1)\) be the set of remaining equivalence classes.

    Return \(\min \{\left| L\right| \mid L \in P\}\) as minimal Hamming distance.

Complexity. The size of \(\mathcal L\) is linear in the number of variables, the reflexive closure can be computed in linear time in \(\left| \mathcal L\right| \), the transitive closure in cubic time in \(\left| \mathcal L\right| \), see [16]. The equivalence relation \(\sim \) is the intersection of \(\le \) and its inverse (quadratic in \(\left| \mathcal L\right| \)); from it we can obtain the partition \(\mathcal L/{\sim }\) in linear time in \(\left| \mathcal L\right| \), and combining this with the preorder \(\le \) we can compute the order on \(\mathcal L/{\sim }\) in polynomial time, as well. Similarly, the remaining sets from the proof can be computed with polynomial time complexity.

Correctness. The pairs in R arise from understanding the atomic constraints in \(\varphi \) as implications. Therefore, by transitivity of implication, in every model of \(\varphi \), literals \(u,v\in \mathcal L\) satisfying \(u\le v\) have to be evaluated so that (m(u), m(v)) does not violate the Boolean order relation, i.e. \([{x}\rightarrow {y}]\). Hence, literals \(u\sim v\) from one equivalence class have to share the same value in any model m. Moreover, since literals and their negations have to take on opposite values, we must have \(m(v) = 0\) for all \(v\in \mathcal V_0\) and \(m(v)=1\) for all \(v\in \mathcal V_1\). This proves that the algorithm gives a correct answer in case there do not exist feasible solutions. Furthermore, by transitivity, we see that literals in equivalence classes in \(F_i\) must be evaluated to \(i\in \{0,1\}\). So any two models can only differ on the literals belonging to members of P. Therefore, clearly, the return value of the algorithm is a lower bound for the minimal solution distance. To prove the converse, we shall exhibit two models \(m_0\ne m_1\) of \(\varphi \) having the least cardinality of equivalence classes in P as their Hamming distance.

Let \(L\in P\) be a class of minimum cardinality. Define \(m_0(u):= 0\) for all literals \(u\in L\) and likewise, \(m_1(u):= 1\). We extend this by \(m_1(w) := m_0(w):= 0\) for all \(w\in \mathcal L\) such that \(w\le u\) for some \(u\in L\), and by \(m_0(w):= m_1(w):= 1\) for all \(w\in \mathcal L\) such that \(u\le w\) for some \(u\in L\). For variables \(v\in \mathcal V\) satisfying \(v\le \lnot v\) or \(\lnot v\le v\) we have \([v]_{\sim }\notin P\); in other words, for \([v]_{\sim }\in P\) the classes \([v]_{\sim }\) and \([\lnot v]_{\sim }\) are incomparable. Thus, so far, we have not defined \(m_0\) and \(m_1\) on a variable \(v\in \mathcal V\) and on its negation \(\lnot v\) at the same time. Of course, fixing a value for a negative literal \(\lnot v\) to some value implicitly means that we bind the assignment for \(v\in \mathcal V\) to the opposite value. We complete the definition of \(m_0\) and \(m_1\) by setting them to 0 on every \(v\in \mathcal V\) where \([v]_{\sim }\in P\) and they are not yet defined. Moreover, for \(v\in \mathcal V\) where \([v]_{\sim }\in F_i\) we put \(m_j(v):= i\) for \(i,j\in \{0,1\}\). Obviously, \(m_0\) differs from \(m_1\) only in the variables corresponding to the literals in L, so their Hamming distance is \(\left| L\right| \) as desired. Besides, both assignments respect the order constraints in \((\mathcal L,\le )\). As these faithfully reflect all original atomic constraints, \(m_0\) and \(m_1\) are indeed models of \(\varphi \).

Proposition 8

\(\mathsf {MSD}(\varGamma )\) is in \(\mathrm {PO}\) for \(\varGamma \in \mathfrak {L}\) satisfying \(\varGamma \subseteq \mathrm {iE}_2\) or \(\varGamma \subseteq \mathrm {iV}_2\).

We only discuss the Horn case (\(\varGamma \subseteq \mathrm {iE}_2\)), dual-Horn (\(\varGamma \subseteq \mathrm {iV}_2\)) being symmetric.


Input: A Horn formula \(\varphi \) viewed as a set of Horn clauses.

Output:\(\le 1\) model” or the minimal Hamming distance of any two distinct models of \(\varphi \).


Step 1: For each variable x in \(\varphi \), add the clause \((\lnot x \vee x)\). Apply the following rules to \(\varphi \) until no more clauses and literals can be removed and no new clauses can be added.

– Unit resolution and unit subsumption: Let \(\bar{u}\) denote the complement of a literal u. If the clause set contains a unit clause u, remove all clauses containing the literal u and remove all literals \(\bar{u}\) from the remaining clauses.

– Hyper-resolution with binary implications: Resolve all negative literals of a clause simultaneously with binary implications possessing identical premises.
$$\begin{aligned} \frac{(\lnot x\vee y_1) \cdots (\lnot x\vee y_k) \;\; (\lnot y_1\vee \dots \vee \lnot y_k\vee z)}{(\lnot x \vee z)} \quad \frac{(\lnot x\vee y_1) \cdots (\lnot x\vee y_k) \;\; (\lnot y_1\vee \dots \vee \lnot y_k)}{(\lnot x)} \end{aligned}$$
Let \(\mathcal D\) be the final result of this step. If \(\mathcal D\) is empty or contains the empty clause, return “\(\le 1\) model”.

Step 2: Let \(\mathcal V\) be the set of variables occurring in \(\mathcal D\), and let \({\sim }\subseteq \mathcal V^2\) be the relation defined by \(x\sim y\) if \(\{\lnot x\vee y,\lnot y\vee x\}\subseteq \mathcal D\). Note that \(\sim \) is an equivalence, since the tautological clauses ensure reflexivity and resolution of implications computes their transitive closure. We say that a variable z depends on variables \(y_1,\dots ,y_k\), if \(\mathcal D\) contains the clauses \( \lnot y_1\vee \dots \vee \lnot y_k\vee z\), \(\lnot z\vee y_1\), ..., \(\lnot z\vee y_k\) and \(z\not \sim y_i\) holds for all \(i=1,\dots ,k\).

Return \( \min \{ \left| X\right| X\in \mathcal V/{\sim }, X \text { does not contain dependent variables}\}\) as minimal Hamming distance.

Complexity. The run-time of the algorithm is polynomial in the number of clauses and the number of variables in \(\varphi \): Unit resolution/subsumption can be applied at most once for each variable, and hyper-resolution has to be applied at most once for each variable x and each clause \(\lnot y_1\vee \dots \vee \lnot y_k \vee z\) and \(\lnot y_1\vee \dots \vee \lnot y_k\).

Correctness. Let \(\mathcal {U}\) be the set of unit clauses removed by subsumption. Adding resolvents and removing subsumed clauses maintains logical equivalence, therefore \(\mathcal D\cup \mathcal {U}\) is logically equivalent to \(\varphi \), i.e., both clause sets have the same models. If \(\mathcal D\) is empty, the unit clauses in \(\mathcal {U}\) define a unique model of \(\varphi \). If \(\mathcal D\) contains the empty clause, the sets \(\mathcal D\) and \(\varphi \) are unsatisfiable. Otherwise \(\mathcal D\) has at least two models, as we will show below. As each model m of \(\mathcal D\) uniquely extends to a model of \(\varphi \) by defining \(m(x)=1\) for \((x)\in \mathcal {U}\) and \(m(x)=0\) for \((\lnot x)\in \mathcal {U}\), the minimal Hamming distances of \(\varphi \) and \(\mathcal D\) are the same.

We are thus looking for models \(m_1,m_2\) of \(\mathcal D\) such that the size of the difference set \(\varDelta (m_1, m_2)=\{x\mid m_1(x)\ne m_2(x)\}\) is minimal. In fact, since the models of Horn formulas are closed under minimum, we may assume \(m_1<m_2\), i.e., we have \(m_1(x)=0\) and \(m_2(x)=1\) for all variables \(x\in \varDelta (m_1, m_2)\). Indeed, given two models \(m_2\) and \(m_2'\) of \(\mathcal D\), \(m_1= m_2 \wedge m_2'\) is also a model. Since \({{\mathrm{hd}}}(m_1,m_2) \le {{\mathrm{hd}}}(m_2,m_2')\) holds, the minimal Hamming distance will occur between models \(m_1\) and \(m_2\) satisfying \(m_1 < m_2\).

Note the following facts regarding the equivalence relation \(\sim \) and dependent variables.

– If \(x\sim y\) then the two variables must have the same value in every model of \(\mathcal D\) in order to satisfy the implications \(\lnot x\vee y\) and \(\lnot y\vee x\). This means that for all models m of \(\mathcal D\) and all \(X\in \mathcal V/{\sim }\), we have either \(m(x)=0\) for all \(x\in X\) or \(m(x)=1\) for all \(x\in X\).

– The dependence of variables is acyclic: If \(z_i\) depends on \(z_{i+1}\) for \(i=1,\dots ,l\) and \(z_l\) depends on \(z_1\), then we have a cycle of binary implications between the variables and thus \(z_i\sim z_j\) for all ij, contradicting the definition of dependence.

– If a variable z depending on \(y_1\), ..., \(y_k\) belongs to a difference set \(\varDelta (m_1, m_2)\), then at least one of the \(y_i\)s also has to belong to \(\varDelta (m_1, m_2)\): \(m_2(z)=1\) implies \(m_2(y_j)=1\) for all \(j=1,\dots ,k\) (because of the clauses \(\lnot z\vee y_i\)), and \(m_1(z)=0\) implies \(m_1(y_i)=0\) for at least one i (because of the clause \(\lnot y_1\vee \dots \vee \lnot y_k\vee z\)). Therefore \(\varDelta (m_1, m_2)\) is the union of at least two sets in \(\mathcal V/{\sim }\), namely the equivalence class of z and the one of \(y_i\).

Hence the difference between any two models cannot be smaller than the cardinality of the smallest set in \(\mathcal V/{\sim }\) without dependent variables. It remains to show that we can indeed find two such models.

Let X be a set in \(\mathcal V/{\sim }\) which has minimal cardinality among the sets without dependent variables, and let \(m_1,m_2\) be interpretations defined as follows: (1) \(m_1(y) = 0\) and \(m_2(y) = 1\) if \(y\in X\); (2) \(m_1(y) = 1\) and \(m_2(y) = 1\) if \(y\notin X\) and \((\lnot x\vee y)\in \mathcal D\) for some \(x\in X\); (3) \(m_1(y) = 0\) and \(m_2(y) = 0\) otherwise. We have to show that \(m_1\) and \(m_2\) satisfy all clauses in \(\mathcal D\). Let m be any of these models. \(\mathcal D\) contains two types of clauses.

Type 1: Horn clauses with a positive literal \(\lnot y_1\vee \dots \vee \lnot y_k\vee z\). If \(m(y_i)=0\) for any i, we are done. So suppose \(m(y_i)=1\) for all \(i=1,\dots ,k\); we have to show \(m(z)=1\). The condition \(m(y_i)=1\) means that either \(y_i\in X\) (for \(m=m_2\)) or that there is a clause \((\lnot x_i \vee y_i)\in \mathcal D\) for some \(x_i\in X\). We distinguish the two cases \(z\in X\) and \(z\notin X\).

Let \(z\in X\). If \(z\sim y_i\) for any i, we are done for we have \(m(z)=m(y_i)=1\). So suppose \(z\not \sim y_i\) for all i. As the elements in X, in particular z and the \(x_i\)s, are equivalent and the binary clauses are closed under resolution, \(\mathcal D\) contains the clause \(\lnot z\vee y_i\) for all i. But this would mean that z is a variable depending on the \(y_i\)s, contradicting the assumption \(z\in X\). Let \(z\notin X\), and let \(x\in X\). As the elements in X are equivalent and the binary clauses are closed under resolution, \(\mathcal D\) contains \(\lnot x\vee y_i\) for all i. Closure under hyper-resolution with the clause \(\lnot y_1 \vee \dots \vee \lnot y_k\vee z\) means that \(\mathcal D\) also contains \(\lnot x\vee z\), whence \(m(z)=1\).

Type 2: Horn clauses with only negative literals \(\lnot y_1\vee \dots \vee \lnot y_k\). If \(m(y_i)=0\) for any i, we are done. It remains to show that the assumption \(m(y_i)=1\) for all \(i=1,\dots ,k\) leads to a contradiction. The condition \(m(y_i)=1\) means that either \(y_i\in X\) (for \(m=m_2\)) or that there is a clause \((\lnot x_i\vee y_i)\in \mathcal D\) for some \(x_i\in X\). Let x be some particular element of X. Since the elements in X are equivalent and the binary clauses are closed under resolution, \(\mathcal D\) contains the clause \(\lnot x\vee y_i\) for all i. But then a hyper-resolution step with the clause \(\lnot y_1 \vee \dots \vee \lnot y_k\) would yield the unit clause \(\lnot x\), which by construction does not occur in \(\mathcal D\). Therefore at least one \(y_i\) is neither in X nor part of a clause \(\lnot x\vee y_i\) with \(x\in X\), i.e., \(m(y_i)=0\).

5.2 Hard Cases

Two Solution Satisfiability. In this section we study the feasibility problem of \(\mathsf {MSD}(\varGamma )\) which is, given a \(\varGamma \)-formula \(\varphi \), to decide if \(\varphi \) has two distinct solutions.

Problem: \(\mathsf{2SolutionSAT}(\varGamma )\)

Input: Conjunctive formula \(\varphi \) over the relations from \(\varGamma \).

Question: Are there two satisfying assignments \(m \ne m'\) of \(\varphi \)?

A priori it is not clear that the tractability of \(\mathsf{2SolutionSAT}\) is fully characterized by co-clones. The problem is that the implementation of relations of some language \(\varGamma \) by another language \(\varGamma '\) might not be parsimonious, that is, in the implementation one solution to a constraint might be blown up into several ones in the implementation. Fortunately we can still determine the tractability frontier for \(\mathsf{2SolutionSAT}\) by combining the corresponding results for \(\mathsf {SAT}\) and \(\mathsf {AnotherSAT}\).

Lemma 9

For \(\varGamma \in \mathfrak {L}\) where \(\mathsf {SAT}(\varGamma )\) is \(\mathrm {NP}\)-hard, \(\mathsf{2SolutionSAT}(\varGamma )\) is \(\mathrm {NP}\)-hard.


Since \(\mathsf {SAT}(\varGamma )\) is \(\mathrm {NP}\)-hard, there must be a relation R in \(\varGamma \) having more than one tuple, because every relation containing only one tuple is at the same time Horn, dual Horn, bijunctive, and affine. Given an instance \(\varphi \) for \(\mathsf {SAT}(\varGamma )\), construct \(\varphi '\) as \(\varphi \wedge R(y_1, \ldots , y_\ell )\) where \(\ell \) is the arity of R and \(y_1, \ldots , y_\ell \) are new variables not appearing in \(\varphi \). Obviously, \(\varphi \) has a solution if and only if \(\varphi '\) has at least two solutions. Hence, we have proved \(\mathsf {SAT}(\varGamma )\le _{\mathrm m}\mathsf{2SolutionSAT}(\varGamma )\).    \(\square \)

Lemma 10

If \(\varGamma \in \mathfrak {L}\) and \(\mathsf {AnotherSAT}(\varGamma )\) is \(\mathrm {NP}\)-hard, \(\mathsf{2SolutionSAT}(\varGamma )\) is \(\mathrm {NP}\)-hard.


Let a formula \(\varphi \) and a satisfying assignment m be an instance of \(\mathsf {AnotherSAT}(\varGamma )\). Then \(\varphi \) has a solution other than m if and only if it has two distinct solutions.    \(\square \)

Lemma 11

If \(\mathsf {SAT}(\varGamma )\) and \(\mathsf {AnotherSAT}(\varGamma )\) are in \(\mathrm {P}\) for \(\varGamma \in \mathfrak {L}\), then the same holds for \(\mathsf{2SolutionSAT}(\varGamma )\).


Let \(\varphi \) be an instance of \(\mathsf{2SolutionSAT}(\varGamma )\). All polynomial-time decidable cases of \(\mathsf {SAT}(\varGamma )\) are constructive, i.e., whenever that problem is polynomial-time decidable, there exists a polynomial-time algorithm computing a satisfying assignment. Thus we can compute in polynomial time a satisfying assignment m of \(\varphi \). Now use the algorithm for \(\mathsf {AnotherSAT}(\varGamma )\) on the instance \((\varphi , m)\) to decide if there is a second solution to \(\varphi \).    \(\square \)

Corollary 12

For \(\varGamma \in \mathfrak {L}\), the problem \(\mathsf{2SolutionSAT}(\varGamma )\) is polynomial-time decidable if both \(\mathsf {SAT}(\varGamma )\) and \(\mathsf {AnotherSAT}(\varGamma )\) are polynomial-time decidable. Otherwise, \(\mathsf{2SolutionSAT}(\varGamma )\) is \(\mathrm {NP}\)-hard.

Proposition 13

For \(\varGamma \in \mathfrak {L}\) such that \(\mathsf{2SolutionSAT}(\varGamma )\) is in \(\mathrm {P}\), there is a polynomial-time n-approximation algorithm for \(\mathsf {MSD}(\varGamma )\), where n is the number of variables.


Since \(\mathsf{2SolutionSAT}(\varGamma )\) is in \(\mathrm {P}\), both \(\mathsf {SAT}(\varGamma )\) and \(\mathsf {AnotherSAT}(\varGamma )\) must be in \(\mathrm {P}\) by Corollary 12. Since \(\mathsf {SAT}(\varGamma )\) is in \(\mathrm {P}\), we can compute a model m of the input \(\varphi \) in polynomial time if it exists. Now we check the \(\mathsf {AnotherSAT}(\varGamma )\)-instance \((\varphi ,m)\). If it has a solution \(m'\ne m\), it is also polynomial time computable, and we return \((m,m')\). If we fail somewhere in this process, then \(\mathsf {MSD}(\varGamma )\) does not have feasible solutions; otherwise, \({{\mathrm{hd}}}(m,m')\le n \le n\cdot {\mathrm {OPT}}(\varphi )\).    \(\square \)

MinDistance-Equivalent Cases. In this section we show that, as for the Nearest Other Solution problem (see [4, 5]), the affine cases of \(\mathsf {MSD}\) are \(\mathsf {MinDistance}\)-complete.

Proposition 14

\(\mathsf {MSD}(\varGamma )\) is \(\mathsf {MinDistance}\)-complete if \(\varGamma \in \mathfrak {L}\) satisfies \(\mathrm {iL}\subseteq \langle \varGamma \rangle \subseteq \mathrm {iL}_2\).


We prove \(\mathsf {MSD}(\varGamma )\equiv _{\mathrm {AP}}\mathsf {NearestOtherSolution}(\varGamma )\), which is \(\mathsf {MinDistance}\)-complete by [4]. As \(\varGamma \subseteq \mathrm {iL}_2 = \langle \{{{\mathrm{even}}}^4,[x],[\lnot x]\}\rangle \), any \(\varGamma \)-formula \(\psi \) is expressible as \(\exists y(A_1 x +A_2 y = c)\). The projection of the affine solution space is again an affine space, so it can be understood as solutions of a system \(Ax = b\). If \((\psi ,m_0)\) is an instance of \(\mathsf {NSol}(\varGamma )\), then \(\psi \) is an \(\mathsf {MSD}(\varGamma )\)-instance, and a feasible solution \(m_1\ne m_2\) satisfying \(\psi \) gives a feasible solution \(m_3:=m_0+(m_2-m_1)\) for \((\psi ,m_0)\), where \({{\mathrm{hd}}}(m_0,m_3) = {{\mathrm{hd}}}(m_2,m_1)\). Conversely, a solution \(m_3\ne m_0\) to \((\psi ,m_0)\) yields a feasible answer to the \(\mathsf {MSD}\)-instance \(\psi \). Thus, \({\mathrm {OPT}}(\psi ) = {\mathrm {OPT}}(\psi ,m_0)\) and so \(\mathsf {NSol}(\varGamma )\le _{\mathrm {AP}}\mathsf {MSD}(\varGamma )\). The other way round, if \(\psi \) is an \(\mathsf {MSD}\)-instance, then solve the system \(Ax=b\) defined by it; let \(m_0\) be a model of \(\psi \). As above we conclude \({\mathrm {OPT}}(\psi ) = {\mathrm {OPT}}(\psi ,m_0)\), and therefore, \(\mathsf {MSD}(\varGamma )\le _{\mathrm {AP}}\mathsf {NSol}(\varGamma )\).    \(\square \)

Tightness Results. It will be convenient to consider the following decision problem, already studied in [5].

Problem: \(\mathsf {AnotherSAT}_{<n}(\varGamma )\)

Input: A conjunctive formula \(\varphi \) over relations from \(\varGamma \) and an assignment m satisfying \(\varphi \).

Question: Is there another satisfying assignment \(m'\) of \(\varphi \), different from m, such that \({{\mathrm{hd}}}(m,m') < n\), where n is the number of variables of \(\varphi \)?

Note that \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) is not compatible with existential quantification. Let \(\varphi (y, x_1, \ldots , x_n)\) with the satisfying assignment m be an instance of \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) and \(m'\) its solution satisfying \({{\mathrm{hd}}}(m,m') < n+1\). Let \(m_1\) and \(m'_1\) be the corresponding vectors to m and \(m'\), respectively, with the first coordinate truncated. When we existentially quantify the variable y in \(\varphi \), producing \(\varphi _1(x_1, \ldots , x_n) = \exists y \, \varphi (y, x_1, \ldots , x_n)\), then both \(m_1\) and \(m'_1\) are solutions of \(\varphi '\), but we cannot guarantee that \({{\mathrm{hd}}}(m_1, m'_1) < n\). Hence we need the equivalent of Proposition 4 for this problem, whose proof is analogous.

Proposition 15

(Behrisch et al. [4, 5]). For \(\varGamma ,\varGamma '\in \mathfrak {L}\) with \(\varGamma '\subseteq \langle \varGamma \rangle _{\wedge }\) we have the reduction \(\mathsf {AnotherSAT}_{<n}(\varGamma ') \le _{\mathrm m}\mathsf {AnotherSAT}_{<n}(\varGamma )\).

The following proposition presents only a partial result for \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) already proved in [5]. An exhaustive complexity classification of the problem \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) has been performed in [4].

Proposition 16

(Behrisch et al. [4, 5]).\(\mathsf {AnotherSAT}_{<n}(\varGamma )\) is \(\mathrm {NP}\)-complete for \(\varGamma \in \mathfrak {L}\) such that \(\mathrm {iN}\subseteq \langle \varGamma \rangle \subseteq \mathrm {iI}\).

Remark 17

It is easy to see that \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) is \(\mathrm {NP}\)-complete for \(\mathrm {iI}_0 \subseteq \langle \varGamma \rangle \) and \(\mathrm {iI}_1 \subseteq \langle \varGamma \rangle \), since already \(\mathsf {AnotherSAT}(\varGamma )\) is \(\mathrm {NP}\)-complete for these cases, as it was proved in [12]. It is also clear that \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) is polynomial-time decidable if \(\varGamma \) is Horn \((\varGamma \subseteq \mathrm {iE}_2)\), dual Horn \((\varGamma \subseteq \mathrm {iV}_2)\), bijunctive \((\varGamma \subseteq \mathrm {iD}_2)\), or affine \((\varGamma \subseteq \mathrm {iL}_2)\), just for the same reason as for \(\mathsf {AnotherSAT}(\varGamma )\). In all these four Schaefer cases, for each variable \(x_i\) we flip the value of m[i], substitute \(\overline{m}(x_i)\) for \(x_i\), and construct another satisfying assignment if it exists. Consider now the solutions which we get for every variable \(x_i\). Either there is no solution for any variable, then \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) has no solution; or there are only the solutions which are the complement of m, then \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) has no solution as well; or else we get a solution \(m'\) with \({{\mathrm{hd}}}(m,m') < n\), then \(\mathsf {AnotherSAT}_{<n}(\varGamma )\) also has a solution. Hence, there is an easy to prove dichotomy result also for \(\mathsf {AnotherSAT}_{<n}(\varGamma )\).

We prove that Proposition 13 is essentially tight.

Proposition 18

For \(\varGamma \in \mathfrak {L}\) such that \(\mathrm {iN}\subseteq \langle \varGamma \rangle \subseteq \mathrm {iI}\) and any \(\varepsilon >0\) there is no polynomial-time \(n^{1-\varepsilon }\)-approximation algorithm for \(\mathsf {MSD}(\varGamma )\), unless \(\mathrm {P}= \mathrm {NP}\).


We show that any polynomial time \(n^{1-\varepsilon }\)-approximation algorithm for \(\mathsf {MSD}(\varGamma )\) would also allow to decide \(\mathsf {AnotherSAT}_{<n}(\varGamma )\), being \(\mathrm {NP}\)-complete by Proposition 16, in polynomial time.

The algorithm works as follows. Given an instance \((\varphi , m)\) for \(\mathsf {AnotherSAT}_{<n}(\varGamma )\), the algorithm accepts if m is not a constant assignment. Since \(\varGamma \) is 0-valid (and 1-valid), this output is correct. If \(\varphi \) has only one variable, reject because \(\varphi \) has only two models; otherwise, proceed as follows.

For each variable x of \(\varphi \), we construct a new formula \(\varphi '_{x}\) as follows. Let k be the smallest integer greater than \(1/\varepsilon \). Introduce \(n^k-n\) new variables \(x^i\) for \(i = 1, \ldots , n^k-n\). For every \(i \in \{1, \ldots , n^k-n\}\) and every constraint \(R(y_1, \ldots , y_\ell )\) in \(\varphi \), such that \(x \in \{y_1, \ldots , y_\ell \}\), construct a new constraint \(R(z_1^i, \ldots , z_\ell ^i)\) by \(z_j^i = x^i\) if \(y_j = x\) and \(z_j^i = y_j\) otherwise; add all the newly constructed constraints to \(\varphi \) in order to get \(\varphi '_{x}\). Note, that we can extend models s of \(\varphi \) to models \(s'\) of \(\varphi '_{x}\) by setting \(s'(x^i)=s(x)\). Now run the \(n^{1-\varepsilon }\)-approximation algorithm for \(\mathsf {MSD}(\varGamma )\) on \(\varphi '_{x}\). If for every x the answer is a pair \((m_1,m_2)\) with \(m_2 = \overline{m_1}\), then reject, otherwise accept.

This procedure is a correct polynomial-time algorithm for \(\mathsf {AnotherSAT}_{<n}(\varGamma )\). For polynomial runtime is clear, it remains to show correctness. If \(\varphi \) has only constant models, then the same is true for every \(\varphi '_{x}\). Thus each approximation must result in a pair of complementary constant assignments, and the output is correct. Assume now that there is a model s of \(\varphi \) different from \(\mathbf {0}\) and \(\mathbf {1}\). Hence, there exists a variable x such that \(s(x)=m(x)\). It follows that \(\varphi '_{x}\) has a model \(s'\) for which \({{\mathrm{hd}}}(s', m')<n\) holds, where n is the number of variables of \(\varphi \). But then the approximation algorithm must find two distinct models \(m_1\ne m_2\) of \(\varphi '_{x}\) satisfying \({{\mathrm{hd}}}(m_1, m_2) < n \cdot (n^k)^{1-\varepsilon } = n^{k(1-\varepsilon )+1}\). Since the inequality \(k > 1/\varepsilon \) holds, it follows that \({{\mathrm{hd}}}(m_1,m_2) < n^k\). Consequently, we have \(m_2\ne \overline{m_1}\) and the output of our algorithm is again correct.    \(\square \)

6 Concluding Remarks

Our problem is in \(\mathrm {PO}\) for constraints, which are bijunctive, or Horn, or dual Horn. The next complexity stage of the solution structure is characterized by affine constraints. In fact, these constraints represent the error correcting codes used in real-word applications. If we search for arbitrary two satisfying assignments with minimum distance, we can apply standard linear algebra techniques and perform an affine transformation, where we can enforce one of the assignments to be the zero-vector. This is not surprising, since in linear algebra many problems in an affine space can be transformed to the same problems in the corresponding vector space. The penultimate stage of solution structure complexity is represented by constraints, for which the existence of a solution is guaranteed by their definition, but we do not have any other exploitable information. For \(\mathsf {MSD}\) we need a guarantee of at least two solutions. Our problem belongs to the class \(\text {poly-APX}\) for these constraints. We can exactly pinpoint the polynomial (n, i.e. arity of the formula) for which we can get a polynomial-time approximation. Our complexity results indicate moreover that we cannot get a suitable approximation for these types of the considered optimization problem. All other cases are not polynomial-time approximable at all. It is interesting to see that our results differ considerably from those of [9] for \(\mathsf {MaxHammingDistance}\), asking to produce two satisfying assignments having maximal Hamming distance, even if the two problems are dual.


  1. 1.
    Aspvall, B., Plass, M.R., Tarjan, R.E.: A linear-time algorithm for testing the truth of certain quantified Boolean formulas. Inf. Process. Lett. 8(3), 121–123 (1979)MathSciNetCrossRefzbMATHGoogle Scholar
  2. 2.
    Ausiello, G., Crescenzi, P., Gambosi, G., Kann, V., Marchetti-Spaccamela, A., Protasi, M.: Complexity and Approximation: Combinatorial Optimization Problems and Their Approximability Properties. Springer, New York (1999)CrossRefzbMATHGoogle Scholar
  3. 3.
    Baker, K.A., Pixley, A.F.: Polynomial interpolation and the Chinese Remainder Theorem for algebraic systems. Mathematische Zeitschrift 143(2), 165–174 (1975)MathSciNetCrossRefzbMATHGoogle Scholar
  4. 4.
    Behrisch, M., Hermann, M., Mengel, S., Salzer, G.: Minimal distance of propositional models (2015). abs/1502.06761
  5. 5.
    Behrisch, M., Hermann, M., Mengel, S., Salzer, G.: Give me another one!. In: Elbassioni, K., Makino, K. (eds.) ISAAC 2015. LNCS, vol. 9472, pp. 664–676. Springer, Heidelberg (2015). doi: 10.1007/978-3-662-48971-0_56CrossRefGoogle Scholar
  6. 6.
    Böhler, E., Creignou, N., Reith, S., Vollmer, H.: Playing with Boolean blocks, part II: constraint satisfaction problems. SIGACT News 35(1), 22–35 (2004)CrossRefGoogle Scholar
  7. 7.
    Böhler, E., Reith, S., Schnoor, H., Vollmer, H.: Bases for Boolean co-clones. Inf. Process. Lett. 96(2), 59–66 (2005)MathSciNetCrossRefzbMATHGoogle Scholar
  8. 8.
    Creignou, N., Khanna, S., Sudan, M.: Complexity Classifications of Boolean Constraint Satisfaction Problems. SIAM Monographs on Discrete Mathematics and Applications, vol. 7. SIAM, Philadelphia (2001)CrossRefzbMATHGoogle Scholar
  9. 9.
    Crescenzi, P., Rossi, G.: On the Hamming distance of constraint satisfaction problems. Theor. Comput. Sci. 288(1), 85–100 (2002)MathSciNetCrossRefzbMATHGoogle Scholar
  10. 10.
    Dumer, I., Micciancio, D., Sudan, M.: Hardness of approximating the minimum distance of a linear code. IEEE Trans. Inf. Theory 49(1), 22–37 (2003)MathSciNetCrossRefzbMATHGoogle Scholar
  11. 11.
    Jeavons, P., Cohen, D., Gyssens, M.: Closure properties of constraints. J. Assoc. Comput. Mach. 44(4), 527–548 (1997)MathSciNetCrossRefzbMATHGoogle Scholar
  12. 12.
    Juban, L.: Dichotomy theorem for the generalized unique satisfiability problem. In: Ciobanu, G., Păun, G. (eds.) FCT 1999. LNCS, vol. 1684, pp. 327–337. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  13. 13.
    Lagerkvist, V.: Weak bases of Boolean co-clones. Inf. Process. Lett. 114(9), 462–468 (2014)MathSciNetCrossRefzbMATHGoogle Scholar
  14. 14.
    Schaefer, T.J.: The complexity of satisfiability problems. In: Proceedings of the Tenth Annual ACM Symposium on Theory of Computing, STOC 1978, San Diego, California, pp. 216–226. ACM, New York (1978).
  15. 15.
    Schnoor, H., Schnoor, I.: Partial polymorphisms and constraint satisfaction problems. In: Creignou, N., Kolaitis, P.G., Vollmer, H. (eds.) Complexity of Constraints. LNCS, vol. 5250, pp. 229–254. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  16. 16.
    Warshall, S.: A theorem on Boolean matrices. J. Assoc. Comput. Mach. 9(1), 11–12 (1962)MathSciNetCrossRefzbMATHGoogle Scholar

Copyright information

© Springer International Publishing Switzerland 2016

Authors and Affiliations

  • Mike Behrisch
    • 1
  • Miki Hermann
    • 2
  • Stefan Mengel
    • 2
  • Gernot Salzer
    • 1
  1. 1.Technische Universität WienViennaAustria
  2. 2.LIX (UMR CNRS 7161)École PolytechniquePalaiseauFrance

Personalised recommendations