You are on page 1of 21

LOGIC IN COMPUTER SCIENCE: LECTURE 1

Neil D. Jones

DIKU 2005 Supplementary notes: see web page Some slides today based on Nils Andersens (from 2004)

PRACTICAL DETAILS ABOUT THE COURSE


Book: Logic in Computer Science 2nd Edition; by Michael Huth and Mark Ryan, Cambridge University Press, 2004. The book has a WWW tutor page. Mondays: lecture 09:15-11:00 Wednesdays 09:15-12:00: 2 hours lecture, 1 hour discussion, eg exercises 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) Final exam optional, if you wish credit with a grade on the 13-scale. Week 44 (31 October or 2 November)

INTRODUCTION. PROPOSITIONAL LOGIC


Why learn logic ? History of logic Formal logic as a science The three worlds: The real world Proofs and theorems Models and validity Today: begin Propositional logic Sentences Natural deduction

WHY LEARN LOGIC ?


Correctness of constructed systems: telephones, computers (eg CPUs, oating point, cache, etc.), control systems for autos (e.g., ABS, emissions), factories, power plants (including nuclear), computer graphics, etc, etc, etc. Traditional approach: debugging. (Build it rst, then test, then release.) Problem: too late, e.g., correcting an already-constructed system can be expensive (eg, the Pentium oating-point unit asco) or impossible (eg, an auto ABS system, airplane control, nuclear plant) 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 Propositional logic, e.g., circuits Predicate logic, e.g., theorems Temporal logic, e.g., protocols, systems Analysis Test freedom from errors, race conditions,. . . Test other well-behavedness, e.g., of code from WWW Test correctness with respect to specications Test equivalence, e.g., of circuits Synthesis Transformation: Specication Implementation Formal reasoning, proofs Values T, F or 0, 1 Values from a set, e.g., N Mainly control ow

LOGIC IN ANTIQUITY
The science of inferring correctly. Some conclusions only depend on the form of the argument and not on the actual contents. Doesnt deal with how humans think (psychology) or whether the statements actually agree with facts (theory of knowledge). Socrates (approx. 469399), Plato (427347), Aristotle (384322). All M are P All S are M All S are P Syllogisms Four kinds of statements: All/Some . . . are/are not . . . two premises, a conclusion (256 modes, 19 (15) valid ones).
5

All P are M Some S are not M Some S are not P

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: suciency (expressibility): Has formulas for the items that interest us. necessity : No superuous 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 (16461716). George Boole (181564). Gottlob Frege (18481925). Guiseppe Peano (18581932). Bertrand Russell (1872 1970). Alfred North Whitehead (18611947). Michael R.A. Huth, Mark D. Ryan, Logic in Computer Science: Modelling and reasoning about systems, Cambridge University Press 2004. Symbols, formalism proof, theorem, deduc- model, consequence, vation, p lidity, |= p, Alfred Tarski (190283) 1933 premises : allegedproof statements conclusion : allegedproof statements checkproof : allegedproof bool
7

Real world (objects)

computable!

THREE WORLDS, TWO VIEWS ON MODELING


' $

Engineering
$ * & ' HH % HH H HH H $ HH H ' HH j H

'

The real world


&

model in the
-

sense of science %

World of models, meanings


&

model in the


sense of logic % |=

World of logical formulas


&

Left side: scientic experiments, measurements, what is out there? Purpose: analytic, to understand nature. Right side: specications to dene what is to be done! Purpose: synthetic, to construct systems.
8

MODEL THEORY VERSUS PROOF THEORY


M |= Model (or system) M satises statement (a formula) - This says something about how system M behaves - It is about validity or truth (Alfred Tarski, 1930s) Model M satises 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: Soundness: implies |=: What can be is true. : What is true can be proven.

Completeness: |= implies

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

and |= are undecidable. Further, G odel proved equivalence on universal models, but G odel also proved that is weaker than |= for arithmetic (the natural numbers)

Model checking via temporal logic: Weaker than Predicate logic (formulas have no variables) Stronger in another way (temporal operator like Finally)) There are several dierent temporal logics Designed so that equals |=

- and there exist ecient 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, , , (bottom) Priorities: binds tighter than {, }, We dont decide on a priority between and .) Other logical operators: Exclusive disjunction +, . Equivalence =, , , . Tautology 1, T, ,

11

NATURAL DEDUCTION
A sequent 1, . . . , n Gerhard Gentzen (190945) The rules for conjunction Example 1.4: p q, r Proof trees
pq e2 q q i

i
e2

qr
e1

qr Proofs in linear form 1 p q premise 2 r premise 3 q e2 1 4 q r i 3,2


12

THE RULES OF DOUBLE NEGATION



i e

(Later we shall see that the second rule can be derived from other rules.) Example 1.5: p, (q r ) p r qs

Example 1.6: (p q ) r, s t

13

IMPLICATION
Modus ponens (MP) p, p q, p (q r ) Introduce : . . Modus tollens (MT) Example 1.7: p (q r ), p, r q Example 1.8: p q, q p; p q, q
14
i e

MT

EXAMPLE 1.9

q p q p premise p assumption p i 2 q MT 1,3 p q i 3,2

p q

1 2 3 4 5

Example 1.11:

(q r ) ((q p) (p r )) p (q r )

Example 1.131.14: p q r Example 1.15: p q

pr qr

15

DISJUNCTION
. . pq qp pq pr p (q r ) (p q ) (p r )
16
i1

i2

. .
e

Example 1.16: q r

Example 1.17: (p q ) r Example 1.18: p (q r )

NEGATION
Example 1.20: p q pq . . Example 1.21: p q, p q
i e

p; p p q q

Example 1.22: p (q r ), p, r Example 1.23: p q r, r, p

17

DERIVED RULES

i

MT

Reductio ad absurdum is PBC, Proof By Contradiction: . . Tertium non datur (LEM, law of the excluded middle) Example 1.24: p q p q
18
LEM PBC

PROVABLE EQUIVALENCE
(p q ) (p q ) pq pq pq p pq r p q p q q p p q r r p (q r )

19

INTUITIONISTIC LOGIC
Luitzen Egbertus Jan Brouwer (18811966) 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

You might also like