CS101C Type Theory and Formal Methods · Admin email: [email protected] Mailing list:...

15
CS101C Type Theory and Formal Methods Aleksey Nogin C A L I F O R N I A I N S T I T U T E O F T E C H N O I L O G Y Lecture 1 March 31, 2003 CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 1/15

Transcript of CS101C Type Theory and Formal Methods · Admin email: [email protected] Mailing list:...

Page 1: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

CS101C

Type Theoryand Formal Methods

Aleksey Nogin

CALIFORNIAIN

STITUTE OF TECH

NOILOGY

Lecture 1

March 31, 2003

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 1/15

Page 2: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Quick Information

Time: MW 14:00 – 14:55Place: Jorgensen 74Instructor: Aleksey NoginTA: Xin YuOffice Hours: TBAUnits: 9 (2+3+4), pass/fail or letter gradeGrading: Homeworks (possibly final project)Course Home Page: http://nogin.org/cs101c/

Admin email: [email protected]

Mailing list: [email protected]

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 2/15

Page 3: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Formal MethodsFormal Methods is a science of mathematically describing andreasoning about computer-based systems (including hardwareand software).

Formal Methods help in the reduction of errors introduced into asystem, particularly at the earlier stages of design.

(From WWW Virtual Library — http://www.afm.sbu.ac.uk/)

This course will focus on Logic and Computer-Aided Reasoningsides of Formal Methods.

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 3/15

Page 4: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Pentium FDIV Bug

One of the most famous and most expensive bugs.

Pentium FDIV Bug (1994) cost Intel $475,000,000.

It highlighted the need for formal verification.

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 4/15

Page 5: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Four Color Theorem

The first proof of the Four Color Theorem (Appel andHaken, 1976) involved two programs and about 1200 hours(50 days) of CPU time.

Many mathematicians were at first very skeptical about theproof.

It turned out that one of the programs had a small bug (but aconservative one).

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 5/15

Page 6: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Formal MethodsFormal Methods are widely used in:

Hardware verification: Intel, Motorola, AMD, HP, etc. Verifyingfloating point units is especially popular.

Software verification: Microsoft, NASA, etc.

Formal mathematics

Education

Other areas

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 6/15

Page 7: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Potential of FormalMethods

While the impact of formal methods is often limited, they havea great potential — far beyond what is possible today.

Hardware: ability to handle whole chips, not just individualunits.

Software: ability to handle large programs with complexstructure.

Formal tools: accessible to ordinary engineers, not justthose with a PhD.

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 7/15

Page 8: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Focusing onUnderstanding

Currently most of the applications of formal methods focuson correctness (and sometimes on debugging).

However a bigger value of formal methods is in being ableto better understand the artifacts (uncover hiddenassumptions, etc) we are working with and in using thisknowledge during design and development.

Example: Ensemble verification project at Cornell.

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 8/15

Page 9: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

ProofsWhat is a proof?

Proof is a sequence of statements, where each one is either anaxiom or follows from previous statements in the proof using arule of inference.

Example

1. Socrates is a human (AXIOM).

2. All humans are mortal (AXIOM).

3. Socrates is mortal (FOLLOWS FROM (1) AND (2)).

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 9/15

Page 10: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Language ofPropositional Logic

> “True”⊥ “False”

A, B, C . . . variablesA ∨ B “A or B”A ∧ B “A and B”A ⇒ B “A implies B”¬A “not A”

In classical logic, each variable (and each formula) alwaysstands for either True or False.

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 10/15

Page 11: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Sequents

A sequent “A1; A2; . . . ; An ` C stands for “If all thehypotheses A1, A2, . . . , An are true, then the conclusion C

must be true as well.”

We will use Greek letters Γ, ∆, . . . to denote arbitrarysequences of hypotheses (e.g. Γ ` C).

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 11/15

Page 12: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Inference Rules forClassical Logic – I

Γ; A; ∆ ` A(Axiom)

Γ; A; A; ∆ ` C

Γ; A; ∆ ` C(Copy)

Γ; ∆ ` C

Γ; A; ∆ ` C(Weakening)

Γ ` >

(True-intro)Γ; ⊥; ∆ ` C

(False-elim)

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 12/15

Page 13: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Inference Rules forClassical Logic – II

Γ ` A

Γ ` A ∨ B(Or-intro-1 )

Γ ` B

Γ ` A ∨ B(Or-intro-2 )

Γ; A; ∆ ` C Γ; B; ∆ ` C

Γ; A ∨ B; ∆ ` C(Or-elim)

Γ ` A Γ ` B

Γ ` A ∧ B(And-intro)

Γ; A; B; ∆ ` C

Γ; A ∧ B; ∆ ` C(And-elim)

Γ; A ` B

Γ ` A ⇒ B(Imp-intro)

Γ; ∆ ` A Γ; B; ∆ ` C

Γ; A ⇒ B; ∆ ` C(Imp-elim)

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 13/15

Page 14: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Inference Rules forClassical Logic – III

Γ; A ` ⊥

Γ ` ¬A(Not-intro)

Γ; ∆ ` A

Γ; ¬A; ∆ ` C(Not-elim)

Γ; ¬A ` ⊥

Γ ` A(Proof by contradiction)

Γ; ∆; Γ′; ∆′` C

Γ; Γ′; ∆; ∆′ ` C(Swap)

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 14/15

Page 15: CS101C Type Theory and Formal Methods · Admin email: cs101-admin@metaprl.org Mailing list: cs101-class@metaprl.org CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003

Inference Rules forClassical Logic – All

Γ; A; ∆ ` A

(Axiom)Γ; A; A; ∆ ` C

Γ; A; ∆ ` C

(Copy)Γ; ∆ ` C

Γ; A; ∆ ` C

(Weakening)

Γ; ∆; Γ′; ∆′` C

Γ; Γ′; ∆; ∆′ ` C

(Swap)Γ ` >

(True-intro)Γ; ⊥; ∆ ` C

(False-elim)

Γ ` A

Γ ` A ∨ B

(Or-intro-1)Γ ` B

Γ ` A ∨ B

(Or-intro-2)Γ; A; ∆ ` C Γ; B; ∆ ` C

Γ; A ∨ B; ∆ ` C

(Or-elim)

Γ ` A Γ ` B

Γ ` A ∧ B

(And-intro)Γ; A; B; ∆ ` C

Γ; A ∧ B; ∆ ` C

(And-elim)

Γ; A ` B

Γ ` A ⇒ B

(Imp-intro)Γ; ∆ ` A Γ; B; ∆ ` C

Γ; A ⇒ B; ∆ ` C

(Imp-elim)

Γ; A ` ⊥

Γ ` ¬A

(Not-intro)Γ; ∆ ` A

Γ; ¬A; ∆ ` C

(Not-elim)Γ; ¬A ` ⊥

Γ ` A

(Proof by contradiction)

CS101C: Type Theory and Formal Methods Lecture 1 March 31, 2003 – p. 15/15