Motivation
MQT QAO (arXiv:2406.12840) ships dedicated quadratic penalty gadgets for ~a=b, a&b=c, a|b=c, a^b=c (src/mqt/qao/constraints.py:187-671). Their version is limited to raw single binary variables and its AND/OR solution checkers contain operator-precedence bugs (bool(e1) and bool(e2) == bool(e3) at constraints.py:402,458,557,613), so this is not a battle-tested advantage β but the minimal-gadget forms do save ancillas and penalty magnitude versus a generic squared residual.
Current state
src/compiler/constraints.jl has constraint() dispatch only for SAF/SQF in EQ/LT/GT/Interval (:198-760), VectorOfVariables-in-SOS1 (:770), and Indicator (:914-978) β no logic-set or gadget-pattern handling. Every gate is expressible today: e.g. c == a*b compiles via the SQF-in-EQ path (:484-541, squared residual + Quadratize at :535), at the cost of ancilla overhead.
Proposed change
Add pattern recognition inside constraint(model, ci, f::SQF, s::EQ) (constraints.jl:494-541) for residuals of shape:
c - a*b β textbook AND penalty,
a + b - a*b - c β OR penalty,
a + b - 2ab - c β XOR (cubic residual; reuses the existing Quadratize path),
emitting the penalty PBF directly and skipping the square. Alternatively (or additionally) document MOI.Indicator-based formulations, which are already supported. All variables involved must be verified binary before matching; fall back to the generic path otherwise.
Acceptance criteria
Part of the MQT QAO parity epic: JuliaQUBO/QUBO.jl#69
Motivation
MQT QAO (arXiv:2406.12840) ships dedicated quadratic penalty gadgets for
~a=b,a&b=c,a|b=c,a^b=c(src/mqt/qao/constraints.py:187-671). Their version is limited to raw single binary variables and its AND/OR solution checkers contain operator-precedence bugs (bool(e1) and bool(e2) == bool(e3)atconstraints.py:402,458,557,613), so this is not a battle-tested advantage β but the minimal-gadget forms do save ancillas and penalty magnitude versus a generic squared residual.Current state
src/compiler/constraints.jlhasconstraint()dispatch only for SAF/SQF in EQ/LT/GT/Interval (:198-760), VectorOfVariables-in-SOS1 (:770), and Indicator (:914-978) β no logic-set or gadget-pattern handling. Every gate is expressible today: e.g.c == a*bcompiles via the SQF-in-EQ path (:484-541, squared residual +Quadratizeat:535), at the cost of ancilla overhead.Proposed change
Add pattern recognition inside
constraint(model, ci, f::SQF, s::EQ)(constraints.jl:494-541) for residuals of shape:c - a*bβ textbook AND penalty,a + b - a*b - cβ OR penalty,a + b - 2ab - cβ XOR (cubic residual; reuses the existingQuadratizepath),emitting the penalty PBF directly and skipping the square. Alternatively (or additionally) document MOI.Indicator-based formulations, which are already supported. All variables involved must be verified binary before matching; fall back to the generic path otherwise.
Acceptance criteria
Part of the MQT QAO parity epic: JuliaQUBO/QUBO.jl#69