Exercises.Complexity.FiniteCSP¶
CSP Exercises¶
This is the Exercises.Complexity.FiniteCSP module of the Agda Universal Algebra Library.
Excercises in this module were created by Libor Barto for students at Charles University in Prague. They were formalized in dependent type theory by the agda-algebras development team.
Some exercises below refer to the following relations on ๐ := {0, 1} (where i, j โ ๐):
\begin{align} Cแตแตข & := { i } \ Rแต & := { (0, 0), (1, 1) } \ Nแต & := { (0, 1), (1, 0) } \ Sแต_{ij} & := ๐ยฒ - { (i , j) }, \ Hแต & := ๐ยณ - { (1, 1, 0) } \ Gแตโ & := { (0,0,0), (0,1,1), (1,0,1), (1,1,0) } \ Gแตโ & := { (0,0,1), (0,1,0), (1,0,0), (1,1,1) } \end{align}
Exercise 1. Prove that the definitions of CSP(๐ธ) (satisfiability of a list of constraints, homomorphism problem, truth of primitive positive formulas) are equivalent.
Exercise 2. Find a polynomial-time algorithm for CSP(A), where
2.1. ๐จ = ({0, 1}, Rแต) = (๐ , {(0,0), (1, 1)}) 2.2. ๐จ = ({0, 1}, Rแต, Cโแต, Cโแต) = (๐ , { (0,0) , (1, 1) } , { 0 } , { 1 }) 2.3. ๐จ = ({0, 1}, Sโโแต) = (๐ , ๐ยณ - { (1, 0) }) 2.4. ๐จ = ({0, 1}, Sโโแต, Cโแต, Cโแต) = (๐ , ๐ยณ - { (1, 0) } , { 0 } , { 1 }) 2.5. ๐จ = ({0, 1}, Sโโแต, Sโโแต, Cโแต, Cโแต) = (๐ , ๐ยณ - { (0, 1) } , ๐ยณ - { (1, 0) } , { 0 } , { 1 }) 2.6. ๐จ = ({0, 1}, Nแต) = (๐ , { (0, 1) , (1, 0) }) 2.7. ๐จ = ({0, 1}, Rแต, Nแต, Cโแต, Cโแต) = (๐ , { (0,0) , (1, 1) } , { (0, 1) , (1, 0) } , { 0 } , { 1 }) 2.8. ๐จ = ({0, 1}, Rแต, Nแต, Cโแต, Cโแต, ๐โโ, Sโโแต, Sโโแต, Sโโแต) = (๐ , { (0,0) , (1, 1) } , { (0, 1) , (1, 0) } , { 0 } , { 1 } , ๐ยณ - { (0, 0) } , ๐ยณ - { (0, 1) } , ๐ยณ - { (1, 0) } , ๐ยณ - { (1, 1) }) 2.9. ๐จ = ({0, 1}, all unary and binary relations)
Solution 2.1. If ๐จ = ({0, 1}, Rแต) = (๐ , {(0,0), (1, 1)}), then an instance of (the HOM formulation of) CSP(๐จ) is a relational structure ๐ฉ = (B, Rแตโฉ, where Rแต โ Bยฒ and we must decide whether there exists a homomorphism f : ๐ฉ โ ๐จ, that is, a map f : B โ A (= ๐) such that โ (b, b'), if (b, b') โ Rแต, then (f b, f b') โ Rแต.
Of course, the constant map f โก 0 that sends every element of B to 0 (as well as the constantly-1 map) is such a homomorphism. Let's prove this formally.
module solution-2-1 where -- The (purely) relational structure with -- + 2-element domain, -- + one binary relation Rแต := \{(0,0), (1, 1)\} data Rแต : Pred (๐ ร ๐) โโ where r1 : (๐.๐ , ๐.๐ ) โ Rแต r2 : (๐.๐ , ๐.๐ ) โ Rแต ๐จ : structure Sโ -- (no operation symbols) S001 -- (one binary relation symbol) ๐จ = record { carrier = ๐ ; op = ฮป () ; rel = ฮป _ x โ ((x ๐.๐) , (x ๐.๐)) โ Rแต } -- Claim: Given an arbitrary ๐ฉ in the signatures Sigโ Sig001, we can construct a homomorphism from ๐ฉ to ๐จ. claim : (๐ฉ : structure {โโ}{โโ}{โโ}{โโ} Sโ S001 {โโ}{โโ}) โ hom ๐ฉ ๐จ claim ๐ฉ = (ฮป x โ ๐.๐) , (ฮป _ _ _ โ r1) , ฮป ()
In general, whenever the template structure ๐จ has a one-element subuniverse, say, { a }, then the constant map that always gives a is a homomorphism from any structure in the given signature to ๐จ. โ
Solution 2.2. If ๐จ = ({ 0, 1 }, Rแต, Cโแต, Cโแต) = (๐ , { (0, 0) , (1, 1) } , { 0 } , { 1 }), then an instance of HOM CSP(๐จ) is a relational structure ๐ฉ = (B, Rแต, Cโแต, Cโแต), where Rแต โ Bยฒ, Cโแต โ B, Cโแต โ B, and we must decide whether there exists a homomorphism f : hom ๐ฉ ๐จ, that is, a map f : B โ ๐ such that the following conditions hold: 1. โ (x, y) โ Bยฒ, (x, y) โ Rแต implies (f x , f y) โ Rแต, 2. f is constantly 0 on Cโแต, and 3. f is constantly 1 on Cโแต.
The first condition says that if (x, y) โ Rแต, then either f x = 0 = f y or f x = 1 = f y.
Therefore, there exists a homomorphism f : hom ๐ฉ ๐จ iff Rแต โฉ Cโแต ร Cโแต = โ = Rแต โฉ Cโแต ร Cโแต.
We can check this in polynomial time (in the size of the input instance ๐ฉ) since we just need to check each pair (x, y) โ Rแต and make sure that the following two implications hold:
- x โ Cโแต only if y โ Cโแต, and
- x โ Cโแต only if y โ Cโแต.
module solution-2-2 where -- The (purely) relational structure with -- + 2-element domain, -- + one binary relation: Rแต := { (0,0), (1, 1) } -- + two unary relations: Cโแต := { 0 } , Cโแต := { 1 } data Rแต : Pred (๐ ร ๐) โโ where r1 : (๐.๐ , ๐.๐ ) โ Rแต r2 : (๐.๐ , ๐.๐ ) โ Rแต data Cโแต : Pred ๐ โโ where cโ : ๐.๐ โ Cโแต data Cโแต : Pred ๐ โโ where cโ : ๐.๐ โ Cโแต ๐จ : structure Sโ -- (no operations) S021 -- (two unary relations and one binary relation) ๐จ = record { carrier = ๐ ; op = ฮป () ; rel = rels } where rels : (r : ๐) โ Rel ๐ (arity S021 r) rels ๐.๐ x = ((x ๐.๐) , (x ๐.๐)) โ Rแต rels ๐.๐ x = x ๐ โ Cโแต rels ๐.๐ x = x ๐ โ Cโแต -- Claim: Given an arbitrary ๐ฉ in the signatures Sโ S021, we can construct a homomorphism from ๐ฉ to ๐จ. -- claim : (๐ฉ : structure Sโ S021 {โโ}{โโ}) -- โ (โ (x : ๐ โ carrier ๐ฉ) -- โ (rel ๐ฉ) ๐.๐ x -- if ((x ๐.๐) , (x ๐.๐)) โ Rแต, then... -- โ ((rel ๐ฉ) ๐.๐ (ฮป _ โ (x ๐.๐)) โ ยฌ (rel ๐ฉ) ๐.๐ (ฮป _ โ (x ๐.๐))) -- ร ((rel ๐ฉ) ๐.๐ (ฮป _ โ (x ๐.๐)) โ ยฌ (rel ๐ฉ) ๐.๐ (ฮป _ โ (x ๐.๐))) -- -- ร (x ๐.๐ โ Cโแต โ x ๐.๐ โ Cโแต)) -- ) -- โ hom ๐ฉ ๐จ -- claim ๐ฉ x = {!!}
(The remainder are "todo.")
Solution 2.3. ๐จ = ({0, 1}, Sโโแต) = (๐ , ๐ยณ - { (1, 0) })
Solution 2.4. ๐จ = ({0, 1}, Sโโแต, Cโแต, Cโแต) = (๐ , ๐ยณ - { (1, 0) } , { 0 } , { 1 })
Solution 2.5. ๐จ = ({0, 1}, Sโโแต, Sโโแต, Cโแต, Cโแต) = (๐ , ๐ยณ - { (0, 1) } , ๐ยณ - { (1, 0) } , { 0 } , { 1 })
Solution 2.6. ๐จ = ({0, 1}, Nแต) = (๐ , { (0, 1) , (1, 0) })
Solution 2.7. ๐จ = ({0, 1}, Rแต, Nแต, Cโแต, Cโแต) = (๐ , { (0,0) , (1, 1) } , { (0, 1) , (1, 0) } , { 0 } , { 1 })
Solution 2.8. ๐จ = ({0, 1}, Rแต, Nแต, Cโแต, Cโแต, ๐โโ, Sโโแต, Sโโแต, Sโโแต) = (๐ , { (0,0) , (1, 1) } , { (0, 1) , (1, 0) } , { 0 } , { 1 } , ๐ยณ - { (0, 0) } , ๐ยณ - { (0, 1) } , ๐ยณ - { (1, 0) } , ๐ยณ - { (1, 1) })
Solution 2.9. ๐จ = ({0, 1}, all unary and binary relations)
Exercise 3. Find a polynomial-time algorithm for CSP({0, 1}, Hแต, Cโแต, Cโแต).
Exercise 4. Find a polynomial-time algorithm for CSP({0, 1}, Cโแต, Cโแต, Gโแต, Gโแต).
Exercise 5. Find a polynomial-time algorithm for CSP(โ, <).