ńņš. 11 |

#### c=-3

A line that begins with ā˜##ā™ states what has deduced from the equation

it has just read; a line that begins with ā˜####ā™ states an indirect consequence of that

direct result, if some previously dependent variable has now become known.

Itā™s interesting to continue the computer experiment just begun by typing the

following lines, one at a time, and watching what happens:

aā™+bā™+.5cā™=3;

aā™-bā™-.5cā™=1;

g0=g1=g2=g3=g4;

showdependencies;

g0+g1=1;

z1-z4=z2-z5=z3-z6;

z2-z1=z3-z2=z5-z4=z6-z5;

z4=origin;

z3=(w,h);

x1=0;

y6=0;

w=2h=100;

end.

Notice that on the sixth line ( ā˜z1 ā’ z4 = Ā· Ā· Ā· ā™ ) reports four equations, but

on the next line ( ā˜z2 ā’ z1 = Ā· Ā· Ā· ā™ ) it reports only two. This happens because most of

that line is redundant, as we have already observed.

This computer session indicates that deals with two kinds of un-

known numeric variables: dependent variables and independent ones. Every

variable is independent at the beginning of its life, but every equation causes one

of the independent variables to become dependent or known. Each ā˜##ā™ line emit-

ted by tracingequations shows a newly dependent-or-known variable, together with an

equivalent expression that involves only independent variables. For example, the line

ā˜## c=-0.5b-0.5a+1.5ā™ means that variable c has just become dependent and that it

equals ā’ 1 b ā’ 1 a + 1.5, where variables b and a are independent. Similarly, ā˜## a=2ā™

2 2

means that a has just changed from independent to known. When an independent

82 Chapter 9: Equations

variable v changes to dependent or known, the equivalents of all dependent variables redundant

inconsistent

are updated so that they no longer depend on v; in this updating process some or all of

oļ¬ by x

them may change from dependent to known, whereupon a ā˜####ā™ line will be printed. division

linear dependencies

When reads a numeric equation it replaces all known variables

by their numeric values and all dependent variables by their equivalents. The

resulting equation can be converted into the form

c1 v1 + Ā· Ā· Ā· + cm vm = Ī±

where the cā™s are nonzero constants and the vā™s are independent variables; Ī± is a numeric

constant that might be zero. If some ck is so small that it probably would have been

zero in a calculation free of rounding errors, it is replaced by zero and the corresponding

vk is removed from the equation. Now if m = 0, the equation is considered to be either

redundant (if Ī± is zero or extremely small) or inconsistent (otherwise). But if m > 0,

chooses an independent variable vk for which ck is maximum, and rewrites

the equation in the form

## vk = (Ī± ā’ c1 v1 ā’ Ā· Ā· Ā· ā’ ckā’1 vkā’1 ā’ ck+1 vk+1 ā’ Ā· Ā· Ā· ā’ cm vm )/ck .

Variable vk becomes dependent (if m > 1) or known (if m = 1).

Inconsistent equations are equations that have no solutions. For example,

if you say ā˜0 = 1ā™, will issue an error message saying that the

equation is āoļ¬ by 1.ā A less blatant inconsistency arises if you say, e.g, ā˜a = b + 1;

b = c + 1; c = a + 1ā™; this last equation is oļ¬ by three, for the former equations imply

that c = b ā’ 1 = a ā’ 2. The computer will simply ignore an inconsistent equation when

you resume processing after such an error.

Redundant equations are equations that say nothing new. For example, ā˜0 = 0ā™

is redundant, and so is ā˜a = b + cā™ if you have previously said that c = a ā’ b.

stops with an error message if you give it a redundant equation between

two numeric expressions, because this usually indicates an oversight in the program.

However, no error is reported when an equation between pairs leads to one or two

redundant equations between numerics. For example, the equation ā˜z3 = (0, h)ā™ will

not trigger an error message when the program has previously established that x3 = 0

or that y3 = h or both.

Sometimes you might have to work a little bit to put an equation into a form

that can handle. For example, you canā™t say

x/y = 2

when y is independent or dependent, because allows division only by known

quantities. The alternative

x = 2y

says the same thing and causes the computer no diļ¬culties; furthermore it is a correct

equation even when y = 0.

ā™s ability to remember previous equations is limited to ālinearā

dependencies as explained above. A mathematician might want to introduce

the condition x ā„ 0 by giving an equation such as ā˜x = abs xā™; but is

Chapter 9: Equations 83

incapable of dealing with such a constraint. Similarly, canā™t cope with an absolute value

ļ¬‚oor

equation like ā˜x = ļ¬‚oor xā™, which states that x is an integer. Systems of equations that

hash hash hash

involve the absolute value and/or ļ¬‚oor operation can be extremely diļ¬cult to solve, showdependencies

and doesnā™t pretend to be a mathematical genius. line, point to be on

whatever

The rules given earlier explain how an independent variable can become de-

pendent or known; conversely, itā™s possible for a dependent variable to become

independent again, in unusual circumstances. For example, suppose that the equation

a + b + 2c = 3 in our example above had been followed by the equation d = b + c + a/4.

Then there would be two dependent variables,

## c=-0.5b-0.5a+1.5

## d=0.5b-0.25a+1.5

Now suppose that the next statement is ā˜numeric aā™, meaning that the old value of

variable a should be discarded. canā™t simply delete an independent variable

that has things depending on it, so it chooses a dependent variable to take aā™s place;

the computer prints out

### 0.5a=-0.5b-c+1.5

meaning that 0.5a will be replaced by ā’c ā’ 1 b + 3 in all dependencies, before a is

2 2

discarded. Variable c is now independent again; ā˜showdependenciesā™ will reveal that

the only dependent variable is now d, which equals 0.75b + 0.5c + 0.75. (This is

correct, for if the variable a is eliminated from the two given equations we obtain

4d = 3b + 2c + 3.) The variable chosen for independence is one that has the greatest

coeļ¬cient of dependency with respect to the variable that will disappear.

A designer often wants to stipulate that a certain point lies on a certain

line. This can be done easily by using a special feature of plain

called ā˜whatever ā™, which stands for an anonymous numeric variable that has a diļ¬erent

unknown value each time you use it. For example,

z1 = whatever [z2 , z3 ]

states that point 1 appears somewhere on the straight line that passes through points

2 and 3. (The expression t[z2 , z3 ] represents that entire straight line, as t runs through

all values from ā’ā to +ā. We want z1 to be equal to t[z2 , z3 ] for some value of t, but

we donā™t care what value it is.) The expression ā˜whatever [z2 , z3 ]ā™ is legal whenever the

diļ¬erence z2 ā’ z3 is known; itā™s usually used only when z2 and z3 are both known, i.e.,

when both points have been determined by prior equations.

Here are a few more examples of equations that involve ā˜whatever ā™, together

with their translations into English. These equations are more fun than the

ātameā ones we considered at the beginning of this chapter, because they show oļ¬ more

of the computerā™s amazing ability to deduce explicit values from implicit statements.

Equation Translation

The angle between points 4 and 5 will be 30ā—¦

z5 ā’ z4 = whatever ā— dir 30

above the horizon. (This equation can also

be written ā˜z4 = z5 + whatever ā— dir 30ā™, which

states that point 4 is obtained by starting at

84 Chapter 9: Equations

point 5 and moving by some unspeciļ¬ed mul- dir

parallel

tiple of dir 30.)

intersection

perpendicular

z7 ā’ z6 = whatever ā— (z3 ā’ z2 ) The line from point 6 to point 7 should be unknown quantities, nonnumeric

parallel to the line from point 2 to point 3.

penpos8 (whatever , 60) The simulated pen angle at point 8 should

be 60 degrees; the breadth of the pen is un-

speciļ¬ed, so it will be determined by other

equations.

EXERCISE 9.4

If z1 , z2 , z3 , and z4 are known points, how can you tell to compute

the point z that lies on the intersection of the lines z1 . . z2 and z3 . . z4 ?

EXERCISE 9.5

Given ļ¬ve points z1 , z2 , z3 , z4 , and z5 , explain how to compute z on the line

z1 . . z2 such that the line z . . z3 is parallel to the line z4 . . z5 .

EXERCISE 9.6

What equation says that the line between points 11 and 12 is

perpendicular to the line between points 13 and 14?

EXERCISE 9.7

(For mathematicians.) Given three points z1 , z2 , and z3 , explain how to

compute the distance from z1 to the straight line through z2 and z3 .

EXERCISE 9.8

(For mathematicians.) Given three points z1 , z2 , z3 , and a length l, explain

how to compute the two points on the line z2 . . z3 that are at distance l from z1 .

(Assume that l is greater than the distance from z1 to the line.)

EXERCISE 9.9

The applications of whatever that we have seen so far have been in equations

between pairs of numeric values, not in equations between simple numerics. Explain

why an equation like ā˜a + 2b = whatever ā™ would be useless.

All of the equations so far in this chapter have been between numeric expres-

sions or pair expressions. But actually allows equations between

any of the eight types of quantities. For example, you can write

s1="go"; s1&s1=s2

if s1 and s2 are string variables; this makes s1 = "go" and s2 = "gogo". Moreover, the

subsequent equations

s3=s4; s5=s6; s3=s5; s4=s1&"sh"

will make it possible for the machine to deduce that s6 = "gosh".

But nonnumeric equations are not as versatile as numeric ones, because -

does not perform operations on unknown quantities of other types. For

example, the equation

"h"&s7="heck"

Chapter 9: Equations 85

cannot be used to deļ¬ne s7 = "eck", because the concatenation operator & works only concatenation

ALLEN

with strings that are already known.

ORWELL

After the declaration ā˜string s[]ā™ and the equations ā˜s1=s2=s3ā™, the statement

ā˜show s0ā™ will produce the result ā˜unknown string s0ā™; but ā˜show s1ā™ will

produce ā˜unknown string s2ā™. Similarly, ā˜show s2ā™ and ā˜show s3ā™ will produce ā˜unknown

string s3ā™ and ā˜unknown string s1ā™, respectively. In general, when several nonnumeric

variables have been equated, they will point to each other in some cyclic order.

Let āXā equal my fatherā™s signature.

ā” FRED ALLEN, Vogues (1924)

ALL ANIMALS ARE EQUAL

BUT SOME ANIMALS ARE MORE EQUAL THAN OTHERS

ā” GEORGE ORWELL, Animal Farm (1945)

(page 86)

10

Assignments

Chapter 10: Assignments 87

Variables usually get values by appearing in equations, as described in the pre- :=

colon-equal

ceding chapter. But thereā™s also another way, in which ā˜:=ā™ is used instead of ā˜=ā™. assignment

For example, the io.mf program in Chapter 5 said declarative versus imperative

imperative versus declarative

stem# := trial_stem * pt#

when it wanted to deļ¬ne the value of stem#.

The colon-equal operator ā˜:=ā™ means ādiscard the previous value of the

variable and assign a new oneā; we call this an assignment operation. It was

convenient for io.mf to deļ¬ne stem# with an assignment instead of an equation,

because stem# was getting several diļ¬erent values within a single font. The

alternative would have been to say

numeric stem#; stem# = trial_stem * pt#

(thereby speciļ¬cally undeļ¬ning the previous value of stem# before using it in an

equation); this is more cumbersome.

The variable at the left of ā˜:=ā™ might appear also in the expression on

the right. For example,

code := code + 1

means āincrease the value of code by 1.ā This assignment would make no sense

as an equation, since ā˜code = code + 1ā™ is inconsistent. The former value of

code is still relevant on the right-hand side when ā˜code + 1ā™ is evaluated in this

example, because old values are not discarded until the last minute; they are

retained until just before a new assignment is made.

EXERCISE 10.1

Is it possible to achieve the eļ¬ect of ā˜code := code + 1ā™ by using equations and

numeric declarations but not assignments?

Assignments are permitted only when the quantity at the left of the ā˜:=ā™

is a variable. For example, you canā™t say ā˜code+1:=codeā™. More signiļ¬cantly,

things like ā˜(x,y):=(0,0)ā™ are not permitted, although you can say ā˜w:=(0,0)ā™

if w has been declared to be a variable of type pair. This means that a state-

ment like ā˜z1:=z2ā™ is illegal, because itā™s an abbreviation for the inadmissible

construction ā˜(x1,y1):=(x2,y2)ā™; we must remember that z1 is not really a

variable, itā™s a pair of variables.

The restriction in the previous paragraph is not terribly signiļ¬cant, be-

cause assignments play a relatively minor rĖle in

o programs. The

best programming strategy is usually to specify equations instead of assignments,

because equations indicate the relationships between variables in a declarative

manner. A person who makes too many assignments is still locked into the habits

of old-style āimperativeā programming languages in which it is necessary to tell

the computer exactly how to do everything; ā™s equation mechanism

liberates us from that more complicated style of programming, because it lets

the computer take over the job of solving equations.

88 Chapter 10: Assignments

The use of assignments often imposes a deļ¬nite order on the statements internal quantities

equation

of a program, because the value of a variable is diļ¬erent before and after an =

assignment takes place. Equations are simpler than assignments because they assignment

:=

can usually be written down in any order that comes naturally to you. right-hand side

Assignments do have their uses; otherwise wouldnā™t bother variables, reinitializing

reinitializing

with ā˜:=ā™ at all. But experienced programmers introduce assign- independent variables

ments sparinglyā”only when thereā™s a good reason for doing soā”because equa- numeric

tions are generally easier to write and more enlightening to read.

ā™s internal quantities like tracingequations always have known nu-

meric values, so thereā™s no way to change them except by giving assignments.

The computer experiment in Chapter 9 began with

\tracingequations:=tracingonline:=1;

this illustrates the fact that multiple assignments are possible, just like multiple equa-

tions. Here is the complete syntax for equations and assignments:

equation ā’ā’ expression = right-hand side

assignment ā’ā’ variable := right-hand side

right-hand side ā’ā’ expression | equation | assignment

Notice that the syntax permits mixtures like ā˜a + b = c := d + eā™; this is the same as

the assignment ā˜c := d + eā™ and the equation ā˜a + b = cā™.

In a mixed equation/assignment like ā˜a + b = b := b + 1ā™, the old value of b

is used to evaluate the expressions. For example, if b equals 3 before that

statement, the result will be the same as ā˜a + 3 = b := 3 + 1ā™; therefore b will be set

to 4 and a will be set to 1.

EXERCISE 10.2

Suppose that you want variable x3 to become ālike new,ā completely indepen-

dent of any value that it formerly had; but you donā™t want to destroy the values of x1

and x2 . You canā™t say ā˜numeric x[ ]ā™, because that would obliterate all the xk ā™s. What

can you do instead?

EXERCISE 10.3

Apply to the short program

string s[ ]; s1 = s2 = s3 = s4 ; s5 = s6 ; s2 := s5 ; showvariable s;

and explain the results you get.

If other variables depend on v when v is assigned a new value, the other

variables do not change to reļ¬‚ect the new assignment; they still act as if

they depended on the previous (unknown) value of v. For example, if the equations

ā˜2u = 3v = wā™ are followed by the assignment ā˜w := 6ā™, the values of u and v wonā™t

become known, but will still remember the fact that v = .66667u. (This

is not a new rule; itā™s a consequence of the rules already stated. When an independent

variable is discarded, a dependent variable may become independent in its place, as

described in Chapter 9.)

Chapter 10: Assignments 89

EXERCISE 10.4 MULFORD

NAUR

Apply to the program

tracingequations := tracingonline := 1;

a = 1; a := a + b; a := a + b; a := a + b;

show a, b;

and explain the results you get.

At ļ¬rst his assignment had pleased,

but as hour after hour passed

with growing weariness,

he chafed more and more.

ā” C. E. MULFORD, Hopalong Cassidy (1910)

left part ::= variable :=

left part list ::= left part | left part list left part

assignment statement ::= left part list arithmetic expression |

left part list Boolean expression

ā” PETER NAUR et al., Report on the Algorithmic language ALGOL 60 (1960)

(page 90)

11

Magniļ¬cation

and

Resolution

Chapter 11: Magniļ¬cation and Resolution 91

A single program can produce fonts of type for many diļ¬erent kinds resolution

cheapo

of printing equipment, if the programmer has set things up so that the resolution luxo

can be varied. The āplain ā base ļ¬le described in Appendix B estab- mode

mode setup

lishes a set of conventions that make such variability quite simple; the purpose pt

of the present chapter is to explain those conventions. mm

magniļ¬ed

For concreteness letā™s assume that our computer has two output devices. TeX

One of them, called cheapo , has a resolution of 200 pixels per inch (approximately

8 per millimeter); the other, called luxo , has a resolution of 2000 pixels per inch.

We would like to write programs that are able to produce fonts for

both devices. For example, if the ļ¬le newface.mf contains a program for a new

typeface, weā™d like to generate a low-resolution font by invoking with

\mode=cheapo; input newface

and the same ļ¬le should also produce a high-resolution font if we start with

\mode=luxo; input newface

instead. Other people with diļ¬erent printing equipment should also be able to

use newface.mf with their own favorite mode values.

The way to do this with plain is to call mode setup near

the beginning of newface.mf; this routine establishes the values of variables like

pt and mm , which represent the respective numbers of pixels in a point and a

millimeter. For example, when mode = cheapo , the values will be pt = 2.7674

and mm = 7.87402; when mode = luxo , they will be pt = 27.674 and mm =

78.74017. The newface.mf program should be written in terms of such variables,

so that the pixel patterns for characters will be about 10 times narrower and

10 times shorter in cheapo mode than they are in luxo mode. For example, a

line thatā™s drawn from (0, 0) to (3mm , 0) will produce a line thatā™s about 23.6

pixels long in cheapo mode, and about 236.2 pixels long in luxo mode; the former

line will appear to be 3 mm long when printed by cheapo , while the latter will

look 3 mm long when printed by luxo .

A further complication occurs when a typeface is being magniļ¬ed; in

such cases the font does not correspond to its normal size. For example, we might

want to have a set of fonts for cheapo that are twice as big as usual, so that users

can make transparencies for overhead projectors. (Such output could also be

reduced to 50% of its size as printed, on suitable reproduction equipment, thereby

increasing the eļ¬ective resolution from 200 to 400.) TEX allows entire jobs to

be magniļ¬ed by a factor of 2 if the user says ā˜\magnification=2000ā™; individual

fonts can also be magniļ¬ed in a TEX job by saying, e.g., ā˜\font\f=newface

scaled 2000ā™. The standard way to produce a font with two-fold magniļ¬cation

using the conventions of plain is to say, e.g.,

\mode=cheapo; mag=2; input newface;

this will make pt = 5.5348 and mm = 15.74803.

92 Chapter 11: Magniļ¬cation and Resolution

The mode setup routine looks to see if mag has a known value; if not, mag

proof

it sets mag = 1. Similarly, if mode is unknown, mode setup sets mode = proof . pc

Plain also computes the values of several other dimension- in

bp

oriented values in addition to pt and mm , corresponding to the dimensions that cm

are understood by TEX. Here is the complete list: dd

cc

dimensions

pt printerā™s point (72.27 pt = 1 in)

ad hoc dimensions

pc pica (1 pc = 12 pt) sharped

hash

ńņš. 11 |