SlideShare a Scribd company logo
1 of 14
Lecture 4-Proof of Correctness

         May 21th, 2003
Review
• Questions in Assignment 1
  – Negation of English statementQue
• Validity of predicate logic
  – (∀x) [P(x) ∧ Q(x)]  (∀x) P(x) ∧ (∀x) Q(x)
    Yes
  – (∀x) [P(x) ∨ Q(x)]  (∀x) P(x) ∨ (∀x) Q(x)
    No
Motivation
• When a software company is developing a
  new software, it needs to ensure the product
  is error free and reliable. But how?
Motivation
• Software Quality assurance
  – Program Verification
     • Attempts to ensure that a computer program is
       correct. (it follows the specification )
  – Program Validation
     • It attempts to ensure that the program meets the
       client’s original requirements (about the design and
       specification).
  – We will focus on Program verification
Program Verification
• Two approaches: Program testing and program
• Program Testing
  – Seeks to show that particular input values produce
    acceptable output values.
  – Testing can prove the presence of errors but never their
    absence
  – It is a major part of software development (some tools
    could help, e.g.. Junit in Eclipse, a java IDE)
Program Verification (cont.)
• Proof of correctness
   – Use the technique of a formal logic system to
   prove that if the input values satisfy certain
   constraints, the output values produced by the
   program, satisfy certain properties.
• The difference between proof of correctness and
  testing. For example, a program to compute the
  average of two number x1,x2.
   – Testing take each possible input of x1, x2, the result is
     (x1+x2)/2
   – Proof of correctness establish the results is the average
Formal Methods
• Advantages
   – Change program from a private, puzzle-solving activity to a
     public, verifiable activity of translating specifications into
     programs
   – Based on formal mathematical techniques
   – Only way to provide guaranteed correctness
   – Supported by formal languages (Z, VDM-SL, REFINE), proof-
     checkers, and translation systems
• Disadvantages
   – Notations are often confusing
   – Formal techniques do not scale up very well.
Assertions
Hoare triple:      {Q} P {R}
       precondition           post condition
      ==
        (∀X)(Q(X)  R[ X, P(X)])
Q(X)– the input values are supposed to satisfy
R – the output values are supposed to satisfy
{Q}
                                                    S
                                                   o
                                              {R }
                                                 1
                                                S
                                                   1
    Assertions or Predicates,                 {R }
                                                  2
assert what is supposed to be true              
                                                    S
                                                        n −1
                                              {R}


                                       {Q} S       {R 1 }
                                               o
       A proof of correctness for P    {R1 } S {R 2 }
                                                1
        consists of producing this     {R 2 } S {R 3 }
                                                 2
     sequence of valid implications.           
      Some new rules may be used.               
                                       {R n -1 } S          {R}
                                                     n −1
Assignment Rule

                             {Ri} x = e {Ri+1}
•    If the precondition and postcondition are appropriately related, the
     Hoare triple can be inserted at any time in a proof sequence.
•    Can derive {Ri} s {Ri+1}
•     Restrictions
    1.    Si has the form x = e.
    2.    Ri is Ri+1 with e substituted everywhere for x.
•    The assignment rule tells us what a precondition should look like
     based on what a postcondition looks like, a proof of correctness
     often begins with the final desired postcondition and works its way
     back up.
Examples
 Swap(x,y){}
         {y=b, x=a}             {x-4 = x-4}
temp = x       temp = x                 y=x
x=y         {y=b, temp=a}   y=x      {y-4 = x-4}
y=temp           x=y        y=y-4      y=y-4
            {x=b, temp=a}             {y = x – 4}
                y=temp
              {x=b, y=a}

Try:   { x = 3}
          y=4
          z=x+y
       { z = 7}
Conditional Rule
                                {Q} Si {R}

If si is a conditional statement.The triplet is inferred from two other
triplets. Each branch of the conditional statement must be proved correct.

From: {Q ∧ B} P1 {R},             can derive   {Q} Si {R}
      {Q ∧ B’} P2 {R}

Restriction: Si has the form       if condition B then
                                           P1
                                    else
                                           P2
                                    end if
Examples
   {n=5}                      precondition is n = 5, B is n >= 10
if n >=10 then
    y=100                     We must prove:
     else                    1) {n = 5 and n>= 10} y = 100 { y = 6 }
  y = n+1                    2) {n = 5 and n < 10} y = n + 1 { y = 6 }
   end if
  {y = 6}                   1) is true because the antecedent is false
                             to prove 2)        {n+1 = 6 or n=5}
                                                    y=n+1
                                                     {y = 6}
     thus {n=5 and n<10} y = n + 1 {y=6} is true by the assignment rule
                  and {n = 5 and n < 10} y = n + 1 { y = 6 } is also true
Exercise
• Exercise 1.6
 3, 8, 11

More Related Content

What's hot

What's hot (20)

Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and Problems
 
Theory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite AcceptorsTheory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite Acceptors
 
Inverse laplace
Inverse laplaceInverse laplace
Inverse laplace
 
free Video lecture
free Video lecture free Video lecture
free Video lecture
 
push down automata
push down automatapush down automata
push down automata
 
Push down automata
Push down automataPush down automata
Push down automata
 
NFA DFA Equivalence theorem
NFA DFA Equivalence theorem NFA DFA Equivalence theorem
NFA DFA Equivalence theorem
 
MSc_thesis
MSc_thesisMSc_thesis
MSc_thesis
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Theory of Computation Unit 4
Theory of Computation Unit 4Theory of Computation Unit 4
Theory of Computation Unit 4
 
Ece4510 notes06
Ece4510 notes06Ece4510 notes06
Ece4510 notes06
 
Unit v laplace transform(formula)
Unit v laplace transform(formula)Unit v laplace transform(formula)
Unit v laplace transform(formula)
 
Laplace table
Laplace tableLaplace table
Laplace table
 
Directional derivative and gradient
Directional derivative and gradientDirectional derivative and gradient
Directional derivative and gradient
 
Nfa egs
Nfa egsNfa egs
Nfa egs
 
Vector spaces
Vector spaces Vector spaces
Vector spaces
 
Nfa to-dfa
Nfa to-dfaNfa to-dfa
Nfa to-dfa
 
Lines, planes, and hyperplanes
Lines, planes, and hyperplanesLines, planes, and hyperplanes
Lines, planes, and hyperplanes
 
Pda
PdaPda
Pda
 
Vector differentiation, the ∇ operator,
Vector differentiation, the ∇ operator,Vector differentiation, the ∇ operator,
Vector differentiation, the ∇ operator,
 

Similar to wddd

Lecture 3 qualtifed rules of inference
Lecture 3 qualtifed rules of inferenceLecture 3 qualtifed rules of inference
Lecture 3 qualtifed rules of inferenceasimnawaz54
 
Algorithmic foundations.docx
Algorithmic foundations.docxAlgorithmic foundations.docx
Algorithmic foundations.docxedwin orege
 
CMSC 56 | Lecture 5: Proofs Methods and Strategy
CMSC 56 | Lecture 5: Proofs Methods and StrategyCMSC 56 | Lecture 5: Proofs Methods and Strategy
CMSC 56 | Lecture 5: Proofs Methods and Strategyallyn joy calcaben
 
6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdfshruti533256
 
Orthogonal basis and gram schmidth process
Orthogonal basis and gram schmidth processOrthogonal basis and gram schmidth process
Orthogonal basis and gram schmidth processgidc engineering college
 
Principle of mathematical induction
Principle of mathematical inductionPrinciple of mathematical induction
Principle of mathematical inductionKriti Varshney
 
Sep logic slide
Sep logic slideSep logic slide
Sep logic sliderainoftime
 
1606751772-ds-lecture-6.ppt
1606751772-ds-lecture-6.ppt1606751772-ds-lecture-6.ppt
1606751772-ds-lecture-6.pptTejasAditya2
 
Discreate structure presentation introduction
Discreate structure presentation introductionDiscreate structure presentation introduction
Discreate structure presentation introductionyashirraza123
 
SMB_2012_HR_VAN_ST-last version
SMB_2012_HR_VAN_ST-last versionSMB_2012_HR_VAN_ST-last version
SMB_2012_HR_VAN_ST-last versionLilyana Vankova
 
Consistency proof of a feasible arithmetic inside a bounded arithmetic
Consistency proof of a feasible arithmetic inside a bounded arithmeticConsistency proof of a feasible arithmetic inside a bounded arithmetic
Consistency proof of a feasible arithmetic inside a bounded arithmeticYamagata Yoriyuki
 

Similar to wddd (20)

Lecture 3 qualtifed rules of inference
Lecture 3 qualtifed rules of inferenceLecture 3 qualtifed rules of inference
Lecture 3 qualtifed rules of inference
 
Kumera2.docx
Kumera2.docxKumera2.docx
Kumera2.docx
 
Algorithmic foundations.docx
Algorithmic foundations.docxAlgorithmic foundations.docx
Algorithmic foundations.docx
 
CMSC 56 | Lecture 5: Proofs Methods and Strategy
CMSC 56 | Lecture 5: Proofs Methods and StrategyCMSC 56 | Lecture 5: Proofs Methods and Strategy
CMSC 56 | Lecture 5: Proofs Methods and Strategy
 
6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf
 
Orthogonal basis and gram schmidth process
Orthogonal basis and gram schmidth processOrthogonal basis and gram schmidth process
Orthogonal basis and gram schmidth process
 
Principle of mathematical induction
Principle of mathematical inductionPrinciple of mathematical induction
Principle of mathematical induction
 
Discrete Math Lecture 02: First Order Logic
Discrete Math Lecture 02: First Order LogicDiscrete Math Lecture 02: First Order Logic
Discrete Math Lecture 02: First Order Logic
 
Sep logic slide
Sep logic slideSep logic slide
Sep logic slide
 
Chap05
Chap05Chap05
Chap05
 
L16
L16L16
L16
 
chapter9.ppt
chapter9.pptchapter9.ppt
chapter9.ppt
 
Microeconomics-Help-Experts.pptx
Microeconomics-Help-Experts.pptxMicroeconomics-Help-Experts.pptx
Microeconomics-Help-Experts.pptx
 
1606751772-ds-lecture-6.ppt
1606751772-ds-lecture-6.ppt1606751772-ds-lecture-6.ppt
1606751772-ds-lecture-6.ppt
 
Discreate structure presentation introduction
Discreate structure presentation introductionDiscreate structure presentation introduction
Discreate structure presentation introduction
 
dma_ppt.pdf
dma_ppt.pdfdma_ppt.pdf
dma_ppt.pdf
 
6e-ch4.ppt
6e-ch4.ppt6e-ch4.ppt
6e-ch4.ppt
 
SMB_2012_HR_VAN_ST-last version
SMB_2012_HR_VAN_ST-last versionSMB_2012_HR_VAN_ST-last version
SMB_2012_HR_VAN_ST-last version
 
Consistency proof of a feasible arithmetic inside a bounded arithmetic
Consistency proof of a feasible arithmetic inside a bounded arithmeticConsistency proof of a feasible arithmetic inside a bounded arithmetic
Consistency proof of a feasible arithmetic inside a bounded arithmetic
 
LPS talk notes
LPS talk notesLPS talk notes
LPS talk notes
 

Recently uploaded

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

wddd

  • 1. Lecture 4-Proof of Correctness May 21th, 2003
  • 2. Review • Questions in Assignment 1 – Negation of English statementQue • Validity of predicate logic – (∀x) [P(x) ∧ Q(x)]  (∀x) P(x) ∧ (∀x) Q(x) Yes – (∀x) [P(x) ∨ Q(x)]  (∀x) P(x) ∨ (∀x) Q(x) No
  • 3. Motivation • When a software company is developing a new software, it needs to ensure the product is error free and reliable. But how?
  • 4. Motivation • Software Quality assurance – Program Verification • Attempts to ensure that a computer program is correct. (it follows the specification ) – Program Validation • It attempts to ensure that the program meets the client’s original requirements (about the design and specification). – We will focus on Program verification
  • 5. Program Verification • Two approaches: Program testing and program • Program Testing – Seeks to show that particular input values produce acceptable output values. – Testing can prove the presence of errors but never their absence – It is a major part of software development (some tools could help, e.g.. Junit in Eclipse, a java IDE)
  • 6. Program Verification (cont.) • Proof of correctness – Use the technique of a formal logic system to prove that if the input values satisfy certain constraints, the output values produced by the program, satisfy certain properties. • The difference between proof of correctness and testing. For example, a program to compute the average of two number x1,x2. – Testing take each possible input of x1, x2, the result is (x1+x2)/2 – Proof of correctness establish the results is the average
  • 7. Formal Methods • Advantages – Change program from a private, puzzle-solving activity to a public, verifiable activity of translating specifications into programs – Based on formal mathematical techniques – Only way to provide guaranteed correctness – Supported by formal languages (Z, VDM-SL, REFINE), proof- checkers, and translation systems • Disadvantages – Notations are often confusing – Formal techniques do not scale up very well.
  • 8. Assertions Hoare triple: {Q} P {R} precondition post condition == (∀X)(Q(X)  R[ X, P(X)]) Q(X)– the input values are supposed to satisfy R – the output values are supposed to satisfy
  • 9. {Q} S o {R } 1 S 1 Assertions or Predicates, {R } 2 assert what is supposed to be true  S n −1 {R} {Q} S {R 1 } o A proof of correctness for P {R1 } S {R 2 } 1 consists of producing this {R 2 } S {R 3 } 2 sequence of valid implications.  Some new rules may be used.  {R n -1 } S {R} n −1
  • 10. Assignment Rule {Ri} x = e {Ri+1} • If the precondition and postcondition are appropriately related, the Hoare triple can be inserted at any time in a proof sequence. • Can derive {Ri} s {Ri+1} • Restrictions 1. Si has the form x = e. 2. Ri is Ri+1 with e substituted everywhere for x. • The assignment rule tells us what a precondition should look like based on what a postcondition looks like, a proof of correctness often begins with the final desired postcondition and works its way back up.
  • 11. Examples Swap(x,y){} {y=b, x=a} {x-4 = x-4} temp = x temp = x y=x x=y {y=b, temp=a} y=x {y-4 = x-4} y=temp x=y y=y-4 y=y-4 {x=b, temp=a} {y = x – 4} y=temp {x=b, y=a} Try: { x = 3} y=4 z=x+y { z = 7}
  • 12. Conditional Rule {Q} Si {R} If si is a conditional statement.The triplet is inferred from two other triplets. Each branch of the conditional statement must be proved correct. From: {Q ∧ B} P1 {R}, can derive {Q} Si {R} {Q ∧ B’} P2 {R} Restriction: Si has the form if condition B then P1 else P2 end if
  • 13. Examples {n=5} precondition is n = 5, B is n >= 10 if n >=10 then y=100 We must prove: else 1) {n = 5 and n>= 10} y = 100 { y = 6 } y = n+1 2) {n = 5 and n < 10} y = n + 1 { y = 6 } end if {y = 6} 1) is true because the antecedent is false to prove 2) {n+1 = 6 or n=5} y=n+1 {y = 6} thus {n=5 and n<10} y = n + 1 {y=6} is true by the assignment rule and {n = 5 and n < 10} y = n + 1 { y = 6 } is also true