Representing Specifications

4.3.1 Representing Specifications

If one asks junior computer science (CS) students in a programming course to write

a C++ function that reads a real number and compute its square root, they would

4.3 SIMPLE INPUT OUTPUT PROGRAMS

Total Surjective

Deterministic

Reflexive

Symmetric Antisymmetric

Partial ordering

Total ordering

Figure 4.7 Properties of relations.

rush immediately to their computers to write code and run it; and yet this problem statement, despite being simple and short, leaves many questions unanswered. Consider that this statement may be interpreted in a wide range of manners, leading to a wide range of possible specifications, where space S is defined to be the set of real numbers:

1. Only nonnegative arguments will be submitted; the output is a (positive or non- positive) square root of the input value:

s 1 2 s,s s ≥ 0 =s

2. Only non-negative arguments will be submitted; the output is the nonnegative square root of the input value:

2 = s,s s ≥ 0 s =s s≥0

44 SOFTWARE SPECIFICATIONS

3. Only nonnegative arguments will be submitted; the output is an approximation (within a precision ε) of a (positive or non-positive) square root of the input value:

s,s s ≥ 0 2 s =s<ε

4. Only nonnegative arguments will be submitted; the output is an approximation (within a precision ε) of the non-negative square root of the input value:

4 = s,s s ≥ 0 s =s<ε s≥0

5. Negative arguments may also be submitted; for negative arguments, the output is −1; for nonnegative arguments, the output is a (positive or nonpositive) square root of the input value:

5 = s,s s ≥ 0 s =s s,s s < 0 s = −1

6. Negative arguments may also be submitted; for negative arguments, the output is −1; for nonnegative arguments, the output is the nonnegative square root of the input value:

R 6 = s,s s ≥ 0 s 2 =s s≥0

s,s s < 0 s = −1

7. Negative arguments may also be submitted; for negative arguments, the output is arbitrary; for nonnegative arguments, the output is an approximation (within a precision ε) of a (positive or nonpositive) square root of the input value:

R = s,s s≥0 s 2 7 =s<ε

s,s s < 0

8. Negative arguments may also be submitted; for negative arguments, the output is arbitrary; for nonnegative arguments, the output is an approximation (within a precision ε) of the non-negative square root of the input value:

R 8 = s,s s≥0 2 s =s<ε s≥0 s,s s < 0

9. Only nonnegative arguments will be submitted; the output must be within ε of the exact square root of the input (comparison with specification R 4 : Precision ε applies to the square root scale rather than the square scale):

R 9 = s,s s≥0 s−s<ε

4.3 SIMPLE INPUT OUTPUT PROGRAMS

We could go on and on. This simple example highlights two lessons: First, the importance of precision in specifying program requirements and second, the premise that relations enable us to achieve the required precision.

As a second illustrative example, consider the following requirement pertaining to space S defined by an array a[1..N] of some type, where N is greater than or equal to 1,

a variable x of the same type, and an index variable k, which we use to address array a: Search x in a and place its index in k. Again, this simple requirement lends itself to a wide range of interpretations, some of which we write as follows, along with their relational representation:

1. Variable x is known to be in a; place in k an index where x occurs in a.

F 1 = s,s h1≤h≤Nah=x ak=x

2. Variable x is known to be in a; place in k the first (smallest) index where x occurs in a.

F 2 = s,s h1≤h≤Nah=x ak=x h1≤h<kah x =F 1 s, s

h1≤h<kah x

3. Variable x is known to be in a; place in k an index where x occurs in a, while preserving a and x.

F 3 =F 1 s,s a = a x = x

4. Variable x is known to be in a; place in k the first (smallest) index where x occurs in a, while preserving a and x.

F 4 =F 2 s,s a = a x = x

5. Variable x is not known to be in a; if it is not, place 0 in k; else place in k an index where x occurs in a.

F 5 =F 1 s,s

h1≤h≤Nah x k=0

6. Variable x is not known to be in a; if it is not, place 0 in k; else place in k the first (smallest) index where x occurs in a.

F 6 =F 2 s, s

h1≤h≤Nah x k=0

7. Variable x is not known to be in a; if it is not, place 0 in k; else place in k an index where x occurs in a, while preserving a and x.

F 7 =F 3 s, s

h1≤h≤Nah x k=0

46 SOFTWARE SPECIFICATIONS

8. Variable x is not known to be in a; if it is not, place 0 in k; else place in k the first (smallest) index where x occurs in a, while preserving a and x.

F 8 =F 4 s,s

h1≤h≤Nah x k=0

Note that F 1 can be written simply as F 1 = s,s

a k = x since the clause

h 1 ≤ h ≤ N a h = x is a logical consequence of a k = x. We draw the reader’s attention to the importance of carefully watching which variables are primed and which are unprimed in a specification. By writing F 1 as we did, we mean that the final value of k points to a location in the original array a where the original value of x is located. As written, this relation specifies a search program. If, instead of F 1 , we had written the specification as follows:

F 1 = s,s a k = x ,

then it would be possible to satisfy this specification by the following simple program:

{k=1; x=a[1];}

If, instead of F 1 , we had written the specification as follows:

F 1 = s,s ak=x,

then it would be possible to satisfy this specification by the following simple program:

{k=1; a[1]=x;}

If, instead of F 1 , we had written the specification as follows:

F 1 = s,s ak=x,

then it would be possible to satisfy this specification by the following simple program:

{k=1; x=0; a[1]=0;}

Neither of these three programs is performing a search of variable x in array a.

Dokumen yang terkait

Analisis Komparasi Internet Financial Local Government Reporting Pada Website Resmi Kabupaten dan Kota di Jawa Timur The Comparison Analysis of Internet Financial Local Government Reporting on Official Website of Regency and City in East Java

19 819 7

ANTARA IDEALISME DAN KENYATAAN: KEBIJAKAN PENDIDIKAN TIONGHOA PERANAKAN DI SURABAYA PADA MASA PENDUDUKAN JEPANG TAHUN 1942-1945 Between Idealism and Reality: Education Policy of Chinese in Surabaya in the Japanese Era at 1942-1945)

1 29 9

Improving the Eighth Year Students' Tense Achievement and Active Participation by Giving Positive Reinforcement at SMPN 1 Silo in the 2013/2014 Academic Year

7 202 3

Improving the VIII-B Students' listening comprehension ability through note taking and partial dictation techniques at SMPN 3 Jember in the 2006/2007 Academic Year -

0 63 87

The Correlation between students vocabulary master and reading comprehension

16 145 49

Improping student's reading comprehension of descriptive text through textual teaching and learning (CTL)

8 140 133

The correlation between listening skill and pronunciation accuracy : a case study in the firt year of smk vocation higt school pupita bangsa ciputat school year 2005-2006

9 128 37

Perancangan Sistem Informasi Akuntansi Laporan Keuangan Arus Kas Pada PT. Tiki Jalur Nugraha Ekakurir Cabang Bandung Dengan Menggunakan Software Microsoft Visual Basic 6.0 Dan SQL Server 2000 Berbasis Client Server

32 174 203

Pengaruh Kualitas Software Aplikasi pengawasan kredit (C-M@X) Pt.PLN (PERSERO) Distribusi Jawa Barat Dan Banten (DJBB) Terhadap Produktivitas Kerja karyawan UPJ Bandung Utara

5 72 130

Transmission of Greek and Arabic Veteri

0 1 22