Sample Formulas

5.3.1 Sample Formulas

As a way to nurture the reader’s understanding of this notation, we give below a number of formulas, which we want to consider as valid (in reference to the definition above); we let x and y be integer variables and we classify the sample formulas by the control structure of the program p.

Assignment statement: • {x=1} x=x+1; {x=2}

• {x≥1} x=x+1; {x≥2} • {x≥1} x=x+1; {x≥1} • {x=1

y=4} x=x+1; {x=2

y=4}

• {x=x0} x=x+1 {x=x0+1}, for some constant x0. • {x=x0

y=y0} x=x+1 {x=x0+1 y=y0}, for some constants x0 and y0. • {x=x0

y=y0} x=x+1 {x≥x0+1 y≥y0}, for some constants x0 and y0. Sequence statement:

• {x=3} x=x+3; y=x*x; {x=6

y=36}

• {x=3} x=x*x; y=x+9 {x=9

y=18}

• {x=x0 y=y0} x=x+3; y=x*x; {x=x0+3 y=(x0+3) 2 }, for some constants x0 and y0. • {x=x0

y=y0} x=x*x; y=x+9; {x=x0 2 y=x0 2 +9}, for some constants x0 and y0. • {x=x0

y=y0} x=x+y; y=x–y; x=x–y; {x=y0 y=x0}, for some constants x0 and y0. • {x=x0

y=y0} x=x+1; y=y–1; {x=x0+1 y=y0–1}, for some constants x0 and y0.

90 PROGRAM CORRECTNESS AND VERIFICATION

• {x=x0 y=y0} x=x+1; y=y–1; {x+y=x0+y0}, for some constants x0 and y0. • {x+y=A} x=x+1; y=y–1; {x+y=A}, for some constant A.

Conditional statement: • {true} if (x<0) {x=−x;} {x≥0}. • {x=x0} if (x<0) {x=–x;} {x=|x0|}. • {true} if (x<y) {x=x+y; y=x−y; x=x−y;} {x≥y}. • {x=x0

y=y0} if (x<y) {x=x+y; y=x–y; x=x–y;} {x=max(x0,y0) y=min (x0,y0)}, for some constants x0 and y0.

Alternation statement: • {x=x0

x y} if (x>y) {x=x–y ;} else {y=y–x ;} {gcd(x,y)=gcd(x0,y0)}, for some constants x0 and y0. • {gcd(x,y)=A

x y} if (x>y) {x=x–y ;} else {y=y–x ;} {gcd (x,y)=A}, for some constant A.

x>0

y>0

Iteration: • {true} while (y 0) {x=x+1; y=y–1;} {y=0} • {y≥0} while (y 0) {x=x+1; y=y–1;} {y=0} • {y<0} while (y 0) {x=x+1; y=y–1;} {y=0} • {x=x0

y=y0} while (y 0) {x=x+1; y=y–1;} {x=x0+y0 y=0}, for some constants x0 and y0. • {y≥0} while (y>0) {x=x+1; y=y–1;} {y=0}

• {x=x0 y≥0} while (y>0) {x=x+1; y=y–1;} {x≥x0} • {y<0} while (y>0) {x=x+1; y=y–1;} {y<0}

• {x=x0 y=y0 y≥0} while (y>0) {x=x+1; y=y–1;} {x=x0+y0 y=0}, for some constants x0 and y0. • {x=x0

y=y0 y<0} while (y>0) {x=x+1; y=y–1;} {x=x0 y= y0 y<0}, for some constants x0 and y0. • {y<0} while (y 0) {x=x+1; y=y–1;} {y=–1}

• {y<0} while (y 0) {x=x+1; y=y–1;} {y=1} • {y<0} while (y 0) {x=x+1; y=y–1;} {y=2}

We leave it to the reader to ponder, by reference to the definition of this notation, why each one of the formulas above is valid. So far we have established the validity of these formulas by inspection, in reference to the definition. For larger and more com- plex programs, this may not be practical; in the next section, we introduce a deductive process that aims to establish the validity of complex formulas by induction on the complexity of the program structure.

5.3 VERIFICATION

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