Todays Agenda - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Todays Agenda

Description:

High level solution to problem. Consists of modules and module interconnections ... Similar argument can be applied for more than one step as well. ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 16
Provided by: discovery
Category:
Tags: agenda | todays | use

less

Transcript and Presenter's Notes

Title: Todays Agenda


1
Todays Agenda
  • Top down design strategy ?
  • Correctness issues

2
Correctness Issues
  • Motivation
  • Modules, Contracts, Invariants
  • Tests and Test Cases

3
Why Correctness?
  • Recall programming is engineering
  • Program is a product
  • Program quality to be determined during
    production process
  • Correctness is one (essential) aspect of quality

4
What is correctness?
  • Design Correctness
  • Solution (design) meets requirements
  • Verified offline (often on paper)
  • Proof arguments
  • Implementation Correctness
  • Implementation (program code) matches design
  • Verified online (often by execution)
  • Tests and Test Cases

5
What is Correctness?
  • Output of Design step Program Design
  • High level solution to problem
  • Consists of modules and module interconnections
  • Modules are solutions to sub-problems
  • Interconnections capture ways to combine
    sub-solutions

6
Design Correctness
  • Design Correctness involves
  • Module correctness (for each module)
  • Combination correctness
  • Design Correctness is verified by correctness
    arguments
  • Establish Module Correctness
  • Verify contracts between modules.

7
Module Correctness
  • Often reduces to algorithm correctness
  • Algorithm will terminate
  • Algorithm will produce required result if and
    when it terminates.
  • Both arguments are fairly easy for
    straight-line programs i.e., no loops.

8
Module Correctness
  • e.g.,
  • Define function to compute square(x) as
  • return x x
  • It is easy to verify the requirements
  • It terminates a single step
  • It computes the square of a given number x2xx

9
Module Correctness
  • Similar argument can be applied for more than one
    step as well.
  • Problem Given a, b, and c, solve quadratic
    equation
  • ax2 bx c 0

10
Module Correctness
  • Solution Define function quad(a, b, c, sign) as
    disc bb 4ac
  • if (sign) return (-b sqrt(disc)) / (2 a)
  • else return (-b sqrt(disc)) / (2a)

11
Module Correctness
  • Termination
  • if sqrt terminates, this function terminates.
  • Valid results
  • if sqrt is correct then this returns correct
    value.
  • How do we handle the if conditions above?
  • Contracts

12
Inter-Module Correctness
  • Whoever writes sqrt function, specifies
    input-output contract
  • / Pre-condition m gt 0
  • Post-condition return n such that
  • n n m / m lt .01
  • /
  • float sqrt(float m) ? argument must be ve
    definite

13
Inter-Module Correctness
  • Observation
  • Precondition m gt 0
  • This is required for sqrt to be correct (or may
    be even to terminate).
  • So, quad module must guarantee before invocation
    of sqrt disc gt 0

14
Inter-Module Correctness
  • The previous contract may propagate up
  • / Pre-condition bb gt 4ac
  • Post-condition return x such that
  • axx bx c lt epsilon
  • /
  • float quad(float a, float b, float c, int sign)

15
Module Correctness for sqrt(x)
Write a Comment
User Comments (0)
About PowerShow.com