39
Boolean logic Implication Defining a set Propositional Logic Boolean or Propositional Logic SET07106 Mathematics for Software Engineering School of Computing Edinburgh Napier University Module Leader: Uta Priss 2010 Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 1/31

Boolean or Propositional Logic - · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Embed Size (px)

Citation preview

Page 1: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Boolean or Propositional Logic

SET07106 Mathematics for Software Engineering

School of ComputingEdinburgh Napier UniversityModule Leader: Uta Priss

2010

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 1/31

Page 2: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Outline

Boolean logic

Implication

Defining a set

Propositional Logic

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 2/31

Page 3: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Boolean logic

Consider variables A,B,C , ... which can have two values:either True (1) or False (0).

There are three logical operators: and, or, not.

Negation: not(not A) = A not(1) = 0 not(0) = 1

Complements: A or (not A) = 1 A and (not A) = 0

Implication: A =⇒ B

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 3/31

Page 4: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Where is this logic used?

In many programming languages, query languages, search engines.Using different notations:

and: &, &&or: |, ||not: ∼, !

if ( ... and ... )if (not ( ... ) or ... )

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 4/31

Page 5: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Boolean logic properties

I associative:(A and B) and C = A and (B and C)(A or B) or C = A or (B or C)

I commutative:A and B = B and AA or B = B or A

I distributive:(A and B) or C = (A or C) and (B or C)(A or B) and C = (A and C) or (B and C)

I idempotent:A and A = AA or A = A

I transitive: A =⇒ B and B =⇒ C implies A =⇒ C

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 5/31

Page 6: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Logic versus natural language

The logical use of “and, or, not” can be quite different from howthese are used in natural language.

Formal logic can be counter-intuitive.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 6/31

Page 7: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

AND

What does “and” mean in these sentences:

I He entered the room and sat down.

=⇒ then

I She bought a computer and a printer. =⇒ and

I Students in classes 101 and 202. =⇒or

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 7/31

Page 8: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

AND

What does “and” mean in these sentences:

I He entered the room and sat down. =⇒ then

I She bought a computer and a printer.

=⇒ and

I Students in classes 101 and 202. =⇒or

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 7/31

Page 9: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

AND

What does “and” mean in these sentences:

I He entered the room and sat down. =⇒ then

I She bought a computer and a printer. =⇒ and

I Students in classes 101 and 202.

=⇒or

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 7/31

Page 10: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

AND

What does “and” mean in these sentences:

I He entered the room and sat down. =⇒ then

I She bought a computer and a printer. =⇒ and

I Students in classes 101 and 202. =⇒or

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 7/31

Page 11: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

OR

What does “or” mean in these sentences:

I Would you like a beer or a whisky.

=⇒ exclusive or: “either or” (BOTH would be impolite)

I I bet he is sitting in the bar and drinking a beer or a whisky.=⇒ inclusive or: (BOTH is acceptable)

Logical “or” is always inclusive: “one or the other or both”.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 8/31

Page 12: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

OR

What does “or” mean in these sentences:

I Would you like a beer or a whisky.=⇒ exclusive or: “either or” (BOTH would be impolite)

I I bet he is sitting in the bar and drinking a beer or a whisky.

=⇒ inclusive or: (BOTH is acceptable)

Logical “or” is always inclusive: “one or the other or both”.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 8/31

Page 13: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

OR

What does “or” mean in these sentences:

I Would you like a beer or a whisky.=⇒ exclusive or: “either or” (BOTH would be impolite)

I I bet he is sitting in the bar and drinking a beer or a whisky.=⇒ inclusive or: (BOTH is acceptable)

Logical “or” is always inclusive: “one or the other or both”.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 8/31

Page 14: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

NOT

I Rhetoric uses: The drink was not bad.

I Double negative: I doN’T DISlike computers. =⇒ positive

I Double negative: We doN’T need NO education. =⇒ negative

Logical “not not A” always means “A”.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 9/31

Page 15: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

NOT

I Rhetoric uses: The drink was not bad.

I Double negative: I doN’T DISlike computers.

=⇒ positive

I Double negative: We doN’T need NO education. =⇒ negative

Logical “not not A” always means “A”.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 9/31

Page 16: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

NOT

I Rhetoric uses: The drink was not bad.

I Double negative: I doN’T DISlike computers. =⇒ positive

I Double negative: We doN’T need NO education.

=⇒ negative

Logical “not not A” always means “A”.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 9/31

Page 17: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

NOT

I Rhetoric uses: The drink was not bad.

I Double negative: I doN’T DISlike computers. =⇒ positive

I Double negative: We doN’T need NO education. =⇒ negative

Logical “not not A” always means “A”.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 9/31

Page 18: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Truth Tables

not(name = ’Smith’ or age = ’40’)

name age name or age not(name or age)

true true true falsetrue false true falsefalse true true falsefalse false false true

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 10/31

Page 19: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

De Morgan’s law

I not (a and b) = (not a) or (not b)

I not (a or b) = (not a) and (not b)

He doesn’t want tea or coffee.He doesn’t want tea and he doesn’t want coffee.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 11/31

Page 20: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Exercise

Use de Morgan’s laws to show that the complement of

(A and B) and (A or B) and (A or C )

is

(A or B) or (A and (B or C ))

Note: A means: not A.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 12/31

Page 21: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Set theory and Boolean logic

0 0 1

{a, c} {b, c}

{b}{a} {c}

{}

{a, b, c}

1 0 0

0 0 0

1 0 1 0 1 11 1 0

1 1 1

0 1 0

{a, b}

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 13/31

Page 22: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Implication

A =⇒ B means (not A) or B

A B not(A) (not A) or B

true true false truetrue false false falsefalse true true truefalse false true true

True implies true.True can never imply false.If A is false, then anything can be implied.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 14/31

Page 23: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Examples of implication: A =⇒ B

I A is true:I If x = 2, then 2x = 4.I If you practice for an exam, then you will succeed.

I A is false:I If I were a carpenter, then I would be rich.I If 5 = 7, then 15 = 22.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 15/31

Page 24: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Exercise: is this true or false?

If Sue is a programmer, then she is smart.If Sue is an early riser, then she does not like porridge.If Sue is smart, then she is an early riser.

Therefore, if Sue is a programmer, then she does not like porridge.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 16/31

Page 25: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Contraposition

A =⇒ B implies not B =⇒ not A.

Example:

If it is raining, I carry an umbrella.If I don’t carry an umbrella, it is not raining.

The following are false:

If it is not raining, I do not carry an umbrella.If I carry an umbrella, it is raining.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 17/31

Page 26: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Exercise

Prove that contraposition is true, i.e.A =⇒ B implies not B =⇒ not A.

Hint: you can use truth tables or the properties of Boolean logicfor this.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 18/31

Page 27: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Extensional and intensional definition of sets

? Extensional:

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}{2, 4, 6, 8, 10}{2, 3, 5, 7, 11, ...}

? Intensional:

{n | 1 ≤ n ≤ 10}{m | m = 2n and 1 ≤ n ≤ 5}

{n | n is a prime number }= {n | ∀k : k is a factor of n =⇒ n = 1 or n = k}

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 19/31

Page 28: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Intensional definition of sets

{n | ∀k : k is a factor of n =⇒ n = 1 or n = k}

? name of the resulting variable: n

? definition: ∀k : k is a factor of n =⇒ n = 1 or n = k

What symbols can be used in definitions?

Here: ∀k , =, “is a factor of”, and, or, not

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 20/31

Page 29: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

The Liar’s Paradox

I am a liar!

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 21/31

Page 30: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

The Liar’s Paradox

I am a liar!

Either:The Liar speaks the truth ⇒ The Liar lies.Or:The Liar lies ⇒ “I am a liar” is wrong. The Liar speaks the truth.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 22/31

Page 31: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Russell’s paradox: Is there a set of all sets?

Intensional: S := {T | T is a set }Extensional: S := { set of integers, set of real numbers, set oftraffic light symbols, set of all things in the universe, ..., S }.

But then one can also define:

S : the set of all sets that do not contain itself.But then since S does not contain itself, it must contain itself!

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 23/31

Page 32: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

What does this mean for Set Theory?

I Sets must be carefully defined.

I Not every collection of elements that can be described inwords is necessarily a set.

I In extensional definitions of infinite sets, it must be clear what“...” means.

I In intensional definitions, it must be clear what symbols canbe used.

If one isn’t sure whether something is a set, call it a “class”.There is no “set of all sets”, but there is a “class of sets”.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 24/31

Page 33: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

In intensional definitions, it must be clear what symbolscan be used:

A formal logic is a language with a fixed set of symbols withsyntax, grammar, semantics (formal meaning) which can be usedfor defining sets and for reasoning, deduction and inference.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 25/31

Page 34: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Exercise

Which of these are sets, which are classes?

I all elements in the universe

I n | n < 5 and n > 5

I all dinosaurs which ever lived on the Earth

I all dinosaurs which would be alive now, if some catastrophehad not killed their species

I all sets

I all subsets of a set

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 26/31

Page 35: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Propositional logic

A proposition is a statement that is either true or false.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 27/31

Page 36: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Exercise: which of these are propositions?

I 1 + 1 = 2

I How are you?

I I am fine.

I x == 3

I if (x == 3) {I print ’Hello World’

I n = n + 1

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 28/31

Page 37: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Formal propositions

Propositions are formed using “and, or, not” and variables(i.e. Boolean Logic).

The semantics (or meaning) of a proposition is its truth value.

Two propositions p, q are equivalent (p ⇐⇒ q) if they always havethe same truth value. (They are either both true or both false.)

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 29/31

Page 38: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Exercise: which of these are equivalent?

I 1 + 1 = 2 and 2 + 2 = 4

I It is raining today.

I 8 is a prime number.

I x = 3 ⇐⇒ x = 4

I There are 25 students in this classroom.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 30/31

Page 39: Boolean or Propositional Logic -  · PDF fileTitle: Boolean or Propositional Logic Author: SET07106 Mathematics for Software Engineering Created Date: 20100119095932Z

Boolean logic Implication Defining a set Propositional Logic

Intensional definitions of sets

Propositional logic in combination with some mathematicalsymbols (=, ≤, ×) can be used to define sets, such as:

{2, 4, 6, 8, 10} = {m | m = 2× n and 1 ≤ n ≤ 5}

But propositional logic is not sufficient for this definition:

{n | ∀k : k is a factor of n =⇒ n = 1 or n = k}

because ∀k is not part of propositional logic.

Copyright Edinburgh Napier University Boolean or Propositional Logic Slide 31/31