Download as pdf or txt
Download as pdf or txt
You are on page 1of 296

/€86S80001

J
7

phbbipetteapety
* Oo

= < whet
Peserenan ;

: TESS UMBUMOCE
SFE LESTE
BOD LATE
IO EP SERNETEATE TARR
2s ATS OATTIS LAR IRAESSEMRA

iobot, Spaaat rete piers Lt CHLOE MMe


UNIVERSITY of ALASKA
ELMER BE. RASMUSON LIBRARY
Introduction to
Computer Science Mathematics
Digitized by the Internet Archive
in 2022 with funding from
Kahle/Austin Foundation

https//archive.org/details/introductiontoco0000jami
Robert V. Jamison
Northrop Institute of Technology

Introduction to
Computer Science Mathematics

McGraw-Hill Book Company

New York Kuala Lumpur Panama


St. Louis London Rio de Janeiro
San Francisco Mexico Singapore
Diisseldorf Montreal Sydney
Johannesburg New Delhi Toronto
itn
Fee siaae
THE r
OF ALASKA
Library of Congress Cataloging in Publication Data
Jamison, Robert V.
Introduction to computer science mathematics.
1. Mathematics--1961- I. Title.
QA39.2.J35 510 70-39901
ISBN 0-07-032276-7

INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS

Copyright © 1973 by McGraw-Hill, Inc. All rights re-


served. Printed in the United States of America. No part of
this publication may be reproduced, stored in a retrieval
system, or transmitted, in any form or by any means, elec-
tronic, mechanical, photocopying, recording, or otherwise,
without the prior written permission of the publisher.

12 ESR 4e0n6) 708) II0CKG Rak e7e9ese 7sGroned

The editors for this book were Robert Flowers and Cath-
erine Kerr, the designer was Marsha Cohen, and its
production was supervised by James E. Lee. It was set
in Palatino by Progressive Typographers. It was printed
and bound by Kingsport Press Inc.
Contents
Preface
Vii

Chapter 1 The Decimal Number System


u

1.1 Introductory Remarks 1


1.2 The Decimal Number System z.
1.3 Standard Form. Significant Figures. Rounding off 7
1.4 Operations 12
1.5 Concluding Remarks 17

Chapter 2 Nondecimal Number Systems 19

2.1 Introductory Remarks 19


2.2 The Decimal Value of Nondecimal Numbers 20
2.3 Transforming Decimal Numbers into Nondecimal Numbers 24
2.4 Related Bases 28
2.5 Arithmetic Opertons in Various Bases 31
2.5.1 Addition 31
2.5.2 Subtraction 34
2.5.3 Multiplication 39
2.5.4 Division 41

2.6 Binary Coded Decimal Numbers 47

Chapter 3 Algebra: Linear Functions 53

3.1 Preliminary Remarks 53


3.2 Functions 58
3.3 Coordinate Systems. Analytic Geometry of the Straight Line 60
3.4 Simultaneous Linear Equations 65
3.5 Linear Inequalities in One Variable. Absolute Value 69
3.6 Linear Inequalities in Two Variables Us
3.7 Linear Programming 78
3.8 Fitting Data to a Line. Summation 82

Chapter 4 Introduction to Symbolic Programming Languages, Fortran 89

4.1 Introductory Remarks 89


4.2 Introduction to Fortran Programming 91
4.3 Fortran Arithmetic Statements 94
4.4 Fortran Input-output Statements. Fortran programs 104
4.5 Fortran Control Statements 116
Chapter5 Arrays. Matrices. Determinants 127
5.1 One-dimensional Arrays 127
5.2 Matrices 131

5.2.1 Introduction. Definitions 131


5.2.2 Algebra of Matrices 133
5.2.3 Solution of Simultaneous Linear Equations 137.
5.2.4 Elementary Row Operations. Inverses 140

5.3 Determinants 147

Chapter 6 Polynomial Functions 155

6.1 Introductory Remarks 155


6.2 Complex Numbers 156
6.3 Quadratic Functions and Equations 158
6.4 Analytic Geometry of Quadratic Functions; Curvefitting 160
6.5 Polynomial Equations of Degree Higher Than 2 167

Chapter 7 Exponential and Logarithmic Functions 173

7.1 Introduction. Definitions 173


7.2 Calculations Involving Logarithmic and Exponential Functions 7
7.3 Transcendental Equations Involving Logarithmic and
Exponential Functions 178
7.4 Log and Semilog Graph Paper. Curvefitting 181
7.5 Approximations Based on Series 188

Chapter 8 Boolean Algebra 193

8.1 Introductory Remarks 193


8.2 Series-parallel Switching Circuits. Logic Blocks 194
8.3 Basic Operations. Identities. Theorems 197)
8.4 Normal Forms for Boolean Expressions 210
8.5 Simplification of Boolean Expressions: Karnaugh Maps 213
8.6 Other Logic Blocks: NAND, NOR 229
8.7 Applications of Boolean Algebra: Half- and Full-adders 235

Answers to Selected Exercises 243

Index 269

vi CONTENTS
Preface
This book is designed to present those special topics which are generally con-
sidered fundamental to the fields of data processing, computer programming,
and computer design. Its level is that of a first course with one year of algebra
considered prerequisite. The material is suitable for all students who will do
any kind of computing, whether they will ultimately specialize in business or
scientific and engineering applications or whether their interest will lie in strict
computer science and computer design applications.
Finite mathematics concepts are covered in two chapters on the decimal
number system and on other number systems, including the binary system. A
comprehensive study of arithmetic in all these number systems is presented.
The function concept is used throughout. Linear, quadratic, polynomial,
exponential, and logarithmic functions and equations are included. Addition-
ally, they are linked together through the general topic of curvefitting. Numer-
ical and useful semigraphical methods are explained and used extensively.
Particular attention is paid to the linear function by means of such topics as
linear equations, simultaneous linear equations, linear inequalities, linear
programming, and matrix methods. Set theory is used throughout rather than
being presented as a separate topic. Further topics in algebra should be
studied by means of a full course in college algebra.
Matrices and determinants and their applications are discussed in a
separate chapter. Included are applications of the method of elementary row
operations to the finding of matrix inverses and to the solution of simultaneous
linear equations.
Symbolic programming languages are discussed. A complete presenta-
tion is made of a somewhat shortened version of the Fortran IV language.
Fortran was chosen as the language most suitable for the solution of the types
of problems presented in this book. Basic Fortran IV is presented, including
such topics as real and integer constants, arithmetic statements, input and out-
put statements with Format, and control statements. Subprogramming is not
discussed. Complete executable Fortran programs can be written following the
study of this material. The topics of program planning and flowcharting are
presented, and Fortran programs are used to solve problems throughout the
subsequent portion of the book. Once again, those who will specialize in
programming to solve advanced problems in the scientific and engineering
fields can then undertake a full course in Fortran programming and with this
background should succeed with great ease.
The rather extended chapter on Boolean algebra proceeds from the basic
physical properties of the simple switching circuit to a full study of the theory
and further applications of Boolean algebra. Such topics as Boolean identities,
truth tables, and normal forms for Boolean expressions are covered. Karnaugh

vii
maps are used extensively as the main method for simplifying Boolean expres-
sions. Throughout, logic blocks are used to design logic circuits that imple-
ment Boolean functions. Functionally complete logic blocks such as NAND
and NOR are explained and employed. An insight into the design of the arith-
metic unit of a digital computer is provided by the section on half- and full-
adders.
Problem sets are interwoven throughout the chapters immediately fol-
lowing the presentation of the topics to which they apply. Answers to selected
exercises appear at the end of the book.
The author is indebted to Robert D. Chenoweth, County College of
Morris, Robert L. Monsees, Meramec Community College, and Forrest L.
Barker, Los Angeles City College, for their critical reviews of the original manu-
script and their valuable suggestions for its improvement.
Robert V. Jamison

viii PREFACE
Introduction to
Computer Science Mathematics
.

; 7 sh oe! Ca ral

oa e)> : 5
MARR
; : S _——

SS
The Decimal Number System

1.1 INTRODUCTORY REMARKS

The first chapter of this book is about decimal numbers because they are the
objects that we write, manipulate, and combine in various ways to do all the
computations that are required to solve problems. We do not intend to discuss
the theoretical and abstract nature of numbers. Instead, we shall often assume
that you are familiar with many of the properties of numbers simply because
you have used them so often in presumably reasonable and useful applica-
tions. Sometimes, though, we shall present interesting properties of numbers
in unusual ways in order to provoke some new thinking on your part. It is
extremely important that we understand the properties of numbers and the
rules of arithmetic before we undertake the study of algebra. After all, algebra
is simply a generalization of the arithmetic of numbers in which nonnumeric
symbols are often used to represent numbers.
No matter how delightfully descriptive (or mischievously deceptive)
the language in which a problem in science, engineering, business, or other-
wise is stated, the words must be translated into algebraic and other kinds of
relations and equations among the numbers and symbols representing num-
bers. To make this possible, we shall always require that the problem be in-
herently amenable to mathematical solution; that is, it must be well posed.
This translation must accurately restate the problem in mathematical form. It
therefore seems fairly evident that careful reading and logical analysis of the
problem as well as familiarity with applicable mathematical language are abso-
lutely essential for making the correct mathematical interpretation.
ALGEBRAIC
MATHEMATICAL WORD
WORD FORMULATION
SOLUTION SOLUTION
PROBLEM OF THE
PROBLEM

Fig. 1.1

With all the rhetoric then removed, the problem becomes one on which
is, the
the principles and techniques of applied mathematics can be used, that
and computin g you will learn here and in later courses in
tools of analysis
applied mathematics. The solution of the problem can then be translate d back
into the language in which it was originally stated.
The process just described can be graphically represented by the block
diagram of Fig.1.1. All problems from whatever source must be translated into
the form shown in block II and solved by mathematical techniques indicated
by block III without any consideration as to the original meaning of the num-
bers, symbols, and relations involved. In this sense, applied mathematics is
abstract. Much of your work will be concerned with the achieving of the solu-
tion required in block III after the problem has been properly stated mathe-
matically. Experience through much practice is the only reasonable way of
acquiring the facility in thought and deed necessary to achieve proper and
accurate results.

1.2 THE DECIMAL NUMBER SYSTEM

Any number is constructed from a (usually) small set of basic numbers called
digits. As you recall, the digits of the decimal number system are the 10 inte-
gers 0,1, 2,3, 4,5, 6, 7,8, and 9. It is from the number of digits that the sys-
_ tem takes its name. If we include the three symbols + (the plus sign), — (the
_ minus sign), and . (the decimal point), we can construct every number of the
decimal number system. Any number of the system is simply a sequence of
these digits and symbols formed by placing them horizontally and in close
proximity, that is, next to each other. Of course, a few rules must be followed.
The minus sign, as you already know, need not occur at all and if it does, it
must appear as the first symbol of the number and can occur only once in each
number. The decimal point need not appear either but if it does, it can occur
only once and can be in any position in the sequence. Thus, we can have the
numbers —43.7000, 0.1324, 8475663, and —3.002.
Numbers whose first symbol is the minus sign are called negative num-
bers; for example, —3.56 and —4567723 are negative numbers. Those num-
bers that do not start with the minus sign are called positive numbers; for ex-
ample, 0.0098 and 2345.7 are positive numbers. Sometimes the positiveness of

2 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


a number is emphasized by starting the sequence with the symbol + (the plus
sign). Thus, we sometimes write +0.0098 and +2398.7, but we shall continue
to omit the plus sign before numbers if its use is merely to indicate that the
number is positive.
Numbers that contain no decimal point are called integers. Thus, 0,—12,
and 3753 are integers. Obviously, there are positive and negative integers.
The positive integers are often used for counting. We shall later also use
them as subscripts.
The sequence of symbols that occur before the decimal point is called
the integral or whole part of the number. For example, 17.38 has 17 for its in-
tegral part; —896.7 has —896 for its integral part. The integral part of anumber
is an integer. The part of the number that starts with the decimal point and
includes all the digits that follow the decimal point is called the fractional part
of the number. 17.38 has .38 as its fractional part; 0.083 has .083 as its frac-
tional part. Integers, like 255, of course, have no fractional part.
We shall see when we discuss in Chap. 4 the computer language called
Fortran that much is made of the difference between numbers that do and
do not contain a decimal point.. In that language a number is called an integer
if it does not contain a decimal point, just as we have defined it. It is called
real if it does contain a decimal point. Adding a decimal point after the 7 in
17 changes the integer 17 to the real number 17. in that language.
Nothing has yet been said about how many digits a number may con-
tain. None of the sample numbers we have shown so far have had very many.
In your experience in computing with numbers of the decimal system, you
undoubtedly preferred numbers that contained relatively few digits. Many
desk calculators have room in their register for only 12 digits, and all digital
computers, although they may allow many more digits than 12 in their reg-
isters, still definitely restrict the number of digits in all the numbers they
operate on. Here is where the kind of numbers used in theoretical mathe-
matics and those used in actual computing work differ. Let us first discuss
numbers that are hypothetically allowed in mathematics.
Any quantity of digits, including sequences which go on indefinitely
and never stop, is allowed in numbers. Thus, 37.828282 . . . could indicate
that the number has infinite repetitions of the terminal sequence 82. Fora
number of this kind we shall prefer the notation 37.(82), in which the paren-
theses around 82 are used to indicate the infinite repetition of the terminal
sequence 82. In the representation 37.828282 . . . , the three decimal points
indicate that the pattern thus presumably set is to be repeated indefinitely.
A number need not terminate (that is, have a last digit) nor repeat a terminal
sequence at all. In this case, we would use the. . . notation. For example,
2.14935876 . . . could indicate a number in which no repeating pattern of
digits ever occurs.

THE DECIMAL NUMBER SYSTEM 3


Now, a number which terminates or which has a terminal repeating
sequence like 37.(82) is called a rational number. Any rational number can be
represented exactly as the quotient of two integers; in fact, this property of
rational numbers is often taken as their defining property. In Exercise 1.2 we
shall present a method for finding these integers for a rational number pre-
sented in decimal form. It seems fairly obvious that all integers are rational
numbers according to this last criterion. For example, the integer 17 can be
written as 17/1, the ratio of two integers, and hence is a rational number.
A number which does not terminate and which never exhibits a re-
peating sequence no matter how far one continues its digits is called irrational.
You recall that numbers which you have previously symbolized as V2, V7,
and 7 are irrational. They are thus represented by digit sequences that do
not terminate and never have a repeating terminal sequence. An irrational
number cannot be expressed as the quotient of two integers.
The entire collection of all rational and irrational numbers is called (in
mathematics) the set of real numbers. In Chap. 6 we shall define a new kind
of number called complex. We shall see that every real number is a complex
number but that there are complex numbers which are not real.
As we mentioned above, in computing either by hand or by any kind
of mechanical or electronic computer, all numbers must be represented by a
sequence of digits that does terminate. When computing by hand, carrying
too many digits in the numbers puts a strain on anyone’s patience and time.
Suppose a calculator allows five digits, regardless of the position of the
decimal point in the number, if it has one. Clearly, one cannot insert such ir-
rational numbers as 38.25827546 . . . , such rational numbers as 7.(3), or even
such integers as 84670995 into the calculator. To use such numbers in this
machine, one must first cut them off in some way to a maximum of five digits.
We shall return to this project and discuss the notion of significant figures
in.Sec., 1,3,
We must now turn to the notion of the value of the numbers we have
constructed. Long experience with numbers has no doubt revealed to you
that somehow, even though the numbers 861 and 168 are composed of the same
set of integers, the digits are in different orders and the numbers have differ-
ent “‘values.’” This is implied by the very way we read the numbers. When
we read the number 861, we do not just say “eight six one,” we say “eight
hundred sixty-one.”
The simple but important concept of how the position of the
digits in
a number determines its value is explained below. Consider the following
diagram:

4 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


The blocks indicate the positions the digits of the number will occupy. They
are numbered as shown starting with 0 at the block farthest to the right and
proceeding to the left. Associated with each digit in a number is a value called
its positional value. It is determined in the following way: The positional value
of a digit in position 0 (called the units position) is 10° = 1; the positional value
of a digit in position 1 (called the tens position) is 10' = 10; in a similar way, in
position 2 (called the hundreds position) a digit has positional value 10” = 100;
and in position 3 (the thousands position) a digit has positional value 10° = 1000.
The same process continues as indicated until the first digit of the number has
been reached and assigned its positional value. We finally arrive at the fol-
lowing rule: The value of a number is the sum of the product of each digit of
the number and its respective positional value. Thus,

| PEM
a 16) ee)

8| 6 4 4

has value 8 X 10? +6 Xx 107+ 4 x 10'+ 4 x 10° = 8000 + 600 + 40 +4, which
we read “eight thousand six hundred forty-four.’’ This is the value of the
number that we write, using only the digits underlined, as 8644.
The method just used gives the value of numbers which either are inte-
gers or have a decimal point immediately after their last digit. Let us now see
how we find the value of numbers that have zero integral part. Recall that
1 1 i
—_ = 0:17.10 a100
10 1 =— 10 1000 = 0.001, and so forth, so that
0.01, 10 —3 — ———_

a nonzero number with zero integral part can have its digits placed in the
following diagram:

et >
Now, the positional value of a digit in position —1 (called the tenths position)
is 10-'= 0.1; the positional value of a digit in position —2 (called the hun-
dredths position) is 10-?=0.01; similarly, a digit in position —3 (called the
thousandths position) has positional value 10 *= 0.001; we can continue in the
same way until we reach the last digit of the number and its positional value
is assigned. Thus,

Ano eewaliomo 10 8+ 0.x 102-7 x 102 25 10 a9 10 S— 0:3 7, 0.00


+ 0.007 + 0.0005 + 0.00009, which we write, using the digits underlined, as

THE DECIMAL NUMBER SYSTEM 5


0.30759. The number in this example has an interior zero digit. If we pose a
problem in reverse—write a number with value 3 x 107' + 8 x 10% +9 x 10->—
we must insert the digit zero in the appropriate positions in the number so
that the proper value will be obtained by using the method described above.
The number is 0.30809.
More generally a number can have both integral and fractional parts.
For example,

has value 8 xX 10?+6x10!+6 x 10°+0x10!+5x107+9xX 10 3= 800


+ 60+ 6+ 0.0 + 0.05 + 0.009, which we write 866.059.
All this probably seems self-evident to you, but only because your pre-
vious use of numbers has impressed the notion of position and its connection
with value deeply in your consciousness. Actually the notion of position is not
at all obvious, and the positional notation which is so natural to us today has
evolved after years of thought and refinement on the part of mathematicians.

EXERCISES
1.1 Represent each of the following rational numbers in the form of
infinitely repeating decimals. Use the abbreviated notation de-
scribed in the text. Example: 2./3. = 0.(6).

(a) 16./11.
(b) 53./15.
(c) 4./7.
(d) —17./23.
(e) 35./4.
(f) 11./9.

1.2 The repeating decimal 1.(63) can be represented as the ratio of two
integers by following this procedure: Let p = 1.63636363 . . . ; then
100p = 163.63636363 . . . . By subtraction, 99p =162. Therefore,
p = 162/99 = 18/11. Use this procedure to represent the following
repeating decimals as the ratio of two integers:

(a) 0.(23)
(b) 1.6(4)
(c) —0.0(325)
(d) 0.0000(87)

6 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(e) 4.(6034)
(f) 0.45(7)
(g) 12.(5)
(h) —0.36(72)
(i) 0.00(707)

1.3 The notation [x] is often used to denote the greatest integer con-
tained in the real number x. Thus, [4.32] =4, [0.37] =0, and
[72.999] =72. Show that if x is not negative, [x] is the integral
part of x. What is [—13.72]? [—0.0678]?

1.4 Use the power-of-10 method to write the value of the following
numbers. Example: 87.3 = 8 X 10'+7 x 10°+3 x 1071.

(a) 67995
(b) 0.009506
(c) 4.586
(a) 736.947
(e) 50.009
(f) 12.12125

1.5 Write the number whose value is

(a) 6 X 10? + 8 X 10? + 0 X 10!+ 8 x 10°


(D) poe Oma Oral Ome
(CO) WX NWO a 6 OY EA SO
(d) 8X 103+4x104+3x10%+7x107
(e) 4 x 102 -- 6-x 10°+ 7 X 10° 4+ 7 x 102+8 x 103

1.3. STANDARD FORM. SIGNIFICANT FIGURES. ROUNDING OFF

Often it is desirable to write a real number in what is called standard form.


This has to do with the position of the decimal point in the number. If the
decimal point immediately precedes the first nonzero digit of the number, we
say that the number is written in standard form. Thus, 0.30472 is in standard
form but neither 17.30 nor 0.000976 is. In order to place a number in this form,
clearly a way must be found to move the decimal point in a number left or
right as required but without changing the value of the number.
Suppose one has a number; it should be fairly obvious that if one allows
the decimal point to float up and then to the right over succeeding digits, each
(oN
time it passes a digit the number is multiplied by 10. For example, 86.4632 re-

THE DECIMAL NUMBER SYSTEM 7


sults in 86463.2, which is 10? or 1000 times the original number. To maintain
the value of the original number without moving the decimal point back, the
resultant number must be multiplied by 10°. This can be done by writing
86463.2 x 107%.
Again, if the decimal point floats to the left over five digits, the number
is actually divided by 10°, and to compensate, the resultant number must be

multiplied by 10°. Thus, 00098:43 results in 0.0009843 and 98.43 = 0.0009843


x 10°. Note the zeros that were inserted because of positional considerations.
Now, all this discussion leads to the following rule for placing a number
in standard form: Move the decimal point until it is immediately before the
first nonzero digit in the number. If the decimal point has been moved left,
multiply the result by 10 raised to the power equal to the number of places
moved. If the decimal point has been moved right, multiply the result by 10
raised to the power equal to the negative of the number of places moved.
Thus, 76.73125 = 0.7673125 x 10? and 0.000001025 = 0.1025 x 10°°.
Once a number has been placed in standard form, it can be stored (that
is, placed) in the register of a calculator or computer in the following two-
block form:

eGR ES Pe +) 0| 2

and

WP IEra ome Goleo BES:

The number in the first block in each case is called the mantissa of the number;
the second number (with its sign) is called the characteristic of the number.
This mantissa and characteristic method (and standard form) enables
one to write very large or very small numbers without using all the zeros that
might be necessary in ordinary decimal form. For instance, 765540000000000.
can be written as 0.76554 x 10’ and 0.0000000000000013401 can be written as
0.13401 x 107".
We shall later see that in the computer language called Fortran a special
code is used to indicate a number written in the form of mantissa and charac-
teristic. There we shall write 0.86732 X 10* as .86732E+04 and 0.1025 x 10-8 as
.1025E — 08. Clearly, the combination of symbols E+04 is replacing the multi-
plier x 10*, and E — 08 is replacing X 10°.
Up to now we have been writing numbers of all sorts and sizes without
any information about their source—that is, without knowing or caring about
what is sometimes called the accuracy of the number. When we write 17.38,
there is absolutely no way of telling how “accurate’’ the number is by merely
looking at it. However, if we knew that this number resulted from a rounding
off of another number previously known exactly, then we would have some

8 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


idea as to its accuracy. We shall discuss the procedure of rounding off ina
moment, but in the absence of any prior knowledge of it, when we write 17.38
we mean 17.38 exactly and not approximately.
Here we must discuss a concept concerning numbers called significant
figures, because of its current common usage. One must be cautioned, how-
ever, not to place too much emphasis on the usual meaning of the word “sig-
nificant” as it is used here. The number of significant figures a number con-
tains is simply the number of digits it contains, the number of digits being
counted using the following rule: Count the number of digits in the number
(no matter where the decimal point is) starting with the first nonzero digit.
Thus, 86.472 has five significant figures, 0.003705 has four significant figures,
and 14.3700 has six significant figures. Note that zeros occurring after the first
nonzero digit are included in the count. Some special cases occur. For ex-
ample, 837000. has three significant figures when one presumes that the three
zeros are present merely for positional purposes; but if the number is known
to be exact, then 837000. has six significant figures.
As indicated in the last section, numbers sometimes have so many sig-
nificant figures that it is physically next to impossible to do all the operations
of a set of calculations and throughout maintain all the figures the given num-
bers and the intermediate results contain. This is true not only when one is
computing by hand with pencil and paper but also when one is computing
with the aid of the fabulous computer. Here the notion of the approximate
value of anumber becomes important. You recall that the important irrational
number symbolized by a is represented as a decimal number by an infinitely
long, never-repeating sequence of digits (since it is irrational). The sequence
starts with 3.14159 and continues indefinitely. In order to do any calculation
involving 7, it is fairly clear that one must approximate it (that is, replace it
with a rational number by terminating its sequence of digits at some reason-
able finite place). One could approximate 7 by writing 7 = 3.1 (to two signifi-
cant figures). Here we are using the new symbol = to replace the words “‘is
approximately equal to.” One could also write 7 = 3.14, 7 = 3.141, 7 = 3.1415,
or 7 = 3.14159, depending on whether one wants three, four, five, or six sig-
nificant figures in the approximation. In this context all these numbers are
approximate in the sense that they are known to be approximations of the
number 7. But, obviously, if one were to see 3.14 in a completely unrelated
context, one would not conclude that in that situation 3.14 would be approxi-
mating 7. It could perfectly well be that 3.14 is an exact number, perhaps the
decimal equivalent of the mixed fraction 37/so. It could just as easily have
been the result of rounding off the exact number 3.144627 to three significant
figures.
It is clear that all decimal numbers with a large, perhaps infinite, quan-
tity of digits must be rounded off at some finite stage even if they are rational

THE DECIMAL NUMBER SYSTEM 9


numbers. Recall that /s = 0.(3) = 0.333333 . . . .. Thus, 1/s can be approxi-
mated by 0.3, 0.33, 0.333, 0.3333, etc., depending upon the number of signifi-
cant figures one wants, or perhaps more often depending upon the capability
of storage of the computer one is using. Here the rounding off is achieved
by simply cutting off the sequence at the selected place and completely omitting
the remaining digits of the sequence, whatever they were. Ina case like this
one, if the choice of how many 3s to carry in a certain calculation is completely
up to you, we suggest that you carry as many significant figures as you physi-
cally can or as many as are feasible in the computing device you are using.
One can round off a number that already has a terminal digit if one cares to.
For example, 873.2 can be rounded off to 870. (and thus reduced from four to
two significant figures) by omitting the 3.2 and supplying the 0 needed for
positional accuracy. It is hard to think of the circumstances which would
cause one to do this, however.
There is a kind of rounding off called symmetric. It is the method that
you are perhaps familiar with even though it is not the method used in most
computers; they usually automatically round off to a prescribed number of
digits (depending upon the particular machine) by simply cutting off (trun-
cating) the sequence of digits and replacing digits by zeros when necessary.
Here is the rule for symmetric rounding: Starting with the first significant
figure, count to the right the number of places equal to the number of signifi-
ON
cant figures desired in the result. For example, 0.0083625 says that three sig-
nificant figures are wanted. Let us call the very next digit the roundoff digit.
We then follow these steps:

1. If the roundoff digit is 4 or less, simply omit the roundoff digit and
the remaining sequence of digits:

0.0083625 = 0.00836 (three significant figures)

and

0.9563499 = 0.9563 (four significant figures)

2. If the roundoff digit is 6 or more, advance the digit just before it by


1 and omit the roundoff digit and the remaining sequence of digits:

7.83694 = 7.84 (three significant figures)

3. If the roundoff digit is 5 and at least one nonzero digit follows it


eventually, advance the digit just before it by 1 and omit the roundoff
digit and the remaining sequence of digits:

10 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


87.4650004 = 87.47 (four significant figures)

4. If the roundoff digit is exactly 5 (with no nonzero digit ever appear-


ing after it), advance the digit just before the 5 by 1 if it is odd, but
do not advance it if it is even, and once again omit the roundoff
digit and the remaining sequence of digits:

862.5 = 862 (three significant figures)

but

0.0093555 = 0.009356 (four significant figures)

Note again that most digital computers do not use built-in symmetric
rounding but instead automatically round off by the simple process of trun-
cating, that is, cutting off the sequence of digits. It is possible, of course, for
a program to be written and stored in the computer which will allow one the
option of symmetric rounding.

EXERCISES
1.6 Express each of the following numbers in standard form:

(a) 4862.47
(b) —0.007053
(c) 337.0 x 10°
(d) 42832. x 10-7
(e) 93470000000000000000.
(f) 0.000000000045688
(g) —4785.003

1.7 Find the mantissa and the characteristic of each of the following
numbers:

(a) 869.37
(b) 4283000.
(c) 625 x 10"
(d) 6
(e) 497 x 10°
(£) 0.00098907

1.8 Express each of the numbers of Exercise 1.6 using the Fortran E
notation.

THE DECIMAL NUMBER SYSTEM 11


following
1.9 State the number of significant figures in each of the
numbers:

(a) 17.320
(b) 0.008326
(c) —13.227
(d) 98300.7
(e) 93902
(£) 1.00467
(g) 100.001
(h) 1.1111
(i) 78

1.10 Express each of the following numbers to the given number of


significant figures using symmetric rounding:

(ayn 2258(4)
(b) 887.12 (1)
(c) 0.003295 (2)
(d) 637.5 (3)
(e) 985435 (5), (4), (3), (2)
(f) 14.5678 (2), (3)
(g) 789.07 (4), (2)

1.11 Express each of the numbers of Exercise 1.10 to the given number
of significant figures using truncation.

1.4 OPERATIONS

We shall assume that you are perfectly capable of doing the arithmetic involved
when you perform the operations of addition, subtraction, multiplication, and
division of real numbers. Some confusion seems to exist, however, about
the accuracy of the result when numbers are combined using these operations.
Suppose someone asked you to add 8.37, 4.2, and 863. You undoubt-
edly would place the numbers in a column with the decimals lined up and
add as usual:

S37,
4.2
863.
S705,

12 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


The result would be 875.57. Since the three numbers are presumed to be
exact, the result is exactly 875.57. Then, if for some unknown reason the re-
sult is desired to only two significant figures, we replace 875.57 by 870. (using
truncation) or by 880. (using symmetric rounding). We never round off the
original numbers to two significant figures before adding.
Similarly, when 7.5 is multiplied by 3.7, the result is 27.75. We do not
presume that the numbers 7.5 and 3.7 are somehow approximate merely be-
cause they contain only two significant figures. The result is exactly 27.75.
There are, of course, instances where roundoff of the result of a calcu-
lation must occur. Suppose we are using a calculator which has three regis-
ters for the use of the operation of multiplication—the multiplicand, multi-
plier, and product registers. Suppose each of these registers is made up of
two parts, each allowing three symbols. The first contains the mantissa of
three digits with the decimal point assumed as preceding the first digit. The
second part contains the characteristic, the power of 10 by which the number
in the first section is to be multiplied. For example,

ei). Ebr
is the way a register looks when it contains the number 0.123 x 10°.
Suppose that the multiplicand and multiplier registers contain, re-
spectively,

eae —|Q|] 2 and AL |! ey || & i+ [os

(representing 0.123 x 10°? and 0.469 x 10°). Now let us suppose that the
computer takes these two numbers to some internal calculating area where
there is plenty of room to perform the multiplication carrying all figures,
rounds off the product to three significant figures (by cutting off the proper
terminal digits), and returns to the product register the result in standard
form. Then the following occurs internally:

0.123 x 10-2
0.469 x 10°
1107
738
492
0.057687 X 102 = 57.687 = 0.57687 X 10°
in
Notice that the first product is found by multiplying as usual the numbers
of the two registers and supplying the decimal point in the re-
the first parts
sult as usual in arithmetic. The numbers that appear in the second part of

THE DECIMAL NUMBER SYSTEM 13


the two registers are added, that is, (—2) + (5) =3, and the result is the power
of 10 by which the first product must be multiplied. The reason the numbers
—2 and 5 are added is that we are actually multiplying 10~* by 10° to get 10°
and the laws of exponents require us to add the exponents.
As shown above, the next step is to place the result 0.057687 x 10° in
standard form. Then, since there is no symmetric rounding, the following
will appear in the product register:

5|7| 6 |+] 0] 2

The 87 on the end of 57.687 has been truncated.


The two registers could contain two numbers that are to be added, for
example,

fe [6 |3 +] 0) 2 and [1] 2| 5] |+| 0 1 |


representing 0.863 x 10” and 0.125 x 10.
Then, if the add button is pushed, the following calculation could ensue
internally:

86.3 x 10°
1.25 x 10°
87.55 X 10°
Note that now the characteristics are treated in a different manner. First,
the characteristics must be the same before the numbers are added. In the
example just above, we have made the characteristics both zero by writing
0.863 X 10? as 86.3 X 10° and 0.125 X 10! as 1.25 xX 10°. We then add the new
mantissas and multiply the result by this common power of 10. We could just
as well have written 0.863 < 10” as 0.0863 < 10% and 0.125 X 10! as 0.00125 x 103,
and then have added in this way:

0.0863 x 10°
0.00125 x 10°
0.08755 X 10° = 87.55 (as before)

In any case, the following will appear in the sum register:

fe) | 7 || 8) Til Oma

Obviously, the numbers that we have shown appearing as if by magic


in the various registers of the computer could very easily have been themselves

14 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


the rounded-off results of previous calculations. Ina sequence of calculations
where roundoff occurs at the end of each operation, the final result will have
accumulated roundoff errors. This sort of buildup is an inherent property
of computers and is one of the most troublesome problems that one has to
consider when evaluating the accuracy of the result of a set of calculations. It
has simply to do with the fact that the various registers of the computer are
capable of storing numbers that are finite in length. If one is computing by
hand, then of course one can maintain many more figures throughout and
thus protect the accuracy of earlier results. In this case one should keep at
least one (and preferably more than one) figure in excess of the number of sig-
nificant figures one desires in the result. If possible, never round off inter-
mediate results. In any case, never round off to the final number of figures
except in the very last result. Note that in some computers it is possible to
achieve much this same effect of keeping more figures throughout a set of cal-
culations by using the computer’s capability called extended precision. When
one can use this, even when the numbers (data) inserted into the computer
for it to perform calculation on are of few significant figures, the computer
automatically maintains quite a few more figures continually and thus helps
alleviate the problem of roundoff error.
Here is an example which compares the calculation by hand with no
rounding except in the final result and by use of a computer with rounding-
off characteristics we have just discussed (not extended precision).

Example. Compute (8.2 X 17.9 + 2.87) X 3.7. Presume the numbers are exact
and round off the result to three significant figures.
Method 1: Exact calculation carrying all figures throughout.

8.2 146.78 149.65


se git Te VONyp ee ay
738 149.65 104755
574 44895
82 553.705
146.78

Result: 553.
Method 2: Use the computer method with roundoff (truncation) as re-
quired at the end of each operation.

8 2 |0 | J+ |o| 4 x EEA Toe

= “|1|4|e +] 0] 3|

THE DECIMAL NUMBER SYSTEM 15


ji f4[o| |+ 0 |3 “= a ey aes +]of.]

= i[4[s elpede ae

1/4] 8 a o| 3 | x 3| 7 0 |+] 0 1|

os Se Ne sire )+[0 3

We leave it to you to check the intermediate results shown. In any


case, the final result of the computer method is 547.
Notice the “error” introduced in the final result by the accumulation
of roundoff error even though all the given numbers, the data, fit exactly into
the computer registers with no initial roundoff required to store them.

The operation of division will often lead to infinite repeating decimals


which must necessarily be rounded at some finite place. For example, 8./7.=
1.(142857) = 1.143 to four significant figures (in this case using symmetric
rounding). We repeat that if the final result of a sequence of operations is
to be rounded to a certain number of significant figures, one should maintain
one or two more significant figures than this number in all the intermediate
calculations.

EXERCISES

1.12 Assume that each of the numbers given below is exact. Perform
the indicated operations by hand carrying all figures. Round the
final result to three significant figures using truncation (cutting off).

(a) 17.3 x 0.82


(b) 149.3 X 7.1
(c) 8.267 + 5.92 + 13.2 + 17. + 647.8957
(d) (13.67 X 12.5) + 72.8
(e) 138.75 — 67.983
(£) 0.678 X 4.3 X 0.06
987.
(g) —~ + 6.389
(h) (23.45 — 9.56) X 12.6

Oheeeces— =
1 89.0
13.
467
wey

1.13 Assume that a computer has a four-digit register for the storage

16 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


of numbers. For example, |8 | 1|4|7]|[+]0 ]0 [1] represents
0.8147 X 10'= 8.147. Assuming rounding by cutting off (trun-
cation) at the end of each operation, perform the following se-
quence of operations. Place the result in the register form shown.

(a) 0.6428 x 10° + 0.2375 x 102 — 575.0


(6). (8.32 x 17-76) + 2.376
(c) 8.27/7. — 0.003728 x 102
(d) (6.28) X (72.9)/8.
(e) (8.37 + 0.6578 + 17.379) x 4.72
(f) 2.632 X 2.632 — 4. X 1.873 x 6.03
(g) (56.78 + 68.79 + 45.68 — 34.77) /0.4
(h) 5.678 X 34.5 + 3.45 X 32. +4. X 5.679 + 5.6 X 34.6

1.14 Perform the sequences of operations of Exercise 1.13


(a) assuming that the computer has a three-digit register for the
storage of numbers—for example, | 7 | 8 | 9]/—|0 |4 |represents
0.789 x 10°-* = 0.0000789;
(b) assuming that the computer has a five-digit register for the
storage of numbers—for example, |6| 7 | 8 19] 8 [+ |2 |3 |rep-
resents the number 0.67898 x 10°.

1.15 For each of the parts of Exercise 1.13, compute exactly each oper-
ation using all figures throughout. Then find the error in each
answer of Exercises 1.13 and 1.14.

1.5 CONCLUDING REMARKS

In the next chapter we shall introduce real-number systems with bases other
than 10. The four arithmetic operations in these systems will prove new,
fascinating, and, interestingly enough, very practical. Several of these sys-
tems, namely the binary, octal, and hexadecimal, are particularly important
in computer applications.

THE DECIMAL NUMBER SYSTEM 17


9 +

: ~

;
4

™ F
-
i]

f
> =
S


7

by

>
“Ne
Nondecimal Number Systems

2.1 INTRODUCTORY REMARKS

Any positive integer greater than 1 can be used as the base of a number system.
The digits of a number system using a base b which is 10 or less are 0, 1, 2,
3, ...,b-—1. For example, the digits of number base 8 are 0,1, 2,3, 4,5, 6,
and 7. We shall see in a moment how we handle the situation of the digits
of a number system with base more than 10. In any case, the numbers of the
system are then constructed in exactly the same way we used for the decimal
system except, of course, that the digits used are restricted to those belonging
to the system. Thus, 630.72 is a very respectable number in the base 8 num-
ber system. As before, 630 is the integral part of the number and .72 is its
fractional part. And, even though the system is no longer decimal, the “deci-
mal point” which, in a sense, joins the two parts of the number is used.
Systems with certain bases, because of their importance in computer
applications, have been given specific names (like decimal for base 10). Some
of these are the binary system (base 2), the ternary system (base 3), the octal
system (base 8), and the hexadecimal system (base 16). Systems with bases
other than these must be referred to by giving the base itself.
One notices immediately that if the number 630.72 is standing alone,
out of any context which indicates the base being used, it would only be natural
to assume that the number is decimal. So some way must be found to desig-
nate the base if it is necessary for clarity. The method we shall use here is
to follow the number by a subscript indicating the base; thus we would write
630.72.) to indicate that the number is in the octal system. Generally, if no
subscript follows a number, we shall presume that the number is decimal.
The binary system, base 2, is of such paramount importance that much
attention will be paid to it in the following discussions in this chapter and in
later chapters when specific applications are explained. It has the neat prop-
erty of requiring only two digits, 0 and 1. So, 110111011.1101 could be a
number in the binary system.
Suppose, however, that one wants to use a base greater than 10, say 12.
Then the digits we shall use will be 0, 1, 2, 3, 4, 5,6,7,8,9, A,and B. Notice
that since 12 digits will be required and there are only 10 decimal digits, we
have used the single symbol A to stand for the decimal number 10 and B to
stand for the decimal 11. A39B1.8A is a number in this system. We shall
not use numbers of base greater than 16, but, in general, the digits for a num-
ber of base greater than 10 could be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F,
G,.... In the hexadecimal system, base 16, the first 16 of these are used,
so that A, B, C, D, E, and F stand for the decimal numbers 10, 11, 12, 13, 14,
and 15, respectively, but are digits in the hexadecimal number system. Thus,
39F7E.4BA is a hexadecimal number.

2.2 THE DECIMAL VALUE OF NONDECIMAL NUMBERS


We now turn to the important notion of the decimal value of numbers in non-
decimal systems. We shall consider first numbers with no fractional part,
that is, whole numbers. Suppose we are using base 7 and have the number
32057). The following shows the positional values we assign to each digit:

Number oy B®
Positional
value a

We notice, of course, the direct analogy with the positional values we discussed
in Chap. 1 for decimal numbers. Here, however, the positional values are
powers of 7 and not of 10. Now we come to the rule for calculating the
deci-
mal value of the number: The decimal value of a number is found
by multi-
plying each of its digits by its respective positional value and adding
these
products. Here the multiplication and addition required are
done using the
ordinary decimal arithmetic. Thus, to find the decimal value of 3205,,), we have

3X P+2X 7 +0 X 71 +5 X79 = 3(343) + 2(49) +04 5(1)


= 1029 98 45
= 1132

20 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


That is, 3205 (7) — 113266) = 1132.

Example. The decimal value of 3E5Bi,,) is found by multiplying each of its digits
by its respective positional value and adding these products. Thus,
3E5Bas)= 3 X 16° + E X 167 +5 X 161+ BX 16°
= 3(4096) + 14(256) + 5(16) + 11(1)
= ihets) = Sisters = te) ae ll
= 15963(40)
— 15963

Note that to find these products, we have replaced E by 14 and B by 11. Re-
call that the first 16 decimal whole numbers 0, 1, 2, 3, 4,5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15 are designated as 0, 1,2, 3,4,5,6,7,8,9, A, B, C, D, E, F in the hexa-
decimal system.

Example

OM ejese 1 PSE OK 2 oe il ESE a ASE se EE iL ey


= SY se spi ae hse 2 se Al
= 47 (10)
= 47

To generalize this procedure we shall have to use some algebraic nota-


tion. As you know, in algebra letters and other symbols (like x, y, z) are often
used to stand for numbers; these symbols are called variables since their values
are not determined until they have been definitely assigned. A detailed
study of variables in general will be presented in Chap. 3. In many mathe-
matical applications and particularly in certain types of computer program-
ming, a whole set of variables will often have the same common name but be
separately identified by subscripts. For example, we could choose the main
variable name a and then write many other variables such as aj, dy, a3, a4
(which we read ‘a sub 1,” “a sub 2,” “a sub 3,” “a sub 4’)—all identified
by the a but considered different variables because of the varying subscripts.
In all our work, subscripts are always integers. A set of variables like
{@,, Gz, Az, 44, As, dg} is also called a one-dimensional array. The subscript
itself could be a variable. We could let a; stand for the general member of
this one-dimensional array. We shall use subscripted variables from time
to time, and in the chapters on computer programming we shall greatly ex-
pand the notion and applications of subscripted variables.
Let us now return to the problem of generalizing the procedure for
determining the decimal value of a nondecimal number. Suppose we again
let b stand for the base, let n stand for the number of digits in the integral

NONDECIMAL NUMBER SYSTEMS 21


part of the number, and let d; stand for the digits in the number. We can
then designate a number in base b as

An—14y—2On—-3 * * * Asdyd,dy

The value of this number is given by

ame ame ar ae Uae ap Gl fle qe 2 8 Se db? a5 d,b} == dyb®

Here the superscripts represent the usual algebraic exponents, that is, powers
of the base b. ;
As you would expect, the decimal value of the fractional part of a num-
ber to a nondecimal base is determined by a process entirely analogous to the
decimal case. For instance, suppose we have 0.20314). We associate with
each digit the positional value as shown below:

Number 2 0 3 1
Positional
value A AR A ae

So, clearly,

0.2031q) = 2X 47+0x424+3x4341x4-4
2 Sel

1
=_—
3 0
eel
ad ——

Die GAS O56


_128+12+1
256
_ 141
256
=WDa0AS . o .

We note that the equivalent of 0.2031(4) is not a terminating decimal. It is


exactly 41/256 but is approximately 0.5507 when truncated to four significant
figures. Again we run into the problem of roundoff error when we attempt
to store the base 4 number in a decimal register. Although 0.2031 will fit ex-
actly into a base 4 four-digit register, the decimal value 0.5507 stored in a
four-digit register has at least an error of 0.000081.

22 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Example

OOM ey 1 254-0 X27 1X 2341k24%+1x2>

= 0°95 + 0.125'+ 0.0625 + 0.03125


= 0.71875(0)
= 0.71875

Example

B.3Aqs) = B X 129+ 3 X 1271+ A X 12-2


=11 x 1243 < 127 +10 122

Sle 2200-0694)
= 11.319(4)
=11.3194444 ...

Here 4 is an infinitely repeated digit. B.3A(.) = 11.319 (rounded to five sig-


nificant figures).

EXERCISES

2.1 Determine the decimal equivalent (value) of the following:

(a) 43256)
(b) 11101111.)
(c) 2AF3q¢)
(d) 675,g)
(e) 120202)
(£) 1A31¢1)
(g) 1234.)
(h) 12346)
(i) 1001435)
2.2 Determine the decimal value of the following. Express each ex-
actly as a fraction, in the form of a decimal with repeating terminal
digits, and also as a decimal truncated to five significant figures.

(a) 0.25,7)

(b) 0.010101¢)

NONDECIMAL NUMBER SYSTEMS 23


(c) 0.303145)
(d) 0.0A35(42)
(e) 0.5667(g)

(f) 0.7D Aus)


(g) 0.10101¢5)
(h) 0.233324)
(i) 0.0001101,)

2.3 Determine the decimal value of the following. Express the frac-
tional part as a repeating decimal.

(a) 102.12()
(b) 32.023,4)
(c) 34.221 5)

(d) FE.FBus)
(e) 173.465.)
(f) 1101111.1101(.)
(g) 344.36)
(h) 50.2024)
(i) ABC.914q3)

2.3. TRANSFORMING DECIMAL NUMBERS INTO NONDECIMAL NUMBERS

So far we have learned how to find the decimal value of a number in a non-
decimal base. Now we present a method for changing decimal numbers into
numbers in other bases. We will show the method in two parts—one for an
integer decimal number and one for a purely fractional decimal number. Sup-
pose we have a decimal integer N and desire to transform it into base b. Here
is the general procedure. Let us divide N by b. Let g, be the quotient and
r, the remainder. Now divide q, by b and let q, be the quotient and r, the
remainder. Now divide q, by b and let qs be the quotient and r; the remainder.
(Note the natural use we are making of subscripted variables to describe the
procedure.) Now we continue in the same manner until the quotient is zero.
Suppose that at that step the remainder is r,. Then,

N = Nao) = fatn-1tn-2 °° * T3%aF1(0)

We note, of course, that the base b equivalent of the decimal integer N is com-
posed of the remainders generated but in exactly the reverse of the order in
which they were generated. The first remainder r; is the last digit of the

24 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


number base b, and the last remainder r, is the first digit. There are many
ways to actually perform the mechanics of the steps just outlined. We have
selected the schematic method shown below. In this model, the symbols
represent the quantities we have just discussed.

b N |4 deeds Weds oe PO
|Ty > Ts 14 Tk ae Tr

The arrow on the right side of the model is to emphasize that the remainders
are to be taken in reverse order.

Example. Transform decimal 861 to base 5.

5 |861 |172 34 | 6 1 |o |
+

Lea 2| 4 i
{

Thus, 861(9) = 11421). Let us check this result:

11421) =1X 54+1X59+4x 52742514159


= 625+125+100+10+1
= 861

Example. Transform decimal 597 to base 11.

11 597 | 54
|
|
- 0
3 |
A) 4
|

Thus, 597,49)= 4A3q1. Note that the remainder r, is (decimal) 10 which is


represented by A in the base 11 system. Now we again check:

WAGs 44 11e A 1 10°


ACT) Otte ol)
= 484+ 110+ 3
= 597

Example. Transform decimal 597 to base 2.

2597) 2981-149 74 *)37> 18 9 4 |2 |1 0


=}

i) Gls ce Sie Enel ae ee oe a ic

NONDECIMAL NUMBER SYSTEMS 25


Thus, 597 = 1001010101). Check:

1X 2°4+1* 2°41 2441 27+1X 2=512 + 644 164471


= 597

EXERCISES

2.4 Transform each of the decimal integers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,


11, 12, 13, 14, and 15 into base 2. Transform the decimal integers
into base 4. Repeat for base 8 and for base 16.

2.5 Use the method just presented to transform the following given
decimal integers to the bases called for:

(a) 635 into base 2; into base 4; into base 5


(b) 87054 into base 8; into base 12; into base 16
(c) 9114 into base 3; into base 6; into base 9
(d) 450774 into base 4; into base 8; into base 16
(e) 67833 into base 3; into base 7; into base 11
(f) 1010101 into base 4; into base 5; into base 6

2.6 The number 837%) can be transformed into base 5 by first finding
the decimal value of 837() using the method of Sec. 2.1 and then
transforming this decimal integer into base 5 using the method of
this section. Transform 837() into base 5.

2.7 Following the plan of Exercise 2.6, transform the numbers below
(with nondecimal bases) to the bases called for:

(a) 34421(;) into base 6; into base 4; into base 8


(b) 11011101,,) into base 4; into base 8; into base 16
(c) 4AF(,g) into base 3; into base 5; into base 8
(d) 4567A(,,) into base 15; into base 9; into base 8
(e) 3001223,4) into base 8; into base 2; into base 6
(f) 44321) into base 2; into base 4; into base 16

Let us now turn to fractional decimal numbers. Again, let the number
be n and the base be b. Multiply n by b. Let p, be the integral part of the
product and f; be its fractional part. Multiply f, by b. Let p. be the integral
part of the product and let fy be its fractional part. Continue in the same
manner as long as desired or until a repeating pattern emerges. Then

Nao)= -PiP2P3sP4 °° * (0)

26 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Note that now the digits of the base b number are being generated
by the
procedure in exactly the same order as they occur in the number. Our sche-
matic plan for this procedure is

b n |f
o P2 | P3

Example. Express decimal 0.4 in base 7.

a 0.4 0.8 0.6 0.2 0.4 |0.8 |0.6


| 2a 5 4 | 1 | | 5

A repeating pattern occurs, as you can verify by proceeding. Thus, 0.4(9) =


0.254125412541 | . .q)=0.(2541),) using our repeating pattern notation for
rational numbers. We note that 0.4 is terminating in base 10 but its equiv-
alent base 7 is nonterminating.

Suppose we are using a computing machine that has been constructed


to operate internally on base 7 numbers, and that it maintains three digits.
In order to store the external exact decimal number 0.4, the best we could do is
to internally store 0.254, the first three digits of the corresponding number
base 7. Since the remainder of the base 7 number has been truncated, this
introduces an error in merely storing of 0.00012541254 . . (7) =0.000(1254),).
We can compute this error in decimal form by evaluating 0.254,)=2 Xx ¥/7
+5 xX Ya9 + 4 X Y343 = 1/343(98 + 35 + 4) = 137/343, so that the error is 0.4
— 137/343 = 9/5 — 137/343 = (686 — 685) /1715 = Yizis.

Example. Express the decimal 0.33 in base 2.


]
2 |0.33 |0.66 |0.32 | 0.64 |0.28 |0.56 |0.12 |0.24 0.48 0.96 |0.92
EE ap ar a Gs a es
|

Therefore 0.33 = 0.0101010001(,) (to 10 significant binary figures).

All current electronic digital computers are constructed to perform all


their arithmetic operations on binary numbers. Thus, the remarks we have
just made concerning a hypothetical computer which operated on base 7 num-
bers are particularly pertinent to actual computers. We here see that a com-
puter which allows 10 binary digits cannot store the (external) decimal 0.33
exactly as a binary number. This means that the computer will, in general,
be acting on approximate numbers.

NONDECIMAL NUMBER SYSTEMS 27


If the decimal number has both nonzero integral and fractional parts,
a combination of both parts of the method just discussed must be employed.

Example. Express decimal 37.51 in base 8.

8 37 4 | 0

S| 2

Thus, 3740) = 45). And

| 8 |0.51| 0.08 0.64]


0.12|0.96 |0.68] - - -
4 0| 3) Ae
Thus, 0.51(9) = 0.40507). Finally, 37.51 = 45.40507).
EXERCISES

2.8 Express each of the following decimal numbers in the bases given.
In each case, if the result is not terminating, carry to at least six
figures or indicate the repeating pattern.

(a) 0.04375 into base 2; into base 4; into base 8


(b) 0.1 into base 12; into base 2; into base 5
(c) 0.443 into base 6; into base 5; into base 4
(d) 0.73 into base 2; into base 8; into base 16
(e) 0.005 into base 5; into base 8; into base 7
(f) 0.6245 into base 3; into base 12; into base 16

2.9 Express each of the following decimal numbers in the base given.
In each case truncate the fractional part to five significant figures.

(a) 245.06 into base 2; into base 3; into base 4


(b) 4.44 into base 4; into base 8; into base 16
(c) 8764.55 into base 12; into base 13; into base 14
(d) 99.64 into base 6; into base 7; into base 8
(e) 16.1616 into base 4; into base 8; into base 16
(f) 983.17 into base 3; into base 9; into base 12

2.4 RELATED BASES

With each base b is associated a set of bases which is said to be related


to
base b. The related set of bases is composed of bases which are the various

28 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


powers of b. For example, if b=2, then the bases 4= 27, 8= 2°, 16=2!,
32 = 2°, etc., are related to base 2. Similarly, if b = 3, then bases 9 = 3?, 27 = 33,
81 = 3+, etc., are related. Because of their extraordinary importance, we shall
be concerned here specifically only with the base 2 and its related bases. -Con-
sider the related base 4. The digits of the base 4 system are, of course, 0, 1, 2,
and 3; these digits can be expressed as binary numbers of two digits, namely,
00, 01, 10, and 11, respectively. A number of base 2 can immediately be
changed to base 4 by following this procedure: Mark off sets of two digits start-
ing with the two preceding the decimal point and moving left. If the number
has a fractional part, mark off sets of two digits starting from the decimal point
and moving to the right. For example, 1 1 Q 1 19 0 1 Q OQ».
Now replace each set of two binary digits by its decimal equivalent. In this
case, we would have3 1 2 1 O. This is the base 4 equivalent of the orig-
inal binary number. We leave it to you to check this.

Example. Transform the binary number 1100110.111 into base 4. We mark off
as prescribed: 1 (ge Digit 1 0. Leh 1 0. Therefore, the result is
1212.32(4). Note that the first pair is Q 1.

Now consider the related base 8. The digits of the octal system are 0,
1, 2,3,4,5,6,and 7. Each one of them can be expressed as a binary number
of three binary digits. These are, respectively, 000, 001, 010, 011, 100, 101,
110,and111. A binary number can easily be transformed into base 8 by mark-
ing off (starting from the decimal point and moving left and right) sets of three
binary digits. If each group is replaced by its decimal equivalent, the result
will be the octal representation of the original binary number.

Example. 001 101 100 1000) = 1 5 4 Ag).

Check 1101100100.) = 2° - 2° + 2°. 2° 2"


= 512 + 256 + 64 + 32 + 4
= 868 (40)
1544,5,— 1 <3? + 5 x 6-4 4 x 844 x 8°
= 512 +5(64) + 4(8) + 4
= 868,10)

Base 16 is another important base related to base 2. As before, we now


group in sets of four. Thus, 901101100100.) =3 6 4azg).

Check: 364,46) =3 X 167+ 6 X 16'+ 4 xX 16°


= 3(256) + 6(16) +4
= 868:10)

NONDECIMAL NUMBER SYSTEMS 29


Of course, base 16 has some nondecimal digits, so whenever the decimal
equivalent of a set of four binary digits is more than 9, we replace it by the
corresponding base 16 digit.

Example. 111] 1011 Q111 iS)(SS)i i S S Soary 1101 1001.2) results


Its in
in (decimal)
(decimal
—- = :
15 “11 7>3-1.~13 9. Thus, FB731.D9 is the- hexadecimal equivalent

It should be clear from the discussion above that any number in a base
related to 2 can very easily be expressed in base 2. One simply replaces each
of its digits by the corresponding binary equivalent. Thus,

30172, 0 1g =11 01 10) 00" 011101100001G,


oy te eet
and

A C 5 Eqs
=1010 1109 Q10J 1119 = 1010110001011110.)
AS OMe ae
EXERCISES

2.10 Use the method of this section to transform the following binary
numbers to base 4, to base 8, and to base 16:

(a) 11011011
(b) 11111110110111100
(c) 10100111101.1101
(d) 10101101001.10010011

2.11 Use the method of this section to transform the following numbers
to base 2:

(a) 32231204)
(b) FA8Cas)
(c) 0.77466;

(d) 1010337%)
(e) OO DEV Ge)

(f) 3003312.2.4)

2.12 Transform 312103,4) to base 16 by first transforming to base


2 and
then transforming this result to base 16.

2.13 Recall that 16 = 4? so that base 16 is related


to base 4. Transform
312103,4) to base 16 by grouping its digits in sets of two,
replacing

30 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


each set (considered as a two-digit base 4 number) into decimal,
and then replacing each decimal by its base 16 equivalent.

2.14 Since 9 = 3”, base 9 is related to base 3. Use the method described
in Exercise 2.13 to transform 12102122;,) into base 9.

2.5 ARITHMETIC OPERATIONS IN VARIOUS BASES

2.5.1 Addition

First, let us consider the basic operation of addition. The rule for addition
of number base b is: Add the numbers of the rightmost column as usual using
decimal addition. Transform this partial sum into its base b equivalent. The
rightmost digit of this partial sum (in base b) is called the sum digit. Put down
the sum digit in the sum as in ordinary addition and prepare for the carry oper-
ation. For example, if the partial sum is 67, then 7 is the sum digit and 6 is
the carry digit; it would be carried and added to the next column to be added.
However, if, for example, the sum is 112, then 2 is the sum digit, and the set
of digits 11 are to be carried. These are carried over the next two columns,
one in each column. After this, each column is added as described above.

Example. Add the following base 8 numbers:

CO
I W
ouN
OUONs fF
nooNY
NN
&N

Add the digits of the right column; the sum is 15 (decimal). This is 1%), and
so 7 is the sum digit and 1 is the carry digit. Place the 7 and carry 1 to the next
column. Add the digits of the next column. The sum is 16 (decimal). This
is 20). Place the sum digit 0 and carry 2. If you carry on in the same manner,
the next partial sum is 17 = 21.) and the last partial sum is 23 = 27). The
final sum is 27107,g).

Check:

73425) = 7(512) + 3(64) + 4(8) +2= 3810


6707) = 6(512) + 7(64) +7 = eve)
5554; = 5(512) + 5(64) +5(8) +4 = 2924
3062) = 3(512) + 6(8) +2 = 1586
11847410)

NONDECIMAL NUMBER SYSTEMS 31


and

8 |11847 |1480 | 185 23 2 0 |


| 7 0 1 7 2 —

so that the result is 27107;,), as above.

Example. Add the following base 5 numbers:

13.214
202.434
123.433
400.021
1300.212

In this problem, note that 12 = 22(5), 11 = 215), 10 = 20(5),5 = 10), and 8 = 13s).

Adding two binary numbers is especially simple. The following combi-


nations are the only ones that can occur:0 +0=0,0+1=1,1+1=10, and
Tela t—117 all binary.

Example. Add the following two binary numbers:

111011011
101111011
1101010110

Finally, here is an interesting example: Add the following base 3 numbers:

2
1
11
11
2122
1022
10012
20122
10002
21021
12122
1002201

32 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


The numbers that are written above the upper line are carry digits. The sum
of the righthand column is 13 = 111g). Put down the 1 and carry 11 over the
next two columns as shown. The second column adds to 12=110(3). Put
down 0 and carry 11 over the next two columns, as shown. The sum of the
third column is 5=12(). Put down the 2 and carry 1 to the next column.
The fourth column adds to 8= 223. Put down the 2 and carry 2. The fifth
column adds to 9= 100i). Finally, put down 100.

EXERCISE

Pe AES ANG Kee

(a) Base 6: 4033


2235
1052
2222

(b) Base 9: 566778


345672
803366

(c) Base 12: 455A2


98B39
345678
A00985

(d) Base 16: 9 FDE


ABCD
3478
20F9
66A5

(e) Base 2: 101110011


111011010
100011111
1011101110

(f) Base 4: 32232


32221
3200022
3221102
321123
(g) Base 5: 42310.23
23334.24
40003.01
23441.44

NONDECIMAL NUMBER SYSTEMS 33


(h) Base 7: 5.66354
4.62435
3.33344
1.00026
3.55534

2.5.2 Subtraction

Next let us turn to the operation of subtraction. We have a choice of two


methods, the first being the standard method we are all familiar with based
on borrowing digits. The second method we shall present is to subtract by
adding the b — 1 complement.

Example. Subtract using the method of borrowing (base 7):

4025
— 2346

Start from the right as usual. Since 6 is greater than 5, borrow 1 from 2 (leav-
ing 1), add 7 to5 and have12. Now subtract 6 from 12 = 6, the righthand digit
of the remainder. Proceed to the next column. Again 4 is greater than 1, so
borrow 1 from the 4, add 7 to the 0, borrow 1 from the 7 (leaving 6), and add
7 to 1=8. Now subtract 4 from 8=4. The rest of the subtraction proceeds
without further borrowing. The remainder is 1346). This example can be
expressed as follows:

Gos
ep VA Fe avi
Ise
eo 4 6
eh PEWS

in which the / indicates the borrowing maneuvers and the numbers above the
upper line are part of the work involved.

Example. Subtract base 3:

201210
= PRA?

34 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Following the notation of the previous example, we have:

134103
2012A9
— 22129
102011
Check:

201210(g) = 2(243) + 1(27) +2(9) +3 = 534


22122(3) = 2(81) + 2(27) + 1(9) + 2(3) + 2= 233

The difference is 30149). Now,

|Ba) 30181100433 «i 3 | ree


Lal el 0 2 | 1 ——

Thus, 102011,;).
Let us now turn to the second method for subtracting, the b — 1 comple-
ment method. It turns out that some version of this method is precisely the
one used by digital computers to subtract, particularly binary numbers. If
the base is J, first subtract each digit of the subtrahend from b—1. Then add
this result to the minuend. If a carry digit (defined below) appears, add this
carry digit to the result; this process is often called an end-around carry. If no
carry digit appears, the answer (the difference) is negative and is found by
recomplementing the result. Examples will demonstrate the procedure.

Example. Decimal numbers, subtraction using the 9s complement method:

6132
— 4158

The 9s complement of 4158 is found by

9999
4158
5841

Each digit is simply subtracted from b—1=9. Now add this to 6132.

NONDECIMAL NUMBER SYSTEMS 35


6132
5841
ae Lone

carry digit

(end-around 1
carry)
1974 result, which is easily checked

Example. Decimal numbers, using the 9s complement method:

9247
aeLOOSS

The 9s complement of subtrahend is clearly 84316. Then

09247
84316
0}93563

There is no carry digit, so that the result is the 9s complement, that is, —6436.
The result is negative.

Example. Base 5 numbers, by the 4s complement method:

3240
— 1434

The 4s complement of 1434 is clearly 3010, the result of subtracting each digit
in 1434 from 4. Adding this to 3240, we have:

3240
3010
1 {1300 addition is in base 5, of course
1
1301 result

Example. Base 16:

639AF2
mee 295

36 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


The 15s complement of 097C95 is F6836A. Then

639AF2
+ F6836A
1 5A1E5C
1
5AILE5D result

Example. Base 7:

02503
— 61445

The 6s complement of 61445 is 05221. Then

02503
ar Wye
0)11024

The result is, therefore, —55642.

The base 2 is of special interest. First note that the 1s complement of


a binary number is easily found. Simply replace each 1 in the number by 0
and replace each 0 in the number by 1. Let us check this. Consider the
number 11011. Its 1s complement can be found by

il
eee LOOT
001100

and this is exactly the same as changing each 0 to 1 and each 1 to 0 in the
original number.

Example. Base 2:

1101100
— 0110111

The 1s complement of 0110111 is 1001000. Then,

NONDECIMAL NUMBER SYSTEMS 37


1101100
+ 1001000
1)0110100
il
110101 result

Example. Base 2:

1101 001101
— 110011 + 001100
0)011001

The result is —100110.

EXERCISES

2.16 Subtract using the direct (borrowing) method:

(a) Base 3: 21002211


= FHA

(b) Base 2: 110101010


= lite ae

(c) Base 6: 430542


— 45323

(d) Base 8: 1170341


— 675473

(e) Base 14: 1246A3


BAC ID

(f) Base 16: 357 ADEA6


— 2FD7768E

2.17 Subtract using the b — 1 complement method:

(a) Base 2: 1101101


— 1010010
(b) Base 3: 21101
e202)

(c) Base 7: 4023561


— 2606635

38 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(d) Base 11: 34567 8
— 4963A1

(e) Base 16: 1234567


— ABCDEF

(f) Base 8: 132435672


— 24566777

(g) Base 4: 3030303


=
3301223
(h) Base 10: - 98076543
— 123677898

2.5.3 Multiplication
Now for the operation of multiplication. Perhaps a detailed, worked-out ex-
ample would be instructive. Consider this problem: Multiply, using base 6,
325 X 43.

325

x
43
1423
2152
23343

Analysis: First place the numbers under each other as in usual multiplication
in decimal system. Multiply 3 by 5 as decimals. The result is 15 which we
place in base6as23. Putdownthe3and carry the2. Now2X3=6,6+2=8
(decimal). Place 8 in base 6 as 12(,. Put down the 2 and carry the 1. Now
3X3=9, 9+1=10, and 10(9)= 144). As shown, the first intermediate
product is 1423. Shift one to the left as is usual in this type of multiplication.
Multiply 4 by 5. Result is 20 = 32(,. Put down the 2 and carry the 3 as ex-
pected. Now4x2=8,8+3=11, and 11=15¢). Put down 5 and carry 1.
Then 4 X 3=12,12+1=13= 21). This completes the second intermediate
product as 2152). Now add base 6. The result, the product, is 23343,).
We check this result. First, we leave it to you to show that 325(6) = 125,19)
and that 43(g) = 2740). Then we multiply these two base 10 equivalents for a
product of 3375. Now

|6 |3375 562 93 | 15 | 2

3 amlteasit 3 2 a

NONDECIMAL NUMBER SYSTEMS 39


Thus, 3375 = 233434) and the check is complete.

Example. Multiply the base 3 numbers 21022 and 2112.

21022
Zi?
202M
21022
21022
112121
200101011

Check the details of this multiplication; recall that 3 = 10(3), 4 = 11(3), 5 = 12(g),
6=20q), and 7= 21). Verify the result by showing that 21022(3)= 197(0),
2112 = 6849), the decimal product is 13396, and 13396) = 200101011().

Example. Multiply, base 16:

3A7
x B9
20DF
28 2D
2A3AF

Again, you should check the multiplication itself, and if you care to, verify
the result by following the steps as outlined above.

Example. Multiply, base 2:

11011
x 11101
11011
11011
11011
11011
1100001111

The partial products in this example are, of course, very easy to calculate.
Some intricacies occur during the addition of these partial products using
binary addition. When the (decimal) sum of a column is 4, the binary equiv-

40 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


alent is 100. The right zero is placed down, and the left 10 is carried over the
next fwo columns to the left. Check this example carefully.

EXERCISE

2.18 Multiply using the method described in the text:

(a) Base 4: 13013


Ke23i

(b) Base 9: 483


x 78

(c) Base ll: 4A3


x 9A

(d) Base 2: 1011101


ee LOM

(ec) Base 8: 4775


x 1247
(f) Base 16: BEF
x AC
(g) Base 5: 4432
x 302

(h) Base 13: 5BA8


~ AE

2.5.4 Division

The operation of division is straightforward like ordinary division but carry-


ing it out becomes a rather tedious experience. It necessarily makes use of
the previously discussed operations of subtraction and multiplication. Let
us try an example and discuss it in some detail.

Example. Divide, base 5, 123221 by Siz,

32) 123221

Following the usual division procedure, we attempt the trial division of 32


into 123. First, try 3. But 32 X 3= 201), and so 3 is too large. Next, try 2.
32 X 2=114;). This is satisfactory, so place 114 under 123 and subtract

NONDECIMAL NUMBER SYSTEMS 41


(base 5):

2
32) 123221

11442
Carry down the next digit as usual. Clearly 32 goes into 42 once. We now
have

21
32) 123221
114
42
32
102
Clearly, 32 goes into 102 only once, so we now have

211
32) 123221
114
hy,
32
102
32
201

Luckily, 32 goes into 201 three times evenly. We have finally

113
32) 123221
114
42
32
102

Example. Divide 1F8) 734AC (base 16).

42 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


3A8
1F8) 734AC
5E8
14CA
13B0
“hye.
FCO
IEE remainder

This example is, of course, the result of lots of trial and error in the trial
divisors. We have chosen to stop the division as shown and indicate the re-
mainder. One could have supplied a decimal point and continued by insert-
ing zeros in the dividend. We check the result of this division problem.

1F8
X 3A8
FCO
13B0
5E8
3220
se° AUS remainder
734AC check

Although the method of division we have just shown is loads of fun to


do (as well as a test of patience), most computers (either electric or electronic)
do not perform the division operation in this way. Instead they use a method
of repeated subtraction as demonstrated in the following example.

Example. Divide 8041 by 17 (base 10) using the method of repeated subtraction.
First we set up a four-digit register in which to store the quotient. In
addition to the ordinary process of subtraction, we shall require that the com-
puter (or you if you are doing the division by hand) be able to count how many
times the divisor 17 is subtracted during the process. This means that each
position in the four-digit register we have set up is actually a counter. Here
is how we proceed. To determine the first digit in the quotient, take the first
digit of the dividend and subtract 17 (the divisor):

8
mls
=f)

Since the remainder —9 is negative, do not advance the first counter by 1 but

NONDECIMAL NUMBER SYSTEMS 43


move one place to the right in the dividend and consider the first two digits 80.
At the same time advance to the second counter. Again subtract 17, over and
over again as follows:

80
VE
63

Since the difference is positive, advance the counter 2 by 1. The register now
looks like this:|0|1]0]|0|. Proceed (using the second counter):

46 (advance counter 2 by 1)

2) (advance counter 2 by 1)
eal?
12 (advance counter 2 by 1)

=.)

Since this last remainder is negative, do not advance the counter. The register
now looks like this: |0] 4 | 0[ 0].
Now move back to the previous remainder 12, bring down the next digit
of the dividend, and advance to the third counter. Proceed as before:

124
en VS
~ 107 (advance counter 3 by 1)
me LA
~ 90 (advance counter 3 by 1)
ahd.
Ve (advance counter 3 by 1)
made
56 (advance counter 3 by 1)
ail
39 (advance counter 3 by 1)
eee
22 (advance counter 3 by 1)
ae
5 (advance counter 3 by 1)
eer
== 12. (do not advance counter 3)

44 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Recover the previous remainder 5, carry down the next digit of the dividend,
move to counter 4, and proceed, starting with the number 51. If one carries
this procedure through the necessary steps to find the final value of counter
4, the quotient register will then contain [0] 4] 7[ 3]; the quotient is 473.

Before we turn to some discussion of this method, let us present an-


other example which is closer to the way computers actually work. In this
example, the subtractions that are required over and over again will be done
using the method of adding the b — 1 complement.

Example. Divide, base 4, 123103 by 321. The 3s complement of the divisor


0321 is 3012. We shall set up a six-digit quotient register of counters. Clearly,
the first three digits of the quotient are0 0 0. Proceeding from there, we
have:

0321) 123103
OUD
(end-around ( 1} 0303
carry) 1
0310 (advance counter 4 by 1)
+3012
3322

Recall that since the last addition results in no carry digit, this means that the
last difference is actually —0011. We do not advance counter 4 but instead
recover the previous difference 310, bring down the next digit of the dividend,
proceed to counter 5, and restart the process on the number 3100. The re-
mainder of the process goes like this:

3100
TOOL
1)2112

(advance counter 5 by 1)

1132 (advance counter 5 by 1)

0211 (advance counter 5 by 1)

03223 (do not advance counter 5)

NONDECIMAL NUMBER SYSTEMS 45


So far the quotient register looks like this: [o [0 [0 |1/3 |0)|. Recover the
previous difference 211, carry down the next digit of the dividend, advance
to the next counter, and proceed.

32 (advance counter 6 by 1)
12

0211 (advance counter 6 by 1)

Clearly, repeating will lead to a negative remainder. We conclude now with


the quotient register looking like this: [0]0[0]1] 3] 2| and with re-
mainder 211.

Considering all the work involved in the two previous examples, you
can see why one does not employ this method when computing by hand.
But an electronic computer can perform at a dizzying pace. It performs all
arithmetic operations using only one basic operation—addition. Wehaveseen
that we can subtract by adding, for example, the b—1 complement. Clearly,
multiplication can be achieved by repeated addition. And now we see how
division can be done using only the arithmetic operation of addition. The
computer does not mind doing all the required additions, the setting up and
advancing of counters in registers, the shifting left or right as required by the
operations of multiplication and division. Circuits have been devised to
do all these things and myriads of other required tasks. As far as arithmetic
operations are concerned, it is much simpler to make the computer able to do
only one operation but at a fantastically rapid pace. The circuits required to
perform addition are very simple to design. To have separate circuits de-
signed for each operation would terrifically complicate the computer.

EXERCISES

2.19 Divide using the direct method. Carry to at least one fractional
digit if the division is not even. State the remainder in each case.

(a) Base 5: 23) 14302


(b) Base 2: 1011) 11011101.1
(c) Base 7: 43) 61405
(d) Base 16: FA) 19E47

46 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(e) Base 4: 322) 3330231
(f) Base 8: 67) 171717

2.20 Divide using the method of subtraction as described in the text.


Actually subtract, do not use the method of adding the b — 1 com-
plement.

(a) Base 2: 101) 1110111


(b) Base 8: 347) 42562
(c) Base 4: 322) 332021
(d) Base 16: 9F) C37DE

2.21 Divide using the method of subtraction. Do the subtracting by


using the method of addition of the b — 1 complement.

(a) Base 2: 101) 110111


(b) Base 7: 346) 256332
(c) Base 12: 98A) B345B
(d) Base 10: 756) 568934

2.6 BINARY CODED DECIMAL NUMBERS

Another method sometimes used to translate external decimal numbers into


a binary form that the computer can easily manage is called binary coding.
Although we shall present this method for hand calculations, you should
realize that the coding and the subsequent operations of the computer on
these coded numbers are handled completely by the computer itself internally.
First, recall (see Exercise 2.4) that each of the decimal numbers 0 through
15, inclusive, can be expressed in binary form using four binary digits:

0 0000 4 0100 8 1000 12 1100


1 0001 5 (OOH! 9 1001 (See Ol
2 0010 6 0110 10 1010 14 1110
3 0011 af (Oni ial sib! is ihlalal

Thus, 16 four-digit binary numbers can be constructed. Now suppose that


one associates one of these 16 numbers with each decimal digit, but not neces-
sarily the binary equivalent of the decimal digit. There are 10 decimal digits,
and so evidently this association can be done in quite anumber of ways. Here
is one way which we shall call code 1 (each set of associations is called a coding):

NONDECIMAL NUMBER SYSTEMS 47


O 0011 5 0100
1 1001 6 0010
2 0001 7 1000
@ TANIA 8 1010
4 1101 9 1110

You note, of course, that this particular coding does not associate any decimal
digit with its corresponding binary equivalent. Any decimal number can
now be coded using this code by following this rule: Replace each digit of the
decimal number by the corresponding four-digit binary number according to
the code.

Example. 8 6 2 (decimal number) is coded thus:

1010 0010 0001

The 12-digit coded result 101000100001 is, naturally, not the ordinary binary
equivalent of the decimal number 862. [862(19)= 1101011110]. Thus, as
you can see, once the code has been selected, it is very easy to code any deci-
mal number.

The problem of consequence arises once the computer has coded a set
of decimal numbers and then must perform the operation of addition upon
them, retranslate the sum to ordinary decimal, and output the result. To see
this difficulty more clearly, suppose we code the decimal numbers 2 and 4
using code 1 and add these numbers using binary addition. We have

2 0001
4 1101
1110

The result is 1110. According to our code this corresponds to decimal 9. But
clearly 9 is not the sum of 2 and 4. Ina rather arbitrary coding like this one
we have just chosen, there is no simple way to figure out just how we would
ever make the result 0010, which is the code for decimal 6, the proper result.
A commonly used code which we shall call code 2 associates each deci-
mal digit with its four-digit binary equivalent. That is,

0 0000 OO
1 0001 6 0110
2 0010 7 O111
Cm OOM 8 1000
4 0100 9 1001

48 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


We shall now proceed to investigate this code. Other codes are in actual use
in some computers.
One would think that all the problems that arose in code 1 would now
evaporate. However, consider

0110
0101
lon
a 1011

The correct result is decimal 11, a number of two digits, while the binary addi-
tion of the coded decimals is of four digits, cannot represent a two-digit num-
ber, and besides is not one of the allowable four-digit numbers of code2. But
notice this. Suppose that to this result (1011) we add 0110, which is 6 in code2.

Thus,

6 0110
5 0101
1011
+ 0110 (binary equivalent of decimal 6)
00010001
Lovee

We have inserted three zeros to the left of the first 1 to complete the four-digit
requirement of the code. Then, as if by magic, after translating back to deci-
mal digits using the code, we have decimal 11, the correct result. This can
be expressed in the following rule: If the sum of the coded digits is more than
the binary equivalent of 9, add 0110 to the sum, then decode as shown above.
Let us now try adding two decimal numbers of several digits.

Example. Add

SuOmes 1000 0110 1001


AL fs) of 0100 1000 011i

We have shown the code 2 coding of the given decimal numbers slightly spread
apart for clarity. The procedure is to now add (using binary addition) but to
be careful to note whenever the sum of a set of two numbers is greater than
the binary equivalent of 9. Otherwise, we add as usual carrying carry digits
as we ordinarily do. This is what occurs:

NONDECIMAL NUMBER SYSTEMS 49


1
3 @ © 1000 §=©0110 1001
Ag ote: 0100 1000 8 0111
iss 3 © 1100# 1111#% 0000#
OL O Ra OLLO OL Le
0001 0011 0101 0110
Y Y J
ie <3 5 6
The symbols (#) after the sums of the third row indicate that binary 0110 is
to be added to them since the sum of the corresponding set of two binary num-
bers is more than the binary equivalent of 9. The second addition operation
is done as usual with carry digits if required. The first set 0001 is completed
as before. In any case, the set of four four-digit binary numbers corresponds,
by recoding back to decimal, to the proper answer.

Example

dt Ske 2 0100 0011 1001 0010


8S i 7 © 1000 0001 0111 0110
Dem OmeS 1100# 0101 0000# 1000
0110 0110
0001 0010 0101 0110 1000
eS _@SES eas of <7

1 2 5 6 8

We shall not proceed any deeper into the further intricacies of the properties
of binary coding of decimal numbers. Perhaps you can figure out, for this
particular coding, why the addition of 0110 to the proper sums makes the
process work.

EXERCISES

2.22 Construct a binary code different from the two used in this section
and use it to code the following decimal numbers:

(a) 8142
(b) 93047
(c) 63415
(d) 3999

2.23 Use code 2 of this section to code the following decimal numbers,
then add them using the rules given. Follow the presentation
plan
used in the text, that is,

50 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Decimal Binary coded
§2 1000 0010
4 7 0100 0111 etc.
129:

(b) 75
23
(c) 75
48
(d) 325
299
(e) 1473
9243
(f) 2837
48796

(g) 8007
3998
(h) 437
245 +
938

NONDECIMAL NUMBER SYSTEMS 51


are
A as Behe
oe{
¥
1
¥
, # r
ane. -
>” wt
| 7 " v7 4
Lo

| _ -
e
y 7
y - ie
: aes
AA
«

as
-
=

~
: . ;
ry

x a
Sa
~~
x
/5 -
.
‘ i
¥
e =
>
‘¢
a
:* A

od

airy
a

e a)

a|

Maar
' 5o¢ 1

ve

Ut
Algebra: Linear Functions

3.1 PRELIMINARY REMARKS

In algebra we construct mathematical expressions and statements using two


kinds of symbols representing numbers. We use constants (or explicit num-
bers) like 7, —34, and 5.62—these symbols are fixed in value; we use variables
(or literal numbers) like a, b, x, y, a, and @—these are nonnumeric symbols,
usually letters of the English or Greek alphabet. The variables stand for num-
bers but may take on different values in varying contexts. All these symbols,
constant or variable, either are numbers or represent numbers. They can be
combined following simple rules by using the four operations of addition,
subtraction, multiplication, and division into mathematical phrases called
expressions. Standard symbols are used to represent these operations. For
addition, we use +. Examples of expressions using + area + 3,7+9.3, and
x+y. For subtraction we use —. Examples are a—3,7—9.3, and 479 — y.
The symbols representing multiplication are various. Sometimes we use X
or :. Examples of expressions using these symbols for multiplication are
aX b,473 x y,andc:d. Often in algebra we simply omit either symbol and
indicate multiplication by placing the numbers or symbols directly next to each
other. For example, 4y means 4 X y, and abc means a X b X c. Of course, we
cannot do this if the two symbols are both constants. Would you interpret
738 as meaning 7 X 38? In the product of a constant and a variable, we always

53
write the constant first. Thus, it is 4y and not y4. This is an example of
algebraic etiquette. As you recall, if a variable or constant is multiplied by
itself, we use the symbol representing power or exponentiation. Thus, we
write, if we want to, a X a as a?,a X aX aasa*,andso forth. As we shall see
in the next chapter, the symbolic programming language called Fortran uses
the asterisk * as the symbol for the operation of multiplication. There we
shall write A * B instead of a X b (or ab). Note also the use of nonitalic capital
letters in this example. For the operation of division the symbols / or
are the most common. The symbol + used sometimes in arithmetic is rarely
used. Some examples of expressions using division symbols are a/b (a di-

vided by b), 2 and 4.5/3.7. The slash symbol / is the one most used in com-

puter languages. In Fortran we write such expressions as X/Y and A/2.5.


Of course, many expressions contain several of these operation symbols.
Thus, x + 3y, a—c/d, and a+b—A4x are properly formed expressions. An
expression can be evaluated if the values of the variables it contains are speci-
fied. Suppose x has the value 7 and the variable y has the value 8. Then the
expression x + 3y has the value 31 (that is, 7 + 24). If the variable x has the
value 8.7 and y has the value —3.2, then the same expression x + 3y has the
value —0.9. We find this value by substituting the given values for x and y
into the expression and calculating the value by evaluating 8.7 + (3)(—3.2).
When an expression contains more than one operation, a definite order
in which the operations are to be performed has been agreed upon. This
order is called the hierarchy of operations and is as follows:

1. Exponentiation
2. Multiplication and division
3. Addition and subtraction

Let us now consider some expressions that do not contain parentheses and
determine the order of performance of the operations they contain.

Example. Suppose a is 4, b is —3, and c is—7. Then the expression ab? + c is


evaluated like this: Since it contains exponentiation, that operation is done
first; b? is evaluated as 9. It contains the product of a by b?, so the multipli-
cation is done next: the product of a and b? is 4 X 9 and has value 36. Since
there are no more multiplications or divisions, we start executing any addi-
tions or subtractions involved; to the product 36 we now add the value of c.
We finally evaluate the numerical expression 36 + (—7) and arrive at the final
result of 29, the value of the expression.

Example. Evaluate the expression ab + c if a is 12, b is 3, and c is 5.

54 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Solution: Multiply a by b, then to this product add c. The result is 36 +5,
so the value of the expression is 41.

Example. Evaluate the expression a/b — c/d if a is 6, b is 4, c is 5, and d is 4.

Solution: Divide a by b, divide c by d, then subtract these two quotients.


Since a/b is 1.5 and c/d is 1.25, the value of the expression is 0.25.

The symbol = (read ‘is equal to”) is used to equate two expressions.
The resulting algebraic statement is called an equation. Thus, the equation
x+y =7 is read ’’x plus y equals 7” or “the sum of x and y is 7.” Note the
difference between an expression and an equation. An algebraic expression
is a mathematical phrase; an algebraic equation is a mathematical sentence.
An equation is said to be satisfied for a certain set of values of the vari-
ables it contains if the two expressions equated become identical when the
values of the variables are substituted into them. For example, the equation
x+y =7 is satisfied ifx=5 and y=2. Itis not satisfied for x = 3 and y = 8.
Evidently many sets of values for x and y satisfy the equationx+y=7. As
you recall, many equations are satisfied by a unique value of the variable con-
tained. Thus, x +3=8 is satisfied only when x=5. In such an equation,
finding the unique value that satisfies it is called solving the equation.

EXERCISES
3.1 Evaluate each of the following expressions for the values of the
variables given:

(a) ae 7,8 = 3, X= 7
(b) a/b + cd,a=3,b=2,c=4,d=1.25

(c) 2a —<,a=—2, c= 12, d=—6


(y=
1) b= 06 =3/4 =9
gi = I
(ej ase Oxk —74
(f) AUF phy, = by ated mace et
G
(g) Gat 2 oo

3
(h) & + xy, a=10,x=—6, y= 30

3.2 Solve each of the following equations:

(a) 3x +7=7
(b) 2—x=8

ALGEBRA: LINEAR FUNCTIONS 55


(c) 3a=5+7
Mat
(ier =3

(C2
Oe =D ae
bea. 28
a Ste PIR

3.3 Translate each of the following word statements into algebraic


equations.

(a) The sum of p and q is —8.


(b) The product of a and b is 12.
(c) The product of 4 and x added to the product of 3 and y is 15.
(d) The sum of a and b is equal to the product of c and d.
(e) The square of a is 37.
(f) The area A of a rectangle is the product of its length L and its
width W.
(g) The distance d is the product of the velocity v and the time t.

3.4 (a) Find at least five sets of values for x and y each of which satis-
fies the equation x + 3y = 8.
(b) Solve the equation x = 16.
(c) Show that x=2 does not satisfy the equation x° + 7x? — 8x
— 67=0.
(d) If x=0, y =7, evaluate the expression xy, the expression x + y,
the expression y/x, the expression 3x° + 7xy + 8y’.

3.5 Solve the following linear equations for x if all the constants and
the variable x are in the given base. All operations required to
solve for x are thus to be performed in that base.

(a) Base 5: 3x —4= 131


(b) Base 8: 7x + 11 = 333
(c) Base 4: 10x + 201 = 2010 — 13x
(d) Base 12: 63 = 1A3 — 14x

Another set of symbols often used in algebraic expressions is the pair


of parentheses (and ) called, respectively, the opening parenthesis and closing
parenthesis. These are symbols of grouping and indicate that the quantities
they enclose are to be considered as a unit. They always occur in pairs; for
each opening parenthesis there must be an accompanying closing parenthesis.

56 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Their use in an expression can alter the order in which operations are done.
Here are some examples of expressions containing parentheses.

a+(b+c)/d (a+ c)/d (Gai) |(Ga)


a+ (b/c) +d a+ b/(c+d) (a+d(b+c))/e

The last example contains what are called nested parentheses, one set of paren-
theses within another set. In such an expression, we follow this rule: To evalu-
ate an expression containing parentheses, proceed to the innermost parentheses
and evaluate the expression they contain according to the usual hierarchy rules.
Then move to the next outer pair of parentheses, evaluate, and so on. Con-
sider the expression (a+ d(b+c))/e. Since the innermost parentheses en-
close b + c, we calculate this sum first. We then proceed to the outer pair,
multiply b + c by d, and add the result to a. Finally we divide by e. For ex-
ample, ifa=3,b=6,c=8,d=4,ande=2,b+c=14,d(b+c) =4(14) =56,
at+d(b+c)=3+56=59, and (a+d(b+c))/e=*%2=29.5. In algebra
other symbols of grouping such as brackets[ ]andbraces{_ } are sometimes
used. In most computing applications the parentheses are the only symbols
of grouping that are permitted, no matter how nested they have to become.
In addition to possibly redirecting the order of operations, parentheses can
be used to provide clarity even when they are not actually required. It is per-
fectly permissible to write (ab) + (c/d) even though ab + c/d means exactly
the same thing. However, some expressions cannot be written without using
parentheses. For example, to divide r by the quantity a + b, we must write
r/(a + b); we cannot write r/a + b.

EXERCISE

3.6 If a=2, b=3, c=8, and d=2, evaluate each of the following
expressions:

(a) a+ bic
(b) (a+ b)/c
(jias- bile+rd
(d) (a+ b)/(c+4)
(e) a+ (b+c)d
(f)a — bj(e+a)
(g) (a—b)/c+d
(h) (a— b)/(c
+ a)
(i) (3a — 4b)/(bc)
(j) (3a — 4b)/be
(k) 12a/bc
(1) 12/1/b

ALGEBRA: LINEAR FUNCTIONS 57


(n)) Gab) 7/4
(njisa— bid
(0) (a+ b)?/(a — b)?
(py4e(a = ed --7) (b+ 24)

3.2 FUNCTIONS

When an equation involves one or more variables, it can be solved using


standard algebraic operations for one of them. Thus, the equation

3x + 7y=8+w (3.1)

contains the variables x, y, and w. Suppose we solve for y. This means that
we want to, without in any way altering the mathematical content or meaning
of the equation, write the equation in the form y= .... Clearly, 7y=8
+ w— 3x, and y= (8+ w-—3x)/7. (Note the use of parentheses; the result
is not y=8+w-—3x/7.) The value that y will have is determined uniquely
if specific values are given to w and x. We say that the variable y is a single-
valued function of the variables x and w. Since the value of y is dependent
upon the values assigned to x and w, the variable y is called the dependent
variable. The two variables x and w are independent variables since, presum-
ably, any values may be assigned to them.
A short glance back to Eq. (3.1) is sufficient to make one realize that
any of the three variables it contains can be regarded as a function of the other
two. We can solve for w explicitly. Thus, w=3x+7y—8. Here w is the
dependent variable and x and y are independent. Again, w is a single-valued
function of x and y since it is clear that there is one and only one value of w
for each selection of the pair of values for x and y.
It is conventional to represent functions by a certain notation called,
appropriately enough, functional notation. We write, for example, y = f(x)
(read ‘’y is f of x” or “y is a function of x, the function is named f”) to express
the fact that the value of the dependent variable y depends on the independent
variable x. Note the use of parentheses to enclose the x, often called the argu-
ment of the function. The equation y = f(x) does not give explicitly the pro-
cedure one is to follow to determine y if a value of x is prescribed. When one
actually substitutes a specific value of x into the expression f(x), one denotes
this by replacing the x within the parentheses by the specific value of x. For
example, if x =a, we write f(a); if x =—2, we write f(—2). Suppose f(x) =
x*—7x+3. Then f(3) =3?—7(3) +3=9—21 +3 ==9; and f(—b) = 0)"
—7(—b) +3=b?+7b+3. Similarly, f(2/x) = (2/x)? —7(2/x) +3 =4/x? — 14/x

58 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


+3. The letter f in f(x) is not sacrosanct. Other letters such as Ce di relGe
or H can be used.
A similar notation is used for functions of several variables. Suppose
Z— S(x,yp) —x+3y—7p. Then 9(2,3,7)=243(3) —7(7) =2+9—s9—
—38. Clearly the notation g(2,3,7) means that 2 is to be substituted for sd)
for y, and 7 for p wherever these variables occur in the function expressio
n.

Example.
ee ArUe eel lie 5)
Let h(a,b,@) eelnengy
2a0 ENS (est p)i—
ren SSS
or
EXERCISES

3.7 Given 3x + 4y — 5q = 8, find x as a function of y and q; find yasa


function of x and q; find g as a function of x and y.

3.8 Given x? — y=6, find y as a function of x; show that x is not a


single-valued function of y.

3.9 If f(x) = 4 — x2, find f(1); f(-Vs); f(2); f(t).

SAUTE |) oc 5, find F(a-F kh) f(a hk) — F(z).

Fi 2
3.11 If g(p) =e find ¢(5); g (7) g(s—5); ¢(4); Te

3.12 If h(x) =x—4y+1/x, find h(1,2); h(/2-2); h(1/a,1/b);


(Geimlesei to) (6.0)

213 If GGsii—r +s + i7, find G(002)- G(2,3—4); G(1,0)Vs):


G (3/2}/2/4); G(—1,-2,-3); G( V3, V5, V6).

This concludes our introduction to functions. In the remainder of this


chapter we shall restrict ourselves to linear functions. A function (of any
number of variables) is called linear if each of the terms it contains is of first
degree or is aconstant. Thus, 8x —7y + 9z is a linear function of x, y, and z,
and 56 + a + 3b is a linear function of a and b. The simplest linear function,
other than a single constant, is one containing only one variable, for example,
3x + 7,—41+17.3r, and 8f— 45. It is nothing short of amazing how impor-
tant these rather simple kinds of functions are in all sorts of significant appli-
cations. We shall study some of these applications of linear functions in
this chapter.

ALGEBRA: LINEAR FUNCTIONS 59


3.3 COORDINATE SYSTEMS. ANALYTIC GEOMETRY OF
THE STRAIGHT LINE

In order to visualize geometrically the linear function of one variable, let us


choose x as the independent variable, y as the dependent variable, so that
y = f(x) where f(x) is a linear function of x. We now set up a (one-dimen-
sional) coordinate system on which we shall represent the values of the vari-
able x. First, draw a horizontal line and label it with the symbol x as shown
in Fig. 3.1. Now mark a point on the line and associate the real number zero
with this point. This point will be called the origin. If you then mark other
points using a uniform scale as shown in Fig. 3.1 and presume that the line
extends indefinitely to the left and right, you can see that all the values that
the real variable x can take on are associated with unique points on the line.
And, alternately, each point on the line has associated with it a unique real
number. The line has now become a one-dimensional coordinate system
called the x axis. Now for the dependent variable y. We copy the same coor-
dinate system with exactly the same set of real numbers on it, but we label the
variable y instead of x. Clearly, in this manner one can construct one-dimen-
sional coordinate systems for all real variables.
Now we shall begin the construction of a two-dimensional coordinate
system. As shown in Fig. 3.2, again we place the x axis horizontally, but now
we place the y axis at a right angle to the x axis with their origins coinciding.
It is now possible to associate any point in the plane that these two lines de-
termine, called the xy plane, with a pair of realnumbers. These numbers are
called, respectively, the x and the y coordinates of the point. Conventionally,
they are enclosed by parentheses. The point with coordinates (3,2) is shown
in Fig. 3.2. Clearly, it is that point in the plane where the vertical line through
3 on the x axis meets the horizontal line through 2 on the y axis. The general
point in the plane has coordinates (x,y). It now seems obvious each such
ordered pair of real numbers is geometrically associated with a point in the
plane and also that each point in the plane has a pair of real numbers associ-
ated with it.
The graph of a function y = f(x) is the set of all points in the xy plane
just described whose first coordinate is x and whose second coordinate is y,
that is, f(x). Consider y=3x+7. Choosex=1. Then y=10, and the point
P with coordinates (1,10) is a point of the graph of the function. Obviously,
any value for x can be chosen, and the corresponding y easily calculated. The
point (x,y) lying on the graph can then just as easily be plotted in the xy plane.
It is a fact that the set of points (x,y) satisfying this equation lie on a straight

Fig. 3.1

—+—_}—_+—_}—_ ieee
3 5

60 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Fig. 3.2

line. Plot a few more points and see if you can verify this. You recall, though,
that a straight line is determined if two distinct points which lie on it are pre-
scribed. It would appear, then, that the line itself could easily be drawn by
simply plotting very carefully two points on it and then extending the line
segment joining these two points indefinitely in both directions. The points
(1,10) and (—2,1) satisfy the equation and thus lie on the line. The graph is
shown in Fig. 3.3. If you employ this two-point method for graphing straight
lines, it would be best if the two points chosen are not too close to each other.
In general, the graph of the linear equation y = ax + b is a straight line.
a and DB are constants.
Some lines have peculiar equations. Consider the line with equation
y=2. Clearly, whatever x one chooses, the corresponding y is 2. Two points
on the line are, for example, (3,2) and (—7,2). Evidently, y = 2 is the equation

Fig. 3.3

ew t4++++

ALGEBRA: LINEAR FUNCTIONS 61


of a straight line parallel to the x axis and two units above it. Again, consider
the equation x=—3. (—3,4), (—3,8), (-3,5), etc., are all points of the line.
All points of the plane with x coordinate —3 are points of the line. Clearly,
x =—3 is the equation of a line parallel to the y axis and three units to the left
of it. We leave it to you to generalize to the family of lines y= a and to the
family of lines x = b, where a and b are any constants.
Now one ought to be able to write the equation of a line if one knows
two points on it. We state the following rule: If (x,,y,) and (x,,y2) are two
distinct points on a straight line, then its equation is

Yo Wi
Ui emma) (3.2)
Xy
— X4

or, equivalently,

Vip Un
Wa ce od(ie x5) (3.3)
1

Note that x and y are the variables here and that x,, x2, y;, and y»2 are constants.
The resulting equation is linear and hence represents a straight line. Using
the first version, we now verify that both (x,,y,) and (x2,y2) lie on the line.

We substitute x, for x, y, for y; then 0= = (0) = 0; hence, (x,,y;) lies on


2 1

the line. Now we substitute x, for x and Y> for y; then

Veo Yoel

=U Ue

Fig. 3.4

62 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


hence, (x:,y2) is on the line. We leave it to you to verify that (x,,y,) and
(X2,Y2) satisfy Eq. (3.3).
The quantity (y2— y,)/(x:—x,) which appears in both Eqs. (3.2) and
(3.3) is the slope of the line. It is usually denoted by m. Consider Fig. 3.4.
It shows a straight line, and the points (x,,y,) and (X2,Y,) are any two distinct
points on it. The vertical distance y, — y, is sometimes called the rise of the
line; the horizontal distance x, — x, is called the run. The ratio of the rise to
the run is the slope of the line, that is, m = (Yo — y1)/(%_.—x,). It seems evi-
dent that the slope of a line is constant. In fact, it can be shown that the only
plane curve with its slope constant is the straight line.

Equation (3.2) can be written

Y — Yi = m(x— x) (3.4)

This version of the equation of a straight line is called the point-slope form
since it allows one to find the equation of the line if its slope m and a point
(x,,y,) on the line are given.

Example. Find the equation of the straight line which passes through the points
(4,2) and (—3,5).

Solution: Using Eq. (3.2) with x, = 4, x, =—3, y,; = 2, Y2=5, we get

Ome.
y—-2= (ets)
pe sea A

y-2=— (x4)
7y — 14=—3x
+ 12

or, finally, 3x + 7y — 26=0. The slope of this line is —%/7.

Example. Find the equation of the straight line whose slope is —4 and which
passes through the point (3,6).

Solution: Using (3.4), with x,=3, y,=6,m=—4, we get y—6=—4(x—3),


Y—6=——47 + 12, or y= —4x + 18.

We note that if m is positive, the line rises as it moves to the right; if m is nega-
tive, the line falls as it moves to the right; and if m = 0, the line is parallel to
the x axis. The slope of a vertical line is not defined.

ALGEBRA: LINEAR FUNCTIONS 63


Equation (3.4) for the straight line can be rewritten as follows: y — yi =
m(x—%), y=mx+ (¥,—mx), y= mx +b, where b= yy, — mx; The new
form for the equation of the line y = mx + b is called the slope-intercept form.
Clearly, m is its slope. But note that when x=0, y=b. Thus, the point
(0,b) is on the line, and this is the point at which the line intersects the y axis.
The number b is called the y intercept.

Example. Find the equation of the line whose slope is 3 and whose y intercept
iSO!

Solution: Using the slope-intercept form with m=3 and b=—5, we have
y = 3x—5.

Example. Find the slope of the line 3x + 4y = 8.

Solution: We place the equation into the slope-intercept form. Thus, 4y =


—3x + 8,y=—3x/4+ 2. Therefore, m= —3/4, and the y intercept is 2.

EXERCISES

3.14 Find the equation of the line which passes through the points
(a) (3,4) and (—2,5)
(b) (—4,0) and (5,6)
(c) (4,1) and (—3,1)
(d) (0,0) and (—6,2)
(e) (5,6) and (5,0)
(f) (11,0) and (0,4)

3.15 Plot the lines with the following equations:

(a) y=3x+4
(Diva4
(c) x+y=3
(d) 3x—2y=5
(e) x=5
(t) y= 4x
(g) y=—3x+4
(h) y=x

3.16 Find the slope of each of the following lines:

(a) y=x
(b) 3x +5y =7

64 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(c) x-—y=8
eee pe
Ch Dens a5
OS eeete

SIV Find the equation of the line with the following properties:

(a) passes through (0,0) and (4,6);


(b) passes through (—5,6) and has slope —4.
(c) has y intercept 4 and slope 6.
(d) passes through (4,5) and is parallel to the line 2x — 4y =9.
Hint: Two lines are parallel if they have the same slope.
(e) passes through (—3,—2) and has y intercept 3.
(£) has y intercept 5 and x intercept —4.

3.18 The line y= mx +7 passes through the point (6,7). What is its
slope?

a219 Two variables F and C are related linearly, that is, F+ bC=d,
where b and d are constants. If F=32 when C=O, and F= 212
when C = 100, find b and d.

3.20 The linear equation of Exercise 3.19 represents the relation between
Fahrenheit and Celsius temperatures. (a) Use the result of this
exercise to find the Celsius temperature C corresponding to the
Fahrenheit temperature F= 450°. (b) Use the result of Exercise
3.19 to find the temperature at which F=C.

ged The position of a particle is given by s = 3t + 8, where s is in feet


and tisinseconds. (a) Finds whent=/7. (b) Findtwhens= 29.

3.4 SIMULTANEOUS LINEAR EQUATIONS

We suppose you have already learned how to solve two simultaneous linear
equations like

x+2y=5 (3.5)
i aed

So, recall that a suitable method is called the method of elimination. First, we
eliminate the variable x by multiplying the first equation of (3.5) by —2, then

ALGEBRA: LINEAR FUNCTIONS 65


adding the resulting equation to the second equation of (3.5). Thus,

—2x — 4y =—10
26a er
= oY =>3
3
I>5
Then, using the first equation of (3.5), x=5—2y. Substituting y = %/s5, we
have x =5— %s=1%s. One easily verifies that substituting x= 1%5, y = 9/5
into (3.5) satisfies both equations; i.e., they form a solution set.
From our discussion in Sec. 3.3 we note that each of the equations of
(3.5) can be represented geometrically as a straight line. To solve the equa-
tions algebraically corresponds geometrically to finding the coordinates of the
point at which the two lines intersect. Figure 3.5 shows these lines and their
point of intersection.
There are occasions, of course, when the two lines do not intersect. If
the lines are distinct and parallel to each other, they will have no point of
intersection. Consider

eee
2x + 8y = 17

If we follow the usual procedure and try to eliminate x from the two equations
by multiplying the first equation through by —2 and adding, we have

Fig. 3.5

66 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


2x — SY ——14
2x + 8y = 17
0=3

Both variables are eliminated, and the false result 0=3 ensues. As you can
check, the two lines represented by the equations are parallel.
It is possible that the two linear equations actually represent the same
line. Consider

al Sy =7
4x —10y
= 14

Elimination of x now leads to the true result0 = 0. Closer inspection reveals


that the second equation is merely the first one multiplied through by 2 and
thus represents geometrically the same set of points as the first equation. If
one must consider this simultaneous set as representing two lines, even though
they are not distinct, then every point lying on one satisfies the other equation.
The solution set is thus the entire (infinite) set of points satisfying either equa-
tion. Some of the infinitely many solutions are (0,—%/s), (2,—9/s), and (7/2,0).
The algebraic procedure followed above can be used for the solution of
three simultaneous linear equations in three unknown variables. We shall
not present the geometric significance in detail except to say that the three
equations now represent planes in three-dimensional space and we are trying
to find the point (with three coordinates) in which the three planes intersect.
Consider the following:

Xr eYrisz5 (3.6a)
x + 2y a (3.6b)
2x = BU! (3.6c)

We eliminate z from (3.6a) and (3.6c) by multiplying (3.6c) through by 3


and adding the result to (3.64). Thus,

LY js — oO
6x ee 4 (3.6d)
TE¥ Sh

Now combining (3.64) with (3.6b) which already contains only x and y,
we have

7x+ y=17 (3.64)


x+2y=1 (3.6b)

ALGEBRA: LINEAR FUNCTIONS 67


Multiplying (3.6d) through by —2 gives

—14x — 2y = —34
gar AY = i
—=13x = —33
33
7G
Using (3.6b), which is x + 2y = 1, we have 2y =1—x=1— 99/13 = (13 — 33) /13 =
—%3; therefore, y=—1%s. Now using (3.6c), which is 2x —z=4, gives
Z=2x—4=2(3)/13) —4 = 6/13 — 52/33 — 1443: therefore, z=141s. Thus, the
solution set is x = 99/13, y= —1%13, z= 14/13.

EXERCISES

3.22 Solve the following sets of simultaneous linear equations:

2 Eee
y=7
2x + Sy = 12
a {x—7y=-—2
() {a+b=3
2a + b=13

| 3x + 4y = 16

ie
6x + 8y = 32
eae
(e) [ey
ieee!
BaP AD ap Bye == DS
(a3) 4c — = 36

lies
ie ame

| Rep ek
0.03v + 0.05u = —0.04
3x + 4y + 5z=6
o| 2Y 32 — 4.
2z=7

3.23 Solve the following sets of simultaneous linear equations if all


the

68 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


coefficients and the variables are in the given base. All the oper-
ations required to solve the equations are to be done using that base.

(a) Base 2: 10x + y= 101


x—y=100
(b) Base 4:10x— y= 21
3x — 2y = 10
(c) Base 9: 6x+ 5Sy= 38
18x — 16y = 110
(d) Base 16: 20x— y=3D
11x + Dy = 49

3.5 LINEAR INEQUALITIES IN ONE VARIABLE. ABSOLUTE VALUE

Consider the coordinate system of Fig. 3.6. Note that two points labeled a
and b are marked on it. Clearly, b is greater than a because it is farther to the
right on the coordinate system than a is. We write this as b > a (read “b is
greater than a’’). At the same time, of course, a is less than b since it is farther
to the left than b is. We write this as a < b (read “a is less than b’’). Note
that a < b is just another version of b > a read (and written) from right to left.
The two statements b >a and a < b are examples of inequalities. Here are
some examples of inequalities that are evidently true:

=f<2 pe 8 Te <2 12.6

It seems fairly evident that if a and b are any two real numbers, exactly
one of the following must hold: a < b,a > b, ora=b.
We now proceed to geometrically interpret some linear inequalities in
one variable.

Example. Show the set of all numbers x such that x > 2.

Solution: Draw the one-dimensional coordinate system for the variable x and
mark on it all numbers that are greater than 2:

ALGEBRA: LINEAR FUNCTIONS 69


—____.+
+ ¢——_>«
OR te2
Fig. 3.7

This is evidently the set of all numbers to the right of 2; that this set does
not include 2 itself is designated on Fig. 3.7 by the (, the opening parenthesis,
at 2.

Example. Show the set of all x such that x <3. We read this inequality ‘x is
less than or equal to 3.” The set includes 3 and is shown in Fig. 3.8. The
symbol | indicates that x = 3 is to be included in the set of values.

We read 2 < x <5 as “x is greater than 2 and (at the same time) less
than 5.” Figure 3.9 shows this set of values of x. This is called an open in-
terval—it contains all values of x between 2 and 5 but does not include the end
points 2 and 5 themselves. Figure 3.10 shows geometrically the set of values
of x satisfying —3 <x <2. This is another interval but it contains the left
end point —3; it is called half-closed. Another notation for the set of values
of x between 2 and 5 is (2,5), which is read ‘the open interval from 2 to 5.”
Context is used so that this notation is not confused with the same notation
used for coordinates of a point. If an interval contains its left end but not the
right end, it is written with a square bracket on the left, as in [3,7).
Finally, the notation [2,12] is used to represent the closed interval (all
x such that x is greater than or equal to 2 and is less than or equal to 12). If
an interval extends indefinitely to the right, we write (a,~), meaning all x
such that x is greater than a. We also write such expressions as (—~,5] for
—° <x <5, meaning all x which are less than or equal to 5. We never close
the interval at © since © is not a number but is used to indicate indefinite ex-
tension to the left or right. It is the infinity symbol.
The notion of absolute value is of some importance in many applied
problems. We write, for example, |a| and read “the absolute value of a.”
The absolute value of a is simply a itself if a is zero or positive, i.e., if a > 0.

Fig. 3.8

ae
Oe

Fig. 3.9

e+ C++ x
(Oy af sh GE Te

Fig. 3.10

70 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Fig. 3.11

It is —a if a is negative, i.e.,ifa <0. Thus, |0|=0, |+5|=5,|-7| =—(—7) =7.


The result is, as you can easily see, that the absolute value of any real number
is just its magnitude and is always positive or zero. To interpret |a| geomet-
rically, we draw a one-dimensional coordinate system and place a onit. |a| is
the distance, always 20, that the point a is from the origin. Figure 3.11 shows
the idea.
Consider the equation |x — 2|= 3. What could x be? Sheer guessing
shows that xcould be5or—1. There is a way to proceed algebraically to find x.
If the absolute value of “something” is 3, then the “something” must be 3
or —3. Thus, in this case, the ‘“something’’ x — 2 must either be 3 or —3.
Thus, x -2=3 or x—2=~—3. Solving each of these, we arrive at x=5 or
c= —1.

Example. Solve for x: |7 — 3x| = 6.

i 16 6x1 ys
= eS Se 32— 115 e738

Thus, x = ¥3 or 15/3. Either of these values of x, and none other, satisfies the
equation |7 — 3x| = 6.

Inequalities can involve absolute value. Consider the inequality |x| < 3.
Clearly, x could equal 2, —1, —2.5, 1.7, etc. But a check reveals that x cannot
be greater than 3 or less than —3. Thus, |x| <3 is exactly the same set of
values of x as —3 < x < 3, that is, the open interval (—3,3). In general, if the
absolute value of an expression is less than a, then the expression itself must
be between —a and a. Example. |7 — 5x| < 8 is equivalent to—8 < 7 —5x < 8.
Consider the inequality |x —3| >5. Values of x like 12, —7, 347, etc.,
satisfy this inequality. A check reveals that for this inequality to hold, the
quantity x — 3 must be either greater than 5 or less than—5. This means that
x >8orx<-—2. This set of values of x is not an interval on the x axis, as
Fig. 3.12 reveals.

Fig. 3.12
—+ -+++ + +++€-—>
2, 0 8

ALGEBRA: LINEAR FUNCTIONS 71


It is possible to solve inequalities in one variable in almost exactly the
same way one solves linear equations.

Example. Solve 2x +3=—8 for x. Clearly, 2x =—11 (by subtracting 3 from


both sides) and x = —1¥/2 (by dividing both sides of the equation by 2). x has
exactly one value.

Example. Solve 2x + 3 <—8 for x. Adding —3 to both sides of the inequality,


we have 2x <—11. Then dividing both sides by 2, x <—1¥%2. In other
words, if any value of x less than —1/2 (like —7) is chosen, the expression 2x + 3
will have value less than —8.

We have the following first rule: Adding or subtracting a number from


both sides of an inequality does not alter in any way the meaning and mathe-
matical content of the inequality. Special care must be taken, however, when
both sides of an inequality are multiplied or divided by a number (not zero).
Consider the inequality 4— x <3. Suppose we subtract 4 from both sides.
We now have—x <—1. So farso good. But we want to isolate x on one side.
Two methods now present themselves. Add x to both sides, 0 <—1+ x, now
add 1 to both sides, 1 < x, with the result x > 1. Let us now reconsider
—x<—1. Multiplying both sides by —1, we must at the same time reverse
the inequality in order to arrive at the correct result, and again end with x > 1.
In general, the sense of the inequality must be reversed when both sides
of the inequality are multiplied or divided by a negative number. We have
this rule, then: To solve a linear inequality for x, follow normal algebraic pro-
cedures to isolate x on one side of the inequality but if this procedure involves
multiplying or dividing both sides by a negative number, reverse the in-
equality at this step.

Example. Solve 4 — 3x < 10 for x. We have

3x <6 (by subtracting 4 from both sides)


ee 2. (by dividing both sides by —3 and reversing the inequality)

One can solve combined inequalities for x, too.

Example. Solve 8 < 41 — 5x < 76 for x. We have

ees hee < Bs (adding —41 to both sides)


33
5 ee ee ea (by dividing all parts by —5 and reversing both in-
equalities)

72 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


We can solve simultaneous linear inequalities in one variable using a
semigraphical method.

Find all x satisfying both of the following inequalities: 3 < x <8,


—1<3x—7< 11. Solving the second inequality for x, we have 2 <x <6.
We then plot on the same x coordinate system the sets of x satisfying each of
the inequalities 3 <x <8 and2<x<6. If x is to satisfy both inequalities,
clearly we should choose x in the part where the two regions overlap. Thus,
3 < x < 6 is the solution, as shown in Fig. 3.13.

Example. Solve the simultaneous inequalities

ee:
=) S37

We leave it to you to show that the second inequality is equivalent tol <x <5.
Figure 3.14 shows the plot of these inequalities. Thus, thesolutionis1 <x <4.

EXERCISES
3.24 Using the method illustrated in Figs. 3.7 and 3.8, show geomet-
rically the set of all x such that

(a)
x 24
(D)i
2 aie = 4
(Cyt
(dyel
=a <7
(e) 3=x< 0
y
(i) 2 SZ el
5

3.25 Express each of the intervals of Exercise 3.24 using the notation
described after Fig. 3.10.

ALGEBRA: LINEAR FUNCTIONS 73


B06 Solve for x:

(a) |x +1/=5
(b) |4—5x| =7
(c) |2x-7|=0

3.27 Solve the following linear inequalities for the variable contained:

ORS ee
(b) 2—7x
< 12
sey
(es qr 5

(d)iG ope=10
(Ce ORS 0
aie
(PROFS 2 bt aL
3 2 Ox 7 9
(8) 3 -=
8 5
<-

(Dy eee
(i) -7 <1—Y%eaw <-3

3.28 Use the semigraphical method of the text to solve the following
simultaneous linear inequalities:

(a) eabenes
O<x+2<9

2
O<x+3
< 10

Ole |
5) Ss eee hee 115
= 8 SEG)

3.29 Solve the following inequalities for x:

(a) |2x| < 6


(b) 13x) 25

(d) |jx+7|>3
(e) |7—3x| >4

74 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


3.6 LINEAR INEQUALITIES IN TWO VARIABLES

We complete this section on inequalities with a discussion of the graphing


of linear inequalities in two variables. Consider 2x+3y >7. Clearly, a
great number of points (x,y) in the xy plane satisfy this inequality, like (1,2),
(2,2), (—1,5), and (0,3). In fact, as we shall soon see, there is an entire half-
plane of points that satisfy it. Here is how we proceed to find the part of the
xy plane all of whose points satisfy 2x + 3y > 7. First, consider for a moment
the set of points that satisfy the equation 2x + 3y = 7, geometrically a straight
line. Figure 3.15 shows this line plotted in the xy plane. This line divides
the plane into two half-planes, the half-plane above the line and the half-plane
below the line. In one of these half-planes the expression 2x + 3y is always
greater than 7 for any point (x,y) in it and in the other half-plane 2x + 3y
always has a value less than 7. To discover which is which, we just select at
random a point known to lie in one of the half-planes (not on the line). Sup-
pose we select (5,0). By simple substitution into 2x + 3y (let x=5, y=0),
we find that it has the value 10 +0=10. Since 10 > 7, we conclude that (5,0)
belongs to the half-plane defined by 2x + 3y > 7 since it satisfies the inequality.
Since (5,0) is clearly in the upper half-plane, we then conclude that all the
points above the line will satisfy the inequality 2x + 3y > 7 and that this half-
plane is in fact the set of all points which satisfy the inequality. We have
noted this region on the graph of Fig. 3.15. We now reason that all the points
below the line satisfy the inequality 2x + 3y <7. [Just to be sure, though, we
note that (0,0) is in this region and it obviously satisfies the inequality 2x + 3y
< 7 since 0 <7.] Wesee now that actually only one point need be tested, and
the character of the entire plane with reference to the inequality can be
determined.

Fig. 3.15

ei

ab

DXi Vi a, iF
ae 2x+3y=7
~
ae

ALGEBRA: LINEAR FUNCTIONS 75


Fig. 3.16

Now we are ready to consider simultaneous linear inequalities in two


variables. Suppose we are to find all points in the xy plane which satisfy
both 2x —y >3 andx+y >-—2. As shown in Fig. 3.16, we first plot the two
lines 2x -y=3 andx+y=-—2. Then, using the method just described, we
find and shade horizontally the half-plane corresponding to 2x—y > 3. It is
clearly the half-plane to the right of the line [for example, (5,0) lies in this half-
plane and it satisfies the inequality 2x — y > 3 since 10 > 3]. Next we find
and shade vertically the half-plane corresponding to the inequality x + y > —2.
It is clearly the half-plane above the line since (0,0) lies in this half-plane and
it satisfies the inequality since 0 >—2. Finally, we reason that the set of
points satisfying both the inequalities is simply the intersection of the two
shaded half-planes, that is, the parts they have in common. The double-
shaded region that appears in Fig. 3.16 (this does not include the points on the
lines themselves) is the region we have been seeking.
It should now be clear to you how you could geometrically represent
the region in the xy plane all points of which satisfy any number of simul-
taneous linear inequalities in two variables x and y. Here is an example of
three such inequalities.

Example. Find and sketch the region determined by the inequalities x + y < 2,
x—y>—5, and 2x+4y>5. The three lines x+y=2, x—y=—5, and
2x + 4y =5 are shown in Fig. 3.17. We leave it to you to show that the half-
plane below the line x + y = 2, the half-plane above the line 2x + 4y = 5, and
the half-plane to the right of the line x — y=—5 are the proper half-planes
and that the shaded area shown in Fig. 3.17 is the region required.

76 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


2x + 4y=5

Fig. 3.17

EXERCISES

3.30 Plot and shade the half-plane determined by each of the following
inequalities:

(Gl) ese) Ss
(b) 3x + 4y < 12
(Ceo
(d) y>3
(ce) 23 — oy 15

3.31 Plot and shade the region determined by each of the following
sets of inequalities:

|
Ly
SS 3%
(a) Shear
Guy 2 Als
36 SP
(b)
(ee 2c A?
714
Wear
Bil <I
(d) Sh aU ee
5x + 6y > 60
(e) Aga iit & io)

ALGEBRA: LINEAR FUNCTIONS 77


following sets
3.32 Plot and shade properly the area determined by the
of inequalities:

2% AO ea
(a) |4x + 3y > 12
Cia OU eto
—2¢- oy = 0
(b) Ax oy 012
645
— 3a lo
fr
(c) Se
Na eae
DG TA IanO,
(d) [stay >
3x + 4y < 12
y <4
Ye
“|De y = 12
— on eye 10
=sr 2 22
gar Se
(f) NY ee
Abe Sy) > il

3.7 LINEAR PROGRAMMING

Linear programming is a subject that we can pursue only through its elemen-
tary ideas and applications but which plays an extremely important role in
many decision problems of business and industry. It is often concerned with
optimum allocation of certain resources to meet certain commitments and
objectives but subject to definite restrictions. Interestingly enough, as you
could guess from the word linear in its name, it is concerned mathematically
entirely with such problems as the solution of simultaneous sets of equations
and inequalities; so, at least to start, it should not be beyond our understanding.
The main idea is that a linear expression (which could be representing
such a thing as profit) is to be maximized when the variables it contains are
not specifically given but are to be determined subject to restrictions in the
form of linear equations and/or linear inequalities that these variables must
satisfy. Another way to say this is that the given linear expression, often
called the object function, is to be optimized by choosing values for the vari-
ables that it contains but that these variables are themselves subject to severe

78 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


restrictions that are also specified. Although we are not yet mathematically
prepared to read its text completely, the book “Linear Programming” by Saul I.
Gass, McGraw-Hill, New York, 1964, in its introductory chapter describes
many different practical problems that the processes of linear programming
can solve. Some of these are the transportation problem, the diet problem,
the allocation of contract awards, personnel allocations, production scheduling,
and inventory control. Applications are made to such industries as agricul-
ture, chemicals, commercial airlines, and petroleum.
One must keep in mind that because of the type of quantities, such as
amounts of material and number of personnel, which the variables represent,
the solution values of the variables must always be nonnegative. Let us pro-
ceed, as usual, by presenting an example. Suppose we have the object func-
tion z= 5x + 11ly and we wish to find the maximum value of z if the variables
x and y are restricted by the inequalities x + y <5 and 3x— 2y <6. Thatis,
we must find x = 0 and y = 0, subject to these restrictive inequalities, that
will make the linear expression 5x + 11y as large as possible. To proceed, let
us plot the lines x + y =5 and 3x — 2y = 6, then find the region R correspond-
ing to the set of inequalities

es
a
Kika
ape PAY) KN
NW (any
KV ==)
Male
hoa)

This will at least display the region in the xy plane we shall be restricted to.
Figure 3.18 shows this plot and the region R.
To find the region R, we have, of course, followed exactly the method

Fig. 3.18

5x + 11y =—22

ALGEBRA: LINEAR FUNCTIONS 79


discussed in the last section. The region R including all its edges is the set of
all pairs (x,y) satisfying all four restrictive inequalities. Now we select, if
we can, a point (x,y) in R which will make the value of z, that is, the object
function 5x + 11y, as large as possible. The corners of R have coordinates
A(0,0), B(2,0), CCA%,%s), and D(0,5). These points are found by solving
simultaneously the pairs of equations of lines that intersect at the point. It
turns out that it is quite easy to find this interesting point (x,y) in R.
We can regard z= 5x + 11y as representing a set of straight lines, each
member of which we get by assigning a definite value to z. Such lines as
5x + lly=1,5x + lly =2, 5x F1ly =7, and 5x + 1ly = 47 belong to this set.
We note that each line of the set is parallel to every other line of the set, since
they all have the same slope. On Fig. 3.18 we have drawn one such line,
5x + 1ly=—22. We now move this line upward parallel to itself, and we
note that this simply amounts to changing the z in 5x+1ly=z. The first
vertex of R that the (moving) line will pass through is A(0,0). Then5x + 1ly =
0, since (0,0) satisfies this equation. So z now has value 0, considerably
greater than the value —22 it had originally. As we move the line higher, the
value of 5x + 11y, that is z, will increase since the points in R have positive
coordinates. Soon the line will pass through B(2,0). Now5x + 11y has value
10, and z has value 10. We note while pausing here that all the other points
in R now lying on the line will cause the linear function 5x + 11y to have the
value 10. Again we move higher until the line passes through C(?%/5,%s).
Now z=5(?4%5) + 11(9°) = 16 + 9%s = 33.8, a still greater value for z. We
now have a pretty good value for z but we hope to push on and again move
the line parallel to itself and higher. We finally pass through D(0,5) at which
z has value 5(0) + 11(5) =55. This is clearly the maximum value z = 5x + 11ly
could have for any point of R. Thus, z is maximum if x=0, y=5, and its
maximum value is 55.
The result of all this moving of the line z=5x+ 11y can be stated in
the following rule: Evaluate z=5x+11ly at each of the corners of R. The
largest value of z thus obtained is its maximum value of z on R; the minimum
value of z thus obtained is the minimum value of z on R. Again recall that
staying in K or on its edge means that we are maintaining the restrictions
caused by the imposition of the given inequalities.
A simple practical interpretation of the problem we have just solved
could be as follows. A manufacturer produces two items A and B. Let x be
the number of items A produced each week and y be the number of items B
produced each week. Because of manufacturing and other physical restric-
tions, the total number of A and B items must be less than 5, that is, x + y <5.
Suppose also that because of mysterious circumstances it is known that three
times the number of A items less two times the number of B items is less than
or equal to 6. Now suppose that each A item sells for $5 and each B item sells

80 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


for $11. Thus, the income is 5x + 11y (in dollars). Call this z. The problem
can then be stated as “Find how many items A and how many items B should
be produced each week in order that the income be maximized.” As we have
seen, it would be better if the manufacturer abandon item A since our analysis
shows that he should produce no (zero) items A and five items-B each week.
His income will then be maximum at $55.
This simple example, possible for us to do with the mathematical tools
we have at hand, has given us a beginning notion of the extremely important
applications of linear programming.

EXERCISES

3.33. Maximize z= 10x + 7y under the conditions

8x + 5y < 40
[s—ay = 6
4x—9y =< 36

Recall that x = 0 and y = 0. Sketch the region R as discussed in


the text.

3.34 Find the maximum value of z= 42x + 17y + 16 under the condi-
tions x <7, 6y —5x < 30. Recall that x > 0 and y 2 0.

3.35 Given the set of restrictions

x—4y <8
Loy= 6
x—4y =—8
Ss 12

and alsox =0,y 20,

(a) minimize z=x+2y+7


(b) maximize z = 3x — 1ly

3.36 A manufacturer produces two items A and B. Let x be the num-


ber of items A produced each week and let y be the number of items
B produced each week. Suppose his profit is $25 for each item A
produced and $18 for each item B produced. To manufacture these
items, three resource materials C, D, and E are used. The manu-
facturer has available each week a maximum of 24 of material C,
20 of material D, and 27 of material D. To produce one item A

ALGEBRA: LINEAR FUNCTIONS 81


requires eight material items C and five items D. To produce one
item B requires six material items C, four items D, and nine items E.
Determine the number of items A and B he should produce each
week in order to maximize his profit. What is this maximum
profit?

3.8 FITTING DATA TO A LINE. SUMMATION

The final application of linear functions we shall present in this chapter is


curvefitting to a line. Suppose we are given a set of points, no matter how
many but more than two points. For example, the data set could be

Let us plot these points (1,2), (2,3), (3,5), (4,8), (6,9). Clearly the points
do not lie on a straight line. We do not know any function y = f(x) whose
graph contains all the points—at least any simple function. It might be pos-
sible, though, to find a straight line L which even if it cannot possibly pass
through all the points will pass “reasonably” close to the points. Such a line
can be sketched by “eyeballing” as we have done in Fig. 3.19. Notice that
this first approximation does not go through any of the points. We wonder
whether there might not be an analytic way to determine what might be called
the best-fitting line. There are many ways that people use to define what is
meant by best fitting. Perhaps the most often used notion is called the method
of least squares. It is used to fit data to many different kinds of curves, and

Fig. 3.19

82 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Y (x3, y3)

|
|
@(x4, Yq)

a+ bx2

(x1, ¥1)

X2

Fig. 3.20

we shall be using it again in a later chapter. For now we present the method
as it applies to fitting data to a straight line. Let us generalize the process so
that it will be necessary to use general symbols for the data, the x’s and the
corresponding y’s. Thus, the data will be represented by (x;,,y;), that is, by
(X1,Y1), (X22), (%3,Y3), - . - + (Xn-Yn), 1 points in all. On the graph in Fig.
3.20 we have shown some of these points.
We have also shown a line, whose properties are yet to be stated, which
we want to be the best-fitting line. Now we want the line to pass relatively
near if not go through the points, and it is this closeness that we must make
precise. Suppose we let the equation of the line be y=a+bx. The points
on the line which lie directly above (or below) the given data points have co-
ordinates (x,, 0 + bx,), (%5,.4-4- bx2),. = . ; (X,,a + bx,),; since the y coordi-
nate of the point corresponding to x; is clearly a + bx; using the equation of
the line. We look at the vertical deviations of the data points from the cor-
responding point on the line. This deviation is simply the difference in the y
coordinates of the two points. Thus, the first point deviates a+ bx,— yj, the
second point deviates a + bx, — yz, and the third point deviates yz — (a + bxs),
etc. Now we come to the central notion of the method of least squares. We
shall impose the condition that the sum of the squares of each deviation shall
be minimum. The best-fitting line is that line for which this sum is minimum.
It is from the squaring and minimum ideas that the method of least squares
takes its name. Thus we want the sum S, expressed in the equation

Sea (a te ye)
ger
te) (a bx)

to be as small as possible. In this expression for S, all the x; and y; are known,
being the data, so we must choose a and b in sucha way as to minimize S. Once

ALGEBRA: LINEAR FUNCTIONS 83


we have determined them, we insert a and b into y=a + bx and have the
equation of the best-fitting line. By use of processes of the differential cal-
culus, it can be shown that the a and b we want must satisfy the following set
of linear equations.
n

na+(3 x)b= Sy;


i=1
i=1
(3.7)
(S x at (> x?) b= (S x)
i=1 i=1 i=1

Before we can proceed, the notations used in Eq. (3.7) require some
explanation. Consider

xX;
o.i] mn

The symbol % is the (capital) Greek letter sigma, and in mathematics it stands
for sum. The x; are of course the one-dimensional array of the given x values
of the points of the data, that is, x,, X2, X3, X4, . . . , Xp. The notation

means that we are to sum the x; as i (called the index) runs through integers
from 1 to n, inclusive. Thus,

xX;
oHIl mt

simply means to add up the x’s of the data. That is,

Ayr Ag ge pe tee
ay
i=1

Similarly,

yt yt ety.
Sun yt

and

S rfa xi txt xe t nth oie


i=1

84 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


that is, the sum of the squares of each of the x’s of the data. Finally,

»y SU oak, ae Reis ae OS a Rea he


i=1

Before we turn back to our problem of fitting a line to data, a few more
remarks and examples on this summation notation in general might be appro-
priate. Consider

5
ney 3)
1

This means that we are to evaluate the function f(j) = 2j +.3 for jrunning from
1 to 5 and sum these values. Thus

oO

Dj 7 3) = 12) 5 3) + (202) 3) + (203) +31 + [2(4) +3] + (26) +3]


SS

= yar aR Dar Inbar hehe

Similarly,

Me g(k) = (2) + 9(3) + 9(4)


k 2

whatever g(k) is. Interestingly,

10
ete is 451 Oty Oe toa 9 4510
1
= 55

the sum of the first 10 integers (greater than 0). Finally, take note of this
example:

8
Nth UE ills Uhm Vt

= 35

Now that we know the meaning of the summation symbols used in


Eq. (3.7), we return to our line-fitting example. Let us compute the various
sums required by filling in the following table:

ALGEBRA: LINEAR FUNCTIONS 85


thee 1 2 1 2
Db 3 4 6
33 5 9 15
4 4 8 ie ey
5 © 9 36 54

yy) 5 Df iH ile

Using (3.7), we now have

{5a + 16b = 27
16a + 66b = 109

Multiplying the first equation through by 16 and the second through by —5,
we have

{ 80a + 256b = 432


—80a — 330b = —545

Adding, we arrive at —74b =—113, b=1*¥/74._ Then using the first equation
again, we have 5a = 27 — 16b = 27 — 16(12/74) = 27 — 113(¥/37) = 27 — 94/37 =
(999 — 904) /37 = %/s7. Thus, a = 1%/s7.
: eae 19% 413 :
The equation of the line is therefore y = 37° 74 x «We leave it to

you to check that none of the given points lies on this line. As a small check,
let us find the point on the line whose x coordinate is 4. Substituting x = 4
into the equation, we have y = 1%/s7 + 113(7/s7) = 24/37 = 6.62. Note that
the data call for y to be 8 when x = 4.
Some final remarks may be helpful here. If the given data are collinear
(that is, if they actually lie on a straight line), the method of least squares will
give that line as the best fitting. Note that a line can be fitted to any data, no
matter how many points it contains and no matter whether the points, when
plotted, even appear to be vaguely collinear. In the latter case, it seems evi-
dent that the choice of the straight line would be highly inappropriate. Some
other standard curve could undoubtedly be found which would fit the data
much better than a straight line. As mentioned before, in later chapters we
shall have more to say about the selection of other curves for fitting use and
how to determine them by the method of least squares.

86 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


EXERCISES

Bion Show that the three points (0,7), (1,15), and (3,31) lie on the line
y=7-+ 8x. Now use the method of least squares to determine the
best-fitting line for the given data.

3.38 Use the method of least squares to fit a line to the following data:

Jae
ple |"
Maedice
Shee) Plot the data points given in the following table:

| |

+ |-2 | 0 yeaa aia’


ae See ee ea ea ae
Use the method of least squares to determine the best-fitting line.
Plot the line on the same graph.

3.40 Fit the following to a straight line using the method of least squares:

2 eee ee
spe ycirioa| | 9 |fs
Recall the sum of squares called S in the text. Use the equation
of the line you have just found to compute the value of S (that is,
the minimum value that the sum of the squares of the deviations
will have).

3.41 The voltage V across a certain resistor is measured as the current


I through it is held constant and the resistance R is varied. The
data resulting are as follows (R is in ohms, V in volts):

20 |40 |60 |80 |100

| 9.82 |20.21 |29.42 |40.48 |49.72

Use the method of least squares to fit these data to the linear equa-
tion V=a+bR. Recall that I was held constant. Suppose I is
known to be /2 amp. Compare and discuss your resulting linear
equation with Ohm’s law, V = IR.

ALGEBRA: LINEAR FUNCTIONS 87


Introduction to Symbolic
Programming Languages, Fortran

4.1 INTRODUCTORY REMARKS

Every digital computer combines basic components called the input, storage,
arithmetic-logic, and output units. They are arranged as shown in Fig. 4.1.
In this chapter we shall not be concerned with the actual design of the
components that make up the computer; we shall, however, in Chap. 8 present
some basic notions that are involved in the design of the arithmetic-logic unit.
A brief description of the functions of these components would now be appro-
priate. As you might suspect, the input unit is a device by means of which
the computer receives the set of instructions it is to subsequently follow and
the data, if any, on which the instructions are to act. This information can
be fed in via (IBM) cards, from a disk, from a typewriter keyboard, or from a
magnetic or paper tape. Once the instructions are stored in the memory unit
of the computer, the command is given to start executing the instructions. If
all is well and the input has been presented in proper form for the computer
to understand, the execution proceeds. The execution can call for the reading
in (again by means of an input unit) of data, that is, the numerical values of
variables, on which the arithmetic-logic unit is to operate. Following the
stored instructions precisely, the control unit passes data and results back
and forth between the storage unit and the arithmetic-logic unit where arith-
metic calculations are done until all the instructions have been executed. The

89
STORAGE

OUTPUT:
INPUT: CARD
CARD DISK
KEYBOARD CONTROL PRINTER
DISK TAPE
TAPE TYPEWRITER

[anrtanenc-toote |

Fig. 4.1

set of instructions should contain the commands necessary to cause the com-
puter to select an output device and to put out the desired results on that device.
As noted above, the computer is an extremely intricate electronic device
so engineered and constructed that it will receive, store, and execute your in-
structions. These instructions must be written and presented to the computer
in a manner that it can understand. The only language it can actually under-
stand is called machine language. In this language the instructions are a spe-
cially coded sequence of (usually) binary digits, and the computer has been
constructed to react to these coded instructions in a certain very specific way.
Sooner or later if you progress far and deep enough into the design and use
of computers, you will have to learn how to write programs in either machine
language or a slightly more sophisticated version called assembly language.
Both of these languages are relatively difficult and tedious to write. To solve
problems in applied mathematics and for business and engineering applica-
tions, there are many so-called symbolic languages that are currently in use by
programmers. Among these are Fortran, Cobol, APL, PL1, and myriads of
others. All these higher-level languages have the following basic property
in common: their use allows the programmer to write his instructions in easy-
to-use English and ordinary mathematical words and symbols. This, of
course, relieves the programmer from the extremely painstaking work involved
when writing in machine language. In order that such symbolic languages
can be understood by the computer, it is absolutely necessary that the state-
ments of the program be converted into machine language so that the com-
puter can do its job. So, for each of the languages mentioned above, a special
program in machine language has been written by experts which converts
the statements of the symbolic language into machine language. This program
is called a compiler. Suppose a Cobol program, that is, a program written
using the Cobol language, has been written and punched in the proper way
onto cards. Now, the computer itself can previously have had stored on its
disk or in its core memory the Cobol compiler we have just mentioned, whose

90 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


sole task is to receive the statements of the Cobol program and translate and
store the resulting corresponding set of machine language instructions in
memory. This chore is usually done completely internally so that one never
sees the translation itself. The set of machine language instructions can then
be executed.
Each of the languages mentioned above has a compiler associated with it.
These compilers are different for different computers since each computer has
its own individual characteristics. In most computer centers several of the
most used compilers are permanently stored within the computer system so
that they can be immediately called up for duty when required. As an addi-
tional useful feature, many compilers also contain error-detecting routines
that can find certain errors that the programmer may make in the use of his
language—these routines usually cause an output listing of the errors they
detect.

4.2 INTRODUCTION TO FORTRAN PROGRAMMING

We shall not be able to discuss the details of programming in all these sym-
bolic languages, but we do want to introduce enough details of the basic
Fortran IV language so that you can write programs that can actually be run
on acomputer. In this presentation we cannot go into the important subject
of control cards, that set of special cards designed to give the computer such
information as the language in which the program is written, the number of
significant digits the computer should carry in its computations, whether a
printed copy of the program should be produced, and many other similar con-
trol situations. The format of control cards, which precede and/or follow the
program itself, is different for each computer even though the symbolic pro-
gram itself is written in exactly the same way for different computers. The
Fortran programs that we shall learn to write can be executed on any computer
that has available to it the proper Fortran compiler. The control cards re-
quired for the execution can be supplied by the computer center.
A Fortran program is a sequence of carefully written and ordered Fortran
statements. These statements are classed into five categories:

1. Arithmetic statements are used to define the calculations to be per-


formed. We shall study their proper formulation in the next section.
2. Input-output statements are used to transmit information between
the computer and its input or output units. We shall present the
basic notions of these statements in Sec. 4.4.
3. Control statements are used to govern the sequence of execution of
program statements. The most important of these statements will
be discussed in Sec. 4.5.

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 91


“By
Ty
WIOJ S144 WO) 5jUaWEjOYs BU;Yy>UNd s0y a/qO]!0A0 $1 4751 BBR O11D9/2 WA] ‘Wy PICD PJOPUDIS y,
64 08 L294Bf SL fL{ vd 2 IL 69 0 8 99 19 SP £9 $9 2% 09 19 65 LS BS 95 SS ¥S ES 2S OS IS sy Of 62 82 “2 9% SZ we E2 22 12 OF SI BI ZAI MI Si vl El Zi itl Ol 6 8B
T
BY Ly I Sh ve EP cy Oy Ib 6c AP Ge 9G SE ve fe ze Ie

cea
TTLrT
HH ttt Hf I
|

de

ie
i
ab
pied

a
-=

Zz
(nS
jr|oe
uo |<
a)>
=

x\|d
hiss
oo |
SY
aa 7 LI fet flail Gott - 4
| | 1} }+} +i JN N
t
ee | nae LTT Taltal [=| Giclees,
‘eae
fx x

loi=|"[i|-[x|*[*[s]-|z/«
-| [xi*|“[a) [+] [z[*[x|x/*|“[e] [=| [a
wlalxlel Tht (+! Iai |
lelwlelxialziael=) xi (all
|_t +
| ae Pt +

PE os ;
Sik
om ee

(C55 eaa
|
it

1
+.

il
S|)
) st

a"
jtiolelyl

julojsl
wiViain]

jalwiatyl

TE
[aldie

Ee]

Sie
DlFi
=>

=>
yn

HES

7
wD
eas

=
=
aa

INAWALVLS

c~@
>|
tu

ive)

ce
cc
a

a.

ei
wm
NVaLdOs

=
JON3INOIS

>

D
=

IN3W31V1S
o}

¥38WNN
IdILN3GI
NOVO

OBN EZ OL NSE PE TEL OZ eZ


6918929099! HOMER159) GINO9CON 6GNES ZG 9S MSG osu,iPS 05 Ts 6y 8) dy SF Sh Fh Ey ch lh OF 6€ Z4E BE 96 SE FE ce Ze le Of 6z 82 L2 9% Se FZ €@ 22 12 02 61 ZU/9l8l_ Sl Fl _€l_ Zl _ol_6it

—I
SNOILONYISNI CLO Yi ‘a4 sivo] dSIWWYe99d £o) J YN 44D WWE Oud
ONIKONNd
DIHdVYS GQHLIW S.NOLMIN WvsOud
Wal
uuog Burpo) NYYLYOI
econ GanTier ot
4. Specification statements are used to provide information about the
data that the program is to process. These statements are covered
in conjunction with input-output statements in Sec. 4.4.
5. Subprogram statements are used to define and provide linkage to
and from subprograms. We shall not discuss this type of statement
in this book.

As you can surmise, there are myriads of details and complications in


a full study of the basic Fortran IV language. It is our objective here to present
a version that is somewhat simplified but complete in itself. If you care to
pursue all the intricacies of the complete language, there are many good texts
available (including my book “Fortran IV Programming,” McGraw-Hill, New
York, 1970).
The set of statements constituting the program are written on specially
prepared Fortran coding sheets. Figure 4.2 shows such a sheet with a source
program written on it. You note the numbers across the sheet directly under
Fortran statement. The numbers correspond to column numbers on a standard
80-column IBM card. Clearly, the Fortran statement must be placed in columns
7 to 72, inclusive. All the alphabetic characters used are capital letters. Once
the program is written, one statement per line, on the sheet, it is then the chore
of someone, perhaps you, to reproduce each line of the program on IBM cards,
punching one line per card, in exactly the same way the statement is written
on the coding sheet. The deck of cards thus produced is called the source deck.
Throughout our discussion of input (of program and data) we shall presume
it is done with IBM cards.
Keep in mind that what is being punched on the IBM card is simply a
one-to-one reproduction of one line on the Fortran coding sheet. You are
thus preparing the source deck which will be read by the card reader. Obvi-
ously the computer cannot read a program written on a sheet of paper. All
IBM card readers are constructed to read only cards which have been punched
“full of holes” by a keypunch. These holes represent a code to the computer;
each letter, number, or special character that you “type” on the keypunch
keyboard causes a unique hole or set of holes in the corresponding column of
the card. Then, when the card is read, the very same letter, number, or spe-
cial character is interpreted by the card reader. Figure 4.3 shows a punched
IBM Fortran card that is in common use.
Let us return to the coding sheet and to the example shown in Fig. 4.2.
Notice that the first line contains a comment. You can disregard with com-
plete confidence this wholly nonessential feature of programming. However,
the heading above the first five columns, STATEMENT NUMBER, is important.
These columns may contain a statement number, which is an unsigned integer
from 1 to 99999. The statement number can occur anywhere in columns 1

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 93


i a gas : IRV ORD
Ll |ed eae ed| ese ares. :
<—ror
2
COMMENT |
ua L] iT FORTRAN STATEMENT s(DENTIFICATION

OORT! CHOOTAVOOOOOONDONSOOOVOTOTOTOOOOOTOTOOOCOSONOFTVOOCOTINDOOcL OCU soOoOrD $3 ED615269 GFCS BFG705 63707) 12)73 74 75 76 77 78 25 £0|
6 Ly 5 VG 5512.19 14-95 16 47 $8 19 2021 2229:24 ZS2B27 ZB29-9221 32-39 S435 3627 38-394 41 AZ AL44-454047 4B49 50St 52 53.54 Sr $657 52
‘ HOU DUNTUID AOA ATOM IDNA APT UO Ue TT ae ee Pet D tT Pe at

2i22.2.21022222222M22222222022220222222222222222222222222222222222222222222202020022
H i]
3
313.3.3-713:933333339339M033333303333399339339339393393393393393993393939939339333393

YOY PIRI YTN] | VEYEVEN) PETEUTUPEEEUCECOCU OIC COUCrererereverereercrcc CCC

SS
SISSSSSISSSSSSSSSSSSSSSSSSSSSMSMSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSIOSSSS5SSSSSSS
OSES
SeGENGGGSRSSGSESNGESSESSCESSSEGRSSEGEGSEGESSEGSOSSSESSSESSSESESSSSEECSSOEEES

PE DO
BS SESEEBS
GBH HGHIGHBB
gigce sie SGM GMM GMs oMoMccMceMsBssccasssssissaCGBBSHAEREHBBSBB
i !

919999 ig 999999999999999999N99995999999999999999999
112.34 516! 8 HNN IBIMIRBAMBHTIBAMIND
RBUSH 6m uBat as Age "
E 7 STANDARD FORM 823157

Fig. 4.3 A Punched IBM Fortran Card

through 5. Thus, 37 in columns 3 and 4 would serve to designate the state-


ment number 37. It is usually sufficient to use one or two digits for which
it is common practice to use column 5 or columns 4 and 5, respectively. Al-
though any statement may have an assigned statement number, in most cases
a statement is numbered only when it is necessary to refer to that statement
from some other part of the program. We shall soon see (Sec. 4.5) that a prin-
cipal use of statement numbers is to provide a reference for control statements.
In the example of Fig. 4.2 the control statement GO TO 17 contains the state-
ment number (17) of the next statement to be executed. Not every statement
need or even should be numbered. The actual number used as a statement
number has absolutely no numerical or arithmetical significance. The num-
bers are chosen arbitrarily by the programmer. No particular order of num-
bers is required. Successive statements can be numbered by such a sequence
of numbers as 5, 4576, 74, 12, and 3268. The sequence of operations in a pro-
gram is always dependent upon the order of the statements in the program, not
upon the value of the statement numbers. One should not, of course, use the
same statement number for two different statements.

4.3. FORTRAN ARITHMETIC STATEMENTS

In this section we shall present the proper formulation of arithmetic statements.


An arithmetic statement contains constants, variables, arithmetic operation
symbols, and an equal sign, and has the form of an equation. Let us discuss
each of these in order.
A constant is a specific number like 8, —1.73, and 7506.45. Constants
are of two kinds, real and integer. A real constant is a decimal number which
contains a decimal point. Examples are 0.6, —45.6, and 34.56. An integer con-

94 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


stant is a number that does not contain a decimal point, like 8, —17, and 432.
Note that the word “real” as used here does not have the same meaning as it
has in mathematics—here a real constant is a number which has a decimal
point in it. An integer constant like 13 can be changed into a real constant
by simply placing a decimal point after it.
As you recall from our discussion in Chap. 1, the number of digits that
these constants can contain is restricted in most computers. This number
varies in different versions of Fortran and from computer to computer. For
our purposes let us restrict the number of digits according to the following rule:
real constants, six figures; integer constants, four figures. This restriction is
compatible with current versions of Fortran.
For real numbers like 43800000000., recall the power-of-10 notation
4.38 X 10'°, which we write in Fortran in the form 4.38E+10. Similarly, we
write 0.837 X 10° as .837E—25. The exponents (like 10 and —25) are also
usually restricted in size. Let us again arbitrarily assume that they must be
between —30 and +30, inclusive. A general form for real numbers using the
E notation is then x.xxxE+xx, where x is a positive digit. Once again, here are
some examples of permissible real constants using this notation: —8.765E+00,
72.5689E+ 23,—.7042E—03. The largest number in absolute value we can write
is 1.E+30. Of course, as long as the real number does not require more than
six digits to express, we can use the ordinary decimal form for real numbers,
like 5.67 and —234.507.
Integer constants, to repeat, are numbers written without a decimal
point. Thus, 0, 456, —5069, and 35 are allowable integer constants; 45678 is
not permissible since it contains more than four digits.
For both kinds of constants, the plus sign preceding them is optional
if the number is positive. Of course, negative numbers are preceded by a
minus sign. Incidentally, commas are not permitted in any constant. Thus,
one never writes 45,600. in a Fortran statement.
As you have probably expected, just as there are two kinds of constants,
there are two kinds of variables called integer and real variables, so-called be-
cause the values that these variables take on are restricted to the corresponding
kind of number. It is important to the computer that it be able to differentiate
between these two kinds of variables because the mode of arithmetic it will
use to calculate expressions involving them is determined by the type of vari-
able the expression contains.
Variables are designated by names as is usual in mathematics. Thus,
X, Y, and Z (capitalized) are variable names. In Fortran, though, more com-
plicated multicharacter names are permitted. Thus, DIST, TIME, MASS,
M73X, and YY are also variable names. In each of these names the whole set
of alphabetic and numeric characters constitute the name. Note that in the
mathematical expression xy + 8, we mean that x and y are separate variables,

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 95


and xy means to multiply x and y. If we write the Fortran arithmetic expres-
sion XY + 8., the computer will assume that only one variable is used and that
variable has the name XY. Soon we shall see that the proper way to translate
the mathematical expression xy + 8 into Fortran in order to achieve its usual
mathematical meaning is to write X*Y + 8.. Here * stands for the operation
of multiplication.
Integer-variable names can contain from one to five alphabetic or nu-
meric characters, but the first character must be alphabetic and must be one
of the following letters: I, J, K, L, M, or N. No special characters such as
+—(),./* or blanks are allowed in the name of any variable. Thus, M73, IX,
J57Y, MM, MASS, and JBM as well as simple one-character names like LJ,K,L,M,
and N are allowable integer-variable names. 8Né4 is not allowed (its first
character is not alphabetic), J**B is not allowed (it contains the special char-
acter *), and KIPPERS is not allowed (it contains more than five characters).
A real-variable name may consist of from one to five alphabetic or nu-
meric characters, the first of which must be alphabetic and must not be I, J,
kK, L, M, or N., Thus, A, B, C, X,Y, XX, ZEST, 1347A, DSTIN, RATE, ALPHA;
and R4X5Y are allowable real-variable names. JERK is not permitted since
its initial letter is J; RX/BV is not permitted since it contains the special char-
acter /; and TY567AS is not permitted since it contains more than five characters.
Note that the computer is using the name merely to identify a certain
variable and itself attaches no meaning whatsoever tothe name. For example,
TIME is just the name of a real variable to the computer, and it does not know
that you are using the name TIME in your program to actually represent time.
A brief explanation of how the computer treats the variable names it reads in
a Fortran statement would be appropriate now. One of the major tasks of the
compiler is to note all the constants and variables you have written in your
Fortran statements. It causes the constants to be neatly stored. But the vari-
ables are designated by names, and they do not have values until the program
is executed. For this reason the compiler arranges to have separate and dis-
tinct areas of storage reserved for each variable you have named in your pro-
gram. For example, if you have the variable A in your program, the compiler
will reserve an area in storage which it will label A. Then as the values of A
are assigned or computed in the course of the execution of the program, they
will be stored in the area labeled A. At different times during the execution,
the storage area A may have different values of the variable but only one value
at any one time. We often say the value is stored at A, when we mean in the
storage area labeled A. Suppose that you have written the Fortran expres-
sion A+ 4.5 in your program. At the time this expression is evaluated, the
current value of A stored will be brought from storage to the arithmetic unit
and used to add to 4.5. What the computer then does with the sum we shall
soon learn.

96 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


We now turn to the arithmetic operations that are used in Fortran.
They are the usual five operations:

Addition, symbolized by +
Subtraction, symbolized by —
Multiplication, symbolized by *
Division, symbolized by /
Exponentiation (raising to a power), symbolized by **

We have already discussed in some detail in Sec. 3.1 the important sub-
jects of hierarchy of operations and the use of parentheses. They both apply
to Fortran expressions, so review that material if necessary. Arithmetic ex-
pressions are easy to write in Fortran; the only difference from mathematical
expressions is that multiplication must be denoted by the asterisk *, division
by the slash /, and exponentiation by the double asterisk **. The following
examples should be easy to follow:

Fortran expression Mathematical expression

AP B/C a -! +a

AS BIC DY) ac ss
eas
az
AY 2/3. + B a ie)
b 3
A> (B/Cj#3 (Nae ’)

a+b
(Ace By (ee) eT,

Art B*CtX ha anton


ee (Vie 3) m3

Note that in exponentiation the exponent may be real or integer, con-


stant or variable.
An expression is said to be real if all the variables and constants it con-
tains are real. Thus, X*Y + C**3./67. is a real expression. An expression is
said to be integer if all the variables and constants it contains are integer.
Thus, (M/N)**2 + 45/I is an integer expression. An expression that contains
both real and integer constants or variables is called a mixed expression. The
Fortran expression X/N + 56*Y is clearly of this type. All these three types
of expressions are allowed in Fortran. Only one circumstance offers any diffi-
culty, the case of the division of one integer constant or variable by another
integer constant or variable. An expression like M/N is calculated in what is

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 97


called integer mode, and the result of the calculation is always an integer. Sup-
pose M= 16 and N=3. The result of the calculation of M/N will be the in-
teger 5. The ordinary arithmetic answer of (approximately) 5.33 is truncated
by the removal of the fractional part 0.33. The result is the greatest integer
in 1%s. Another example: 14/8*6 will be calculated as 1 - 6 = 6, since 7s = 1
using integer arithmetic.
Here is an interesting example which makes explicit use of the property
of integer arithmetic concerning division. Suppose we want to determine
whether an integer M is divisible by an integer N, that is, N goes evenly into
M like 3 goes evenly into 24. We note that if M is not divisible by N, then
ordinary arithmetic will yield a remainder when M is divided by N. Thus, if
M is 17 and N is 6, the quotient would properly be written as 2 + °/6; /e is the
remainder. Now if the computer were to evaluate the Fortran expression 1%/e,
the result would be 2, and, as we have seen, the remainder would be lost.
The fact that a remainder has been lost can be substantiated by noting that the
“quotient” 2 multiplied by the divisor 6 does not equal the dividend 17. This
result also clearly indicates that 17 is not divisible by 6. In general, then, let
us call the result of the calculation I by writing I= M/N. We then compute
I*N. Clearly, M is divisible by N if I*N is M and it is not divisible by N if
I*N isnot M. For example, suppose M= 19,N=4. Then computing I= M/N
yields I= 4. Now I*N is 4X 4=16. Since 16 is not M, 19 is not divisible
by 4. We shall ask later that you write a complete Fortran program concern-
ing divisibility in which you can make use of the material of this paragraph.
The division operation of mixed variables will be done using ordinary real
arithmetic, and so no difficulty arises. For example, if X = 32. and N=5, the
expression X/N will be calculated as 6.4 as expected. Similarly, 48/10. = 4.8.
One can, of course, use the operation of exponentiation to calculate
roots. As you recall, radicals can be expressed using fractional exponents.
Thus, V5. = 5.12, +b
Wa = (a+ b)**, and so on. In Fortran one can write
Vx as X**.5. Be careful, though, about the peculiarity of integer division. For
example, one could write WX+ Y as (X + Y)**(1./3.) but not as (X + Y)**(1/3).
The last expression would be evaluated as 1., regardless of the values of X and
Y, since the exponent would be calculated using integer arithmetic and result
in the value 0. We shall not be able to go into the special subroutines called
the library functions that are built into the Fortran system except to mention,
for our immediate purposes, the SORT (square root) function. This library
function is used in the following way: SORT(X). The parentheses are manda-
tory, and the variable enclosed by the parentheses (the argument of the func-
tion) must be either a real constant or a real or mixed expression. It cannot
be an integer constant or variable. In any case, the expression SQRT(X) will
be evaluated automatically by the computer by taking the square root of what-
ever the current value of X is. Here are some further examples:

98 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Fortran expression Mathematical expression
Abi oOR PCB + GC) at Vb-Pe
(x24 ¥"2)"*(1./2.) Very
Xe LOAN YEE Bo) 27:
Wx Vyt8
a i

One final note concerning blanks before you try the next set of exercises.
As you have undoubtedly noticed in the source program of Fig. 4.2 and in
many of the example expressions we have written, use has been made of
(empty) spaces or blanks so as not to crowd the characters of the expressions
together and to provide more clarity and neatness. When the blanks in an
expression or statement you write on a Fortran coding sheet are transferred to
the corresponding IBM card, the card contains no character at all in that col-
umn; no punch appears on the card in the column corresponding to the blank.
Blanks in expressions and statements are ignored by the compiler so that, un-
less a statement is already too long, blank columns can be used to space it. For
instance, the statement X=A*B+C/D can be written X = A * B+ C/ D,
and the statement GO TO(12,13,14,15),M can be written GO TO (12, 13, 14,
15), M. One should not insert blanks in the middle of a number; one should
not write X = 8 3.0 when one means, algebraically, x = 83. And, of course,
one cannot have blanks in the name of a variable since the computer then con-
siders the blank to be a special character.

EXERCISES
4.1 Identify each of the following as a real or an integer constant. If
the constant is not acceptable (according to the criteria given in the
text), state why.

(a) —457
(b) 0
(c) 0.0034
(d) 328.8934
(e) 67.E+03
(£) —677308
(g) +87
(h) 3.E—89
4.2 Write each of the following real numbers in exponent form with
the decimal point just preceding the first significant nonzero digit.

(a) .0678E+04
(b) 876.1

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 99

THE ELMER E. RASMUSON LIBRARY


UNIVERSITY OF ALASKA
(c) 9.35E—06
(a) 0.0000000067845
(e) 5678.4E+12
(f) .000347E—08
4.3 In the following list identify the acceptable variable names as real
or integer. If the name is not acceptable in Fortran, state why.
(a) V
(b) LAMBDA
(c) SUM7
(d) *AB
(e) N45X
(f) TIME
(g) XNNN
(h) LAST
(i) FIRST
(j) SECOND
(K)RO7Y
(l) XXXXX
(m) X/UZ
(n) P5678
(0) 45.6

4.4 Write a Fortran expression for each of the following mathematical


expressions. Use the same variable names as those used in the
expression.

(a) re ics

5 (?—— 1)3 _7
(b) oy
(C)5a crt Bare)
(d) Vue + v4
la) fel
Nas araie

b
(f) a— Ak = 9%
ib (esr@ J
uel +k)
Bye (Qh)
(h) Vs
3470 7856
(i)
d* a 17r

100 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(j)n (a+)
m

(k) 14+x4+
224+ x3 + x!

4.5 Shown below are pairs of expressions, each of which consists of a


mathematical expression and what purports to be the corresponding
Fortran expression. Each contains at least one error. Point out
the errors and correct the Fortran expressions.

ais} (R/S) *K+7


(DOS ye estaba 83
Tesy/
=e X+71/Y—6
d+5)\4
(d) G3) (D +5.)/(D—3.)**4
(e) a(x+y) A*X
+ Y

() 4424 A/C + CD/A


(g) OE6
6./X*Y*Z
Vs

45,678 + p
(h) 5557—, (15.678. + P)/5,557.—Q

4.6 Determine the mode of the following expressions (real, integer, or


mixed):

(a) I+ 2/NXX
(b) X*Y + 34.5/P78
fa) 0s 9g SEO)
(d) 13+ (N+5)/X
(e) 456 — NNNN + NP/6
(f) X*3r— X"'2. + 5*BIG

We have finally arrived at the main objective of the section— the writing
of Fortran arithmetic statements. Every Fortran arithmetic statement has the
following form: variable = expression. The variable may be real or integer
(and, naturally, is not a constant or an expression), and the expression may be
a variable, a constant, or any properly formed Fortran arithmetic expression.
Thus, V= X*Y**4 and N= X+ M-—7.8 are correctly formed statements, but
4=X and C+ D=P**3 are not. Note that C + D cannot be the name of a
variable since it contains the special characters blank and +.
This is the way an arithmetic statement is executed. The expression

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 101


on the righthand side of the equal sign is evaluated using the mode of the ex-
pression itself—integer for an integer expression, real if the expression is real
or mixed. This evaluation takes place regardless of the mode of the variable
on the lefthand side of the equal sign. The result is changed in mode, if neces-
sary, to agree in mode with the variable on the left, and it is stored at that vari-
able’s storage location. Thus, the execution of an arithmetic statement changes
the value of only one variable, the one on the left of the equal sign. All the
variables in the righthand expression keep the same values they had. Thus,
for N= X + Y—5.0, we have the following: Add x to y, subtract 5.0, and store
the result at n. Since N is an integer variable, its values are integers, and an
integer must always be stored at N. Once the real expression X + Y — 5.0 has
been calculated in real mode, the decimal part of the number (together with
the decimal point) is removed, and the resulting integer is stored at N. Sup-
pose x were 8.47 and y were 6.63; the real result would have been 8.47 + 6.63
— 5.0 = 10.10, and 10 would be stored at N.
Similarly, when the statement X = N + 8 is executed, the integer result
of adding N to 8 is made real by the proper insertion of a decimal point, and
the corresponding real number will be stored at X.
A very simple way of initially assigning a value to a variable is to write
a statement like X =3.. When this statement is executed, the value 3. will be
stored at X. The value stored at X need not always remain 3. If, later in the
program, an arithmetic statement has X as its left-side variable, the new value
of X thus calculated will simply replace the old value of X. The old value of
X is now erased and is lost. Only one value of X may be stored at any one
time in the storage locations reserved for the values of the variable X. Con-
sider the following sequence of arithmetic statements:

A= 4.0
M=3
A=A+ 2*M

When these statements are executed, the value of A will be initially set at 4.0,
the value of M initially set at 3. The righthand side of the third statement
will now be executed: the current value of A (namely, 4.0) will be added to
2*M (which is 6) with the result 10.0. Then, since A is the variable on the left
side of the statement, the new value of 10.0 will be stored at A, erasing the
old value of 4.0. stored there by the first statement.
This last sequence of statements has made us realize that Fortran arith-
metic statements are not equations in the algebraic sense. Rather, they con-
tain what is to be calculated and where the result of the calculations is to be
stored. The algebraic equation n =n + 1 is not true for any n. But the For-
tran statement N = N + 1 is not only perfectly valid but turns out to be rather

102 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


useful. Let us analyze this statement. Suppose that a value of N is stored
previous to the execution of the statement. The expression N +1 is evalu-
ated, that is, 1 is added to N, and the result is stored at N. Clearly, the effect
is to advance the number stored at N by 1. The original value of N is lost.
The number stored at N can be thought of as a counter in many applications.
In a similar way, the statement SUM = SUM + X advances the value of SUM
by X.
Here are some examples of properly formed Fortran arithmetic state-
ments of the mathematical statements they represent.

a=5(r?+ 4rh) A = 5.*(R**3 + 4.*R*H)


i a’ +g ND Gee)
ip NiGea sy, a CXS 7.) Ss)
u=16a°+ VB U = 16.*ALPHA**2 + SORT(BETA)
68
ea ge aig W = 68./(4./X + 7./Y)

d= Vb? — 4ac D== (BY? — 47 AtC)F5

It should be clear to you now that all the numbers the computer uses
to calculate with are rational numbers. If you ask the computer to calculate
V31 by writing 31.**.5, the six-significant-figure rational approximation 5.56776
will be the best effort of the computer. As you recall from the discussion in
Chap. 1, even some rational numbers like 1./3. require infinitely many digits
to be represented exactly whether they are stored as decimal numbers or binary
numbers, and since only a finite number of these digits can be used to repre-
sent the number, calculated results will contain errors due to truncation. Ex-
actly the same kind of error due to truncation occurs in any computing device
because all computers have only a finite number of storage places to store the
digits of a number.
We have learned in this section how to properly write Fortran arith-
metic statements that will cause the calculations of the operations of addition,
subtraction, multiplication, division, and exponentiation to be performed when
a program containing them is executed. We have also seen the use of arith-
metic statements to assign values to variables. The prime way, however, of
assigning values to variables is to read in numerical data during the execution
of the program. In the following section we show how one prepares data
cards, and we present the input Fortran statements that will be required in
the program so that data cards can be read in at the appropriate time. We
shall then discuss the outputting of results. After the introduction of just a
few more essential Fortran statements, we shall finally employ all we have
learned to write complete Fortran programs.

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 103


EXERCISES
following
4.7 State the value of X or I stored as the result of each of the
arithmetic statements.

(a) X=2"6 +3
(b) I= 2740/6
(c) 1= 2/40*6
(d) X = 2*40/6 + 3
(e) X= 50/3
(f) X=2. +37/5
(g) X = 15/6 + 17/2
th) 1=3.7 + 8.7— 4/3

4.8 Write arithmetic statements to compute the following formulas.


Use Fortran coding sheets, if possible, to write the statements on.
Use the letters in the formulas for variable names.

(a) y= V2x +7
5x
Oe aa
(c) v = 3.141591?
(d) v =; (3.14159)
r2h

(e) q =7 (v7 + 3w®)

_ Gar V6
(f) ic ve
(g) r= V2 V2+5
mat aioe
ES ONT
@) a=5 (ee
—4)

4.4 FORTRAN INPUT-OUTPUT STATEMENTS. FORTRAN PROGRAMS

We have seen that variables can be assigned values by using arithmetic state-
ments in the program itself. Every time such a program is run, the same
values will be assigned to the same variables, and the results of the program

104 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


will inevitably be identical. Most programs are designed so that the values
of at least some of the variables they contain are different each time the pro-
gram is executed. Instead of writing a sequence of arithmetic statements like

A=47
X = 8.32
C= A*2 + X*3

one could write the input statement READ (2, 5) A, X followed by the state-
ment C= A**2 + X**3. A card containing the values of A and X would be
read by the card reader, and these values used to calculate C. Then, if this
sequence of statements is executed again, it is perfectly possible that the new
card will have different values of A and X punched on it. The card being
read which contains the values of A and X is called a data card. Notice that
the data cards are not part of the source program; they are read and entered
by the computer after the program itself has been written, punched, compiled,
and stored and is in the process of being executed.
In this section we shall learn how to prepare data cards, how to properly
write input READ statements and their associated FORMAT statements. We
shall also have to learn to write proper output statements in order to discover
the results of the calculations of the program; we shall describe various output
WRITE statements and their associated FORMAT statements. In this book
we shall be concerned only with the input and output of numerical data. A
full description of the Fortran IV language would include a presentation of
the input and output of alphanumeric data, that is, data that could contain
alphabetic and special characters as well as numeric characters. In keeping
with the fundamental character of our entire presentation, we shall restrict
even our discussion of input and output to basic essentials. We shall assume
throughout that the input device being used is the card reader and that the
output device is the printer.
The input statement has the form

READ (J, K) list

where J is a logical unit number (an integer constant or variable) indicating


which input device is being used, K is an integer constant which is the state-
ment number of the associated FORMAT statement (of which we shall have
much more to say presently), and list is the list of the variables whose values
are to be inputted. The comma between J and K is mandatory, and the dif-
ferent variable names in the list must be separated by commas, but no comma
is placed after the last variable in the list. The READ statement thus indi-
cates that input is to be instituted, tells what input device is to be used and

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 105


what the names of the variables whose values are to be read are, and refers
to a FORMAT statement which, as we shall see, specifies the type and length
of the numbers.
Let us consider J, the code which identifies the input device to be used.
Different computer systems use varying input devices and varying codes to
identify them. For our purposes we shall use 2 for J and assume that this
value for J identifies the card reader as the input device. Thus, the statement
READ (2, 56) N, X, Y, P indicates that the values of the variables N, X,
Y, and P are to be entered by means of a punched card read by the card reader.
The 56 refers to the FORMAT statement whose number is 56 and which con-
tains the necessary information about how these values are punched on
the card.
Let us now turn to the subject of the data card itself. Recall that a
standard IBM card contains 80 columns in which the values of the variables
are to be punched. Since the card is always read from left to right, the values
of the variables must be in the same order as the list of names so that the
proper value will be assigned to each variable. Except for this order, the
values may appear anywhere on the card. The FORMAT statement will tell
the type of numbers they are and where they are on the card. Here is an
example of a READ statement and its corresponding FORMAT statement.

INES (27-47, meeae te VV eT


47 “FORMAT (F6.2,. 14, E6.1, F10.4, 12, F12.4, 13)

Notice that within the parentheses of the FORMAT statement there are seven
specifications, one for each variable of the list. The commas which separate
the specifications are mandatory punctuation. Let us first explain the special
code letters F, E, and I which occur in this statement. F identifies a real
number written in ordinary decimal form; E identifies a real number written
with the exponential notation; I identifies an integer number. As you look
over the FORMAT statement, notice that each real variable of the list has either
an E or F specification and that each integer variable of the list has an I speci-
fication. This correspondence is required. The integral part of each number
that follows these code letters indicates the number of columns of the card the
corresponding punched number may occupy. Thus, the 6 in F6.2 shows that
the value of the variable P is contained in 6 columns of the card.. Four columns
are used for M, and so on across the card. Thus, the sequence 6, 4, 6, 10, 2,
12, 3 of these integral parts divides the card into consecutive sets of columns
each containing the value of the corresponding variable. The card could look
like the card of Fig. 4.4. The values of the variables appear on the card
in
this way: P in columns 1 to 6, M in columns 7 to 10, Z in columns 11
to 16, W

106 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


numBer |S
FORTRAN STATEMENT HDENTIFICATION
DODO CIOOCOOOOOMIGOOOTCOCHDONFDODHODONDHDGHOODODDON
LODO ODODNDNDCNKION00000D0000NGD|
12-3 4 SIG)7 & 9 1004 12 19 14 GS 6 17 12 19 2G28 ZZ BS BWIV I BWWI B33 HIS W IIS BW4 Al AZ AL 444S 4G4) $263:50 5!57 'S2SASt $657 S859 G0G616263 G4US Gb 67 G86970.71 22/79 14 75 76 7778 7980)

TERR! Ret POPP Reee Pees ee cece heehee heen

2222/21222222222222222222222022222222222222M2222222222222222222222222 222222222222
313339)39H39939399333339M0N9339933333N39N339339339939993393993999399399999999993993
OUUE ORUCEPECCUrereerel £1 COVERT ET) EP) PEER VERY OV EVE O reeVer yer erreryey) evr rer)
'
SISMSSSSSSMSSHSSSSSSSSSSSSHSSSSSSSSSSSSSSSSSSSSSSHSHSSSSSSSSSSSSSSSSSSS SSIS SSSSSD
|
BESCEMEGHSESSEE CES ESEGEEGCREGSEEOCEE GEESE EEGESEGSS FSFE SE EGB EEG EG BSB GECGEES

7777777777877777077777777777777877808977979777797777977979997297997979
77:94:
I
eHesceeMSceceeerMsesssessecsesoMessceees ees RHE RRR AB RHR B RES REHEARSE DABS

9999999999999999999995999999
WURIKSCIBINADDKSAIBVAMDHNNVHSEN
STANCARD FORM 883157

Fig. 4.4 A Data Card

in columns 17 to 26, J in columns 27 and 28, R in columns 29 to 40, and I in


columns 41 to 43.
Note that the value of M as punched in columns 7 to 10 must be right-
justified, that is, the last digit of M must appear in column 10. Suppose M
were 89; then

is correct. If the card were punched

with a blank (no punch at all) in column 10, the computer would automatically
assume a zero in column 10 and would read the value of M as 890. To avoid
such errors, it is best for all the numbers punched on the card to be right-justi-
fied so that the last digit of the number appears in the last column of the field
of columns assigned for that number. Thus, if Z were 8.32, we would have

(i
cell ccl6

In the case of F and E specifications, the digit following the decimal


point denotes how many decimal places the number is to contain. This part

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 107


of the specification is ignored if the decimal point is physically punched on
the card. It can be used, however, to place the decimal point if one is not
punched. In columns 1 to 6, for example, 125678 is punched. The specifi-
cation is F6.2, so when the card is read the value of 1256.78 will be assigned
to P. Similarly, in columns 11 to 16, 61E+07 is punched. Since the specifica-
tion is E6.1, the value 6.1E+07 will be assigned to the variable Z. In the case
of W, the specification is F10.4. The 4 in F10.4 will be ignored since the deci-
mal point is already punched in 17.345 and 17.345 will be assigned as the value
of W. The following values will thus be assigned to the variables of the READ
statement’s list when the card is read: P = 1256.78, M= 315, Z= 6.1E+07,
W = 17.345, J = 42, R= —1347.47, and I= —72.
With reference to the preparation of data cards, two situations often
confront one. In the first case, one may be asked to write a general-purpose
program to solve a certain problem that will require the reading of data the
values of which one would not know in advance when writing the program.
In this circumstance one can write the FORMAT statements in an appropriate
manner which will surely accommodate the expected data, and whoever uses
the program must of course prepare his data cards to conform with the given
specifications. An example of this kind of program could be one to solve the
general quadratic equation ax” + bx + c=0 in which the data read in would
be the values of a, b, and c. In the second case, one may be writing a very
specific program with data on hand that one knows. One may then write the
FORMAT statements in any manner that is appropriate and then follow those
specifications as one prepares the data cards for immediate use.
There are many more facets and techniques of input that we shall not
consider here. Again we assume that if you desire to delve more deeply into
this subject, you consult a complete text on Fortran programming.
Now we turn to the problem of the output of the results of calculations
or other desired numerical items. Recall that we have selected the printer
as the output device. Again we shall present just the amount of fundamental
output material to enable us to achieve output in the simplest manner. The
Fortran output statement is the WRITE statement. It and its associated
FORMAT statement have the following form:

WRITE (M, N) list


N FORMAT (_ )

Here the word WRITE indicates that data are to be outputted, M is


the logical
code number of the output device (we shall use 3 to indicate
the printer), N
is the statement number of the associated FORMAT statement, and list
is the
list of variables whose values are to be outputted. The FORMAT
statement
prescribes the layout of the printed line. Here is an example.

108 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


WV RULER 3 a1 8)eX: Yy. IN
1GSPORMAT (1X,7F125,-30X,E 10.3, 15)

Here is a description of the functions of the various items that appear


within the parentheses of the FORMAT statement. We immediately recog-
nize the code letters F, E, and I that are clearly associated with the variables
X, Y, and N, respectively. In output, however, the digits that follow these
letters do not have the same significance as for input since they are evidently
trying to prescribe just how the printed line will look. In input the specifi-
cations in the FORMAT statement are completely determined by the manner
in which the data card is punched. In output the numbers to be printed are
in storage deep in the computer, and their values and magnitudes may be
completely unknown to you.
If you output a real number under the specification Fw.d, the number
will be outputted with d places to the right of the decimal point and will be
in the form of an ordinary decimal number. The w in Fw.d is the number of
printing positions that will be used to print the number. When using the F
specification to output a real number, one must be careful to allow enough
printing positions to accommodate the number. Suppose the number 79.56
is to be outputted. One could use the specification F6.2 because exactly six
printing positions will be required. The number (including the printing of
its decimal point) will require five positions, and one position will be used
for the sign of the number. The plus sign is not printed if the number is posi-
tive, but a printing position must be reserved for the sign. If the number is
negative, a minus will be printed. Any specification larger than F6.2, such
as F9.2, will clearly accommodate the number, and the printing under this
specification will cause three blank spaces before the printing of the number
itself. If you write F7.3, then three places to the right of the decimal point
will be printed, and the entire number will be printed as 79.560. Note that
w must now be at least 7; the zero on the end now requires an additional
printing space.
Many Fortran compilers will cause the printing of a set of asterisks in-
stead of the value of the number if the specification is not the proper size to
accommodate the number to be outputted. Suppose you desire to output
567.893 and you provide the specification F5.3. Clearly, the number cannot
be outputted in such a few numbers of printing positions. The computer
could cause the output to be *****, which would be disconcerting, to say the
least. As you have no doubt surmised by now, it is not always evident in
advance just what the size of the number to be outputted is going to be. This
asterisk type error is then liable to occur rather often. There is, however, a
way out which will never fail: using the E specification, which we now discuss.
The Ew.d specification as usual calls for w printing positions to be used

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 109


and for d decimal places to the right of the decimal point. In addition, it calls
for the number to be printed in exponential notation. The E specification
always causes the normalizing of numbers on output; that is, whatever the
number is, its decimal point is shifted to the immediate left of the first nonzero
significant digit of the number, and the power of 10 following the number is
adjusted to compensate for this shift. Suppose we have the number 874.56
stored. When this number is normalized, it becomes .87456E+03. Under
the specification E12.5, this number would be printed as 0.87456E+03. We
note that 12 printing positions are used. One is used for the sign (this will
be printed if the number is negative), two are used for 0. (this 0 is always
printed), five are used for the digits of the number, and four printing posi-
tions are used to print E+03. Now you recall that the maximum number of
digits a real number can contain is six. From the counting that we did in the
last example, it should be clear to you that in order to output a real number
of six digits the specification E13.6 is entirely sufficient. As noted before, a
specification like E17.6 will merely cause four spaces to appear before the
number itself. Thus, we shall follow the rule that unless we definitely know
just about what the real number is that we want to output, we shall use (at
least) the specification E13.6. If we know the number is about 13.45, we can
of course use an F specification like F7.2.
This last mention of the occurrence of spaces brings up an important
point. We would prefer that the various values of variables that appear in
a printed line have spaces between them. This horizontal spacing of numbers
across the line can be achieved by increasing the w of the specifications as we
have indicated above. A simpler way of spacing, however, is to use the speci-
fication wX. Here X is a code letter and w is the number of spaces desired.
Note the previous example:

WRITE (3, 18) X, Y, N


18 FORMAT (1X, F12.5, 30X, E10.3, I5)

Evidently, one space will occur in the printout just before the value of X is
printed, 30 spaces will occur between the printing of the values of X and of Y.
The printed line has a maximum number of printing positions, usually 120.
The FORMAT statement just given will cause the values of X, Y, and N to be
printed on one line.
The material presented so far concerning input and output is sufficient
for our immediate purposes. More willbe revealed in the chapter on arrays
and matrices.
We introduce just one more Fortran statement before we start writing
some complete programs. Some method must be found to signal the com-

110 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


piler that the end of the program has been reached, that it can stop reading
Fortran statements, and prepare to do its compiling and translating job. This
is done using the END statement: we simply write END. Every Fortran pro-
gram must have this statement as its last statement. Now for some sample
Fortran programs.

Example 4.1. Write a complete Fortran program to assign the value 6.789 to the
variable X, 7 to the variable M, —34.66 to the variable P, compute and output
the value of the variable Y if y= Vx? + p + (x—p)”.

Analysis: The plan of this program is direct and simple. We shall use arith-
metic statements to assign the values of the variables, write an arithmetic
statement to compute y, and follow it by an appropriate output statement to
print the value of y, as follows.

X = 6.789
M = 7
P = —34.66
2 a ORLOX oP) ae CP) eM
WRITE -G, 45) -Y
45 FORMAT (3X, E13.6)
END

It is characteristic of computer programs that the various statements of the


program are executed in order, that is, sequentially, unless somehow the order
is altered by some control statement. The program above is clearly sequen-
tial. The statement which calculates the value of y cannot be executed unless
the computer had been previously informed as to the values of x, p, and m.
This has luckily been done in the first three statements. Note that the FORMAT
statement contains the useful specification E13.6.

Example 4.2. Write a complete Fortran program to read a card containing the
values of the variables A, B, C, and D, compute x= a/(b +c) and y=d? +c?
+ 4x, and print the values of a, b, c, d, x, and y on one line.

Analysis: Since the FORMAT of the card must be known, let us assume that
someone has informed us that the value of A is punched in the first 10 col-
umns, the value of B in the next 12 columns, the value of D in the next 10
columns, and the value of C in the next 8 columns, and that each is in decimal
form with the decimal point punched. The program appears as follows.

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 111


READ |(27965) eAy RB, Dae
35 FORMAT (F10.0, F12.3, F10.1, F8.0)
X = A/(B + C)
Yous De 2 s+5 G3 a4 ex
WRITE SG? 563) <A; Ba Ca Dee. y
568 FORMAT (E15.6,E15.6,E15.6,E15.6,E15.6,E15.6)
END

The input format statement should be clear. The computer then knows
the values of a, b, c, and d when it comes to the third statement. It also knows
the value of x when it is asked to calculate the value of y. We have used E15.6
as the output specification for all the variables, since it allows for horizontal
spacing without the use of the X specification. It is possible, though not
necessary, to simplify this FORMAT statement by writing it this way: 568
FORMAT (6E15.6). The 6 preceding E15.6 merely indicates that the speci-
fication E15.6 is to be repeated six times. Notice that the entire program has
been written without the knowledge of the actual values of A, B, C, and D.
If desired, then, this program can be run over and over again with each run
using a different set of values for these variables, that is, with different data
cards.

Example 4.3. Write a complete Fortran program to solve the following set of
simultaneous linear equations:

‘eon
dx + ey =f

The values of a, b, c, d, e, and f are to be read on two cards, the first card con-
taining the values of a, b, and c punched in format 3F7.2, the second card con-
taining the values of d, e, and f punched in format 3F10.0. Print the values of
x and y on consecutive lines.

Analysis: We leave it to you to show that the value of x is (ce — bf)/(ae — bd)
and the value of y is given by (af—cd)/(ae— bd). We shall assume that
ae—bd #0. We first present the program and then give a discussion of
some of its interesting facets.

READ. (27 LA. beac


1 FORMAT (3F7.2)
READ A(2,02) 5D bee
2 FORMAT (3F10.0)
DENOM = A*E — B*D

112 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


X (C*E — B*F)/DENOM
Y = (A*F — C*D)/DENOM
WRITES. 3) X.
3 FORMAT (1X, E13.6)
WRIDET (yaa). Y¥
END

With the simplified version we are presenting, the two READ statements are
necessary since we are to read the data from two separate cards.

REA Doo LGA Bs C.D. Ry FE


1 FORMAT (3F7.2/3F10.0)

The above set of two statements can replace the first four original
statements. The slash (/) in the input FORMAT statement is a code to the
computer that the reading of the card is to end at that point and another card
is to be read for more data. In this context / does not mean division. The
use of this additional coding merely simplifies the writing of the input state-
ments for the program and we can get along without it.
Note that the expression ae — bd occurs in the denominators of both x
and y. It is good practice to compute this quantity separately once (here it
is called DENOM), rather than to compute it twice, once when x is calculated
and another time when y is calculated.
It is not clear why the two WRITE statements will cause X and Y to be
printed on consecutive lines. The 1X which appears in the FORMAT state-
ment numbered 3 is a special code to the printer that a new line of printing is
to be initiated. We shall continue to use this printer signal 1X as the first
item of the output FORMAT statements we write in order to ensure that print-
ing will always occur on new lines. The 1X code we use here may not be the
code for every computer or compiler.
Another way to write the set of two WRITE statements is as follows:

WRITES (753) ahyat.


3 FORMAT (1X, E13.6)

This set of statements will cause the printing of X and Y on separate lines.
First, X will be printed (on a new line because of the specification 1X). The
specifications are now all used up, and there appears to be no specification for
the variable Y. However, when this occurs, the FORMAT statement will be
again entered at the left parenthesis and the specification will be reread and
used for the variable Y. Evidently, the 1X will cause the printer to space verti-
cally so that the value of Y will be printed on a new line. If there were more

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 113


variables in the list, this process would be repeated for each of them. Perhaps
you are wondering whether such rereading of specifications could be used in
input too. It can. For example, consider

READ a2 ey mes rar Zak,


7 FORMAT (F10.0)

In this case, each time the FORMAT statement is reentered, a new card must
be read. Thus, this set of statements will cause the reading of four cards; each
of the cards should contain the value of the corresponding variable in the first
10 columns of the card, and each card is read under the specification F10.0.
In the program above the output FORMAT statement numbered 3 is
referred to by both the WRITE statements. This is perfectly legal. In addi-
tion, FORMAT statements need not necessarily follow the READ or WRITE
statement that refers to them. All the FORMAT statements of the program
may be placed in a set at the beginning of the program. We prefer the natural
order as used here.
Let us present the rewritten program above using the simplifications
just remarked on.

READ QO, PA, BAC DEE


1 FORMAT (3F7.2/3F10.0)
DENOM = A*E — B*D
X = (C*E — B*F)/DENOM
Y = (A*F — C*D)/DENOM
WRITE (3703) Xs
3 FORMAT (1X, E13.6)
END

Again, note that this program can be used to solve many sets of simul-
taneous linear equations. The first two cards read can be different on each
run of the program. At this point, however, the only way the program can
be rerun is to start again from the reading in of the source deck and proceeding
through compiling and execution each time. In the following section we shall
present control statements that can be inserted in this program and which will
cause the immediate rerunning, in essence, of the program. As you recall,
control statements can alter the usual order of execution of statements.

EXERCISES
4.9 Figure 4.5 shows a punched data card which is read using the
statement READ (2, 4) A, B, N, X, Y, M. What are the
values assigned to these variables if the corresponding FORMAT

114 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Comet
IsTaTEMENT |=
NUMBER E /DENTIFICATION
lev0¢)
Wy23456) 7274 757677 78 79e0
wi POPRORREROR! BORED bt DREGE! DPCP Cee CER eee eee eee c rece heehee nl Perrone

2222 20222220 2022222822022222222222222222222222222222222222222222222222\22222222


1
339338 M93333333333333033333033333033333333339333339333339333333333333993 593339393

aaa TORU RU RUCECE! POCO VeLECE! PUeee rere reer rv rrrUrerrrrVrOrrVUVreVrEll VrrrrEr|
vt

55555 SSSSMSSSSSMSSSSSSSSSSSSSSSSSSSSSSSSSSHSS SS SSS HSH 5S 5555555 555555585555 58S


'
6 E6E GSCMSEHSESSCSE SES SESESERSSEEE SEES ESCH ESSEC SS SSESFOESSSS ESSE SEG E EG SE SE EGOE

7770077777777777877977987777797979777779779979999777797977777999777797740
090720
\
cssshss sess SS SyPRSRSFHLHHHSSKRHBKHSHHKHSGHGHHRHGHGHHHBGHRHBHSHSHE
SB B8B BEBE
J9sgggggsggsgaggggaggsMMasagagggggssggggggggsggggagggagggS 99999999
7 8 8 WO4 1213 141516-9718192021Z2Zo24BE 77 BW79-WIH WH BSBI BW 4D4142-49444S46478 485ST 525)345556STS559 6051 D'S 731475787 78780
STANCARD FORM 889157

Fig. 4.5 A Data Card Called for in Exercise 4.9

statement is:

(a) 4 FORMAT (F5.2, E9.1, 13, F7.3, F6.5, 12)


(b) 4 FORMAT (F7.5, E7.1, 14, F5.2, F6.2, 13)
(c) 4 FORMAT (F4.0, E10.1, 13, F6.2, F6.4, 13)
(d) 4 FORMAT (F6.1, E8.5, 12, F7.2, F5.4, 14)

ZA0 Civen thes READ estatement READS (27.5) Ay Bb, GD Eyer,


G, H, under each of the following FORMAT statements tell how
many cards are to be read and which variables are to be on each
card:

(a) 5 FORMAT (8F10.0)


(b) 5 FORMAT (3E12.6, 3F10.0, 2F7.5)
(c) 5 FORMAT (F12.0)
(d) 5 FORMAT (2E13.6)
(e) 5 FORMAT (4F10.0/4E15.5)
(f) 5 FORMAT (2F10.0/4E13.6/F7.2, F5.1)

4.11 Write a complete Fortran program to assign the value 4.72 to the
variable X, —12.73 to the variable Y, 7 to M, and —5 to N, compute
Z=x + y"* and q= Vz + (x" + y")/17, print z and q on one line.

4.12 Write a complete Fortran program to read a card containing the


values of the variables A, B, C, D, and E. The card is punched
BE12.0-. Computes x=(Va ei ie d*, y= Be*, and
z= (4x+5y)/2. Print A and B on one line, GD randsEsonstie
second line, and X, Y, and Z on the third line.

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 115


4.13 Write a complete Fortran program to read two data cards. The
first card contains the values of X, P,Q, and N. X, P, and Q are
punched as decimal numbers with the decimal point punched.
X appears in columns 1 to 10, P in columns 11 to 15, and Q appears
in columns 16 to 25. N is punched in columns 26 to 29. The
second card contains the value of I punched I3. Compute a=
(x—4p+7q)/11, b= Wa" + pi, and c= a?/5+56p— Vab. Print
A, B, and C on one line.

4.14 Write a complete Fortran program to read three cards with the
values of A, B, and C, each punched F9.0. A, B, and C are all
positive numbers and represent the lengths of the sides of a tri-
angle. Compute the semiperimeter and area of the triangle using
the formulas S = (a+ b+ c)/2 and AREA = Vs(s—a)(s—b)(s—c).
Print A, B, and C on one line. Print S and AREA on the next line.

4.5 FORTRAN CONTROL STATEMENTS

Control statements in Fortran are those that will enable you to control the
course of the program. As you recall, statements are normally executed se-
quentially; after one statement is executed, the statement immediately follow-
ing it is executed. It is often more useful to alter the sequence of the state-
ments of the program, as we shall soon see. In this section we shall present
the two basic control statements (unconditional) GO TO and IF. There are
additional control statements in the expanded version of Fortran.
The GO TO statement provides a means of transferring control immedi-
ately to some other statement of the program. This is often immediate
branching. It is written in the form

GO TO n

where n is the statement number of the statement to which the control is to be


immediately transferred. This means that when the statement GO TO n is
executed, the next statement executed is the one numbered n. This will
happen whether the statement numbered n is before or after the GO TO
statement itself.
An obvious use of the GO TO statement is to return to the beginning
of a program so that the complete program can be executed again. The fol-
lowing example shows an important process in programming called looping.
Consider

116 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


7D BREAD, (235. eeX oY
235 FORMAT (2F10.0)
Z = X¥2 — 4*X/Y
WRITE (3, 17) Z
17 FORMAT (1X, E13.6)
GO TO 75
END

When executed, this program will first cause a card with the values of
X and Y to be read, the value of Z calculated and printed. Then control is
transferred by means of the statement GO TO 75 to the statement numbered
75. This means that the READ statement will be executed next, a new card
will be read, a new value of Z calculated and printed. Again control is trans-
ferred to the READ statement and the process will be repeated. Since now a
loop has been created, the process will be repeated over and over again as long
as there are cards supplied to be read. Note that the presence of the END
statement has no effect on the looping; it does not cause the program to end.
We shall return to this program once again to see how we can limit the number
of cards that will be read, if that is our plan.
In any case, the GO TO n statement alters the sequence of statement
execution unconditionally; the transfer of control is immediate and does not
depend at all on any values computed in the program. Then in the GO TO
n statement must be the statement number of some executable statement in
the program; if no statement is numbered n, the GO TO is rather pointless,
and its presence in the program reveals a certain degree of poor planning on
the part of the programmer. Note that it is not permissible to transfer control
to a nonexecutable statement like FORMAT or END.
Before we present some more examples of the use of GO TO and in-
troduce the IF statement, we consider the concept of the flowchart. A flow-
chart is a graphical presentation of the order of execution of the statements
of a program. It should be carefully drawn for each program in order to plan
the logical flow of the program before writing out the statements of the pro-
gram in detail. Figure 4.6 shows the graphical symbols we shall use to create
the flowchart. To illustrate the use of the flowchart, we diagram the last illus-
trative program in Fig. 4.7. Note the arrow indicating the return to read a new
card. Note also that the complete statements of the program itself are not
given in the diagram. The intricate details of the actual written program are
to be supplied by the programmer after he has planned the desired flow of
execution with a flowchart. You realize, of course, that we wrote the pro-
gram without the aid of a flowchart since it was so simple in its flow. Butin
even moderately complex problems the various interrelationships within the

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 117


ANY PROGRAM STEP (ARITHMETIC
STATEMENT, ETC.), BUT NOT
A DECISION-MAKING STEP

ee DECISION-MAKING STEP

INPUT-OUTPUT STEP

STOP

> ARROWS INDICATING


———_--— — THE DIRECTION OF FLOW
Fig. 4.6 Flowchart Symbols

program often become very difficult to keep clear without the use of some
visual scheme. In addition, appending the flowchart to a complex program is
a valuable aid in communicating to others the actual operation of the program-
ming. The flowchart is thus a part of the documentation of the program.
A CONTROL statement that involves decision making is the IF state-
ment. It has the form

IE (UR) Taky, te, is

Here E stands for any expression, and n,, n,, and n; are statement numbers
(and are thus unsigned integer constants). This is the way the statement
works.
Fig. 4.7 Flowchart

READ X, Y

COMPUTE
Z= Ko ax

WRITE Z

118 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


When the IF statement is executed, the current numerical value of the
expression is calculated. Then if this value is less than zero (that is, negative),
control is transferred immediately to the statement numbered n,; if the value
of the expression is zero, control is transferred to the statement numbered nj;
and if the value of the expression is greater than zero (that is, positive), control
is immediately transferred to the statement numbered n;. Thus, the IF state-
ment causes a decision to be made on where to transfer to, based on the current
value of E. As we shall see, when you write the IF statement in a program,
you should already have planned to cause the program to branch to various
places in the program for various purposes. The statements numbered ny,
nj, and nz must appear somewhere in the program, and they can be before or
after the IF statement itself. However, the numbers n,, nj, and nz need not
necessarily be distinct. The statement

IPS (0013, 13,014

is perfectly permissible. The three statement numbers must be listed, sepa-


rated by commas as shown. Some examples follow.

Example. Write an IF statement that will transfer control to statement number


73 if B2 —4AC < 0, to statement number 86 if B? = 4AC = 0, and to statement
number 412 if B®? — 4AC > 0.

Solon Ebr? ea Ac @)in/3 6OO LD.

Example. Write an IF statement that will transfer control to statement number


12 if X > Y and to statement 15 if X < Y. Note that X > Y means that X — Y
= 0 and
x = Yimeans
X— Y= 0!

Solutions Hanae anys) melee ome 1)

Example. Write an IF statement that will transfer control to statement number 7


if N = 9 and to statement number 18 if N < 9.

Solution: IF (N — 9) 18, 7, 7

Suppose that when the following IF statement is executed, U=4.,


V=8.,and W=6.:

TH GY ee VV) melo, 2

Since the expression has the value 4(8) — 7(6) =—10 <0, control will be
transferred to statement number 17.

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 119


EE<0 E>0

Fig. 4.8 IF Statement Block

Figure 4.8 shows a typical block diagram representation for an IF state-


ment. It contains the diamond symbol with one arrow indicating the flow
into the statement. Three output paths are shown indicating the flow to be
followed depending upon the value of the expression E. The arrow on the
right will be followed if the value of E is positive, etc.
We now present several illustrations of the use of the IF (and GO TO)
statements in programs; each program will be preceded by a flowchart.

Illustration: Write a complete Fortran program to read a card containing the


values of the variables A, B, C, and P, punched 4F8.0. If b — 5ac is negative,
compute g=7p?; if b —5ac is positive or zero, compute q=5p%. In either
case, print q.

Fig. 4.9

The Flowchart:

COMPUTE
COMPUTE q=7p*
q=5p*
The Program:
36 READ (2, 6) A, B, C, P
6 FORMAT (4F8.0)
[EAB = 5.%A2C)758,.8
70=7,*pt*3
GOTO9
8Q=5.*P**4
9 WRITE (3, 19) O
19 FORMAT (IX, E13.6)
END

120 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


A little reflection (and a perusal of the flowchart in Fig. 4.9) reveals the
importance of the GO TO 9 statement in this program. Suppose that in fact
b — Sac is negative. Then, following the direction of the IF statement, state-
ment 7 will be executed calculating the value of q as 7p?. Now suppose that the
statement GO TO 9 were not present. The next statement executed would be,
in sequential order, q=5p*. This value of q would replace the previously cal-
culated value, and this new value would then be printed. This is not what we
want. The GO TO 9 statement is placed after statement 7 in order to bypass
statement 8 and go directly to the printing of q calculated from 7p*. Note that
if b — 5ac is positive or zero, statement 8 calculates q as 5p*, and the sequential
order of statements immediately causes this value to be printed, just as planned.

Illustration: Write a complete Fortran program to read, one at a time, nine


cards each containing values of X, Y, Z, and N, punched 3F10.0, 13. After
reading the card, if n is greater than 2, compute s = (x + y + z)/3, print s, and
return to read another card; if n is less than 2, compute s= Vx? + y? + 2,
print s, and return to read another card; if n equals 2, do not compute anything,
just return to read another card. After the nine cards have been read, print
the number 40 and stop.
The use of a counter to keep track of the number of cards read is a fea-
ture of this program. We discuss this process. First, the value of the vari-
able I (the counter variable) is set equal to1. A card is read, and the value of
S is computed or not, depending on the value of N. Statement 3 then ad-
vances the counter by 1 sinceI+1=2. The next IF statement checks whether
I is more than 9. Since it is not, the IF statement transfers control to state-
ment 7. With I now 2, a second card is read. The same internal computing
process is again followed, and it is repeated over and over again. However,
each time through the value of the counter is checked. When I has advanced
to 9, the IF statement following statement 3 again transfers control to the READ
statement and the ninth card is read. When statement 3 is encountered again,
I is advancedto 10. Now the IF statement transfers control to statement 8
since 10 is greater than 9. And, after the printing of the number 40, the pro-
gram ends. This example is important to understand because it demonstrates
the programming techniques of initializing, incrementing, and testing the
value of a variable. Review Fig. 4.10 for your information.
The following final example again uses these techniques and introduces
a new Fortran statement, CONTINUE.

Illustration: Write a complete Fortran program to evaluate the polynomial


x3 + 3x2 — 7x + 10 for values of x from 1 to 5 in increments of 0.05, that is, for
x=1.00, 1.05,1.10,1.15,. . . ,4.95,5.00. Print each x and the correspond-
ing value of the polynomial. A look at Fig. 4.11 will help you.

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 121


The Flowchart:

Set
counter
at 1

READ X,Y, Z, N

COMPUTE
COMPUTE kia Vaan Zs
s=Veety2+z27| |S>~ 3

Advance
counter
by 1

Is
counter The Program:
>9? 1=1
7 READ (2, 1) X, Y, Z, N
1 FORMAT (3F 10.0, 13)
IE(NES2)2,354
ZS — SORT (X= 2 2 ee 2)
GOTO5
4S=(X+Y+2)/3.
5 WRITE (3, 6)S
6 FORMAT (1X, E13.6)
Si =e
IES 9)7eeee8
8J=40
WRITE (3, 9) J
9 FORMAT (1X, 14)
END
Fig. 4.10

122 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


The Flowchart:

COMPUTE
y= xe dE 3x? =
7x + 10

ADVANCE
x
by .05

The Program:
X= 1.0
2 NG KISS de oa 2 Xo 10;
WRITE (3, 1) X, Y
1 FORMAT (1X, F5.2, 4X, E13.6)
NE Xe5)) 2220s
3 CONTINUE
END
Fig. 4.11

CONTINUE is a dummy statement which does not cause anything to be com-


puted. It is used here in order to provide some place to which to transfer
control when x is greater than 5. Recall that we have stipulated that control
cannot be transferred to the END statement.

EXERCISES

For each of the following exercises construct a flowchart and write the pro-
gram itself on Fortran coding sheets.

4.15 Write a complete Fortran program to read a card containing the


values of the variables B and X (punched 2F10.0), compute y = bx?
and print y; read another card containing another set of values for
b and x, compute y = bx‘, and print y; read a third card, compute

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 123


and print y = bx®; continue in the same manner for 12 cards, finally
computing and printing y = bx** and printing y.

4.16 Write a complete Fortran program to solve the set of equations

fest ae
dx + ey =f

A deck of 15 cards each containing a, b, c, d, e, and f (punched


6F10.0) is provided. Compute and print x and y for each set of
constants. (Refer to Example 4.3.)

4.17 Write a complete Fortran program to read a card containing the


values of the variables A, B, C, and X (punched 4F6.0). If C >A
+ 3B, compute and print y = x°; if C= A+ 3B, compute and print
y =x‘; if C < A+ 3B, compute and print y=x°. In any case, re-
turn to read a new card with (new) values of the variables A, B,
C, and X.

4.18 Write a complete Fortran program to read a card with the numbers,
all positive, A, B, C, and D, punched 4F10.0. Determine and print
the value of the variable BIG if BIG is the largest of A, B, C, and D.

4.19 Write a complete Fortran program to read a card with the positive
numbers A, B, C, and D, punched 4F10.0, read another card with
the value of N, punched I[2. Let BIG be the largest of A, B, C, and
D and SMALL be the smallest of A, B,C, and D. If N = 0, deter-
mine and print BIG; if N # 0, determine and print SMALL.

4.20 Write a complete Fortran program to read three cards containing,


one per card, the values of XFST, DELX, XLST, each punched F8.3.
Compute z= (4 + x)"3 + 5.6x? for values of x from XFST to XLST
in increments of DELX. Print each x and the corresponding value
of z.

4.21 Write a complete Fortran program to read a card with the values
of N, R, and S, punched 14, 2F10.0. If m=1 andr <s, compute
z= 4r— 3s and print z; ifn = 1-andr = s, compute z = 3s — 4r and
print z; if n ~ 1, print the number 567.

4.22 Write a complete Fortran program to read a card with the value
of k >0 and A, C, and X (14, 3F10.0). If k=1, compute d=

124 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(a—c)?+ x? and print d; if k= 2, compute d= (a+ c? + x°)” and
print k and d; if k > 2, compute d= (a + c + x)?” and print k and d.
In any case, return to read a new card.

4.23 Write a complete Fortran program to read a card containing values


of M and N (punched 215) and determine whether M is divisible
by N. If M is divisible by N, print the number 5; if it is not, print
the number 7. Assume that M is greater than N.

INTRODUCTION TO SYMBOLIC PROGRAMMING LANGUAGES 125


Arrays, Matrices, Determinants

5.1 ONE-DIMENSIONAL ARRAYS

A set of singly subscripted variables like {x,, x, x3, x4, . . . , Xn} is called a
one-dimensional array. Each variable uses the common array name x and has
one integer subscript. In Fortran these subscripted variables are written X(1),
AZ ieAS) om 4) a XUN):
Recall the expression

which means that the variables x,, %., . . . , X, are to be added. Let us now
consider how we could find such a sum as part of a Fortran program. Sup-
pose that the numerical values of the 80 variables X(1), X(2), . . . , X(80) are
known to the computer and we want to calculate the sum of these 80 values.
Consider first the following set of instructions:

I=1
SUM = 0.
SUM = SUM + X(I)
initially. The third
The first two statements set the values of I and of SUM
SUM (now 0) is added
statement’s righthand side is now evaluated. Thus, to
Then this result is stored atSUM. Now
X(1), that is, X(1) since I is now 1.
the array X has thus
SUM contains the value of X(1). The first element of
been stored in SUM. Now suppose we extend the set of statements above to

I=1
SUM = 0.
16 SUM=SUM + X(I)
I=I+1
GO TO 16

say:
The first three statements are as before. Then the next two statements
Add 1 toI Now I= 2) and GOTO 16. Statement 16 says: Add to SUM [which
now contains X(1)] the value of X(I) [that is, X(2) since now I = 2]; store the
result in SUM. It is clear that now SUM has stored in it the sum of X(1) and
X(2). Then the process will be repeated; 1 will be added to I (now I= 3), GO
TO 16, etc. A nice loop has been set up. However, this process cannot be
permitted to go on indefinitely because X(80) is the last element of the array
which we desire to add on. This situation is easily taken care of by telling
the computer to stop repeating the process as soon as I becomes 81. We thus
extend the previous partial program to the following:

I=1
SUM = 0.
16 SUM=SUM+ X()
I=I+1
IF (I— 80) 16, 16, 18
18 WRITE (3, 19) SUM
19 FORMAT (1X, E13.6)

As you can see, when the IF statement tests the value of I and finds it is 81,
SUM will contain the sum of the 80 elements of the array X. The partial pro-
gram then calls for this value to be printed.
We have assumed throughout this last discussion that somehow the
80 values of the elements of the array had been stored and thus were known
to the computer. We now present a method to read in and store the elements
of a one-dimensional array. First, the computer must know, before it en-
counters arrays in the body of a program, the name and number of elements
of the arrays so that it can reserve in advance the storage positions required.
We inform the computer of this by using a DIMENSION statement. The
DIMENSION statement identifies the names of the arrays and indicates the

128 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


maximum number of elements of each array. It must occur in the program
before the subscripted variables whose dimensions it specifies appear in the
program. If a program contains subscripted variables, the DIMENSION
statement containing the required information is usually placed first in the
program. For one-dimensional arrays the DIMENSION statement has the
form shown in the following example:

DIMENSION X(80), ZUTZ(23), NN(6)

It specifies to the computer during compilation that three subscripted one-


dimensional variables are used later in the program, that the array X has at
most 80 elements, the array ZUTZ has at most 23 elements, and the array NN
has at most six elements. Note that arrays can have real or integer variable
names. Clearly, the array NN will have integer values for the elements of
the array. Note that the number of elements specified in each case must be
an actual constant, it cannot be a variable. Any number of arrays (within
reason) can be specified in a single DIMENSION statement.
We now present a complete Fortran program to read in the elements
of an 80-element array X, sum its elements, and output this sum. We know
that a little study on your part of the flowchart and program shown in Fig. 5.1
will enable you to write similar programs.

EXERCISES
5.1 Write a complete Fortran program to read and store the 30 elements
of the one-dimensional array X, punched one per card F10.0, 30
cards in all. Compute and print the sum of the squares of the
elements

5.2 Write a complete Fortran program to read in the 40 elements of the


one-dimensional array A, 40 cards, one element per card, punched
F6.0. Then read a card with the value of M. If M is less than 1 or
greater than 40, print the value of M. If 1 <M < 40, compute and
print the sum of the first M elements of the array.

5.3 Write a complete Fortran program to read in the 50 elements of two


one-dimensional arrays X and Y. The elements of the arrays are
punched one value of the X array and one value of the Y array per
card, 50 cards in all, (x,,y,) on the first card, (x,y) on the second
card, etc. Each element is punched F10.0. Compute and print

ARRAYS. MATRICES. DETERMINANTS 129


The Flowchart:

READ
X (1)

COMPUTE
SUM =
SUM + X(I)

INCREMENT
| by 1

The Program:
DIMENSION X(80)
SUM = 0.
1=0
PRINT SUM 10 READ (2, 12) X(1)
12 FORMAT (F10.0)
SUM = SUM + X(I)
=!+1
IF (1 — 80) 10, 10, 24
24 WRITE (3, 25) SUM
25 FORMAT (1X, E13.6)
END
Fig. 5.1

50
=> (yay)
7-1

5.4 Write a complete Fortran program to read 40 cards. The first 10


cards contain the 20 elements of the one-dimensional array A, two
elements per card, punched 2F10.0. The next 30 cards contain the
30 elements of the one-dimensional array B, punched one element
per card, F10.0. Compute

130 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Print x.

5.5 Write a complete Fortran program to read in the 24 elements of the


one-dimensional array D, punched one per card F7.0. Compute

24

<=> (d? + d;+5)


i=1

Print the elements of the array D, one per line, then print the value
Of:

5.6 Write a complete Fortran program to read in the 40 elements of the


one-dimensional array G, 10 cards each containing four elements,
punched 4F10.0. Compute

40 } 1/2
— (Ss3?)

i=1

Brings

5.2 MATRICES

5.2.1 Introduction. Definitions

The set of subscripted variables {x,,,, X21, X1,2, X2,9, X32, . . .} is called a two-
dimensional array; each variable uses the common array name x and two integer
subscripts. In Fortran, these variables are written X(1,1), X(2,1), X(1,2), X(2,2),
X(3,2), . . . . Variables with two subscripts are usually placed in geometric
rectangular arrangements called matrices. For example,

is a 4 X 3 matrix; it has four rows and three colunns. Note that the first sub-
script indicates the number of the row in which the element occurs, the second
subscript indicating the number of the column in which the element occurs.

ARRAYS. MATRICES. DETERMINANTS 131


In general, the m X n matrix A is the array

Ay, Ayo 41,3 Ayn


A 42,9 42,3 fon

Ama Am.2 Am.3 Amn

A matrix may be 1 X n and thus have 1 row and n columns; it is then called,
appropriately enough, a row matrix. Similarly, an n X 1 matrix has n rows
and 1 column and is called a column matrix. A matrix is square if m =n, that

is, if it has the same number of rows as columns. Thus, 5 fl 15 ae x.

(square) matrix. The set of elements of a square matrix which lie along the
diagonal extending from the upper left element to the lower right element is
called the principal diagonal of the matrix. The elements 3, 4,5 of the matrix

St Be ae
: 4 j
an” ee

constitute its principal diagonal. A square matrix with all its elements below
the principal diagonal equal to zero is called upper triangular. Thus, the
matrix

Stee nO
OR 2a 3 aah
OO) 4b ile
0 @ OO 8

is upper triangular. Similarly, a matrix with all its elements above the prin-
cipal diagonal equal to zero is called lower triangular. A matrix which is
both lower and upper triangular is called a diagonal matrix. For example,

x0 0
Oo aA wo ©
? 0 @ ©
oY © @ =7

is diagonal. Finally, a diagonal matrix in which all the elements along


the
principal diagonal are 1s is called a unit matrix. Thus, the 3 x 3 unit matrix is

132 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


i ORO
Oo wt @
OROme

A matrix all of whose elements are equal to zero is called_a zero matrix.
Ore 0 ,
E 0 4 is the 2 X 3 zero matrix.

As you have noted above, we often give a matrix a single letter name,
usually the common variable name, like A. We also write A = [a;,,;| for short-
hand. We write equations concerning matrices at two levels. On one level
is a matrix equation in which each letter represents a matrix and the operation
symbols are matrix operations, such as A+ 3B=CXD. On the other level
we can write a numerical equation involving the elements of the matrices, as
Ci;= b;7 + 6, where c;,; and b;,; represent elements of the matrices C and B,
respectively. For example, as we shall soon see in detail, when one is asked
to multiply the matrices A and B, that is, find A x B, the actual calculations
consist of ordinary arithmetic operations on the elements of the matrices A
and B.

5.2.2 Algebra of Matrices

Two matrices are equal if they are identical, that is, if they have the same num-
ber of rows and the same number of columns and if each element of one is
equal numerically to the corresponding element of the other.
We shall first define the operations of addition and subtraction of two
matrices. We write C= A+B, and the elements of C are defined by c=
a;,;+b;;. In order that two matrices may be added or subtracted, they must
have the same number of rows and the same number of columns. The sum
matrix C then has for its elements simply the sum (or difference) of the cor-
responding elements of A and B. Obviously, the order of C will be the same
as the common order of A and B. Here are some examples. Suppose

Jo aa A
A=[} —5 “4

and

B=|) 4 5
Ae =

Then

De I ANE)
c=a+B=|) 0 |

ARRAYS. MATRICES. DETERMINANTS 133


and

=a-B=| 2 -1 ge
De ~ |-1 —10 9

Clearly, the operation of matrix addition is commutative, that is, A + B=B + A;


the order of adding is immaterial. Next, we define the scalar multiple of a
matrix. If @ is a number, then by aX we mean the matrix Y such that yj;,; = 4%;,;.
Each element of X is simply multiplied by the number a. Thus, if

20)
5X = c 5
ORS

We can now form linear combinations of matrices, like A —3B-+ 4C, pre-
suming, of course, that A, B, and C are all of the same size.
The operation of matrix multiplication is rather peculiar and at first
glance seems involved. If C is the product of two matrices A and B, we write
C=AXB. We first point out that a certain kind of compatibility must be
satisfied by the matrices A and B if they are to be multiplied. The number
of columns of A must be the same as the number of rows of B. Thus, if A is
an i X j matrix, then B must be aj X k matrix. The product matrix C will then
be ani Xk matrix. Thus, if A is 3 X 5 and B is 5 X 7, then C will be 3 X 7.
Two matrices which do not satisfy this criterion cannot be multiplied.
The operation of matrix multiplication is not commutative. In general,
A XB is not equal to BX A. One must therefore keep good track of the
order of the multiplication. In the product A xX B we often say that A pre-
multiplies B, or equivalently that B postmultiplies A.
Suppose we have the m X p matrix A and the p X n matrix B. The ele-
ments of the product matrix C= A X B are found in the following way: the
elements c;,; are computed by multiplying the elements of the ith row of A
by the elements of the jth column of B and adding these products. That is,

Pp

Cu > > GinD3


k=1

134 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


For instance, if A is 3 X 4 and B is 4 Xx 5, then

k
= A,1b1,3 + Aeobe,3 + 2,303.3 + Ar 4D43

Note, again, that cy; is found by summing the products of the elements of the
second row of A by the third column of B. Similarly, c,,; is found by summing
the products of the elements of the first row of A by the fifth column of B. It
is clear now why, to multiply the matrices A and B, the number of columns of
A must equal the number of rows of B. If this were not so, the required prod-
ucts of elements could not be found.

Example.
If

epee PR eh ge!
e=[0 4 2 mmel

3 il

then

GAeas
mg A AS al

eyed Alene
2 a
ee gs as nied
for 42963 + 10-8
my o2e 24
= & a

If the elements are simple numbers like these, one usually performs the prod-
ucts and sums in one’s head and simply enters the result in the proper position
in the product matrix. A two-finger method can be used. Run your left
index finger across the first row of A and at the same time run your right in-
dex finger down the first column of B, multiply corresponding elements, and
add as you go. The result will be the element c,,, in the product matrix C;
place it in the proper place in C. Then again run your fingers across the first
row of A and down the second column of B, multiply and add as you go. Place
this result in the position c,. in C. Continue in the same way across each
row of A and down each column of B, being sure to place the respective re-
sults in the proper place in C.
If A is a square matrix and U is the unit matrix of the same size as A,
then one can easily verify that AX U=UXA=A. That is, multiplying by

ARRAYS. MATRICES. DETERMINANTS 135


U leaves A unchanged, and, in addition, this multiplication is commutative.
In the previous example of multiplication of matrices, A was 2 X 3, B was
3 X 2, and the product C was, of course, 2 X 2. Clearly, the product B x A
is also possible in this case. Thus,

2S
Zao a
xX A=
exaz[oalx[ x 3
3 4
535580) 9102
= © 10 ‘
ie BY Be

Now B X A is 3 X 3, and clearly AX B# BX A.

E xample.le. 3 5 pe iit 4
Le Let A= E A , B B= E AY
; then A X B = 1 A while
1 B X A =

ee
1 |
7 Again,
gain, AXB#B x A.

EXERCISES

: 8) © =8)
a CG iven 1 — E 4,B=
B - |;

(a) find C=AX Band D=BXA:;


(b) find E=3A — 5B + 4U;
(c) if A2= A X A, B= BX B, find A?— B?:
(d) find (A+B) xX (A—B);
(e) find 5A?
+ 4AB + B?.

5.8 Given

B=[1 2-5 4}
ilps al
C=/4 1 1
0 6

Woondl
136 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS
GN
N NF
oF

find the products Dx CX A,AXB,BXE,ExDxC.

5.2.3 Solution of Simultaneous Linear Equations

We return once again to the problem of solving sets of simultaneous linear


equations and present some ways in which matrices and matrix methods can
be used. Suppose we have the set of equations:

eae ieON tee OO eae —


X4 SS Gaya Jag P47
(5.1)
Oe Se Gey CES =—3
Ae ee cin Ota tka OO

The matrix

= 2) 371
FeTOR ANIwoes
a te Ue
Merle sees I

of the coefficients of the four variables is called the coefficient matrix. Now
consider this matrix equation:

Smee =A! Xs 7
i 1 Te ais Ti By
x =
ae eee A 0 ks =3} ne
Aya 8 1 58" 38

The matrix equation (5.2) is equivalent to the original set of equations (Ss)
To see this, we multiply the left-side matrices. The product is the column
matrix

She ae Jab ake Bin


X4 ae Bese Hae,
2x4 Xo 4X3
Abe ae) Gey ae Cheese oe

ARRAYS. MATRICES. DETERMINANTS 137


Since this matrix is equal to the column matrix

I
Pf

their corresponding elements must be equal. If you write all this down, you
will clearly have just the original set of linear equations (5.1). Now since
the matrix equation (5.2) is equivalent to the set of equations (5.1), we wonder
whether we can solve the set of equations written in the matrix form (5.2)
using only matrix methods. Let us generalize (5.2) to the following form:

AX (5.3)
where A is the coefficient matrix, X is the column matrix of unknowns whose
values we are to find in order to solve the set of equations, and B is the column
matrix of the righthand members of the equations.
Suppose we could find a matrix, say C, which would have the remark-
able property that C x A=U, where U is a unit matrix. We could then pre-
multiply each side of Eq. (5.3) by C and get

C(AX) = CB

Then (CA)X = CB (since matrix multiplication is associative), UX = CB (since


CA = U), and X = CB (since UX = X, as you recall). Thus, according to the
matrix equation X = CB, CB is the column matrix whose elements are pre-
cisely the same as those in the corresponding positions in X. By equating
these corresponding elements, we shall then have solved for x,, %2, . . . , Xp.
This matrix method looks very promising. The difficulty involved here,
though, is that we must first find this peculiar matrix. The matrix C (if it ex-
ists) is called the inverse of A. If is, of course, unique. To indicate its defining
property with reference to A, we usually write it as A~! (which we read “A in-
verse’). Thus, A"'X A=U. It turns out also that AX A7!'=U. Unfortu-
nately, it turns out that for even relatively small matrices like 4 X 4 it is rather
difficult to find the inverse. We can, by turning the tables and solving simulta-
neous equations by the ordinary algebraic method, easily find the inverse of a

2x 2matrix. Suppose that we have the matrix b


A = E d |a,b,c,andd known.
c
Let its inverse A~! be E {| e, f, g, and h unknown and to be found. Then,
h
since A X A“! must equal U, we have

138 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


a b Comey ae bo.
[ | « k 1]_ |, |

Multiplying, we have

bee Hee | |
ce+dg cf+dh} [0 1

This leads to the four simultaneous equations

ae+bg=1
af +bh=0
ce +dg=0 (5.4)
cf +dh=1

Solving the second equation for f, we have f=—bh/a. Substituting this for
f in the fourth equation, we have (—bc/a)h + dh = 1, or h(d— bc/a) = 1 and

eet
h
~ d—bcela
ae a

~ ad—be

We also have f =—bh/a =—b/(ad— bc). Again, solving the third equation
for e, we have e =—dg/c. Substituting into the first equation, we have

ad ad 1 mh c me ==
ei st g(b-“)=1 ea ~ be-ad ad—be
c

And, since e = —dg/c,e=d/(ad—bc). Thus,

d =D
a UC Od pC eee 1 dab
SE a ere mie a
il (Xe (= lee

A comparison of A’ and A reveals the following little rule: A~’ is found


by interchanging a and d, changing the signs of b and c, and dividing by the
quantity ad — be.
Clearly, ad — be cannot equal zero. A will not have an inverse (and
4 8
will be called singular) if ad—bc=0. The matrix | does not have an
1
inverse.

ARRAYS. MATRICES. DETERMINANTS 139


Example. If

3 4
= = |
then

ie Lo7
ee 4
s 29 be |
mi be i, al
~ 29/29

You can easily verify that

i
<Am
AXA = 5 4

Example. Solve

{ ox + 4y=) 7
—2x + 7y = 12

using matrix methods. We have

ie 7|A a ka
Thus,

Therefore, x = 29 and y = *%29.

5.2.4 Elementary Row Operations. Inverses

Unfortunately, the little rule above for inverting 2 X 2 matrices cannot be


easily extended to cover the cases of matrices of larger size, and so we now pre-

140 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


sent an entirely different matrix technique which experts in numerical analysis
use. This new method can solve simultaneous linear equations and produce
the inverse of the coefficient matrix at the same time. We must first introduce
new notions of elementary row operations on matrices and of equivalent
matrices.
The following operations on the rows of any matrix A result in a new
matrix which we say is equivalent to the matrix A: (1) Multiply each of the ele-
ments of any row by a fixed nonzero constant; (2) interchange any two rows;
(3) fix any row, then add a fixed multiple of each of its elements to the cor-
responding elements of any other row.
Clearly, any of these so-called elementary row operations on a matrix A
can result in a matrix B which is not equal to A. But the new matrix B is equiv-
alent to the original matrix A, in a sense which the following applications will
make clear. We can apply any of these operations successively on a matrix
and thus get a chain of equivalent matrices.

per siar tel 2 ae aa


eae VE a re ces oa eG

In the first step we have multiplied the first row by 3, and in the second we
have interchanged the two rows.

Example. Suppose we have the matrix

3 4 1
bare? ae
ALP PS oof

and we fix the second row, then add two times this row to row 1. We now
have

[s : |
1B ts

a 2 7

which is equivalent to

3.4 1
By 2 |
el was

ARRAYS. MATRICES. DETERMINANTS 147


Now we present several interesting and useful applications of equivalent
matrices. First, suppose a square matrix A has aninverse. By an adroit selec-
tion of a sequence of elementary row operations, it is possible to transform A
into a unit matrix which is equivalent to A. The fascinating fact we shall
make use of is that the very same sequence of elementary row operations that
transformed A into U will transform U into A~'. Here is how this is done in
actual practice. Suppose we have the 3 X 3 matrix

a-|s |
4 1 3

Sr Gl 5

We augment A into the 3 X 6 matrix

by appending on the right of A the 3 X 3 unit matrix. Then as you pick out
and apply the sequence of elementary row operations that will transform A
into U, instead of applying them only to A, you apply them to the entire row
of the augmented matrix. So, in effect, you are automatically applying ex-
actly the same sequence of elementary row operations to U. Thus, when
A—U,U—A‘™. That is, the 3 X 3 matrix on the right will be exactly the
inverse of A. We shall have an example of this in a moment.
Now suppose you have a set of linear equations like

ce z= 8
ariiar we 7
ee Ups ge 8,

to solve. If you were to go through the standard elimination process for


solving them, you would apply such steps as multiplying an equation through
by a fixed number, adding one equation to another, and possibly interchanging
any two equations. You realize that these steps are just like elementary row
operations applied to the entire equation in each case. One could reduce the
set of equations to the following set:

142 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


from which the solution is obvious. All this leads one to conclude that ex-
actly the same effect can be achieved using only the matrix of the coefficients
augmented by the righthand column of numbers and applying elementary
row operations until this augmented matrix has the form

i @ @ @
:0 \
O50 Lec

The solution of the set of simultaneous linear equations would then be x= a,


he rare
We are now going to present an extensive example which incorporates
both of these techniques. We shall solve a set of linear equations and at the
same time find the inverse of its coefficient matrix.

Example. Given the set

oe Yate 2 ae
2X ea Ieee 2 — el
x+4y—2z= 11

use the matrix method just described to solve the equations and at the same
time find the inverse of the coefficient matrix.

Solution: First form the (very) augmented matrix

1 1 1 | {1 0 0
E eal UA eA TRO
1 A =P iOO al

by appending to the coefficient matrix both the column matrix of the right-
hand sides of the equations and the 3 X 3 unit matrix. We now proceed to
apply a sequence of elementary row operations which will transform A into
the unit matrix U, but we apply each operation to the entire row at each step.

Step 1 Fix row 1. Multiply it through by —2 and add to row 2:

Ds 219]
0-3. =1.—> 5 —2,-1 0
ju e
ee ee ee Oo 00iL

ARRAYS. MATRICES. DETERMINANTS 143


Step 2 Fix row 1. Multiply through by —1 and add to row 3:

1 1 1 2 i @ @
|:= =) =) —27 I wv
0 2 =) =i © il

Step 3 Multiply row 2 through by = Yee

‘ee ee | 0 O
|:i Ya Fe 4% =We ©
Yo = 2 =i © il

Step 4 Fix row 2. Multiply through by —3 and add to row 3:

Ge Se Bal 0 O
|:1 Ys Fs Y%3 —YV3 j
0 @ =f 4 =3 7 il

Step 5 Multiply row 3 through by —¥/a:

i a fl D 1 0 0
|:il Ye % 4 =Ye |
0 @ f@ =i So =. =e

Step 6 Fix row 2. Multiply through by —1 and add to row 1:

|: 0 4% %Ys Ys Ee)
Od 8h Js Fe =p 0
0 © t S Y Ya —Yal

Step 7 Fix row 3. Multiply through by —¥s and add to row 2:

DO ae saree ce Ld
fi 0 2 ie Ya Vie
Oa Oe Le ees ae

Step 8 Fix row 3. Multiply through by —?/s and add to row 1:

i © @ | 1 |—"/6 Wo Ve
f ile) | 2 | S/o Wa |
O01 Seas

144 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


A has now been transformed into U. The fourth column is thus the column
of unknowns. So, x=1, y=2,z=—1. The last three columns are the in-
verse of A. Thus,

—V¢ Vy Ve
t=] S12 —Wq a
Ya —Ye —Ya

Hil tet. 2
rd) ogee 1
23 so,

A quick check on your part will reveal that A X A“ is in fact U, and so what
we are calling A“ here is truly the inverse of A.
You should study this example and take note of the systematic way the
matrix A is transformed into U. This method can easily be applied to any
number of equations, but as the number gets larger, the manual work, though
arithmetically simple, becomes almost tedious even when the numbers in the
original matrix are simple integers. If the coefficients are rational numbers
in decimal form with a large number of significant figures, then one could
not hope to do the operations manually. Obviously, one would seek the help
of the computer. We hope that in your later work in computer programming
you will be able to write a Fortran program with ease which will solve any
reasonable number of simultaneous linear equations using the method of ele-
mentary row operations and which will also invert a matrix of not too unreason-
able size.

EXERCISES
5.9 Write the following set of simultaneous linear equations in the
matrix form AX=B. Use the method of matrix inverse to solve
this matrix equation for X and thus solve the set of equations:

ee 7
Dieta
i NS

5.10 Use the matrix method of elementary row operations to transform


the matrix

ARRAYS. MATRICES. DETERMINANTS 145


into

2 Jan O
F 3a00
0 0 4

5.11 Augment the matrix

ie eee 2,
a-| ik i
Aw 2F 2.

to

ee oe ee Lee)
eg eee a
Ame 2/2 Ses One

Then use the method of elementary row operations described in


the text to find A“.

5.12 Solve the following set of simultaneous linear equations using


the method of matrix inverse:

hie ea ee 7/
[2 y + 5z= 16
4x+2y+2z=11

Hint: Make use of the matrix A™! of Exercise 5.11.

5.13 Use the matrix method of elementary row operations described in


the text to solve the following sets of simultaneous linear equations:

par Pais Fa Iki


| Lie Vie Zi)
2x 2Y OZ — 7,
2Y + 7Z=12
»|x wos — so
GeiOy) = 8
x+2y+3z+4w=30
Se i eee iS
(c) Vitae gG— ci
2x +22 3 = —)

146 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Hint: In (a) form the augmented matrix

i 2 ih att
Py Sl ell
2 Ps 5 i

and transform it by means of elementary row operations into the


equivalent matrix

i .©@ © «
O) Gk 0) fe
OO Flere

5.3. DETERMINANTS

Associated with any square matrix A is anumber called its determinant. (Non-
square matrices do not have determinants.) We abbreviate this number
det A. We shall soon give some rules for finding this number and then by
means of some applications try to present some notions as to the reasons for
these rules. The determinant associated with a matrix A is the square array
of the very same elements of the matrix except that the square brackets hold-
ing the matrix elements together are changed to straight bars on each side.
: Ay 4 7
For example, the 2 X 2 matrix A= E 5 has determinant det A= 3 5

Note: Determinants can also be thought of as existing completely inde-


pendently of matrices. If you have encountered determinants before, this is
probably the context in which you studied their properties. In any case, asso-
ciated with each determinant is a number called its value. Matrices, of course,
do not have value. They are strictly structural entities.
It is very easy to evaluate 2x2 determinants. We follow this
rule: Find the product of the elements along the principal diagonal and sub-
tract the product of the elements along the other diagonal. For example,
4 7
det A= E |= 4(5) —7(3) = 20 —21=~—1. Here are some more examples:

ela, ee bz Cra ee ee ae
ie Bie 15 + 28 = 13 and i 3 O58 8.
Evaluation of 3 X 3 determinants can be done by a slightly fancier rule.
Suppose the determinant is

i lo
dae
Crain d

ARRAYS. MATRICES. DETERMINANTS 147


Its value is given by aei + bfg + cdh — (ceg + afh + bdi). Since this form is
not easy to remember, the following mechanical procedure achieves the same
result. Form an “augmented” array by copying the first two columns and
placing them on the right of the original array. Find the product of the ele-
ments on all the three-element diagonals from upper left to lower right. Sum
these products. Now form the products of the elements of the diagonals from
upper right to lower left. Sum these products. Now subtract the second sum
from the first sum. This process is easier than it sounds. Suppose we have
the determinant

ey ab.
45 6
i 8)

The “augmented” array is

3 il ome
4 5 Go 4S
ih 2d SY A

The first sum is clearly 3(5)(—3) + (1) (6) (1) + (2) (4) (2) =—45+6+16=
—23. The second sum is (2)(5)(1) + (3)(6)(2) + (1) (4) (—3) = 10 + 36
—12=34. The value of the determinant is thus —23 — 34 =—57.
Before we turn to higher-order determinants, let us present an intro-
duction into the reason for these peculiar methods for evaluating 2 X 2 and
3 X 3 determinants. Consider the set of simultaneous linear equations:

ea ae
dx + ey =f

Let us solve by the standard method of elimination. In order to eliminate y,


we multiply the first equation through by e, the second equation through by b:

earners a
bd x + be y = bf

Subtracting, we have (ae — bd)x = ce — bf. Thus

© 10
a)Rien gO
~ ge—bdla b
d e

148 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


In the last step we have made use of our previous definition of the value of a
2 xX 2 determinant. We note that x is the quotient of two determinants, both
of which are easy to write (and to evaluate). The denominator is simply the
determinant of the coefficients of x and y in the two equations in exactly the
same position as they occur in the equations. The numerator determinant is
found by replacing the column of x coefficients by the column of the righthand
numbers of the equations. By solving in a similar way, one can easily show
that

ac
_la_f
Lo. as
de

y has the same denominator determinant as for x. The numerator is found


by replacing the column of y coefficients in this determinant by the column of
righthand numbers of the equations. This method of solving simultaneous
linear equations by expressing each unknown as the ratio of two determinants
is called Cramer's rule.

Example. Solve

fe Oe
s+ 5t=17

using Cramer’s rule.

12 —7
Pires
oe ye,
_
hl
60 — (119)
~ 15— (-7)
_ 179
Ts
Sani?
i
F e
22
ot
a?
_39
>

ARRAYS. MATRICES. DETERMINANTS 149


Cramer’s rule can be extended to any number of simultaneous equations, pro-
vided, of course, that the method of evaluating the corresponding determi-
nants has been carefully selected so as to produce the correct results!

Example. Solve

x+ 3y+4z= 17
0a Ae eae)
YS 2.

17 3 4
3a 1
ro 2 1S]
1 3 4
2 il
0 ik eal
34 + 12 —6-— (16—-9+17)
2+4+0-—(-3+0+1)
40-24
~~ GID
_ 16
<8
=2
eo he
ih”
_lo -2 -1
z 8
__—3-—8-— (-17—2)
a 8
_-11+19
pele
=1
liye ee Abe
i peer
as:
8
_4+17—- (-64+3)
i 8
2143
= ere
3

150 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


A derivation like the one we went through for the general case of two simul-
taneous linear equations would reveal that our rule for evaluating third-order
determinants was, to say the least, fortunate. The results of the last example
can be checked by substituting into the original equations.

We note in passing that Cramer’s rule will be in some trouble if the de-
nominator determinant has value zero. In fact, if this determinant is zero and
any of the numerator determinants is not zero, the set of equations has no
solution. On the other hand, if the denominator determinant is zero and all
the numerator determinants are also zero, the set of equations has infinitely
many solutions.
Unfortunately, these simply mechanical rules for evaluating second-
and third-order determinants do not extend to higher orders. In numerical
analysis determinants of higher order are not evaluated by any extension of
mechanical rules, but interestingly enough their values can be found as by-
products of the elementary row operation techniques we presented in the last
section. Cramer’s rule is very seldom used in numerical analysis. Sets of
many simultaneous linear equations are solved by the process of elimination,
iteration, or by the matrix methods using elementary row (or column) opera-
tions! Cramer’s rule is often used by people who have only two or three
simultaneous equations to solve.

EXERCISES

5.14 Evaluate the following determinants:

eee
(a) |4 5 6
WH ws &
ie pee wee
(b) |2 3 4
De Se

ARRAYS. MATRICES. DETERMINANTS 151


(d) »
5
1
(e) |3 =)
4 = il

5.16 For the following matrices, find det A:

3 —2 -6
(a) a-| iene d
=) ee?
45 6
a= 2 3
65 90.12

5.17 For the following matrices A and B, find det A, det B, det (A + B),
det (A X B), det A + det B, det A X det B:

wa-[f 3] [29
5.18 Use Cramer’s rule to solve the following:

3x + 5y = 56
Eaoeeraee,
6s + 5t = 23
(b) ee
Bee PAY) a eye ———
o fa Y= 26
5x + 7y + 4z= 23
r+4s—5t= 0
(d) [s+ t=—6
4r+3s+5t= 14

152 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


5.19 Use Cramer’s rule to show that

3x+ 5y= 7
o fem ae
has no solutions;

b
2X liso,
J

( eet aes

has infinitely many solutions. Give at least four explicit different


solutions.

5.20 If U is 2 X 2 or 3 X 3, show that det U=1. Show that det A is


the product of the diagonal elements if A is 2 X 2 or 3X3 andA
is diagonal.

5.21 Let A be any 2 X 2 matrix which has an inverse. Prove that

det At =
det A

DPM RSE

ope ee a
a-| 4 1 :
=, 22 1S

Find det A, det A”, and det Al.

ARRAYS. MATRICES. DETERMINANTS 153


Polynomial Functions

6.1 INTRODUCTORY REMARKS

We shall call f(x) a polynomial function of degree n if it has the form a,x”
+ Ayyx" 1+ + > + + a,x + a,x + dy, where n is a positive integer. In mathe-
matical analysis, the coefficients a; are real numbers. But, as you recall, in
numerical analysis all real numbers must be approximated by a rational number
in decimal form found by truncating the decimal form of the real number after
a suitable number of significant figures. Thus, in actual practice the coeffi-
cients in the polynomial function are decimal rational numbers approximating,

if necessary, the real coefficients. For example, the function V2x° +5 ae:

— 7.209x + 12.0 would have to be written as 1.414x3 + 0.3333x? — 7.209x + 12.00


if all the coefficients are to be expressed to four significant figures. Often-
times, of course, no approximations at all are required, as in x4 + 3x”—7. In
any case, however, 4, # 0.
In this chapter we shall be concerned with the analytic geometry of these
functions, that is, the graphing of such equations as y = x* + 7x — 3, the solu-
tion of polynomial equations, like finding the roots of the equation x* + 4x°
— 7x —3=0, the fitting of empirical data to polynomial functions, and an in-
troduction to the theory of equations. We shall also present some examples
of Fortran programs which are appropriate to solve problems that are not amen-
able to simple hand calculations. In order to achieve some of these objectives,
it is necessary that we first present the notion of complex numbers.

155
6.2 COMPLEX NUMBERS

The system of complex numbers is the result of a perfectly natural extension


of the system of real numbers. Complex numbers were “invented” so that
the roots of any polynomial equation could be found and appropriately dis-
played. A simple case is the equation x*+4=0. Clearly, there is no real
number whose square is —4. A new quantity i, called the imaginary unit, is
defined by the property i7=—1. This unit i is obviously not a real number.
Then the roots of x2 + 4 = 0 are x = +2i, since (2i)” = 4i? = —4 and also (—2i)? =
4i7 = —4,
The unit i is then combined with real numbers a and b to form the gen-
eral complex number a+ bi. For example, —3 + 4i and 2+ V7i are complex
numbers. The a in a+ bi is called the real part of a+ bi, and we sometimes
write a= -#e(a+ bi). The b in a+ bi is called the imaginary part of a + bi,
and we often write b=-%m (a+ bi). For example, A-(—3 + 7i) =—3, and
Im (5 — 61) =—6. Note that both the real and imaginary parts of a complex
number are real numbers. If b=0, the complex number a + bi is simply the
real number a. Thus, all real numbers are complex numbers; that is, they
can all be written in the complex number forma+0i. Ifa=0andb # 0, then
the complex number reduces to bi, which is called a pure imaginary number.
As you undoubtedly know, the complex numbers can be combined using
the operations of addition, subtraction, multiplication, and division. Under
each of these operations the system of complex numbers is closed; that is, the
result of the operation is again a complex number. In fact, not even the more
complicated operation of taking roots of complex numbers will lead out of the
set of complex numbers. The system of complex numbers together with these
operations which we define in the next paragraph is thus the most complete
system of numbers we shall ever need in applied mathematics.
The addition of complex numbers is defined by

(a+ bi)+(c+di)=(at+c)+(b+4)i

Thus, the sum is a complex number whose real part is the (real) sum of the
real parts of the two numbers and whose imaginary part is the (real) sum of
the imaginary parts of the two numbers. For example,

(3 + 4i) + (6—5i) = (3 +6) + (4—5)i


=9-i
The definition of subtraction is simply

(a+ bi) — (e+ di) =(a—c) + (—a)i

156 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Multiplication of complex numbers is done following the ordinary rules
of algebra with the proviso that whenever i? occurs, it is replaced by—1. Thus,
in general,

(a + bi)(c + di) =ac+ bei + adi + bdi?


=ac—bd+ (bce+ad)i

Example

(3 — 41) (—1+ 71) =—3 4+ 4i + 21i — 28:2


=a) ar Basra
— 25 1 251

Note that all positive integral powers of i must be one of the numbers
1,—1, i, or—i. In particular, i} =i, i?=—1,i?=—i,i*=1. High powers of
i can be easily calculated by taking note of the fact that i*=1. Thus, i?” =
17473 = (is) or = 13 = —] and 7 482 = j 48072 = —1.

Associated with each complex number a+ bi is its conjugate a— bi,


formed from a+ bi by changing the sign of its imaginary part. We write
a+bi=a-— bi.
Division is performed by following this rule: Multiply the numerator
and the denominator by the conjugate of the denominator. Note that
(c+ di)(c — di) = c? + cdi— cdi+ d*?=c? + d”, a real number.

Example

34+i 3+i2+3i
2-31 2-—312+3i
LAS
ee ay
ee 13
o. eek.
B13.

Example

ee : Oniad ; ; (6 +1) (3 — 41)


She) tags i+ 2i ore

5 = OA
SS ae hai 5

72 4
5DWe”

POLYNOMIAL FUNCTIONS 157


Example. Show that —1— V5i is a root of x?+2x?+4x—6=0. Substituting
—1— V5i into the left side of the equation, we have

(—1 — V5i)3 + (-1— V5i)2+ 4(—1 — V5i) — 6


= (-1— V5i)2(-1— V5i) +1+2V5i-5 -—4—4V5i—6
= (—4 + 2V5i)
(-1 — V5i) +14+2V5i-5 —4-—4V5i— 6
=44+4V5i-2V5i+10+1+2V5i-5—4—4V5i-6
=0
The simplified version of Fortran we are presenting in this book does
now allow its variables to take on complex numbers as values. An error mes-
sage will result, for instance, if the computer is asked to evaluate SQRT(A) if A
happens to be negative. Clearly, the computer does not recognize the symbol
I as the imaginary unit. We can, however, compute the real and imaginary
parts of complex numbers since they are real numbers, but we shall have to
manually insert the i after the computer has computed them. We shall in-
vestigate this further in program examples that appear in subsequent sections
of this chapter.

6.3 QUADRATIC FUNCTIONS AND EQUATIONS

A polynomial equation of the form ax” + bx + c=0 is called a quadratic equa-


tion. There are several ways to solve for the two roots of such equations.
One method is by factoring the left side into the form (x—1,)(x—1.). We
shall then have (x—1,)(x— 1.) =0. Now the product of numbers can be
zero only if at least one of them is zero. Thus, it follows that either x — r, = 0
and hence that x =r, or that x —r.=0 and hence that x=r,. Therefore, tj
and r, are the roots.

Example. Solve, by factoring, 3x” — 19x + 20=0. Factoring, we have the fol-
lowing equation:

(3%—
4) (+ —5):=0

Hence, x= “/s or x=5. The method of factoring is useful if the factors can
easily be determined. But consider 2x7—7x+13=0. The left side of this
equation is evidently not easily factored.

We now present a method called the quadratic formula which can be


used to solve any quadratic equation, whether or not it can be easily solved
by the method of factoring. Consider the general equation ax® + bx +c=0,
with a #0. Dividing through by a, we have x2 + bx/a + cla=0. We move

158 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


c/a to the right side of the equation: x? + bx/a=—c/a. Next we complete the
square on the left side by adding the quantity b2/4a? to both sides of the equa-
tion. Now we have

Factoring the left side gives

b\?
ee b?—4ac
eS
(x | 4a?

Then taking the square root of both sides, we have

b We
== Bile
x+—=+
2a 2a

Thus

pee Vb? — 4ac


% 2a

the quadratic formula. To use the formula, we have merely to identify a, b,


and c from the original equation and substitute them into the formula.

Example. Use the quadratic formula to solve 2x*—7x+13=0. Here a=2,


b=—7, and c=13. Thus, x= (7+ V49—104)/4= (7 + V—55)/4 =
(7 + iV55)/4 = V4 +iV55/4. The roots are 7/4 + i1V55/4 and V4 — iV55/4.
Note that the factored form of this equation is

(@=1)@—n)=(x-7-i-G 1 BY 24 5) ac
No wonder we could not easily solve this equation by factoring.

Example. Solve x7 + 2x—15=0. Herea=1,b=2,c=~—15. So,

pai VASHON 2 8

POLYNOMIAL FUNCTIONS 159


Hence, x = (—2 + 8)/2=3 or x= (-2—8)/2=—5. The roots are 3 and —5.

The quantity b? — 4ac that occurs in the quadratic formula is called the
discriminant of the equation. Since Vb? — 4ac occurs in the formula, it is clear
that the roots r,; and r2 will be real and unequal if b? — 4ac > 0 and will be com-
plex if b> —4ac <0. In the case b? — 4ac = 0, the roots are real and double.

Example. Solve x? —6x +9 using the quadratic formula. a=1, b=—6, and
c=9. Hence, x= (6+ V36
— 36)/2=(6+0)/2. The roots are then
(6+ 0)/2=3 and (6—0)/2=3. Clearly, 3 is a double root. The equation
has two equal roots.

Let f(x) be any function of x. Then the function a[f(x) ]? + b[f(x)] +c


is in quadratic form. It is clearly just the quadratic function ax? + bx + c with
x replaced by f(x). The intermediate solution of the equation a[f(x) ]? + b[ f(x) ]
+c=0 is just the quadratic formula with x replaced by f(x). That is, f(x) =
(—b + Vb? — 4ac)/2a. This is, however, another equation which must be
further solved for x.
Consider the equation 4(x—5)?+3(x—5)—8=0. Letting f(x) =
x—5, we have x—5=(—3+ V9 + 128)/8 =—9/s + V137/8. So, x=5—%s
+ V137/8 = 37s + V137/8. That is, x = (37 + V137)/8 or x = (37 — V137)/8.

Example. Solve 1/x* + 4/x?—21=0. We let f(x) be 1/x?, and the equation is in
quadratic form. Then 1/x?= (—4+ V16 + 84)/2 = (—4+10)/2. Thus, we
have either 1/x?=3 or 1/x?=—7. In the first case, x» =Y3 and x= +V3/3.
In the second case, x? = —¥7 and x = +(V7/7)i.

Example. Solve 15/x —9 V3/x +4=0. This equation can be written 5(V3/x)?
— 9(V3/x) +4 and hence is in quadratic form with f(x) = V3/x. Using the
quadratic formula, we have V3/x = (9 + V81 — 80)/10 = (9+1)/10. There-
fore, V3/x=1 or V3/x=4%s. In the first case, 3/xk=1 and x=3. In the
second case, 3/x = 1%25 and x =75/16. You can check that each of these is a
root by substituting it into the original equation.

6.4 ANALYTIC GEOMETRY OF QUADRATIC FUNCTIONS; CURVEFITTING

The graph of the quadratic function y = ax + bx + c,a ¥ 0, iscalleda parabola.


Consider, for example, y= x” + 3. Its graph can be sketched by first
finding
an appropriate number of points that are on it. The following table of
values
can be used:

160 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


The graph appears in Fig. 6.1.
The low point (or high point) of these parabolas is called the vertex of
the parabola. The point (0,3) is the vertex of the parabola of Fig. 6.1. The
curve is clearly symmetric with respect to the y axis.
The equation of any parabola of this type can be written in the standard
form

Y — Yo = p(X — x)?

When the equation is written in this form, the point with coordinates (%,Yo)
is the vertex. If p is greater than zero, the parabola opens upward; if p is
negative, the parabola opens downward.

Example. Suppose we have y=—4x— x. We place this equation in standard


form in the following way: y =—(2x?+ 4x) =—(x? + 4x +4) +4=—(x+2)?
+4. Thus, y—4=—(x+2)*. From this equation we read that the vertex
is at (—2,4) and since p =—1, the parabola opens downward. This informa-
tion, together with a few more points which lie on the parabola, will enable
us to draw a perfectly suitable sketch. Often the points where the curve

Fig. 6.1

POLYNOMIAL FUNCTIONS 161


ee

Fig. 6.2

crosses the coordinate axes are useful. Clearly, the parabola above crosses
the x axis at the point where y=0. Setting y=0 in the equation, we solve
for x and discover that the points (0,0) and (—4,0) are the x intercept points.
Similarly, setting x = 0 in the equation, we discover that the curve crosses the
y axis at (0,0). The sketch of the graph of y—4=—(x + 2)” appears in Fig. 6.2.
We note that the line x = —2 is now the axis of symmetry of the parabola.

Example. Find the vertex and intercepts of the parabola y = 4x” — 8x +5 and
sketch it.
We place the equation in standard form as follows: y = 4(x* — 2x) +5=
A(x = 2x-+ 1) +5 —4=4(y = 1)? > Thus, y— l= 4(e— 1)*, the vertexas
at (1,1), and the parabola opens upward, since p=4>0. As for the inter-
cepts, when x = 0, y=5, and so the point (0,5) is the y intercept point. But
now when y = 0, we have 4x” — 8x + 5=0, so that x= (8 + 4i)/2, using the
quadratic formula. This nonreal value for x is algebraic evidence that the
parabola does not intersect the x axis. The sketch in Fig. 6.3 substantiates
this evidence geometrically.

The quadratic function ax’ + bx +c is often used for curvefitting pur-


poses. Recall the analysis we gave when we discussed the fitting of data to
a straight line by the method of least squares. If the data, when plotted, look
as if a parabola would fit them better than a line would, the method of least
squares will once again provide the means for this fitting. As we shall soon
see, the arithmetic calculations involved are straightforward but tend to be
somewhat laborious. The use of the computer is thus indicated in order to

162 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


relieve us of some of the work. However, we plunge forward and solve the
problem by hand calculations.
Consider the (empirical) data

x
| ae =! 0 1 2 3
|

|
4

y 3 1 0 1 1 3

The points are plotted in Fig. 6.4, and a reasonable parabola has been sketched
in just to see whether the idea is feasible. It evidently is. The technique we
now describe will, of course, determine the unique parabola which is “best
fitting’’ by the method of least squares and will undoubtedly not be at all the
parabola we have just sketched in.
Just a note about the use to which one would be able to put the equation
of the best-fitting parabola y=ax’+bx+c. It can be used to interpolate
values of x, that is, to approximate the value y would have for values of x in
the domain [—2,3] which are not data values.
Suppose the parabola we seek has equation y = ax? + bx +c. The co-
efficients a, b, and c of the best-fitting parabola are found by solving the fol-
lowing set of simultaneous linear equations for a, b, and c.

POLYNOMIAL FUNCTIONS 163


I
Ms:
eS
a
feat
a +
Me3 eee
> ai = ‘sy
M:= a!
(=I
=
oi] on

Me& Me & aT
Me iS ° I
wo w
~) + >
<a
ll = as =
o.i] -
ey
pe (——SI
2.] mo eee =i
i] mn

‘%if ]=
LS
ut oi] -

Here the (x;,y;) are the given data points, and n is the number of data
points. The various summations that occur must be computed from the data,
and then the three simultaneous linear equations resulting must be solved for
a,b, and c. To facilitate finding all these sums, the following tabular method
is displayed for the data just given (n=6):

x y x? xe x! xy xy

=? 3 4 =8 16 =6 12
= 1 1 al 1 =I 1
0 0 0 0 0 0
1 1 1 1 1 1 1
2 1 4 8 16 2. “
3 3 9 27, 81 9 27

3 9 19 27 115 5 45

The entries in the last row are the various sums that are requested as
coefficients in the equations above. We then have the following set of equa-
tions to solve:

194+ 3b+ 6c= 9


27/4+19b+ 3c= 5
1154 + 27b + 19c = 45

164 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


As noted above, here is where some sort of automatic calculator would
be helpful. But since the numbers involved are not too unwieldy, we proceed
by hand. We use the simple method of elimination. Multiplying the second
equation through by 2 and subtracting from the first equation, we have 35a
+35b=1. We again eliminate c by multiplying the first equation by 19, the
third equation through by 6, and subtracting. We then have 329a + 105b = 99.
We must then solve the set

ee + 105b = 99
35a + 35b= 1

Multiplying the second equation through by 3 and subtracting from the first
equation, we easily eliminate b. We then have 224a = 96, that is, a= %/7.
Then substituting into a+ b= '/s5s, we have b = 35 — 9/7 = —7/s. Now sub-
stituting both a and b into the first original equation, 19a + 3b + 6c =9, we
have 57/7 — &s + 6c =9, from which c = 1%/3s.
The best-fitting parabola has the equation y = 3x?/7 — 2x/5 + 1%7/ss.
More analysis of this example is requested in the exercise set that follows.

EXERCISES

6.1 If z,=3—4i, z =—1—2i, z= 2i, evaluate the following expres-


sions and give the result in the form a + bi:

(a) z, + 3z,
(b) i2z12¢ 42,
(c) Z3°
ZOOL
(4) ee ai D2
Ga aes
(e) Phe va
(f) 4iz, — 51z, + 61z3
(g) (23/2)*7

6.2 Solve the following quadratic equations using factoring:

(ajax Aye 30
(b) 22—t=21
(c) 10x2 — 11x -6 =0
(d) 45? = 205.4421
=.0
(e) 9ye 52 y 4.30 —0

POLYNOMIAL FUNCTIONS 165


6.3 Solve the following quadratic equations using the quadratic
formula:

(ajar = Ox 40— 0
(b) x2+3x—10=0
(c) 42—4t+1=0
(dy Az 7
(6) Bi, ir
(f) 7x2 -4x +3=0
(g) 2+ 4x+6=0
(h) yy=—7y
(i) 4q2+9=0
Ge ere

6.4 Solve the following equations which are in quadratic form:

i a!
—+=+3=0
(a) a2 2 58
(b) x—2Vx—8=0
48 20 a
Olea elo p=)
(d) #=3F —10=0
(e) x3 — 10x27 +9=0
x—1\? x-—1
20
nS en

6.5 Place the equation of each of the following parabolas in standard


form, find the coordinates of the vertex, determine whether it
opens upward or downward, find its x and y intercepts, and by
finding enough additional points, sketch the parabola:

(a) y= 7x? — 28x + 25


(by y ==2 = 44 1
(ce) 128y'= 63 8x — 163°
(d) y=0.6x — x? — 0.29
(e) y= 8x—2x°—-1
Gy =5rt 4x 7

6.6 Refer to the parabola y = 3x?/7 — 2x/5 + 1/35 which was the best-
fitting parabola for the curvefitting example given in the text.
Place this equation in standard form and thus determine its vertex.
Then sketch the parabola on a graph which also contains the orig-
inal data points.

166 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


6.7 To check just how well the parabola of Exercise 6.6 fits the data
set given in the text, calculate the value of y on the parabola for
each x data value and compare with the given y data.

6.8 Use the parabola of Exercise 6.6 to estimate y when x = ¥/2 and
when x =—YVa.

6.9 Use the method of least squares to fit each of the following data
sets to the parabola y = ax? + bx +c:

(a) x |y (b) x | y (c) x y


oS 0 1 3 all =]
6 1 2 0 0 0
- 3 3 2 il 1
del) 4 2 3
3 8

6.10 Write a complete Fortran program to solve any quadratic equation


ax” + bx +c=0,a #0. Read the values of a, b, and c on one card,
3F10.0. Print the real and imaginary parts of each of the roots.
Allow any number of cards containing a, b, and c to be consecu-
tively read so that the program can solve any number of quadratic
equations.

6.5 POLYNOMIAL EQUATIONS OF DEGREE HIGHER THAN 2

Polynomial equations of degree higher than 2 cannot in general be easily


solved. The cubic equation (degree 3) can be solved exactly using a formula
of much more difficult form than the quadratic formula, but this cubic formula
is not now currently in vogue. Instead, numerical methods to find the real
roots of such equations are used, methods which can apply in general to poly-
nomial equations of any degree. We shall present an introduction to some of
these methods in this section, but we must leave quite a lot of material to await
your eventual study of a full-blown course in numerical methods.
Most of the numerical methods for finding a real root of a polynomial
equation start out with the knowledge of the approximate location of the root.
Then the method proceeds to zero in more and more closely on the root in
order to find it to a good degree of accuracy. A simple method of locating a
real root is now described. Let f(x) be a polynomial function and suppose
X > xX. If f(x.) > 0 and f(x,) < 0, then the equation f(x) = 0 has a real root
r such that x; <7 < x». The same result follows if f(x.) < 0 while f(x,) > 0.

POLYNOMIAL FUNCTIONS 167


Fig. 6.5

For example, suppose f(x) = x? —3x*—7x+5. Clearly, f(0) =5 while f(1) =


—4. Therefore, f(x) =0 has at least one real root between x= 0 and x= 1.
The graph of Fig. 6.5 shows the geometric idea behind this rule. On the graph
the points (0,f(0)) and (1,f(1)) are plotted, and a smooth single-valued curve
has been sketched between them to represent approximately the graph of f(x)
between 0 and 1. Clearly, f(x) must cross the x axis somewhere between 0
and 1, or else how could it get from above the axis to below the axis? At the
value of x where the graph crosses the x axis, y = 0; that is, f(x) equals 0, and
this value of x is the desired real root. We, of course, have only a reasonably
good approximate idea of what the root is, but at least we now have a starting
place for a refining process to find the root more precisely. We note that the
root is approximately halfway between 0 and 1. Let us check x= ¥2 as the
approximate value of the root. We have f(¥2) = (7/2)? —3(/2)? —7(¥)
+5=7/s. So, ¥2 is not the root but is close to the root. Now, since f(1) =—4
and f(1/2) = 7/s, we see that the root is between 1/2 and 1 and is evidently much
closer to 1/2 than it is to 1.
Having located the desired real root at least between two integers, we
can choose from among many techniques of numerical analysis to squeeze
down on the root. Many of these make use of the differential calculus, but
there are methods that use geometrically oriented notions not so involved.
One method that will always work is called the method of bisection. It depends
only on a simple geometric construction which we now explain.
Suppose we have isolated the real root between two integers x, and x9.
Suppose f(x,) > 0 and f(x.) <0 and the situation is shown in Fig. 6.6. The
root is r. Suppose we now bisect the interval from x, to x2; that is, let x3 be
(x; + x,)/2. We note that x3 is shown on the figure. We now calculate f(x3).

168 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


y = f(x)
(x4, £(x4))

(x3, f(x3))

(X2, f(x2))

Fig. 6.6

If it is 0, then x3 is the root and our work is done. But if f(x3) > 0, the root
must be between x; and x, since f(x.) <0. Similarly, if it had turned out that
f(x3) had been negative, the root r would be between x, and xg [since f(%1) is
positive]. In any case we have somewhat closed in on the root. If we carry
on, following the graph of Fig. 6.6 as our example, we would then proceed to
repeat the process. Again, bisect the interval in which we know the root lies,
this time the interval between x3; and x,. Suppose we let x;= (x, + x3)/2.
Again we calculate f(x,) and by observing its sign decide whether the root now
lies between x3; and x, or between x, and x,. The process consists of repeated
bisection operations as often as desired. Clearly, we shall close down on the
root, and even though the process may be slow and laborious, it cannot fail
to converge to the root. As usual, when laborious but well-defined calcula-
tions confront us, we immediately think of making use of a computer to do
the work. However, let us present just a few steps of the method of bisection
as it is used to solve the cubic equation x* — 3x” — 7x + 5 = 0 originally given
for the root between 0 and 1.
Let us start with x, = Y2,x,=1. Recall that f(#/2) = 0.875 and f(1) =—4.
Now x3 = Y2(x, + x2) =0.75.
We calculate f(0.75) as —1.52. Thus the root
must be between 0.5 and 0.75. Again, we calculate x,= ¥2(0.5 + 0.75) = 0.625.
Now f(0.625) =—0.30 so that the root must be between 0.5 and 0.625, since
f(0.5) = 0.875. Perhaps you will care to proceed and show that the root is
approximately 0.599.
A very useful iterative procedure, which is often used since it converges
to the root rather rapidly, is called Newton's method. The formula we are about
to give is based on the differential calculus and will not be derived here. It
will be sufficient to note first that associated with each polynomial function
if CeCe 5 Ure
2 ek a eas ean Ayx* + a,x + dy is another polynomial function

POLYNOMIAL FUNCTIONS 169


called its derivative and denoted by f' (x) and f' (x) = na,x""! + (n— 1)ay—4x"?
ee eet Lhe X cies,

Example. Given f(x) = 8x*+3x*—7x+9, then f'(x) =32x?+6x—7. It is


found by simply multiplying the coefficient of each term by the corresponding
power of x and then reducing the power by 1.

Now suppose that f(x) =0 has a real root near x, This fact is to be
determined earlier as we did in the previous method. Then, Newton’s method
consists of evaluating the iterative formula

f(x;)
Mee = T= 2 3 RAs
f(%)

The sequence x2, x3, X4, . . . thus generated presumably converges to the root
desired. One naturally takes x, as the first approximate value.
Let us take an example for which we can find the root by analytic
methods just so we can check the result. Let f(x) =x*—3x+1=0. Since
f(2) =—1 and f(3) = 1, this equation has a real root between x = 2 and x =3.
Let us take x, =3 and apply Newton’s method. Now, f(x) =x*—3x+1 so
that f’(x) =2x—3. Newton’s formula for this problem is

ee = 3x; == il
Xi441 —— oes
: : Deg}

x=3

So, letting i= 1, we have

octamer tae
ep = She) Heal

= Oral
13
63
=.
3

Then, i= 2 and

ree ie — Shear Al
ar 2x»
—3
eo 78 ocr
1 16/5
—3
_ 99
21

170 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Finally, °°/21 = 2.619.
We may continue in the same manner to increase the accuracy, but, of
course, we must now turn to approximate decimal numbers resulting in some
pretty hard calculations. For the fun of it, let us now solve the original equa-
tion using the quadratic formula. Obviously, the root we are seeking is ex-
actly (3+ V5)/2. Using tables, we have V5 = 2.236 so that the root is
= (3 + 2.236)/2. This is 2.618, showing that our result above is pretty good.
Other iterative methods for solving polynomial equations appear in
the exercise set below.

EXERCISES

6.11 Use the method of bisection to solve the following:

(a) 2x° + 4x — 7 = 0 for the real root between 1 and 2


(b) x* — 3x? — 15x — 16 for the root between 3 and 4
(c) x? — 87 =0 for the root between x = 4 and x=5

6.12 Solve the following equations using Newton’s method:

(a) x? — 3x — 15 =0 for its positive real root


(b) x4 — 8x? + 7x — 12 = 0 for the root between —1 and —2
(c) x? + 2x — 7x + 5=0 for any real root
(d) x*— 3x + 2x? + 4x — 7 =0 for the root between 1 and 2

6.13 Other iterative methods can be concocted depending upon the in-
genuity of the concocter. For example, to solve x° + 3x—5=0
for the root near 1, one could dream up the iterative formula

xP ar 3X; =)
Xin = Xj tp
10

See how this formula works by applying it several times.

6.14 To solve x4 + 3x2 — 7 =0, one could maneuver the equation into

Ti FF 1/2

x2 (x? + 3) =7 iC — r= (=)

To find the root near 1, one uses this last formula in an iterative
manner by writing it

7
ET tae br
reer Xj ape)
el

POLYNOMIAL FUNCTIONS 171


Use this iterative formula several times to test its convergence.
Solve the original equation exactly by recalling that it is in quad-
ratic form and using the quadratic formula.

6.15 Write a complete Fortran program to solve the fourth-degree equa-


tion of Exercise 6.14 using the method given there.

6.16 Write a complete Fortran program to solve the cubic equation given
in Exercise 6.13 using the iterative formula given there.

6.17 Solve any of the equations of Exercise 6.12 by writing a complete


Fortran program.

172 INTRODUCTION TO COMPUTER SCIENCE MATHEM


ATICS
Exponential and Logarithmic Functions

7.1 INTRODUCTION. DEFINITIONS

The function y=a*, a>0O, a #1, is called the exponential function. The
domain of this function is the set of all real numbers, that is, x € (~,—°).
Let us discover some properties of this function by drawing its graph. First,
let a >1. For example, y=2%. We easily calculate the following table of
values:

x y

—2 227= Ya
=i] 21=Y¥e2
0 2=1
1 2'=2
D 2=4
3 27>=8

We plot these points and draw the graph in Fig. 7.1. From the graph we note
that y is positive for all x.y is always increasing with x; that is, the graph
rises continuously as x moves from left to right. y increases rather rapidly
as x becomes more positive and larger. Evidently y = 1 is the y intercept, and
the graph has no x intercept. As x becomes more and more negative, y be-

173
Fig. 7.1

comes closer and closer to zero. We say that a line like y = 0 is a horizontal
asymptote.
Now, suppose 0 <a <1; for example, y= (1/3)”. A table of values
and the graph follow.

x y

=y (/s)?=
al (Ys)4 =3
0 (/3)°=1
1 Cass
2 (7/3)? = Yo

174 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


For our subsequent use, we recall the “laws of exponents.”

ata’ = qzuty

fee —— r—-y
a
(av)¥ = qty

Now we begin our development of the logarithmic function. We write


x= log, y if a*= y and read this first equation “x is the logarithm to the base
aofy.” It appears that x is the logarithm of y if the base a raised to the power
xis y. The relations x= log, y and a*=y are identical and have the same
graphs.
Suppose we algebraically interchange x and y in x= log, y to get y=
log, x. We then have normal variable names, and y is the logarithmic func-
tion of x. That is, now y is the dependent variable, and x is the independent
variable. The graph of y = log, x can be determined by noting the geometric
significance of the algebraic interchange of variables. The graph of y = log, x
is simply the graph of y =a’ reflected into the line y= x. The reason for this
is that (yx) satisfies y= log, x whenever (x,y) satisfies y=a*. Figure 7.3
shows this geometric juxtaposition.
From the graph of y = log, x we note that the function y = log, x is not
defined if x is 0 or negative. The logarithm of 1 is zero since the x intercept
of the graph is x=1. The logarithm of numbers less than 1 is negative and

Fig. 7.3

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 175


for numbers more than 1 is positive. Recall that the base a is a positive real
number.
To make clear the equivalence of y = log, x and x = a”, suppose we want
re-
to calculate the value of y = log, 25. We then have 5” = 25, and inspection
veals that y=2. Thus, y is the power to which 5 must be raised to give 25.
Again, consider y = log, 8. Thus, (7/2)”= 8, 2”= Vg, and y=—3. We can
also ask, “If 3 = log, 8, what is a?” Since we know that a’ = 8, it is clear that
the base a = 2.

EXERCISES

7.1 Find y if

(a) y = log, 27
(b) y = log, (7/49)
(c) y = logiy 0.001
(d) y = logs), 16
(e) y = logy 3
(f) y = log; 0.008

7.2 Find the base a if

(a) log, 8=3


(b) log, 8=—3
(c) log, 27 = ¥/2

These examples and exercises have used special numbers so that the
result would be easy to find by inspection. Suppose one were to be asked,
“What is log; 7?’ In other words, to what power must 3 be raised to give 7?
This power is an irrational number, and the best we can do is to find a rational
approximation to it. Possibly this rational answer appears in some kind of
a table of logarithms. You have already seen an entirely similar situation occur
in trigonometry. Although the sine of 30° and the sine of 45° are easily found
without using trigonometric tables, it is not easy to approximate the sine of
17° without a table (or at least a slide rule). So, as we suspect, tables of the
values of the logarithmic functions have been constructed, and from them we
can read approximate values of both the logarithmic and exponential functions.
We observe that since there are infinitely many bases we could use, probably
we should restrict the bases used in tables to just one or two special ones.
This is precisely what has been done, the bases chosen being 10 and e. The
latter is a very special irrational number which has been given a special name,
as has 7. Logarithms using base 10 are called common logarithms, and those
using base e are called natural logarithms.

176 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


If we are restricted numerically to two bases, then how do we calculate
logarithms which use bases other than these? Certain identities which will
now be derived permit this. Let p= log, N and q=log,N. Thena?=Nand
b’=N. Thus, a?=b* or a=b*?. Therefore, q/p is log, a. But q/p is also
log, N/loga N. We finally have the identity:

log, N = (log, N) (log, a)

In the light of our previous discussion, if we let a= 10, then

log, N = (logo N) (log, 10)

We can find the logarithm of N to any base b if we know its common logarithm
and the logarithm of 10 to the base b.
Since most conversions of bases are between bases 10 and e, it would
be sufficient to know that log, 10 = 2.30259 and logiy e = 0.43429.

Example. Suppose we know that log;) 43 = 1.63347. Then log, 43 = logy, 43 -


loge 10 = 1.63347 (2.30259) = 3.76120. This result can be verified by consult-
ing a table of natural logarithms.

7.2 CALCULATIONS INVOLVING LOGARITHMIC AND


EXPONENTIAL FUNCTIONS

We first derive three basic properties of the logarithmic function. Let x=


log, A and y=log, B. Then a*=A and a¥=B. Then AB=a’a¥= a".
Taking logarithms base a of both sides, we have log, AB=x+y=log, A
+ log, B, or

log, AB = log,A + log, B (CAI)

Similarly, a*/a”=a*’. Therefore,

A
loga ae log, A — log, B (722)

Since A” = (a*)’ = a’”, we also have

log, A’ =r log, A (7.3)

In essence, Eq. (7.1) reduces the problem of multiplying two real num-
bers to that of adding their logarithms and then finding the real number which

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 177


has this sum for its logarithm. Equation (7.2) reduces the problem of division
to that of subtraction, and Eq. (7.3) reduces the problem of raising to a power
to multiplying a logarithm by the power. In each case, of course, there is the
additional problem of converting the logarithmic result back to the number
which has this logarithm.
We shall presume that you have had some experience with the use of
logarithms as tools of calculation and that you know that the design of the
slide rule is based on logarithmic properties. Here we are concerned more
with the logarithmic and exponential functions.
The natural logarithm log, x and exponential e” use base e. It is con-
ventional to write log. x as In x (with the base now assumed to be e). _Inci-
dentally, advanced methods reveal that e = 2.718281828. Interestingly enough,
the natural logarithm lives up to its description “natural.” It is the most
used type of logarithm in applied mathematics and engineering. Your dif-
ferential and integral calculus classes will reveal its importance and why it
has been given the adjective ‘‘natural.’” Many physical quantities obey phys-
icallaws. You will find, for example, that the current in a certain circuit decays
exponentially, that is, i= iy) e “, and that a certain population increases expo-
nentially, that is, p = py e“’. The atmospheric pressure P in pounds per square
inch at an elevation of h miles above sea level varies approximately according
to p= 14.7 e *". One may solve this last equation for h. Taking the natural
logarithm of both sides, we have In p = In 14.7 e~*" = In 14.7 + In e~*” = 1n 14.7
—kh. Thus, h= (In 14.7—In p)/k. If one knew k, one could use this last
relation to find the elevation for a given pressure p.

EXERCISES

7.3 Suppose p = 14.7 e°-18°. Use natural logarithm tables to find the
elevation h (in miles) at which p is 7.35 lb/in.”.

7.4 Suppose i= 5.0 e**". Use exponential tables to find i when t = 1.5.
else amperes, ¢ in seconds.

7.3| TRANSCENDENTAL EQUATIONS INVOLVING LOGARITHMIC AND


EXPONENTIAL FUNCTIONS

Recall that a reasonable method for solving certain types of equations is the
iterative process in which we write the equation in the form x = g(x),
finda
good starting approximation for the root we desire, call it x, and iterate using
the formula

Xi+1 = B(x) 1 3

178 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Not every iterative formula will converge, however.
Consider the equation e* + 3x= 20. Investigation in exponential
tables and a few rapid calculations reveal that the equation has a root near 2.5.
We shall choose this for x, Now we rewrite the equation in the form x=
In(20 — 3x) and set up the iterative formula

Xi+1 = In(20 — 3x;) (Olaae eee

Calculation reveals that x, = 2.5257, x3 = 2.5180, and so the process seems to


be converging nicely toward the root.
Let us write a Fortran program to solve this problem. Recall that
Fortran has built-in library functions that automatically calculate the values
of functions like e”, In x, sin x, etc. We write EXP(X) for e® and ALOG(X)
for In x. In each of these, X must be a real constant or a real or mixed expres-
sion. For example, the Fortran statement Y = EXP(—3.*X) tells the computer
to compute the value of e~*” for the current value of x and store the result at Y.
Since we have decided that this particular formula converges when
x, = 2.5, let us write the program to iterate 20 times and then print the value
of the then current value of x. The program could be as follows:

X= 2.5
I=0
5 X= ALOG(20. — 3.*X)
I=I+1
TE (l= 20) 55,6
6 WRITE (3, 1) X
1 FORMAT (1X, E13.6)
END

First, x is initialized at 2.5. The counter | is set at 0. Note the state-


ment numbered 5. The righthand side is evaluated using x = 2.5. Then the
result is stored at X, erasing the original value of X and replacing it with the
new approximation. The counter is advanced by 1, and since I is still con-
siderably less than 20, transfer is made to the statement numbered 5. The
new approximation is used to calculate the righthand side once again. This
next approximation again replaces the old, and the process is repeated. By
the time the output step is arrived at, only the very last approximate value re-
mains and is called X. This is printed and the program ENDs.

EXERCISES

7.5 Write a complete Fortran program using the same iterative formula
to solve the equation e’ + 3x = 20. Again, let x,=2.5. This time,
however, print x after each five iterations. Iterate a total of 20 times.

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 179


7.6 Investigate writing the equation e’+3x=20 in the form x=
(20 — e*)/3. Set up the iterative formula x;+;= (20 —e*)/3, 1=
1,2,3,.... Using exponential tables, start calculating by hand
starting with x,=2.5. Does the process seem to be converging?
Write a complete Fortran program to do the calculating and print
the result of each iteration, that is, each x;,, fori=2,3,4,... ,20.

7.7 The equation logy) 3x + x* = 10 has a real root near x = 3.


(a) Show that this equation can be rewritten in the form

x= V10 — logy 3x

1 2
or in the form x = 3 GOP =>).

(b) Write a complete Fortran program using the formula

XxX; Pel (AML)


i+1 Bi

x,;=3, to solve the equation. Iterate 20 times and print the


result of each iteration.
(c) Write a complete Fortran program using the formula x;.,;=
(10 — logy» 3x)”, x, = 3, to solve the equation. Note that the
computer will compute ALOG(X) as the natural logarithm of x.
Recall from Sec. 7.1 how to change from base e to base 10. In
any case, iterate 20 times and print the result of each iteration.

Recall Newton’s method for solving the equation f(x) = 0 for the real
root near X;:

If f(x) has a term be", then the corresponding term in f'(x) is bae*”. If f(x)
has a term b In(ax), then f'(x) contains the term b/x. Recall that f’(x) con-
tains the term anx""' for each term ax" contained in f(x). For example, sup-
pose f(x) = 4e* — 5x3 +3Inx. Thenf’(x) = 8e?* —15x*+ 3/x. The equation
4e?* — 5x3 + 3 In x= 0 has a real root nearx=1. Newton’s iterative formula
is, therefore,

Ne ot 3} In xy Spay
Xin, = Xj y=
ea a Sie, — Iheyer

180 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


I=1
X= 1.0
U4 EXP(Q*X) + 8" ALOG(X) —5.°xX"3
Na On EXPOSA) eo Xk= 15K 2
X=X—U/V
= ltd
TP 10)) 1; 172
2. WRITE (373) X
3. FORMAT (1X, E13.6)
END

EXERCISE

7.8 Write the equation of Exercise 7.5 as e™+3x—20=0. Write a


complete Fortran program using Newton's iterative method to
solve for the root near 2.5. Iterate 10 times.

7.4 LOG AND SEMILOG GRAPH PAPER. CURVEFITTING

Log and semilog graph paper is often used in applications where the graphing
of exponential or logarithmic functions is involved. To understand its con-
struction and use, let us start with a logarithmic coordinate scale instead of the
ordinary uniform scale we have used up to now. As we know, the uniform
scale is one in which each unit length represents the same change in the value
of the variable. A logarithmic scale looks like this:

On this scale if we mark x= 4, we are actually plotting the logarithm of 4.


The base of the logarithm is immaterial—the scale looks the same regardless
of the base. Naturally the base will most probably be either 10 ore. Wenote
that the distance between integral marks is not constant but lessens as we move
from left to right. But the distance (measured with an ordinary ruler) is the
same between 1 and 2 as between 2 and 4 (or between 4 and 8). To see why
this is so, suppose we mark on the logarithmic scale x, and x, so that x, = x,/2.
Then log x2 = log x, — log 2, so that log x, — log x, = log 2. Thus, the distance
between the marked x, and x, on the logarithmic scale is constant, namely,
log 2. This occurs regardless of what x, and x, are as long as x,=¥x,/2. In
the same way, of course, 1, 3, 9, and 27 are the same distance apart.
We can construct a two-dimensional coordinate system in which one
coordinate scale (either vertical or horizontal) is logarithmic and the other is
uniform. Graph paper which uses such a system is called semilog paper. It

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 181


could look like these:

8 uN
7 te
6 3

4 Ali
;
3
2
1
Se ee
If both coordinate scales of a two-dimensional coordinate system are
logarithmic, it is called log (or log-log). It could look like this:

: aly
ta pea
1 2 3 45576878)
S10

Note, once again, that a point whose coordinates are (5,7) on this type
of graph paper is actually (log 5, log 7) numerically. What the logarithmic
scales do, then, is to automatically take the logarithm of whatever number
is plotted.
These coordinate systems are extremely useful on many occasions.
We shall be presenting some applications to curvefitting, especially to curves
of type y = ab” and y = ax".
First, consider the exponential curve with equation y= ab". We have
already seen in Sec. 7.1 the graph of such a function using the ordinary uni-
form x and y coordinate system. Now suppose we take logarithms base b of
both sides of the equation. Then, log, y = log,(ab") = log, a+ log, b™=
log,a+x. That is, log, y=log,a+x. Now, let y’ = log, y,a=log,a,x' =x.
Then we have the equation y’=a+x’. This is the equation of a straight
line with slope 1 in the (x’,y’) coordinate system. But, since y’ = log, y, if
the (x,y) coordinates of points lying on the curve y = ab” were to be plotted
on semilog graph paper with the y axis logarithmic, the resulting curve would
be a straight line.

182 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Suppose y = 5(2"). The table of values is

= (=)

oO 160
PON

As before, the uniform scale graph appears thus:

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 183


Now consider y= ax". Taking the logarithm of both sides of this
equation (any base), we have log y = log(ax”") = log a + log x" = loga + n log x.
Let log y= y’, log a=a,logx=x'. Then we have y’=a+nx'. Again, we
have arrived at the equation of a straight line. Now, however, y’ = log y
and x’ = log x, so that if the (x,y) coordinates of points lying on y = ax” were
to be plotted on log-log paper (both scales logarithmic), the resulting curve
would be a straight line.
Suppose y = 5x, x > 0. The ordinary graph is a portion of a parabola.
On this curve lie the following points: (1,5), (2,20), (3,45), (4,80), (5,125),
(6,180). We plot these points on log-log paper.

200

160

Semilog and log-log graph paper can often be of assistance in the process
of fitting data toacurve. Recall that any set of data can be fitted to any curve,
and the method of least squares will be of considerable use in finding the best-
fitting curve of the type selected. We still have the important preliminar
y
problem of selecting the type of curve the data should be fitted to. Obviously,
data like the following would not be well fitted by a straight line:

184 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


SaaS

ot -

Even so, a straight line can be fitted, but the deviations of the line from the
data points will be so large as to obviate any further practical use of the linear
equation. For these data, one would do better to select a parabolic type of
function like y = ax* + bx + c.since the data look, at least approximately, very
like a parabola.
The practical way to proceed in this selection process is to first plot the
data points on an ordinary uniform coordinate system. Glance casually at
this plot and select from a list of suitably fitting curves one which seems to
best fit the data. Then to get a very rough idea of the fitting equation, one
could sketch in by hand a curve of that type and, using points on this rough
sketch, find the equation of the curve. The equation would be very approxi-
mate, of course. The better idea would be, after selecting the type of curve
to be fitted, to call upon the good process of the method of least squares to
calculate the various parameters that occur in the equation. At least, one
would be getting the ‘“best” curve of that type.
We have already investigated fitting data to the straight line and to the
parabola, so that if the plotted data (on uniform scale coordinates) appear
either to be in a relatively straight line or to lie near a reasonable parabola,
our choice and further procedure are clear. We can now consider fitting data
to curves of two more types, y = ae” and y=ax". Thus, if we were not pleased
with the fitting to a line or parabola, we could proceed to plot the data on semi-
log paper. Then if the data show up as nearly in a straight line, we could con-
sider fitting the curve y = ae’”. Again we could proceed very roughly from the
straight line, drawn on the semilog plot, that approximates the data; perhaps
from the slope of the line and from its intercepts we could find rough values
for a and b. Or, more profitably, we could proceed directly to a modified ver-

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 185


sion of the fitting of data to a straight line using the method of least squares
to calculate a and b. We shall discuss this technique ina moment. Finally,
we could plot the original data on log-log paper. If the points then appear
to be approximately in a straight line, we would consider fitting a curve of the
‘SOXS YS wae,
Now before we present the method of linearizing mentioned above, we
recall the following. Given the data

x yi

ty
x4 Yi
, t

the method of least squares fits the data to the line with equation y’ = a + Bx’
if a and B are determined by solving simultaneously the equations

| nat (2x')B= Xy’


(ua (2x) B= Sx

Suppose we are given the following data:

— 2 NX

FR
WN
OF

We discover that when these data are plotted on log-log paper, the points lie
approximately in a straight line. We decide to fit the data to a curve of the
type y= ax". Clearly, we must determine the parameters a and n. This is
how we proceed to linearize the problem. We first take the log of both sides
of y=ax". As before, we end with the linear equation y’ =a-+t Bx', where
y’ = log y, x’ =log x, B=n, and a=log a. We decide to use natural loga-
rithms. We want to use the method of fitting to a straight line that we have
just reviewed. The data used in that method are values of x’ and y’ (not
x
and y). Thus, we must first construct a new set of data from the original
set
in x and y, recalling that y’ = In y and x’ =In x. We construct the
following
new table:

186 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


0.000 2.092 0.000 0.000
0.693 2.425 1.681 0.482
1.099 2.617 2.876 1.208
1.386 2.760 3.825 1.921
1.609 2.944 4.737 2.589

% 4.787 12.838 isha A) 6.200

We have used a table of natural logarithms and lengthy arithmetic. Substi-


tuting into the simultaneous equations for a and B, we have

{ 5a + 4.7876 = 12.838
4.787a + 6.2008 = 13.119

Solving these equations, we arrive at a= 2.08, 8=0.508. Therefore,


n= B=0.508 and a=e*=e? = 8.00. The equation of the fitting curve is
y = 8.00x°°8,
As we review this exercise, we realize that the process of linearizing can
be used whenever the fitting curve can be rewritten in the form y’ = a+ Bx’.
We then fit a straight line to the transformed data (x',y’) and transcribe a and
B back to the original parameters in the equation of the fitting curve. It is
important to note that this is not the same process as applying the method of
least squares directly to the fitting function.
We hope that you can figure out how to proceed if the data plotted on
semilog paper turn out to be almost ina straight line. Other curves can be used
for fitting purposes. If the method of linearizing is to work, such a function
should contain only two parameters. Other examples are y = ab” and its spe-
cial version y = ae’”. Some types, like y=a/(b +x) or y= (x+a)/(y+b),
are not suitable for the linearizing method. They can, however, be used fol-
lowing much more analysis with the general method of least squares.

EXERCISES

7.9 Use the method of this section to fit the following data to the more
appropriate form of y = ax" and y = ae”:

y (b) x y (ex *
‘aa Je Se
|

4.5 ili 0.62 =i 0.05


1.02
1.35; | 0.68 ~0.8 0.12
272 14.9 0.57
49.5 1.49 | 0.72 =A
7.39 0.2 0.63
20.10 163.0 1.64 | 0.73
2.25 | 0.84 0.7 | 47.00
55.00 | 521.0 1.2 | 330.00
148.00 | 1810.0 2.74 | 0.89
ils) 517.00

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 187


7.10 Use the methods described in this section to fit the following data
to the curve of type y = ab’:

(a) x y (D) # ex y
—3 | 5.64 0.1 6.69
S| ne 0.4 9.39
1 34s 0.6 | 10.60
Ose 2:83 0.8 | 12.90
Ds 78 1.0 | 18.00
Sale 1,42 11h. 10
4 erie 1.3 | 24.60
1.5 | 32.40

7.5 APPROXIMATIONS BASED ON SERIES

As you have discovered, hand calculations involving exponential and loga-


rithmic functions have required looking up the values of these functions in
atable. The computer does not maintain such tables inits memory. Instead,
it can calculate the value of these functions (and many others) almost instan-
taneously for any reasonable value of the argument with a great degree of
accuracy. You simply write ALOG(X) or EXP(X), give the value of X and
where you want the result stored, and the computer automatically calculates
and stores that specific value of the function. One can, of course, write a
program to have the computer calculate complete tables of functional values
such as those that appear in handbooks. In this section we shall present some
notions about the methods the computer uses to compute functional values
such as these.
In the calculus course you may soon be taking, formulas for the calcula-
tion of the values of transcendental functions will be derived. Most of these
formulas are based on the notion of finding a power series which represents
the function and then truncating it appropriately to a finite polynomial. For
our purposes the following discussion will have to suffice.
A power series in powers of (x — a) is a “huge” polynomial of the form
by + by (x — a) + Oo (¥ — 2)? + b,(8— a): © > bea or ee
a=0, in powers of x, by + bx + box* + box = = bx i Them
are (real) constants. As you note, the series extends indefinitely—it has an
infinite number of terms. Now it turns out that for certain values of x, the
series converges; that is, it has a sum. It is clear by inspection that every
power series converges for x=a and the sum is precisely by. In general, a
power series converges in some interval a < x < B. Outside that interval it
does not converge, has no sum, and will be useless for our purposes.
Suppose that a < x < B is the interval of convergence of a given power

188 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


series. Then for each x in the interval, the series has a unique sum. Ina
sense, the series is a function whose domain is the interval of convergence.
Let us denote this function by f(x). Thus, f(x) = bo + by (x — a) + by(x — a)?
ts ,a@<x<£. We cannot in general find out what this function f(x)
is in explicit form, like f(x) = e® or f(x) =1/V1+ x. Even so, we can still
find the value of f(x) for a value of x in the interval of convergence. Let us
use an example to demonstrate the techniques involved.

Example. Let f(x) =x + x9/5 + x5/25 4+ x7/125 + - + + + x2mt/5n 4... y

—V5<x< V5. We calculate (O25

f(0.2) =0.2+ 0.2)" pecOs2 ) 0.2) +:+:--


25 125
oe 0.008 ,0.00032 0.0000128 vee
5 55 pails Mee
= 0.2 + 0.0016 + 0.0000128 + 0.0000001024 + - - -
= 0.201613824

We note that as more terms are added on, the sum increases but at a much
slower pace. We would suspect (and you can verify this) that adding on the
next term of the series (0.2)°/625 would not affect the first four figures of our
present sum. In any case, we note that the number of terms that need be used
to approximate f(x) depends on what x is and also on the required degree of
accuracy. It appears that in our example f(0.2) = 0.20 to two significant fig-
ures [using the approximation f(x) = x], f(0.2) = 0.202 to three significant
figures [using the approximation f(x) = x + x°/5], f(0.2) = 0.2016 to four sig-
nificant figures [using the approximation f(x) = x + x3/5 + x°/25], and f(0.2) =
0.20161 to five significant figures (using the first four terms of the series).
These approximations, like f(x) = x + x?/5, are simply truncations of the series
and are simple polynomial approximations to f(x).
Suppose we desire the value off(x) to be accurate to four decimal places.
We could proceed like this. Start evaluating and adding the terms of the
series one by one. After each addition, see if the absolute value of the differ-
ence between the new approximate sum and the immediately preceding one is
less than 5 X 10°°. When this occurs, the new sum would have to be accurate
to four decimal places. In our example above, f,(0.2) =0.2, and f,(0.2) =
0.2 + 0.0016 = 0.2016. Now |f, — f,| = 0.0016, which is greater than 5 x 107°,
so we proceed to the next term. f3(0.2) =0.2016128. Now f; — f,=0.0000128,
which is less than 5 X 10-°. We stop and take 0.2016 as the result desired.
Such a general procedure would obviously be amenable to computer pro-
gramming.

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 189


EXERCISES

7.11 Let f(x) be defined by the following power series. Calculate


f(0.1) and f(1.) correct to three decimal places:

Sete x Xe ae A pie wcXe SS.2:


FI erg 3 e108" 4108 (ise lee 10%

7.12 Calculate f(0.01) and f(0.1) correct to five decimal places if

x3 x? x7 (ail )ecneae

Ae Eee oreo
7.13 Calculate f(0.1) and f(0.5) correct to four decimal places if

eo he
La aura ate BHO © cae

(Note: Here we are using the factorial. We read n! as ‘’n factorial.”


By definition, 0!=1 and n!=1-2-3.-- -: nifnis an integer 1.
Thus, 5! = 1) 2 43 7 4*5 — 1203)

7.14 Write a complete Fortran program to calculate

2
(i= pete ele oe for0 <x <2
2! n!

in intervals of 0.1, that is, for x—0, 0.1,0.2, 0.3,.°. « ,1-9, 2.0.
Each value is to be correct to four decimal places. Print each x,
the corresponding value of f(x), and the value of e*. Recall the
Fortran library function EXP(X).

Now we consider the reverse situation which is also studied in the


calculus. Suppose we are given an explicit function f(x). What is the cor-
responding power series in powers of (x — a), given a, and where does this
series converge? We shall not be able to answer this question. We do give
some important examples, however.

x? x4 x"
SAR we Saree ayo Py areal il ae lt a~°) (7.4)

Inx=(x-1) -S54 ss 2
Go = 3
perineal VCE = n = n
|
nN

O<x<2 (75)

190 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


i x3 x? (Hiya
Sine =
—10 31
——+—
Sit a) fe fe:
+ A
(Qn eS
+! + =
aoc x< oo (7.6)
r x3 x Ge esol) ce

aneex =x 375 SHE eel (a7)

After each series its interval of convergence is given. We have included series
for the trigonometric functions sin x and tan”! x to show how extensive the
series representation of functions canbe. You note that series (7.4) is precisely
the one used in Exercise 7.14.
A polynomial can be obtained by truncating any of these power series
after a suitable number of terms. This polynomial can then serve as an ap-
proximation to the function. As you recall, the number of terms one should
use depends on the value of x to be substituted and how accurate the resulting
approximation is required to be. It can be shown that at least 12 terms of
series (7.4) will be required to achieve an accuracy of 10 8if—1 <x <1. This
is not too distressing, but some series, although they surely converge, do it
so slowly that a very much larger number of terms must be used to achieve
accuracy like this. Recall that because of roundoff-error accumulation this
could lead to an almost guaranteed severe loss of accuracy.
It would be very useful if there were more condensed series still repre-
senting f(x) which would converge more rapidly, at least over a certain range
of x, and still ensure the same accuracy. In fact, the computer makes use of
such economized power series rather than the usual power series we have just
given above. We cannot here present how they are derived, but we can point
out some typical examples. Perhaps you will make a further study of this
matter in a course in numerical analysis. For example, the series forIn(1 + x) =
x — 22/2 + x9/3 + x4/4+ - + + ,—1 <x <1, which is obtained from series (7.5)
by replacing x by x +1, is very, very slow to converge. Many hundreds of
terms would be required to achieve any reasonable accuracy, and even then
the result would be suspect because of accumulated roundoff error. C. Hast-
ings, Jr. in “Approximations for Digital Computers,” Princeton University
Press, 1955, has shown that the following polynomial approximates In(1 + x)
to an accuracy of 0.0000015 for all x in the interval 0 < x <1:

In(1 + x) = 0.99990167x — 0.49787544x* + 0.31765005x*


— 0.19376149x* + 0.08556927x*> — 0.01833851x*

Formulas like this are the sort that are actually used in the library function
subprograms of Fortran to compute very efficiently functions like In(1 + x)
and all the other elementary functions like sin x, cos x, tan™' x, and e”.

EXPONENTIAL AND LOGARITHMIC FUNCTIONS 191


Boolean Algebra

8.1 INTRODUCTORY REMARKS

In this chapter we shall develop that application of Boolean algebra which is


concerned specifically with the design and use of logic circuits for electronic
computers. The general subject of Boolean algebra can be specialized in other
ways so that it will apply to set theory and probability, mathematical logic, and
switching circuits for telephone and control systems. This algebra, which in
its original form was quite theoretical and formal, thus turns out to be quite
practical and extremely useful.
In order to begin understanding the subject of Boolean algebra, we shall
keep before us a very simple physical application—a simple on-off switch.
The physical means used to activate or deactivate the switch will not concern
us. It can be turned on or off manually or by means of an electromagnet. We
A
shall let o—|H stand for a simple switch (named A) which is either on so
that current is able to flow through it—the variable A then has value 1—or off
(or open so that current cannot flow through it)—the variable A then has
value 0. A switching circuit may consist of several switches which we may
name A,B,C, . . . arranged in series-parallel branches. We shall discuss these
arrangements in the next section. In any case, at any specific time each of the
switches will be either on or off. The name of each switch is a variable which

193
may take on only one of the two values 0 or 1. We note, of course, that these
values are precisely the two digits which are used in binary numbers.
Although we are using the simple switch as our physical realization of
the Boolean variables A, B,C, . . . , any device which operates in two distinct
states can be used. Such devices are called two-state devices, and many of them
are in current use. These include diodes, transistors, and other electronic
components. In these, on and off, the two states, vary from one device to an-
other. We thus have such states as on-off, closed-open, conducting-noncon-
ducting, charged-discharged, magnetized-not magnetized, high voltage-low
voltage, and so forth.

8.2 SERIES-PARALLEL SWITCHING CIRCUITS. LOGIC BLOCKS

Let us first consider a series circuit of two switches shown in Fig. 8.1. It
seems obvious that current will flow from input to output only if both switches
A and B are closed. Current cannot flow if either A or B is open or if they are
both open.
Associated with each switching circuit is a function of the variables it
contains. This function is called the switching function. The value of this
Boolean function is to reflect the state of the entire circuit—its value will be 1
if the entire circuit is closed and 0 if the entire circuit is open. Clearly, the
switching function depends upon the states of the various switches that com-
pose it. Our first project is to figure out how to write the switching function.
For the series circuit shown in Fig. 8.1 we introduce the operation of
multiplication, and we write the switching function asf=A-B. Wecanread
this function “A and B.” From physical considerations we see that f = 1 only
if both A and B are 1. It is O for all other combinations of states of the switches
A and B. A table of functional values for f can be easily constructed. In this
table we display the value of f for all possible combinations of states of the
switches A and B. Recall that A and B can take on only values 0 or 1. We
have the following table:

A B f= AB

0 0 0
0 1 0
1 0 0
1 1 1

Fig. 8.1

>
4
194 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS
A

Fig. 8.2

We note that this multiplication table is exactly the same as for ordinary arith-
metic multiplication of binary digits.
We now move naturally to the logic block corresponding to the same
state of affairs. We introduce the AND block as shown in Fig. 8.2.
The AND block has two “wires” to carry in the two inputs and one
“wire” to carry out one output. Signals appear at the two input terminals.
They have “values” of either 0 or 1. In later applications we shall call these
signals binary signals. Recall that we are idealizing an actual circuit, and
actual signals could be, for example, a voltage of some measurable magnitude
appearing at terminal A, none appearing at terminal B. We would say that
A=1, B=0 at this time. The block contains the components (electronic or
otherwise) that react to the two inputs and as a result output A- B. Note that
an output appears only if both A and B have signals. It is this property that
leads us to call this block the AND logic block. The multiplication table given
above for the series circuit switches clearly is to apply.
Consider now the parallel switching circuit shown in Fig. 8.3. Clearly,
a current will be conducted through the circuit if either A or B is on or if they
are bothon. The only way current will not be conducted from input to output
is if A and B are both off. For this circuit, we introduce the operation of addi-
tion, and we associate the switching function f= A+B. We can read this
function “A or B.’’ From physical consideration, the following addition table
is evident:

A B f=A+B

0 0 0
0 1 1
1 0 it
1 1 1

Fig. 8.3

BOOLEAN ALGEBRA 195


Addition appears to be normal except for the entry 1 +1= 1. Although this
is peculiar in ordinary arithmetic, it is evident that in Boolean arithmetic this
statement simply means that in a parallel circuit if both switches are closed,
then so is the circuit. We therefore accept this equation in Boolean arithmetic.
The logic block corresponding to the parallel switching circuit is the
OR block which we denote:

The OR logic block has two input “wires” and one output “wire.” Again
binary signals (0 or 1) appear at the input terminals, and the OR block circuit
outputs the value of f = A + B as given in the addition table above.
The third essential operation in Boolean algebra is that of imversion.
We write A’ and read “not A.” The value of f= A’ is 0 if A is 1 and is 1 if
Ais0. The table is simply

This operation simply inverts the signal and is called inversion. The inver-
sion logic block is

In a switching circuit we shall denote A’ by

pena analyMee ls A'

To review, in Boolean algebra there are two constants 0 and 1, any num-
ber of variables denoted by letters like A,B,C,D,..., and three basic oper-
ations: multiplication (AND), addition (OR), and inversion (I). Recall that
a variable can take on different values (either 0 or 1) at different times. At
any given time it has one of the values 0 or 1. We note that 0 and 1 are the
binary digits from which numbers in the binary system are constructed, and
we are looking forward eagerly to see how logic blocks and other logic circuits
can be used to store and manipulate binary numbers and possibly add them.
Finally, physically a binary signal (digit) can be thought of as appearing on a

196 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


“wire” according to the level of voltage which appears on the wire. We
can
let 1 stand for a higher (or more positive) voltage and 0 stand for a lower
(or
more negative) voltage. The logic circuit which constitutes the logic blocks
(we shall not be able to design them) react to these input signals (voltages)
and output a signal (voltage) according to their natures as described above.

8.3 BASIC OPERATIONS. IDENTITIES. THEOREMS

We have already accepted the following identities for the constants 0 and 1:

0'=
v=
0+0=0
0+1=1+0
=1+1

1:-1=
0O:-1= 0
=0-0

Since A and B can take on only values 0 or 1, it is clear that AB = BA and


A-+B=B-+A for any variables A and B. Thus, in Boolean algebra the oper-
ations of multiplication and addition are commutative.
Identities like those above are easily seen to be true. In general, how-
ever, we have the very important property: A relation among variables is an
identity if it holds for all possible combinations of the values of the variables
it contains.
We make use of this property as we now extend our addition and multi-
plication to more than two variables. We now show that (A+B) +C=
A+ (B+); that is, addition is associative and the parentheses directing the
order of adding are unnecessary. Consider the following “truth” table:

A|B|C || A+B] (A+B)+C | B+C | A+(B+C)


+ + .
o/oj}o 0 0 0 0
Cao t1 0 1 1 1
O Te tehet 1 i 1 1
ind ia 1 1 1 1
a 1 1 0 1
LP SOt it 1 1 1 1
Lets tet 1 1 1 1
Deelaatent 0 1 1 1 1

BOOLEAN ALGEBRA 197


The first three columns contain the eight possible combinations of
values of the variables A, B, and C. The column headed A+ B is found by
simply adding the corresponding entries in the A and B columns using the
basic addition table for the addition of two numbers. The column headed
(A + B) + C is found by adding the corresponding entries in the A + B column
and the C column. The other columns are found in exactly the same manner.
Now we finally compare the entries in the columns headed (A + B) + C and
A+ (B+ C) and we note that the columns are identical. Thus, (A+B) +C=
A+ (B+ C) is an identity. We have shown that addition is associative. In
an entirely similar way we could show that (AB)C = A(BC) so that multipli-
cation is also associative. We could have reverted to the switching-circuit
versions of these identities and convinced ourselves that they are.
In order to facilitate the addition and multiplication of more than two
variables, we now extend the AND and OR logic blocks to allow any number
of inputs greater than or equal to two, as shown in Fig. 8.4. Each of these
blocks has one output. For the OR block f=1 if any of A,B,C, ... ,Pis1,
and f= 0 only if all A,B,C, ...,Pare0. In the AND block f=0 if any of
ALB aC sae boare 0 and £= lt only inal4- a. © eae areal
We now present some examples of switching circuits and corresponding
logic block diagrams which realize Boolean functions.

Example. f = AB + C’

THE SWITCHING CIRCUIT THE LOGIC BLOCK DIAGRAM

A B

198 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


We shall assume throughout that inverted values of variables are not available.
This requires the use of the inverter to obtain C’.

Example. f= A(AB +C+C’'D)

THE SWITCHING CIRCUIT

A B

A Cc

& D

THE LOGIC BLOCK DIAGRAM

(AB)

(AB + C)

f = A(AB +
+
C + C’'D)
I

(AB +C+C’'D)
(CD)

So that you may trace the development of the function, we have shown the
output of each block. The presence of both C and C’ in the switching circuit
diagram means that a switch is in essence ganged or coupled from two switches
that operate together but oppositely so that when one is open the other is
closed. Note that we read the figures from left to right; thus arrows indicating
the flow direction are not necessary.

Example. f = ABCD’ + C(AB+ D)

BOOLEAN ALGEBRA 199


THE SWITCHING CIRCUIT

Oe
THE LOGIC BLOCK DIAGRAM

In the switching circuit the presence of two switches named A (or B) indicates
that these two switches are ganged and act together simultaneously either both
open or both closed. The block diagram shows two A, B, C, D inputs in order
to simplify the geometry of the diagram. Actually, the signal on A appears
simultaneously at both input wires labeled A. For these diagrams suppose
that at a certain time A=1,B=1,C=1,andD=0. We find the value of f
in different ways.

1. By use of the switching diagram, switches A, B, and C are closed


and, since D is open, D’ is also closed. This means that the entire
upper branch is closed and clearly f = 1 (regardless of the condition
of the lower branch). .
2. In the logic block diagram, the output of the upper AND block is 1
since A=B=C=D'=1. The lower first AND block has output 1,
the OR block has output 1, and thus f=1+1=1.

200 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


3. Using Boolean algebra and arithmetic, we have

f = ABCD’ + C(AB + D)
= (1) (1) (1) (0) +1(1 - 1+ 0)
ha hot boa ees eG oom vee Beg
=1+1+0
=]

As noted above, identities in Boolean algebra can be verified by use of


the truth table. Sometimes of course identities can be proved on the basis
of previously proved or verified theorems. Before we present some of these
proofs, let us call your attention to a very important fact concerning a certain
duality involved in Boolean expressions. Let us first define the dual of a
Boolean expression.
If, in any Boolean expression, + is replaced by -, - is replaced by +, 0 is
replaced by 1, and 1 is replaced by 0, the resulting expression is called the dual
of the original expression. For example, the dual of A+B’ +1 is A: B’ <0;
the dual of A(B + C’ + DE) is A+[BC’(D+E)]. Note that inversions like
B’' and C’ are unaffected. Note also, in the second example, the retention of
parentheses and the insertion of new parentheses when DE appears as D + E
in the dual. As a matter of notation we could write du(f) to indicate the dual
of the expression for f. Thus, if f= AB’ + CD, then du(f) = (A+ B’)(C+D).
Recall that an identity in Boolean algebra (as in most algebras) is an
equation which is true for all values of the variables it contains. We have
what is called the principle of duality: If f= g is a Boolean identity, then du(f) =
du(g) is also an identity. We cannot prove this principle, so we shall accept
it and notice its uses and consequences. This will mean that as soon as one
identity has been verified or proved, its dual will automatically be assumed
proved. The dual can be proved independently, too. As we shall soon see,
A+0=A isan identity. Thus, its dual A- 1=A is also an identity.
As in trigonometry there are myriads of identities in Boolean algebra.
We shall consider and prove only a few, selecting those that are basic or those
that are more involved but which have some important applications. Let us
first consider basic simple identities involving 0 and 1. We demonstrate the
truth of the identity using switching circuits and then prove it using either
truth tables or algebraic methods.

A+0=A
Dual: A:1=A

BOOLEAN ALGEBRA 201


THE SWITCHING DIAGRAM FOR A+0
A

Here 0 represents a permanently open switch. Evidently, the circuit


is open or closed as A is open or closed.

THE TRUTH TABLE METHOD

A | f=A+0

0 0
1 1

Since the two columns are identical, A+0=A is an identity. Recall


thatO +0=0 and0+1=1.

Aas 0i—10
DvalwAcle—sl

THE SWITCHING CIRCUIT FOR A-0

A O

Here again 0 is a permanently open switch so that the circuit is always


open whether or not A is closed. Thus, A - 0 always has value 0.

THE TRUTH TABLE METHOD

A f=A-0

0 0
1 0

A:-A=A
Dual: A+A=A

THE SWITCHING CIRCUIT FOR A: A


A A

202 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


The two switches A act together so that if A is open, the circuit is open,
and if A is closed, both switches are closed and the circuit is closed.

THE TRUTH TABLE METHOD

A f=A-A

0 0
1 1

Recall that0-0=0 and1-1=1. We again note that this identity is


not an algebraic equation. In Boolean algebra there is no such thing
as 2A
or A’.

Ansa
Dual:
A: A'’=0

THE SWITCHING CIRCUIT

A’

Regardless of the state of switch A, one branch or the other is always


closed, and the circuit is thus always closed.

THE TRUTH TABLE METHOD

Recall that 0’ =1 and 1'=0. Thus, A+ A’ is always 1.


Now we turn to some important identities involving more than one
variable. We note that as the number of variables increases, we rely more
and more on algebraic and truth table methods. Switching circuits get too
involved to use for the purpose of verifying identities.

A+AB=A (Absorption law)


Dual: A(A+B)=A

BOOLEAN ALGEBRA 203


THE SWITCHING CIRCUIT

A
Peet
Notice that if A is closed, the circuit is closed regardless of the state of B.
If A is open, the circuit is open, again regardless of the state of B.

THE TRUTH TABLE METHOD

b i.) > i) os I > + > Cs)

OO
CO
pe FP
Oro

Recall that to use a truth table with two variables, we must list every
combination of possible values of the variables. There are four such combi-
nations as shown. This law will be used quite often in the simplification
procedures that we shall be eventually concerned with.

A(B+C) = AB + AC (distributive law)


Dual: A+ BC = (A+ B)(A+C)

THE TRUTH TABLE METHOD

PX 73 (8 Hi) sete A(B+C) | AB AC AB + AC

0 Ono 0 0 0 0 0
0 OR 1 0 0 0 0
0 ee 1 0 0 0 0
0 Hal 1 0 0 0 0
1 One) 0 0 0 Oe 0
1 al 1 1 0 1 1
1 iO 1 1 1 0 1
1 eal 1 1 1 il 1

204 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Since the columns headed by A(B + C) and AB+ AC are identical for
every one of the eight possible combinations of values of A, B, and C,
the
distributive law is verified. It is important to note carefully the dual of this
law. The “factorization” of A+ BC is different from ordinary algebra. In
simplification procedures we often use this dual identity. Note that we can
now prove the previous identity A + AB = A algebraically. Thus,

A+ AB=A(1+8B) (using the distributive law)


=A-l
=A
A+A'B=A+B
Dual: A(A’ + B) = AB

Proof: A+ A'’B= (A+ A’)(A+B) (factoring)


1 -(A-t-B)
=A+B

Example. Simplify algebraically the expression A + ABC + A’B’.

A+ ABC + A'B’ = A(1 + BC) + A'B’


=A+ AB’
=A+B'
Example. Simplify algebraically the expression B’ + AB + BC.

B’ + AB + BC = (B’ + A)(B’ +B) + BC


= B’'+A+BC
=B'+BC+A
= (B'+B)(B'+C)+A
=B’+C+A

The two preceding examples are given to show how some of the identi-
ties already covered can be used to simplify Boolean expressions. In Sec. 8.5
we present a much more satisfactory method for the simplification process,
one which does not require complicated selective choices of identities but
which instead automatically uses identities by means of a semigraphical pro-
cedure. This is the method of Karnaugh maps.
Now we present some more identities concerning inversion. First,
we want to allow expressions to be inverted such as (A+ B’ + C)’ and we

BOOLEAN ALGEBRA 205


must see how to do this. We already know that 0'=1 and 1'=0. We also
have

(A')'=A (double inversion) (no dual)

THE TRUTH TABLE METHOD

A A’ |A”

0 1 0
1 0 1

(AB)’ =A’ + B’ (De Morgan’s law)


Dual: (A+ B)’=A’B’

THE TRUTH TABLE METHOD

A B AB (AB)’ A’ B' Ai + B:

>)
ll Pp
©
OF =) FP
He
or Ff
coor
orFoOor KF
eS
or

Since the entries in the column headed (AB)’ and those in the column headed
A' + B’ are identical for every set of values of A and B, De Morgan’s law,
(AB)' = A’ + B’, is an identity. It and its dual are very important and useful
identities. The laws naturally extend to finding the inverse of the sum of
any number of variables or the inverse of the product of any number of vari-
ables. For example, (A+B+C+D+E)'=A'B'C'D'E' and (ABCD)'=
A' + B'+C'+D'. Using De Morgan’s law and the distributive law, one can
multiply out a complicated expression like [C(A+D)' + E’]’ into a simple
sum form. Thus,

[c(A+ D)' + E']' = (CA'D' + EB’)


= (CA'D")'(E’)'
= (CA'D')'E
=(C'+A+D)E
=AE+DE+C'E

Let us momentarily return to the subject of simplification of Boolean


expressions by means of a physical example. Suppose we are given the
following switching circuit:

206 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Clearly, the switching function is f= A + AB + A’BC + B’, and seven switches
are needed. We use Boolean identities to simplify the switching function
and thus, we hope, arrive at a completely equivalent function and correspond-
ing switching circuit. Now

f=A-+AB + A'BC +B’


=A+A'BC +B’
=A-+BC +B’
=A+B'+BC
=A+B'+C

The equivalent switching circuit is

Now only three switches are needed, a saving of four switches. This is a re-
duction in cost of whatever physical element the switches represent. Recall
that they may be mechanical switches, diodes, transistors, or other types of
devices, and still we represent their operation, circuit, and simplification as
we have done for simple, manually operated on-off switches.
The process of simplifying a function to its absolute minimum form is
a major and most important phase in design. However, often several equiv-
alent minimum forms result. If the expression to be simplified is not too

BOOLEAN ALGEBRA 207


involved and rather obvious simplifications come to mind without too much
manipulation and deep thought, they should obviously be done algebraically.
If this is not the case, some systematic way of simplifying Boolean expressions
must be used. Of several methods in current use, we have selected the Kar-
naugh map method. But before we can present this method in detail, some
preliminary groundwork must be laid. This is done in the following section.

EXERCISES

8.1 Draw switching circuits which realize each of the following Boolean
functions:

(a)f=A+B'C
OFC Gay
(c) f= (ABCD + E+ F)G
(d) f= (AB! + A’B + AB) (A+ B+C)
(ec) f=D(A' +B +C’)+E(C'+D’) +F

8.2 Draw logic block diagrams using [+], [-], and [I ] which realize
each of the Boolean functions of Exercise 8.1.

8.3 Draw logic block diagrams which realize each of the following
Boolean functions. Do not simplify first.

(a) (A+ By! +Cl' =p


(b) (A'B? 1-C. D)(A aor)!
() (A+B+C+D+E)(A’ +B’ +C'+D’)
(d) (AB + A'B’)'(A+B’)
(e) [((A+B’)’ + (C'+D)' +E]

8.4 Write the switching function f for each of the following switching
circuits:

208 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


A E’

8.5 Draw the logic block diagram corresponding to each of the switch-
ing circuits of Exercise 8.4.

8.6 Simplify the following using algebraic techniques:

(a) A(A’ + AB)


(byPABC UABGS A'B'C
(c) C(A+ BIC’)
(djs (AG) (ALEC)
(e) (AB! + A’B)’
(jpA PAB B'C
(g) AF B+C+A'B
(h) AB’ + C(A’ +B’ +C)
(i) (AB)' + (A’BC)'+A
(j) (C’'+D'+A’')(A+C+D)
(k) B+ AC+ AB+C
(l) ABC’ + E + D(ABC’ + E)

8.7 Use the truth table method to verify the following identities:

(a) (A+B)(A'+B)=B
(b) B(B+C)=B
() A(A+B+C)=A
(dy (A> BC)’ — ABC

BOOLEAN ALGEBRA 209


(e) (A’ + AB)’ = AB’
() (C2D)o+ G=C 4D!
(g) (A+B+C)(A’ +B’ +C) = AB’ + A’B+C

8.4 NORMAL FORMS FOR BOOLEAN EXPRESSIONS

An expression containing n variables is said to be in sum normal form if it is


the sum of terms each of which contains each of the n variables (in inverted
form or not).

Example. The expression AB + A’B’ is in sum normal form in the two variables
A and B. But, clearly, the expression A+ AB is not. Also, ABC + AB’C
+ A’BC’ is in sum normal form in the three variables A, B, and C. (A+C)’
+ BC is not. First we show how any expression can be put into sum normal
form. The importance and the uses of the form will become evident as we
proceed. Several examples follow which reveal the procedure.

Example. Place the expression A+B in sum normal form in the variables A
and B.
We note that the first term A does not contain the variable B. But
A=A-+1=A(B+ B’) = AB + AB’ is equivalent to A and contains terms each
of which has both of the variables A and B. Similarly, B= (A+ A’)B=
AB+A'B. The result is A+B=AB+ AB’ + AB+ A’B=AB+ AB’'+A’B,
the sum normal form.

Example. Place the expression A + B in sum normal form in the three variables
JAN, 183, aiael (C-

A=A-1-1
= A(B+B')(C+C’)
= ABC + ABC’ + AB’C + AB’C’

B=B-1-1
=B(A+A’')(C+C’)
= ABC + ABC’ + A'BC + A'BC’

Thus,

A + B= ABC + ABC’ + AB'C+.AB'C' + A'BC + A'BC’

210 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Example. Place the expression (A’ + B)’ + BC’ in sum normal form in the three
variables A, B, and C.
Applying De Morgan’s law, we have AB’ + BC’. Then

AB’ (C + C’) + (A+ A’)BC' = AB'C + AB'C’ + ABC’ + A’BC'

Consider the expression AB + AB’ + A'B+ A’B’. The sum contains


all possible two-variable terms in A and B. It is called the complete sum normal
form in two variables A and B. We note that AB+ AB’ + A’B+A’B’ =
A(B + B’) + A'(B+ B’) =A+A'=1. In general, the complete sum normal
form in 7 variables has 2” terms and always equals 1. Thus, the complete sum
normal form in three variables A, B, and C has eight terms and their sum
ere he eaD Get BiG tA BG 4a BG AB Ct AUB Cis 1,
Let us look at the terms of this last complete sum normal form. Sup-
pose we select a particular combination of values for the variables, say A= 0,
B=1, C=0. Evaluating these eight terms in order, we then have ABC =
0(1)(0) =0, ABC’ = 0(1)(1) =0, AB’C=0(0)(0) =0, AB’C' = 0(0)(1) =0,
A'BC = 1(1) (0) =0, A’BC’ = (1) (1) (1) =1, A’B’C=1(0) (0) =0, and A’B'C’ =
1(0)(1) =0. Exactly one term has value 1, the term A’BC’. All the rest have
value 0. One can easily find the term which will be 1 for any other combina-
tion of values of A, B, and C by noting that if a variable is 0, we select the term
containing that variable inverted, and if a variable is 1, we select that term
which has that variable not inverted. Thus, should A=1,B=0,C=1, then
the term AB’C is the one and only term in the complete sum normal forrn which
will have value 1. This works for any number of variables. In four variables
A, B, C, D the complete sum normal form has 16 terms, and the term A’BCD’ is
the only one which equals 1 when A= 0,B=1,C =1, and D=0.
It begins to be apparent that a function of, say, three variables A, B,
and C is completely determined when one knows for which combinations of
sets of values for A, B, and C the function has value 1. For example, suppose
that f is a function of A, B, and C and has value 1 for each set in the following
table and has value zero for all other combinations

A B Cc

1 0 0
0 1 0
0 1 1

Then f = AB’C’ + A'BC’ + A'BC.


Let us check up on this assertion. Clearly for each combination of
values given in the table, f has value 1 since for each combination one of the

BOOLEAN ALGEBRA 211


terms of f has value 1 and the other two have value 0. Thus, the sum always
equals 1. Also, for all the other eight combinations of values of A, B, and C
each of the terms of f has value 0 and thus f has value 0.
Alternately, if a function is written in sum normal! form, its truth table
is evident. For example, suppose f= A’BC + ABC’ + A’B'C’. Then

A B Cc f

0 il il 1
il 0 1
0 0 0 1

and f is 0 otherwise.
An interesting note: If f is written in sum normal form, then f’ consists
of those terms of the complete sum normal form which are not present in f.
Thus, if f= AB’ + A'B + A’B’, then f’=AB. You may check this by other
means. If the values of f are read from a truth table, then f’ consists of those
terms for which f has value 0.
There is the dual normal product form in which the function is represented
as the product of factors, each of which contains the sum of each of the vari-
ables in either inverted or noninverted form. For example, (A + B)(A’ + B’)
is in product normal form in the two variables A and B; A+ B’(A + B) is not.
Similarly, (A + B+ C’)(A' + B’ +C’')(A +B’ +C) is in product normal form;
A+ BC’ isnot. Since we shall not be making use of this form, which is equiv-
alent to the sum form for a given function f, we shall not discuss its properties
further.

EXERCISES

8.8 Place each of the following functions in sum normal form in two
variables, A and B:

(a) A
(b) “CAC Es
(@) Adar ley

8.9 Place each of the functions in Exercise 8.8 in sum normal form in
three variables, A, B, and C.

8.10 Place each of the following functions in sum normal form in three
variables, A, B, and C:

(a)-B +c’
(b) A+ B'C

212 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(A BeeB'C
(d) Cc
8.11 Place each of the following functions in sum normal form in four
variables, A, B, C, and D:

(a) BC'+D
(b) ABC + C'D
(c) A+ BCD'
(d) (AB'C)’
(ec) A+B+C+D'

8.5 SIMPLIFICATION OF BOOLEAN EXPRESSIONS: KARNAUGH MAPS

One of the most used methods to simplify Boolean functions is the Karnaugh
map. This method provides a definite procedure, a specific way, to simplify
any Boolean expression.
Recall that if f is a function of two variables, we can display it as in the
following truth table:

A B f
iT
0 0 1
0 if 0
1 0 0
1 1 1

that is, f = A’B’ + AB.


The Karnaugh map for this function is as follows:

Note the 2” = 4 squares to allow for the four possible terms in the complete
sum normal form for a function of two variables. The values of A are read
across the top, B down the left. The upper block is thus the space for A = 0,
B=0. We place a 1 in those blocks corresponding to those pairs of values
of A and B for which f has value 1. It is common practice to assume that for
all blocks left empty the function has value 0.
For three variables we shall require a map with 2?=8 blocks. The

BOOLEAN ALGEBRA 213


standard form is as follows:

A
BC Q a
OO

Omar

Let

i ©
——

Again it is clear that the importance of the sum normal form emerges. In
order to fill in the appropriate squares to represent a function, the function
must first have been expressed in sum normal form. Each block of the map
represents a certain term in the complete sum normal form. A 1 is placed in
each block which corresponds to the occurrence of a term of the sum normal
form of f.
For four variables, 16 blocks are necessary. The map is as follows:

AB
CD OG Ost ai 1
ORO

Ot

1 1

Lt @

Although we shall not use them here, Karnaugh maps can be constructed
for functions of five or six variables rather easily. Here is the map for five
variables:

A 0 1
BC BC
DE 0 Ott Sitter tO DE OO "Ud Lt ooo
O20 0 O

ap a i aaat
Pal
lope 1ae
| | | |
176 Peed

214 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


One can very easily read out the unsimplified sum normal form for f from
any
of these maps.

Example

Xo
BC
ORO
0 1
heen

ORES eel

Le: 1

ik XY a

f= AlB'C + ABC

Example

AB
CD ORO Oe ie 1 30
T ir ]

ie ie) |

0 1 | | 1

tea va es |
FPO | |

f= A'BC'D’ + AB'C'D + A'B’CD

We have two basic problems: (1) Reading into the map any function no
matter what form it is originally in, and (2) reading out the most simplified
equivalent form for f. Let us consider the first problem, first for functions of
three variables. Any function of three variables after having been freed of
all parentheses by the use of De Morgan’s law, the double complementation
law, and the distributive law, will then contain terms of three kinds: Terms
which contain only one variable, terms which contain two variables, and terms
which contain all three variables. For each of the terms containing three vari-
ables we simply mark a 1 in the corresponding square of the map. For the
two- and one-variable terms we could proceed algebraically, expanding them
to three-variable terms, that is, placing f in sum normal form. Thus, if the
term is AB, we could write AB = AB(C + C’) = ABC + ABC’ and then place a
1 in each of the squares corresponding to ABC and ABC’. However, we want

BOOLEAN ALGEBRA 215


the Karnaugh map procedure to be semiautomatic, and so instead of perform-
ing the algebra, we follow this rule: Place a 1 in each block for which A= 1,
B=1, regardless of what C is. The map would then look like this:

0 0

a) 4 earive’

hoi 1

il © 1
Ae eal

Similarly, for a term like B, we place a 1 in each block where B is 1, regardless


of what A or C is in those blocks. The map for the term B would be

A
BC 0 lia
OmO

Ome

Le ie 1

i @ | a 1

Example. Map the function f= A+ A’B’C’.


For the term A we place a 1 in every block where A is 1, that is, in every
block of the second column. For the term A’B'C’, we place a 1 in the block in
which A=0,B=0,andC=0. The map is

A
BC @ il
oy @ | 4 1

(dy al il

iho A 1

i 1

We note that a three-variable term requires only one block to display it, a two-
variable term requires two blocks, and a one-variable term requires four blocks.

Now let us turn to the mapping of functions of four variables. As be-


fore, the function will have terms involving one, two, three, or four variables.

216 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


The four-variable terms will require just one square, the three-variable terms
will be displayed in two squares, the two-variable terms will require four
squares, and the one-variable terms will require eight squares for display.
For example, the term A is read in by placing a 1 in every square in which A
is 1, regardless of what B, C, or D is. The map will appear thus:
AB
CD O20 eoOrt still e1 <0
0 Oo 1 1
aa 1 1
L |
tart 1 1
Tee 0 1 1

The term ACD will be read in by placing a 1 in two blocks, the two blocks for
which A= 1, C=1, D=1, regardless of what B is. Now consider the func-
tion f=A+CD. It maps as follows:

AB
CD OA Ora ah al ai)
0 0 | | il 1

0 1 | 1 1

We note that the two terms generate 1s in some of the same squares. A single
1 is placed in the squares where they overlap. In the example above, the A
term causes the eight 1s appearing in the third and fourth columns; the CD
term causes the four 1s appearing in the third row. They overlap in the third
and fourth columns.

Example. Plot the function f = AB + CD’ + A'B’C’D + AC'D.

COE 100 Ot, 1 desl 0


i Ss (1)
|
0 1 1 1 1

1 1 |
mil) |
1 0 il 1 il il

BOOLEAN ALGEBRA 217


You should be able to verify the entries in this table; note once again the over-
lapping of entries. The following exercise set gives you the opportunity to
sharpen your skill in plotting Boolean functions on Karnaugh maps.

EXERCISES

8.12 On a two-variable Karnaugh map, plot each of the following


functions:

CO ere
(b) f=A+t+B’
(c) f= AB! + A'B
(d) f=AB+ A’ +B’

8.13 Plot each of the following functions on a three-variable map:

(a) f=A+B
(b) f=A+BC’
(c) f= ABC’ + A'C’
(d)f=A+B'+C
(e) f= AB+A'C
+ BC’

8.14 Plot each of the following functions on a four-variable map:

(a)f=A+D
(b) f= AB+C'D + AB'C
(c) f= ABCD’ + A’ + BIC
(d) f=A+B+C+B'D+CD'
(e) f= ABCD’ + AB'C’D + A'BC'D

8.15 Plot each of the following functions on a five-variable map:

(a)f=C+D+E'
(b) f= AE + CDE
(c) f= ABCE’ + A'D + C'
(d) f= E+ (CD! + ABC + AB'CDE'
(e) f= ABC'DE + AB'C'D'E’ + A'B'CD'E
We now turn to the essential part of this section—the reading out of the
most simplified form of a function that has been plotted on a Karnaugh map.
This is equivalent, of course, to simplifying a given function, a process most
important in logic design.

218 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Given a map, we proceed to “loop” it so that all the 1s it contains are
enclosed in 1-loops, 2-loops, 4-loops, 8-loops, etc.
A 1-loop is a loop containing just one 1. For example,

We read out f = AB.


A 2-loop is a loop containing two 1s which are adjacent in one of the
following senses: They are next to each other horizontally; they are next to
each other vertically; or they lie at the ends of the same row or column. For
example,

1 0 1

Notice that when two 1s are adjacent, the terms corresponding to the 1s
differ in just one variable. For the marked two-loop, the terms are ABC’D’
and ABC’D—they differ in the D’s only. Note that ABC’D' + ABC'’D =
ABC'(D + D') = ABC’ so that this looped pair of 1s is read out as ABC’ (which
contains the same variables which did not change in the two adjacent squares).
For the bottom loop, the two terms are A’B'CD’ and AB’CD’. Thus, they add
up to B’CD’. We note that the read-out of a two-loop always contains one
less variable than the total number of variables of the map.
A 4-loop contains four 1s which are adjacent in the sense that the terms
corresponding to the four 1s contain two variables which remain constant.
Here are some examples of four-loops.
AB
CD 6 0801. 1h 1:0
0 0 (1)
a wo 1
+

ie 1
1 0 Ly

BOOLEAN ALGEBRA 219


Here A and B remain constant. The read-out is f= AB.

AB
CD COU ESa es Nu
OO
Oneal
ew
I [ 1
dye Oe t 1 1 1)

Clearly, C and D’ remain constant. Hence, f=CD’. Let us check this read-
out algebraically. First,

f—A BCD + A’ BCD - ABCD’ + ABCD’


= (AB 7 ALB 4 AB AB. )ED"
= (1)CD’
= CD'

AB
CD OOD ON ees TO
an)
Om

Here B’ and C remain constant. f= B'C.

AB
CD Ot Oe
0 0 1 il

0 il it 1

1 1

1 0

f= AC’

220 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


f= Bap:

Note that the example below is not a 4-loop; however, it is two 2-loops. Thus,
f=B'C'’D' + B'CD.

AB
CD sae ns ae ie I ar
Te mS 1G
|

0 1
tc a ieee
T) | r
Ta se |
L

It is clear that the read-out of a 4-loop contains two less variables than
the total number of variables in the map.
An 8-loop (in a map containing three or more variables) is a set of eight
1s which are adjacent in the sense that the terms corresponding to the 1s have
one variable which remains constant. Here are some examples.

AB
CD eg As Os Oe OL
0 O
T =

‘ae (a 1 1 a
Teas 1 1 Thal
tad

fae

BOOLEAN ALGEBRA 221


CD G O_O a_i SLL
oO 0} vt fe)
De sel el 1
1 a 4 1
i? 0 41) Ce

fe.
The read-out of an 8-loop contains three less variables than the total
number of variables in the map.
Note that the following is not an 8-loop:
AB
CD OO O@2 17 1
Oo OE 1 1 ig)

Pee tercs i 1 1)

It does contain two 4-loops so that the read-out is f= C’D’ + CD.


We have so far presented functions whose maps contain single two-,
four-, or eight-loops. Several of the maps contained several 2-loops or 4-loops.
We now turn to maps that in general contain several loops of the same or of
different sizes. We must learn how to most efficiently read out f. We note
immediately that the larger the loop one can use, the better. We shall restrict
ourselves to maps with at most four variables.
The general rules of procedure go like this:

1. Loop all 8-loops.


2. Proceed to the remaining uncovered 1s. Loop them with 4-loops as
long as possible. An important note: It is perfectly permissible to
have loops overlap; in fact, in many circumstances this is precisely
the procedure to follow in order to ensure that the most simplified
version of f will be read out.
3. Cover as many of the remaining 1s as possible with 2-loops.
4. Cover the rest of the 1s with 1-loops.

Then, following the read-out schemes given above, proceed to read out
the terms represented by the loops. f is the sum of such terms, and if the loops

222 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


have been judiciously applied as prescribed in these rules, the resulting f is
the most simplified equivalent version of the function. Some examples illus-
trating the use of these general rules follow.

Sy Zak

No 8-loops, no 4-loops, two 2-loops.


f=S'C+AC

Note the overlapping of the two 2-loops. It would not be correct to


encircle the two right 1s in a 2-loop and the left 1 inasingle 1-loop. If one did
this, f= AC + A'B'C could be simplified further: AC + A’B'C = C(A + A'B') =
C(A+ A’) (A +B’) =C(A + B’) = B’C+ AC, as before.

No 8-loops, one 4-loop, one 2-loop.


f=C’+AB

Again note the overlapping of the 2-loop and the 4-loop.

oe
BCU ad
6 0}@)
ch melee.

11 |@pa
inea

BOOLEAN ALGEBRA 223


No 8-loops, no 4-loops, one 2-loop, one 1-loop.
f= BE ABC

AB
Cu Wietinie Sa 30
Cael hl dhl
Cae g leis
i!
a0

No 8-loops, one 4-loop, one 2-loop.


f=A'C'
+BCD

AB
CD OO O22 Lt 1g
|
OF ec at
QO 1 a)

1 1

je ot 1D) a

No 8-loops, two 4-loops, one 2-loop.


f= BD COD er A BC
Again note the neat overlapping of loops.

01 10
o~ 0 (1) (1)
Ce are) oy
eet 8 1
1 0 1

No 8-loops, one 4-loop, four 2-loops.


f= A’B'D + A'BC’ + AB'C' + ABC + C'D

224 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


SNeAB
CD 00
OO
0 1 (|G
1 1 |
1 of
No 8-loops, three 4-loops, one 2-loop.
i PC AC FBC CD

AB
CD Te: Pee a es
0 0 |
Cm
eS
ae
O41 Muse

One 8-loop, one 4-loop, one 2-loop.


F—-b4aA.C PACD:

We now present several applications of the reading in and reading out


of functions. Suppose we read in the unsimplified function f= A+ BC’
+ A'BC’ + A'B’ and then read out the simplified version of f. To show clearly
once again how the function is read in, we present the following Karnaugh
maps:

A A A A
BC 0 1 BC a! BC 0 1 BC 0 1
0 0 1 Om 0 0 OR Om met

Ome 1 Ome oO) at OL


+ /-——— + aE =
i il 1 ie Gt eal itil

1 0 1 ik © 1 1 i @ 1 0)
a ee pee

Normally, of course, the separate terms of f are read in directly on the final map
of this sequence—here we are displaying each term’s map for initial clarity.
Then, the read-out of f from the last map is f= A+ B’+C’.

BOOLEAN ALGEBRA 225


As the final example, suppose function f = AD’ + A’CD + A'BC'D + D'
is to be simplified and then a logic circuit is to be drawn which will realize the
simplified function. First, we read in f as shown:

AB

Thus, f= D’ + A’B+ A’'C=D'+ A'(B+C). The logic diagram appears thus:

EXERCISES

8.16 Use the looping method to read out the (most) simplified version
of f if its Karnaugh map is:

(a) A (b) A (c) A


BC Qi BC Ome! BC il
0 0 1 DO |p ile jp a OROeT

Oks lal i ae) ah esi Old 1


iW aia} EN ar A) Tet im |
l @ | a ia ic0\ i
[Pe

8.17 Use the looping method to read out the simplified version of f if
its Karnaugh map is:

226 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(a) AB AB
CD GO OF al a@ (CID)
0 0 1 1 o ©

0 i 1 1 Oo 41

1 1 1 1 1 1
1

1 0 1 il it

AB (d) AB
CD oo 01 i 10 CD OO O88 2th 10
OO 1 1 ORO i
0 if 1 1 il 1 Ol 1 1 1
4
1 1 1 1 1 1 1 1 1
+

1 0 1 i © (|
a

(e) AB (f) AB
CD (OMe Onis) ele 1a0 CD
OREO 1 1 1 oe

0 1 1 1 Ome!

if 1 1

ioe 10 1 1 hy

(g) AB (h) AB
SD, ‘oe a Se) Dp
in
ORO a 1 of O @ 1 1

One! 1 1 One 1 1 1

1 1 1 1 1 L | 1

i 1 i) 1

AB (j) AB
CD CeO Geral at aE ie CD

0 60 1 1 1 0 860

Ome! it Oe il il il

1 1 1 i 1 1 1 1 1

0 1 1 1 1 1

BOOLEAN ALGEBRA 227


8.18 Recall that f’ can be read out from the Karnaugh map for f by read-
ing out those blocks that contain 0s. Follow the method of looping
but loop the 0s to read out f’ for each of the Karnaugh maps of
Exercise 8.17.

8.19 Read each of the following Boolean functions into a three-variable


Karnaugh map (without algebraically simplifying). Then read out
simplified f.

(a) f=A+ BC’ + A’BC


(b) f= ABC + AB'C’ + A'B+A
(c) f= BC! + AB + A'BC' + AB'C
(d) f=B+C+ A'BC'

8.20 Read each of the following Boolean functions into a four-variable


Karnaugh map and then read out simplified f.
(a) f=ABC’ + CD --AC'D + Dt
(b) f= A+B + BC + ABCD
(c) =A BC = ABC? A CB eC
(d) f=A + BC + A B'C+ ABCD

8.21 Write the switching function directly for each of the following
switching circuits. Read f into an appropriate Karnaugh map,
read out simplified f, and draw the corresponding simplified
switching circuit.

228 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


8.6 OTHER LOGIC BLOCKS: NAND, NOR

We have seen that any Boolean function can be realized (that is, constructed)
from the three elemental logic blocks AND, OR, and INVERTER. In fact,
however, just the two blocks AND and INVERTER are sufficient. To show
that this is so, we make good use of De Morgan’s law: (A’B’)' = (A’)' + (B')' =
A+B. Thus,

0 f=(A’ B’)’'=A+B

and A+B can be constructed using the operations of - and inversion. Ina
similar way, the blocks OR and INVERTER are sufficient, since (A' + B')'=
(A')'(B')' = AB, so that

f= AB

BOOLEAN ALGEBRA 229


o f= (A’+B’)’=AB

A set of blocks which can implement any Boolean function is said to be


functionally complete. Thus, the block set {(- | Lo} and {[+], [1}} as well as
eared I |} are functionally complete. In a sense, the last set of blocks is
more than complete, but, as we have seen, it is common practice to use this
set so as not to restrict and complicate implementation of functions.
There are single compound blocks which are functionally complete in
themselves and which have wide current use.
The first one we shall investigate is called NAND, and its logic block
will be denoted by [N-]. It has any number of inputs and one output which
is 1 only if at least one input is 0. Thus, for two variables (NAND):

A B f

0 0 1
0 i 1
1 0 1
1 1 0

from which we read (simplified) f as A’ + B’. Thus, the single NAND block
diagram
AO

is equivalent to the (compound) block

230 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


We now proceed to show that NAND is functionally complete. We
plan to do this by proving that both AND and INVERT can be implemented
using NANDs alone—since the set {|- |,| I ]}is functionally complete. First,

it is clear that Ao f=A’_ since the output

is 1 only if the input is 0. Now consider

The output of the first NAND block is A’ + B’ and that of the second block is
the inversion of its input, namely, (A’ + B’)’ which reduces to AB. Therefore,
NAND is functionally complete.
Incidentally, OR can also be implemented using NAND alone. Alge-
braically, A ++ B= (A')’ + (B’)’ so that

We can realize any Boolean function using NAND alone. For example,
consider f= A+BC’. A+BC'=(A')'’+ (B'+C)’, and we should therefore
NAND A’ and B’+C. We know how to get A’. As for B’ + C, itis B’ + (C’)’
and is thus formed by NANDing B and C’. We can easily construct C’, so

BOOLEAN ALGEBRA 231


our plan is complete. The diagram follows:

p= (A’)! + (B’ + ce)

=A+ BC’

Another often-used compound block is NOR. We shall use the block


symbol for NOR. It has any number of inputs, and the output is 1 only
if all its inputs are 0. So, for two variables, we have

Ao
N+ o ¢ and f has the following Karnaugh map:
Bo

A
B Oa
@ | i 0

i | 0

Thus, f = A’B’, the dual of A’ + B’. Again we show that NOR is functionally
complete by showing that INVERT and AND can be implemented using NOR
alone.

First, Ao N+ O A’

Then, since AB = (A’)'(B’)',

O f= (a’)' (B')' = AB

232 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


Thus, NOR is functionally complete. OR can be constructed using NOR
alone. A-+ B= (A'B’)', so

Any Boolean function can be implemented using NOR alone. Many times a
judicious use of De Morgan’s laws can reduce the number of NOR blocks nec-
essary to implement a function. Consider f= A’B+C. We could construct
this function directly by simply using developments for + and - given above.
We would then have

But now consider that A’B + C can be written as [(A’B)'C’]’ and this can be
written {[A’(B’)']’C’}. Thus we have the following circuit:

A'(B')' [A'(B’)']'C’

0 A'B+C

Other compound logic blocks are in current use. We shall introduce


some of them in the exercises that follow, but we present just one more as this
section ends. It is called EXCLUSIVE OR, and we use the logic block sym-
bol [E+]. It has two inputs A and B, and its truth table is as follows:

A
B Oe al
0 1

pti) a

BOOLEAN ALGEBRA 233


Thus, f= AB’ + A’B. EXCLUSIVE OR is not functionally complete. Note
that its output is 1 if either A or B is 1 but not if they are both 1.

EXERCISES
8.22 Recall the EXCLUSIVE OR logic block [E+ discussed above:
A

B Sle t—ef=A(+)B. Use truth tables to prove (or disprove)

that the following are identities:

(a) AD B=BQA
(b) A(B G) C) = (AB) G (AC)
(c) A+ (BGC) = (A+B) @ (A+C)

8.23 Prove that the set {[E+], |+]} is functionally complete. Assume
that constants 0 and 1 are available as inputs.

8.24 Draw a logic block diagram which realizes f = A’ + BC

(a) using NAND blocks only;


(b) using NOR blocks only;
(c) using EXCLUSIVE OR and OR blocks only.

8.25 A logic block called MAJORITY which we denote by has an


odd number of inputs. The output is 1 only if more than half the
inputs are 1 (that is, if the majority of its inputs are 1). For exam-
ple, for three inputs A, B, and C, the output is 1 if two of the inputs
are 1 or if all three are 1; it is 0 otherwise.

(a) Verify the output of the following:

Oo f=A+B

(b) Prove that the set {|MAJ ,[I} is functionally complete.


(c) Show that f= AB can be constructed using and [T], as-
suming that 0 and 1 are available as inputs.

8.26 A function f has the following Karnaugh map:

234 INTROD UCTION TO COMPUTER SCIENCE MATHEMATICS


CD OO Oia aes SiG)
0 0 1

0 1 1

1 1 1 1 1 1
| a
1 0 1 1

(a) Draw the logic circuit which realizes f using the logic blocks
Pad [eiand {1}.
(b) Draw a logic circuit using ee and only.
(c) Draw a logic circuit using only.

8.27 A logic block called IMPLICATION denoted by IMP has two in-
puts denoted by Aand B. The output is 1 unless A = 1 and B= 0.
We write algebraically A — B.
(a) Place the values of f= A-— B in a Karnaugh map and show
that f= A’ + B.
(b) Assuming that constants 0 and 1 are available as inputs, show
that is functionally complete.
(c) Draw a logic circuit which realizes f=A’ + BC using [IMP]
only.

8.7 APPLICATIONS OF BOOLEAN ALGEBRA: HALF- AND FULL-ADDERS

We now turn to some of the ways Boolean algebra and logic block circuits are
used to design circuits that perform arithmetic in the digital computer. Addi-
tion is the basic operation; binary numbers are used. Recall that the other
operations can all be reduced to addition. We first reinterpret the values 0
and 1 that Boolean variables take on. Let us now consider that when a signal
appears on a “wire” the binary digit or bit 1 is present at that input position,
and when no signal appears on a wire the binary bit 0 is present.
We first construct what is called a half-adder. It is a logic circuit which
actually adds two binary bits. Recall the arithmetic of adding binary digits:

+t or + ANS + Se
S
i oO (=)= Ooeat > So

BOOLEAN ALGEBRA 235


We have represented each sum as two digits. The rightmost digit of the sum
is called the sum digit. We clearly have the following table for the sum digit
of two digits A and B:

A
B 0 1
® |@ 1

i | at 0

From this table we read out the sum digit function fs = AB’ + A’B. We can
implement f; in various ways using the methods of Sec. 8.6. Any functionally
complete set of logic blocks can be used. We note, incidentally, that AB’ + A’B
recalls the logic block EXCLUSIVE OR, E+]. However, we shall here revert
to the more basic set {|+ iy -|,|I}}. We thus have the following logic circuit
for fs:

O fy = AB’ + A’'B

In this diagram we have repeated the inputs A and B rather than introduce
“wires’’ that cross each other.
The lefthand digit in the sum above is called the carry digit. We can
plot its values in a table:

A
B Oma
0

1 1

from which we read the carry function fc = AB. The simple logic circuit
which realizes this function appears thus:

236 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


fo
= AB

We now place both of these circuits in one circuit:

fe

fs

We now have the half-adder. This compound block is denoted thus:

where HA stands for half-adder.


We have now designed a logic circuit which is capable of adding two
binary bits.
Let us now consider the more general problem of adding two binary
numbers, as in

110111
+ 111001

BOOLEAN ALGEBRA 237


We immediately note that in order to perform this addition we shall have to
be able to add three binary bits—we have to carry over the carry digit to the
next column each time. This will lead us to the design of the full-adder.
The full-adder has three inputs, and its output is once again a sum digit
and a carry digit. The addition table for three binary bits A, B, and C leads
to the following Karnaugh map for the sum digit:

A
BC Oma
0 0 1

@) ih ia

ih 1

i @ | a

The map reveals that no simplification is possible. Thus, fs = AB’C’ + A’B’C


TTABCA A BE;
As for the carry digit, we have the following Karnaugh map:

0 0
Omi
al =a
iy
1 0 1

Using the three 2-loops, we read out fe = AC + BC+ AB. The full-adder is
denoted thus:

O fs (= AB'C’ + A'B'C + ABC + A'BC’)

O fo (= AC + BC + AB)

We now want to construct the logic block diagram for the full-adder. We
first
present a circuit drawn directly from the function for f; and fc given
above.

238 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


BOOLEAN ALGEBRA 239
This circuit makes use of six inverters, seven ANDs, and two ORs. A some-
what simpler version of this circuit can be achieved by first doing a little anal-
ysis using Boolean algebra. We note first that f¢ = A’B’C’ + AB’C’ + A'B’C
+ A'BC’. This can be found by expanding f¢ into sum normal form and then
including in f¢ all those terms of the complete sum normal form in three vari-
ables which do not appear in fe. Next, we note that

CAEL Bit ©) fa = (AEB + C) (AB Ce AB Ga ACE Ga bey


= JANIE! se PANIC! a= AVEC

This last sum is precisely f; except for the term ABC. In our new circuit we
plan to first construct f¢,as we did above. Then we shallimplement A + B+ C
and f; and, making use of the algebra just shown, implement all f; except for
the term ABC. This term will be implemented separately and addedin. This
is the new circuit:

Oie | fo

oO O
io)

We have now used just one inverter, five ANDs, and three ORs, a total of six
less of these blocks.
Our last project will be to put together a collection of adders to com-
pose a circuit which will add two binary numbers. Suppose we take two
four-digit binary numbers which we shall denote by X4Xs%2X, and Y4Ys¥oY1,

240 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


where each x; and y; is either 0 or 1. Let us denote the sum of these two num-
bers by s.$45,5.s,. Thus,

+ YaYsYo¥i
G5 iss

Example

1011
+ 1001
10100

There are many ways to construct such a circuit. We shall show two ways.
The first method uses just one full-adder over and over again. An important
facet of the process that we shall not be able to discuss is the timing and se-
quencing of the appearance of the various signals to the input of the adder.
To make this first method work properly will evidently require an elaborate
network of preliminary timing and sequencing circuits. The proper alloca-
tion of the output of the adder will also be required so as to produce the cor-
rect sum. Here is how this method works. Ata certain appropriate time t,,
the signals representing 0, x,, and y, appear at the input terminals of the full-
adder. The sum digit output s, is transmitted away and saved. At the next
appropriate time ft, (after a certain delay), the carry digit output c, is moved to
the input of the adder and at the same time the next two digit signals x, and
Y2 are inputted to the adder. Once again the sum digit s, is transmitted and
saved; once again the carry digit c, is fed into the adder together with the next
two digits x, and y;. This occurs again, after a suitable delay, at time t;. The
process is repeated until s, has been transmitted and saved. At this time the
carry digit c, is actually the sum digit s;._ It can then be transmitted as s, and
the sum 555453535, displayed. Another method would be to carry c, once again
as input to the adder and cause 0 and 0 to also be fed in as input. The output
would then be s, with carry digit 0. A pictorial view of this method follows.
Note that only one FA is used.
The second scheme uses as many full-adders as there are digits in the
sum. All the digits of both of the numbers to be added are fed in to the set
of full-adders at one time instead of sequentially. The pictorial view we have
just given can be used for this method, too. The sequencing times f; will not
appear, however. Instead, at the appropriate time t, preceding circuitry will
cause all the x; and y; and the required Os to appear at the designated input
terminals. The signals would then be held until the output signals s; appear.

BOOLEAN ALGEBRA 241


At time t;:

At time tg:

At time tg:

At time tq:

Different preliminary circuitry and five full-adders are used in this method.
The careful sequencing of sets of digits we used in the previous method is
eliminated but at the expense of supplying four additional full-adders.

EXERCISES

8.28 Design a full-adder using half-adders only.

8.29 Redesign the full-adder circuit using NAND only.

8.30 Think about how the circuit of full-adders (either version) which
adds two four-digit binary numbers could be used to subtract two
binary numbers. Recall the subtraction methods presented in
Chap. 1.

242 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


ANSWERS TO SELECTED EXERCISES

Chapter 1

1.1 (a) 1.(45) (©) 0.(571428) —(e) 8.75(0)


1.2 (a) 23/99 (c) —®/1998 (e) >14/1111 (g) 1439 (i) 7°%/s99900
is ((@)) © S< ae7 IOP =P) >< I aS) <0 5b Se 110
(O) 4x IP SB So DUS Xe 1-2 SE IO (e) 5X 107+
9 x 103
1.5 (a) 6808 (c) 75.04 —(e) 406.778
1.6 (a) 0.486247 x 104 —(c) 0.3370 X 109 _~—(e) 0.9347 x 102°
(g) —0.4785003 x 104
1.7 (a) 0.86937 +03 (co) NO L625 eee. Lo (e) 0.497 —03
1.8 (a) .486247E+04 (c) .3370E+09 —(e) .9347E+20
(g) —.4785003E+04
is Gse Os. 5 6 @2
LALO S(ayn i7es2 (c) 0.0033 (e) 985440, 985400, 985000, 990000
(g) 789.1, 790.
it (@) Ws (c) 0.0032 (e) 985430, 985400, 985000, 980000
(g) 789.0, 780.
Waive (@y 8} ET (Coe?6/7 OD (e) 138.7507 70.7
82 5.92 — 67.983
“346 13.2 70.767
1384 17,
14.186 647.8957
692.2827

243
(2) co29 (i) 89.5 104769250
3)987 335. 46.7. 13) 136.2
329, 136.2
6.389 10.47692 . . . 0.906
335.389 — 9.57
0.90692...
1.13 (a) 64280. 64300. [6]
3] 7] 2][+]0]0[5
23.75 — 575
64303.75 63725
(cman Si Slee
7) 8.27 1.181 8] 0] 8] 2] [+ [0] 0 [o
— 0.3728
0.8082
(e) 8.37 9.027 26.40 1[ 2] 4] 6] [+ Jo Jo [3 |
0.6578 17.379 4.72
9.0278 26.406 5280
18480
10560
124.6080
(g) 56.78 125.5 171.1 34.075
68.79 45.68 — 34.77 4)136.3
125.57 171.18 136.33
3] 4] 0] 7|[+]o[o[2
1.14 (a) [6]3|7]|+| 015 (c) [8{ 0] 7]|[+[o][o]
(e) [1]
2] 4][+]0]3 (gs) [3] 3]7][+]0]2
1.15 (a) [6]41712]181 (41015 () [8[ 0[ 8 [6] 0] [+]0 Jo]
(e) [12] 4[6[3][+[0[3] (g) [8] 4/1]2] 0] [4]
0] 2]

Chapter2
2.1 (a) 989 (c) 10995 (e) 425. = (g) 194 (i):317
2.2 (a) ?%/49 = 0.(591836734693879) = 0.59183
(c) 195°/3125 = 0.62688 (0) = 0.62688
(e) 2999/4096= 0.732177 . . . = 0.73217
(g) 9/243 = 0.374485 . . . = 0.37448
(i) 18/128 = 0.1015625(0) = 0.10156
2.3 (a) 11.(5) — (c):19.488(0) ~(e) 123.60351 ... = (g) 136.5(0)
(i) 1845.69822 .. .
2.5 (a) 10011110112), 213234), 10020(5) (c) 110111204), 110110(), 23346.)
(e) 10000221100(3), 355523(7), 42467 (41)

244 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


2.6 102125)
2.7 (a) 15302(¢), 212312(4), 4666;g)
(c) 1211201105), 14244(5), 2257)
(e) 100100,g), 11000001000000,.), 133104,¢)
2.8 (a) 0.00001(0110) (2), 0.002 (30) (4), 0.02 (6314) g)
(c) 0:235404335 . . .¢), 0.210(14)@, 0.130112 . . .u)
(e) 0.00(03) 5), 0.002436 . . .(@), 0.00(1434)(7)
2.9 (a) 1110101.00001(.), 100002.00112,3), 3311.00331(4)
(c) 50A4.67249(15), 3CB2.73333(13), 322C.79B42,,4)
(e) 100.02211(4), 20.12257(g), 10.285E9(44)
2.10 (a) 3123(4), 333;8), DBas) — (c): 110331.31,4), 2475.64:g), 53D.Dae)
2.11 (a) 11101011011000,) = (c):0.111111100110110;,)
(e) 111001.110111100111,)
2.12 B936)
2.14 5378)
2.15 (a) 14030) — (c) 126896042) — (e) 11101011010.)
(h) 25.14362(7)
2.16 (a) 110220203) (c) 341215%) — (e) 4780444)
2.17 (a) ‘1101101 (c) - 4023561 (e) 1234567
0101101 4060031 0543210
1 0011010 1 1113622 le epmeey
1 1 1
11011(2) 1113623;7) HPNGES
(g) 3030303
0032110
3123013
— 210320;4)
2.18 (a) 13013 (c) 4A3 (e) 4775 (g) 4432
231 _9A _ 1247 __ 302
13013 4538 42653 14414
111111 4045 24764 24401
32032 44988;,1) 1772 3010014,
103333234) 4775
6506713.)
2.19 (a) 332.2%) (c) 1256.1q@) —(e): 10112.34)
2.23 (a) Decimal Binary coded
7 0111
5 0101
12 1100#
0110
0001 0010
1 2

ANSWERS TO SELECTED EXERCISES 245


(c) Decimal Binary coded
Ee) 0111 0101
48 0100 1000
ie Pee 10114 1101#

0001
0110
0010
0110
0011
1 a 3
(e) Decimal Binary coded
[47 3 0001 0100 0111 #0011
Dee eo 1001. 0010 0100 0011
102 nantes 6 1010#%# 0110 1011#% 0110
0110 OLl0 sr
0001 0000 0111 0001 # 0110
1 0 7 1 6

Chapter 3

3.1 (a) 14 ()-14 (ec) 1% = (pg) -3


3.2 (a) x=0 (c) a=4 (e)
x= 21
3.3 p+q=-8 (c) 4x + 3y =15 (e) a?
= 37 (g) d=vt
3.4 (a) (8,0), (1,7s), (0,%s), (3,5/s), (2,2)
(c) 8 + 28:— 16 = 67 = —47 4 0
320) (a) 3% a4 = 131 (c) 10x + 201 = 2010 — 13x
3x = 140 23x = 1203
x = 305) x= 214)
3.6: (a) 1% (opie (e) 1/2 (g) 1%/s @) —V2 (k) 64
37 goa s

3.8 Y= x — 6,x=4(6 + y) 1?
3.10 f(x +h) — f(x) = 2xh + h?
ms = Oe: 4(5+ 1)
3,11 2(5)
= Yio; (e— 5 y=
é =
8 8 See tr) jd!
(1.2) ih il
=—6;h (7,5) =2—4
Lo 4
3.12 h(1,2) =—6; h (-, =)=——= ; + a;(3,0)
= =2%
3.13 G(0,0,2) = 4; G(1,0,s) = 1+ s G(—1,—1—3) =13
3.14 (a) x + 5y = 23 (c) y=1 (e) x=5
3.16 (a) m=1 (c) m=1 (e) m=0
oh
Onl7 CR So (c) y=6x+4 > (6). Se —=3y 19 =0

ard) P= 432

3.20 (b) —40°

246 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


3.21 (a) s= 29
3.22 (a) x= 2%10, y= 1/10 (c) a=10,b=—7
(e) x=—-1,y=-8,z=-2 (g) x =—48%/21, y = 10%
S123 (a) x= 11), y =—le) (c) x = 5.51), y= 0.27 (9)

3.24 (a) : '

2) 0
(c), ————4$—4+4+— x

0 2 V2
(fp) ———— + +

3.25 (a) [4,%) (c) (—~,3] (e) [3,%)


3.26 (a) x= 4 0rx=—6 (c) x= V2
Br iay per ss @) 28 @) 15 <4 Sie
(2) “/e= xs 7% (i) 8<w < 16

=o) a 2 5 uf
a oe ee ey ae i)

=3 2 Ye
(c) 9f DES FAS Y/

5.29 (a) =3:< x <3 (oc) —=2oxee = 45 (ex 41 Orn sys


3.30

Yj VY,
les

ANSWERS TO SELECTED EXERCISES 247


o sX
p

Zz
(c)

3.83 Zoiax = 51.74 occurs at x= 14%a1, y = a1


334 2 ox = 494.2 occurs at (7,%/6)

ANSWERS TO SELECTED EXERCISES 249


B30

[iS

(a) Zmin = 11 at (0,2)


(b) Zmax = 25 at (12,1)

3.38 Xi Ys eeXane XY’

=i DG ee 4a+ 4b=—10
Con 1 0 Pere 4a + 14b = —36
Me tg far Te ys y=04—2.6x
5.8 89 Boe pay
See 45-108 14a a=0.4

3.40 x y x xy

1 -2 1 -—2 ipns= Reins &


2-1 4-2 284+140b=51 ree
Rh he
5 ana 26s
2: ene
ze
eG (ee

Gy ose IS ara S
7. & S49 0035

Chapter 4

4.1 (a) integer (c) real (e) real (g) integer


4.2 (a) .678E+03 (c) .935E—05 (e) .56784E+16
4.3 (a) real (c) real (e) integer (g) real (h) integer
(kk) not acceptable (contains first character which is not alphabetic)

250 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(m) not acceptable (contains nonalphanumeric character)
(0) not acceptable (first character not alphabetic, contains nonalpha-
numeric character)
44 (a) A—(B+C)/G (Ag Ba Cy ens (6) A= B/Ce- D/E
(g) CX S)IN+K)*J)/5 (i) 3470/D**2 + 7856/(17*R)
(KL a XE XE te XS
4 (a) (R/S) **(K-+7) (ce) (X47)(Y — 6) (G) A/Ca- © D/A
(g) 6/(X*Y*Z)
4.6 (a) integer (c) mixed (e) real
4.7 (a) 15. (c) 0 (e) 16. (g) 10.
A S(a) YH 2X7) 5 (c) V= 3.14159 * R **2
(e) O= H*(V*7 + 3*W**6)/6 (2) R= (2 @-2S)i.5)5
(i) ALPHA = (4.*(BETA**2 — 4.)**1.5)/BETA
4.9 (a) A= 281.43, B = 8.267E+02, N = —25, X = 143.271, Y = 2.13997,
M= 41
(c) A= 28143.8, B= .267E+02, N=—2, X= 50143.27, Y = 1.2139,
M = 9741
4.10 (a) 1 card, 8 variables (c) 8 cards, 1 variable per card
(e) 2 cards, 4 variables per card
4.11 X = 4.72
Y =-12.73
M=7
N=-5
Z=X**2 + Y**(M+N)
Oe Fe por x MY IN) /17;
WRITE (3, 1) Z, Q
1 FORMAT (1X, 2E16.6)
END
4.14 READ (2,1) A, B, C
1 FORMAT (F9.0)
S=(A+B+4+C)/2.
AREA=(S7(S-—A)*(S— B)*(S = €))**.5
WRITE G,; 2) A,B; C
2 FORMAT (1X, 3E16.6)
WRITE (3,3) $, AREA
3 FORMAT (1X, 2E16.6)
END
AN 7 READ; 1)cA; By CX
1 FORMAT (4F6.0)
Lee UA. 6. BD) 270, 2
2 Y=xX"5
GOTOS

ANSWERS TO SELECTED EXERCISES 251


3 Y=X™*4
GO TO 5
4 Y=X"™*3
or WRITE (3, 6) Y
6 FORMAT (1X, E 13.6)
CO1O7
END
4.18 READI27 1) A, B,C
1 FORMAT (4F10.0)
Te (A B) 2273
2 BIG=B
GO TO 9
3 BIG=A
9 IF (BIG—C) 44, 44,5
44 BIG=C
5 aL (BIG=. DG Gr 7,
BIG=D
7 WRITE (3,8) BIG
8 FORMAT (1X, E13.6)
END
4.21 READ {27 1) N7R-S
1 FORMAT (14, 2F1010)
TEC N oes
Zale (R = S \e4e525
AL = 4. R35
GO TO 6
De OO aR.
3 [=567
WRITE (G, 7) I
7 FORMAT (1X, 15)
GO TO 8
6 WRITE (4,9) Z
\o FORMAT (1X, E13.6)
8 CONTINUE
END

Chapter 5

Be DIMENSION A(40)
I=]
25 READ Y(27 1) ACI)
1 FORMAT (F6.0)

252 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


I=I+1
TEL =>40) 253; 3
READ (3, 4) M
FORMAT (12)
Tee (M1) 56; 6
TEM M — 40) 777, 5
I=1
SUM = 0
SUM = SUM + A(1)
LEAT Mest
I=I+1
GO TO 10
WRITE (3, 12) SUM
FORMAT (1X, E13.6)
GO 1O713
WRITE (3,9) M
FORMAT (1X, I4)
CONTINUE
END
5.4 DIMENSION A(20), B(30)
Deseo!
READ (2,1) A(I), A(I+1)
FORMAT (2F10.0)
TPM 7) 22; 25509
I=1+2
GO TO 4
I=1
READ (2,5) B(I)
I=I+1
IF (129) _6; 67-7
I=I+1
GO TO 8
I=1
SUM = 0
SUM = SUM + A(I)
IPL = 19)°9,.97 10
I=I+1
GO TO 11
I=1
TOT=0
14 TOT = TOT + B(J)
hes 29) 5121213,

ANSWERS TO SELECTED EXERCISES 253


12 I=I+1
GO TO14
13 S$=SUM+ TOT
WRITE (3, 15) S
15 FORMAT (1X, E13.6)
END
5.6 DIMENSION G(40)
I=1
READ (2,1) G(I), G(I+1), G(I+2), G(I+3)
Ol
me FORMAT (4F10.0)
TF 33) 3,304
3 I=1+4
COMO
4 I=1
SUM = 0
8 SUM =SUM + G(I)*2
IF (I— 39) 6, 6,7
6 I=I+1
GO TO 8
7 X=SQRT(SUM)
WRITE (3,9) X
9 FORMAT (1X, E13.6)
END

ssmc=[s }°-[4 al OMMfe ol


eG ake-e-[a 3] O5¢=[anasl
use(s lea[y aoe renre=[y SF
5.8 Dxcxa=|
90
| BxE= bs 45]
150

aa ; AE lees at Ss:Gaba “alkl>


aL ee x= —1/o7, y= 61/57
PH | ill
1 Oia 4 eel S
511) AV =—7% 18 = 10 j
mae 13836
foaee ee Pe ai
5.13 (a)| 2 -1 —1 -3]-[2 —5 -3 2 -
me 2k es OF) Oar 129

254 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


0 0
0 | Thus, x=0, y=6,z=—1.
1
5.14 (a) 33. () 0
5.15 (a) 90 = (c) 0.116 = (e) 0
5.16 (a) det A=—103
6 11
(a)
ley) UF! A+B= > ; |:det(A + B) =2

=f BN)
ASB
x B= lis x B) =— 1184
4 det(A X

det A=—37, det


B= 32, det
A+ det B=—5, det A X det B=
—1184
es 4 3 a
=3 =7\| ByAy DQ =3) ail
Bose p Z en Sie a
2 7

5.19 (a)x=Mal
ie aly) le Eb)
y= ita
(0-7), (4.1), (42.0), (8-1)
eae. eagle | a =|
5.21 Let A= k a: Then A1t= ee ee |=

d —b
ad—bce ad—bce De hdd ts
=e a peo ede: ~ (ad—bc)?
ad—be deta
dd ve sad— pe

Chapter 6

F : ils} ia =
Galea) lO; (C321 (e B 13! (g) -1

Ge (aie Ss (to) (X07 —1


(c) 10x? — 11x — 6 = (5x + 2) (2x — 3) = 0; x=—4/s,
x = %/2
(e972 — 527 + 35— (9y —7) (y 5) =0;747 = Ve, y—=5
V95
6d 42 V61 (Cc) ¥2, 42" (€) Ag+ i

(ye) 0) Gps
64 (a) x=—43,x=—1 (c) = 3/19, x = Yo (e) x=27,x=1

ANSWERS TO SELECTED EXERCISES 255


6.5 (a) y= 25 = 7 (4X) =7 (2 — 4x-+4)— 28; Thus;y+3—
7(x—2)?. V(2,—-3); upward; y intercept 25; x intercepts
Se
3
=
2/2.

(ce) 128y = 63 — 16 (x2 — 42x) = 63 — 16(x* — Yau + 16) + 1;


128y — 64 =—16(x? — Yox+ Vie) =—16(x—%/4)*; thus, y— a
—VWe(x — Y4)?; V(/4,/2); downward; x intercepts %/4 and —7/4; y
intercept ®/128.
(e) y +1 = 8x — 2 =—2(x — 4x) =—2(x? — 4x + 4) + 8; thus,
7
y —7=—2(x—2)?; V(2,7); downward; x intercepts 2 + Vy |
y intercept
—I.

69) y=artey-Z
6.11 (c) f(x) = x° — 87, f(4) =—23, f(5) = 38
f(4.5) = (4.5)3 — 87 = 91.125 — 87 = 4.125
f(4.75) = 20.17
f(4.37) = —3.55
f(4.43) = —0.062
f(4.46) = 1.717
f(4.45) = 1.121
f(4.44) = 0.528
Thus, x = 4.43
6,120 (a): x =13% 315i OS Ce) ee a eo ee
right side of Newton’s formula is, therefore,

aie ame1D
33 Ves aaa?)

The iterative formula is

ee aetrelo
Japa! 3 (x? pm 1)

x,=3

We then have

256 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


and

yee 2(2 87 )ia2 15


esl er = 13)
= 2.869

so that x = 2.869.
ee H. |
6.14 x i+1 — x? wa 3 ; xy — ile Thus, Xo>= ve
4 = 1BB23) ey i: i A

a iee
X4
oo
4.475
Ros re
Sy, oa ee 4.56
7
1.24, x5=
a
4.53 = 1.241.

Thus,
x= 1.241. Check: x4+3x2—-7=0,x NF an

so that x = 1.24.
6.15 X=1.
is!
1 OS (CA ODS Ses)
I=I+1
[EAT 10) tl 72
2VVRUTEA (373) eX
3 FORMAT (1X, E13.6)
END

Chapter 7

7X (a) 3*=27,y=3. _(c) 10°= 0.001, y=—3. _ (e) 9°=3, y=0.5


7.2 (a) a@®=8,a=2 (c) a? =27,a=9.
7.3 0-18" = 0.5, —0.18h = In 0.5 + —0.693, h = 3.85 miles.
7.4 i=5e #805) = 5e57 = 5(0.00335) = 0.01675 amp.
76 X=25
I=1
5 WRITE (3,8) LX
8 FORMAT (1X, I4, E16.6)
X = (20. — EXP(X))/3.
I=I+1
IF (220) 5,5,.6
6 CONTINUE
END
78 X=25
I=1
bX (EXPO) + 3.x 20.) /(EXP(X)-3.)
I=I+1
TF 10)'575,6

ANSWERS TO SELECTED EXERCISES 257


6 WRITE (3,1)
1 FORMAT (1X, E13.6)
END
7.11 f(0.1) = 1.005
7.12 f(0.01) = 0.01000
713° f(O1 = 171052

Chapter 8

8.1 (a) A

258 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


ANSWERS TO SELECTED EXERCISES 259
8.4 (a) f=B(A'BC + B’ + A’) (A+ B)
(c) f= AE’ + (A+B)(C+D)E
8.6 (a) A(A’ + AB) = AA’ + AAB=0 + AB= AB
(c) C(A+B'C’)' =C[A'(B+C)] = A'BC+ A'C= A'C
(e) (AB! + A'B)' = (AB')'(A’B)' = (A' + B) (A+ B’) = A'B' + AB

260 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(g) A+B+C+A'B=B+C+(A+A’')(A+B) =B+C+A+B=
A+B+G
(i) (AB)' + (A'BC)’ + A=A'+B’'+A+B'+C'+A=1
(kk) B+ AC+AB C= BUI +A) + CO +A) =BEC

8.7 (a) A |B | AB | A’ || A’ B | (A+ B)(A’ +B)

ele 1 0 1 1
al || ae 1 0 0 0
OF et 1 1 1 1
O | ol 1 1 0
ce f

(c) A | B/C | A+B+C | A(A+B+C)

Oo) Ow 0 0
1 Of © 1 1
il Osi al 1 1
1 it || 6 1 1
1 Tom 1 1
0 ila iV 1 0
0 Lalo 1 0
0 | 0 1 1 0
(ioe i)
| |
(e) Aa BePAB A Al ABs) (Ala AB) 4 Ba AB’
(fi

Teil ail 1 0 1 0 0 0
fells Ola 0) 0 0 1 1 1
ON etal G 1 if 0 0 0
ON Os) 0 1 1 0 1 0
fee
eee Sie

(g)
A\B\C|A+B+C/| A‘ B’\A’ +B'| A’ +B’ +C|(A+B+C)(A’ + B’ + C)| AB’ AB) AB’ + A’B|A'B+ A'B+C

i
Gea Fe
0} 0|0 0 tae 1 1 0 ON 0 0 0

1 0; 1 1 1 1 1 0 il 1
1} 0/0
1}0}1 1 0; 1 x 1 iL 1 0 1 1

1 0/0 0 0 0 0 0 0 0
1; 1/0
if 0; 0 0 1 1 0 0 0 1
Ds
1/0 1 1 1 0 1 ‘il is
0} 1)1 1
1} 0) 1 1 if 0 1 1 1
0/ 1/0 1
iy) Gl 1 1 1 0 0 0 if
0} 0} 1 1
4 i

8.8 (a) A=A-1=A(B+ B’) = AB + AB’


(iA b ABE BoB (A+ A’) = AB AB’ + AB, AB =
Ab AR =A B

ANSWERS TO SELECTED EXERCISES 261


8.9 (a) A= (AB + AB’)(C + C') = ABC + AB'C + ABC’ + AB'C’
(c) A+B’ = ABC + AB’C + A’B’C + ABC’ + AB'C’ + A’B'C’
8.10 (a) B+ C’= (A+ A)B(C+C') +C'(A+ A’) (B + B’) = ABC
+ ABC’ + A'BC + A'BC’ + AB'C’ + A’B'C’
(c) A'B+ B/C =A'B(C + C’) + B'C(A + A’) = A’BC + ABC’
AB GAL GC
8.11 (a) BC’ +D=BC'(D+D')(A+A’) + (A+ A’) (B+B')(C+C)D=
BC’(AD + AD’ + A'D + A'D’) + (AB + AB’ + A'B + A’B’)
(CD + C’D) = ABC'D + ABC’D’ + A'BC'D + A’BC'D'
+ ABCD + AB'CD + A’BCD + A'B'CD + AB'C'D + A’B'C'D

8.13 (a) A (c) A (e) A


BC O 4 BC © @ BC Oumar:
0 0 OOM eel Oia, da
SS ae
@ a yf Oma Oil aie tan (ad
=a ee en eal
mi | a i i al oe Tom Met et

fh@) 2 a dheOh Ae ea) ih © af

8.14 (a) \.AB (c) AB


CD OO OF th De CD Oe Wak ales Aw
© @ 1 1 0 0 1 a

Omar 1 1 il 1 Oem v1 1 1
=P .

i il 1 1 1 1 th al 1 1 1

‘ee 0 1 1 10 1 1 il 1

(e) AB
CD OO) Ghat wba asd
0 0
|
® 8 1 1
aie +

ee
1

tO 1
ail

262 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


8.15 (d) a
On 1
BC
DE OO Oa Na a (0)(0) te ik @)

OF ow 1 lee 00 1 |1

0 1 1 1 1 1 01 1 1 | 1 1
t =!)

1 1 1 1 1 an 1 il ie il i

1 0 i) © 1 1

8.16 (a) f=AC'+A'C+A'B (c) f= A'B'C' + AC + BC


8.17 (a) f=BD+B'D'’ (c)f=D+A‘B'+BC’ (e) f=BC'
+ AB'D'+A'CD+A'B'C (g) f= A’B'CD’ + AC’ + BC'D’
+AB’D (i) f= AB'D' + ACD + A'BC' + B'C'D'
8.18 (a) f’=BD'+B’D (c) f'=BD'+ACD' —(e) f= A’B'C’
+BCD' + ACD+ AB/D (g) f' = A/D + BC+ A'B'C’ + ACD’
(i) f' = A'C + A’B'D + BCD’ + ABC’ + AC'D

8.19 (a) A (c) A


BC 0 il BC

0 0 1 0 0
01 1 01
en
tots Lim

see sae | a 1 0

(Ace f=AC+ BC

8.20 (a) AB
CD UL Gok sos Sey)
Ce ene! 1 1 1
4

0 1 1 1 P= Der CAA

ANSWERS TO SELECTED EXERCISES 263


ee Sa a a Oe f=C'+A'B

A
BC Om 1 A
0 0 1

GP oe em alia! f=At+C =
= re
Le et 1 a

1 0 1

(c) f= A[BC(A'B’C’ + D + AD’) + A'C'] = ABC(A’B'C' + D


+ AD’) +0= ABCD + ABCD' = ABC

(c)

A|B|c | BG)c |A+(BG)c)| A+B | At+C | (A+B)G)(A+¢)


‘iz 4 L
]
Po Lehed 0 1 1 1 0
1 pA oO 1 1 1 1 0
1 1C0-e 1 1 1 1 1 0
CeO 0 0 1 1 1 0
ON 07) 0 0 0 0 0 0
OM Oy st 1 i 0 1 1
0.) 4-1-6 1 1 1 0 1
One Ladeal 0 0 1 1 0
t pees:
Not identical Not an identity

264 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


8.24 (a) A'+BC=A' + (B'+C’)’.

A’ + (B’+C')'=A'+BC
Of

Of=A’'+BC

8.25 (a) Clearly the output is 1 only if A=1 or B=1 or both A and B
are 1. This is equivalent to A + B. (c) f= AB= (A' + B’)'’

ANSWERS TO SELECTED EXERCISES 265


8.26 f= A'B + CD + AB'C

N+ Of

AB'C
A
Ao N+ AB’

N+ N+

8127 (a). SA

=A'+B
1 1 1 f

266 INTRODUCTION TO COMPUTER SCIENCE MATHEMATICS


(c) f=A'+ BC

ANSWERS TO SELECTED EXERCISES 267


Index
Absolute value, 70-71 Coding sheets, 92-93
and inequalities, 71 Column matrix, 132
Absorption law in Boolean algebra, Comment statements in Fortran, 93
203 Common logarithms, 176-177
Accuracy of numbers, 8 Compilers, 90-91
Addition: Complex numbers, 156-157
of decimal numbers, 12 Computers:
with roundoff, 14 arithmetic-logic unit of, 89
of matrices, 133-134 basic components of, 89
of numbers to various bases, 31-33 input unit of, 89
AND logic block, 195 Conjugate of a complex number, 157
Arithmetic-logic unit of computer, 89 Constants in Fortran, 94-95
Arithmetic operations of numbers to CONTINUE statement in Fortran,
various bases, 31-46 121-122
Arithmetic statement in Fortran, 91, Control cards, 91
94-103 Control statements in Fortran, 91,
Arrays: 116-123
one-dimensional, 21, 127-129 Coordinate systems, 60-61
two-dimensional, 131-147 Counter in division operation, 43-46
Asymptote, horizontal, 174 Cramer's rule, 149-151
Curvefitting:
to exponential functions, 182-187
to lines, 82-86
B-1 complement method of
to quadratic functions, 162-165
subtraction, 35-38
Bases:
of number systems, 19
Decimal numbers:
related, 28-30
binary coding of, 47-50
Binary coding of decimal numbers,
and numbers to other bases, 24—28
47-50
system of, 2-6
Binary numbers and related bases, 29
Decimal value of nondecimal
Binary system of numbers, 19-20
numbers, 20-22
Bisection method for roots of
De Morgan’s law, 206, 211, 215
equations, 168-169
Derivative of polynomial functions,
Blanks in Fortran statements, 99
170
Boolean algebra, 193-242
Determinants, 147-148
applications of, 235-242
Diagonal matrix, 132
identities in, 197-208
Diagrams, logic block, 198-200
Digital computers, 27
basic components of, 89
Carry digit, 36 Digits, 2
Characteristic of a number, 8 DIMENSION statement in Fortran,
Cobol, 90 128-129

269
Division of numbers to various bases, Fractional part of number, 3
43-46 decimal value of, 22
using method of repeated Full-adders, 238-242
subtraction, 44—46 Functional notation, 58
Duality, principle of, 201 Functions:
exponential, 173-174
linear, 59
E specification: logarithmic, 175-177
in input, 106 polynomial, 155
in output, 109-110 of several variables, 59
Elementary row operations on
matrices, 140-145
End-around carry, 36 Ganged switches, 199
END statement in Fortran, 111 GO TO statement in Fortran, 116-117
Equation: Graph of a function, 60
definition of, 55 Graph paper, log and semilog,
matrix, 133 181-185
satisfying of, 55 Greatest integer function, 7
Error due to roundoff, 15-16 Grouping, symbols of, 56
Exclusive OR logic block, 230
Exponential functions, 173-174
Exponentiation, 54 Half-adders, 235-237
laws of, 175 Hexadecimal number system, 19
Expressions: digits of, 20
algebraic, 53-55 Hierarchy of operations, 54
integer, in Fortran, 97
mixed, in Fortran, 97
Extended precision, 15 I specification in Fortran, 106
IF statement in Fortran, 118-120
Inequalities, 69-77
F specifications in Fortran, 106, 109 linear: in one variable, 69-73
Flowcharts, 117-118 in two variables, 75-77
symbols used in, 118 Infinity, 70
Format statements in Fortran: Input-output statements in Fortran,
position in programs of, 114 91, 104-110
with READ statement, 106 Input unit of computer, 89
with WRITE statement, 108 Integer constants in Fortran, 94—95
Fortran: Integer mode in Fortran, 98
arithmetic statements in, 94-103 Integer variables in Fortran, 95—96
coding sheets for, 92-93 Integers, 3
control statements in, 116-123 Integral part of numbers, 3, 19
input and output statements in, Intercepts, 64
104-110 IBM cards, 93-94
programs in, 92, 111-114 Interval of convergence of power
Fractional decimal numbers into series, 188
other bases, 26-28 Intervals, 70

270 INDEX
Inverse matrix, 138-145 Logic blocks:
Inverter logic block, 196 AND, 195
Irrational numbers, 4, 9 exclusive OR, 233
Iterative methods, 169-172 functionally complete set of, 230
solution of equations using, IMP, 233
178-179 inverter, 196
MAJ, 232
NAND, 230
Karnaugh maps, 213-226 NOR, 232
loops in, 219-222 OR, 196
Loops in Karnaugh maps, 219-222
rules concerning, 222
rules concerning, 222
plotting function in, 215-217
reading functions out from,
218-226
Machine language, 90
standard forms of, 213-214
MAJ logic block, 234
Keypunch, 93
Mantissa of number, 8
Matrices, 131-147
addition of, 133-134
Language, machine and symbolic, column, 132
90-91 diagonal, 132
Laws of exponents, 175 elementary row operations on,
Least squares, method of, 32, 82-84, 140-145
102, 185 equivalent, 141
Line: inverse of, 138-145
fitting data to, 82-86 lower triangular, 132
point-slope form of equation of, 63 multiplication of, 134-136
slope of, 63 row, 132
slope-intercept form of equation of, scalar multiple of, 134
64 unit, 132, 142-143
two-point form of equation of, 62 upper triangular, 132
Linear equations: zero, 133
matrix solution of, 137-138 Method of least squares, 32, 82-84,
simultaneous, 65-68 102, 185
Linear functions, 59 Multiplication:
Linear inequalities, 69-77 of decimal numbers, 13
in one variable, 69-73 of matrices, 134-136
simultaneous, 73 of numbers to various bases, 39-41
solution of, 72-73
in two variables, 75-77
Linear programming, 78-81 NAND logic block, 230
Logarithmic functions, 175-179 Natural logarithms, 176-179
Logarithms, 176-177 Nested parentheses, 57
common, 176 Newton’s method for solution of
laws of, 177 equations, 169-171, 180
natural, 176 NOR logic block, 232

INDEX 271
Normal forms of Boolean expressions, Power series, 188-191
210-212 economized, 191
Number systems: Principal diagonal of a matrix, 132
bases of, 19 Principle of duality in Boolean
binary, 19 algebra, 201
decimal, 2-6 Programming:
hexadecimal, 19 Fortran, 91-123
nondecimal, 19-51 linear, 78-81
octal, 19
Numbers:
accuracy of, 9-10
Quadratic form, equations in, 160
characteristic of, 8
Quadratic formula, 158-160
complex, 156-158
Quadratic functions, 158
fractional part of, 3
integral part of, 3
irrational, 4
mantissa of, 8 Rational numbers, 14
negative, 2 READ statement in Fortran, 105
positive, 2-3 Real constants in Fortran, 94-95
rational, 4 Real numbers, 4
standard form of, 7-8 operations on, 12-16
value of, 4 Real variables in Fortran, 95-96
Related bases, 28-30
Repeated subtraction, 43-46
Octal number system, 19 Repeating decimal numbers, 3
One-dimensional arrays, 21, 127-129 Roots of polynomial equations,
sum of elements of, 127-128 167-171
Open interval, 70 by bisection method, 168-169
Operations: location of, 167-168
in Fortran, 97 by Newton’s method, 169-171
hierarchy of, 54, 97 Rounding off numbers, 10
OR logic block, 196

Semilog paper, 181-183


Parabola, 160-165 Significant figures, 8
fitting data to, 162-165 Simultaneous linear equations, 65-68
intercepts of, 162 represented by straight lines, 66
standard forms of equation of, 161 solution by method of elimination,
vertex of, 161 65-66
Parentheses, 56-57 Slash (/) specification in input, 113
Piz? Solving equations, 55, 68
Polynomial equations, 167-171 Source deck, 93
Polynomial functions, 155 Specification statements in Fortran,
derivative of, 170 93
Positional value, 5 Square root function in Fortran, 98
Positive numbers, 2-6 Standard form of number, 7

272 INDEX
Statement numbers in Fortran, 93-94 Ternary number system, 19
Straight lines, 61-64 Truncation:
equations of, 61-64 of numbers, 10
parallel, 67 of power series, 188
point-slope form of equation of, 63 Truth tables, 197, 202
slope of, 63 Two-state devices, 194
slope-intercept form of equation of,
64
two-point form of equation of, 62 Unit matrix, 132, 142-143
Subprogram statements in Fortran, 93
Subscripted variables, 21, 127
Subtraction of numbers: Value of numbers, 4-6, 20-22
method of b-1 complement, 35-38 Variables:
method of borrowing, 34 in algebra, 53
repeated, 43-46 dependent, 58
in various bases, 34-38 in Fortran, 95-96
Sum normal form of Boolean independent, 58
expressions, 210-212, 215 subscripted, 21, 127, 194
complete, 212
Summation, 84—85
Switching, 193, 199 WRITE statement in Fortran, 108-109
Switching circuits, 193-196, 206-208
series-parallel, 194-196
simplification of, using Boolean X specification in Fortran, 110
algebra, 206-208
Switching function, 194
Symmetric roundoff, 10 Zero matrix, 133

INDEX 273
7 be

a
>*

: &
: a

a ‘
*

< ¥~

~~
:

4
a
oe: i | foe hes
ee: A SeOe ~. ] OFT. CR
_. ==
| E
ly, mad
get a"we 7cp a‘a @ Se a, . ©.
D.
ab
—& A a
—y
Ot
Jy. _
ns

Sr
ey)
. >

[>

You might also like