You are on page 1of 3

Models of Software Systems Name:

Assignment 2 Due: 25.02.2022

1 Formal specification with Propositional Logic and Calculus


Below you are given the description of the game called Hedgehog adventures. Your task is to convert
this natural language requirements into formal specification using Propositional Logic. After the
conversion you will verify some of the properties for you specification using a variety of methods
and tools. Follow the task questions to complete the entire process.

Hedgehog adventures.

As the player you are required to navigate your hedgehog character through a forest, eating mush-
rooms and avoiding the fox who is chasing you through the forest. Mushrooms the hedgehog eats
can be of two types: normal or powered. Thus, your hedgehog can avenge the pursuer by eating a
“powered” mushroom, which enables him to enter into the “prickly ball” mode and chase down the
fox instead. When this occurs, the fox’s behavior changes, and instead of chasing the hedgehog it
tries to run from him. When your hedgehog meets the fox in this special mode, then the unlucky
predator gets beaten up badly. To win your hedgehog needs to eat all the mushroom. However if
it meets the fox while not in “prickly ball” mode, then it gets eaten and loses.

Q1. Specify each of the rules below using propositional logic. The current titles of the rules are
hinting at what their logical formulation should be about. Follow the procedure from the lab,
and try to arrive at a minimal set of logical literals necessary to specify the rules.

Game rules.

A. (Example): The two types of mushrooms to eat.

Original statement:
"Mushrooms the hedgehog eats can be of two types: normal or powered."

Literals:
enm - "Hedgehog eats a normal mushroom"
epm - "Hedgehog eats a powered mushroom"

Rule:

enm ∨ epm

B. How to enter ”prickly ball” mode.


C. ”Prickly ball” mode keep the fox away.
D. The fox can get beaten too.
E. Different states the fox can be in.

1
F. Win condition.
G. Loss condition.

Q2. Specify each of the properties below using propositional logic. The properties are quite close
to what their formulation in logic should be.

Properties to verify.

A. If the fox is chasing the hedgehog, then he is not in “prickly ball” mode.
B. The fox cannot be both running away and chasing.
C. If the fox is beaten up, then the hedgehog met it in the “prickly ball” mode.
D. If the hedgehog met the fox and it is not beaten up, then he could have only eaten a normal
mushroom.
E. The hedgehog cannot lose while in “prickly ball” mode.
F. The hedgehog cannot both win and lose.

Q3. Produce a truth table for the following:

Rule E <=> Property B.

(Example): p ∧ (p ∨ q)

p q (p ∨ q) p ∧ (p ∨ q)
T T T T
T F T T
F T T F
F F F F

Q4. Is the expression from question above a tautology, contradiction or contingent statement?
Explain why.

Q5. Produce two variations of the expression that differ from the original by only one operator, so
that as a result you will have three statements: the original and two variations. One of them
has to be a tautology, another a contradiction, and the third one a contingent statement.

Q6. Deduce linearly the following two entailments using Propositional Calculus:

a. Rule C entails Property A.


b. Rules A, B, and D entail Property D.

Q7. Implement all of the game rules in Z3 and check if their combination is satisfiable.
(Example):

2
(declare-const p Bool)
(declare-const q Bool)
(define-fun conjecture () Bool
(and p (or p q)))
(assert conjecture)
(check-sat)

Q8. Explain briefly what it would mean if the combination were unsatisfiable.

Q9. Check if the combination of all rules guarantees Property C using Z3.

Q10. Check if the combination guarantees Property F. If not, suggest a modification to guarantee
it.

You might also like