Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author:...

65
Models and Design

Transcript of Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author:...

Page 1: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Models and Design

Page 2: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

INTRODUCTION

• Declarative Model: Functional Model

what is to be achieved rather than how to achieve it

• Imperative Model : Structured Programming model

imperative == command

how to do something, rather than what is to be done

Page 3: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

FUNCTIONAL MODEL

• Very close to mathematics

• Easy to analyze in terms of their correctness and efficiency

• Functional algorithm can serve as a specification for the development of algorithms in other models of computation

• Every problem is viewed as an evaluation of a function

• The solution to a given problem is specified by a complete and unambiguous functional description

Page 4: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

• A good model of computation

1. Primitive expressions which represent the simplest objects with which the model is concerned.

2. Methods of combination which specify how the primitive expressions can be combined with one another to obtain compound expressions.

3. Methods of abstraction which specify how the compound objects can be named and manipulated as units.

Page 5: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Features of Functional Model

1. The Primitive Expressions

2. Definition of one function in terms of another (substitution)

3. Definition of functions using conditionals

4. Inductive definition of functions

Page 6: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

The Primitive Expressions

• The basic primitives of the functional model are constants, variables, and functions

• Elements of the sets , , are the constants. Also, the elements of the set B = {true, false} are constants.

• There can be other kind of constants as well.

• Variables are identifiers which refer to data objects (constants).• E.g. the declarations x = 5 and y = true bind the variables x and y to the

values 5 and true, respectively.

Page 7: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Availability of Primitive functions of the type

f: × →

and

f: × →

• E.g. addi on (+), subtrac on (−), and mul plica on (*)

The functional mapping symbolism like f : × → is also called the signature of that function.

Page 8: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

• If a and b and a = q * b + r for some integers q and 0 ≤ r < b then div(a, b) = q and mod(a, b) = r.

• The division function / : × → will be assumed to be valid only for real numbers.

• In addition to these, we will assume the relational functions =,≤,<,≥,>, and ≠ which are of the type

f : × → B

or

f : × → B depending on the context.

Page 9: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 10: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Substitution of Functions

• Definition of one function in terms of another

• Evaluate such functions through substitution.

Page 11: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Example 1

Finding the square of a natural number.

We can directly specify the function square, which is of the type

square : →

As, square(n) = n * n

Where, * : × → as

Page 12: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Example 1

Finding the square of a natural number.

We can directly specify the function square, which is of the type

square : →

As, square(n) = n * n

Where, * : × → as

To find square(5), we have to thus evaluate 5 * 5

Page 13: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Example 2: Finding the sum of two squares

• More complex functions from simpler ones

sumsquares : × → as follows:

sum_squares(x, y) = square(x) + square(y)

The function sum_squares is thus defined in terms of the functions + and square.

Page 14: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Example 3: Using local variables

• Suppose:

f(x, y) = x(1 + xy)2 + y(1 − y) + (1 + xy)(1 − y)

We can express, a = 1 + xy,

b = 1 − y,

Then f(x, y) = xa2 + yb + ab.

avoids multiple computations

Page 15: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Definition of Functions using Conditionals

• Example: Finding the larger of two numbers

max : × →

The function accepts a pair of natural numbers as its input, and gives a single natural number as its output

Page 16: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Definition of Functions using Conditionals

• Example: Finding the larger of two numbers

max : × →

The function accepts a pair of natural numbers as its input, and gives a single natural number as its output

Assumed that two natural numbers can be compared using the ≥ function

Page 17: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Definition of Functions using Conditionals

The basic primitive used in this case is if-then-else. Thus if a ≥ b, the function returns a as the output, else it returns b.

Note that for every pair of natural numbers as its input, max returns a unique number as the output and hence it adheres to the definition of a function.

Page 18: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Example: Finding the absolute value of x

• abs : → as

Page 19: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Inductive Definition of Functions

• Till now ,

Functions which can be evaluated by substitutions or evaluation of conditions

Inductively defined functional algorithm

Page 20: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Example: Computing the GCD of two numbers

gcd : × → as,

Function because:for every pair of positive integers as input, it gives a positive integer as the output. It is also a finite computational process: Unambiguously tells us how to compute the solution The process terminates after a finite number of steps.

Page 21: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Example: Computing the GCD of two numbers

gcd : × → as,

For example, gcd(18, 12),

gcd (18, 12) = gcd (12, 6) = gcd (6, 6) = 6.

Page 22: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Not all mathematically valid specifications of functions

Mathematically a perfectly valid

How to evaluate the function

Page 23: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Another Example

f: →

f(n) = 0 for n = 0 and

f(n) = f(n + 1) – 1 for all n

Unique solution However try to evaluate f(1)

Infinite computational process

rewrite

g(0) = 0

g(1) = g(0) + 1 = 1

g(2) = g(1) + 1 = g(0) + 1 + 1 = 2

Page 24: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Yet another…

f(n) = f(n)

• Every function is a solution to this trivial definition, but it is computationally undefined.

Page 25: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

A specification of a function is an algorithm ??

only if defines a precise computational procedure to evaluate it.

1. It is directly specified in terms of a pre-defined function which is either primitive or there exists an algorithm to compute the function.

2. It is specified in terms of the evaluation of a condition.

3. It is inductively defined and the validity of its description can be established through the principle of Mathematical Induction.

4. It is obtained through a finite number of combinations of the steps (1), (2), and (3) using substitutions.

Page 26: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Complex functions can be algorithmically defined in terms of two main types of processes

1. Recursive

2. Iterative.

Page 27: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Recursive Processes

• chain of deferred operations

Example

Factorial Computation: Given n ≥ 0, compute the factorial of n(n!).

factorial : → as

Page 28: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

A computation such as this is characterized by a growing (recursive descent) and a shrinking (recursive ascent) process.

factorial(5) = (5 × factorial(4)) = (5 × (4 × factorial(3))) = (5 × (4 × (3 × factorial(2))))

= (5 × (4 × (3 × (2 × factorial(1))))) = (5 × (4 × (3 × (2 × (1 × factorial(0))))))

= (5 × (4 × (3 × (2 × (1 × 1))))) = (5 × (4 × (3 × (2 × 1)))) = (5 × (4 × (3 × 2)))

= (5 × (4 × 6)) = (5 × 24) = 120

Page 29: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Analysis of Correctness and Efficiency

• Correctness : Principle of Mathematical Induction (PMI)

• Proof By PMI on n.

• Basis When n = 0, factorial(n) = 1 = 0! by definitions of factorial and 0!.

• Induction hypothesis For k = n − 1 , k ≥ 0, we have factorial(k) = k!.

• Induction step Consider factorial(n).factorial(n) = n × factorial(n − 1)

= n × (n ∕ 1)! by the induction hypothesis

= n! by the definition of n!

Page 30: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Efficiency :

In order to compute factorial(n), the n integers will have to be remembered somewhere (or stacked up)

This leads to a space requirement of about n.

Let T (n) be the number of multiplications required for a problem of size n

T(0) is obviously 0T(n) = T(n − 1) + 1

= T(n − 2) + 2

= T(0) + n= n

Page 31: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

More Examples of Recursive Algorithms

• Computing xn. Given an integer x > 0, compute xn, where n ≥ 0

• power : × → .

Page 32: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

More Examples of Recursive Algorithms

1. To count the number of primes between integers a and b (both inclusive).

2. Computing

3. Determining whether a positive integer is a perfect number.

A positive integer is called a perfect number if the sum of its proper divisors add up to the number itself.

Page 33: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

To count the number of primes between integers a and b (both inclusive).

Correctness To show that the function count_primes(a, b) returns the count of the number of primes between a and b, assuming the function prime(n) is correct.

Page 34: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Proof By PMI—strong version, on (b − a + 1).

Basis If a > b, the interval is empty and count_primes(a, b) returns 0.

Induction hypothesis count_primes(a, b − 1) returns the count of the number of primes between a and b − 1 for a, b such that (b − a + 1) ≥ 0.

Induction step If b is a prime then count_primes(a, b) returns count_primes(a, b − 1) + 1. Otherwise, it returns count_primes(a, b − 1).

Page 35: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Computing

• We will assume that the function f(n) is available. We can then define the function sum : × → , inductively, as:

Page 36: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Determining whether a positive integer is a perfect number.

We define a function perfect: → {true, false} for determining whether a number is perfect or not as follows:

perfect(n) = n = addfactors(n)

add factors: → :

addfactors(n) = sum(1 , n div 2)

Note that the n used in the definition of f(i) is the same as in the function perfect.

Page 37: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Determining whether a positive integer is a perfect number.

We define a function perfect: → {true, false} for determining whether a number is perfect or not as follows:

perfect(n) = n = addfactors(n)

add factors: → :

addfactors(n) = sum(1 , n div 2)

Note that the n used in the definition of f(i) is the same as in the function perfect.

Top-down design and step-wise refinement

Page 38: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Scope Rules

a and b are natural numbers and f is a function on natural numbers.

But what they denote???

Hence the names a, b, and f arecalled free in the expression

Page 39: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Scope Rules

However n is said to be bound in the sense that the expression makes it clear that nranges over the interval [a, b]

the scope of n is limited to the summation expression and we say that n is local to the summation function.

Page 40: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 41: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 42: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 43: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 44: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 45: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 46: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 47: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 48: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

factorial(5) = (5 × factorial(4)) = (5 × (4 × factorial(3))) = (5 × (4 × (3 × factorial(2))))

= (5 × (4 × (3 × (2 × factorial(1))))) = (5 × (4 ×(3 × (2 × (1 × factorial(0))))))

= (5 × (4 × (3 × (2 × (1 × 1))))) = (5 × (4 × (3 ×(2 × 1)))) = (5 × (4 × (3 × 2)))

= (5 × (4 × 6)) = (5 × 24) = 120

Page 49: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

factorial(5) = (5 × factorial(4)) = (5 × (4 × factorial(3))) = (5 × (4 × (3 × factorial(2))))

= (5 × (4 × (3 × (2 × factorial(1))))) = (5 × (4 ×(3 × (2 × (1 × factorial(0))))))

= (5 × (4 × (3 × (2 × (1 × 1))))) = (5 × (4 × (3 ×(2 × 1)))) = (5 × (4 × (3 × 2)))

= (5 × (4 × 6)) = (5 × 24) = 120

Space??

Page 50: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Tail-Recursion

factorial(5) = fact_iter(5, 1, 0) = fact_iter(5, 1, 1) = fact_iter(5, 2, 2) = fact_iter(5, 6, 3)

= fact_iter(5, 24, 4)

= fact_iter(5, 120, 5)

= 120

Page 51: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Tail-Recursion

factorial(5) = fact_iter(5, 1, 0) = fact_iter(5, 1, 1) = fact_iter(5, 2, 2) = fact_iter(5, 6, 3)

= fact_iter(5, 24, 4)

= fact_iter(5, 120, 5)

= 120Space??

Page 52: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Fibonacci numbers: Computation of the nth Fibonacci number, n ≥ 1.

• fib : →

Computation mechanism of iterative processes reveals that final state is obtained from a starting state

Page 53: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

3

Page 54: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

3

Space??Time??

Page 55: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

• Computation speed:• Start with the two smallest Fibonacci numbers• Retain the values of the last two Fibonacci numbers as the state• Use a counter count, to represent the stages of the computation.

• An invariant condition for this process for n ≥ 3 is

(n ≥ 3) Λ (3 ≤ count ≤ n) Λ (a = fib(count − 2)) Λ (b = fib(count − 1))

Page 56: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

n−2 additions to compute fib(n) for n ≥ 3

O(n) time and O(1) space for computing the nth Fibonacci number.

Page 57: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

The Primitives for the Imperative Model

• State of a computation as a collection of instantaneous values of certain quantities.

• A state change occurs if at least one of the quantities comprising the state is changed.

• The imperative model of computation uses instructions or commands to make the desired state changes.

Page 58: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Imperative model constructs

• Variables and the assignment instruction

• Assertions

• The if-then-else instruction

• The while-do instruction

• Functions and procedures in the imperative model

Page 59: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Step-Wise Refinement

• Determining whether a given positive integer n is a prime • 1 is not a prime. • Since all even numbers are divisible by 2, the only even prime is 2 itself. • Hence a prime other than 2 is necessarily an odd number. • If n is an odd number, we can determine whether n is a prime by testing the

divisibility of n by test divisors chosen successively from the sequence 3, 5, 7, 9 ….

Page 60: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

prime(n) = (n = 2) V (odd(n) Λ (smallest_divisor(n) = n))

Page 61: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

• The function odd: → {true, false} can be defined as

odd(n) = ((n mod 2) = 1)

• smallest_divisor(n) = find_iter(n, 3)

Page 62: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM
Page 63: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

Proof Rule

• Proof rules are generally expressed as:

H1, H2, … Hn / H

if H1, H2, … are all true then H is also true.

For example, {P} S {R}, R Q / {P} S {Q}

Page 64: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM

proof rules for simple statements

{P} S {R}, R Q / {P} S {Q} (I)

For example, from {(x > 0) (y > 0)} S {(z + u * y = x * y) (u = 0)} and (z + u * y = x * y) (u = 0) (z = x * y), we conclude that

{(x > 0) (y > 0)} S {z = x * y}

P R, {R} S {Q} / {P} S {Q} (II)

Consequence Rules.

Page 65: Unit 2faculty.pictinc.org/LectureNotes/Unit 2.pdf · Title: Microsoft PowerPoint - Unit 2 Author: PICT Created Date: 1/15/2019 12:38:29 PM