Exercise 8: Datalog Database Theory 2020-06-08 Maximilian Marx, David Carral 1 / 47
Exercise 1 Exercise. A graph is planar if it can be drawn on the plane without intersections of edges. For example, the following graph A is planar, while graph B is not: Figure: A Figure: B 1. Can the graphs A and B be distinguished by a FO query? 2. Show that planarity is not FO-definable by using locality. 2 / 47
Exercise 1 Exercise. A graph is planar if it can be drawn on the plane without intersections of edges. For example, the following graph A is planar, while graph B is not: Figure: A Figure: B 1. Can the graphs A and B be distinguished by a FO query? 2. Show that planarity is not FO-definable by using locality. Solution. 3 / 47
Exercise 1 Exercise. A graph is planar if it can be drawn on the plane without intersections of edges. For example, the following graph A is planar, while graph B is not: Figure: A Figure: B 1. Can the graphs A and B be distinguished by a FO query? 2. Show that planarity is not FO-definable by using locality. Solution. 1. This query matches B but not A: ∃ x , y , z , w , v . E ( x , y ) ∧ E ( y , z ) ∧ E ( z , w ) ∧ E ( w , x ) ∧ E ( x , v ) ∧ E ( y , v ) ∧ E ( z , v ) ∧ E ( w , v ) ∧ E ( x , z ) ∧ E ( y , w ) 4 / 47
Exercise 1 Exercise. A graph is planar if it can be drawn on the plane without intersections of edges. For example, the following graph A is planar, while graph B is not: Figure: A Figure: B 1. Can the graphs A and B be distinguished by a FO query? 2. Show that planarity is not FO-definable by using locality. Solution. 1. This query matches B but not A: ∃ x , y , z , w , v . E ( x , y ) ∧ E ( y , z ) ∧ E ( z , w ) ∧ E ( w , x ) ∧ E ( x , v ) ∧ E ( y , v ) ∧ E ( z , v ) ∧ E ( w , v ) ∧ E ( x , z ) ∧ E ( y , w ) 2. For ϕ with quantifier rank r , consider counterexamples of size d = 3 r : d d d d . . . . . . . . . . . . . . . . . . . . . . . . d d . . . . . . . . . . d d . . . . . . . . . . . . . . d d d d 5 / 47
Exercise 2 Exercise. Consider the example Datalog program from the lecture: (a) Father ( alice , bob ) (4) Ancestor ( x , z ) ← Parent ( x , y ) ∧ Ancestor ( y , z ) (1) Parent ( x , y ) ← Father ( x , y ) (b) Mother ( alice , carla ) (5) SameGeneration ( x , x ) ← (2) Parent ( x , y ) ← Mother ( x , y ) (c) Mother ( evan , carla ) SameGeneration ( x , y ) ← Parent ( x , v ) ∧ Parent ( y , w ) (3) Ancestor ( x , y ) ← Parent ( x , y ) (6) (d) Father ( carla , david ) ∧ SameGeneration ( v , w ) 1. Give a proof tree for SameGeneration ( evan , alice ) . 2. Compute the sets T 0 P , T 1 P , T 2 P , . . . When is the fixed point reached? 6 / 47
Exercise 2 Exercise. Consider the example Datalog program from the lecture: (a) Father ( alice , bob ) (4) Ancestor ( x , z ) ← Parent ( x , y ) ∧ Ancestor ( y , z ) (1) Parent ( x , y ) ← Father ( x , y ) (b) Mother ( alice , carla ) (5) SameGeneration ( x , x ) ← (2) Parent ( x , y ) ← Mother ( x , y ) (c) Mother ( evan , carla ) SameGeneration ( x , y ) ← Parent ( x , v ) ∧ Parent ( y , w ) (3) Ancestor ( x , y ) ← Parent ( x , y ) (6) (d) Father ( carla , david ) ∧ SameGeneration ( v , w ) 1. Give a proof tree for SameGeneration ( evan , alice ) . 2. Compute the sets T 0 P , T 1 P , T 2 P , . . . When is the fixed point reached? Solution. 7 / 47
Exercise 2 Exercise. Consider the example Datalog program from the lecture: (a) Father ( alice , bob ) (4) Ancestor ( x , z ) ← Parent ( x , y ) ∧ Ancestor ( y , z ) (1) Parent ( x , y ) ← Father ( x , y ) (b) Mother ( alice , carla ) (5) SameGeneration ( x , x ) ← (2) Parent ( x , y ) ← Mother ( x , y ) (c) Mother ( evan , carla ) SameGeneration ( x , y ) ← Parent ( x , v ) ∧ Parent ( y , w ) (3) Ancestor ( x , y ) ← Parent ( x , y ) (6) (d) Father ( carla , david ) ∧ SameGeneration ( v , w ) 1. Give a proof tree for SameGeneration ( evan , alice ) . 2. Compute the sets T 0 P , T 1 P , T 2 P , . . . When is the fixed point reached? Solution. 1. SameGeneration ( evan , alice ) (6); { x �→ evan , v �→ carla , y �→ alice , w �→ carla } Parent ( evan , carla ) Parent ( alice , carla ) SameGeneration ( carla , carla ) (5); { x �→ carla } (2); { x �→ evan , y �→ carla } (2); { x �→ alice , y �→ carla } Mother ( evan , carla ) Mother ( alice , carla ) (c) (b) 8 / 47
Exercise 2 Exercise. Consider the example Datalog program from the lecture: (a) Father ( alice , bob ) (4) Ancestor ( x , z ) ← Parent ( x , y ) ∧ Ancestor ( y , z ) (1) Parent ( x , y ) ← Father ( x , y ) (b) Mother ( alice , carla ) (5) SameGeneration ( x , x ) ← (2) Parent ( x , y ) ← Mother ( x , y ) (c) Mother ( evan , carla ) SameGeneration ( x , y ) ← Parent ( x , v ) ∧ Parent ( y , w ) (3) Ancestor ( x , y ) ← Parent ( x , y ) (6) (d) Father ( carla , david ) ∧ SameGeneration ( v , w ) 1. Give a proof tree for SameGeneration ( evan , alice ) . 2. Compute the sets T 0 P , T 1 P , T 2 P , . . . When is the fixed point reached? Solution. 2. T 0 P = ∅ 9 / 47
Exercise 2 Exercise. Consider the example Datalog program from the lecture: (a) Father ( alice , bob ) (4) Ancestor ( x , z ) ← Parent ( x , y ) ∧ Ancestor ( y , z ) (1) Parent ( x , y ) ← Father ( x , y ) (b) Mother ( alice , carla ) (5) SameGeneration ( x , x ) ← (2) Parent ( x , y ) ← Mother ( x , y ) (c) Mother ( evan , carla ) SameGeneration ( x , y ) ← Parent ( x , v ) ∧ Parent ( y , w ) (3) Ancestor ( x , y ) ← Parent ( x , y ) (6) (d) Father ( carla , david ) ∧ SameGeneration ( v , w ) 1. Give a proof tree for SameGeneration ( evan , alice ) . 2. Compute the sets T 0 P , T 1 P , T 2 P , . . . When is the fixed point reached? Solution. 2. T 0 P = ∅ T 1 P = { Father ( alice , bob ) , Mother ( alice , carla ) , Mother ( evan , carla ) , Father ( carla , david ) } 10 / 47
Exercise 2 Exercise. Consider the example Datalog program from the lecture: (a) Father ( alice , bob ) (4) Ancestor ( x , z ) ← Parent ( x , y ) ∧ Ancestor ( y , z ) (1) Parent ( x , y ) ← Father ( x , y ) (b) Mother ( alice , carla ) (5) SameGeneration ( x , x ) ← (2) Parent ( x , y ) ← Mother ( x , y ) (c) Mother ( evan , carla ) SameGeneration ( x , y ) ← Parent ( x , v ) ∧ Parent ( y , w ) (3) Ancestor ( x , y ) ← Parent ( x , y ) (6) (d) Father ( carla , david ) ∧ SameGeneration ( v , w ) 1. Give a proof tree for SameGeneration ( evan , alice ) . 2. Compute the sets T 0 P , T 1 P , T 2 P , . . . When is the fixed point reached? Solution. 2. T 0 P = ∅ T 1 P = { Father ( alice , bob ) , Mother ( alice , carla ) , Mother ( evan , carla ) , Father ( carla , david ) } T 2 P = T 1 P ∪ { Parent ( alice , bob ) , Parent ( alice , carla ) , Parent ( evan , carla ) , Parent ( carla , david ) , SameGeneration ( alice , alice ) , SameGeneration ( bob , bob ) , SameGeneration ( carla , carla ) , SameGeneration ( david , david ) , SameGeneration ( evan , evan ) } 11 / 47
Exercise 2 Exercise. Consider the example Datalog program from the lecture: (a) Father ( alice , bob ) (4) Ancestor ( x , z ) ← Parent ( x , y ) ∧ Ancestor ( y , z ) (1) Parent ( x , y ) ← Father ( x , y ) (b) Mother ( alice , carla ) (5) SameGeneration ( x , x ) ← (2) Parent ( x , y ) ← Mother ( x , y ) (c) Mother ( evan , carla ) SameGeneration ( x , y ) ← Parent ( x , v ) ∧ Parent ( y , w ) (3) Ancestor ( x , y ) ← Parent ( x , y ) (6) (d) Father ( carla , david ) ∧ SameGeneration ( v , w ) 1. Give a proof tree for SameGeneration ( evan , alice ) . 2. Compute the sets T 0 P , T 1 P , T 2 P , . . . When is the fixed point reached? Solution. 2. T 0 P = ∅ T 1 P = { Father ( alice , bob ) , Mother ( alice , carla ) , Mother ( evan , carla ) , Father ( carla , david ) } T 2 P = T 1 P ∪ { Parent ( alice , bob ) , Parent ( alice , carla ) , Parent ( evan , carla ) , Parent ( carla , david ) , SameGeneration ( alice , alice ) , SameGeneration ( bob , bob ) , SameGeneration ( carla , carla ) , SameGeneration ( david , david ) , SameGeneration ( evan , evan ) } T 3 P = T 2 P ∪ { Ancestor ( alice , bob ) , Ancestor ( alice , carla ) , Ancestor ( evan , carla ) , Ancestor ( carla , david ) , SameGeneration ( alice , evan ) , SameGeneration ( evan , alice ) } 12 / 47
Exercise 2 Exercise. Consider the example Datalog program from the lecture: (a) Father ( alice , bob ) (4) Ancestor ( x , z ) ← Parent ( x , y ) ∧ Ancestor ( y , z ) (1) Parent ( x , y ) ← Father ( x , y ) (b) Mother ( alice , carla ) (5) SameGeneration ( x , x ) ← (2) Parent ( x , y ) ← Mother ( x , y ) (c) Mother ( evan , carla ) SameGeneration ( x , y ) ← Parent ( x , v ) ∧ Parent ( y , w ) (3) Ancestor ( x , y ) ← Parent ( x , y ) (6) (d) Father ( carla , david ) ∧ SameGeneration ( v , w ) 1. Give a proof tree for SameGeneration ( evan , alice ) . 2. Compute the sets T 0 P , T 1 P , T 2 P , . . . When is the fixed point reached? Solution. 2. T 0 P = ∅ T 1 P = { Father ( alice , bob ) , Mother ( alice , carla ) , Mother ( evan , carla ) , Father ( carla , david ) } T 2 P = T 1 P ∪ { Parent ( alice , bob ) , Parent ( alice , carla ) , Parent ( evan , carla ) , Parent ( carla , david ) , SameGeneration ( alice , alice ) , SameGeneration ( bob , bob ) , SameGeneration ( carla , carla ) , SameGeneration ( david , david ) , SameGeneration ( evan , evan ) } T 3 P = T 2 P ∪ { Ancestor ( alice , bob ) , Ancestor ( alice , carla ) , Ancestor ( evan , carla ) , Ancestor ( carla , david ) , SameGeneration ( alice , evan ) , SameGeneration ( evan , alice ) } T 4 P = T 3 P ∪ { Ancestor ( alice , david ) , Ancestor ( evan , david ) } = T 5 P 13 / 47
Recommend
More recommend