You are on page 1of 44

DEBREMARKOS

UNIVERSITY BURIE CAMPUS

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

 Boolean logic, for the circuits used in


computer processors.
 Logics of knowledge and beliefs (of
human and artificial agents); used for
reasoning.
 Prolog: programming languages based on
logic.

07/18/2021 3
Statements (Propositions)

• Formal logic can represent the statements we use


in English to communicate facts or information. A
statement (proposition) is a declarative sentence which
may be asserted to be either true or false but not both.
• Hence, the truth value of a statement is either T(1) or
F(0).
• Examples:
 Five men can have eleven eyes.
 No bachelor is married.
 The sum of the numbers 3 and 5 equals 8.

07/18/2021 4
Statements (Propositions)

• The sentences which are not propositions include


questions, command, exclamations etc for which
we may not like to associate a truth value.
Examples:
 How are you?
 Turn off the TV right now.
 Ready, steady, go!
• Statements/Propositions usually represented by
letters like A, B, C, D, etc. The letters are called
statement variables or propositional variables.
07/18/2021 5
Propositional Logic
• Propositional logic is used to investigate properties of
complex sentences built from elementary sentences by using
propositional connectives like negation, conjunction,
disjunction, implication and bi-implication.
• Whether complex sentences are true or not, depends solely
on logical values of elementary sentences involved in them.
• Logic doesn’t help in determining the individual truth of these
statements/sentences.
• However, if the first n number of statements are true, logic
assures the truth of the next statement.

07/18/2021 6
Syntax of propositional logic

Syntax: Vocabulary for expressing concepts without ambiguity.

• Logical constants: true, false.

• Propositional symbols: P, Q, S, ...

• Wrapping parentheses: ( … ).

• The alphabet of Propositional Logic, PL, is the set { ), (, ¬, ∧ ,


∨ , → , ↔ , T , F , P0, P1, P2, . . .} consisting of all these symbols.

• We build propositional formulas (sentences) from truth values and


propositional variables by applying propositional connectives
¬,∧,∨,→, ↔.

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

(d) →(conditional/implication) : Given statement variables


p and r, The implication of p and r is p → r and read as
“if p then r” or “p implies r” or “r if p”.
• Here p is called the hypothesis/antecedent statement
and r is called the conclusion/consequent statement.
• p → r is false if p is true and r is false, otherwise true.
(e) ↔(equivalence/bi-implication) : If p and r are two
statements then bi-conditional statement is denoted by
“p ↔ r”.
• “p ↔ r” is true if both p and r have the same truth
value .And false if they have opposite value.

07/18/2021 10
Semantics of Propositional logic

• The semantics of propositional formulas is


given by assigning truth values to
propositional variables and then
calculating values of formulas.

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

– If S is a sentence, then S is a sentence


– If S is a sentence, then (S) is a sentence

– If S and T are sentences, then (S  T), (S  T), (S  T), and (S ↔ T) are


sentences
 Formulas are either atomic formula, or composite formula.
 Atomic formula is an elementary propositional variables. example S,T
 Composite formula can be formed by combining atomic formulas with logical
connectives. Example (S  T)

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

• The truth table for the wff A ∨ B′ → ( A ∨ B)′


shown below. The main connective according to
the rules of precedence is implication there fore:

A B B΄ A ∨ B′ A∨B ( A ∨ B)′ A ∨ B′ → ( A ∨ B)′


T T F T T F F
T F T T T F F
F T F F T F T
F F T T F T T

07/18/2021 15
Truth tables for some wffs

• The total number of rows in a truth table for n


statement letters is 2n.i,e. If there is two statement
variables A and B ,total number of rows are 22=4.
Exercise:
• Construct the truth table for the wff:-
(a) (A→B)↔(B→A)
(b) (A ∨ A′)→( B ∧ B′)
(c) [(A ∧ B′)→C′]′
(d) (A→B)↔(B′→A′)

07/18/2021 16
Tautology

• A propositional expression is a tautology if and only if


for all possible assignments of truth values to its
variables, its truth value is T.
• A wff that is “intrinsically true”. It is true no matter what
truth values of the statements that comprise the wff.
Example: P V ¬ P is a tautology.
A simple example is ;Today the sun will shine or today
the sun will not shine
P ¬P PV¬P
T F T
F T T

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.

• logical equivalences of two statement forms P and Q is denoted by P ≡ Q.

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)

3. Distributive laws: P V (Q Λ R) ≡(P V Q) Λ (P V 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

• An argument is a sequence of statements in


which the conjunction of the initial
statements(called the premises/hypotheses)
is said to imply the final statement(called the
conclusion).An argument can be presented
symbolically as
• (P1 Λ P2 Λ P3 Λ …………… Λ Pn) →Q,
where p1,p2,p3………pn represents the
hypotheses and Q represents the conclusion.

07/18/2021 21
Valid and Invalid Arguments
• To test whether or not an argument is valid, we do the following:

(i) Identify the premises and the conclusion


(ii) Construct a truth table showing the truth values of the premises
and the conclusion
(iii) Look for all the rows where the premises are all true - we call
such rows critical rows.
If the conclusion is false in a critical row, then the argument is invalid.
Otherwise, the argument is valid (since the conclusion is always true
when the premises are true).

07/18/2021 22
Valid argument

 (P1 Λ P2 Λ P3 Λ …………… Λ Pn) →Q is a valid argument when it is a


tautology
 if an Arguments is valid, it has the following property

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.

3. The true of premises guaranty the true of conclusion.

Example all actors are robot

Mr. X is actor

therefor Mr. X is robot

07/18/2021 23
Example: Determine whether the following arguments

are valid or invalid .


1. p → q
q→r
therefor p ∨ q → r
2. p ∨ q
p→¬q
p→r
Therefore r

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:

Look for all the critical rows - the conclusion in row6 is


false,
07/18/2021
then this argument(form) is invalid. 26
Proof Sequence
• A proof sequence is a sequence of wff in which each wff is either a hypothesis
(assumption) or the result of applying one of the formal system’s derivation rules to
earlier wffs in the sequence.
• Using formal logic to prove that Q is a valid conclusion from P1 Λ P2 Λ P3 Λ
…………… Λ Pn we must produce a proof sequence of the form.
P1
P2
.
.
P3 (hypothesis)
wff1 (obtained by applying a derivation rule to earlier wff)
wff2 (obtained by applying a derivation rule to earlier wff)
.
.
Q (obtained by applying a derivation rule to earlier wff)
The derivation rules for a formal system must be carefully chosen.

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

• Inference rules says that if one or more wffs


that match the first part of the rule pattern
are already part of the proof sequence we
can add to the proof sequence a new wff that
matches the last part of the rule pattern.
• Unlike equivalence rules, inference rules do
not work in both directions
• Table below shows the propositional
inference rules:-
07/18/2021 30
Inference rule

• Note: The Inference rules are also truth preserving. Suppose


that P and P→Q are both true wff in a proof sequence. Then
Q is deductible from these two wffs by modusponens.If P and
P→Q are both true - then by the truth table for implication - Q
is also true.

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

• It is the expression of arguments in the form of


words.
Example:
 Convert the following verbal argument into a
propositional form using letters A,B,C and D.
And prove the validity of this propositional form .
 Russia was a superior power, and either France
was not strong or Napoleon made an error.
Napoleon did not make an error. But if the army
did not fail, then France was strong. Hence the
army failed and Russia was a superior power. 36
07/18/2021
Verbal arguments
 Convert the verbal argument into a propositional letter.
• A: Russia was a superior power
• B: France was strong B’: France was not strong
• C: Napoleon made an error C’: Napoleon did not make an
error
• D: the army failed D’: the army did not fail
 Combining the statements using logic.
(A Λ(B’VC)) ………… hypotheses
C’……………………… hypotheses
(D’ →B)……………….hypotheses
(DΛA)………………….conclusion
 Combining them, the propositional form is
(A Λ(B’VC)) Λ C’ Λ (D’ →B) → (DΛA)

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

You might also like