Compre-2021-Solved-
Compre-2021-Solved-
No, it is not decidable. Finding a model and a lookup table is undecidable like in validity. We may never be able to
find a model in spite of searching infinite number of models.
No it is not decidable. Just because we are not able to find a proof, it doesn’t mean that there can’t be one. And
by completeness of predicate logic, we can say that since semantic entailment of predicate logic formulas is
undecidable, so is the provability of the same formula using natural deduction.
Substitution only yields a new formula. It doesn’t evaluate it. So, substitution can’t be used for evaluation.
1M for writing that substitution can’t be used for evaluation. 1M for right justification.
1|Page
Name: ID:
4. What can you infer about countability of a set of binary trees of infinite height? Explain briefly. 2M
Set of binary trees of infinite height is also infinite. Each tree can be encoded as an infinite sequence of binary
bits. The problem reduces to finding countability of set of infinite binary sequences, which is not countable.
5. Given a natural deduction proof for the sequent |- j. Is verifying the proof decidable for a propositional formula
j? Justify. 2M
Yes, since the number of steps in a natural deduction proof is finite without any ambiguity, verifying such a proof
is decidable.
6. What does Godel’s incompleteness theorem say about Hoare Logic? Is Hoare Logic Sound and Complete?
Explain briefly. 2M
Hoare Logic proves soundness of imperative style programs. The system is sound. However, it is not complete. In
terms of Godel’s incompleteness theorem, it is sufficiently complex.
7. Consider the Natural Deduction (ND) proof system for propositional system. Suppose the proof rule for PBC is
removed from ND. Would the resulting proof system (say, ND2) be complete? Justify briefly. 2M
Yes, the system would still be complete. Note that PBC is a derived rule. We can do exactly the same thing as we
can do with PBC, using ¬𝒊 and ¬ ¬ rules.
2|Page
Name: ID:
Loop Invariant:
2M for correct loop invariant written in Predicate Logic. 1M for writing the right loop invariant in English.
a)
b)
Yes, it satisfies.
3|Page
Name: ID:
10. Following our understanding of CTL grammar, one can have an equivalent grammar, the existential normal form
(ENF) of CTL, given as: 2x2=4M
a)
¬ ꓱ□¬ φ
b)
¬ꓱ (true U ¬ φ)
11. Given the predicate div(X,Y,Q,R) to denote that Q is the quotient and R is the remainder when X is divided by Y;
the predicate nat(X) to denote X is a natural number, the predicate prime(X) to denote X is prime. You may also
use the constant zero and other comparative predicates (=,<,>,<=,>=,!=) on natural numbers. Write the following
statements in first order predicate logic: 3x2=6M
a) A natural number is a prime if it has no factors other than 1 and itself.
b) Given any natural number, there is a larger prime number. (Without using the predicate prime(X))
a)
∀𝑋 ∀𝑌 𝑛𝑎𝑡(𝑋) ∧ 𝑛𝑎𝑡(𝑌) ∧ C(𝑌 < 𝑋) ∧ (𝑌 > 0) → ¬ ∃𝑄 ∃𝑅 𝑛𝑎𝑡(𝑄) ∧ 𝑛𝑎𝑡(𝑅) ∧ ,𝑑𝑖𝑣(𝑋, 𝑌, 𝑄, 𝑅) ∧ (𝑅 = 0)?K
→ 𝑝𝑟𝑖𝑚𝑒(𝑋)
b)
∀𝑋 N𝑛𝑎𝑡(𝑋) → ∃𝑌 𝑛𝑎𝑡(𝑌) ∧ (𝑌 > 𝑋) ∧ ∀𝑍 𝑛𝑎𝑡(𝑍)
4|Page
Birla Institute of Technology & Science, Pilani
1st Sem. 2021-22
CS F214 Logic in Computer Science
Comprehensive Examination (Open Book) (Solutions) (Part B)
=============================================================================================
Time: 75 minutes Dec 13, 2021 Marks: 50M
=============================================================================================
1. Consider the following program fragment and the post-condition given: 2+8+5=15M
/* Pre-condition: A>0 Ù B>=0 */
x=A; y=B; z=1;
while (y!=0) {
if (y%2==0) { x=x*x; y=y/2; }
else { y=y-1; z=z*x; }
}
/* Post-condition: z = AB */
a) Define an appropriate loop invariant and express it in predicate logic.
b) Prove that the proposed loop invariant is indeed an invariant.
c) Prove that the program terminates.
Solution:
a) Loop Invariant (𝒍): 𝑥 ! . 𝑧 = 𝐴" 2M. No partial marking. Marks awarded only for exact loop invariant.
The above statement is true since 𝑥 ! = 𝐴" before the loop starts and 𝑧 = 1 in the pre-condition.
Proof of < 𝒍 ∧ 𝑩, 𝑺, 𝒍 > 4M. Partial Marking has been appropriately done for the proof below.
// 𝒙𝒚 . 𝒛 = 𝑨𝑩 ∧ 𝒚! = 𝟎 this statement would imply the next by ∧𝒆
// 𝒙𝒚 . 𝒛 = 𝑨𝑩 (common part brought out of the conditional)
if (y%2==0)
{
// 𝒙𝒚 . 𝒛 = 𝑨𝑩 ∧ (𝒚%𝟐 == 𝟎) this statement would imply the next by ∧𝒆
// 𝒙𝒚/𝟐 . 𝒙𝒚/𝟐 . 𝒛 = 𝑨𝑩 => 𝒙𝒚 . 𝒛 = 𝑨𝑩
x=x*x;
// 𝒙𝒚/𝟐 . 𝒛 = 𝑨𝑩
y=y/2;
}
else
{
// 𝒙𝒚 . 𝒛 = 𝑨𝑩 ∧ ¬(𝒚%𝟐 == 𝟎) this statement would imply the next by ∧𝒆
// 𝒙𝒚(𝟏*𝟏 . 𝒛 = 𝑨𝑩 => 𝒙𝒚 . 𝒛 = 𝑨𝑩
y=y-1;
// 𝒙𝒚 . 𝒛. 𝒙 = 𝑨𝑩 => 𝒙𝒚*𝟏 . 𝒛 = 𝑨𝑩
z=z*x;
}
// 𝒙𝒚 . 𝒛 = 𝑨𝑩
1|Page
Proof of ⊢ 𝒍 ∧ ¬𝑩 → 𝝍 2M. No partial marking.
(𝑥 ! . 𝑧 = 𝐴" ) ∧ (𝑦 = 0) → (𝑧 = 𝐴" )
The above statement is True, since 𝑦 = 0 means 𝑥 ! = 1. For 𝑥 ! . 𝑧 to be equal to 𝐴" , 𝑧 = 𝐴" must hold.
c) Program termination
Quantity that reduces is y. Proof that y reduces at each iteration is shown here. 4M for the proof below
It can be also similarly argued that y eventually reaches the termination condition which is 0. 1M for
correct reasoning.
2. Express the following statement in SOPL: “Every connected graph has a spanning tree”. Include all properties
of a graph and a spanning tree. 4M
Solution:
∀𝑝 GH∀𝑋 𝑝(𝑋, 𝑋)J ∧ K∀𝑋 ∀𝑌 ∀𝑍 H𝑝(𝑋, 𝑌) ∧ 𝑝(𝑌, 𝑍) → 𝑝(𝑋, 𝑍)JN ∧ K∀𝑋 ∀𝑌 H𝐸(𝑋, 𝑌) → 𝑝(𝑋, 𝑌)JN → H∀𝑢 ∀𝑣 𝑝(𝑢, 𝑣)JR
→ ∀𝐸𝑡 ∀𝑝𝑡 TGH𝐸𝑡(𝑋, 𝑌) → 𝐸(𝑋, 𝑌)J ∧ K∀𝑋 ∀𝑌 ∀𝑍 H𝑝𝑡(𝑋, 𝑌) ∧ 𝑝𝑡(𝑌, 𝑍) → 𝑝𝑡(𝑋, 𝑌)JN
∧ H∀𝑋 ¬𝑝𝑡(𝑋, 𝑋)J ∧ K∀𝑋 ∀𝑌 H𝐸𝑡(𝑋, 𝑌) → 𝑝𝑡(𝑋, 𝑌)JNR → H∀𝑢 ∀𝑣 𝑝𝑡(𝑢, 𝑣)JU
Here p denotes path in a graph, E denotes edge in a graph, Et denotes edge in the spanning tree and pt denotes
path in the spanning tree. No Partial Marking. 0 or 4 marks awarded.
2|Page
3. Consider the following, proposed proof rules for propositional logic: 4M
𝜙, ¬𝜙-
→i1 (proposed) →i2 (proposed)
𝜙- → 𝜙, 𝜙, → 𝜙-
Suppose the implication introduction rule (→i) in Natural Deduction (ND) is replaced with these two proposed
rules. Prove that the resulting proof system (say, ND1) is sound assuming that the rest of the system is sound.
Solution:
The first rule is sound. Including it into the new system would make is sound. You can prove its soundness using
truth table. The second rule is not sound. You can show by truth table. So the system can’t be sound, nor
complete. However, if you switch 𝜙- and 𝜙, in the consequent part of the second rule, then the rule can be shown
to be sound using truth table. 2M for each of the above rules.
4. Given the following formula ∃𝑆 ∀𝑋 ∀𝑌 𝑟(𝑋, 𝑌) → 𝑖𝑛(𝑋, 𝑆) ∨ 𝑖𝑛(𝑌, 𝑆) , provide a model that satisfies it. 4M
Solution:
A C
𝑟 . = {(𝐴, 𝐵), (𝐵, 𝐶), (𝐴, 𝐶)} // denotes a path between any two vertices of the graph
5. (a) Write a grammar (G1) for propositional logic formulas using operations $ (i.e. XOR), → (IMPLIES), and ¬
(NOT), given in increasing order of precedence. 4M
(b) Prove using structural induction on grammars that equivalent of any general propositional logic formula
can be generated using G1 as well. 8M
Solution:
(b) Proof involves showing step by step that all other operators of general propositional logic formulas (∨, ∧)
can be expressed using the above three operators only. It also involves that keeping the above
precedence, it is good enough to eliminate over-riding parenthesis, as negation is associated to
propositions only and not with the entire formula.
8M. Partial marking appropriately done when the proof is almost correct. Correct Proofs without truth
tables loose marks. Incorrect proofs are awarded no marks.
3|Page
6. Prove the sequent: ∃𝑥 H¬𝑎(𝑥) ∧ ¬𝑏(𝑥)J ⊢ ∃𝑦 K¬H𝑎(𝑦) ∧ 𝑏(𝑦)JN 6M
Solution:
6M. 1M deducted for each mistake of the proof is almost correct. Otherwise partial marks are awarded to the
extent the proof is correct.
“If n pigeons sit in (n − 1) holes, then some hole contains more than one pigeon, here n ≥ 2. Other
information provided was: Pi,j indicates that pigeon i is in hole j, i.e., Pi,j is true if pigeon i is in hole j, and Pi,j is
false if pigeon i is not in hole j.“
The above statement has been written in Propositional logic with an error induced in it:
where ∧)*+,_./!0, and ∨)*+,_./!0, are shorthand notation to write long sequences of conjunctions and
disjunctions respectively. Assuming the only error in reasoning is by ambiguous presentation of ∧)*+,_./!0,
and ∨)*+,_./!0, operators, answer the following:
Solution:
4|Page