Download slides

Survey
yes no 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

Peano axioms wikipedia , lookup

List of first-order theories wikipedia , lookup

Gödel's incompleteness theorems wikipedia , lookup

Model theory wikipedia , lookup

Ramism wikipedia , lookup

Axiom wikipedia , lookup

Inquiry wikipedia , lookup

Foundations of mathematics wikipedia , lookup

Willard Van Orman Quine wikipedia , lookup

Fuzzy logic wikipedia , lookup

Mathematical proof wikipedia , lookup

Catuṣkoṭi wikipedia , lookup

Argument wikipedia , lookup

Jesús Mosterín wikipedia , lookup

Modal logic wikipedia , lookup

Lorenzo Peña wikipedia , lookup

Propositional calculus wikipedia , lookup

First-order logic wikipedia , lookup

Theorem wikipedia , lookup

Natural deduction wikipedia , lookup

Combinatory logic wikipedia , lookup

Interpretation (logic) wikipedia , lookup

History of logic wikipedia , lookup

Syllogism wikipedia , lookup

Mathematical logic wikipedia , lookup

Quantum logic wikipedia , lookup

Law of thought wikipedia , lookup

Laws of Form wikipedia , lookup

Curry–Howard correspondence wikipedia , lookup

Intuitionistic logic wikipedia , lookup

Transcript
.
CS 4110
Programming Languages & Logics
Lecture 11
Hoare Logic
17 September 2012
Announcements
• Homework #3 due today at 11:59pm
• Foster office hours today 4-5pm in Upson 4137
• Rajkumar office hours today 5-6pm in 4135
• Additional help available on Piazza
• Homework #4 out today
2
Overview
Friday
• Assertion language: P
• Assertion satisfaction: σ |=I P
• Assertion validity: |= P
• Partial/total correctness statements: {P} c {Q} and [P]c[Q]
• Partial correctness satisfaction σ |=I {P}c{Q}
• Partial correctness validity: |= {P}c{Q}
Today
• Hoare Logic
• Soundness and Completeness
• Examples
3
Review
De nition (Partial correctness statement satisfaction)
A partial correctness statement {P} c {Q} is satis ed by store σ and
interpretation I, written σ I {P} c {Q}, if:
∀σ ′ . if σ I P and C[[c]] σ = σ ′ then σ ′ I Q
De nition (Partial correctness statement validity)
A partial correctness triple is valid (written {P} c {Q}), if it is valid
in any store and interpretation: ∀σ, I. σ I {P} c {Q}.
4
Hoare Logic
Want a way to prove partial correctness statements valid...
... without having to consider explicitly every store and
interpretation!
5
Hoare Logic
Want a way to prove partial correctness statements valid...
... without having to consider explicitly every store and
interpretation!
Idea: develop a proof system in which every theorem is a valid
partial correctness statement
Judgements of the form ⊢ {P} c {Q}
De ned inductively using compositional and (mostly)
syntax-directed axioms and inference rules
5
Hoare Logic: Skip
⊢ {P} skip {P}
Skip
6
Hoare Logic: Assignment
⊢ {P[a/x]} x := a {P}
Assign
7
Hoare Logic: Assignment
⊢ {P[a/x]} x := a {P}
Assign
Notation: P[a/x] denotes substitution of a for x in P
7
Hoare Logic: Assignment
⊢ {P[a/x]} x := a {P}
Assign
Notation: P[a/x] denotes substitution of a for x in P
Question: Why is the assignment on the left?
7
Hoare Logic: Sequence
⊢ {P} c1 {R}
⊢ {R} c2 {Q}
Seq
⊢ {P} c1 ; c2 {Q}
8
Hoare Logic: Conditionals
⊢ {P ∧ b} c1 {Q}
⊢ {P ∧ ¬b} c2 {Q}
If
⊢ {P} if b then c1 else c2 {Q}
9
Hoare Logic: Loops
⊢ {P ∧ b} c {P}
While
⊢ {P} while b do c {P ∧ ¬b}
10
Hoare Logic: Consequence
|= P ⇒ P′
⊢ {P′ } c {Q′ }
⊢ {P} c {Q}
|= Q′ ⇒ Q
Consequence
Note: |= P ⇒ P′ denotes assertion validity
11
Example: Factorial
{x = n ∧ n > 0}
y := 1;
while x > 0 do {
. y ∗ x;
y :=
.
x := x − 1
}
{y = n!}
12
Soundness and Completeness
De nition (Soundness)
If ⊢ {P} c {Q} then |= {P} c {Q}.
De nition (Completeness)
If |= {P} c {Q} then ⊢ {P} c {Q}.
Today: Soundness
Wednesday: Relative Completeness
13
Soundness and Completeness
Theorem (Soundness)
If ⊢ {P} c {Q} then |= {P} c {Q}.
14
Soundness and Completeness
Theorem (Soundness)
If ⊢ {P} c {Q} then |= {P} c {Q}.
Proof.
By induction on {P} c {Q}...
14
Soundness and Completeness
Theorem (Soundness)
If ⊢ {P} c {Q} then |= {P} c {Q}.
Proof.
By induction on {P} c {Q}...
Lemma (Substitution)
• σ |=I P[a/x] ⇔ σ[x 7→ A[[a]] σ] |=I P
• A[[a0 [a/x]]] (σ, I) ⇔ A[[a0 ]] (σ[x 7→ A[[a]] (σ, I)], I)
14