1 / 8

A formal system:

Ch 23:Formal Semantics. A formal system:. Axioms and Rules,. for inferring valid specification. { m ≥1, n ≥1 }. assertion. pre-condition. x := m; y := n; while ¬(x=y) do if x>y then x := x-y else y := y-x. program. specification. { x = gcd(m,n) }. assertion.

bvera
Télécharger la présentation

A formal system:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ch 23:Formal Semantics A formal system: Axioms and Rules, for inferring valid specification { m≥1, n ≥1 } assertion pre-condition x := m; y := n; while ¬(x=y) do if x>y then x := x-y else y := y-x program specification { x = gcd(m,n) } assertion post-condition IT 327

  2. A formal system: Axioms and Rules, { P } skip { P } map { true } diverge { false } { [P] (i  E) } i := E { P } assignment { P } C {Q}  { P } ( C ) { Q } grouping { P } C0 {Q} & { Q } C1 { R }  { P } C0 ; C1{ R } sequencing { P, B } C0 {Q} & { P, ¬B } C1 { Q }  { P } if B then C0 else C1 { Q } if-statement { P, B } C{ P }  { P } while B do C { P, ¬B } while-loop this P is called the loop invariant IT 327

  3. (II) A formal system: Axioms and Rules, implies { P  R} & { R } C { Q }  { P } C{ Q } pre-condition strengthening { R  Q} & { P } C { R }  { P } C{ Q } post-condition weakening or { P1} C { Q } & { P2} C { Q }  { P1  P2 } C{ Q } pre-condition disjunction and { P} C { Q1 } & { P} C { Q2 }  { P} C{ Q1, Q2 } post-condition conjunction IT 327

  4. A correct program { ( n+1) ≥0 } This (piece of) program is correct.. This is a correct specification n := n+1; { n ≥0 } Is what sense? It is correct because we can apply the following axiom to obtain the specification: { [P] (i  E) } i := E { P } assignment IT 327

  5. Another proof of the program correctness {b ≥0 } assertion pre-condition s := a; i := 0; while ¬(i=b) do ( s := s+1; i := i+1 ) program specification { s = a+b } assertion post-condition The most difficult part is to figure out a useful loop invariant { s = a+i } IT 327

  6. {b ≥0  (b ≥0, a = a+0) } {b ≥0, a = a+0 } s := a; {b ≥0,s = a+0 } {b ≥0 } {(b ≥0,s = a+0)  (b ≥0, s = a+0, 0=0) } s := a; i := 0; {b ≥0, s = a+0, 0=0 } {b ≥0, s = a+i } i := 0; {b ≥0, s = a+0, i = 0 } { (b ≥0,s = a+0 , i=0)  (b ≥0, s = a+i) } IT 327

  7. { P, B } C{ P }  { P } while B do C { P, ¬B } {b ≥0, s = a+i , ¬(i=b) } {b ≥0, s = a+i } s := s+1; i := i+1; while ¬(i=b) do ( s := s+1; i := i+1 ) {b ≥0, s = a+i } {b ≥0, s = a+i , ¬¬(i=b) } {(b ≥0, s = a+i , ¬¬(i=b))  (b ≥0, s = a+i , i=b) } {(b ≥0, s = a+i , i=b) s = a+b} IT 327

  8. Examples of correctness proofs Easy introduction to loop invariants IT 327

More Related