Docsity

Program Checking: Verifying the Correctness of Functions through Checkers, Study notes of Computer Graphics

Partial preview of the text

Download Program Checking: Verifying the Correctness of Functions through Checkers and more Study notes Computer Graphics in PDF only on Docsity!

Program Checking Lecture 9 3 Feb 2004 290G - Lecture 9

The Idea 3 Feb 2004 290G - Lecture 9

  • Software should check its own work
    • When the answer is computed, check that it is the correct answer - Just as we check our own work... - Do sums forwards and backwards – Double-entry book-keeping

What Does It Mean to Check? 3 Feb 2004 290G - Lecture 9

  • Say procedure p(x) implements a function f(x)
    • if we compute y := p(x) – then we should have y = f(x)
      • How can we verify y = f(x)?
        • multiple implementations and voting – testing – static analysis – on-line, independent checking

Simple Checkers 3 Feb 2004 290G - Lecture 9

  • Procedure p(x) implements function f(x) • Have a c

hecking procedure C(x,y) with

  • C(x,y) = true ⇔ f(x) = y
    • With high probability, if C is randomized

      C is asymptotically faster than f - We call

C is a

checker for

f

C is also an executable specification for f

Example: Factoring Integers 3 Feb 2004 290G - Lecture 9

  • Problem: factor a large integer
    • Believed to be very hard
      • Checker
        • Multiply factors together
          • More generally, any problem in NP ... • ... has a PTime checker • Other examples ...?

Another Example 3 Feb 2004 290G - Lecture 9

  • Sort an array of numbers • How do we check this? Need two things:
    • Elements are ordered – Elements are a permutation of original array
      • Compute checksum of both arrays and compare
        • Sorting is O(n log n), but checker is O(n)

Interface 3 Feb 2004 290G - Lecture 9

  • The last example is instructive
    • Sometimes we must augment the output with extra information to enable efficient checking - This is a general technique - What can I add to the output to make it verifiably correct?

Propositional Satisfiability 3 Feb 2004 290G - Lecture 9

  • Complicated, expensive SAT solver finds a satisfying truth assignment for a givenboolean formula - Have a separate, linear-time routine to ensure the truth assignment satisfies the originalformula

And Another Example 3 Feb 2004 290G - Lecture 9

  • Translation validation
    • Is my compiled program faithful to the original? – A very widespread, low-level problem – Limits what compiler writers will attempt
      • A research subarea of its own (recent)

Translation Validation Sketch 3 Feb 2004 290G - Lecture 9

  • A compiler proves to itself that the source and target programs are equivalent - Make this proof explicit - And part of the output - Proof checking is relatively easy - In contrast to proof discovery

Randomness 3 Feb 2004 290G - Lecture 9

  • Randomization often gives very simple and fast checkers - Problem: Calculate A x B = C • Let r be a randomly chosen small prime • Check ((A mod r) x (B mod r)) mod r = C mod r

Why Does this Work? 3 Feb 2004 290G - Lecture 9

((A mod r) x (B mod r)) mod r = C mod r - If A x B does equal C, then the = clearly holds - from axiom: ((A mod r) x D) mod r = (A x D) mod r - If A x B = C’, then C mod r ≠ C’ mod r - With high probability - Small number multiplies/mod can be done fast - This is the example application to the Pentium bug

Comparison with Other Techniques 3 Feb 2004 290G - Lecture 9

  • The papers draw comparisons to several other approaches: - Verification • Asserts • Testing • “Fault tolerance”

Verification 3 Feb 2004 290G - Lecture 9

  • Verification proves correctness for

all inputs

  • Before the program is run in production
    • Checking proves correctness on

one input

The one we care about - But this is largely a strawman - Full verification is only used in special situations