<< . .

. 11
( : 45)



. . >>

## b=7
#### 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
( : 45)



. . >>