#2 formal methods-principles of logic.
These slides are part of a formal class notes prepared for the module "Formal Methods" taught for the students of Software engineering.
5. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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)
4
6. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Mid to late 19th Century.
Attempted to formulate logic in terms of a mathematical
language
Rules of inference were modeled after various laws for
manipulating algebraic expressions.
5
7. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Late 19th to mid 20th Century
Frege 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 Paradox
T = { S | S ∉ S}
6
8. Preparedby:SharifOmarSalem–ssalemg@gmail.com
In computer science, we design and study systems
through the use of formal languages that can
themselves be interpreted by a formal system.
Boolean circuits
Programming languages
Design Validation and verification
AI, Security. Etc.
7
12. Preparedby:SharifOmarSalem–ssalemg@gmail.com
developed set theory
set theory was not initially accepted
because it was radically different
set theory today is widely accepted and is
used in many areas of mathematics
11
the concept of infinity was expanded by Cantor’s set theory
Cantor 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…
13. Preparedby:SharifOmarSalem–ssalemg@gmail.com
John Venn 1834-1923
studied and taught logic and probability theory
articulated Boole’s algebra of logic
devised a simple way to diagram set operations
(Venn Diagrams)
12
George Boole 1815-1864
self-taught mathematician with an interest in logic
developed an algebra of logic (Boolean Algebra)
featured the operators
and
or
not
nor (exclusive or)
14. Preparedby:SharifOmarSalem–ssalemg@gmail.com
developed two laws of negation
interested, 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
13
15. Preparedby:SharifOmarSalem–ssalemg@gmail.com
A set is a collection of elements
An element is an object contained in a set
If every element of Set A is also contained in Set B, then Set A is a
subset of Set B
A 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
14
17. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Symbol Meaning
Upper case designates set name
Lower 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
16
18. Preparedby:SharifOmarSalem–ssalemg@gmail.com
a set is a collection of objects
sets can be defined two ways:
by listing each element
by defining the rules for membership
Examples:
A = {2,4,6,8,10}
A = {x | x is a positive even integer <12}
17
19. Preparedby:SharifOmarSalem–ssalemg@gmail.com
an element is a member of a set
notation: means “is an element of”
means “is not an element of”
Examples:
A = {1, 2, 3, 4}
1 A 6 A
2 A z A
B = {x | x is an even number 10}
2 B 9 B
4 B z B
18
21. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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 Relationships
A A A B A C
B A B B B C
C A C B C C
20
22. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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
21
23. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Cardinality refers to the number of elements in a set
A finite set has a countable number of elements
An infinite set has at least as many elements as the set of natural
numbers
notation: |A| represents the cardinality of Set A
Set Definition Cardinality
A = {x | x is a lower case letter} |A| = 26
B = {2, 3, 4, 5, 6, 7} |B| = 6
A = {1, 2, 3, …} |A| =
22
24. Preparedby:SharifOmarSalem–ssalemg@gmail.com
The universal set is the set of all things pertinent to to a
given discussion
and 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}
23
25. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Any set that contains no elements is called the empty set
the empty set is a subset of every set including itself
notation: { } or
Examples ~ both A and B are empty
A = {x | x is a Proton Civic car}
B = {x | x is a positive number 0}
24
26. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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| = 3
P (A) = {{a, b}, {a, c}, {b, c}, {a}, {b}, {c}, A, }
and |P (A)| = 8
In general, if |A| = n, then |P (A) | = 2n
25
27. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Z represents the set of integers
Z+ is the set of positive integers and
Z- 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
26
35. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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
A B A B Ç
34
40. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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.
39
41. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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.
40
42. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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.
41
43. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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)
42
44. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Connective # 1:
Conjunction “AND” (symbol Λ)
Symbol Unicode is 8743
If 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.
43
A B AΛ B
T T T
T F F
F T F
F F F
45. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Connective # 2:
Disjunction “OR” (symbol V)
Symbol Unicode is 8744
If 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.
44
A B A V B
T T T
T F T
F T T
F F F
46. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Connective # 3:
Implication (symbol )
Symbol Unicode is 8594
If 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
45
A B AB
T T T
T F F
F T T
F F T
47. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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)
46
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
48. Preparedby:SharifOmarSalem–ssalemg@gmail.com
Connective #5:
Negation (symbol )
Symbol Unicode is 0732
If 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 –2
B: She likes butter
B : She dislikes butter / She hates butter
Sometimes we use the symbol ¬ for negation
47
A A
T F
F T
49. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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.
48
A A
T F
F T
A B AΛ B
T T T
T F F
F T F
F F F
A B A V B
T T T
T F T
F T T
F F F
A B AB
T T T
T F F
F T T
F F T
A B AB
T T T
T F F
F T F
F F T
50. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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
outwards
Negation ()
Conjunction (Λ), Disjunction (V)
Implication ()
Equivalence ()
Hence, A V B C is the same as (A V B) C
49
51. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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.
50
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
52. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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
51
53. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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)
52
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 T
T T F T T T T
T F T T T T T
T F F T F T T
F T T T T T T
F T F T T T T
F F T F T T T
F F F F F F F
54. Preparedby:SharifOmarSalem–ssalemg@gmail.com
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.
53
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