logic program for stratified datalog
Assume a directed graph is represented as a set of facts of the form node(x) for a node x, and edge(x; y) for an edge (x; y). A node x is red if there is a fact red(x). If possible, formulate the following queries in Datalog. If this is not possible, explain why, and formulate the query in Stratied Datalog not, proving that the resulting program is stratied. The programs can share rules but you have to clearly indicate which rules belong to which program.
Write a logic program P1 that returns the nodes x such that there is a path from x to a red node.
Write a logic program P2 that returns the pairs (x; y) such that there is a path from x to y that does not include a red node.
Write a logic program P3 that returns the pairs (x; y) such that every path from x to y includes a red node.
Construct a graph G such that P2 and P3 return at least one answer each.
Run P2 and P3 on the set of facts representing G, using xsb. Document the runs.