Birla Institute of Technology and Science-Pilani, Hyderabad Campus
First Semester 2024-2025
Tutorial-13
Course No CS F214 Course Title: Logic in Computer Science
Date: 18/11/24
General Instructions: Argue logically. Write it in a manner that explains your logic very
clearly. Do not miss steps in between.
Q1 For any state l for which l(x) = −2, l(y) = 5, and l(z) = −1, determine which of the relations below
hold; justify your answers:
(a) l |= (x + y < z) → ¬(x ∗ y = z)
Ans: This holds as (x + y < z) is not true.
(b) l |= ∀u(u < y) ∧ (u ∗ z < y ∗ z)
Ans:This does not hold when u = y.
Q2 Use the proof rule for assignment and logical implication as appropriate to show the validity of the
following.
(a) ⊢par (T) y = x; y = x + x + y (y = 3.x)
Ans:
(T)
(x + x + x = 3.x) Implied
y = x;
(x + x + y = 3.x) Assignment
y=x+x+y
(y = 3.x) Assignment
(b) ⊢par (x > 1) a = 1; y = x; y = y-a; (y > 0 ∧ x > y)
Ans:
(T)
(x − 1 > 0 ∧ x > x − 1) implied
a = 1;
(x − a > 0 ∧ x > x − a) Assignment
y = x;
(y − a > 0 ∧ x > y − a) Assignment
y = y-a;
(y > 0 ∧ x > y) Assignment
(c) ⊢par (T) Test (z >= 0) where Test is as follows:
if(y>3){
z=y-x;
1
}
else{
z=x-y;
Ans:
(x=3)
if(y > 3){
(x = 3 ∧ y > 3) if statement
(y − x ≥ 0) implied
z=y-x;
(z ≥ 0) Assignment
}
else{
(x = 3 ∧ ¬(y > 3)) if statement
(x − y ≥ 0) implied
z=x-y;
(z ≥ 0) Assignmentt
}
(z ≥ 0) if statement
Q3 Write down a program P such that the following preconditions and post conditions are met under
partial correctness; then prove that this is so.
(a) (T) P (y = x + 5).
(b) (T) P ( z > x + y + 4).