0% found this document useful (0 votes)
51 views164 pages

MM CHAPTER 1 Advanced LOGIC Landscape

Uploaded by

ngodiemquyen69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views164 pages

MM CHAPTER 1 Advanced LOGIC Landscape

Uploaded by

ngodiemquyen69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 164

MATHEMATICAL MODELING

Methods and Application

Chapter 1: ADVANCED LOGIC

With Application in Computing

Khuong An Nguyen, Trang Hong Le

and Man Van Minh Nguyen


MATHEMATICAL MODELING

© Trang Hong Le, Khuong An Nguyen(‡)

Man V. M. Nguyen (†) 2024

(†) Faculty of Science - Mahidol University

(‡) Faculty of Computer Science & Engineering -

HCMC University of Technology

With Courtesy of FCSE- HCMUT’s former colleagues Tan V. Tran, Nguyen T. Huynh
Contents

Chapter 1 LOGIC THEORY


With Application in Computing 1

PART I: Propositional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4


1.1 PROPOSITIONAL LOGIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

PART II: Advanced Propositional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27


1.2 Advanced Propositional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

PART III: Predicate Logic- A Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42


1.3 Predicate Logic- A Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

PART IV: Advanced Predicate Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82


1.4 Advanced Predicate Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

PART V: Logic for Program Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109


1.5 Logic for Program Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
1.6 Hoare Triples - Partial and Total Correctness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

MATHEMATICAL MODELING Methods and Application


1.7 Practical Aspects of Correctness Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
1.8 HOMEWORK and Chapter Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Chapter 1

LOGIC THEORY

With Application in Computing


2

MATHEMATICAL MODELING- AN OVERVIEW

CSE = Computer Science and Engineering = COMPUTING (by ACM) 1

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

MATHEMATICAL MODELING Methods and Application


3

Key Reference texts of the course


REF 0. Lecture notes and text of the instructor (like this document)
1. REF 1. Michael Huth & Mark D. Ryan. Logic in Computer Science (2nd Ed.), Cambridge,
2004. (Ch. 1, 2, 4)
REF 1A. Michael R.A. Huth and Mark D. Ryan. Logic in Computer Science: Solutions to
designated exercises (2nd Ed.), Cambridge University Press, 2004. (Chapters 1, 2), link
https://web.archive.org/web/20191027035952/
http://www.cs.bham.ac.uk:80/research/projects/lics/tutor/index.html
REF 1B. (Further reading): Chapter 15 in Ben-Ari, M., Mathematical logic for computer
science. Springer 2012.
2. REF 2. Peter Linz. An Introduction to Formal Languages and Automata, John & Barlett
Learning, 5th ed., 2011. (Chap. 1-4)
REF 2A. (Further reading): John Hopcroft et. al. Introduction to Automata Theory, Lan-
guages & Computation, Prentice Hall, (3rd Ed.) 2006
(Vietnamse translation is available, "Tran Duc Quang - Ly Thuyet Automat & Ngon Ngu Hinh
Thuc, NXB ÐHQG TP HCM 2002")

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 4

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

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 5

1.1 PROPOSITIONAL LOGIC

OVERVIEW with CHAPTER’S STRUCTURE* Logic, and Discrete Optimization

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. ⌅

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 6

1.1.1 Propositions- Propositional logic

Mathematical Logic nowadays finds applications in many areas of computing. We firstly


remind Propositional Logic.
Propositions– Propositions versus predicate
Connectives and truth tables - Compound propositions
Tautology– Contradiction – Logical equivalence
Decomposing complicated proposition
Semantics of propositional logic
Natural deduction and Provable equivalence- Rule of Inference
We begin by looking at examples involving everyday English sentences. This is followed
by an introduction to the more formal mathematical approach used in propositional and
predicate logic.
Propositions- Propositional logic

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.

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 7

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.

Here are some examples of English sentences that are propositions:


‘Canberra is the capital of Australia.’
‘There are 8 days in a week.’
‘Isaac Newton was born in 1642.’
‘5 is greater than 7.’
‘Every even number greater than 2 is expressed as the sum of two prime numbers.’

Propositions– truth values

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.

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 8

The following sentences are not propositions:


‘Where are you going?’ OR ‘Come here!’

How about these?


‘Anne is tall.’
‘Ice cream is delicious.’
‘x > 5.’
The last of the three sentences given above is an example of a predicate.

Propositions versus predicate


Definition 1.2
|

A predicate is a statement containing one or more variables; it cannot be assigned a truth


value until the values of the variables are specified. We will investigate predicate logic later.
Statements containing variables commonly occur in algorithms and computer programs.
For example, an algorithm might contain the statement ‘x > 5’
treated as the condition in a control structure such as an If-then.

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 9

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 next example is different, however:


‘If Brian and Angela are not both happy,
then either Brian is not happy or Angela is not happy.’

The sentence about Brian and Angela is an example of a compound proposition. It is built

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 10

up from the atomic propositions


‘Brian is happy ’ and
‘Angela is happy ’
using the words and, or, not (also written ¬) and if-then.

Connectives and truth tables

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.

⌅ We will use lower-case letters such as p, q and r to denote atomic propositions.


There are five connectives that we will use in our work; they are listed in table below, to-
gether with their symbols.

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 11

Connective Symbol

and ^
or _
not ¬
if-then !
if-and-only-if $
Table 1.1: Connectives and associated symbols

1.1.3 Compound propositions

With the exception of not, the symbols for these connectives are written between the two
operands (the propositions they connect).

For example, if p denotes the proposition ‘Today is Monday ’, and


q denotes the proposition ‘It is raining’,
then we can write

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 12

the symbol p, ¬p or not p before the proposition to which it applies; thus,


¬p means ‘Today is not Monday ’.
the symbol p ^ q to denote the proposition
‘Today is Monday and it is raining’.
Compound propositions– p ^ q has the true value given in table below
p q p^q
T T T

T F F

F T F

F F F

Table 1.2: Connective and

Can we form compound propositions p _ q , and p ! q similarly?

Writing compound propositions in symbolic form

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.

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 13

⌥ EXAMPLE 1.1. Express the proposition below in symbolic form:

‘Either my program runs and it contains no bugs, or my program contains bugs’

⌥ 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

If Brian and Angela are not both happy,

then either Brian is not happy or Angela is not happy

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 14

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

contains, is called a tautology.

(B) An expression that is always false, regardless of the truth values of the variables it

contains, is called a contradiction. Mathematically , contradictions are expressions of

the form ^¬ or ¬ ^

where is any proposition (simple or compound). |

(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

A(p, q, r, ...) , B(p, q, r, ...)

if we have A(p, q, ...) = B(p, q, ...) for every choice of boolean values of p, q, ...

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 15

Definition 1.4 (Converse and Contrapositive)


|

Expressions of the form p ! q are called implications.


The converse of p ! q is q ! p
The contrapositive of p ! q is ¬q ! ¬p

⌥ EXAMPLE 1.4. Can you write English sentences for the converse and the contrapositive of

the statement? If 250 is divisible by 4 then 250 is an even number.

Logical equivalence and connective if-and-only-if

There is a subtle but important distinction between


the connective if-and-only-if or $
and the concept of logical equivalence ,.

When we write A $ B , we are writing a single logical expression.

(A ! B) ^ (B ! A).
MATHEMATICAL MODELING Methods and Application
1.1. PROPOSITIONAL LOGIC 16

Hence the value is either (A $ B) ⌘ T RU E or (A $ B) ⌘ F ALSE .


Logical equivalence, A () B , read [expressions A and B are logically equivalent]
on the other hand, is a relationship between A and B : they are both TRUE or FALSE.
Connection of the two concepts:
A and B are logically equivalent if and only if the expression A $ B is a tautology.

1.1.5 Decomposing proposition

We began this section with an example of a complicated proposition that we showed to


be logically equivalent to a simpler one. Occasions often arise in practice where it is desirable
to replace a logical expression with a simpler expression that is logically equivalent to it.
For example, we have seen how logical expressions representing propositions can occur in
algorithms and computer programs. By writing these expressions as simply as possible, we
can make a program more efficient and reduce the chance of error.

How do we do? Use Laws of Logic (Logical equivalence)

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 17

In order to be able to simplify logical expressions effectively, we need to establish a list of


pairs of expressions that are logically equivalent.

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

where P and Q are logical expressions is called a law of logic.


A list of the most important laws of logic is given as follows.
Most important laws

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 18

De Morgan ¬(¬p ^ ¬q) ⌘ p_q


Contrapositive p!q ⌘ ¬q ! ¬p
Equivalence law p$q ⌘ (p ! q) ^ (q ! p)
Implication law p!q ⌘ ¬p _ q
Double negation law ¬(¬p) ⌘ p
Idempotent laws p^p ⌘ p
p_p ⌘ p
Commutative laws ?
Associative laws ?
Distributive laws ?
Inverse laws ?
Absorption laws ?

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 19

p_q ⌘ q _ p Commutative laws


p^q ⌘ q^p
(p _ q) _ r ⌘ p _ (q _ r) Associative laws
(p ^ q) ^ r ⌘ p ^ (q ^ r)
p _ (q ^ r) ⌘ (p _ q) ^ (p _ r) Distributive laws
p ^ (q _ r) ⌘ (p ^ q) _ (p ^ r)

¬(p ^ q) ⌘ ¬p _ ¬q De Morgan’s law


¬(p _ q) ⌘ ¬p ^ ¬q
p _ (p ^ q) ⌘ p Absorption laws
p ^ (p _ q) ⌘ p

Using important laws to simplify logical expressions

QUIZ
1. Converse and contrapositive. (5 min) Prove that

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 20

p ! q is not logically equivalent to its converse, but that it is logically equivalent to its
contrapositive. That is
p ! q ⌘ ¬q ! ¬p

2. Use the laws of logic to simplify the expression:

p _ ¬(¬p ! q)

3. An algorithm contains the following line:

If not (x > 5 and x  10) then...

How could this be written more simply?

1.1.6 Semantics of propositional logic

REMINDER: There are two truth values, T and F, denoted for truth and falsity.
The meaning of logical connectives: The propositional connectives are:
negation (¬ ),

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 21

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

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 22

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

Consider a sentence as follows.


I will buy a new phone only if I have enough money to buy iPhone 4 or my
phone is not working.
If define
p: I will buy a new phone
q : I have enough money to buy iPhone 4
r: My phone is working

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 23

then its symbolic form is: p ! (q _ ¬r)


But if consider the sentence:
“I will buy a new phone if I have enough money to buy iPhone 4 or my phone
is not working”.
What answer (symbolic form) do you get?

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 relationship between $ and ,


p $ q : bi-implication of p and q , p if and only if q

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 24

p , q : logical equivalence, p is logically equivalent to q


We understand that:
if p $ q is a tautology, then we say
p is logically equivalent to q , and write p , q .
How did it go?
Logical equivalence , means bi-implication $ is tautology.
Five rules for infering
p
p!q
— ———
) q
———————
p!q
q!r
— ———
) p!r
...

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 25

PRACTICE 1.1. (30 min).

1. Determine whether the following argument is valid:

‘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

MATHEMATICAL MODELING Methods and Application


1.1. PROPOSITIONAL LOGIC 26

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

where P1 , P2 and P3 are the premises, and Q is the conclusion.


(There is no ambiguity in writing P1 ^ P2 ^ P3 without brackets, because the connective ^
obeys the associative law.)
If the argument is valid, the expression should be a tautology.
You have to define a few propositional atoms to form P1 , P2 and P3 .

MATHEMATICAL MODELING Methods and Application


PART II. Advanced Propositional Logic

[[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 Advanced Propositional Logic

1.2.1 REMINDER on Rules of Inference (Logic Laws)

Consider an implication of the form 1, 2, . . . , n !


Valid arguments. This implication is understood as 1 ^ 2 ^ ... ^ n ! .
When all the premises 1, 2, . . . , n have true value T, and find that under these circum-
tances also has the value T, then the implication

1 ^ 2 ^ ... ^ n !

is tautology, and we have a valid argument. Valid (correct) arguments


1. enable us to consider only the cases wherein all the premises 1, 2, . . . , n are true;
2. used in the development of step-by-step validation of how the conclusion
logically follows from the premises 1, 2, . . . , n in the implication of the form

1, 2, . . . , n !

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 29

A few well known valid arguments are summarized next.


I: Rule of Modus Ponens p ^ (p ! q) ! q
Modus Ponens is also called the Rule of Detachment.
Quiz : Can you check p ^ (p ! q) ! q is a valid argument? In the tabular form:
p
p!q
— ———
) q
where the ) stands for ‘therefore’, indicating that q is the conclusion of two premises p and
p ! q above the line.

⌥ EXAMPLE 1.5. Consider the following statements.

1/ Barack Obama is a human being.

2/ If x is a human being then x will die.

3/ ) Barack Obama will die.

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 30

II: Rule of Syllogism (p ! q) ^ (q ! r) ! (p ! r) where p, q and r are any statement. In


the tabular form, it is written
p!q
q!r
— ———
) p!r

III: Rule of Modus Tollens, a method of denying.

In the tabular form:

p!q
¬q
— ———
) ¬p
Quiz: Use Modus Tollens to prove the follwing scheme

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 31

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

In the tabular form:

p_q
¬p
— ———
) q

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 32

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

Denote F0 to be a contradiction. You can prove that

(¬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 ?

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 33

1.2.2 Propositional Logic as a Formal Language

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.

Definition 1.5 (Natural deduction in propositional logic)


|

This intention is symbolically denoted as

1, 2, . . . , n (premises) ` (conclusion)

This expression is called a natural deduction or a sequent.


It is valid if a proof for it can be found.

Definition 1.6 (Well-formed formulas)


|

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 34

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, ....

Let L be a propositional language. An L-assignment is a mapping

M : {p|p is an atomic L f ormula} ! {T, F }.

Note that if L has exactly n atoms then there are exactly 2n different L- assignments.

Lemma 1.1
~

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 35

Given an L-assignment M , there is a unique L-valuation

vM : {A|A is an L f ormula} ! {T, F }

Definition 1.7
|

A set of formulas S is said to be satisfiable if there exists an assignment M , and a corre-


sponding L-valuation vM which satisfy S , i.e., vM (S) = T.

Definition 1.8 (Provable or Logical implication)


|

Let and be formulas of propositional logic. Build the implication S = ! .


We say S is provable implication, denoted as ) , iff ! is valid,
that means we can show a rigorous series of arguments (reasonings)
such that the implication is true, i.e.

! ⌘ True

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 36

Question: Given a provable implication,

S= ! ,

is it satisfiable, that is there exists L-valuation vM which satisfies S , i.e.,

vM (S(p, q, ...)) = T for all p, q, 2 S.

ANSWER: not sure. To be answered in Section 1.4.4.

Definition 1.9 (Provable equivalence )

Let and be formulas of propositional logic.

We say and are provable equivalent iff the sequents

! and ! are valid .

In other words, [ and are provably equivalent iff , (also write ⌘ )]. |

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 37

1.2.3 Soundness and Completeness of Propositional Logic

Consider a provable implication

1, 2, . . . , n (premises) ) (conclusion)

Soundness of Propositional Logic means:


Every provable implication is satisfiable for all valuations!
We need to show: for all valuations of p, q, ... in which
all propositions 1, 2, . . . , n evaluate to True, then evaluates to True.
Definition 1.10 (Semantic entailment relation)
|

If for all valuations in which all 1, 2, . . . , n evaluate to True,


formula evaluates to True as well, we say that

1, 2, . . . , n (premises) ✏ holds, and


call ✏ the semantic entailment relation.

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 38

Theorem 1.1 (Soundness)


Let 1 , 2 , . . . , n and be propositional logic formulas. If

1, 2, . . . , n )

is valid, then the semantic entailment relation

1, 2, . . . , n (premises) ✏

holds. ~

How about the other way? That is, if we have

1, 2, . . . , n (premises) ✏ ,

will we have the provable implication

1, 2, . . . , n ) ?

Completeness of Propositional Logic

We show that the provable implications of Propositional Logic is complete, i.e: whenever

1, 2, . . . , n (premises) ✏

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 39

holds, then there exists a provable implication

1, 2, . . . , n )
being valid (i.e. you have to find a proof for the implication

1, 2, . . . , n ! ).

Soundness and Completeness of Propositional Logic


Theorem 1.2 (Soundness and Completeness)

Let 1, 2, . . . , n and be formulas of propositional logic. Then

1, 2, . . . , n ✏

holds iff the implication

1, 2, . . . , n )

is valid. ~

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 40

1.2.4 Proof theory of Propositional Logic

AIM: we want to transform formulas into simpler ones


which don’t contain ! at all,
and the occurrences of ^ and _ are confined to separate layers
such that validity checks are easy!

Definition 1.11 (Conjunctive Normal Form of Propositional Logic Formulas)


|

A literal L is either an atom p or the negation ¬p.


A propositional formula C is in Conjunctive Normal Form (CNF)
if it is a conjunction of clauses, where each clause D is a disjunction of literals.

In other words, propositional formulas are recursively defined, in Backus Naur form,

MATHEMATICAL MODELING Methods and Application


1.2. Advanced Propositional Logic 41

as:
L ::= p | ¬p

D ::= L | L _ D

C ::= D | D ^ C.
Example

(¬q _ p _ r) ^ (¬p _ r) ^ q

is a CNF, but (¬(q _ p) _ r) ^ (q _ r) is not! WHY?

Lemma 1.2
A disjunction of literals L1 _ L2 . . . Lm is valid iff there are 1  i, j  m such that Li is

¬Lj . ~

MATHEMATICAL MODELING Methods and Application


PART III: Predicate Logic- A Primer

[[GoogleMap]]
1.3. Predicate Logic- A Primer 43

1.3 Predicate Logic- A Primer

We discuss the followings in PART III:


1/ Fundamentals of Predicate logic
2/ Natural deduction calculus in Predicate Logic-
Predicate vocabulary

3/ Parse tree of a logic formula


4/ Free and bound variables, in part 1.3.4.

Warming up

Propositional logic dealt quite well and satisfactorily with sentence components like
not
and
or, and

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 44

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.

1.3.1 Fundamentals of Predicate logic

A/ Predicate: one or many variables


A predicate P that contains a variable x can be written symbolically as P (x).

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 45

A predicate can contain more than one variable;


a predicate P with two variables, x and y for example, can be written P (x, y).
In general, a predicate with n variables, x1 , x2 , . . . , xn , can be written P (x1 , x2 , . . . , xn ).

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.

The process of applying a quantifier to a variable is called quantifying the variable.


(L1) ’For all n, P (n) is true’ can be reduced to 8n, P (n)
(L2) ‘There exists an n such that P (n) is true’ can be reduced to 9n, P (n)

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 46

Always True we use symbol 8 Example

(L1) ’For all n, P (n) is true’. “For all x, x2 0.

8 n, P (n) is true
or P (n) is true for every n x2 0 for every x

Sometimes True we use symbol 9

(L2) ‘There exists an n such that There exists an x

P (n) is true’. such that 5x2 7=0


9n: P (n) is true

The above tables give some general formats on the left


and few examples using those formats on the right.

⌥ EXAMPLE 1.6. Let P (x) be the statement “x < 2”.

I) What is the truth value of the quantification 8xP (x), where the domain consists of all real
number?

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 47

P (3) = 3 < 2 is false


) 8xP (x) is false

3 is a counterexample of 8xP (x)


II) What is the truth value of the quantification 9xP (x), where the domain D = R ? ⌅
A/ Predicate: one or many variables .
B/ Quantifying a Predicate: many propositions
For two predicates (i.e. open statements) p(x), q(x) defined for a prescribed universe U ,
consider the universally quantified statement

8x 2 U [ p(x) ! q(x) ] or shortly 8x [ p(x) ! q(x) ].


Definition 1.12
If the implication p(a) ! q(a) is true for each a in the universe U then we say that

p(x) logically implies q(x), and can write

8x [ p(x) ! q(x) ].

[a is a value, x is the variable of predicate.]

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 48

We similarly define the logically equivalent statement

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.

This is complex, and tell us many things, about:


1. being a student
2. being an instructor, and

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 49

3. being younger than somebody else.


Need a mechanism to express them, plus their logical dependence.
Introduce predicates

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

8x, [S(x) ! (9y : I(y) ^ Y (x, y))]


or 8x, [S(x) ! (9y : (I(y) ^ Y (x, y))) ] ? Rephrase this back to daily used sentence?

PRACTICE 1.2.

A) Consider a declarative sentence: Every child is younger than its mother.


Write this example in an entire symbolic way.

B) Write the declarative sentence below in an entire symbolic way:


Andy and Paul have the same maternal grandmother.

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 50

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)

The function form/symbol m(x) of a binary predicate M (x, y) allows us to represent


the semantic of a sentence elucidatedly.
E.g., for M (x, y) : ‘x is the mother of y 0 we write m(y) ⌘ y ’s mother. See EXAMPLE 1.10.

D/ Predicate logic- Quantifiers with many variables

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 51

Definition 1.13
A variable which has been quantified is said to be bound.

A variable that appears in a predicate but is not bound is said to be free. |

Mixing quantifiers. Many mathematical statements involve several quantifiers.

⌥ EXAMPLE 1.9. Goldbach’s Conjecture states that

Every even integer greater than 2 is the sum of two primes.

Write this more verbosely to make the use of quantification clearer.


ANSWER: 8n, [n 2 Z ^ ?] ! [??]

⌥ EXAMPLE 1.10. Let’s look at an English sentence ‘Every girl is younger than her

mother’.

Using three predicates


1/ G(x): x is a girl;
2/ M (x, y): y is x’s mother; and the third

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 52

3/ Y (x, y): x is younger than y


gives us the complete statement 8x8y [G(x) ^ M (x, y) ! Y (x, y)].
Note that y is only introduced to denote the mother of x. If everyone has exactly one mother,
the 2-variable predicate M (x, y) is a function, when reading from right to left.
A function symbol m(x) ⌘ “the mom of x ” then can be applied [in place of M (x, y)] to
give a better answer
8x [G(x) ! Y (x, m(x))] ⌅

E/ Order of quantifiers is important


Swapping the order of different kinds of quantifiers (either existential or universal) changes
the meaning of a proposition.

⌥ 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

H(a, d) to be “American a has dream d.⌘.


MATHEMATICAL MODELING Methods and Application
1.3. Predicate Logic- A Primer 53

Now the sentence could mean either


(I) there is a single dream that every American shares:

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).

PRACTICE 1.3. (15 min)

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 .

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 54

F/ Negating a predicate with many variables and quantifiers

Applying not to a proposition/predicate is called negating the proposition/predicate.


Suppose we want to apply the connective not to the following proposition:
‘All swans are black.’
The original proposition can be written in symbols: 8x, P (x)
where P (x) is the predicate ‘Swan x is black ’.
- Here is one way of forming the negation: ‘It is not true that all swans are black.’
- Or, more simply: ‘Not all swans are black.’ ⌘ ‘There is a swan that is not black.’
Rule for negating a predicate
We negate the predicate and changing all its quantifiers.

Statement Negation Equivalent form


8xP (x) ¬(8xP (x)) 9x¬P (x)
9xP (x) ¬(9xP (x)) 8x¬P (x)
⌥ EXAMPLE 1.12.
S = All CSE students study Discrete Math 1

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 55

Let C(x) denote “x is a CSE student”


Let S(x) denote “x studies Discrete Math 1”
Then S is symbolized as 8x : C(x) ! S(x)
Hence, ¬ S = 9x : ¬(C(x) ! S(x)) ⌘ 9x : C(x) ^ ¬S(x)
means There is a CSE student who does not study Discrete Math 1??
W
hat is the rule for negating a predicate?
The general principle for negating a predicate is that moving a not across a quantifier
changes the kind of quantifier.

PRACTICE 1.4. (5 min)

Now write down the negation of the following proposition:


‘For every number x there is a number y such that y < x.’
For one variable but compound case:

Rule 4 : ¬ [ 8x (P (x) ! Q(x)) ] ⌘ 9x [ P (x) ^ ¬Q(x) ]

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 56

WHY? We know the law [p ! q ⌘ ¬p _ q],


and when negating a complex proposition, we always
- go from the left to the right, apply from inner to outer, and
- negate component by component.
Summary of Quantifier Equivalences
Rule 1: ¬ [ 8x P (x) ] ⌘ 9x [ ¬P (x) ]
Rule 2: ¬ [ 9x P (x) ] ⌘ 8x [ ¬P (x) ]
Rule 3: ¬ [ 8x 9y P (x, y) ] ⌘ 9x 8y [ ¬P (x, y) ]
Rule 4: ¬ [ 8x (P (x) ! Q(x)) ] ⌘ 9x [ P (x) ^ ¬Q(x) ]

HOMEWORK: Try problems below at home within 120 minutes.


1. Translate these:
All lions are fierce.
Some lions do not drink coffee.
Some fierce creatures do not drink coffee.

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 57

HINT: Let P (x), Q(x) and R(x) be the statements “x is a lion”, “x is fierce” and “x drinks
coffee”, respectively.

2. Translating Nested Quantifiers

8x (C(x) _ 9y (C(y) ^ F(x, y)) )

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)

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 58

8x 9y(x2 = y)

8y 9x(x2 = y)

8x 6= 0 9y(xy = 1)

9x 9y : (x + 2y = 2) ^ (2x + 4y = 5)

4. (Order of quantifiers is important).


Let p(x, y) be an open statement ‘x + y = 25’ where x, y 2 Z. Are the statements
8x 9y p(x, y) and 9y 8x p(x, y) logically equivalents?
5. Translating into Logical Expressions: Every people has one best friend.
6. Inference
If I have a girlfriend, I will take her to go shopping.
Whenever I and my girlfriend go shopping and that day is a special day, I will surely buy
her some expensive gift.
If I buy my girlfriend expensive gifts, I will eat noodles for a week.
Today is March 8.

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 59

March 8 is such a special day.


Therefore, if I have a girlfriend,...
Your conclusion is: ??

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 60

1.3.2 Natural deduction calculus in Predicate Logic

Two things involved in a predicate logic formula:


terms or objects include individuals 2 and variables x, v ...
formulas: Y (x, m(x)) is a formula, though x and m(x) are terms [ See from EXAMPLE
1.10].

Definition 1.14
A predicate vocabulary consists of 3 sets:

a) a set of predicate symbols P

b) a set of function symbols F

c) a set of constant symbols C .

* Arity of a function f (...) 2 F is the number of arguments it expects. |

We view constants are nullary functions (don’t take any argument), so can view C ⇢ F .
2
such as a= Andy, p= Paul ...

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 61

Terms and Their Backus Naur forms


Definition 1.15

Terms are recursively defined as follows. |

Any variable x is a term


If c 2 F is a nullary function [having arity 0] then c is a term
If t1 , t2 , . . . , tn are terms and f 2 F has arity n > 0, then f (t1 , t2 , . . . , tn ) is a term.
Nothing else is a term.
In Backus Naur form we may write

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.

Are g(f (n), n) and f (g(n, f (n))) terms? Why?


Are g(n), f (f (n), n) terms? Explain.

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 62

⌥ EXAMPLE 1.14 (Database as a logic model).

We may define a 4-tuples P = {M, F, S, D} referring to


M: being male; F : being female
S: being a son of ...
D: being a daughter of ...
if we work on database representing relations between human being. Here,
F, M are unary predicates (they take one argument), but
S and D are binary predicates (taking twos). We utilize this instance in Example 1.21. ⌅

Denoted respectively sets P be predicate symbols, and F be function symbols.


Use the defined set of terms over F we recursively define the set of formulas over (F, P).

Definition 1.16 (The formulas of predicate logic)

If P 2 P is a predicate symbol of arity n 1, and

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 63

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

:= P (t1, t2, . . . , tn) |


(¬ ) | ( ^ ) | ( _ ) | ( ! ) |
(8x ) | (9x )

What have been done

4.3.1 Fundamentals of Predicate logic

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 64

4.3.2 Natural deduction calculus in Predicate Logic

4.3.3 Parse tree of a logic formula?

4.3.4 Free and bound variables

To construct the Parse tree of a logic formula we follow the rule


Leaves are atomic propositions, and
internal nodes are operations ¬, ^, _, !.

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 65

1.3.3 Parse tree of a logic formula

RULES:
1. Leaves are atomic propositions, and internal nodes are operations ¬, ^, _, !.
2. We employ the binding priorities for logic connectives:

first a/ ¬; second b/ the _ and ^; finally c/ the !.

Parse tree of a propositional logic formula


Example, draw the parse tree of a propositional logic formula

[((¬p) ^ q) ! (p ^ (q _ (¬r)))]

Parse tree of a predicate logic formula


Convention (for predicate logic): Just like for propositional logic, we introduce
convenient conventions to reduce the number of parentheses:
¬, 8x and 9x bind most tightly;
then ^ and _;

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 66

then !, which is right-associative.

PRACTICE 1.5.

Draw the parse tree of a predicate logic formula

8x[(P (x) ! Q(x)) ^ S(x, y)]

HINT: Just remember that:


1. the quantifiers 8x and 9y form nodes and have, like negation, just one subtree;

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

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 67

8x

! S

P Q x y

x x

PRACTICE 1.6.

Let n, f, g 2 F be function symbols, respectively nullary, unary and binary.


Are g(f (n), n) and f (g(n, f (n))) terms? Explain
Are g(n), f (f (n), n) terms?
(*) Define a set of function symbols
F = {0, 1, 2, ...}(nullary) [ {s}(unary) [ {+, , ⇤}(binary).
Is t = ⇤( (2, +(s(x), y)), x) a term? Draw the parse tree of t.

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 68

Rewrite t using infix notation.


EXTRA

1. (About the role of domain-specific knowledge) Translate the sentence


Every son of my father is my brother
into predicate logic by two different ways.
2. HINT: we need two predicates
S(x, y) : x is a son of y ; B(x, y) : x is a brother of y .
and two functions:
m : constant for “me”; f (x) : father of x. ⌅

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 69

Predicate Logic- What for?


Remind that variables and quantifiers (introduced in Section 1.3.1 - Predicate logic (Re-
minder)) allow us to express the notion
all ... and some ...
QUESTION: But how to verify that the claim

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!

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 70

1.3.4 Free and bound variables

| OBSERVATION 1. Variables in a formula occur at two different sorts of places in parse

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:

⌅ CONCEPT 1 (Informal description).


a/ Bound case: when walk up the tree from a node x, we run into the quantifier 8:
these nodes represent any value of x.
b/ Free case: when walking upwards from a node y , we run into the node 8x,
that x is not relevant to y , so y is free from x.

⌥ EXAMPLE 1.15.
MATHEMATICAL MODELING Methods and Application
1.3. Predicate Logic- A Primer 71

A simple parse tree


a) Does the figure show the parse tree T1 of the formula
8x[(P (x) ! Q(x)) ^ S(x, y)]?
b) Recognize free and bound variables.
c) What is the relationship between variable ‘binder’ x and occurrences of x? ⌅

Definition 1.17
Let be a formula in predicate logic. |

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 72

* Any occurrence of x in is free in formula


if it is a leaf node in the parse tree of
such that there is no path upwards from node x to node 8x or 9x.
* Otherwise, that occurrence of x is called bound.

Hence, if x occurs in formula , then


- it is bound if, and only if it is in the scope of some nodes 9x or 8x;
- otherwise it is free.

⌥ EXAMPLE 1.16. From the figure could you recover a predicate formula?

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 73

The figure shows the parse tree T2 of the formula

[8x(P (x) ^ Q(x))] ! [¬P (x) _ Q(y)]

Which variable occurrences are free; which are bound? ⌅

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 74

Definition 1.18 (Substitution)


|

Given a variable x, a term t and a formula , we define [t / x] to be


the formula obtained by replacing each free occurrence of variable x in with t.

PRACTICE 1.7.

A) Could you substitute occurrences of variable x in the tree T1 by a term f (x, y)?

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 75

A simple parse tree


NOTE: Instead of using [x ) t] few textbooks also use the notation [t/x]
(we find the order of arguments in the latter notation hard to remember).

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 76

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))

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 77

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)
|

Given a term t, a variable x and a formula in predicate logic. We say that:

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 78

1. Term t is free for x if no free x leaf in occurs in the scope of node 8y or 9y


for any variable y occurring in t.
2. Formula is free for x if x is a leaf node in the parse tree of such that
there is no path upwards from that node x to a node 8x or 9x.
Otherwise, that occurrence of x is called bound (in ).
3. In terms of parse trees, the scope of a quantifier is just its subtree, minus any subtrees
which re-introduce a quantifier for x.

Thus, Item 2 equivalently says: if variable x occurs in , then


it is bound if, and only if, it is in the scope of some 9x or some 8x;
otherwise it is free.
Free-ness as precondition:
To compute [x ) t] , we demand that t is free for x in .

What if not? Rename the bound variable!


Example of Renaming:
MATHEMATICAL MODELING Methods and Application
1.3. Predicate Logic- A Primer 79

[x ) f (y, y)](S(x) ^ 8y(P (x) ! Q(y)))


,! [x ) f (y, y)](S(x) ^ 8z(P (x) ! Q(z)))
,! S(f (y, y)) ^ 8z(P (f (y, y)) ! Q(z))

NOTE: The logic equivalence notation ⌘ in propositional logic


can be replaced by the two-way sequent a`. For example,
¬ [ 8x P (x) ] a` 9x [ ¬P (x) ] means ¬ [ 8x P (x) ] ⌘ 9x [ ¬P (x) ]

Fact 1.2. We so can employ the followings, with any predicate (formula) and .

¬8x a` 9x¬
¬9x a` 8x¬
9x9y a` 9y9x

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 80

Assume further x is not free in , the followings are applied:

8x ^ a` 8x( ^ )
9x( ! ) a` ! 9x

———————————————————————————

BASIC LOGIC THEORY: Reviewed Homework

A) Summarized terms [ REF. 4: Chapter 2c]


Write down the explanations (in Vietnamese, or in English if possible) of the following terms,
find examples for each term, what are the differences between them:
1. fallacy, contradiction, paradox, counterexample;
2. premise, assumption, axiom, hypothesis, conjecture;
3. tautology, valid, contradiction, satisfiable; soundness, completeness;
4. sequent, consequence, implication, (semantic) entailment;

MATHEMATICAL MODELING Methods and Application


1.3. Predicate Logic- A Primer 81

5. argument, variable, arity.


B) Summarized notation [REF. 4: Chapter 2c]
What are the differences between the following notations: ’ !’, ’=)’, ’`’, ’|=’?
What are the differences between the following notations: ’ !’, ’()’, ’a`’, ’⌘’, ’=’?
Find examples to illustrate these differences.

C) Try the following problem within 1 hour at home.


An adequate set of connectives for propositional logic P is a set S such that for every
formula of P there is an equivalent formula with only connectives from S .
For example, the set S0 = {¬, _} is adequate for propositional logic.
1. Explain why we conclude that S0 = {¬, _} is adequate for propositional logic.
2. Show that S1 = {¬, ^}, S2 = {¬, !} are adequate sets of connectives for propositional
logic. Is {$, ¬} adequate? Prove your answer.
THE END of BASIC LOGIC THEORY

MATHEMATICAL MODELING Methods and Application


PART IV: Advanced Predicate Logic
1.4. Advanced Predicate Logic 83

1.4 Advanced Predicate Logic

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. )

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 84

1.4.1 Proof Theory of Predicate Logic

We discuss
Natural Deduction Rules
Quantifier Equivalences

Relationship between propositional and predicate logic:


1. If consider propositions as nullary predicates, then propositional logic is a sub-language of
predicate logic. Hence, by inheriting natural deduction we can translate the rules
for natural deduction in propositional logic directly to predicate logic.
2. The logic implication notation =) in propositional logic can be replaced by the (one-way)
sequent ` in predicate logic.

Natural Deduction Rules

Most used proof rules in predicate logic are the following.

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 85

1. Built-in Rules for Equality : Identical rule and Equality rule


2. Universal quantification
3. Existential Quantification

Explicitly we discuss one by one.


1. Built-in Rules
with Identical rule = i, formally written

=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]

1 f (x) = g(x) premise


2 h(f (x)) = h(f (x)) =i
3 h(g(x)) = h(f (x)) = e 1, 2
p
1. Built-in Rules
2. Universal quantification
2a/ Equality case 8x e

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.

⌥ EXAMPLE 1.18. for Universal quantification- 2a/ Equality case


MATHEMATICAL MODELING Methods and Application
1.4. Advanced Predicate Logic 87

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

2b/ Identical case : 8x i


If we manage to establish a formula about a fresh variable x0 ,
we can get the claim 8x .

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 88

' $

x0
..
.
[x ) x0]
& %
[8x i]
8x

⌥ EXAMPLE 1.19. for Universal quantification- 2b/ Identical case


h i
We prove 8x(P (x) ! Q(x)), 8xP (x) ` 8xQ(x) via the logic diagram

' $

x0
..
.
[x ) x0]
& %
[8x i]
8x

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 89

1 8x(P (x) ! Q(x)) premise


2 8xP (x) premise

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

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 90

' $

x0 [x ) x0]
..
9x .

& %
[9 e]

where is a logical conclusion.

⌥ EXAMPLE 1.20. for Existential Quantification

h i
8x(P (x) ! Q(x)), 9xP (x) ` 9x Q(x)

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 91

1 8x(P (x) ! Q(x)) premise


2 9xP (x) premise

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

Fix formulas 1, 2 of predicate logic.

A sequent 1 ` 2 means a provable implication 1 ! 2,

in oher words, 1 ! 2 is valid (a proof for it can be found). |

Fact 1.3.

1/ Two notations 1 ` 2 and 1 ) 2 are (equivalently) the same.

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 92

2/ We write 1 a` 2 (an equivalence of two predicate logic formulas) as


an abbreviation of 1 ` 2 and 2 ` 1.

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 ¬

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 93

3.
a/ 8x ^ 8x a` 8x ( ^ )

b/ 9x _ 9x a` 9x ( _ )

4. Assuming that x is not free in , then 8x ^ a` 8x ( ^ ).


[Here we see 8x ^ = (8x ) ^ .]
We next discuss semantics of predicate logic via the concept of model.

1.4.2 Model

Definition 1.21 (Model)

Let F contain function symbols and P contain predicate symbols.

A model M for (F, P) consists of:

1. A non-empty set A, the universe;

2. for each nullary function symbol f 2 F a concrete element f M 2 A;

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 94

3. for each f 2 F with arity n > 0, a concrete function f M : An ! A;

4. for each P 2 P with arity n > 0, a set P M ✓ An . |

⌥ EXAMPLE 1.21 ( See from Example 1.14).

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.

Let F = {z, s} and P = {}.


Let model M for (F, P) be defined as follows:
1. Let A be the set of natural numbers, so A = N;
2. let z M = 0;
3. let sM be defined as arity 1 function, from N1 ! N, such that s(n) = n + 1 [succesor
function];
4. let M be defined such that n1 M n2 iff the natural number n1 is less than or equal to
n2 . ⌅
In both examples we see that
(1) the set P of predicates has one element P =  only, and
(2) predicate P = has arity n = 2, could view P M =M as binary relation on {0, 1}⇤ and
on N.

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 96

| OBSERVATION 2. Generally, fix model M, let predicate P 2 P has arbitrary arity n then

(⌥) P M is a n-ary relation on A [see Item 4 of Definition 1.21].

1.4.3 Satisfaction Relation

Handling Free Variables


We can give meaning to formulas with free variables by providing
an environment (lookup table) that assigns variables to elements of our universe:

l : var ! A.

We define environment extension such that notation


l[x 7! a] is the environment that maps x to a and any other variable y to l(y).

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.

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 97

Definition 1.22 (Satisfaction of a formula by models)


|

The model M satisfies formula with respect to environment l,


written M |=l in the following cases.
1. formula is of the form P (t1 , t2 , . . . , tn ),
if the result (a1 , a2 , . . . , an ) of evaluating t1 , t2 , . . . , tn with respect to l is in P M ,
meaning P M (a1 , a2 , . . . , an ) is true;

2. has the form 8x , if the M |=l[x7!a] holds for all a 2 A;


3. has the form 9x , if the M |=l[x7!a] holds for some a 2 A;
4. has the form ¬ , if M |=l does not hold;
5. has the form 1 _ 2, if M |=l 1 holds or M |=l 2 holds;
6. has the form 1 ^ 2, if M |=l 1 holds and M |=l 2 holds; finally
7. has the form 1 ! 2, if M |=l 1 holds implying M |=l 2 holds.

⌥ EXAMPLE 1.23.

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 98

Define model M on two universes A1 = R (reals) and A2 = C (complexes),


with a predicate-form formula = P (x) = ‘x2 00 with arity 1,
and formulas 1 = 8x , and 2 = 9x .
Then M satisfies formula 1 on A1 , since M |=l holds for all a 2 A1 .
M does not satisfy 1 on A2 [with a counter example of a = i, i2 = 1?].
But M satisfies formula 2 on the complexes A2 , with respect to environment l
since M |=l holds for some a 2 A2 ; ... ⌅

Satisfaction of Closed Formula (one with no free variables)

If a formula has no free variables, we call a sentence.


M |=l either holds or does not hold for sentence regardless of the choice of l.
Thus we conclude M |= or M 6|= for any sentence .

Semantic Entailment, Satisfiability, and Validity

Let be a (possibly infinite) set of formulas in predicate logic and a formula 2 .

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 99

Definition 1.23 (Four concepts motivated by models)


|

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.4.4 Soundness and Completeness of Predicate Logic

Entailment ranges over models


Semantic entailment between sentences:

1, 2, . . . , n |=
requires that in all models that satisfy 1, 2, . . . , n, the sentence is satisfied.

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 100

How to effectively argue about all possible models?


Usually the number of models is infinite; it is very hard to argue on the semantic level in
predicate logic. Can we use natural deduction for showing entailment?

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.

Problems of Propositional and Predicate Logic:


Given a formula in propositional logic we can, in principle,
determine whether |= holds:
FACT: If has n propositional atoms, then the truth table of contains 2n lines; and
|= holds if, and only if, the column for (of length 2n ) contains only True entries.

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 101

Such a mechanical procedure cannot be provided in predicate logic.


The decision problem at hand is this: Validity in predicate logic.
Given a logical formula in predicate logic, does |= hold, yes or no?

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

It a question in some formal system with a yes-or-no answer.

2. Decidability:

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 102

Decision problems for which there is an algorithm

that returns “yes” whenever the answer to the problem is “yes”,

and that returns “no” whenever the answer to the problem is “no”,

are called decidable.

3. Decidability of satisfiability

The question, whether a given propositional formula is satisifiable, is decidable. |

In predicate logic, however, some negative results have been found.

Theorem 1.4 ( On Undecidability of Predicate Logic)

The decision problem of validity in predicate logic is undecidable:

No program exists which, given any language in predicate logic and

any formula in that language, decides whether |= . ~

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 103

The proof employs two concepts- problems: [follow A. Church’s proof]


1. Post Correspondence Problem
2. Turing machines.

STEPS of proving (sketch)


Establish that the Post Correspondence Problem (PCP) is undecidable
Translate an arbitrary PCP, say C , to a formula .
Establish that |= holds if and only if C has a solution.
Conclude that validity of pred. logic formulas is undecidable. (See more in Theorem 2.22-
REF. 2)
Undecidability of Post Correspondence Problem
Post Correspondence Problem (PCP): Can we line up copies of the cards such that the top
row spells out the same sequence as the bottom row?
Formalization: Given a finite sequence of pairs (s1 , t1 ), (s2 , t2 ), . . . , (sk , tk ) such that all si
and ti are binary strings of positive length, is there a sequence of indices i1 , i2 , . . . , in with

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 104

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 =

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 105

ti1 ti2 . . . tim .


4. Build the formula for solution C = = 1 ^ 2 ! 3, where

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.

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 106

Undecidability of Predicate Logic


The decision problem of validity in predicate logic is undecidable:
No program exists which, given any language in predicate logic and
any formula in that language, decides whether |= .

1.4.5 Compactness of Predicate Calculus

Proposition 1.1 ( Compactness Theorem)


Let be a set of sentences of predicate logic.

If all finite subsets of are satisfiable, then is satisfiable. [See Item 3 of Definition 1.23.]

Proof Use Method of Contradiction.


Assume is not satisfiable. [See Definition 1.23 Item 3 for Satisfiability of Formula
Set.] We thus have |= ? (contradiction). Via completeness, we have ` ?.
The proof is finite, thus only uses a finite subset ⇢ of premises.
Thus, ` ?, and |= ? via soundness [Kurt Gödel ’s Theorem]. ⌅

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 107

REMINDER: Required Texts/Materials


Electronic copies of [2-6] are available on the WWW
1. Handouts (Obtained via emails.)
2. Michael R.A. Huth and Mark D. Ryan.Logic in Computer Science (2nd Ed.), Cambridge Uni.
Press, 2004. (Ch. 1, 2)
3. Michael R.A. Huth and Mark D. Ryan. Logic in Computer Science: Solutions to designated
exercises (2nd Ed.), Cambridge University Press, 2004. (Chapters 1, 2)
4. F.R. Giordano, W.P. Fox & S.B. Horton,
A First Course in Mathematical Modeling, 5th ed., Cengage, 2014.
5. K. M. Bliss K. R. Fowler B. J. Galluzzo, Math Modeling: getting started & getting solutions.
Society for Industrial and Applied Mathematics (SIAM) Handbook, 2014.
6. Peter Linz. An Introduction to Formal Languages and Automata (3rd Ed.) Jones and
Bartlett, 2001. (Chap. 1-6)
An Introduction to Formal Languages and Automata: Instructors’ Manual (Chapters 1-6)
7. John Hopcroft et. al. Introduction to Automata Theory, Languages, and Computation (Cha
1-5)

MATHEMATICAL MODELING Methods and Application


1.4. Advanced Predicate Logic 108

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?

Logic for Program Verification, in Section 1.5

Hoare Triples and Partial and Total Correctness, Section 1.6

Practical Aspects of Correctness Proofs in Section 1.7

MATHEMATICAL MODELING Methods and Application


PART V: Logic for Program Verification

[[GoogleMap]]
1.5. Logic for Program Verification 110

1.5 Logic for Program Verification

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)

MATHEMATICAL MODELING Methods and Application


1.5. Logic for Program Verification 111

i
^ x > 0 ^ y > 0 ^ z > 0 ! xn + y n 6= z n .

INITIAL EXAMPLE on imperative programming language

A binary search function written in an imperative programming language:

bool binarySearch ( int [] a, int l, int u, int e)

{ if (l > u) return false ;

else {int m = (l + u) div 2;

if (a[m] == e) return true ;

else if (a[m] < e) return binarySearch (a, m + 1, u, e);

else return binarySearch (a, l, m - 1, e);}

| OBSERVATION 3.

As a first step towards determining whether an implementation (such as that in the function

MATHEMATICAL MODELING Methods and Application


1.5. Logic for Program Verification 112

above) fulfills its specification, the specification has to be formalized.


We do so in terms of preconditions and postconditions.

1.5.1 Preconditions and postconditions

Definition 1.25
A precondition specifies what should be true upon entering the function,

meaning, under what inputs the function is expected to work.

The postcondition is a formula G whose free variables include only

the formal parameters and

the special variable rv representing the return value of the function. |

The post-condition relates the function’s output (the rv ) to its input (the parameters).

| QUESTION.

Formulate in Predicate Logic the precondition/postcondition for binarySearch.

MATHEMATICAL MODELING Methods and Application


1.5. Logic for Program Verification 113

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).

1.5.2 Program verification: Why (Motivation) and What (Approaches)?

Favours of program verification include the following:


Documentation: The program’s formal specification is important because the logical struc-
ture and properties (theorems) typically serve as guiding principles for an implementation

MATHEMATICAL MODELING Methods and Application


1.5. Logic for Program Verification 114

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)

1. In approach a)- Proof-based checking, the verification method consists of trying


to find a proof that ` ', [provability, defined in Definition 1.20]
where is a set of formulas for the system description, and
formula ' represents the system specification.
2. In approach b)- Model checking- the system is represented by a model M for an appropriate
logic. The system specification is again represented by a formula ' and
the verification method consists of computing whether M satisfies ',
written M |= [i.e. M |=l , for certain environment l], see Definition 1.23.
3
such as nuclear power stations and aircraft cockpits.

MATHEMATICAL MODELING Methods and Application


1.5. Logic for Program Verification 115

Problems with the model checking approach:


Models become infinite.
Satisfaction/validity becomes undecidable.
In this part, we only cover a proof-based framework for program verification [to avoid
checking infinitely many models of a set of predicate logic formulas in order to establish the
validity of an Entailment M |= ].

1.5.3 Program Verification (PV): Characteristics and Framework

We consider few characteristics of PV as follows.


Semi-automatic: not always be carried out algorithmically by a computer
Property-oriented: verify properties of a program rather than a full specification of its be-
haviour
Application domain: use sequential programs (means that we assume the program runs on
a single processor and that there are no concurrency issues).

MATHEMATICAL MODELING Methods and Application


1.5. Logic for Program Verification 116

A framework for producing the software


1. Listen to all the requirements R [with informality info] from the customer,
2. Convert the informal description R into an ‘equivalent’ formula R, of some symbolic
logic,
3. Write a program P meeting/realizing R, in suitable programming environment,
4. Prove that P satisfies the formula R.

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.

What are the four steps? Which one is most critical? ⌅

1.5.4 Core programming language

Popular imperative programming languages consists of

MATHEMATICAL MODELING Methods and Application


1.5. Logic for Program Verification 117

assignments to integer- and boolean-valued variables,


if-statements, while-statements
and sequential compositions.

Core language (discussed in this section ) has three syntactic domains:


Arithmetic (integer) expressions, Boolean expressions and Commands [called programs].

Grammatical Points in Core Language (use Backus Naur form throughout)

1. Arithmetic expressions E :
E ::= n | x | ( E) | (E + E) | (E E) | (E ⇤ E)
2. Boolean expressions B :

B ::= true | false | (!B) | (B&B) | (BkB) | (E < E)


NOTE: Boolean expressions are built on top of integer expressions, why?
3. Command C [with expressions as its components]:

C ::= x = E | C; C | if B {C} else {C} | while B {C}

MATHEMATICAL MODELING Methods and Application


1.5. Logic for Program Verification 118

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.

MATHEMATICAL MODELING Methods and Application


PART VI: Hoare Triples

[Courtesy Andre Derain]


1.6. Hoare Triples - Partial and Total Correctness 120

1.6 Hoare Triples - Partial and Total Correctness

| 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.

We make the assertions, therefore of triplet forms,

(| |) 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.

MATHEMATICAL MODELING Methods and Application


1.6. Hoare Triples - Partial and Total Correctness 121

A state of a Core program P is a function l that assigns each variable x in P to an integer


l(x).

⌥ EXAMPLE 1.24. Consider the factorial function n!.


y = 1; z = 0;
while (z != x) { z = z + 1; y = y * z; }

We need to be able to say that at the end, y is x!


That means we require a post-condition y = x!
Do we need pre-conditions, too?
Yes, they specify what needs to be the case before execution.
Example: x > 0

⌥ 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|)

If define program P : y = 0 then

Our Hoare triple (|x > 0|) y = 0 (|y · y < x|)


Another example for program P
y = 0;
while (y * y < x) {
y = y + 1;
}
y = y - 1;

Then we get another Hoare triple

(|x > 0|) P (|y · y < x|)

REMINDER 1- Models in Predicate Logic:

MATHEMATICAL MODELING Methods and Application


1.6. Hoare Triples - Partial and Total Correctness 123

Let F contain function symbols and P contain predicate symbols.

A model M for (F, P) consists of:


1. A non-empty set A, the universe;
2. for each nullary function symbol f 2 F a concrete element f M 2 A;
3. for each f 2 F with arity n > 0, a concrete function f M : An ! A;
4. for each P 2 P with arity n > 0, a set P M ✓ An .
REMINDER 2: Satisfaction of a formula by models
The model M satisfies formula with respect to environment l, written M |=l :
in case is of the form P (t1 , t2 , . . . , tn ), if the result (a1 , a2 , . . . , an ) of evaluating t1 , t2 , . . . , tn
with respect to l is in P M , i.e. P M (a1 , a2 , . . . , an ) is true;

in case has the form 8x , if the M |=l[x7!a] holds for all a 2 A;


in case has the form 9x , if the M |=l[x7!a] holds for some a 2 A;

MATHEMATICAL MODELING Methods and Application


1.6. Hoare Triples - Partial and Total Correctness 124

in case has the form ¬ , if M |=l does not hold;


in case has the form 1 _ 2, if M |=l 1 holds or M |=l 2 holds;
in case has the form 1 ^ 2, if M |=l 1 holds and M |=l 2 holds; finally
in case has the form 1 ! 2, if M |=l 1 holds implying M |=l 2 holds.

Definition 1.26

An assertion of the form (| |) P (| |) is called a Hoare triple.

is called the precondition, is called the postcondition. |

A state of a Core program P is a function l that assigns each variable x in P to an inte-


ger l(x).
A state l satisfies precondition if 9 M : M |=l , where model M contains integers
and gives the usual meaning to the arithmetic operations. Write l |= .
Quantifiers in and bind only variables that do not occur in the program P .

⌥ 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)

1.6.1 Partial and total correctness

Regarding the termination of a program P in the Hoare triple (| |) P (| |) we study


1) partial correctness (means that we do not require the program to terminate), and
2) total correctness (we insist upon its termination).
Definition 1.27
|

1. We say that the triple (| |) P (| |) is satisfied under partial correctness if,


for all states which satisfy , the state resulting from P ’s execution satisfies ,
provided that P terminates. We write |=par (| |) P (| |).
2. We say that the triple (| |) P (| |) is satisfied under total correctness if,

MATHEMATICAL MODELING Methods and Application


1.6. Hoare Triples - Partial and Total Correctness 126

for all states which satisfy ,


P is guaranteed to terminate and the resulting state satisfies .
We write |=tot (| |) P (| |).
⌥ EXAMPLE 1.27 (Partial correctness).

The Hoare triple (| |) while true { x = 0; } (| |) holds for all and .

⌥ EXAMPLE 1.28 (Total correctness ).

Consider program P (x) = Fac1(x):


y = 1;
z = 0;
while (z != x) { z = z + 1; y = y * z; }

Note: > means tautology, [and ? means contradiction].


|=tot (|x 0|) Fac1 (|y = x!|)
6|=tot (|>|) Fac1 (|y = x!|)

|=par (|x 0|) Fac1 (|y = x!|)


MATHEMATICAL MODELING Methods and Application
1.6. Hoare Triples - Partial and Total Correctness 127

|=par (|>|) Fac1 (|y = x!|)

1.6.2 Proof Calculus for Partial Correctness

If the partial correctness of triples (| |) P (| |) can be proved in the partial-correctness


calculus, we say that the sequent `par (| |) P (| |) is valid. In other words,
`par (| |) P (| |) means it is provably correct according to our calculus, being developed
now. We look for a proof calculus that allows us to establish

`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

MATHEMATICAL MODELING Methods and Application


1.6. Hoare Triples - Partial and Total Correctness 128

(| |) 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.

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 129

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 (| |)

⌥ EXAMPLE 1.29 (On Assignment).

Let P be the program x = x + 1. Using rule (2) of Assignment


we can prove:
(|x + 1 = 2|) P (|x = 2|)
(|x + 1 = y|) P (|x = y|)

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 130

1.7 Practical Aspects of Correctness Proofs

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.

1.7.1 Proof Tableaux

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 :

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 131

(| 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.

⌥ EXAMPLE 1.30. Consider the following proof tableaux:

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 132

(|y < 3|)


(|y + 1 < 4|) Implied
y = y + 1;
(|y < 4|) Assignment
1. Can we claim u = x + y after z = x; z = z + y; u = z; ?

(|>|)
(|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

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 133

1.7.2 An Alternative Rule for If

We have:
(| ^ B|) C1 (| |) (| ^ ¬B|) C2 (| |)
[If-statement]
(| |) if B { C1 } else { C2 } (| |)

Sometimes, the following derived rule is more suitable:

(| 1|) C1 (| |) (| 2|) C2 (| |)
[If-Statement 2]
(|(B ! 1) ^ (¬B ! 2 )|) if B { C1 } else { C2 } (| |)

⌥ EXAMPLE 1.31. Consider this implementation of program Succ: [input x?]

a = x + 1;
if (a - 1 == 0) {y = 1;}
else {y = a;}

Can we prove (|>|) Succ (|y = x + 1|) ?

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 134

GUIDANCE for solving.

This program is the sequential composition of an assignment and an if-statement.


We push the postcondition (here y = x + 1) upwards through branches Ci of the if-
statement, get the results i. Thus, we need to obtain a suitable midcondition to put be-
tween
the if-statement and the assignment. Indeed, let
8
< 1 : 1 = x + 1;
: : a = x + 1;
2

we obtain the midcondition (|(a 1 = 0 ! 1 = x + 1) ^ (¬(a 1 = 0) ! a = x + 1)|).


We just calculated the weakest = (B ! 1) ^ (¬B ! 2)

such that we get the postcondition by the If-Statement 2


(| 1|) C1 (| |) (| 2|) C2 (| |)
[.]
(|(B ! 1) ^ (¬B ! 2 )|) if B { C1 } else { C2 } (| |)
The partial proof now looks like this:

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 135

..
.
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

We finally push the long formula (midcondition) above the if-statement


through the assignment a = x + 1!, to obtain the proof

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 136

(|>|)
(|(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

1.7.3 Correctness of the Factorial Function

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 137

Partial-while Rule Revisited

(| ^ B|) C (| |)
[Partial-while]
(| |) while B { C } (| ^ ¬B|)

ELUCIDATION: In the premise (| ^ B|) C (| |), the formula is chosen to be an


invariant of the body C of the while-statement: provided the boolean guard B is true, if is
true before we start C , and C terminates, then it is also true at the end.

⌥ EXAMPLE 1.32 (Factorial Example).

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; }

Thus, to show (|>|) Fac1 (|y = x!|) we begin with

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 138

..
.
(|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

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 139

(|>|)
(|(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 ⌅

1.7.4 Proof Calculus for Total Correctness

We just developed a calculus for proving partial correctness of triples

(| |) P (| |).

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 140

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.

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 141

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. ⌅

⌥ EXAMPLE 1.33 (Factorial revisited).

y = 1; z = 0;
while (z != x) { z = z + 1; y = y * z; }

What could be a good variant E ?

E must strictly decrease in the loop, but not become negative. Answer: E ⌘ x z
When it is 0, the while-statement terminates. ⌅

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 142

RULES: We describe this intuition in the following rules.


(| ^ B|) C (| |)
[Partial-while, recalled]
(| |) while B { C } (| ^ ¬B|)

(| ^ B ^ 0  E = E0|) C (| ^ 0  E < E0|)


[Total-while]
(| ^ 0  E|) while B { C } (| ^ ¬B|)

The is called the invariant, the expression E is called variant.


In the 2nd rule, E is the expression whose value decreases with each execution of the body
C . This is coded by saying that,
if its value equals that of the logical variable E0 before the execution of C ,
then it is strictly less than E0 after it – yet still it remains non-negative.
* NOTE: in practical computation, as in Econometric or Data analytics, with real numbers,
E does not need to be integer expression, E can be real expression.
Total Correctness of Fac1

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 143

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

(| ^ B ^ 0  E = E0|) C (| ^ 0  E < E0|)


Let us illustrate this rule by proving that `tot (|x 0|) Fac1 (|y = x!|) is valid.
We knew that E ⌘ x z is a suitable variant. The invariant (y = z!) of the partial correctness
proof is retained. We obtain the following proof

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 144

..
.
(|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:

MATHEMATICAL MODELING Methods and Application


1.7. Practical Aspects of Correctness Proofs 145

(|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

Hence, `tot (|x 0|) Fac1 (|y = x!|) is valid. ⌅

FINAL COMMENTS

MATHEMATICAL MODELING Methods and Application


1.8. HOMEWORK and Chapter Problems 146

1. The precondition x 0 is crucial in securing the fact that


0x z holds right before the while-statements gets executed: it implies the precon-
dition (|(1 = 0! ^ 0  x 0|) computed, and the program must terminate because z
certainly meets x.

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.

1.8 HOMEWORK and Chapter Problems

1. Do all HWs which have not been done in previous lectures.

MATHEMATICAL MODELING Methods and Application


1.8. HOMEWORK and Chapter Problems 147

2. Try to understand deeply the following notations/terms


arity, expression, term, formula, atomic formula, sentence, clause, Backus Naur form (BNF),
parse tree, precondition, postcondition, binding priorities, provability, witness, scope, bound,
verification, model checking, Hoare triple, and their other related notation/terms.
3. Do exercise 1.5.14 on page 89 in [2].
4. Consider the following program

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]:

MATHEMATICAL MODELING Methods and Application


1.8. HOMEWORK and Chapter Problems 148

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).

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)]

MATHEMATICAL MODELING Methods and Application


1.8. HOMEWORK and Chapter Problems 149

3. 8x [P rize(x) ! 9y (Boy(y) ^ W in(y, x))]


4. and 5. DIY

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.

3. All fathers are parents.


4. No uncle is an aunt.

5. Ed and Patsy are husband and wife.

MATHEMATICAL MODELING Methods and Application


6. Carl is Monique’s brother-in-law.

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

1.1 Connectives and associated symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11


1.2 Connective and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

MATHEMATICAL MODELING Methods and Application


An Introduction to Generalized Linear Models,
Third Edition, CRC (2008)
Bibliography
[4] Antal Kozak, Robert A. Kozak, Christina L. Staud-
hammer, Susan B. Watts Introductory Probability
[1] Stein W. Wallace and William T. Ziemba, Editors, and Statistics Applications for Forestry and Natu-
Applications of stochastic programming MPS- ral Sciences, CAB International (2008)
SIAM (Society for Industrial and Applied Mathe-
matics and the Mathematical Programming Soci- [5] Canvas paintings by Australian artists of ethnic mi-
ety) series on optimization, 2005 norities, Australian National Museum

[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-

Annette J. Dobson and Adrian G. Barnett, tific, 1997

An Introduction to Generalized Linear Models,


[8] U. N. Bhat. A controlled transportation queueing
Third Edition, CRC (2008)
process. Management Science, 16(7): 446-452,
[3] Annette J. Dobson and Adrian G. Barnett, 1970.

MATHEMATICAL MODELING Methods and Application


BIBLIOGRAPHY 154

[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,

[12] Esra Koca et. al. Two-stage stochastic facility loca-


Modern Mathematical Statistics with Applications,
tion problem with disruptions and restricted short-
2nd Edition, Springer (2012)
ages, Journal of Computers & Industrial Engineer-
ing, vol 183, Elsevier (2023)
[17] Glonek G.F.V. and Solomon P.J. Factorial and time
[13] Man VM Nguyen. Data Analytics Foundation: course designs for cDNA microarray experiments,
Inference, Regression & Stochastic Processes. Biostatistics 5, 89-111, 2004.

MATHEMATICAL MODELING Methods and Application


BIBLIOGRAPHY 155

[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

Introduction to Mathematical Statistics, Seventh


[26] Paul Mac Berthouex, Linfield C. Brown, Statistics
Edition Pearson, 2013.
for Environmental Engineers, 2nd Edition, LEWIS
PUBLISHERS, CRC Press, 2002
[20] David Ruppert and David S. Matteson. Statistics
and Data Analysis for Financial Engineering with [27] Madhav, S. P., Quality Engineering using robust
R examples, Second Edition. Springer (2015) design, Prentice Hall, 1989.

[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.

MATHEMATICAL MODELING Methods and Application


BIBLIOGRAPHY 156

[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

MATHEMATICAL MODELING Methods and Application


BIBLIOGRAPHY 157

[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-

MATHEMATICAL MODELING Methods and Application


mann, Hans Singular- a computer alge- http://www.singular.uni-kl.de
bra system for polynomial computations,

You might also like