南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)07_Axiomatic Semantics and Hoare Logic

Axiomatic Semantics and Hoare Logic (Slides modified from Mike Gordon,Hongjin Liang) 11197
Axiomatic Semantics and Hoare Logic (Slides modified from Mike Gordon, Hongjin Liang) 1 / 197

Outline Program Specifications using Hoare's Notation Inference Rules of Hoare Logic Automated Program Verification Soundness and Completeness Discussions 2/197
Outline Program Specifications using Hoare’s Notation Inference Rules of Hoare Logic Automated Program Verification Soundness and Completeness Discussions 2 / 197

Floyd-Hoare Logic This class is concerned with Floyd-Hoare Logic also known just as Hoare Logic Hoare Logic is a method of reasoning mathematically about imperative programs It is the basis of mechanized program verification systems Developments to the logic still under active development,e.g. separation logic(reasoning about pointers) concurrent program logics 3/197
Floyd-Hoare Logic This class is concerned with Floyd-Hoare Logic I also known just as Hoare Logic Hoare Logic is a method of reasoning mathematically about imperative programs It is the basis of mechanized program verification systems Developments to the logic still under active development, e.g. I separation logic (reasoning about pointers) I concurrent program logics 3 / 197

A simple imperative language (IntExp)e ::n x I e+el e-el... (BoolExp)b ::true false e=eee -b bAb l bvb l .. (Comm)c:= skip x:=e 1 C;C L if b then c else c while b do c (State)σeVar→lnt 4/197
A simple imperative language (IntExp) e ::= n | x | e + e | e − e | . . . (BoolExp) b ::= true | false | e = e | e e | ¬b | b ∧ b | b ∨ b | . . . (Comm) c ::= skip | x := e | c ; c | if b then c else c | while b do c (State) σ ∈ Var → Int 4 / 197

Outline Program Specifications using Hoare's Notation Inference Rules of Hoare Logic Automated Program Verification Soundness and Completeness Discussions 5/197
Outline Program Specifications using Hoare’s Notation Inference Rules of Hoare Logic Automated Program Verification Soundness and Completeness Discussions 5 / 197

Specifications of imperative programs Acceptable Acceptable Initial State Final State “Xis “Y is the greater than square root Zero” Action ofX” of the Program 6/197
Specifications of imperative programs 6 / 197

Hoare's notation(Hoare triples) For a program c, partial correctness specification: (p)ciq) total correctness specification: [p]c[q] Here p and g are assertions,i.e.,conditions on the program variables used in c. p is called precondition,and q is called postcondition Hoare's original notation was plc)q not (p)c(q),but the latter form is now more widely used 7/197
Hoare’s notation (Hoare triples) For a program c, I partial correctness specification: {p}c{q} I total correctness specification: [p]c[q] Here p and q are assertions, i.e., conditions on the program variables used in c. I p is called precondition, and q is called postcondition Hoare’s original notation was p{c}q not {p}c{q}, but the latter form is now more widely used 7 / 197

Meanings of Hoare triples A partial correctness specification (p)c(g)is valid,iff if c is executed in a state initially satisfying p and if the execution of c terminates then the final state satisfies g It is "partial"because for (p)clg)to be true it is not necessary for the execution of c to terminate when started in a state satisfying p It is only required that if the execution terminates,then g holds 8/197
Meanings of Hoare triples A partial correctness specification {p}c{q} is valid, iff I if c is executed in a state initially satisfying p I and if the execution of c terminates I then the final state satisfies q It is “partial” because for {p}c{q} to be true it is not necessary for the execution of c to terminate when started in a state satisfying p It is only required that if the execution terminates, then q holds 8 / 197

Meanings of Hoare triples A partial correctness specification (p)clg)is valid,iff if c is executed in a state initially satisfying p and if the execution of c terminates then the final state satisfies q A total correctness specification [p]c[q]is valid,iff if c is executed in a state initially satisfying p then the execution of c terminates and the final state satisfies g Informally:Total correctness=Termination Partial correctness 9/197
Meanings of Hoare triples A partial correctness specification {p}c{q} is valid, iff I if c is executed in a state initially satisfying p I and if the execution of c terminates I then the final state satisfies q A total correctness specification [p]c[q] is valid, iff I if c is executed in a state initially satisfying p I then the execution of c terminates I and the final state satisfies q Informally: Total correctness = Termination + Partial correctness 9 / 197

Examples of program specs {x=1} X:=X+1 {x=2} valid {x=1 X:=X+1 {x=3} invalid 10/197
Examples of program specs {x = 1} x := x + 1 {x = 2} valid {x = 1} x := x + 1 {x = 3} invalid {x − y > 3} x := x − y {x > 2} valid [x − y > 3] x := x − y [x > 2] valid {x ≤ 10} while x , 10 do x := x + 1 {x = 10} valid [x ≤ 10] while x , 10 do x := x + 1 [x = 10] valid {true} while x , 10 do x := x + 1 {x = 10} valid [true] while x , 10 do x := x + 1 [x = 10] invalid {x = 1} while true do skip {x = 2} valid 10 / 197
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)06_Denotational Semantics.pdf
- 《程序设计语言的形式语义》课程教学资源(文献资料)Lecture Notes on the Lambda Calculus.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)05_Operational Semantics.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)04_Lambda Calculus.pptx
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)03_Math.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)02_CoqOverview.pptx
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)01_Introduction(主讲:冯新宇)Formal Semantics of Programming Languages.ppt
- 私立华联学院:《html5》课程教学资源(课件讲稿)第9章 CSS3高级应用.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第8章 多媒体技术.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第7章 表单的应用.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第6章 浮动与定位.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第5章 CSS盒子模型.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第4章 CSS3选择器.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第3章 CSS3入门.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第2章 HTML5 页面元素及属性.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第1章 初识HTML5.pdf
- 私立华联学院:《html5》课程教学资源(试卷习题)各章习题答案.pdf
- 私立华联学院:《html5》课程教学资源(试卷习题)第9章 CSS3高级应用_习题.pdf
- 私立华联学院:《html5》课程教学资源(试卷习题)第8章 多媒体嵌入_习题.pdf
- 私立华联学院:《html5》课程教学资源(试卷习题)第7章 表单_习题.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)Separation Logic(1/3).ppt
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)09_Shared-Variable Concurrency.pdf
- 《程序设计语言的形式语义》课程教学资源(文献资料)An Introduction to Separation Logic(Preliminary Draft).pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)Separation Logic(2/3).ppt
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)Separation Logic(3/3).ppt
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)10_Simply-Typed Lambda Calculus.pptx
- 私立华联学院:《C语言程序设计》课程教学资源(教案讲义)教学大纲.pdf
- 私立华联学院:《C语言程序设计》课程教学资源(教案讲义)应用案例.pdf
- 私立华联学院:《C语言程序设计》课程教学资源(教案讲义)课程标准(适用专业:物联网应用技术).pdf
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第一章 初识C语言(负责人:周鹏梅).ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第三章 结构化程序设计.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第二章 数据类型与运算符.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第七章 结构体和共同体.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第五章 函数.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第八章 文件.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第六章 指针.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第四章 数组.ppt
- 私立华联学院:《Python语言程序设计》课程教学资源(教案讲义)课程标准(适用专业:软件技术).pdf
- 私立华联学院:《Python语言程序设计》课程教学资源(教案讲义)课程教学设计(负责人:尹菡).pdf
- 《Python语言程序设计》课程教学资源(拓展资源)Python练习实例(Python 100例).pdf