================================================================= 22c:181 Formal Methods in Software Engineering, Spring 2008 Exercise 1 Solutions ================================================================= A. Propositional Logic 1. All the models of (a and (not b or not c)) are listed in the table below where T stands for true and F for false: a b c =========== T F T T F F T T F 2. All the counter-models of (a and (not b or not c)) are listed in the table below: a b c =========== F F F F F T F T F F T T T T T 3. Here is the truth table for the implication P => Q: P Q P => Q ================ F F T F T T T F F T T T from truth table: if P => Q is false, then P = T and Q = F 4. if P => Q is true, then P = F or Q = T 5. A possible formula: (a and not b and not c) or (not a and b and not c) or (not a and not b and c) An alternative (but equivalent) one: (a or b or c) and (not a or not b) and (not a or not c) and (not b or not c) 6. Formula is unsatisfiable: it has no models Formula is valid: it has no counter-models phi is valid <=> (not phi) is unsatisfiable phi is satisfiable <=> (not phi) is not valid B. Lustre 1. node Sum(X : int) returns (S : int); let S = (0 -> pre S) + X; tel 2. node SumReset(X : int; Reset : bool) returns (S : int); let S = (if Reset then 0 else (0 -> pre S)) + X; tel 3. node Average(X : int; Reset : bool) returns (Avg : int); var C : int; let C = (if Reset then 0 else (0 -> pre C)) + 1; Avg = SumReset(X, Reset) / C; tel Alternative implementation: node Average(X : int; Reset : bool) returns (Avg : int); let Avg = SumReset(X, Reset) / SumReset(1, Reset); tel 4. node HasHappened(X : bool) returns (Y : bool); let Y = (false -> (pre Y)) or X; tel Alternative implementation, using the Sofar operator: node Sofar(X : bool) returns (Y : bool); let Y = (true -> (pre Y)) and X; tel node HasHappened(X : bool) returns (Y : bool); let Y = not Sofar(not X); tel