Part 3 · Constraint Randomization · Intermediate
Interview Constraint Patterns — Write-the-Constraint Drills
Hub — classic write-the-constraint interview drills: parity, ranges, bit games, uniqueness, sums, dependencies, timing, and anti-patterns.
Overview
Every verification interview has a round where the interviewer says “write a constraint so that…” — and the value is constrained to be even, or a power of two, or all array elements are unique. These drills look trivial but discriminate sharply: a candidate who thinks declaratively (relations the solver must satisfy) answers in seconds; a candidate who thinks procedurally (assignments executed in order) writes code that does not compile or silently over-constrains.
This topic is a pure drill set. Each sub-lesson states problems exactly as an interviewer would, walks the solution space, gives the full working constraint, the variation that comes next, and the classic wrong answers — so you recognize the trap before you write it on the whiteboard.
Sub-topics
Even/Odd, Alignment & Divisibility — bit slices, modulo, shifts, alignment masks.
Ranges With & Without inside — bounds, disjoint sets, exclusions, rand-on-rand bounds.
Powers of 2, One-Hot & Bit Games — $onehot, $countones, gray codes, palindromes.
Unique Values & Ordering — unique, pairwise foreach, sorted arrays, permutations.
Sum, Checksum & Distribution Drills — sum-to-N, length fields, dist weight math.
Dependent-Field Puzzles — implication ranges, capacity products, wraparound, FSM pairs.
Sequence & Timing Patterns — gaps, jitter, bursts, fairness bounds.
Constraint Anti-Patterns Review — every interviewer-bait wrong answer in one place.
Legend: [DRILL] [TRAP]
THE WRITE-THE-CONSTRAINT INTERVIEW MAP
"Make x even" ──► bit slice / modulo / shift [DRILL 1]
"x between a and b" ──► relational pair / inside [DRILL 2]
"x is a power of 2" ──► 1<<k helper / $onehot [DRILL 3]
"all elements unique" ──► unique / pairwise foreach [DRILL 4]
"array sums to N" ──► sum() with width cast [DRILL 5]
"addr depends on kind" ──► implication / if-else [DRILL 6]
"requests with min gap" ──► element-wise timing arrays [DRILL 7]
Behind every drill, the same trap: [TRAP]
procedural thinking → "x = x & ~1;" (assignment — illegal)
declarative thinking → "x[0] == 1'b0;" (relation — correct)Key takeaways
Constraints are relations the solver satisfies simultaneously — never sequenced assignments.
Most drills have 2-3 valid forms; know them all and say which you prefer and why.
The follow-up variation is where seniority shows — anticipate it in your first answer.