#2 formal methods – principles of logic

57
Prepared by: Sharif Omar Salem – [email protected] Prepared by: Sharif Omar Salem – [email protected] Formal Methods: Introduction in Logic 1

Transcript of #2 formal methods – principles of logic

Page 1: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

1

Prepared by: Sharif Omar Salem – [email protected]

Formal Methods:Introduction in Logic

Page 2: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

2

Historical ViewSet Theory Symbolic Logic

Truth Tables

This lectute content

Page 3: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

3

Philosophical Logic 500 BC (Before Christ) to 19th Century

Symbolic LogicMid to late 19th Century

Mathematical LogicLate 19th to mid 20th Century

Logic in Computer Science

Historical view

Page 4: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

4

500 B.C – 19th CenturyLogic dealt with arguments in the natural language used

by humans.Example

All men are moral.Socrates is a manTherefore, Socrates is moral.

Historical view -Philosophical Logic

Page 5: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

5

Natural language is very ambiguous.Eric does not believe that Mary can pass any test.I only borrowed your car.Tom hates Jim and he likes Mary.

It led to many paradoxes.“This sentence is a lie.” (The Liar’s Paradox)

Historical view - Philosophical Logic

Page 6: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

6

Mid to late 19th Century.Attempted to formulate logic in terms of a mathematical

languageRules of inference were modeled after various laws for

manipulating algebraic expressions.

Historical view - Symbolic Logic

Page 7: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

7

Late 19th to mid 20th CenturyFrege proposed logic as a language for mathematics in

1879.With the rigor of this new foundation, Cantor was able to

analyze the notion of infinity in ways that were previously impossible. (2N is strictly larger than N)

Russell’s ParadoxT = { S | S S}∉

Historical view - Mathematical Logic

Page 8: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

8

In computer science, we design and study systems through the use of formal languages that can themselves be interpreted by a formal system.Boolean circuitsProgramming languagesDesign Validation and verificationAI, Security. Etc.

Historical view- Logic in Computer Science

Page 9: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

9

Propositional LogicFirst Order LogicHigher Order LogicTheory of ConstructionReal-time Logic, Temporal LogicProcess Algebras Linear Logic

Historical view - Logics in Computer Science

Page 10: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

10

Understanding set theory helps people to …

see things in terms of systems

organize things into groups

begin to understand logic

Set Theory - Why Study Set Theory?

Page 11: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

11

These mathematicians influenced the development of set theory and logic:

Georg Cantor John Venn George Boole Augustus DeMorgan

Set Theory - Key Mathematicians

Page 12: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

12

developed set theoryset theory was not initially accepted

because it was radically differentset theory today is widely accepted and is

used in many areas of mathematics

Set Theory Georg Cantor 1845 -1918

the concept of infinity was expanded by Cantor’s set theoryCantor proved there are “levels of infinity”an infinitude of integers initially ending with or an infinitude of real numbers exist between 1 and 2;there are more real numbers than there are integers…

Page 13: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

13

John Venn 1834-1923studied and taught logic and probability theoryarticulated Boole’s algebra of logicdevised a simple way to diagram set operations

(Venn Diagrams)

Set Theory

George Boole 1815-1864self‑taught mathematician with an interest in logicdeveloped an algebra of logic (Boolean Algebra)featured the operators

andornotnor (exclusive or)

Page 14: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

14

developed two laws of negationinterested, like other

mathematicians, in using mathematics to demonstrate logic

furthered Boole’s work of incorporating logic and mathematics

formally stated the laws of set theory

Set Theory Augustus De Morgan 1806-1871

Page 15: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

15

A set is a collection of elementsAn element is an object contained in a setIf every element of Set A is also contained in Set B, then Set A is

a subset of Set BA is a proper subset of B if B has more elements than A does

The universal set contains all of the elements relevant to a given discussion

Set TheoryBasic Set Theory Definitions

Page 16: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

16

the universal set is a deck of ordinary playing cards

each card is an element in the universal set

some subsets are:face cardsnumbered cardssuitspoker hands

Set Theory Simple Set Example

Page 17: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

17

Symbol Meaning

Upper case designates set nameLower case designates set elements{ } enclose elements in set or is (or is not) an element of is a subset of (includes equal sets) is a proper subset of is not a subset of is a superset of| or : such that (if a condition is true)| | the cardinality of a set

Set Theory Set Theory Notation

Page 18: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

18

a set is a collection of objects

sets can be defined two ways:by listing each elementby defining the rules for membership

Examples:A = {2,4,6,8,10}A = {x | x is a positive even integer <12}

Set Theory Set Notation: Defining Sets

Page 19: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

19

an element is a member of a setnotation: means “is an element of”

means “is not an element of”Examples:

A = {1, 2, 3, 4}

1 A 6 A 2 A z AB = {x | x is an even number 10}

2 B 9 B 4 B z B

Set Theory Set Notation Elements

Page 20: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

20

a subset exists when a set’s members are also contained in another set

notation:

means “is a subset of”

means “is a proper subset of”

means “is not a subset of”

Set Theory Subsets

Page 21: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

21

A = {x | x is a positive integer 8}set A contains: 1, 2, 3, 4, 5, 6, 7, 8

B = {x | x is a positive even integer 10}set B contains: 2, 4, 6, 8

C = {2, 4, 6, 8, 10}set C contains: 2, 4, 6, 8, 10

Subset RelationshipsA A A B A CB A B B B CC A C B C C

Set Theory Subset Relationships

Page 22: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

22

Two sets are equal if and only if they contain precisely the same elements.

The order in which the elements are listed is unimportant.Elements may be repeated in set definitions without increasing

the size of the sets.Examples:

A = {1, 2, 3, 4} B = {1, 4, 2, 3}A B and B A; therefore, A = B and B = A

A = {1, 2, 2, 3, 4, 1, 2} B = {1, 2, 3, 4}A B and B A; therefore, A = B and B = A

Set Theory Set Equality

Page 23: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

23

Cardinality refers to the number of elements in a setA finite set has a countable number of elementsAn infinite set has at least as many elements as the set of

natural numbersnotation: |A| represents the cardinality of Set A

Set Definition CardinalityA = {x | x is a lower case letter} |A| = 26B = {2, 3, 4, 5, 6, 7} |B| = 6A = {1, 2, 3, …} |A| =

Set Theory Cardinality of Sets

0

Page 24: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

24

The universal set is the set of all things pertinent to to a given discussionand is designated by the symbol U

Example:U = {all students at LUCT}Some Subsets:

A = {all Computer Technology students}B = {freshmen students}C = {sophomore students}

Set Theory Universal Sets

Page 25: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

25

Any set that contains no elements is called the empty setthe empty set is a subset of every set including itselfnotation: { } or

Examples ~ both A and B are emptyA = {x | x is a Proton Civic car}B = {x | x is a positive number 0}

Set Theory The Empty Set

Page 26: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

26

The power set is the set of all subsets that can be created from a given set

The cardinality of the power set is 2 to the power of the given set’s cardinality

notation: P (set name)Example:A = {a, b, c} where |A| = 3P (A) = {{a, b}, {a, c}, {b, c}, {a}, {b}, {c}, A, }

and |P (A)| = 8In general, if |A| = n, then |P (A) | = 2n

Set Theory The Power Set ( P )

Page 27: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

27

Z represents the set of integers Z+ is the set of positive integers andZ- is the set of negative integers

N represents the set of natural numbers

ℝ represents the set of real numbers

Q represents the set of rational numbers

Set Theory Special Sets

Page 28: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

28

Venn diagrams show relationships between sets and their elements

Set Theory Venn Diagrams

Page 29: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

29

Set Definition ElementsA = {x | x Z+ and x 8} 1 2 3 4 5 6 7 8B = {x | x Z+; x is even and 10} 2 4 6 8 10

A BB A

Set Theory Venn Diagram Example 1

Page 30: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

30

Set Definition ElementsA = {x | x Z+ and x 9} 1 2 3 4 5 6 7 8 9B = {x | x Z+ ; x is even and 8} 2 4 6 8

A BB AA B

Set Theory Venn Diagram Example 2

Page 31: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

31

Set Definition U = {1, 2, 3, 4, 5, 6, 7, 8}

A = {1, 2, 6, 7}B = {2, 3, 4, 7}C = {4, 5, 6, 7}

Set Theory Venn Diagram Example 4

A = {1, 2, 6, 7}

Page 32: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

32

“A union B” is the set of all elements that are in A, or B, or both.

This is similar to the logical “or” operator.

Set Theory Combining Sets – Set Union

A B

A B

A B

Page 33: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

33

“A intersect B” is the set of all elements that are in both A and B.

This is similar to the logical “and”

Set Theory Combining Sets – Set Intersection

A B

A B

A B

Page 34: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

34

“A complement,” or “not A” is the set of all elements not in A.

The complement operator is similar to the logical not, and is reflexive, that is,

Set Theory Set Complement

A

A A

A A

Page 35: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

35

The set difference “A minus B” is the set of elements that are in A, with those that are in B subtracted out. Another way of putting it is, it is the set of elements that are in A, and not in B, so

Set TheorySet Difference

A B

A B A B

A B A B

Page 36: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

36

Set TheoryExamples

{1,2,3}A {3,4,5,6}B

{3}A B {1,2,3,4,5,6}A B

{1,2,3,4,5,6}

{4,5,6}B A {1,2}B

Page 37: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

37

Set TheorySome test Questions

Page 38: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

38

Set TheorySome test Questions

Page 39: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

39

Set TheorySome test Questions

Page 40: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

40

Symbolic logic is a collection of languages that use symbols to represent facts,

events, and actions,and provide rules to symbolize reasoning.

Given the specification of a system and a collection of desirable properties, both written in logic formulas, we can attempt to prove that these desirable properties are logical consequences of the specification.

Symbolic Logic

Page 41: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

41

Definition of a statement:A statement, also called a proposition, is a sentence that is either true or false, but not both.

Hence the truth value of a statement is T (1) or F (0)

Examples: Which ones are statements?All mathematicians wear sandals.5 is greater than –2.Where do you live?You are a cool person.Anyone who wears sandals is an algebraist.

Symbolic LogicStatement

Page 42: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

42

An example to illustrate how logic really helps us (3 statements written below): All LUCT staff wear Black. Anyone who wears black is an employee. Therefore, all LUCT staff are employees.

Logic is of no help in determining the individual truth of these statements.

Logic helps in concluding fact from another facts (reasoning) However, if the first two statements are true, logic assures the truth of the

third statement.

Logical methods are used in mathematics to prove theorems and in computer science to prove that programs do what they are supposed to do.

Symbolic LogicStatements and Logic

Page 43: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

43

Usually, letters like A, B, C, D, etc. are used to represent statements.

Logical connectives are symbols such as

Λ , V , , , ’Λ represents and, V represents or, represents equivalence,

represents implication, ‘ represents negation.

A statement form or propositional form is an expression made up of statement variables (such as A, B, and C) and logical connectives (such as Λ, V, , )

Example: (A V B) (B Λ C)

Symbolic LogicStatements and Logical Connectives

Page 44: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

44

Connective # 1: Conjunction “AND” (symbol Λ)

Symbol Unicode is 8743If A and B are statement variables, the conjunction of A and B is A Λ B,

which is read “A and B”.A Λ B is true when both A and B are true. A Λ B is false when at least one of A or B is false. A and B are called the conjuncts of A Λ B.

Symbolic LogicDefinitions for Logical Connectives

A B A Λ B

T T T

T F F

F T F

F F F

Page 45: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

45

Connective # 2: Disjunction “OR” (symbol V)

Symbol Unicode is 8744If A and B are statement variables,

the disjunction of A and B is A V B, which is read “A or B”.A V B is true when at least one of A or B is true. A V B is false when both A and B are false.

Symbolic LogicDefinitions for Logical Connectives

A B A V B

T T T

T F T

F T T

F F F

Page 46: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

46

Connective # 3: Implication (symbol )

Symbol Unicode is 8594If A and B are statement variables, the symbolic form of “if A then B” is

A B. This may also be read “A implies B” or “A only if B.”“If A then B” is false when A is true and B is false, and it is true

otherwise. Note: A B is true if A is false, regardless of the truth of B

Symbolic LogicDefinitions for Logical Connectives

A B AB

T T T

T F F

F T T

F F T

Page 47: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

47

Connective # 4: Equivalence (symbol )

Symbol Unicode is 8596 If A and B are statement variables, the symbolic form of “A if, and only if, B”

and is denoted A B. It is true if both A and B have the same truth values. It is false if A and B have opposite truth values. The truth table is as follows:Note: A B is a short form for (A B) Λ (B A)

Symbolic LogicDefinitions for Logical Connectives

A B AB BA (A B) Λ (B A)

T T T T T

T F F T F

F T T F F

F F T T T

Page 48: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

48

Connective #5: Negation (symbol )

Symbol Unicode is 0732If A is a statement variable, the negation of A is “not A” and is denoted

A.It has the opposite truth value from A: if A is true, then A is false; if A

is false, then A is true. Example of a negation:

A: 5 is greater than –2 A : 5 is less than –2B: She likes butter B : She dislikes butter / She hates butter

Sometimes we use the symbol ¬ for negation

Symbolic LogicDefinitions for Logical Connectives

A AT FF T

Page 49: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

49

A truth table is a table that displays the truth values of a statement form which correspond to the different combinations of truth values for the variables.

Symbolic LogicTruth Tables

A AT FF T

A B A Λ B

T T TT F FF T FF F F

A B A V B

T T TT F TF T TF F F

A B ABT T TT F FF T TF F T

A B ABT T TT F FF T FF F T

Page 50: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

50

Combining letters, connectives, and parentheses can generate an expression which is meaningful, called a wff.e.g. (A B) V (B A) is a wff but A )) V B ( C) is not

To reduce the number of parentheses, an order is stipulated in which the connectives can be applied, called the order of precedence, which is as follows:

Connectives within innermost parentheses first and then progress outwardsNegation ()Conjunction (Λ), Disjunction (V)Implication () Equivalence ()

Hence, A V B C is the same as (A V B) C

Symbolic LogicWell Formed Formula (wff)

Page 51: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

51

The truth table for the wff A V B (A V B) shown below. The main connective, according to the rules of precedence, is implication.

Symbolic LogicTruth Tables for some wffs

A B B A V B A V B (A V B)

A V B (A V B)

T T F T T F F

T F T T T F F

F T F F T F T

F F T T F T T

Page 52: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

52

Definition of tautology (VALIDITY): A wff that is intrinsically true, i.e. no matter what the truth value of

the statements that comprise the wff. e.g. It will rain today or it will not rain today ( A V A )P Q where P is A B and Q is A V B

Definition of a contradiction (Unsatisfy): A wff that is intrinsically false, i.e. no matter what the truth value of

the statements that comprise the wff. e.g. It will rain today and it will not rain today ( A Λ A )(A Λ B) Λ A

Usually, tautology is represented by 1 and contradiction by 0

Symbolic LogicTautology and Contradiction

Page 53: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

53

Two statement forms are called logically equivalent if, and only if, they have identical truth values for each possible substitution of statements for their statement variables.

The logical equivalence of statement forms P and Q is denoted by writing P Q or P Q.

Truth table for (A V B) V C A V (B V C)

Symbolic LogicTautological Equivalences

A B C A V B B V C (A V B) V C

A V (B V C)

T T T T T T TT T F T T T TT F T T T T TT F F T F T TF T T T T T TF T F T T T TF F T F T T TF F F F F F F

Page 54: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

54

The equivalences are listed in pairs, hence they are called duals of each other.

One equivalence can be obtained from another by replacing V with Λ and 0 with 1 or vice versa.

Prove the distributive property using truth tables.

Symbolic LogicSome Common Equivalences

Commutative

A V B B V A A Λ B B Λ A

Associative

(A V B) V C A V (B V C)

(A Λ B) Λ C A Λ (B Λ C)

Distributive

A V (B Λ C) (A V B) Λ (A V C)

A Λ (B V C) (A Λ B) V (A Λ C)

Identity A V 0 A A Λ 1 A

Complement

A V A 1 A Λ A 0

Page 55: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

55

1. (A V B) A Λ B

2. (A Λ B) A V B

Symbolic LogicDe Morgan’s Laws

A B A B A V B (A V B)

A Λ B

T T F F T F FT F F T T F FF T T F T F FF F T T F T T

Page 56: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

56

Prepared by: Sharif Omar Salem – [email protected]

End of Lecture

Page 57: #2 formal methods – principles of logic

Prep

ared

by:

Sha

rif

Om

ar S

alem

– s

sale

mg@

gmai

l.com

57

Prepared by: Sharif Omar Salem – [email protected]

Next LecturePropositional Logic