(Context)
Given two byte arrays of length 16, say $L$ and $H$, one can define a mapping $M$ from the set of all bytes to itself in the following way.
If $0 \le b \lt 256$ is a byte, let $\text{lo}(b)$ denote the lower 4 bits of $b$ and let $\text{hi}(b)$ denote the higher 4 bits of $b$.
Let $L_i$ (resp. $H_i$) denote the $i$-th byte of $L$ (resp. $H$). Also let $L_{i,j}$ (resp. $H_{i,j}$) denote the $j$-th bit of the $i$-th byte of $L$ (resp. $H$).
$$ M: \{0,\dots,255\} \to \{0,\dots,255\} \\ b \mapsto L_{\text{lo}(b)} \land H_{\text{hi}(b)} $$
Where $\land$ is bitwise logical conjunction.
If we want $M$ to satisfy $M(b_0) = m_0, \dots, M(b_p) = m_p$ for bytes $b_k$ and bytes $m_k$ with $0 \le k \lt p$. Then $L$ and $H$ have to be chosen accordingly (if possible). Note that while the $b_k$ bytes are known, the $m_k$ bytes are not. Hence why they persist as propositional variables in the following clauses.
A constraint of the form $M(b_k) = m_k$ can be translated to:
$$ L_{\text{lo}(b_k)} \land H_{\text{hi}(b_k)} = m_k $$
Or more precisely:
$$ L_{\text{lo}(b_k), j} \land H_{\text{hi}(b_k), j} = m_{k,j} $$
Where $m_{k,j}$ is the $j$-th bit of $m_k$.
In general, any equation of the form $X \land Y = Z$ where $X, Y, Z$ are bits (or booleans) is equivalent the following boolean clauses in propositional logic:
$$ \bar{X} \lor \bar{Y} \lor Z \\ X \lor \bar{Z} \\ Y \lor \bar{Z} \\ $$
Where $\bar{X}$ is the negation of $X$.
The last remaining piece of the problem is the fact that all $m_k$ bytes should be distinct. Two bits $X$ and $Y$ are non-equal iff the following clauses hold:
$$ X \lor Y \\ \bar{X} \lor \bar{Y} $$
Hence this problem can be solved using 3-SAT. I have three question with regards to this:
- Is my problem equivalent to 3-SAT, i.e. can an arbitrary 3-SAT problem be reduced to it? Or is it further simplifiable into something less difficult?
- If not, do you see an algorithm for solving it efficiently?
- If yes, would a "simple" CDCL-based solver suffice? (We're dealing with around 3000 clauses and 300 variables).
I have already tried a basic backtracking solver and it failed to terminate even after multiple hours. I'm writing this after having spent multiple weeks thinking about this, and having failed to come up with a specialised algorithm. I could of course just use an off-the-shelf SAT solver but I'm interested in solving this as efficiently as possible.
Thank you in advance.