CS345 PROBLEM SET #2

SOLUTIONS

6 Questions, 100 pts.

### Problem 1 (25 pts.)

In this problem we will use two kinds of electronic gates, *NAND
gates* and *INVOR gates*.
A *NAND gate* has inputs X and Y; its output Z is F(alse) if
and only if both X and Y are T(rue).
In this problem the only *INVOR gate* has inputs X and Y; its
output Z is F(alse) if and only if X is T(rue) and Y is F(alse).
We can represents a circuit of NAND and INVOR gates by the EDB predicate
*wireT*(Z), meaning that wire Z is a circuit input set to
T(rue), *nandGate*(X,Y,Z) meaning that there is a NAND gate in
the circuit with input wires X and Y and with output wire Z, and
*invorGate*(X,Y,Z) meaning that there is an INVOR gate in the
circuit
with input wires X and Y and with output wire Z. The rules describing
a circuit are then the following.
```
```- t(Z) :- wireT(Z).
- t(Z) :- nandGate(X,Y,Z) & NOT t(X).
- t(Z) :- nandGate(X,Y,Z) & NOT t(Y).
- t(Z) :- invorGate(X,Y,Z) & NOT t(X).

```
t(Z) :- invorGate(X,Y,Z) & t(Y).
```

Here is a circuit of NAND and INVOR gates represented by the EDB:
wireT(1), nandGate(6,1,3), nandGate(1,2,4), nandGate(3,5,6),
nandGate(1,4,7), and invorGate(3,1,5).

For this EDB and the logic program above it, find the well-founded
model by repeatedly making positive inferences and looking for
unfounded sets.

### Solution

Using the first rule we infer *t(1)* from `t(1) :- wireT(1)`

.
Using the last rule we infer *t(5)* from ```
t(5) :- invorGate(3,1,5)
& t(1)
```

. Then, we instantiate the rules in all possible ways
and eliminate those with a known false subgoal. For convenience, we
also eliminate true subgoals from the remaining bodies and rules whose
head has already been inferred. The result is
```
```- t(3) :- NOT t(6).
- t(4) :- NOT t(2).
- t(6) :- NOT t(3).

```
t(7) :- NOT t(4).
```

The largest unfounded set is {*t(2)*} so we infer *NOT
t(2)*. Then we infer *t(4)* from ```
t(4) :- NOT
t(2)
```

. After eliminating the last rule because *NOT
t(4)* is F(alse) the remaining rules are
```
```- t(3) :- NOT t(6).

```
t(6) :- NOT t(3).
```

The largest unfounded set is {*t(7)*} so we infer *NOT
t(7)*. The remaining rules are the same and there are no
unfounded sets so we are done. The WF model is {*t(1),NOT
t(2),t(4),t(5),NOT t(7)*}. The value of *t(3)* and
*t(6)* is "unknown".
### Problem 2 (15pts.)

For the same EDB and program as in Problem 1, find the well-founded
model by the alternating fixedpoint method.
### Solution

The table below illustrates finding the well-founded model by the
alternating fixedpoint method.

Round |
0 |
1 |
2 |
3 |
4 |

*t(1)* |
F |
T |
T |
T |
T |

*t(2)* |
F |
F |
F |
F |
F |

*t(3)* |
F |
T |
F |
T |
F |

*t(4)* |
F |
T |
T |
T |
T |

*t(5)* |
F |
T |
T |
T |
T |

*t(6)* |
F |
T |
F |
T |
F |

*t(7)* |
F |
T |
F |
F |
F |

Note that column 4 is the same as column 2 so we don't need to do any
more iterations. The WF model is {*t(1),NOT t(2),t(4),t(5),NOT
t(7)*} because *t(1),t(4),* and *t(5)* converge to
T(rue), *t(2)* and *t(7)* converge to F(alse), and
*t(3)* and *t(6)* oscillate.

### Problem 3 (20pts.)

For the EDB and program of Problem 1, find all the stable models. Is
there a stable semantics for this EDB and program?
### Solution

There are only two stable models: {*t(1),NOT t(2),NOT
t(3),t(4),t(5),t(6),NOT t(7)*} and {*t(1),NOT
t(2),t(3),t(4),t(5),NOT t(6),NOT t(7)*}. There is no stable
semantics for the given EDB and program because there is no unique
minimal model.
### Problem 4 (15pts.)

Suppose we change the input of terminal 1 to be F(alse); i.e., the
relation *wireT* is made empty instead of {1}. Show that this
EDB plus the program from Problem 1 is modularly stratified. What are
the "modules"?
### Solution

To be supplied later
### Problem 5 (10pts.)

Is the program and EDB of Problem 4 locally stratified? Justify your
answer.
### Solution

The program and EDB of Problem 4 is not locally stratified because
there is a negative cycle between the ground atoms *t(3)* and
*t(6)*. The cycle arises from the following two rule
instantiations.
```
```- t(3) :- nandGate(6,1,3) & NOT t(6).

```
t(6) :- nandGate(3,5,6) & NOT t(3).
```

### Problem 6 (15pts.)

Compare the well-founded and stable approaches on the following rules
of propositional calculus.
```
```- p :- NOT q.
- q :- NOT r.
- r :- NOT s.

```
s :- NOT p.
```

### Solution

The WF model for the above rules is {}, i.e., the value of
*p,q,r,* and *s* is "unknown". There is no stable
semantics for the above rules because there are two minimal stable
models {*p,NOT q,r,NOT s*} and {*NOT p,q,NOT r,s*}.