<!-- PDF page 60 -->

## Chapter 9 – Mathematical Functions

This chapter deals with the mathematics that the *ZX Spectrum Next* can handle. Quite possibly you will never have to use any of this at all, so if you find it too heavy going, don't be afraid of skipping it. It covers the operation ↑ (raising to a power), the functions **EXP** and **LN**, and the trigonometrical functions **SIN**, **COS**, **TAN** and their inverses **ASN**, **ACS**, and **ATN**.

### ↑ and EXP

You can raise one number to the power of another – that means: *multiply the first number by itself the second number of times*. This is normally shown by writing the second number just above and to the right of the first number like so **2³**; but since this gets unnecessarily complex to write and display on a computer, we use the symbol ↑ instead. For example, the powers of 2 are:

<table>
<tbody>
<tr><td>2↑1=2</td><td></td></tr>
<tr><td>2↑2=2*2=4</td><td>(2 squared)</td></tr>
<tr><td>2↑3=2*2*2=8</td><td>(2 cubed)</td></tr>
<tr><td>2↑4=2*2*2*2=16</td><td>(2 to the fourth power)</td></tr>
</tbody>
</table>

Thus at its most elementary level, a↑b means *a multiplied by itself b times*, but obviously this only makes sense if *b* is a positive whole number. To find a definition that works for other values of *b*, we consider the rule:

a↑(b+c) = a↑b*a↑c

(Notice that we give ↑ a higher priority than **\*** and / so that when there are several operations in one expression, the ↑s are evaluated before the <strong>*</strong>s and /s.) You should not need much convincing that this works when *b* and *c* are both positive whole numbers; but if we decide that we want it to work even when they are not, then we find ourselves compelled to accept that:

<table>
<tbody>
<tr><td>a↑0</td><td>=</td><td>1</td></tr>
<tr><td>a↑(-b)</td><td>=</td><td>1/a↑b</td></tr>
<tr><td>a↑(1/b)</td><td>=</td><td>the <em>b</em>ₜₕ root of <em>a</em>, which is to say, <em>the number that you have to multiply by itself b times to get a</em>.</td></tr>
</tbody>
</table>

and:

a↑(b*c) = (a↑b)↑c

If you have never seen any of this before then don't try to remember it straight away; just remember that:

a↑(-1) = 1/a

and:

a↑(1/2) = **SQR a**

and maybe when you are familiar with these the rest will begin to make sense.

Experiment with all this by trying this program:

```
10 INPUT a,b,c
20 PRINT a↑(b+c),a↑b*a↑c
30 GO TO 10
```

Of course, if the rule we gave earlier is true, then each time round the two numbers that the computer prints out will be equal. (Note – because of the way the computer works out ↑, the number on the left – *a* in this case – must never be negative.)

