Sunteți pe pagina 1din 15

FORMAL FOUNDATION

1. Logic and Inference


1.1. Propositional Logic

What’s wrong with natural languages?


Natural languages are very expressive, flexible and rich. However, our languages
tend to be ambiguous and imprecise. A single expression or sentence may have several
meanings.

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.

Programs are arguments.


A description of a program basically says that given specific inputs (data), it produces
specific output (results).

How to identify Arguments in Logic?


Ex:
If I play chess or I go to work, but not both, then I will not be studying. Therefore, if I study
then I do not play chess or I do not go to work.

Argument:
p: I play chess
q: I go to work
r: I study

It can be written as:


If p OR q, but NOT p AND q, then NOT r. Therefore, IF r THEN either NOT p and NOT
q.

Premises Vs. Conclusion


• Premises – A statement that is an assumption that something is true. It is based on a
set of declarative sentences.
• Conclusion – A statement verified to be true using premises.
Ex:
Premises:
1. My phone is not working
2. When my brother’s phone wasn’t working, it was because it had fallen.
3. My type of phone is very fragile.
4. My phone was on the floor.

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).

Ex: Earth is smaller than Jupiter => Valid proposition.


Parrot is a four-legged animal => Proposition but invalid.
Propositional Connectives

NAME READ AS NOTATION


Negation not ¬
Conjunction and Ù
Disjunction or Ú
Implication if… then… Þ
equivalence if and only if Û

Propositional Logic as a Language


To define a language, we need
• An alphabet: a, b, c, A, B, C
• Rules to govern the syntax. (grammar)
• Semantic interpretation – assigning related meaning to the well-formed sentences.

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

D Excess demand increases


A Inflation rises
B Inflation falls
C There are tax cuts

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)

Contingent – Formulae that can evaluate to true or false.

1.2. Laws of Propositional logic


• Commutative Laws
p^qºq^p
pvqºqvp

• 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 Excluded Middle


p v ¬p º true

• 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

1.3. Logic proofs in Propositional logic


• Rule of Substitution
We can substitute a logically equivalent formula for a sub-formula embedded in a
much larger formula without changing its meaning.

• Rule of Transitivity
If p º q and q º r, then p º r

1.4. Deductive proofs


Deductive proof is an approach to establish the validity of an argument by
using a series of simpler arguments (inference rules) that are known to be valid.
An inference rule is a primitive valid argument form. Each inference rule
enables the elimination (E) or the introduction (I) of a logical connective.

• Conjunction: ^_I
p
q
then
p^q

• Simplification: ^_E
p^q
then
p

• Addition: v_I
p
then
pvq

• Disjunctive syllogism: v_E


pvq
¬p
then
q

• Modus ponens: =>_E


p => q
p
then
q

• Modus Tollens: =>_E


p => q
¬q
then
¬p

• Double negation: ¬_E


¬¬p
then
p

• Transitivity of equivalence: ó_I


póq
qór
then
pór

• Deduction theorem: =>_I


p1, p2,…,pk, s entails t
then
p1, p2,…,pk entails s=>t
• Resolution
pvq
¬p v r
then
qvr

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 denote “x is greater than 3” by P(x) where


• P is the predicate “is greater than 3”
• x is the variable.
Statement P(x) can also be said to be the value of the propositional function P at x.

We can also have statements that involve more than one variable. Ex: Q(x,y) for x = y.

n-ary predicate – P(x1, x2,…, xn)

Pre-conditions – Statements that describe valid inputs.

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.

"X • adult(X) => eligible(X)


Adult(John)
Therefore, eligible(John)

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.

o "x • $y • employs(x,y) => smart(y) ^ clever(x)


All employers are smart if they employ smart employees.

o ("x • $y • employs(x,y) => smart(y))^ clever(x)


All employers employ at least one smart employee and x is clever.

o "x • employs(x,y) => $y • smart(y) ^ clever(y)


If everyone employs y then there is someone who is smart and clever.

Bound variables: Occurrence of a variable has being introduced by a quantifier in that


formula and lies within the scope of that quantifier.
Ex: "x • $y • loves(x,y)

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

Theorems used for Quantifiers


o "x • p(x) ^ q(x) º ("x • p(x)) ^ ("x • q(x))
o $x • p(x) v q(x) º ($x • p(x)) v ($x • q(x))
o ¬$x • p(x) º "x • ¬p(x)
o ¬"x • p(x) º $x • ¬p(x)
Genuine variable: A free variable, the universal quantification of which yields a true
formula.

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.

There are 2 steps:


o Basis step: We verify that P(1) is true.
o Inductive step: We show that the conditional statement P(k) à P(k+1) for all positive
integers k.

4. Modelling Computations
4.1. Languages and Grammars

• Grammar – Tells us whether a combination of words is a valid sentence. It is


concerned only with the syntax but not the meaning.
• Formal language – A language that is specified by a well-defined set of rules of
syntax.

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.

4.2. Finite State Machines

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.

Ex: if A = {0,11} and B = {1,10} then


AB = {01, 010, 111, 1110}

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.

Deterministic FSA (DFA)


M = (S, I, f, s0, F)
where,
F = subset of S consisting of final states.
Transition table for DFA

Non-Deterministic FSA (NFA)


In the state for a NFA, we include an edge from each state to all possible next states,
labelling edges with the input or inputs that lead to this transition.
Theorem
If the language L is recognized by a NFA M0, then L is also recognized by a DFA M1.

4.3. Regular languages

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.

S-ar putea să vă placă și