Transcript Lecture 6

Lecture 6
• Topics
– Program behavior problems
• Input of problem is a program/algorithm
• Definition of type program
– Program correctness
• Testing versus Proving
1
Number Theory Problems
• These are problems where we investigate
properties of numbers
– Primality
• Input: Positive integer n
• Yes/No Question: Is n a prime number?
– Divisor
• Input: Integers m,n
• Yes/No question: Is m a divisor of n?
2
Graph Theory Problems
• These are problems where we investigate
properties of graphs
– Connected
• Input: Graph G
• Yes/No Question: Is G a connected graph?
– Subgraph
• Input: Graphs G1 and G2
• Yes/No question: Is G1 a subgraph of G2?
3
Program Behavior Problems
• These are problems where we investigate
properties of programs and how they
behave
• Give an example problem with one input
program P
• Give an example problem with two input
programs P1 and P2
4
Program Representation
• How do we have program variables?
– Abstractly, we define the type “program”
• graph G, program P
– More concretely, we define type program to be a
string over the program alphabet SP = {a, …, z,
A, …, Z, 0, …, 9, punctuation, white space}
• Note, many strings over SP are not legal programs
• We consider them to be programs that always crash
• Possible declaration of main procedure
– bool main(program P)
5
Program correctness
• How do we determine whether or not a
program P we have written is correct?
– Testing
• Run program P on some inputs x1, x2, …
• What are some weaknesses of testing?
• What might be a better approach?
6
Testing versus Analyzing
Test Inputs
x1
x2
x3
...
Program P
Program
P
Analyzer
Outputs
P(x1)
P(x2)
P(x3)
...
Analysis of
Program P
7
2 Program Behavior Problems
• Correctness
– Input
• Program P
– Yes/No Question
• Does P correctly solve the primality problem?
• Functional Equivalence
– Input
• Programs P1, P2
– Yes/No Question
• Is program P1 functionally equivalent to program P2
8