Documente Academic
Documente Profesional
Documente Cultură
Ex:
• If she is sick, Karen will stay at home.
• Albert is tall.
What’s Logic?
Logic makes a discipline scientific. We can deduce a larger amount of knowledge
from each discipline from a relatively small number of explicitly stated facts or hypotheses.
Logic can be treated as a language which allows to express knowledge concisely and
precisely and gives a way to reason about the consequences of that knowledge
thoroughly.
Argument:
p: I play chess
q: I go to work
r: I study
Therefore,
Conclusion:
5. It is not working because it has had a fall.
Types of arguments:
• Deductive arguments: If the conclusion is made based on only the given premises, it
is a deduction.
• Inductive arguments: If the conclusion is based on a strong but inconclusive
evidence, it is an induction.
Logic Systems
Logic was based on a simple analysis of simple sentences into subject-predicate form.
Actual form:
All men are mortals
Socrates is a man
Therefore, Socrates is a mortal.
Abstract Form
All Xs are Ys
s is and X
Therefore, s is a Y => Valid argument.
Such logic “patterns” used to form of an argument from its content can be referred to as
syllogisms.
Propositional Logic
It allows reasoning about arguments of a particular form where certain types of
statements called propositions are regarded as the smallest building blocks for constructing
complex statements.
Propositions
A proposition is the underlying meaning of a declarative sentence which is either
true(T) or false(F).
Sentences may be regarded as well-formed word strings, adhering to the rules of the
grammar.
Well-formed formula(wff) – A finite sequence or set of symbols from a given alphabet that
is a part of a formal language, following the syntactic rules for composing these symbols, so
that they form valid sentences in the formal language.
Propositional Connectives
• Negation
A negation ¬ p is true if and only if p is false.
p ¬p
0 1
1 0
• Conjunction
A conjunction p ^ q is true if and only if both p and q are true.
p and q are conjuncts.
p q p^q
0 0 0
0 1 0
1 0 0
1 1 1
• Disjunction
A disjunction p Ú q is true if and only if p is true or q is true (or both are true).
p and q are disjuncts.
p q pvq
0 0 0
0 1 1
1 0 1
1 1 1
• Implication
An implication p => q is false if and only if p is true and q is false.
p is called antecedent and q is the consequence.
p q p => q
0 0 1
0 1 1
1 0 0
1 1 1
• Equivalence
An equivalence p ó q is true if and only if p and q have the same truth value.
p q póq
0 0 1
0 1 0
1 0 0
1 1 1
Ex:
1. Increased spending overheats the economy.
Prime propositions
• S spending increases
• E economy overheats
Formalisation
• S => E
2. Rewrite the following English sentences as propositional formulae where
i. Inflation does not rise only if excess demand does not rise.
ii. There will be tax cuts if inflation falls.
iii. Inflation either rises or does not.
Tautology – A formula that is true for every possible assignment of truth-value to the prime
propositions.
Ex: (A v ¬ A)
Contradiction – A formula that is false for every possible argument of truth-value to the
prime propositions.
Ex: (A ^ ¬ A)
• Associative Laws
p ^ (q ^ r) º (p ^ q) ^ r
p v (q v r) º (p v q) v r
• Distributive Laws
p v (q ^ r) º (p v q) ^ (p v r)
p ^ (q v r) º (p ^ q) v (p ^ r)
• De Morgan’s Laws
o 1st: ¬(p ^ q) º ¬p v ¬q
o 2nd: ¬(p v q) º ¬p ^ ¬q
• Law of Negation
¬(¬p) º p
• Law of Contradiction
p ^ ¬p º false
• Law of Implication
p => q º ¬p v q
¬(p => q) º p ^ ¬q
• Contrapositive Law
p => q º ¬ q => ¬p
• Law of Equivalence
(póq) º (p => q) ^ (q => p)
• Idempotence
pvpºp
p^pºp
• Laws of Simplication I
o p ^ true º p
o p v true º true
o p ^ false º false
o p v false º p
• Laws of Simplication II
p v (p ^ q) º p
p ^ (p v q) º p
• Rule of Transitivity
If p º q and q º r, then p º r
• Conjunction: ^_I
p
q
then
p^q
• Simplification: ^_E
p^q
then
p
• Addition: v_I
p
then
pvq
Conditional Proof
A proof done using an additional assumption to the premises.
Reductio as absurdum
An indirect strategy to assume the conclusion is false and derive the contradiction
from that assumption.
2. Predicate Logic
Predicates
Statements involving variables. Ex: x > 3
Has two parts:
• The variable x – subject of the statement
• Predicate “greater than 3” – property the subject can have
We can also have statements that involve more than one variable. Ex: Q(x,y) for x = y.
Post-conditions – Conditions that the output must satisfy when the program has run.
Types of Predicates
• Unary predicates
Ex: ___ is a teacher.
teacher(X)
• Binary predicates
Ex: ___ is_older_than ___
is_older_than(X,Y)
• N-ary predicates
Involves n objects expressing a relationship among them.
Quantifiers
• Universal quantification (") – A predicate is true for every element under
consideration.
• Existential quantification ($) – A predicate is true for one or more elements under
consideration.
Predicate calculus – Area of logic that deals with predicates and quantifiers.
Precedence of quantifiers " and $ is higher than all other logical operators.
Ex:
1. Every adult is eligible to vote.
2. John is an adult.
3. Therefore, John is eligible to vote.
Scope of quantifiers
Brackets can be used to enforce any pattern of scoping.
Ex:
o "x • $y • employs(x,y) => smart(y) ^ clever(y)
All employers employ at least one smart, clever employee.
Free variable: Occurrence of a variable which does not lie in the scope of a quantifier.
Ex: $x • eats(y,x) => x: bound, y: free
Unknown variable: A free variable, the existential quantification of which yields a true
formula.
3. Introduction to Proof techniques
Direct Proof
Direct proof of a conditional statement p => q is constructed when
1. The first step is the assumption that p is true
2. Subsequent steps are constructed using rules of inference
3. With the final step showing that q must also be true.
Proof by Contraposition
Makes use of the fact that the conditional statement p => q is equivalent to its
contrapositive, ¬q => ¬p.
Vacuous proof
Proving p => q to be true when p is false.
Trivial proof
Proving p => q to be true when q is true.
Proof by Contradiction
For any proposition r, the statement r ^ ¬r is a contradiction. If for some r, we can show
that ¬p => (r ^ ¬r), then we can conclude p is true.
Proofs of Equivalence
To prove p ó q, we can show that p => q and q => p are both true.
Proof by Counterexample
To show that the statement of the form "x • P(x) is false, we only need to find an example x
for which P(x) is false.
Forward reasoning: Start with the premises given. Using them and known theorems and
axioms, we can construct a sequence of steps to get to the conclusion.
Backward reasoning: To prove a statement q, we find a statement p that we can prove with
the property that p => q.
Proof by Induction
Mathematical induction – We can show that the propositional function P(n) is true for every
positive integer n.
4. Modelling Computations
4.1. Languages and Grammars
Grammar
• It has a vocabulary V, which is a set of symbols to derive members of a language.
(Finite non-empty set of elements called symbols)
• Terminals (T) – elements that cannot be replaced.
• Non-terminals (N) – elements that can be replaced.
• Start symbol (S) – Element we always begin with.
• V* - the set of all the strings of elements in the vocabulary V.
M = (S, I, O, f, g, s0)
where,
S = finite set of states
I = finite input alphabet
O = finite output alphabet
f = transition function
g = output function
s0= initial state
Recognizing a Language
A string is recognized if and only if it takes the starting state to one of the given final states.
Concatenation
Suppose that A and B are subsets of V*, where V is a vocabulary. The concatenation of A
and B, denoted by AB, is the set of all strings of the form xy, where x is a string in A and y is a
string in B.
Kleene-Closure
Suppose that A is a subset of V*. Then the Kleene closure of A, denoted by A* is the set
consisting of concatenations of arbitrarily many strings from A.
What are the strings in the regular sets specified by the regular expressions
• 10*
• (10)*
• 0 U 01
• 0(0 U 1)*
• (0*1)*
Kleene’s Theorem
o A set is regular if and only if it is recognized by a finite-state automaton.
o A set is generated by a regular grammar if and only if it is a regular set.