LOGIC CH 1 and 2
LOGIC CH 1 and 2
Faculty of informatics
Department of computer science
UOG, Logic in Cs Handout for 3rd Year CS Regular Students
Academic Year: 2014 E.C.
Chapter one
LOGIC
Scientists often gather data for observation, investigation and conducting experiments on it. So if
they are really satisfied with data, scientists may want to draw conclusion from those data to
show that a certain feature is right and others are wrong. To understand science then it would be
important to understand when and how to draw a specific conclusion from we already know. We
need to understand the difference between good and bad arguments, then the study of
argumentation is called logic.so logic is all about reasoning to identify what is good and bad in
the real world. There are lots of different logics:
Probabilistic Logic – for reasoning about probability.
Temporal Logic – for reasoning about time (and programs).
Epistemic Logic – for reasoning about knowledge.
1
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.
Applications of logic in computer science
Logic in computer science covers the overlap between the field of logic and that of computer
science. It has undoubtable importance in the following areas:-
Expert Systems
Knowledge Based Software Assistant
Semantic Web development
Formal Specification and Verification of Software
Formal Specification of Data Structures
Logic Programming and Deductive Databases
Knowledge Representation and Common sense Reasoning.
Propositional logic
Logic can be used to represent and assess many of our most common patterns of reasoning and
rational thought using sentences commonly called statements or propositions. So a proposition in
logic is a declarative sentence that is either True or False, but not both.
For example, "Grass is green", and "2 + 5 = 5" are propositions.
The first proposition has the truth value of "true" and the second "false". But "Close the door", and
"Is it hot outside ?"are not propositions. Also "x is greater than 2",where x is a variable representing
a number, is not a proposition, because unless a specific value is given to x we can not say whether
it is true or false, nor do we know what x represents.
Simple statements which are true or false are basic propositions. Larger and more complex
propositions are constructed from basic propositions by combining them with connectives.
Thus propositions and connectives are the basic elements of propositional logic. Though there
are many connectives, we are commonly using the following five basic connectives.
NOT, AND, OR, IF_THEN (or IMPLY), IF_AND_ONLY_IF. They are also denoted by
the symbols: , , , , , respectively.
2
Negation(NOT) – If p is a proposition, then the negation of p is denoted by , ~p ,which
when translated to simple English means-
“It is not the case that p” or simply “not p“.
The truth value of ~p is the opposite of the truth value of p .
The truth table of ~p is-
P ~P
T F
F T
Example:- The negation of “It is raining today”, is “It is not the case that is raining today”
or simply “It is not raining today”.
Conjunction – For any two propositions p and q , their conjunction is denoted by p 𝖠 q,which
means “p and q “. The conjunction p 𝖠 q is True when both p and q are True, other wise
False.
Disjunction – For any two propositions p and q, their disjunction is denoted by p ∨ q, which
means “ p or q “. The disjunction p ∨ q is True when either p or q is True, other wise False.
3
The truth table of p ∨ q is-
The disjunction of the propositions p – “Today is Friday” and q – “It is raining today”, p ∨ q is
“Today is Friday or it is raining today”. This proposition is true on any day that is a Friday or a
rainy day(including rainy Fridays) and is false on any day other than Friday when it also does not
rain.
Implication – For any two propositions p and q , the statement “if then ”is called an
implication and it is denoted by p⇒q.In the implication p⇒q, p is called the
hypothesis or antecedet or premise and q is called the conclusion or consequence. The
implication is p⇒q is also called a conditional statement. The implication is false when p is
true and q is false otherwise it is true.
The truth table of p ⇒ q is-
You might wonder that why is p ⇒ q true when p is false. This is because the implication
guarantees that when p and q are true then the implication is true. But the implication does not
guarantee anything when the premise p is false. There is no way of knowing whether or not the
implication is false since p did not happen.
Example,
“If it is Friday then it is raining today” is a proposition which is of the form p ⇒ q. The above
proposition is true if it is not Friday (premise is false) or if it is Friday and it is raining, and it is
false when it is Friday but it is not raining.
4
Biconditional or Double Implication – For any two propositions p and q , the statement
“p if and only if(iff) q” is called a biconditional and it is denoted by p ⇔ q.
Example, “It is raining today if and only if it is Friday today.” is a proposition which is of the
form p ⇔q. The above proposition is true if it is not Friday and it is not raining or if it is Friday
and it is raining, and it is false when it is not Friday or it is not raining.
Example, The conjunction of the propositions p – “Today is Friday” and q – “It is raining
today”, p𝖠 q is “Today is Friday and it is raining today”. This proposition is true only on rainy
Fridays and is false on any other rainy day or on Fridays when it does not rain.
Syntax of propositional logic
The “syntax” of a language refers to the “form” of the expressions (words, sentences, etc.).a
expression of propositional logic consists of a sequence of symbols. We distinguish three kinds
of symbols.
Propositional variables. Commonly one uses Latin letters such as p, q, or r.
Logical connectives:- non-alphabetic symbols: ¬, 𝖠 , ∨ , and→.
Punctuation:-only „(‟ and „)‟.
Propositional well-formed formulas
Let P be a set of propositional symbols. We define the set of well-formed formulae over P
inductively as follows. (The term “well-formed formula” is sometimes abbreviated to “WFF”.)
1. An expression consisting of a single propositional symbol is a formula.
2. If α is a formula, then (¬α) is a formula.
3. If α is a formula, β is a formula, then each of (α 𝖠 β), (α ∨ β) and (α → β) is a formula.
5
Chapter two
A propositional expression is a contradiction if and only if for all possible assignments of truth
values to its variables its truth value is False.
Example: P Λ ¬ P is a contradiction
P Q ¬p p 𝖠 ¬q
T T F F
T F F F
F T T F
F F T F
Usage of tautologies and contradictions - in proving the validity of arguments; for rewriting
expressions using only the basic connectives.
6
Arguments
The most basic logical inferences are about combinations of sentences, expressed by such frequent
expressions as „not‟, „and‟, „or‟, „if, then‟. Such combinations allow you to describe situations, and
what properties these situations have or lack: something is „not this, but that‟. You could call this
reasoning about „classification‟, and it is the basis of any description of the world. At the same
time, these logical sentence combinations are also fundamental in another sense, as they structure
how we communicate and engage in thought processing. When you disagree with a claim that
someone makes, you often try to derive a consequence (‟if then‟) whose negation („not‟) is easier
to show. Then set of claims that are supported by evidence for reasoning about some situation in
the real world are called arguments in logic.
7
though we have a true premises, such logical conditions are assessed or evaluated by defining
validity and strength of arguments.
Validity of Arguments
"Validity" and "strength" are technical terms that logicians and philosophers use to describe the
logical "glue" that binds premises and conclusions together. Valid arguments have the strongest
logical glue possible.
An argument is VALID if it has the following hypothetical or conditional property:
If All the premises are true, then the conclusion cannot be false.
It is logically impossible for the premises to be true and the conclusion false.
The truth of the premises guarantees the truth of the conclusion.
Consider the following example.
1. All actors are robots.
2. Tom Cruise is an actor.
Therefore, Tom Cruise is a robot.
In this case in a hypothetical world where all actors are robots, and Tom Cruise also happens to
be an actor, then it's logically impossible for Tom Cruise NOT to be a robot.
Here's an example of an INVALID argument:
The first premise is the same, "All actors are robots". But the second premise is different. Instead
of assuming that Tom Cruise is an actor, we're assuming that Tom Cruise is a robot.Now, if these
premises are both true, does it follow that Tom Cruise HAS to be an actor? No, it does not follow.
It would follow if we said that ONLY actors are robots, but the first premise doesn't say that.
8
All we can assume is that in this hypothetical world, anyone in the acting profession is a robot,
but robots might be doing lots of different jobs besides acting. They might be mechanics or
teachers or politicians or whatever. So in this hypothetical world the fact that Tom Cruise is a
robot doesn't guarantee that he's also an actor. And THAT is what makes this an invalid
argument.
What this means is that even if all the premises are true, it's still possible for the conclusion to
be false. The truth of the premises doesn't guarantee the truth of the conclusion.That's ALL it
means to call an argument "invalid".
9
Inference rules:
In logic, a rule of inference, inference rule or transformation rule is a logical form consisting
of a function which takes premises, analyzes their syntax, and returns a conclusion
(or conclusions). The following are common rules that we use to infer some conclusion from the
premises.
10
Proofing validity of arguments using truth table
Exercise. Check the validity of the following argument using truth table
1. p→q 2. p → (q ∨ ~ r)
~p q → p ˄r
~p p→r
11