liveBook · Manning

Diagonal constraint

As explained in Quantum Programming in Depth

A diagonal constraint is the N queens condition that each board diagonal contains at most one queen.

The diagonal constraint requires that no two queens occupy the same diagonal. Representing the queen in row r by column index c, compare every pair of rows: for row difference Δ, the column difference must be neither 0, Δ, nor −Δ. section 8.3.1

For a pair of queens in rows r1 and r2, compute diff = c1 − c2:

  • Reject diff = 0 because the queens share a column. section 8.3.1
  • Reject |diff| = r2 − r1 because the queens share a diagonal. section 8.3.1
  • Check each row pair independently and store its validity for the marking oracle. section 8.2.2

Classical validation

After extracting one column index per row, reject a placement whenever diff == 0 or abs(diff) == r2 - r1; otherwise continue through all row pairs.

How Quantum Programming in Depth covers it

How deep it goes
Derives the forbidden differences, applies them to every row pair, and stops short of detailed subtraction-circuit internals.
Examples
Uses pairwise row-index differences, a Python validator, and Qiskit oracle registers for row-pair constraint results.
What it assumes
Assumes row and column indices, pairwise subtraction, and one-queen-per-row encoding; teaches the diagonal criterion explicitly.
What you can do after
Apply it via Python or Qiskit to validate placements and mark diagonal violations during quantum search.
How it connects
Connects N queens puzzle, column constraint, Grover's algorithm, marking oracle, and reversible computation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quantum Programming in Depth. The section links point to the parts of the book it draws on.