logic and function
TRANSCRIPT
-
7/29/2019 Logic and function
1/62
Module #1 - Logic
1
The Foundations of Logic
-
7/29/2019 Logic and function
2/62
2
Foundations of Logic
Mathematical Logic is a tool for working withelaboratecompoundstatements. It includes:
A formal languagefor expressing them. A concisenotation for writing them.
A methodology for objectively reasoning abouttheir truth or falsity.
It is the foundation for expressingformal proofsin all branches of mathematics.
-
7/29/2019 Logic and function
3/62
3
Foundations of Logic: Overview
Propositional logic:
Basic definitions.
Equivalence rules & derivations. Predicate logic
Predicates.
Quantified predicate expressions. Equivalences & derivations.
-
7/29/2019 Logic and function
4/62
4
Propositional Logic
Propositional Logic is the logic of compoundstatements built from simpler statementsusing so-calledBooleanconnectives/operators.
Some applications in computer science:
Design of digital electronic circuits.
Expressing conditions in programs.
Queries to databases & search engines.
Topic #1 Propositional Logic
-
7/29/2019 Logic and function
5/62
5
Definition of aProposition
Definition: A proposition(denotedp, q, r, ) issimply:
astatement(i.e., a declarative sentence) with somedefinitemeaning,
(not vague or ambiguous)
having atruth value
thats either true(T) or false(F) it isnever both, neither, or somewhere in between!
However, you might notknowthe actual truth value,
and, the value mightdependon the situation or context.
Topic #1 Propositional Logic
-
7/29/2019 Logic and function
6/62
6
Examples of Propositions
It is raining. (In a given situation.)
Beijing is the capital of China.
1 + 2 = 3But, the following areNOT propositions:
Whos there? (interrogative, question)
Just do it! (imperative, command) 1 + 2 (expression with a non-true/false
value)
Topic #1 Propositional Logic
-
7/29/2019 Logic and function
7/62
7
Anoperator or connectivecombines one or moreoperandexpressions into a larger expression.
(E.g., + in numeric exprs.) Unaryoperators take 1 operand (e.g., 3);
Binaryoperators take 2 operands (e.g., 3 4).
Propositional or Booleanoperatorsoperateonpropositions (or their truth values) instead ofonnumbers.
Operators / Connectives
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
8/62
8
Some Popular Boolean Operators
Formal Name Nickname Arity Symbol
Negation operator NOT Unary Conjunction operator AND Binary
Disjunction operator OR Binary
Exclusive-OR operator XOR Binary
Implication operator IMPLIES Binary
Biconditional operator IFF Binary
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
9/62
9
The Negation Operator
The unarynegation operator (NOT)transforms a prop. into its logical negation.
E.g. Ifp= I have brown hair.then p= I donot have brown hair.
Thetruth tablefor NOT: p p
T F
F TT : True; F : False: means is defined as
Operandcolumn
Resultcolumn
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
10/62
10
The Conjunction Operator
The binaryconjunction operator (AND)combines two propositions to form their
logical conjunction.E.g. Ifp=I will have salad for lunch. and
q=I will have steak for dinner., then
pq=I will have salad for lunchandI will have steak for dinner.
Remember: points up like an A, and it means ND
ND
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
11/62
11
Note that aconjunctionp1 p2 pnofnpropositionswill have 2n rows
in its truth table.
Conjunction Truth Table
p q pq
F F FF T F
T F F
T T T
Operand columns
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
12/62
12
The Disjunction Operator
The binarydisjunction operator (OR)combines two propositions to form their
logical disjunction.p=My car has a bad engine.
q=My car has a bad carburetor.
pq=Either my car has a bad engine, ormy car has a bad carburetor.
Topic #1.0 Propositional Logic: Operators
Meaning is like and/or in English.
-
7/29/2019 Logic and function
13/62
13
Note thatpqmeansthatp is true, or q is
true, or both are true! So, this operation is
also called inclusive or,
because it includesthepossibility that bothpandqare true.
Disjunction Truth Table
p q pq
F F FF T T
T F T
T T T
differencefrom AND
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
14/62
14
Nested Propositional Expressions
Use parentheses togroup sub-expressions:I just saw my oldfriend, and either hes
grownor Iveshrunk. =f
(g
s) (f g) s would mean something
different
f g s would be ambiguous
By convention, takesprecedenceoverboth and .
s f means (s) f , not (s f)
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
15/62
15
A Simple Exercise
Letp= It rained last night,q= The sprinklers came on last night,
r = The lawn was wet this morning.Translate each of the following into English:
p =
r p =r p q =
It didnt rain last night.
The lawn was wet this morning, andit didnt rain last night.
Either the lawn wasnt wet thismorning, or it rained last night, orthe sprinklers came on last night.
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
16/62
16
TheExclusive Or Operator
The binaryexclusive-or operator (XOR)combines two propositions to form their
logical exclusive or.p= I will earn an A in this course,
q=I will drop this course,
p q= I will either earn an A in this course,or I will drop it (but not both!)
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
17/62
17
Note thatpqmeansthatp is true, or q is
true, butnot both! This operation is
calledexclusive or,
because itexcludesthepossibility that bothpandqare true.
Exclusive-Or Truth Table
p q pq
F F FF T T
T F T
T T F Notedifferencefrom OR.
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
18/62
18
Note that Englishor can be ambiguousregarding the both case!
Pat is a singer orPat is a writer. -
Pat is a man or
Pat is a woman. -Need context to disambiguate the meaning!
For this course, assume or means inclusive.
Natural Language is Ambiguous
p q p"or" q
F F F
F T T
T F T
T T ?
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
19/62
19
TheImplicationOperator
Theimplicationp qstates thatp impliesq.
i.e., Ifp is true, thenq is true; but ifp is nottrue, thenqcould be either true or false.
E.g., letp= You study hard.q= You will get a good grade.
p q =If you study hard, then you will geta good grade. (else, it could go either way)
antecedent consequent
-
7/29/2019 Logic and function
20/62
20
Implication Truth Table
p q is falseonlywhenp is true butq isnot true.
p q doesnot saythatpcausesq!
p q doesnot require
thatpor qare ever true! E.g. (1=0) pigs can fly is TRUE!
p q pq
F F T
F T T
T F F
T T T
TheonlyFalse
case!
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
21/62
21
Examples of Implications
If this lecture ends, then the sun will risetomorrow.Trueor False?
If Tuesday is a day of the week, then I am apenguin.Trueor False?
If 1+1=6, then Obama is president of USA.
Trueor False? If the moon is made of green cheese, then I
am richer than Bill Gates.Trueor False?
Topic #1.0 Propositional Logic: Operators
-
7/29/2019 Logic and function
22/62
22
English Phrases Meaningp q
p impliesq
ifp, thenq
ifp, q whenp, q
whenever p, q
q
ifp
qwhenp
qwhenever p
ponly ifq
p is sufficient for q
q is necessary for p q follows fromp
q is implied by p
We will see some equivalentlogic expressions later.
i i i l i
-
7/29/2019 Logic and function
23/62
23
Converse, Inverse, Contrapositive
Some terminology, for an implicationp q:
Itsconverseis: q p.
Its inverse is: p q. Itscontrapositive: q p.
One of these three has thesame meaning
(same truth table) asp q. Can youfigure out which?
Topic #1.0 Propositional Logic: Operators
T i #10 P i i l L i O
-
7/29/2019 Logic and function
24/62
24
How do we know for sure?
Proving the equivalence ofp qand itscontrapositive using truth tables:
p q q p pq qp
F F T T T T
F T F T T T
T F T F F FT T F F T T
Topic #1.0 Propositional Logic: Operators
T i #10 P iti l L i O t
-
7/29/2019 Logic and function
25/62
25
Thebiconditional operator
Thebiconditional p qstates thatp is trueif and
only if (IFF) q is true.p= You can take the flight.
q=You buy a ticket.
p q =You can take the flight if and only if youbuy a ticket.
Topic #1.0 Propositional Logic: Operators
T i #10 P iti l L i O t
-
7/29/2019 Logic and function
26/62
26
Biconditional Truth Table
p qmeans thatpandqhave thesametruth value.
Note this truth table is theexactoppositeofs!
Thus, p qmeans (p q)
p qdoesnot implythatpandqare true, or cause each other.
p q pq
F F T
F T F
T F F
T T T
Topic #1.0 Propositional Logic: Operators
T i #10 P iti l L i O t
-
7/29/2019 Logic and function
27/62
27
Boolean Operations Summary
We have seen 1 unary operator and 5binary operators. Their truth tables are
below.p q p pq pq pq pq pq
F F T F F F T T
F T T F T T T FT F F F T T F F
T T F T T F T T
Topic #1.0 Propositional Logic: Operators
T i #2 Bit
-
7/29/2019 Logic and function
28/62
28
Bits and Bit Operations
A bit is a binary (base 2) digit: 0 or 1.
Bits may be used to represent truth values.
By convention:0 represents false; 1 represents true.
Boolean algebra is like ordinary algebra
except thatvariables stand for bits,+ means or, andmultiplication means and.
Topic #2 Bits
Topic#2 Bits
-
7/29/2019 Logic and function
29/62
29
Bit Strings
A Bit stringof length n is anordered seriesor sequence of n 0 bits.
By convention, bit strings are written left toright: e.g. the first bit of 1001101010 is 1.
When a bit string represents a base-2 number,by convention the first bit is themost
significantbit. Ex. 11012=8+4+1=13.
Topic #2 Bits
Topic#2 Bits
-
7/29/2019 Logic and function
30/62
30
Bitwise Operations
Boolean operations can be extended tooperate on bit strings as well as on single bits.
E.g.:01 1011 011011 0001 1101
11 1011 1111 Bit-wise OR01 0001 0100 Bit-wise AND10 1010 1011 Bit-wiseXOR
Topic #2 Bits
-
7/29/2019 Logic and function
31/62
31
Summary on Propositional Logic
You have learned about:
Propositions: Whatthey are.
Propositional logicoperators Symbolic notations.
English equivalents.
Logical meaning.
Truth tables.
Atomic vs. compoundpropositions..
Bits and bit-strings.
Upcoming topics:
Propositional
equivalences. How to prove them.
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
32/62
32
Propositional Equivalence
Twosyntactically(i.e., textually) differentcompound propositions may be
semantically identical (i.e., have the samemeaning). We call themequivalent.
Learn:
Variousequivalence rulesor laws. How toproveequivalences usingsymbolic
derivations.
Topic #1.1 Propositional Logic: Equivalences
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
33/62
33
Tautologies and Contradictions
A tautology is a compound proposition that istrueno matter what the truth values of itsatomic propositions are!
Ex. p p [What is its truth table?]
A contradiction is a compound propositionthat is falseno matter what! Ex. p p
[Truth table?]Other compound props. arecontingencies.
Topic #1.1 Propositional Logic: Equivalences
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
34/62
34
Logical Equivalence
Compound propositionp is logicallyequivalent to compound propositionq,
writtenp
q, IFF the compoundpropositionpq is a tautology.
Compound propositionspandqare logically
equivalent to each other IFF pandqcontain the same truth values as each otherin all rows of their truth tables.
Topic #1.1 Propositional Logic: Equivalences
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
35/62
35
Ex. Prove thatpq (p q).
p q ppqq pp qq ppqq ((ppqq))
F F
F T
T F
T T
Proving Equivalence
via Truth Tables
FT
TT
T
T
T
TT
T
FF
F
F
FF
FF
TT
Topic #1.1 Propositional Logic: Equivalences
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
36/62
36
Equivalence Laws
These are similar to the arithmeticidentities you may have learned in algebra,
but for propositional equivalences instead. They provide a pattern or template that can
be used to match all or part of a much more
complicated proposition and to find anequivalence for it.
Topic #1.1 Propositional Logic: Equivalences
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
37/62
37
Equivalence Laws - Examples
Identity: pT p pF p
Domination: pT T pF F
Idempotent: pp p pp p Double negation: p p
Commutative: pq qp pq qp
Associative: (pq)r p(qr)(pq)r p(qr)
Topic #1.1 Propositional Logic: Equivalences
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
38/62
38
More Equivalence Laws
Distributive: p(qr) (pq)(pr)p(qr) (pq)(pr)
De Morgans:(pq) p q(pq) p q
Trivial tautology/contradiction:
p p T p p F
Topic #1.1 Propositional Logic: Equivalences
Augustus
De Morgan(1806-1871)
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
39/62
39
Defining Operators via Equivalences
Using equivalences, we candefineoperatorsin terms of other operators.
Exclusive or: pq (pq)(pq)pq (pq)(qp)
Implies: pq p q
Biconditional: pq (pq) (qp)pq (pq)
Topic #1.1 Propositional Logic: Equivalences
Topic#11 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
40/62
40
An Example Problem
Check using a symbolic derivation whether (p ( p q)) p q.
Topic #1.1 Propositional Logic: Equivalences
-
7/29/2019 Logic and function
41/62
41
Predicate Logic
Predicate logic is an extension ofpropositional logic that permits concise
reasoning about wholeclassesof entities. Propositional logic (recall) treats simple
propositions (sentences) as atomic entities.
In contrast, predicatelogic distinguishesthesubjectof a sentence from itspredicate.
Remember these English grammar terms?
Topic#3 PredicateLogic
-
7/29/2019 Logic and function
42/62
42
Subjects and Predicates
InthesentenceThedogissleeping:
The phrase the dog denotes thesubject -
theobject
orentity
that the sentence is about. The phrase is sleeping denotes the
predicate- a property that is trueofthe subject.
In predicate logic, apredicateis modeled asafunctionP() from entities to propositions.
P(x) = x is sleeping (wherex is any object).
Topic #3 Predicate Logic
Topic#3 PredicateLogic
-
7/29/2019 Logic and function
43/62
43
More About Predicates
Convention: Lowercase variablesx, y, z... denoteobjects/entities; uppercase variablesP, Q, Rdenote propositional functions (predicates).
Keep in mind that theresult ofapplyingapredicateP to an objectx is theproposition P(x).But the predicateP itself(e.g. P=is sleeping) is
not a proposition (not a complete sentence). E.g. ifP(x) = x is a prime number,
P(3) is theproposition3 is a prime number.
Topic #3 Predicate Logic
Topic#3 PredicateLogic
-
7/29/2019 Logic and function
44/62
44
Propositional Functions
Predicate logicgeneralizesthe grammaticalnotion of a predicate to also include
propositional functions ofanynumber ofarguments, each of which may takeanygrammatical role that a noun can take.
E.g. letP(x,y,z) = xgaveythe gradez, thenifx=Mike, y=Mary, z=A, thenP(x,y,z) =Mike gave Mary the grade A.
Topic #3 Predicate Logic
Topic#3 PredicateLogic
-
7/29/2019 Logic and function
45/62
45
Universes of Discourse (U.D)
The power of distinguishing objects frompredicates is that it lets you state things
aboutmanyobjects at once. E.g., letP(x)=x+1>x. We can then say,
Foranynumberx, P(x) is true instead of
(0+1>0) (1+1>1) (2+1>2) ... The collection of values that a variablexcan
take is calledxsuniverse of discourse.
Topic #3 Predicate Logic
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
46/62
46
Quantifier Expressions
Quantifiersprovide a notation that allowsus toquantify(count) how manyobjects inthe univ. of disc. satisfy a given predicate.
is the FORLL or universalquantifier.xP(x) means for all x in the u.d., P holds.
is theXISTS or existential quantifier.x P(x) means thereexistsanx in the u.d.(that is, 1 or more) such thatP(x) is true.
p g
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
47/62
47
The Universal Quantifier
Example:Let the u.d. of x be parking spaces at UBC.LetP(x) be thepredicatex is full.
Then theuniversal quantification of P(x),xP(x), is theproposition: All parking spaces at UBC are full.
i.e., Every parking space at UBC is full. i.e., For each parking space at UBC, that
space is full.
p g
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
48/62
48
The Existential Quantifier
Example:Let the u.d. of x be parking spaces at UBC.
LetP(x) be thepredicatex is full.Then theexistential quantification of P(x),xP(x), is theproposition:
Some parking space at UBC is full.
There is a parking space at UBC that is full.
At least one parking space at UBC is full.
p g
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
49/62
49
Free and Bound Variables
An expression likeP(x) is said to have afree variablex(meaning, x is undefined).
A quantifier (either or ) operateson anexpression having one or more freevariables, andbindsone or more of thosevariables, to produce an expression havingone or moreboundvariables.
p g
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
50/62
50
Example of Binding
P(x,y) has 2 free variables, xandy.
xP(x,y) has 1 free variable, and one boundvariable. [Which is which?]
P(x), wherex=3 is another way to bindx.
An expression with zero free variables is anactual proposition.
An expression with one or morefree variables isstill only a predicate: e.g. letQ(y) =xP(x,y)
p g
-
7/29/2019 Logic and function
51/62
51
Negations on Quantifiers
We will often want to consider the negationof a quantified expression.
Example: Consider the statement Every student in the
class has taken a course in calculus.
This statement is a universal quantification,namely, x P(x) where P(x) is the statementx has taken a course in calculus
-
7/29/2019 Logic and function
52/62
52
Negate a Universal Quantification
The negation of the above statement is
It is not the case that every student has taken a
course in calculus, namely, x P(x). Or, put it another way,
There is at least a student in the class who has nottaken a course in calculus, namely, xP(x).
This example illustrates the following equivalence:
x P(x) xP(x)
-
7/29/2019 Logic and function
53/62
53
Negate an Existential Quantification
Example: Consider the statement
There is a student in the class who has taken acourse in calculus, namely x Q(x), where Q(x) is
the statement x has a course in calculus. The negation of this statement is the proposition
It is not the case that there is a student in theclass who has taken a course in calculus,namely, x Q(x).
This is equivalent toEvery student in this class has not taken a coursein calculus, namely, x Q(x).
So x Q(x) x Q(x).
-
7/29/2019 Logic and function
54/62
54
Negation Equivalence
De Morgans Laws in the case of negations ofquantifiers (assuming that all the elements of u.d.can be listed)
x P(x) (P(x1) P(x2) P(xn)) P(x1) P(x2) P(xn)
x P(x)
x P(x) (P(x1) P(x2) P(xn)) P(x1) P(x2) P(xn)
x P(x)
-
7/29/2019 Logic and function
55/62
55
Examples on Negations
What is the negations of the followingstatement? There is an honest politician
Solution: There is an honest politician is represented
by x H(x) where H(x) is the statement x is
an honest politician The negation is
There is not a single honest politicianwhich is represented by
x H(x), or x H(x).
-
7/29/2019 Logic and function
56/62
56
Examples on Negations (cont.)
What are the negations of the followingstatements? All Canadians play hockey
Solution: All Canadians play hockey is represented
by x H(x), where H(x) is the statement
x plays hockey The negation is
Some Canadian does not play hockey,which is represented by
x H(x), or x H(x).
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
57/62
57
Nesting of Quantifiers
Example: Let the u.d. ofx& ybe people.
LetL(x,y)=x likesy (a predicate w. 2 f.v.s)
Theny L(x,y) = There is someone whomxlikes. (A predicate w. 1 free variable, x)
Thenx(y L(x,y)) =
Everyone has someone whom they like.(A __________ with ___ free variables.)
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
58/62
58
Quantifier Exercise
IfR(x,y)=xrelies upony,express the following in unambiguous English:
x(y R(x,y))=y(xR(x,y))=
x(y R(x,y))=
y(x R(x,y))=x(yR(x,y))=
Everyone hassomeoneto rely on.
Theres a poor overburdened soul whomeveryonerelies upon (including himself)!
Theres some needy person who relies
uponeverybody(including himself).Everyone hassomeonewho relies upon them.
Everyonerelies uponeverybody,(including themselves)!
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
59/62
59
Some Conventions
Sometimes the universe of discourse isrestricted within the quantification, e.g.,
x>0P(x) is shorthand forFor all xthat are greater than zero, P(x).
=x(x>0 P(x))
x>0P(x) is shorthand for
There is anxgreater than zero such thatP(x).
=x(x>0 P(x))
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
60/62
60
Defining New Quantifiers
As per their name, quantifiers can be used toexpress that a predicate is true of any givenquantity
(number) of objects.Define!xP(x) to mean P(x) is true ofexactly onex in the universe of discourse.
!xP(x) x(P(x) y(P(y) yx))There is anxsuch thatP(x), where there isnoysuch that P(y) andy is other thanx.
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
61/62
61
A Number Theory Example
Let u.d. = the positiveinteger numbers0, 1, 2,
A number x iseven, E(x), if and only if
it is equal to 2 times some other number.x(E(x) (y x=2y))
A number isprime, P(x), iff
its greater than 1 and it isnt the product of any
two non-unity numbers.x(P(x) (x>1 yz x=yz y1 z1))
Topic #3 Predicate Logic
-
7/29/2019 Logic and function
62/62
Review: Predicate Logic
You should have learned:
Predicate logic notation & conventions
Conversions: predicate logic
clear English Meaning of quantifiers, equivalences
Upcoming topics:
Introduction to proof-writing. Then: Set theory
a language for talking about collections of objects.