Professional Documents
Culture Documents
LOGIC IN COMPUTER
SCIENCE
Chapter one-Introduction
What is Logic?
• Logic is a part of philosophy that founds statements/solutions for
some arguments. It has syntax and semantics and a way of
manipulating expressions in the language.
• Syntax is a description of what you are allowed to write down,
what expressions are legal in a language. Semantics is what legal
expressions mean. Therefore syntax is form and semantics is the
content.
The aim of logic in computer science
• The aim of logic in computer science is to develop languages to model the
situations we encounter as computer science professionals, in such a way that
we can reason about them formally.
• Reasoning about situations means constructing arguments about them; we
want to do this formally, so that the arguments are valid and can be defended
rigorously, or executed on a machine.
07/18/2021 2
Applications of Logic in Computer
Science
07/18/2021 3
Statements (Propositions)
07/18/2021 4
Statements (Propositions)
07/18/2021 6
Syntax of propositional logic
• Wrapping parentheses: ( … ).
07/18/2021 7
Logical Connectives
• Logical connectives are symbols such as we
use the symbols ¬ or ’, ∧, ∨, → and ↔ .
• Their names are negation, conjunction,
disjunction, implication/ conditional and bi-
conditional /equivalence respectively.
• We use the parentheses ‘)’ and ‘(’ as punctuation
marks.
• We also have the special propositions T and F ,
called propositional constants. They stand for
propositions which are ‘true’ and ‘false’,
respectively.
07/18/2021 8
Logical Connectives
(a) ¬ or ΄(negation): If p is a statement variable, the negation of p is
denoted by ¬ p or p΄. It has the opposite truth value from p: if p is
true, then ¬ p is false ; if p is false, then ¬ p is true.
Example
• p:5 is greater than 2. ¬ p:5 is less than 2.
(b) ∨(disjunction) : Given statement variables p and r, The
disjunction of p and r is p ∨ r and read as “p or r”.
• p ∨ r is true when at least one of p or r is true; And false when both
p and r are false.
(c) ∧(conjunction): Given statement variables p and r, The
conjunction of p and r is p ∧ r and read as “p and r”.
• p ∧ r is true when both p and r are true; And false when at least
one of p or r is false.
07/18/2021 9
Logical Connectives
07/18/2021 10
Semantics of Propositional logic
07/18/2021 11
Truth table for Logical
Connectives(semantics of PL)
• Truth table is a table that displays the truth
values of a statement form which
correspond to the different combinations of
truth values for the variables.
p r ¬p p∨r p∧ r p→r p↔r
T T F T T T T
T F F T F F F
F T T T F T F
F F T F F T T
07/18/2021 12
Propositional well formed
formula(WFF)
• We can string statement letters, connectives and parenthesis together to form new
expressions as in (A→B) ∧ (B→A).
• An expression that is legitimate string is called a well-formed formula (wff), But
A)) ∧ ∧ →BC is not considered to be a legitimate string.
A sentence (well formed formula) is defined as follows:
– A symbol is a sentence
07/18/2021 13
Propositional well formed
formula(WFF)
• To reduce the number of parenthesis required in a wff, we can
use the following order of precedence.
1. Connectives within parenthesis, innermost parenthesis first
2. Negation(¬ or ΄)
3. Conjunction(∧),Disjunction(∨)
4.Implication(→)
5.Bi-implication(↔)
• E.g.:- A ∨ B′ stands for A ∨ (B′) and not (A ∨ B)′
A ∨ B→C stands for (A ∨ B)→C and not A ∨ (B→C)
In a wff with a number of connectives, the connective to be applied
last is the main connective
E.g:- In A ∧ (B→C)′ Here the main connective is ∧.
In ((A ∨ B) ∧ C)→(B ∨ C)′ Here the main connective is →
07/18/2021 14
Truth tables for some wffs
07/18/2021 15
Truth tables for some wffs
07/18/2021 16
Tautology
07/18/2021 17
Contradiction
• A propositional expression is a contradiction if and only
if for all possible assignments of truth values to its
variables, its truth value is F.
• A wff that is “intrinsically false”. It is false no matter what
truth values of the statements that comprise the wff.
• Example: P Λ ¬ P is a contradiction
• A simple example is ;Today the sun will shine and today
the sun will not shine.
P ¬P PΛ¬P
T F F
F T F
07/18/2021 18
Inconsistency
• A propositional expression is an inconsistence if
and only if for some possible assignments of
truth values to its variables its truth value is false
and some possible assignments of truth values
to its variables its truth value is true.
• Or, if wff is neither tautology nor contradiction, it
is said to be inconsistence.
Example P ΛQ is inconsistence:
P Q P ΛQ
T T T
T F F
F T F
F F F
07/18/2021 19
Tautological equivalences
• Two statement forms are called logically equivalent iff, they have identical truth values for
each possible substitution of statements for their statement variables.
• Similarly to standard algebra, there are laws to manipulate logical expressions, given as
logical equivalences.
1. Commutative laws: P V Q ≡ Q V P
P Λ Q ≡ Q Λ P
2. Associative laws: (P V Q) V R ≡ P V (Q V R)
(P Λ Q) Λ R ≡ P Λ (Q Λ R)
P Λ (Q V R) ≡ (P Λ Q) V (P Λ R)
4. Identity: P V F ≡ P
P Λ T≡P
07/18/2021 20
Valid and Invalid Arguments
07/18/2021 21
Valid and Invalid Arguments
• To test whether or not an argument is valid, we do the following:
07/18/2021 22
Valid argument
1. If all the premises are true the conclusion must also be true.
2. It is logically impossible for the premises to be true and the conclusion false.
Mr. X is actor
07/18/2021 23
Example: Determine whether the following arguments
07/18/2021 24
solution
Q1. first identify which one is premises and which one is
conclusion
so p → q and q → r are premises and p ∨ q → r is
conclusion.
Second constract the truth table:
Look for all the rows where the premises are all true (row
1,row5, row7 and row8) - we call such rows critical rows
and If the conclusion is true in a critical row, then the
argument is valid otherwise invalid.
So that the argument(form) is valid
07/18/2021 25
solution
Q2. first identify which one is premises and which one
conclusion
so p ∨ q, p → ¬ q and p → r are premises and r is
conclusion.
Second constract the truth table:
07/18/2021 27
Derivation Rules for Propositional
Logic
• The derivation rules fall into two categories: Equivalence rules and
Inference rules.
Equivalence rules
• Equivalence rules allow individual wff to be rewritten while inference rules
allow new wffs to be derived from previous wffs in the proof sequence.
• Equivalence rules states that certain pairs of wffs R and S are equivalent.
• R ≡ S means that S can be substituted for R in any wff with no change to
its truth values.
• Equivalence are therefore truth preserving. A true wff remains true if such
a substitution is done within it.
• Table below lists the equivalence rules in our formal system for
propositional logic.
07/18/2021 28
Equivalence rule
07/18/2021 29
Inference rule
07/18/2021 31
Inference rule
• Example
• Using propositional logic, prove that the argument
• A Λ (B→C) Λ [(A Λ B)→(D V C′)] Λ B→D is valid.
• We begin with the hypothesis and end with conclusion. There are four hypotheses
1. A ……………………………..hyp
2. B→C ………………………… hyp
3. (A Λ B)→(D ∨ C′) …………hyp
4. B ……………………………......hyp
• Our final goal is to arrive at D, the conclusion. But without even looking ahead, there are
a couple of fairly obvious steps that may or may not be helpful.
5. C ……………………………….2, 4 mp
6. A Λ B ………………………..1, 4, con
7. D ∨ C′ ……………………….3, 6, mp
• At least at this point we have introduced D, Step7 is a disjunction of a certain form
into an implementation.
8. C′ ∨ D ………………………….7, comm
9. C→D …………………………….8, imp
10. D ………………………………….5,9 ,mp
07/18/2021 32
Deduction Method and Other Rules
• Suppose the argument we seek to prove has the form P1 Λ P2 Λ P3 Λ
…………… Λ Pn→ (R→S) Where the conclusion itself an implication. Instead
of using P1,P2, P3…………Pn as the hypothesis and deriving R→S , the
deduction method lets us add R as an additional hypothesis and then
derive S . i.e. we can prove
P1 Λ P2 Λ P3 Λ …………… Λ Pn Λ R→S
Example
Using propositional logic, prove that the argument
(A→ (A→B))→ (A→B) is valid
• Using deduction method, we get two hypothesis instead of one, and we want
to derive B
1. A→ (A→B)………………. hyp
2. A ……………………………..hyp
3. A→B ……………………….1,2,mp
4. B …………………………….2,3,mp
07/18/2021 33
Additional inference rules
• Additional rules can shorten proof sequences but at
the expense of having to remember additional rules:-
07/18/2021 34
Additional inference rules
Example:
• Using propositional logic, prove the argument (P→Q) Λ (P
′→Q) →Q is valid.
• Proof
1. P→Q …………..hyp
2. P′→Q………….. hyp
3. Q′→P′ …………1,cont
4. Q′→Q………....2,3,hs
5. (Q′)′ ∨ Q ……..4,imp
6. Q ∨ Q ………….5,dn
7. Q …………………6,self
07/18/2021 35
Verbal arguments
07/18/2021 37
Verbal arguments
Prove (A Λ(B’VC)) Λ C’ Λ (D’ →B) → (DΛA)
1. A Λ(B’VC)) …..hyp
2. C’ ………………..hyp
3. D’ →B…………..hyp
4. A………………….1,simp
5. B’VC……………..1,simp
6.CVB’……………...5,comm
7. B’…………………2,6,ds
8. B’ →(D’)’……...3,cont
9.(D’)’……………….7,8,mp
10.D…………..……..9,dn
11. DΛA…………....4,10,con
So, the given argument is valid.
07/18/2021 38
Normal form
• A literal is an atomic proposition that consists
of a proposition or the negation of a proposition.
Eg: P, ¬P
• A term is a literal or the conjunction (and) of
two or more literals.
Eg: P, ¬P, PΛ¬P,
• A clause is a literal or the disjunction (or) of
two or more literals.
Eg: P, ¬P, P V ¬P,
07/18/2021 39
Disjunctive Normal Form (DNF)
• A compound proposition is in disjunctive normal form (DNF) if it
is a term or a disjunction of two or more terms.
• It can also be described as an OR of ANDs, a sum of products.
• The only propositional operators in DNF are and, or, and not.
The not operator can only be used as part of a literal, which
means that it can only precede a propositional variable.
• Eg:
• 1. A V B 2. A
• 3. (A Λ B) V C 4. (A Λ ¬B Λ ¬C) V (¬DΛ E ΛF)
• The following formulas are not in DNF
• ¬ (A V B) ---- NOT is the outermost operator
• A V (B Λ (C V D)) — an OR is nested within an AND
07/18/2021 40
Conjunctive Normal Form (CNF)
• A compound proposition is in conjunctive normal form (CNF) if it is a clause or
a conjunction of two or more clauses.
• it is an AND of Ors.
• All conjunctions of literals and all disjunctions of literals are in CNF, as they can be
seen as conjunctions of one-literal clauses and conjunctions of a single clause,
respectively.
• The operators used are the same as DNF
Eg:
1. ¬A Λ (B V C)
2. (A V B) Λ( ¬B V C V ¬D) Λ (D V ¬E)
3. A Λ B
4. AVB---- conjunctions of a single clause/ disjunctions of literals
The following formulas are not in CNF
¬(B V C) --- NOT is the outermost operator
(A Λ B) V C
A Λ(B V (D Λ E))
07/18/2021 41
Conversion into CNF and DNF
• Every propositional formula can be converted into an equivalent formula
that is in CNF.
• This transformation is based on the rules about logical equivalences: the double
negation law, the De Morgan’s law and the distributive law.
• Not all formulas can be converted into DNF.
• Conversion involves using the logical equivalence rules mentioned above.
• Example:
Convert (a→ b)→c to a CNF and also to a DNF.
Solution. (a→b)→c
≡ ( ¬ a V b)→c ………imp
≡ ¬ ( ¬ a V b) V c ….imp
≡ (a ∧ ¬ b) V c …….De Morgan’s .
The last proposition is in DNF.
Using distributivity and simplifying we obtain: ≡ (a V c) ∧ ( ¬ b V c) This is in CNF.
07/18/2021 42
Exercise
Prove the validity of the following arguments(1- 3) by using truth table
and derivation rules.
1. Using propositional logic, prove the argument
A′ Λ B Λ (B→ (A V C)) → C is valid.
2. Using propositional logic, prove the argument A Λ (B→C)→(B→(A Λ
C)) is valid.
3. Using propositional logic, prove the argument (R Λ (F′ V N)) Λ N′ Λ
(A′→F) →(A Λ R) is valid.
4. Using propositional logic, prove that the argument (A→ (A→B))→
(A→B) is valid .
5. Using propositional logic, prove the argument (A→ (B V C)) ∧ B ′ ∧
C′→ A′ is valid.
6. Convert (p→ ( ¬ q→ r)) ∧ (p→ ¬ q) to a CNF and also to a DNF.
07/18/2021 43
Thank You!
07/18/2021 44