MM CHAPTER 1 Advanced LOGIC Landscape
MM CHAPTER 1 Advanced LOGIC Landscape
With Courtesy of FCSE- HCMUT’s former colleagues Tan V. Tran, Nguyen T. Huynh
Contents
LOGIC THEORY
The text provides the mathematical foundations for many CS areas, e.g.,
algorithm analysis & design, artificial intelligence (AI),
data analytics [interacting with AI and Statistics, Traffic Engineering],
process analytics [interacting with Smart Manufacturing], etc.
Applications of Logic, Discrete Modeling & Optimization in CSE will be highlighted.
The next part of this text introduces CSE students to automata and formal language, then
the basic concepts of logic (e.g., theories, models, logical consequence, and proof) together
with application in theoretically software verification.
In the third part, students will be learned mathematical modeling through integer optimiza-
tion, particularly integer linear programming (ILP).
Finally, to see connection with newly developed areas/ fields we learn stochastic program-
ming, dynamical systems, and Petri net (extra reading).
1
ACM: Association for Computing Machinery
3. REF 3.
Chapters 1-5 in Matousek et al. Understanding and using linear programming, Springer,
2007.
Chapters 1-4 in R.J. Vanderbei, Linear programming, 3rd edition, Springer 2001.
Chapters I2 in G.L. Nemhauser, L. A. Wolsey, Integer and Combinatorial Optimization,
2nd ed., Wiley, 1999.
Chapters 1-4 in Boyd, Stephen, Stephen P. Boyd, and Lieven Vandenberghe. Convex
optimization. Cambridge University
Chapter 7 in F.R. Giordano, W.P. Fox & S.B. Horton, A First Course in Mathematical
Modeling, 5th ed., Cengage Press, 2004."
4. REF 4. Chapters 1, 11, 12 7 in F.R. Giordano, W.P. Fox & S.B. Horton, A First Course in
Mathematical Modeling, 5th ed., Cengage Press, 2004."
5. REF 5. TBA
The laws of logic are employed in the design of the digital circuitry in a computer.
Logical expressions occur as conditions in the control structures in algorithms and computer
programs, and in the commands used for querying databases.
Expert systems and AI tech employing knowledge-based software use rules of logical
inference to draw conclusions from known facts.
LOGIC THEORY- The Blueprint
PART I. and II: Propositional Logic, Advanced Propositional Logic, Section 1.1 and 1.2
PART III. Predicate Logic, in Section 1.3
PART IV (1.4)- ADVANCED LOGIC THEORY with APPLICATION includes
1. Advanced Predicate Logic - Logic for Program Verification, see part 1.5
2. Hoare Triples - Practical Aspects of Correctness Proofs, see part 1.7. ⌅
The fundamental objects we worked in Discrete Structure course are set, graph, and in
arithmetic are numbers. Similarly, the fundamental objects in logic are propositions.
Definition 1.1
|
A proposition is a statement that is either true or false. Whichever of these (true or false)
is the case is called the truth value of the proposition.
The first and third of these propositions are true, and the second and fourth are false. Is
the last truly proposition? It is not known at present whether the fifth proposition is true or
false.
In this case, however, the truth value of the statement is determined when the line is exe-
cuted while the program is being run with a particular set of inputs,
so statements of this type can be treated as propositions.
1.1.2 Connectives
Logic is not concerned with determining the truth values of propositions from specific appli-
cation information.
(E.g., the truth value of ‘Canberra is the capital of Australia’
is a question of geography, not logic.)
The sentence about Brian and Angela is an example of a compound proposition. It is built
These words are known as connectives. As we will see, the role of connectives in logic is
analogous to the role played by operations such as + and ⇥ in algebra.
Atomic propositions.
The study of the structure of compound propositions is made easier by the use of symbols
for atomic propositions and connectives.
Connective Symbol
and ^
or _
not ¬
if-then !
if-and-only-if $
Table 1.1: Connectives and associated symbols
With the exception of not, the symbols for these connectives are written between the two
operands (the propositions they connect).
T F F
F T F
F F F
We now have the notation we need in order to be able to write compound propositions in
symbolic form. Below example shows how this is done.
⌥ EXAMPLE 1.2. Construct the truth table for the expression (p ^ ¬q) _ q .
Truth table for an expression: Notice that each column is obtained using the truth table
for the principal connective in the expression at the top of the column.
If an expression contains three variables (p, q and r , say), then the table will have eight
lines instead of four (there are 23 = 8 different ways of allocating truth values to three
expressions), but the method is the same.
1.1.4 Tautology
⌥ EXAMPLE 1.3. Look back the proposition we introduced at the beginning of this section
a/ Write this compound proposition in symbolic form and b/ provide its truth table.
Definition 1.3
(A) An expression that is always true, regardless of the truth values of the variables it
(B) An expression that is always false, regardless of the truth values of the variables it
the form ^¬ or ¬ ^
(C) Logical equivalence: Two expressions (composed of the same variables) are logically
equivalent if they have the same truth values for every combination of the truth values of the
variables. Formally, A(p, q, r, ...) is logically equivalent to B(p, q, r, ...), write
if we have A(p, q, ...) = B(p, q, ...) for every choice of boolean values of p, q, ...
⌥ EXAMPLE 1.4. Can you write English sentences for the converse and the contrapositive of
(A ! B) ^ (B ! A).
MATHEMATICAL MODELING Methods and Application
1.1. PROPOSITIONAL LOGIC 16
We will use the symbol ⌘ or , placed between two expressions to indicate that they are
equivalent. A statement of the form
P ⌘Q
or
P ,Q
QUIZ
1. Converse and contrapositive. (5 min) Prove that
p ! q is not logically equivalent to its converse, but that it is logically equivalent to its
contrapositive. That is
p ! q ⌘ ¬q ! ¬p
p _ ¬(¬p ! q)
REMINDER: There are two truth values, T and F, denoted for truth and falsity.
The meaning of logical connectives: The propositional connectives are:
negation (¬ ),
conjunction ^
disjunction _
implication ! or )
biimplication ,
and be read as
“not”,
“and”,
“or”,
“if-then”,
“if and only if” respectively.
The meaning of logical connectives
¬ r: the negation of r
p ^ q : the conjunction of p and q
p _ q: ?
p ! q : the implication of q by p
a ) b: the logical implication of b by a
p $ q : equivalence
p $ q means:
“p is necessary and sufficient for q ”.
“if p then q , and conversely”.
“p (if-and-only-if) iff q ”.
The connectives ^, _, ), , are designated as binary,
while ¬ is designated as unary.
Practice- Translating Natural Sentences
Summary of PART I
Let p, q be arbitrary statements. We distinguish few cases:
The relationship between ! and )
p ! q : the implication of q by p, or p implies q
p ) q : logical implication, p logically implies q .
We understand that: if p ! q is a tautology, then we say
p logically implies q , and write p ) q .
‘The file is either a binary file or a text file. If it is a binary file then my program won’t accept
it. My program will accept the file. Therefore the file is a text file.’
2. Translating Natural Sentences.
He will not run the red light if he sees the police unless he is too risky.
3. System specifications
“When a user clicked on Help button, a pop-up will be shown up”
4. Logic puzzles
There are two kinds of inhabitants on an island, knights, who always tell the
truth, and their opposites, knaves, who always lie.
You encounter two people A and B .
What are A and B if A says “B is a knight” and B says ”The two of us are opposite
types”?
Hints for PRACTICE
An argument of this type consists of some premises (in this example, the first three sen-
tences), which together are supposed to imply the conclusion (the last sentence). The argu-
ment takes the form of the logical expression:
(P1 ^ P2 ^ P3) ! Q
[[GoogleMap]]
Keys:
IIA. REMINDER on Logic Laws
IIB. Propositional Logic as a Formal Language
IIC. Soundness and Completeness of Propositional Logic
IID. Proof theory of Propositional Logic
1.2. Advanced Propositional Logic 28
1 ^ 2 ^ ... ^ n !
1, 2, . . . , n !
p!q
¬q
— ———
) ¬p
Quiz: Use Modus Tollens to prove the follwing scheme
p!r
r!s
t _ ¬s
¬t _ u for any propositions p, r, s, t, u
¬u
— ———
) ¬p
IV: Rule of Disjunctive Syllogism says [(p _ q) ^ ¬p] ! q.
This is derived from Modus Ponens and the logical equivalence p ! q , ¬p _ q or
p _ q , ¬p ! q
p_q
¬p
— ———
) q
This rule of inference arises when there are exactly two possibilities to consider, and we can
eliminate one of them as being true, i.e. it is false. Then the other possibility must be true.
V: Rule of Contradiction
(¬p ! F0) ! p
is a tautology! This called the Rule of Contradiction, written as:
¬p ! F0
— ———
) p
The Rule of Contradiction is a key method of establishing the validity of an argument, the
method Proof by Contradiction. Moreover we may employ this to prove
(p1 ^ p2 ^ . . . ^ pn) ! q
then we can form the validity of the argument
(p1 ^ p2 ^ . . . ^ pn) ^ ¬q ! F0 W HY ?
In natural deduction, we have a collection of laws of logic or proof rules. They allow us to
infer formulas (i.e. logical expressions)
from other simple or given formulas, called premises;
then eventually we may infer a conclusion from a set of premises.
1, 2, . . . , n (premises) ` (conclusion)
The well-formed formulas of propositional logic are those which we obtain by using the
construction rules below, and only those finitely many times:
Atom: every propositional atom p, q, r, . . .; and p1 , p2 , . . . is a well-formed formula.
¬: if is a well-formed formula then so is (¬ )
^: if and are well-formed formulas, then so is ( ^ )
_: if and are well-formed formulas, then so is ( _ )
!: if and are well-formed formulas, then so is ( ! )
We define a propositional language L is a set of propositional atoms p, q, r, ....
Note that if L has exactly n atoms then there are exactly 2n different L- assignments.
Lemma 1.1
~
Definition 1.7
|
! ⌘ True
S= ! ,
In other words, [ and are provably equivalent iff , (also write ⌘ )]. |
1, 2, . . . , n (premises) ) (conclusion)
1, 2, . . . , n )
1, 2, . . . , n (premises) ✏
holds. ~
1, 2, . . . , n (premises) ✏ ,
1, 2, . . . , n ) ?
We show that the provable implications of Propositional Logic is complete, i.e: whenever
1, 2, . . . , n (premises) ✏
1, 2, . . . , n )
being valid (i.e. you have to find a proof for the implication
1, 2, . . . , n ! ).
1, 2, . . . , n ✏
1, 2, . . . , n )
is valid. ~
In other words, propositional formulas are recursively defined, in Backus Naur form,
as:
L ::= p | ¬p
D ::= L | L _ D
C ::= D | D ^ C.
Example
(¬q _ p _ r) ^ (¬p _ r) ^ q
Lemma 1.2
A disjunction of literals L1 _ L2 . . . Lm is valid iff there are 1 i, j m such that Li is
¬Lj . ~
[[GoogleMap]]
1.3. Predicate Logic- A Primer 43
Warming up
Propositional logic dealt quite well and satisfactorily with sentence components like
not
and
or, and
if ... then
but the logical aspects of natural and artificial languages are richer than that!
We have seen modifiers like
there exist ...,
all ... ,
among ... and only ...
and now develop a theory for using them.
To write predicates and quantifiers symbolically,
we will use capital letters to denote predicates.
There are several ways to express the notions of always true and sometimes true in
English.
The expressions ‘for all’ 8 and ‘there exists’ 9 are called quantifiers.
8 n, P (n) is true
or P (n) is true for every n x2 0 for every x
I) What is the truth value of the quantification 8xP (x), where the domain consists of all real
number?
8x [ p(x) ! q(x) ].
8x 2 U [ p(x) , q(x) ]. |
⌥ EXAMPLE 1.7. Express the statement “Some student in this class comes from Central
Vietnam.”
Solutions
1/ M (x) = x comes from Central Vietnam
Domain for x is the students in the class . The answer is 9xM (x)
2/ Domain for x is all people . . .
⌥ EXAMPLE 1.8. Consider a declarative sentence: Every student is younger than some
instructor.
S(x) : x is a student
I(x) : x is an instructor
(Two-variable) predicate Y (x, y) : x is younger than y
We need two quantifiers 8 and 9 to write the above example entirely symbolic way
PRACTICE 1.2.
Fact 1.1 (Logic equivalences and implications for quantified statements in one variable ).
For a prescribed universe and any open statements p(x), q(x), we have
9x [p(x) ^ q(x)] ) [9x p(x) ^ 9x q(x)]
(here only one way =), the x must be the same).
9x [p(x) _ q(x)] , [9x p(x) _ 9x q(x)]
8x [p(x) ^ q(x)] , [8x p(x) ^ 8x q(x)] (here the x must be taken in the same domain).
C/ Two useful binary predicates We often use two useful binary predicates below.
Equality = : a special predicate, a binary one but usually written in between of its
arguments:
x=y instead of = (x, y)
Definition 1.13
A variable which has been quantified is said to be bound.
⌥ EXAMPLE 1.10. Let’s look at an English sentence ‘Every girl is younger than her
mother’.
⌥ EXAMPLE 1.11. Let’s return to a confusing statement: Every American has a dream.
This sentence is ambiguous because the order of quantifiers is unclear. WHY?
Let A be the set of Americans, let D be the set of dreams, and define the predicate
9d 2 D : 9a 2 A : H(a, d)
or (II) every American has an individual dream: 8a 2 A, 9d 2 D : H(a, d).
In the specification of a system for booking theatre seats, B(p, s) denotes the predicate
“person p has booked seat s.”
Write the following sentences in symbolic form:
1. Seat s has been booked.
2. Person p has booked a (that is, at least one) seat.
3. All the seats are booked.
4. No seat is booked by more than one person.
—————————————–
D/ Predicate logic- Quantifiers with many variables
E/ Order of quantifiers is important .
HINT: Let P (x), Q(x) and R(x) be the statements “x is a lion”, “x is fierce” and “x drinks
coffee”, respectively.
provided that:
C(x): x has a computer,
F (x, y): x and y are friends,
x, y 2 all students in your school.
3. For each of the logical formulas, indicate whether or not it is true when the domain of
discourse is N (the natural numbers 0, 1, 2, . . . ), Z (the integers), Q (the rationals), R (the
real numbers), and C (the complex numbers).
9x (x2 = 2)
8x 9y(x2 = y)
8y 9x(x2 = y)
8x 6= 0 9y(xy = 1)
9x 9y : (x + 2y = 2) ^ (2x + 4y = 5)
Definition 1.14
A predicate vocabulary consists of 3 sets:
We view constants are nullary functions (don’t take any argument), so can view C ⇢ F .
2
such as a= Andy, p= Paul ...
t ::= x | c | f (t, . . . , t)
where x 2 Var a set of variables, c 2 F a nullary, and f 2 F with arity n > 0.
The choice of sets P and F is driven by what we intend to describe.
⌥ EXAMPLE 1.13.
t1, t2, . . . , tn are terms over F , then P (t1, t2, . . . , tn) is a formula. |
Furthermore,
If is a formula then so is (¬ ).
If and are formulas, then so are ( ^ ), ( _ ) and ( ! ).
If is a formula and x is a variable, then (8x ) and (9x ) are formulas.
Nothing else is a formula.
We summarize the definition with the above components in the following recursion
RULES:
1. Leaves are atomic propositions, and internal nodes are operations ¬, ^, _, !.
2. We employ the binding priorities for logic connectives:
[((¬p) ^ q) ! (p ^ (q _ (¬r)))]
PRACTICE 1.5.
2. predicate expressions, which are generally of the form P (t1 , t2 , . . . , tn ), [Definition 1.16]
have the symbol P as a node, but now P has n many subtrees,
i.e. the parse trees of the terms t1 , t2 , . . . , tn .
ANSWER
8x
! S
P Q x y
x x
PRACTICE 1.6.
8x Q(x)
is true?
Method 1: replacing x by any of its possible values and checking that Q holds for each one
of them [very inefficient!]
Method 2: Use proof rules (see Section 1.4.1 Proof Theory of Predicate Logic)
Need the concepts of Free and Bound variables to solve these!
tree:
Type 1: they appear next to quantifiers 8 and 9: such nodes always have one subtree,
determining their scope to which the respective quantifier applies.
Type 2: they form leaf nodes: variables stand for values that still have to be made concrete.
Observe any leaf node, there are two key occurrences:
⌥ EXAMPLE 1.15.
MATHEMATICAL MODELING Methods and Application
1.3. Predicate Logic- A Primer 71
Definition 1.17
Let be a formula in predicate logic. |
⌥ EXAMPLE 1.16. From the figure could you recover a predicate formula?
PRACTICE 1.7.
A) Could you substitute occurrences of variable x in the tree T1 by a term f (x, y)?
B) Could you substitute occurrences of variable x in the above parse tree T2 of the formula
[8x(P (x) ^ Q(x))] ! [¬P (x) _ Q(y)] by a term f (x, y)?
ANSWER [x ) f (x, y)] ((8x(P (x) ^ Q(x))) ! (¬P (x) _ Q(y)))
= (8x(P (x) ^ Q(x))) ! (¬P (f (x, y)) _ Q(y))
8x _
^ ¬ Q
P Q P y
x x f
x y
When substitution allowed?
To avoid changing action that gives wrong specification of other variable y 6= x in parse
trees, we can replace some term t into x only the term t satisfying the following.
Definition 1.19 (Freeness and boundness of a variable)
|
Fact 1.2. We so can employ the followings, with any predicate (formula) and .
¬8x a` 9x¬
¬9x a` 8x¬
9x9y a` 9y9x
8x ^ a` 8x( ^ )
9x( ! ) a` ! 9x
———————————————————————————
The Essence
Syntax: We formalized in Section 1.3 the language of predicate logic, including substitution.
Proof theory: We next extend natural deduction from propositional to predicate logic
Semantics: We then describe models in which predicates, functions, and formulas have
meaning.
Further topics: Soundness/completeness
The remaining parts of Section 1.4 include:
Proof Theory of Predicate Logic
The concept of model
Satisfaction Relation
Soundness and Completeness
(See extra info in REF. 4: Lecture DM2- Chapter 2e, 2f. )
We discuss
Natural Deduction Rules
Quantifier Equivalences
=i
t=t
or more general, Equality rule = e
t1 = t2 [t1/x]
=e
[t2/x]
⌥ EXAMPLE 1.17 (Identical rule and Equality rule).
We show:
f (x) = g(x) ` h(g(x)) = h(f (x))
MATHEMATICAL MODELING Methods and Application
1.4. Advanced Predicate Logic 86
using
t1 = t2 [x ) t1]
[= i] and [= e]
t=t [x ) t2]
8x 8x
8x e () [8x e]
[t/x] [x ) t]
In formula we may replace [t/x] by [x ) t] , and think of the term t as a more concrete
instance of x, where x is general term.
Reuse notion of M, F . . . in Example 1.14, with the unary function m(x) : mother of x, we
then prove the logic claim
h i
F (m(Duong)), 8x(F (x) ! ¬M (x)) ` ¬M (m(Duong))
1 F (m(Duong)) premise
2 8x(F (x) ! ¬M (x)) premise
3 F (m(Duong)) ! ¬M (m(Duong)) 8x e 2
4 ¬M (m(Duong)) ! e 3,1
' $
x0
..
.
[x ) x0]
& %
[8x i]
8x
' $
x0
..
.
[x ) x0]
& %
[8x i]
8x
3 x0 P (x0 ) ! Q(x0 ) 8x e 1
4 P (x0) 8x e 2
5 Q(x0) ! e 3,4
6 8x Q(x) 8x i 3–5
p
1. Built-in Rules
p
2. Universal quantification
3. Existential Quantification: two rules 9x i and 9 e:
[x ) t]
[9x i]
9x
' $
x0 [x ) x0]
..
9x .
& %
[9 e]
h i
8x(P (x) ! Q(x)), 9xP (x) ` 9x Q(x)
3 x0 P (x0 ) assumption
4 P (x0) ! Q(x0) 8x e 1
5 Q(x0) ! e 4,3
6 9xQ(x) 9x i 5
7 9xQ(x) ⌘ 9x e 2,3–6
Definition 1.20
Fact 1.3.
PRACTICE 1.8. How could we represent the sentence: Not all birds can fly.
Step 1: Represent the claim p = All birds can fly by predicate logic
Step 2: Apply negation operator to p to get ¬ p. ⌅
HINT: we could exploit the next theorem.
Quantifier Equivalence
Theorem 1.3
Let and be formulas of predicate logic. Then we have the following equivalences: ~
1.
¬8x a` 9x ¬
2.
¬9x a` 8x ¬
3.
a/ 8x ^ 8x a` 8x ( ^ )
b/ 9x _ 9x a` 9x ( _ )
1.4.2 Model
Let F = {e, ·} and P = {}. Let model M for (F, P) be defined as follows:
1. Let A be the set of binary strings over the alphabet {0, 1}, so A = {0, 1}⇤ ;
2. let eM = ✏, the empty string;
3. let ·M be defined such that s1 ·M s2 is the concatenation of the strings s1 and s2 ; and
4. let M be defined such that s1 M s2 iff s1 is a prefix of s2 .
Specific choices for elements of A, as 10001,
1010 ·M 1100 ? = 10101100
000 ·M ✏ ? = 000.
Usually, we require that the equality predicate = is interpreted as sameness.
Extensionality restriction means that allowable models are restricted to those
MATHEMATICAL MODELING Methods and Application
1.4. Advanced Predicate Logic 95
in which a =M b holds if and only if a and b are the same elements of the model’s universe
A. E.g., equality in M is 000 =M 000; but 001 6=M 100 .
⌥ EXAMPLE 1.22.
| OBSERVATION 2. Generally, fix model M, let predicate P 2 P has arbitrary arity n then
l : var ! A.
The last observation (⌥) is viewed in the multivariate case that, for arity n 1
l
evaluating (x1 , x2 , . . . , xn ) ! (a1 , a2 , . . . , an ) implies that P (a1 , a2 , . . . , an ) is true.
⌥ EXAMPLE 1.23.
1. Entailment: |=
if and only if (iff) for all models M [Definition 1.21] and environments l,
whenever M |=l holds for all 2 , then M |=l .
2. Satisfiability of Formula: formula is satisfiable
iff there is some model M and some environment l such that M |=l holds.
3. Satisfiability of Formula Sets: The whole set is satisfiable
iff there is some model M and some environment l such that M |=l , for all 2 .
4. Validity: Formula is valid iff for all models M and environments l, we have M |=l .
1, 2, . . . , n |=
requires that in all models that satisfy 1, 2, . . . , n, the sentence is satisfied.
Central Result of Natural Deduction (Kurt Gödel, 1929 in his doctoral dissertation.)
1, . . . , n |= iff 1, . . . , n `
[The ` is viewed in Definition 1.20, the entailment |= is treated in Definition 1.23.]
We continue in predicate logic with some negative results.
We now show that this problem is not solvable, using a well-known technique called prob-
lem reduction. That is, we take some other problem, of which we already know that it is not
solvable, and we then show that the solvability of our problem entails the solvability of the
other one.
Definition 1.24
Relevant concepts of Decidability include the followings.
1. Decision problem
2. Decidability:
and that returns “no” whenever the answer to the problem is “no”,
3. Decidability of satisfiability
n 1 such that the concatenations si1 si2 . . . sin and ti1 ti2 . . . tin are equal?
Turing machines: Basic abstract symbol-manipulating devices that can simulate in prinicple
any computer algorithm [having seen in Chapter 2 of Automata].
The input is a string of symbols on a tape, and
the machine “accepts” the input string, if it reaches one of a number of accepting states.
Termination of Programs is Undecidable, whether program with input terminates.
Proof idea: For a Turing machine with a given input, construct a PCP such that a solution
of the PCP exists if and only if the Turing machine accepts the solution.
Proof:
1. Bits as Functions Represent bits 0 and 1 by functions f0 and f1 .
2. Strings as Terms Represent the empty string by a constant e.
The string b1 b2 . . . bl corresponds to the term fbl (fbl 1
. . . (fb2 (fb1 (e))) . . .)
3. Formula P (s, t): from in sequence of pairs (s1 , t1 ), (s2 , t2 ), . . . , (sk , tk ), let C be the PCP
s 1 s 2 . . . sk
problem
t 1 t 2 . . . tk .
P (s, t) then holds iff 9 (i1, i2, . . . , im) of indices such that s = si1 si2 . . . sim and t =
k
^
1 = P (fsi (e), fti (e))
i=1
k
^
2 = 8v8w(P (v, w) ! P (fsi (v), fti (w)))
i=1
3 = 9zP (z, z)
Undecidability of Predicate Logic- SUMMARY
Post correspondence problem is undecidable.
Constructed formula C for Post correspondence problem C .
CLAIM: |= C holds if and only if C has a solution.
Proof via construction of C. Formally construct an interpretation of strings and show that
whenever there is a solution, the formula C holds and vice versa.
If all finite subsets of are satisfiable, then is satisfiable. [See Item 3 of Definition 1.23.]
Homework: You should do as much as you can ALL marked exercises in [2, Sect. 2.8]
(notice that sample solutions for these exercises are available in [3]).
[3]: Michael Huth and Mark Ryan. Logic in Computer Science: Solutions
For this lecture, the following are recommended exercises [2]:
2.1: 1a); 2a)
2.2: 6
2.3: 1a); 1b); 6a); 6b); 6c); 7b); 9b); 9c); 13d)
2.4: 2); 3); 11a); 11c); 12e); 12f); 12h); 12k)
2.5: 1c); 1e).
WHAT NEXT?
[[GoogleMap]]
1.5. Logic for Program Verification 110
a) Are there expressions in Predicate Logic that do not evaluate to TRUE or FALSE? An
example?
Ans.: Yes! Terms, unlike predicates and formulas, do not evaluate to the distinguished symbols
true or false. Examples of terms include: a, a constant (or 0-ary function);
x, a variable; f (t), a unary function f applied to a term t.
b) How do you represent a propositional variable in a Predicate Logic formula?
Ans.: As a 0-ary predicate.
c) Fermat’s Last Theorem in number theory says that:
It is impossible to separate any power higher than the second into two like powers.
Or, more precisely: ‘If an integer n is greater than 2,
then the equation xn + y n = z n has no solutions in positive integers x, y, and z.’
Formulate the above statement in Predicate Logic with Equality? DIY
An answer to Fermat’s Last Theorem Formulation:
h
8n.integer(n) ^ n > 2 =) 8x, y, z.integer(x) ^ integer(y) ^ integer(z)
i
^ x > 0 ^ y > 0 ^ z > 0 ! xn + y n 6= z n .
| OBSERVATION 3.
As a first step towards determining whether an implementation (such as that in the function
Definition 1.25
A precondition specifies what should be true upon entering the function,
The post-condition relates the function’s output (the rv ) to its input (the parameters).
| QUESTION.
They are
First precondition: 0 l ^ u < |a|
Second precondition:
8i, j. integer(i) ^ integer(j) ^ 0 i j < |a| ! a[i] a[j]
Postcondition: rv ! 9 i : l i u ^ a[i] = e
Brief Program Verification: We need to verify the correctness of computer systems (hard-
ware, software, or a combination). This is most obvious in the case of
safety-critical systems (i.e., petroleum exploration), and also
commercially critical (as industrial manufacturing).
later.
Time-to-market: verifying programs with respect to formal specifications can significantly
cut down the duration of software development and maintenance
Certification - warranty: verification is required in safety-critical domains 3 .
Broad Approaches to verification can be classified according to the following criteria:
a) Proof-based checking vs. b) Model-based (model checking)
DISCUSSION
Production of a software, targeting to management projects, such as
a) Providing nationally truthful COVID19-related fluctuation, in Health Economics,
b) Providing Airline booking service, in Travel- Hospitality industry.
1. Arithmetic expressions E :
E ::= n | x | ( E) | (E + E) | (E E) | (E ⇤ E)
2. Boolean expressions B :
where the braces { and } are to mark the extent of the blocks of code in the if-statement
and the while-statement, as in languages such as C and Java.
The atomic command x = E is the usual assignment statement; it evaluates the integer
expression E in the current state of the store and then overwrites the current value stored in
x with the result of that evaluation.
| QUESTION.
What syntax should we use for R, the formal specifications of requirements for such pro-
grams? We need to be able to talk not just about the state after the program executes,
but also about the state before it executes.
(| |) P (| |)
Pre-conditions:
Post-conditions:
Informal meaning: If the program P is run in a state that satisfies , then the state resulting
from P ’s execution will satisfy . We may informally say that:
An assertion of the form (| |) P (| |) is called a Hoare triple.
is called the precondition, is called the postcondition.
⌥ EXAMPLE 1.25.
Informal specification:
Given a positive number x, the program P calculates a number y whose square is less than
x.
MATHEMATICAL MODELING Methods and Application
1.6. Hoare Triples - Partial and Total Correctness 122
Assertion
(|x > 0|) P (|y · y < x|)
Definition 1.26
⌥ EXAMPLE 1.26.
MATHEMATICAL MODELING Methods and Application
1.6. Hoare Triples - Partial and Total Correctness 125
Let l(x) = 2, l(y) = 5 and l(z) = 1. Let model M have the universe Z, we have:
l |= ¬(x + y < z)
l 6|= y = x · z < z
l 6|= 8u (y < u ! y · z < u · z)
`par (| |) P (| |)
where
|=par (| |) P (| |) holds whenever `par (| |) P (| |) (correctness), and
`par (| |) P (| |) holds whenever |=par (| |) P (| |) (completeness).
[Read = phi, = psi, ⌘ = eta...]
Rules for Partial Correctness
(| |) C1 (|⌘|) (|⌘|) C2 (| |)
(1) [Composition];
(| |) C1; C2 (| |)
(2) [Assignment];
(|[x ! E] |) x = E (| |)
(| ^ B|) C1 (| |) (| ^ ¬B|) C2 (| |)
(3) [If-statement];
(| |) if B { C1 } else { C2 } (| |)
(| ^ B|) C (| |)
(4) [Partial-while]; and
(| |) while B { C } (| ^ ¬B|)
0 0
`AR ! (| |) C (| |) `AR !
(5) [Implied].
0 0
(| |) C (| |)
0
Rule Implied: a sequent `AR ! is valid iff there is a proof of in the natural deduction
0
calculus for predicate logic, where and standard laws of arithmetic are premises.
Note that the rule Implied allows the precondition to be strengthened (we assume more
than we need to), while the postcondition is weakened (i.e. we conclude less than we are
entitled to).
The rule Implied acts as a link between program logic and a suitable extension of predi-
cate logic. It allows us to import proofs in predicate logic [enlarged with the basic facts of
arithmetic, which are required for reasoning about integer expressions], into the proofs in
program logic.
0 0
`AR ! (| |) C (| |) `AR !
(5) [Implied].
0 0
(| |) C (| |)
Proofs have tree shape: All rules have the structure below, named Proof Tableaux
something
something else
As a result, all proofs can be written as a tree.
These trees, however, tend to be very wide when written out on paper.
Thus we are using a linear format, called proof tableaux, providing 2 patterns.
I) Interleave Formulas with Code:
(| |) C1 (|⌘|) (|⌘|) C2 (| |)
[Composition]
(| |) C1; C2 (| |)
Shape of rule suggests format for proof of series of programs C1 ; C2 ; . . . ; Cn :
(| 0|)
C1 ;
(| 1|) justification
C2 ;
..
.
(| n 1 |) justification
Cn ;
(| n |) justification
II) Working Backwards: Need to find a proof that at the end of executing a program P ,
some condition holds. If program P has the shape C1 ; . . . ; Cn , we need to find the
0
weakest formula such that (| 0 |) Cn (| |).
0
Terminology : The weakest formula is called weakest precondition.
(|>|)
(|x + y = x + y|) Implied
z = x;
(|z + y = x + y|) Assignment
z = z + y;
(|z = x + y|) Assignment
u = z;
(|u = x + y|) Assignment
We have:
(| ^ B|) C1 (| |) (| ^ ¬B|) C2 (| |)
[If-statement]
(| |) if B { C1 } else { C2 } (| |)
(| 1|) C1 (| |) (| 2|) C2 (| |)
[If-Statement 2]
(|(B ! 1) ^ (¬B ! 2 )|) if B { C1 } else { C2 } (| |)
a = x + 1;
if (a - 1 == 0) {y = 1;}
else {y = a;}
..
.
if ( a - 1 == 0 ){
(|1 = x + 1|) If-Statement 2
y = 1;
(|y = x + 1|) Assignment
} else {
(|a = x + 1|) If-Statement 2
y = a;
(|y = x + 1|) Assignment
}
(|y = x + 1|) If-Statement 2
(|>|)
(|(x + 1 1 = 0 ! 1 = x + 1)^ (¬(x + 1 1 = 0) ! x + 1 = x + 1)|) Implied
a = x + 1;
(|(a 1 = 0 ! 1 = x + 1)^ (¬(a 1 = 0) ! a = x + 1)|) Assignment
if ( a - 1 == 0 ){
(|1 = x + 1|) If-Statement 2
⌅
y = 1;
(|y = x + 1|) Assignment
} else {
(|a = x + 1|) If-Statement 2
y = a;
(|y = x + 1|) Assignment
(| ^ B|) C (| |)
[Partial-while]
(| |) while B { C } (| ^ ¬B|)
We shall show that the following Core program Fac1(x) meets this specification:
y = 1;
z = 0;
while (z != x) { z = z + 1; y = y * z; }
..
.
(|y = z!|)
while ( z != x ){
(|y = z! ^ z 6= x|) Invariant
(|y · (z + 1) = (z + 1)!|) Implied
z = z + 1;
(|y · z = z!|) Assignment
y = y * z;
(|y = z!|) Assignment
}
(|y = z! ^ ¬(z 6= x)|) Partial-while
(|y = x!|) Implied
then pushing the postcondition (here y = x!) upwards through a while- statement
to meet the precondition (here (|>|)), we have
(|>|)
(|(1 = 0!)|) Implied
y = 1;
(|y = 0!|) Assignment
z = 0;
(|y = z!|) Assignment
while ( z != x ){
..
.
}
(|y = z! ^ ¬(z 6= x)|) Partial-while
(|y = x!|) Implied ⌅
(| |) P (| |).
Partial correctness does not tell us if P ‘loops’ indefinitely. We now extend the proof calculus
for partial correctness so that it also proves that programs terminate.
Ideas for Total Correctness
The only source of non-termination is the while command. Therefore, the proof calculus
for total correctness is the same as for partial correctness for all the rules except the rule for
while-statements.
If we can show that the value of an integer expression decreases in each iteration, but never
becomes negative, we have proven termination.
Why? Well-foundedness of natural numbers
We shall include this argument in a new version of the while rule.
PROOF STRUCTURE:
A proof of total correctness for a while-statement will consist of two parts:
the proof of partial correctness and
a proof that the given while-statement terminates.
The proof of termination usually has the following form.
We identify an integer expression whose value can be shown to decrease every time
we execute the body of the while-statement: which is always non-negative.
If we can find an expression with these properties, it follows that the while-statement
must terminate; because the expression can only be decremented a finite number of
times before it becomes 0.
Such integer expressions are called variants. ⌅
y = 1; z = 0;
while (z != x) { z = z + 1; y = y * z; }
E must strictly decrease in the loop, but not become negative. Answer: E ⌘ x z
When it is 0, the while-statement terminates. ⌅
We use the rule Total-while in tableaux similarly to how we use Partial-while, but
note that the body of the rule C must now be shown to satisfy
..
.
(|y = z! ^ 0 x z|)
while ( z != x ) {
(|y = z! ^ z 6= x ^ 0 x z = E0|) Invariant
(|y · (z + 1) = (z + 1)! ^ 0 x (z + 1) < E0|) Implied
z = z + 1;
(|y · z = z! ^ 0 x z < E0|) Assignment
y = y * z;
(|y = z! ^ 0 x z < E0|) Assignment
}
(|y = z! ^ ¬(z 6= x)|) Total-while
(|y = x!|) Implied
Now imposing the precondition invariant = (|x 0|), we get the complete proof for total
correctness:
(|x 0|)
(|(1 = 0! ^ 0 x 0|) Implied
y = 1;
(|y = 0! ^ 0 x 0|) Assignment
z = 0;
(|y = z! ^ 0 x z|) Assignment
while ( z != x ) {
..
.
}
(|y = z! ^ ¬(z 6= x)|) Total-while
(|y = x!|) Implied
FINAL COMMENTS
2. The application of Implied within the body of the while-statement is valid, but it makes
vital use of the fact that the boolean guard is true.
This is an example of a while-statement whose boolean guard is needed in reasoning
about the correctness of every iteration of that while-statement.
3. Finding a working variant E is a creative activity which requires skill, intuition and prac-
tice.
temp := x
x := y
y := temp
What does this tinny program do? Find preconditions, postconditions and verify its correct-
ness?
5. Reviewed problems: [ REF. 4: Chapter 2c]
It is recommended that you should do as much as you can ALL marked exercises in [2,
Sect. 2.8] (notice that sample solutions for these exercises are available in [3]). For this
lecture, the following are recommended exercises [2]:
PROBLEM 1.1.
Find appropriate predicates and their specification to translate the following into predicate
logic:
1. Only red things are in the box.
2. No animal is both a cat and a dog.
3. Every prize was won by a boy.
4. A boy won every prize.
5. Any difference between the last two cases, logically?
HINT - SOLUTION 1.
1. 8x [Inb(x) ! Red(x)]
PROBLEM 1.2.
Let F (x, y) mean that x is the father of y ; M (x, y) denotes x is the mother of y .
Similarly, H(x, y), S(x, y), and B(x, y) say that x is the husband/sister/brother of y , re-
spectively. You may also use constants to denote individuals, like ‘Ed’ and ‘Patsy.’
However, you are not allowed to use any predicate symbols other than the above to trans-
late the following sentences into predicate logic:
1. Everybody has a mother.
2. Whoever has a mother has a father.
PROBLEM 1.3.
The following sentences are taken from the RFC3157 Internet Task-force Document
‘Securely Available Credentials – Requirements.’
Specify each sentence in predicate logic, defining predicate symbols as appropriate:
1. An attacker can persuade a server that a successful login has occurred, even if it hasn’t.
2. An attacker can overwrite someone else’s credentials on the server.
3. All users enter passwords instead of names.
4. Credential transfer both to and from a device MUST be supported.
5. Credentials MUST NOT be forced by the protocol to be present in cleartext at any device
other than the end user’s.
6. Different end user devices MAY be used to download, upload, or manage the same set of
credentials.
List of Figures
List of Tables
[2] Anna Mikusheva, course materials for 14.384 [6] Practical Optimization: a Gentle Introduction,
Time Series Analysis, Fall 2007. MIT Open- John W. Chinneck, 2000
CourseWare (http://ocw.mit.edu), Massachusetts
Institute of Technology, nology. Downloaded on [7] Introduction to Linear Optimization, Dimitris
[01 June 2021] Bertsimas and John N. Tsitsiklis, Athena Scien-
[9] Peter J. Brockwell and Richard A. Davis. Time Se- Saarbrücken Germany: LAP LAMBERT Academic
ries: Theory and Methods, Second Ed. Springer, Publishing (2020) ISBN 978-620-2-79791-7
2006.
[14] S.R. Dalai and al., Factor-covering designs for
[10] David M. Cohen, Siddhartha R. Dalal, Michael L.
Testing Software, Technometrics 40(3), 234-243,
Fredman, and Gardner C. Patton The AETG Sys-
American Statistical Association and the Ameri-
tem: An Approach to Testing Based on Combina-
can Society for Quality, 1998.
torial Design, IEEE Trans. on Soft. Engineering,
Vol. 23, No. 7, July 1997.
[15] Douglas C. Montgomery, George C. Runger,
[11] David S. Moore, George P. McCabe and Bruce A. Applied Statistics and Probability for Engineers,
Craig. Sixth Edition, (2014) John Wiley & Sons
Introduction to the Practice of Statistics, 6th edi-
tion, (2009) W. Freeman Company, New York
[16] Jay L. Devore and Kenneth N. Berk,
[18] Avrim Blum, John Hopcroft, and Ravindran Kan- [24] Ljung, L. System identification: theory for the user,
nan Foundations of Data Science, Cambridge Prentice Hall, Englewood Cliffs, NJ, 1987
University Press, 2020.
[25] Mahmut Parlar, Interactive operations research
[19] Robert V. Hogg, Joseph W. McKean, Allen T. Craig with Maple: methods and models, (2000) Springer
[21] H. Wolfgang and L. Simar. Applied multivariate [28] Michael Baron, Probability and Statistics for Com-
statistical analysis. 2nd. Springer, 2007. puter Scientists, 2nd Edition (2014), CRC Press,
Taylor & Francis Group
[22] Jolliffe, I. T. Principal component analysis. 2nd.
Springer, 2002. [29] R. H. Myers, Douglas C. Montgomery and Chris-
tine M. Anderson-Cook
[23] Lapin, L.L. , Probability and Statistics for Modern Response Surface Methodology : Process and
Engineering, PWS-Kent Publishing, 2nd Edition, Product Optimization Using Designed Experi-
Boston, Massachusetts,1990. ments, Wiley, 2009.
[30] Man Nguyen, Tran Vinh Tan and Phan Phuc Doan, sis, Eindhoven Univ. Press, 2005
Statistical Clustering and Time Series Analysis
[34] Paul Mac Berthouex. L. C. Brown. Statistics for
for Bridge Monitoring Data, Recent Progress in
Environmental Engineers; 2nd edition (2002),
Data Engineering and Internet Technology, Lec-
CRC Press
ture Notes in Electrical Engineering 156, (2013)
pp. 61 - 72, Springer-Verlag [35] A. R. Ravindran (editor). Operations Research &
Management Science Handbook, CRC, 2008
[31] Nguyen, Man V. M. Some New Constructions of
[36] Alvin C. Rencher and William F. Christensen,
strength 3 Orthogonal Arrays,
Methods of Multivariate Analysis, Wiley, 2012
the Memphis 2005 Design Conference Special Is-
sue of the Journal of Statistical Planning and [37] Ron S. Kenett, Shelemyahu Zacks.
Inference, Vol 138, Issue 1 (Jan 2008) pp. 220- Modern Industrial Statistics with Applications in R,
233. MINITAB, 2nd edition, (2014), Wiley
[32] Nathabandu T. Kottegoda, Renzo Rosso. Applied [38] Robert H. Shumway and David S. Stoffer.
Statistics for Civil and Environmental Engineers, Time Series Analysis and Its Applications: With R
2nd edition (2008), Blackwell Publishing Ltd and Examples, Springer Texts in Statistics, 3rd Edi-
The McGraw-Hill Inc tion, (2011)
[33] Man Nguyen. Computer-algebraic Methods for the [39] W.M.P. Aalst, van der PROCESS MINING, 2nd
Construction of Design of Experiments, Ph.D the- edition, 2016, Springer
[40] Kurt Jensen, Wil M.P. van der Aalst, Gianfranco [47] Sara M. Grundel et.al. How to Coordinate Vacci-
Balbo, Maciej Koutny, Karsten Wolf (Eds.) nation and Social Distancing to Mitigate SARS-
CoV-2 Outbreaks? SIAM J. APPLIED DYNAMI-
Transactions on Petri Nets and Other Models of
CAL SYSTEMS, Vol. 20, No. 2, pp. 1135–1157,
Concurrency VII LNCS 7480, Springer, 2013
Society for Industrial and Applied Mathemat-
[41] Sheldon M. Ross. Introduction to probability mod- ics, 2021
els, 10th edition, (2010), Elsevier Inc.
[48] Chongli Jiang Mathematical Mechanism of Quar-
[42] Sloane N.J.A., http://neilsloane.com/hadamard/index.html/
antine Measures for SARS Epidemic, The first
International Conference on Algebraic Biology
[43] Google Earth, Digital Globe, 2014- 2019
Japan (2005)
[44] Larry Wasserman, All of Statistics- A Concise [49] Timothy C. Germann and al., Mitigation strategies
Course in Statistical Inference, Springer, (2003) for pandemic influenza in the United States PNAS
(2006) Medical Sciences series, 103; 5935-5940
[45] C.F. Jeff Wu, Michael Hamada Experiments: Plan-
ning, Analysis and Parameter Design Optimiza- [50] G.A.P - Groups, Algorithms, Programming -
tion, Wiley, 2000. a System for Computational Discrete Algebra,
https://www.gap-system.org/
[46] Wendy L. Martinez and Angel R. Martinez, Com-
putational Statistics Handbook with MATLAB, [51] Decker, Wolfram and Greuel, Gert-
CHAPMAN & HALL/CRC, 2002 Martin and Pfister, Gerhard and Schöne-