# Download logic in computer science: lecture 1

Survey
Was this document useful for you?
Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
```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)
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 —
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 —
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 complex systems (both harware and software).
Many people are employed in applied logic, particularly in England, Germany, France and the United States.
—3 —
ROLES OF LOGIC
Descriptive
I Propositional logic, e.g., circuits
I Predicate logic, e.g., theorems
Values T, F or 0, 1
Values from a set, e.g., N
I 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 —
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 statements 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 —
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 —
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- model, consequence, vation, ` p
lidity, |= p, Alfred Tarski
(1902–83) 1933
premises : allegedproof → statements∗
conclusion : allegedproof → statements
checkproof : allegedproof → bool
computable!
—7 —
THREE WORLDS, TWO VIEWS ON MODELING
'
\$
Engineering
*
&
'
\$
The real world
&
“model”
in the
-
sense
of science
%
HH
%
HH
H
HH
H
'
\$
World of
models,
meanings
&
M
HH
H '
HH
j
H
“model”
in the
sense
of logic
%
|=
\$
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 —
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 —
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 Gödel proved equivalence on universal models, but
I Gödel 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 —
PROPOSITIONAL LOGIC
Judgements formed with propositional variables p, q, r, p1, . . ., and operators:
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 =, ≡, ⇔, ↔.
W
Tautology 1, T, , >
— 11 —
NATURAL DEDUCTION
A sequent φ1, . . . , φn ` ψ
Gerhard Gentzen (1909–45)
The rules for conjunction
φ
ψ
φ∧ψ
∧i
φ∧ψ
φ
Example 1.4: p ∧ q, r ` q ∧ r
∧e1
φ∧ψ
ψ ∧e2
Proof trees
p∧q
∧e2
q
q∧r
Proofs in linear form
1 p ∧ q premise
2 r
premise
3 q
∧e2 1
4 q ∧ r ∧i 3,2
— 12 —
q
∧i
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 —
IMPLICATION
Modus ponens (MP)
φ→ψ
φ
→e
ψ
p, p → q, p → (q → r) ` r
Introduce →:
φ
..
ψ
φ→ψ
→i
Modus tollens (MT)
φ→ψ
¬ψ
¬φ
Example 1.7: p → (q → r), p, ¬r ` ¬q
MT
Example 1.8: ¬p → q, ¬q ` p; p → ¬q, q ` ¬p
— 14 —
EXAMPLE 1.9
¬q → ¬p ` p → ¬¬q
1
2
3
4
5
¬q → ¬p premise
p
assumption
¬¬p
¬¬i 2
¬¬q
MT 1,3
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 —
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 —
NEGATION
⊥
φ
⊥e
¬φ
φ
Example 1.20: ¬p ∨ q ` p → q
¬e
⊥
φ
..
⊥
¬φ
¬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 —
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 —
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 —
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
√
√ √2
1. a = b = 2, if 2 is rational, and
√ √2
√
2. a = 2 , b = 2 otherwise.
— 20 —
```
Related documents