CNF Encoding Patterns (At Least, At Most, Exactly)

Context: FIT2014_MOC · turning a counting condition into CNF mechanically · the reusable half of Encoding Problems in Propositional Logic Problem it solves: given options, write CNF for “pick at least / at most / exactly of them”.

Quick Revision

  • 🎯 Trigger: any phrase reducible to “at least / at most / exactly from options” ➔ apply the clause-size formula, then enumerate combinations.
  • ⚡ Key Constraint: the formula is on clause size, not clause count — for at least from , every clause has literals, and you write all of them.

📐 The master formula

  • At least from ➔ literals per clause ; clauses = all combinations of size , i.e. clauses; literals unnegated.
  • Sanity checkat least gives : one clause with everything, . At least gives : singleton clauses .
  • Visual trick ➔ write symbols, circle the first , draw a box from the last symbol back until it encloses exactly one circled symbol; the box size is the clause size.

🔧 Worked patterns

At least from , so all pairs:

At least from , so all triples:

At most from ➔ equivalent to “do not pick at least ” ⟹ use the same formula on the negated literals with : At most from , all clauses of negated literals:

Exactly from ➔ simply conjoin the two:

🔀 Common special cases

ConditionCNF shapeNote
at least one of one clause already CNF
at most one of pairwise for all clauses
exactly one of the workhorse
rewrite implication
two clauses

✍️ Practice

⚠️ Common Mistakes

  • 💡 The formula sizes the clause, not the count is literals per clause; the number of clauses is then . Swapping these is the standard error.
  • 💡 “At most” needs negated literals ➔ it is at least of the complements; forgetting to negate produces a formula asserting the opposite.
  • 💡 A single big negated clause is wrong for “at most one” only forbids all three; “no more than one” needs pairwise clauses.
  • 💡 Enumerate systematically ➔ write clauses in alphabetical order (new leading variable ⟹ new line) so no combination is skipped under time pressure.

🧠 Active Recall