06.03.2017 Views

Mathematics for Computer Science

e9ck2Ar

e9ck2Ar

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

“mcs” — 2017/3/3 — 11:21 — page 213 — #221<br />

7.4. Arithmetic Expressions 213<br />

The constant function equal to 1 will satisfy (7.5), but it’s not known if another<br />

function does as well. The problem is that the third case specifies f 4 .n/ in terms<br />

of f 4 at arguments larger than n, and so cannot be justified by induction on N. It’s<br />

known that any f 4 satisfying (7.5) equals 1 <strong>for</strong> all n up to over 10 18 .<br />

A final example is the Ackermann function, which is an extremely fast-growing<br />

function of two nonnegative arguments. Its inverse is correspondingly slow-growing—<br />

it grows slower than log n, log log n, log log log n, . . . , but it does grow unboundly.<br />

This inverse actually comes up analyzing a useful, highly efficient procedure known<br />

as the Union-Find algorithm. This algorithm was conjectured to run in a number<br />

of steps that grew linearly in the size of its input, but turned out to be “linear”<br />

but with a slow growing coefficient nearly equal to the inverse Ackermann function.<br />

This means that pragmatically, Union-Find is linear, since the theoretically<br />

growing coefficient is less than 5 <strong>for</strong> any input that could conceivably come up.<br />

The Ackermann function can be defined recursively as the function A given by<br />

the following rules:<br />

A.m; n/ D 2n if m D 0 or n 1; (7.6)<br />

A.m; n/ D A.m 1; A.m; n 1// otherwise: (7.7)<br />

Now these rules are unusual because the definition of A.m; n/ involves an evaluation<br />

of A at arguments that may be a lot bigger than m and n. The definitions<br />

of f 2 above showed how definitions of function values at small argument values in<br />

terms of larger one can easily lead to nonterminating evaluations. The definition of<br />

the Ackermann function is actually ok, but proving this takes some ingenuity (see<br />

Problem 7.25).<br />

7.4 Arithmetic Expressions<br />

Expression evaluation is a key feature of programming languages, and recognition<br />

of expressions as a recursive data type is a key to understanding how they can be<br />

processed.<br />

To illustrate this approach we’ll work with a toy example: arithmetic expressions<br />

like 3x 2 C 2x C 1 involving only one variable, “x.” We’ll refer to the data type of<br />

such expressions as Aexp. Here is its definition:<br />

Definition 7.4.1.<br />

Base cases:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!