Lecture 1: Propositional Logic

COMS E6998 Formal Verification of System Software
Fall 2018
Ronghui Gu

1. Logical Statements

Propositional logic involves only declarative statements.

Complex propositions can be constructed by simple ones using operators.
: “If the train is late and there are no taxis in the station, then Bob is late to work.”

We can examine whether such propositions are true or false when we know the values of the basic propositions.

English (or any human language) is imprecise and subtle (verb tenses, etc.) and error prone. A more mathematical language for logic would make the above arguments clear (Propositional Logic).

2. Symbolic Propositional Logical

3. Syntax

To be rigorous, we need to define grammar (or meta-) variables that stand for any term derivable from the grammar:

Definition The logical formulas of Propositional Logic are exactly those accepted by the following grammar in Backus Naur Form (BNF):

We can draw a parse tree for the formula.

4. Semantics

Now we are going to look at the truth values of propositional logic formulas . We will write this as

Definition

A model of the formula can be any of the following:

We can write truth tables of composed operators using multiple columns.

Q: Create the truth table of the formula:

Q: Give a model that makes the above formula true.

Definition

Q: which of the above are properties of

Q: show that if is satisfiable then is satisfiable.

Q: Let be valid. Is it necessary that is satisfiable?

5. Reasoning

Our goal is to use the logic to derive logical conclusions from logical premises (assumptions).

Two ways to do this:

Definition We write “” to mean that any valuation giving to all the value also gives the value .

This is called semantic entailment.

Lemma
is valid iff .

Lemma
is invalid iff .

Lemma
iff .

Lemma
iff .

Lemma
iff or .

Q: show
Proof.

T T T T
T F F _
F F T T
F T F _

Indirect Proof

Q: show
Proof.

1. Set all the preconditions to be T.
We have :
 
| p → (q ∨ r)  |  q → s  | p | ¬ r → s |
|--------------|---------|---|---------|
|     T        |    T    | T |    _    |
 
Thus, p must be T. And the entailment is simplified as:
| q ∨ r | q → s | ¬ r → s |
|-------|-------|---------|
|   T   |   T   |    _    |
 
2. Case analysis over q:
2.1 If q is T, since q → s is T, we know s is T. Thus:
 
|   s   | ¬ r → s |
|-------|---------|
|   T   |    T    |
 
2.2 If q is F, since q ∨ r is T, we know r is T. Thus:
|   r   | ¬ r → s |
|-------|---------|
|   T   |    T    |
 
Qed

6. Syntactic Logical Proofs

Three different entailments:

6.1 Natural Deduction

There is a standard calculus for axioms of this form called Natural Deduction

Inference rules: If we have formulas then we can derive formula .

Examples:
Axiom (∧i) If we have any formulas and then we can derive the formula

Axiom (∧e1) If we have formula then we can derive the formula

Axiom (∧e2) If we have formula then we can derive the formula

Q: Prove “” using above axioms.

Proof
1. (p ∧ q) ∧ r  (Pre)
2. s ∧ t        (Pre)
3. p ∧ q        (∧e1, 1)
4. q            (∧e2, 3)
5. s            (∧e1, 2)
6. q ∧ s        (∧i, 4, 5)
 
Qed

Simple inference rules: given formulas derive a formula
Complex inference rules: given proofs and formulas derive a formula

6.2 Disjunction

The introduction rules of are simple rules.

The elimination rules of are complex rules.

Q: show

Proof
1. p ∨ q      (Pre)
   -------------------------
2. | p        (Hyp)
3. | q ∨ p    (∨i2, 2)
   -------------------------
4. | q        (Hyp)
5. | q ∨ p    (∨i1, 4)
   -------------------------
6. q ∨ p      (∨i, 2~3, 4~5)
 
Qed

6.3 Implication

Elimination of (aka modus ponens)

Q: show
Q: show

Introduction of : “If we can prove by assuming , then implies .”

Q: show

Proof
1. p → q        (Pre)
   -------------------------
2. | p          (Hyp)
     -----------------------
3. | | r        (Hyp)
4. | | q        (→e, 1, 2)
     -----------------------
5. | r → q      (→i, 3~4)
   -------------------------
6. p → r → q    (→i, 2~5)
 
Qed

Q: show ⊢ p → q → p

Thus, we can replace “all the proofs” with “implications”.

If we prove then we can use in our proofs a derivable rule (aka a theorem)

For example, we can prove the following theorem (called modus tollens)

6.4 Negation

Writing contradictions in the logic:

We will pick an atomic proposition (say ) and name the following:

We will allow to introduce from any contradiction.

To introduce a negation we must show that from we can derive bottom (a contradiction).

Finally, from bottom we are allowed to derive anything:

Q: show
Q show

6.5 Double Negation

We know that , for any . That is, .

Can we derive:

Can we derive:

7 Meta-theory of propositional logic

7.1 Soundness

Q: Is every provable statement valid according to the semantics of the logic?
In other words is the proof system sound?

Theorem (Soundness of proof rules)
For any provable statement it is valid that .
Proof by a form of induction.

7.2 Completeness

Q: Do we have enough proof rules so that, any valid , we can be proved syntactically as ? In other words is the proof system complete?

Theorem (Completeness of proof rules)
For any valid sequent it is provable that .
Proof:

  1. Eliminate premises: implies .
  2. Show provability: implies .
  1. Reintroduce premises: implies

7.3 Decidability

Q: is it possible to write an algorithm that decides whether is a valid sequent?

We only need an algorithm to decide whether :
by a theorem, is equivalent to
by soundness and completeness, is equivalent to .

There are many ways to do this. One is to turn formulas into Conjunctive Normal Form (CNF).

7.4 CNF

CNF is a a formula which has the following structure:

Example:

CNF formulas do not contain:

7.4.1 Validity

A CNF formula is valid iff every clause contains a literal and its negation. (Why?)

Valid formulas:

Not valid formulas:

The above gives an efficient algorithm to check validity of CNF formulas (O(n) to the size of the formula).

7.4.2 CNF conversion

Every fomula can be transformed to an equivalent CNF formula by the following method:

  1. replace implication using the theorem:
  2. push all negations inwards using De Morgan laws:
  3. remove double negations:
  4. distribute and over or:

The above conversion outputs in the worst case an exponentially large formula (O(2n) to the size of the input formula).

Convert to CNF and check the validity of the formulas:

(p→q)→(¬q→¬p)
≡ ¬(¬p ∨ q) ∨ (¬¬q ∨ ¬¬p)         (rule 1)
≡ (¬¬p ∧ ¬q) ∨ (¬¬q ∨ ¬¬p)        (rule 2)
≡ (p ∧ ¬q) ∨ (q ∨ p)              (rule 3)
≡ (p ∨ (q ∨ p)) ∧ (¬q ∨ (q ∨ p))  (rule 4)
≡ (p ∨ q) ∧ (¬q ∨ q ∨ p)          (simplified)

7.4.3 Satisfiability

Satisfiability: Given , is there a model which makes true? Q: Can we decide satisfiability?

Theorem The satisfiability problem is decidable, and NP-complete
So there are known algorithms but they are not efficient in the worst case.

SAT is the first problem that was proven to be NP-complete; see Cook–Levin theorem. This means that all problems in the complexity class NP, which includes a wide range of natural decision and optimization problems, are at most as difficult to solve as SAT. There is no known algorithm that efficiently solves each SAT problem, and it is generally believed that no such algorithm exists; yet this belief has not been proven mathematically, and resolving the question of whether SAT has a polynomial-time algorithm is equivalent to the P versus NP problem, which is a famous open problem in the theory of computing.

The exponential time hypothesis asserts that no algorithm can solve 3-SAT (or indeed k-SAT for any k > 2) in exp(o(n)) time (i.e., fundamentally faster than exponential in n).

Algorithms for Satisfiability
Given a sentence in CNF, how can we prove it is satisfiable?


If we assign , we get

The result is

This algorithm is called DPLL, which stands for the names of the inventors of the algorithm (Davis, Putnam, Logeman and Loveland).

Properties of satisfiability algorithms:

Other algorithms: GSAT, WALKSAT,…

But there are efficient algorithms for a some CNF formulas: Horn clauses

A CNF formula is a horn formula if all its clauses have at most one positive literal:

Algorithm: Inputs a Horn formula and maintains a list of literals, , and in the formula.
It marks the literals in this list as follows:

  1. it marks if it exists in the list
  2. If there is a conjunct
    and all are marked then mark L′. Repeat (2) until no more such conjuncts.
  3. if marked then output “unsatisfiable” and stop
  4. else output “satisfiable” and stop

This is a O(n) algorithm.

Q: show

1. ⊤ is marked
2. No conjunct satisfies rule 2.
3. since ⊥ is not marked, the formula is satisfiable
1. ⊤ is marked
2. From clause (⊤ → s), s is marked
3. From clause (s → p), p is marked
4. From clause (p∧s → ⊥), ⊥ is marked. Thus the formula is unsatisfiable