hoare logic
play

Hoare Logic Andreas Podelski November 8, 2011 Hoare logic - PowerPoint PPT Presentation

Hoare Logic Andreas Podelski November 8, 2011 Hoare logic introduced by Hoare in 1969 builds on first-order logic Hoare logic introduced by Hoare in 1969 builds on first-order logic correctness specification = pre- and


  1. Hoare Logic Andreas Podelski November 8, 2011

  2. Hoare logic ◮ introduced by Hoare in 1969 builds on first-order logic

  3. Hoare logic ◮ introduced by Hoare in 1969 builds on first-order logic ◮ correctness specification = pre- and postcondition pair

  4. Hoare logic ◮ introduced by Hoare in 1969 builds on first-order logic ◮ correctness specification = pre- and postcondition pair ◮ standard presentation of Hoare logic: proof uses invariant for every loop in program

  5. Hoare logic ◮ introduced by Hoare in 1969 builds on first-order logic ◮ correctness specification = pre- and postcondition pair ◮ standard presentation of Hoare logic: proof uses invariant for every loop in program ◮ here: invariants are given as part of correctness specification

  6. Hoare logic ◮ introduced by Hoare in 1969 builds on first-order logic ◮ correctness specification = pre- and postcondition pair ◮ standard presentation of Hoare logic: proof uses invariant for every loop in program ◮ here: invariants are given as part of correctness specification ◮ correctness proof possible only if invariants are adequate for pre- and postcondition pair

  7. Programs ◮ (program) expression e ::= x | f ( e 1 , . . . , e n ) where f maps into domain of values

  8. Programs ◮ (program) expression e ::= x | f ( e 1 , . . . , e n ) where f maps into domain of values ◮ Boolean expression b ::= x | f ( e 1 , . . . , e n ) where f maps into Boolean domain

  9. Programs ◮ (program) expression e ::= x | f ( e 1 , . . . , e n ) where f maps into domain of values ◮ Boolean expression b ::= x | f ( e 1 , . . . , e n ) where f maps into Boolean domain ◮ command C ::= skip | x : = e | C 1 ; C 2 | if b then C 1 else C 2 | while b do C

  10. Semantics of Expression e ◮ state s = function from program variables to value, s : Var → Val

  11. Semantics of Expression e ◮ state s = function from program variables to value, s : Var → Val ◮ program expression e in state s evaluates to value [ | e | ]( s ) ∈ Val

  12. Semantics of Expression e ◮ state s = function from program variables to value, s : Var → Val ◮ program expression e in state s evaluates to value [ | e | ]( s ) ∈ Val ◮ semantics of program expressions e = function from set of states to set of values [ | e | ] : States → Val

  13. Semantics of Expression e ◮ state s = function from program variables to value, s : Var → Val ◮ program expression e in state s evaluates to value [ | e | ]( s ) ∈ Val ◮ semantics of program expressions e = function from set of states to set of values [ | e | ] : States → Val ◮ interpretation of function symbol f in expression f ( e 1 , . . . , e n ) depends on logical first-order model (“+” interpreted over model of unbounded integers or in model for modulo arithmetic?)

  14. Semantics of Boolean Expression b ◮ state s = function from program variables to values, s : Var → Val

  15. Semantics of Boolean Expression b ◮ state s = function from program variables to values, s : Var → Val ◮ Boolean expression b in state s evaluates to Boolean truth value [ | b | ]( s ) ∈ { T , F }

  16. Semantics of Boolean Expression b ◮ state s = function from program variables to values, s : Var → Val ◮ Boolean expression b in state s evaluates to Boolean truth value [ | b | ]( s ) ∈ { T , F } ◮ semantics of Boolean expression b = function from set of states to set of Boolean truth values [ | b | ] : States → { T , F }

  17. Semantics of Boolean Expression b ◮ state s = function from program variables to values, s : Var → Val ◮ Boolean expression b in state s evaluates to Boolean truth value [ | b | ]( s ) ∈ { T , F } ◮ semantics of Boolean expression b = function from set of states to set of Boolean truth values [ | b | ] : States → { T , F } ◮ evaluation of Boolean expression b depends on logical first-order model (“ x ≤ x + 1” true in model of unbounded integers but false in model for modulo arithmetic)

  18. Semantics of Commands C (1) ◮ semantics of command C = functions from set of states to set of states s �→ s ′ [ | C | ] : States → States ,

  19. Semantics of Commands C (1) ◮ semantics of command C = functions from set of states to set of states s �→ s ′ [ | C | ] : States → States , ◮ execution of command C starting in state s ends in state s ′ ( C , s ) � s ′

  20. Semantics of Commands C (1) ◮ semantics of command C = functions from set of states to set of states s �→ s ′ [ | C | ] : States → States , ◮ execution of command C starting in state s ends in state s ′ ( C , s ) � s ′ ◮ execution of update statement = update of function s : Var → Val = e , s ) � s ′ where s ′ ( x ) = [ ( x : | e | ]( s ) and s ′ ( y ) = s ( y ) for x �≡ y

  21. Semantics of Commands C (1) ◮ semantics of command C = functions from set of states to set of states s �→ s ′ [ | C | ] : States → States , ◮ execution of command C starting in state s ends in state s ′ ( C , s ) � s ′ ◮ execution of update statement = update of function s : Var → Val = e , s ) � s ′ where s ′ ( x ) = [ ( x : | e | ]( s ) and s ′ ( y ) = s ( y ) for x �≡ y ◮ execution of update depends on logical first-order model

  22. Semantics of Commands C (2) ◮ execution of sequence of commands C ≡ C 1 ; C 2 = execution of first command C 1 followed by execution of second command C 2 ( C , s ) � s ′′ if ( C 1 , s ) � s ′ and ( C 2 , s ′ ) � s ′′

  23. Semantics of Commands C (2) ◮ execution of sequence of commands C ≡ C 1 ; C 2 = execution of first command C 1 followed by execution of second command C 2 ( C , s ) � s ′′ if ( C 1 , s ) � s ′ and ( C 2 , s ′ ) � s ′′ ◮ execution of command skip does not change state ( skip , s ) � s (“empty sequence of commands”)

  24. Semantics of Commands C (3) ◮ execution of conditional command C ≡ if b then C 1 else C 2 = execution of then-command C 1 if expression b evaluates to true ( C , s ) � s ′ if [ | b | ]( s ) = T and ( C 1 , s ) � s ′

  25. Semantics of Commands C (3) ◮ execution of conditional command C ≡ if b then C 1 else C 2 = execution of then-command C 1 if expression b evaluates to true ( C , s ) � s ′ if [ | b | ]( s ) = T and ( C 1 , s ) � s ′ ◮ execution of conditional command C ≡ if b then C 1 else C 2 = execution of then-command C 2 if expression b evaluates to false ( C , s ) � s ′ if [ ]( s ) = F and ( C 2 , s ) � s ′ | b |

  26. Semantics of Commands C (3) ◮ execution of conditional command C ≡ if b then C 1 else C 2 = execution of then-command C 1 if expression b evaluates to true ( C , s ) � s ′ if [ | b | ]( s ) = T and ( C 1 , s ) � s ′ ◮ execution of conditional command C ≡ if b then C 1 else C 2 = execution of then-command C 2 if expression b evaluates to false ( C , s ) � s ′ if [ ]( s ) = F and ( C 2 , s ) � s ′ | b | ◮ execution of conditional depends on logical first-order model

  27. Semantics of Commands C (4) ◮ execution of while command C ≡ while b do C 0 = execution of body C 0 followed by execution of while command C if expression b evaluates to true ( C , s ) � s ′′ if [ ]( s ) = T and ( C 0 , s ) � s ′ and ( C , s ′ ) � s ′′ | b |

  28. Semantics of Commands C (4) ◮ execution of while command C ≡ while b do C 0 = execution of body C 0 followed by execution of while command C if expression b evaluates to true ( C , s ) � s ′′ if [ ]( s ) = T and ( C 0 , s ) � s ′ and ( C , s ′ ) � s ′′ | b | ◮ execution of while command C ≡ while b do C 0 = execution of skip if expression b evaluates to false ( C , s ) � s if [ | b | ]( s ) = F

  29. Semantics of Commands C (4) ◮ execution of while command C ≡ while b do C 0 = execution of body C 0 followed by execution of while command C if expression b evaluates to true ( C , s ) � s ′′ if [ ]( s ) = T and ( C 0 , s ) � s ′ and ( C , s ′ ) � s ′′ | b | ◮ execution of while command C ≡ while b do C 0 = execution of skip if expression b evaluates to false ( C , s ) � s if [ | b | ]( s ) = F ◮ execution of while loop depends on logical first-order model

  30. Hoare Triple { φ } C { ψ } ◮ { φ } C { ψ } valid in given logical first-order model if

  31. Hoare Triple { φ } C { ψ } ◮ { φ } C { ψ } valid in given logical first-order model if for all states s if [ | φ | ]( s ) = T and

  32. Hoare Triple { φ } C { ψ } ◮ { φ } C { ψ } valid in given logical first-order model if for all states s if [ | φ | ]( s ) = T and if ( C , s ) � s ′ then

  33. Hoare Triple { φ } C { ψ } ◮ { φ } C { ψ } valid in given logical first-order model if for all states s if [ | φ | ]( s ) = T and if ( C , s ) � s ′ then [ | ψ | ]( s ′ ) = T ◮ { φ } C { ψ } valid if valid in every logical first-order model ◮ Γ | = { φ } C { ψ } if { φ } C { ψ } valid in every logical first-order model of set of assertions Γ

  34. Variables in Hoare Triple { φ } C { ψ } ◮ program variables: occur in commands in program C

  35. Variables in Hoare Triple { φ } C { ψ } ◮ program variables: occur in commands in program C may occur ( free ) in φ and ψ ◮ auxiliary variables: occur ( free ) in φ and/or ψ but do not occur in commands in program C

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend