feat(encode): add pigeonhole principle generator

This commit is contained in:
dualfroz committed 2026-08-27 09:00:00 +02:00
1 parent 8af1fa439a
commit ec9edca5fa
1 file changed
+20
+20
View File
@@ -0,0 +1,20 @@
module Sift.Pigeonhole
( pigeonhole
) where
import Sift.Types
-- pigeonhole pigeons holes encodes: every pigeon sits in some hole, and no two
-- pigeons share a hole. With pigeons > holes the formula is UNSAT.
pigeonhole :: Int -> Int -> CNF
pigeonhole pigeons holes = CNF (atLeastOne ++ atMostOne)
where
cell p h = Var ((p - 1) * holes + h)
atLeastOne =
[ [ posLit (cell p h) | h <- [1 .. holes] ]
| p <- [1 .. pigeons] ]
atMostOne =
[ [ negLit (cell p h), negLit (cell q h) ]
| h <- [1 .. holes]
, p <- [1 .. pigeons]
, q <- [p + 1 .. pigeons] ]