logic in computer science: lecture 1 -...
TRANSCRIPT
![Page 1: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/1.jpg)
LOGIC IN COMPUTER SCIENCE: LECTURE 1
Neil D. Jones
DIKU 2005
I Supplementary notes: see web page
I Some slides today based on Nils Andersens’ (from 2004)
![Page 2: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/2.jpg)
PRACTICAL DETAILS ABOUT THE COURSE
I Book: Logic in Computer Science 2nd Edition; by Michael Huth and
Mark Ryan, Cambridge University Press, 2004.
I The book has a WWW tutor page.
I Mondays: lecture 09:15-11:00
I Wednesdays 09:15-12:00:
• 2 hours lecture,
• 1 hour discussion, eg exercises
I Exercises assigned Monday and/or Wednesday, due following Monday
(not optional, 5 out of 7 sets must be accepted for 7.5 ECTS points
course credit)
I Final exam optional, if you wish credit with a grade on the 13-scale.
Week 44 (31 October or 2 November)
— 1 —
![Page 3: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/3.jpg)
INTRODUCTION. PROPOSITIONAL LOGIC
I Why learn logic ?
I History of logic
I Formal logic as a science
I The three worlds:
• The real world
• Proofs and theorems
• Models and validity
I Today: begin Propositional logic
• Sentences
• Natural deduction
— 2 —
![Page 4: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/4.jpg)
WHY LEARN LOGIC ?
Correctness of constructed systems: telephones,
computers (eg CPUs, floating point, cache, etc.),
control systems for autos (e.g., ABS, emissions),
factories,
power plants (including nuclear),
computer graphics, etc, etc, etc.
I Traditional approach: debugging. (Build it first, then test, then release.)
I Problem: too late, e.g., correcting an already-constructed system can be
• expensive (eg, the Pentium floating-point unit fiasco) or
• impossible (eg, an auto ABS system, airplane control, nuclear plant)
I Prevention (of bugs) is better than cure
Applied logic is showing its worth for describing, building and analysing com-
plex systems (both harware and software).
Many people are employed in applied logic, particularly in England, Ger-
many, France and the United States.
— 3 —
![Page 5: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/5.jpg)
ROLES OF LOGIC
Descriptive
I Propositional logic, e.g., circuits Values T, F or 0, 1
I Predicate logic, e.g., theorems Values from a set, e.g., NI Temporal logic, e.g., protocols, systems Mainly control flow
Analysis
I Test freedom from errors, race conditions,. . .
I Test other well-behavedness, e.g., of code from WWW
I Test correctness with respect to specifications
I Test equivalence, e.g., of circuits
Synthesis
I Transformation: Specification ⇒ Implementation
I Formal reasoning, proofs
— 4 —
![Page 6: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/6.jpg)
LOGIC IN ANTIQUITY
The science of inferring correctly. Some conclusions only depend on the
form of the argument and not on the actual contents.
Doesn’t deal with how humans think (psychology) or whether the state-
ments actually agree with facts (theory of knowledge).
Socrates (approx. 469–399), Plato (427–347), Aristotle (384–322).
All M are P
All S are M
All S are P
All P are M
Some S are not M
Some S are not P
Syllogisms
Four kinds of statements:
All/Some . . . are/are not . . .
two premises, a conclusion (256 “modes”, 19 (15) valid ones).
— 5 —
![Page 7: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/7.jpg)
LOGIC SYSTEMS
Formalism.
A “game” with symbols
The actual (or
imagined) world
Logic ⊆ Philosophy, Logic ⊆ Mathematics.
Circularity? Mathematics used in logic, but logic used in (or even founding?)
mathematical reasoning.
Desirable properties of a formal system:
sufficiency (expressibility): Has formulas for the items that interest us.
necessity : No superfluous symbols or notions.
consistency : Two contradictory statements never concluded.
soundness : Only true statements concluded.
completeness : All true statements concluded.
decidability : Checkable if a statement is concluded or not.
— 6 —
![Page 8: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/8.jpg)
MODERN FORMAL LOGIC
Gottfried Wilhelm Leibniz (1646–1716). George Boole (1815–64). Gottlob
Frege (1848–1925). Guiseppe Peano (1858–1932). Bertrand Russell (1872–
1970). Alfred North Whitehead (1861–1947).
Michael R.A. Huth, Mark D. Ryan, Logic in Computer Science: Modelling
and reasoning about systems, Cambridge University Press 2004.
Symbols, formalism Real world (objects)
proof, theorem, deduc-
tion, ` pmodel, consequence, va-
lidity, |= p, Alfred Tarski
(1902–83) 1933
premises : allegedproof → statements∗
conclusion : allegedproof → statements
checkproof : allegedproof → bool computable!
— 7 —
![Page 9: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/9.jpg)
THREE WORLDS, TWO VIEWS ON MODELING
'&
$%
Engineering
������
������
��* HHHHH
HHHHHH
HHHj'
&
$
%
The real world
“model”in the
-
senseof science
'
&
$
%
“model”in the�
senseof logic
'
&
$
%
World of
models,
meanings
M |= φ
'
&
$
%
World of
logical
formulas
I Left side: scientific experiments, measurements, what is “out there”?
Purpose: analytic, to understand nature.
I Right side: specifications to define what is to be done!
Purpose: synthetic, to construct systems.
— 8 —
![Page 10: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/10.jpg)
MODEL THEORY VERSUS PROOF THEORY
M |= φ Model (or system) M satisfies statement φ (a formula)
- This says something about how system M behaves
- It is about validity or truth (Alfred Tarski, 1930s)
Γ ` φ Model M satisfies formula φ
- This says that formula φ can be proven from assumptions Γ
(dates back to the ancient Greeks)
- It is about a formal system, not about truth
Amazingly, these two approaches are often equivalent:
One can prove: true properties about systems
by means of : formal manipulation of symbols
This is the central point of this course.
(in spite of what sometimes looks like pedantic symbol pushing.)
— 9 —
![Page 11: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/11.jpg)
MODELING (|=) VERSUS PROVING (`)
A major theme is the equivalence of the two:
I Soundness: ` implies |=: What can be is true.
I Completeness: |= implies `: What is true can be proven.
Propositional logic: ` is equivalent to |=, but nontrivial (in spite of the simplicity of truth
tables). Reason: SAT is NP-hard.
Predicate logic: ` is equivalent to |=. However
I ` and |= are undecidable. Further,
I Godel proved equivalence on universal models, but
I Godel also proved that ` is weaker than |= for arithmetic (the natural numbers)
Model checking via temporal logic:
I Weaker than Predicate logic (formulas have no variables)
I Stronger in another way (temporal operator like “Finally”))
I There are several different temporal logics
I Designed so that ` equals |=
I - and there exist efficient algorithms called model checkers
— 10 —
![Page 12: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/12.jpg)
PROPOSITIONAL LOGIC
Judgements formed with propositional variables p, q, r, p1, . . ., and opera-
tors:
Negation φ, −φ, ¬φ
Disjunction Classically exclusive (lat. aut . . . aut . . . ), now always inclusive
(lat. vel . . . vel . . . ), φ v ψ, φ ∨ ψ, φ+ ψ
Conjunction φ & ψ, φ · ψ, φψ, φ ∧ ψ
Implication φ ⊃ ψ, φ < ψ, φ ⇒ ψ, φ → ψ
Absurdity, contradiction 0, F, 6 ◦, Λ, ⊥ (bottom)
Priorities: ¬ binds tighter than {∨, ∧}, We don’t decide on a priority
between ∧ and ∨.)
Other logical operators:
Exclusive disjunction +, ⊕. Equivalence =, ≡, ⇔, ↔.
Tautology 1, T,∨
, >
— 11 —
![Page 13: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/13.jpg)
NATURAL DEDUCTION
A sequent φ1, . . . , φn ` ψGerhard Gentzen (1909–45)
The rules for conjunctionφ ψ
φ ∧ ψ∧i
φ ∧ ψφ
∧e1φ∧ψψ ∧e2
Example 1.4: p ∧ q, r ` q ∧ r
Proof trees
p∧qq
∧e2 q
q ∧ r∧i
Proofs in linear form1 p ∧ q premise
2 r premise
3 q ∧e2 1
4 q ∧ r ∧i 3,2
— 12 —
![Page 14: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/14.jpg)
THE RULES OF DOUBLE NEGATION
¬¬φφ
¬¬e
φ
¬¬φ¬¬i
(Later we shall see that the second rule can be derived from other rules.)
Example 1.5: p,¬¬(q ∧ r) ` ¬¬p ∧ r
Example 1.6: (p ∧ q) ∧ r, s ∧ t ` q ∧ s
— 13 —
![Page 15: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/15.jpg)
IMPLICATION
Modus ponens (MP)φ φ → ψ
ψ→e
p, p → q, p → (q → r) ` r
Introduce →:
φ...
ψ
φ → ψ→i
Modus tollens (MT)φ → ψ ¬ψ
¬φMT
Example 1.7: p → (q → r), p,¬r ` ¬q
Example 1.8: ¬p → q,¬q ` p; p → ¬q, q ` ¬p
— 14 —
![Page 16: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/16.jpg)
EXAMPLE 1.9
¬q → ¬p ` p → ¬¬q
1 ¬q → ¬p premise
2 p assumption
3 ¬¬p ¬¬i 2
4 ¬¬q MT 1,3
5 p → ¬¬q →i 3,2
Example 1.11: ` (q → r) → ((¬q → ¬p) → (p → r))
Example 1.13–1.14: p ∧ q → r a` p → (q → r)
Example 1.15: p → q ` p ∧ r → q ∧ r
— 15 —
![Page 17: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/17.jpg)
DISJUNCTION
φ
φ ∨ ψ∨i1
ψ
φ ∨ ψ∨i2
φ ∨ ψ
φ...
χ
ψ...
χ
χ∨e
p ∨ q ` q ∨ p
Example 1.16: q → r ` p ∨ q → p ∨ r
Example 1.17: (p ∨ q) ∨ r ` p ∨ (q ∨ r)
Example 1.18: p ∧ (q ∨ r) ` (p ∧ q) ∨ (p ∧ r)
— 16 —
![Page 18: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/18.jpg)
NEGATION
⊥φ
⊥e
φ ¬φ⊥
¬e
Example 1.20: ¬p ∨ q ` p → q
φ...
⊥
¬φ¬i
Example 1.21: p → q, p → ¬q ` ¬p; p → ¬p ` ¬p
Example 1.22: p → (q → r), p,¬r ` ¬q
Example 1.23: p ∧ ¬q → r,¬r, p ` q
— 17 —
![Page 19: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/19.jpg)
DERIVED RULES
φ → ψ ¬ψ¬φ
MT
φ
¬¬φ¬¬i
Reductio ad absurdum is PBC, Proof By Contradiction:
¬φ...
⊥
φPBC
Tertium non datur (LEM, law of the excluded middle)
φ ∨ ¬φLEM
Example 1.24: p → q ` ¬p ∨ q
— 18 —
![Page 20: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/20.jpg)
PROVABLE EQUIVALENCE
¬(p ∧ q) a` ¬p ∨ ¬q¬(p ∨ q) a` ¬p ∧ ¬q
p → q a` ¬q → ¬p
p → q a` ¬p ∨ q
p ∧ q → p a` r ∨ ¬r
p ∧ q → r a` p → (q → r)
— 19 —
![Page 21: LOGIC IN COMPUTER SCIENCE: LECTURE 1 - CNRresist.isti.cnr.it/free_slides/mathematical/lawall/IntroSlides.pdf · LOGIC IN COMPUTER SCIENCE: LECTURE 1 Neil D. Jones DIKU 2005 I Supplementary](https://reader033.vdocuments.site/reader033/viewer/2022052607/5a7856637f8b9aea3e8eb7e5/html5/thumbnails/21.jpg)
INTUITIONISTIC LOGIC
Luitzen Egbertus Jan Brouwer (1881–1966)
Intuitionists claim PBC, LEM, ¬¬e are invalid.
Theorem 1.26: There exist positive irrational numbers a and b such that ab
is a rational number.
Proof (not intuitionistically valid):
Choose
1. a = b =√
2, if√
2√
2is rational, and
2. a =√
2√
2, b =
√2 otherwise.
— 20 —