Assignment #4 - Software Verification and Validation | CP SC 873, Assignments of Computer Science

Material Type: Assignment; Class: SOFTWARE VERIF VALID; Subject: COMPUTER SCIENCE; University: Clemson University; Term: Spring 2007;

Typology: Assignments

Pre 2010

Uploaded on 07/28/2009

koofers-user-f25
koofers-user-f25 🇺🇸

8 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CpSc 873 Spring 2007
Assignment #4:
Reasoning About Programs (II)
March 8, 2007
1 Overview
The goal of this assignment is to give you some practice reasoning about program termination.
In particular, the assignment will help to improve your ability to reason rigorously about program
termination using mathematical induction based on a variant function.
1. Beans, Beans, Again (10 points). Recall the following question from your most recent
midterm exam: Consider a can of black and white coffee beans. You are guaranteed that the
can of beans is initially non-empty. Now consider the following process:
Choose two beans from the can. If they are the same color, toss them out and put
in a white bean. If they are different colors, toss them out and put in a black bean.
Assume that you have enough black and white beans laying around that you can
always add a bean of either color.
(a) (1 points). Let wbe the number of white beans in the can, and let bbe the number
of black beans in the can. Write the program corresponding to the previous informal
description. (Your program should have only two variables, wand b.)
(b) (1 points). Calculate the fixed point of this program, simplifying as much as possible.
(c) (8 points). Prove, using a variant function, that this program terminates. Be as
rigorous as possible.
2. Everything in its Place (10 points). Consider the following program:
program EIIP
var A: array 0..N 1 of integer
assign
([]x: 0 x < N : 0 A[x]< N A[x], A[A[x]] := A[A[x]], A[x]) (1)
(a) (2 points). Calculate the fixed point of this program, simplifying as much as possible.
(b) (8 points). Prove, using a variant function, that this program terminates. Be as
rigorous as possible.
Hand-In Instructions
The assignment is due at the start of class on March 15th. You are required to turn in a typed
document, or alternatively, a document written using exceedingly legible handwriting.
1
pf2

Partial preview of the text

Download Assignment #4 - Software Verification and Validation | CP SC 873 and more Assignments Computer Science in PDF only on Docsity!

CpSc 873 Spring 2007

Assignment #4:

Reasoning About Programs (II)

March 8, 2007

1 Overview

The goal of this assignment is to give you some practice reasoning about program termination. In particular, the assignment will help to improve your ability to reason rigorously about program termination using mathematical induction based on a variant function.

  1. Beans, Beans, Again (10 points). Recall the following question from your most recent midterm exam: Consider a can of black and white coffee beans. You are guaranteed that the can of beans is initially non-empty. Now consider the following process:

Choose two beans from the can. If they are the same color, toss them out and put in a white bean. If they are different colors, toss them out and put in a black bean. Assume that you have enough black and white beans laying around that you can always add a bean of either color.

(a) (1 points). Let w be the number of white beans in the can, and let b be the number of black beans in the can. Write the program corresponding to the previous informal description. (Your program should have only two variables, w and b.) (b) (1 points). Calculate the fixed point of this program, simplifying as much as possible. (c) (8 points). Prove, using a variant function, that this program terminates. Be as rigorous as possible.

  1. Everything in its Place (10 points). Consider the following program:

program EIIP var A : array 0..N − 1 of integer assign ([]x : 0 ≤ x < N : 0 ≤ A[x] < N → A[x], A[A[x]] := A[A[x]], A[x]) (1)

(a) (2 points). Calculate the fixed point of this program, simplifying as much as possible. (b) (8 points). Prove, using a variant function, that this program terminates. Be as rigorous as possible.

Hand-In Instructions

The assignment is due at the start of class on March 15th. You are required to turn in a typed document, or alternatively, a document written using exceedingly legible handwriting.

CpSc 873 Spring 2007

Notes on Collaboration

You are required to work individually on this assignment. Please do not consult anyone other than me on any aspect of this assignment.

Assignment Attribution

The questions on this assignment were developed by Paul Sivilotti. Thanks Paul!