Simple Calculations

Home, Up: First Steps

 

On this page:

Basic Operators, A Few Examples, A Few Error Examples.

 

Basic Operators

You only need two things to start using Hypatia as a calculator:

First, a basic understanding of RPN, namely, that operators are written after their arguments -- see page Reverse Polish Notation (RPN).

And second, a few operators -- 8 of them are enough for now.

The operators + - * and / are obvious -- add, subtract, multiply and divide (these are 2-argument operators).

SQ means "square", SQRT means "square root", and RCP means "reciprocal value" (these are 1-argument operators).

And often useful is SUM, an n-argument operator which means, "add up everything that comes before it".

And as an afterthought, let's add the constant PI to the mix.

 

A Few Examples

The question mark followed by a space is Hypatia's input prompt. You do not type it!

 

? 3 4 +

= 7

(That was easy!)

 

? 8 5 /

= 1.6

(This, too.)

 

? 3 5 2 8 1 9 SUM

= 28

(SUM adds up all numbers to its left.)

 

? 3 5 * 2.5 4 * +

= 25

(The first * multiplies 3 with 5, the second * multiplies 2.5 with 4, and then + adds the two results.)

 

? 3 5 * 2.5 4 * 3 4 * SUM

= 37

(As above, but now we have three multiplication results -- SUM adds them up.)

 

? 3 SQ 4 SQ + SQRT

= 5

(The length of the hypotenuse -- the square of 3 is 9, the square of 4 is 16, + returns their sum 25, then SQRT draws the square root.)

 

? 3.5 SQ PI *

= 38.484510006475

(The area of a circle, with the diameter 3.5 -- SQ returns the square of 3.5, PI is the constant pi, and * multiplies the two.)

 

After each calculation, Hypatia remembers the result.

Note that just entering a single number (or a single variable or constant) is a calculation, too, which can be useful in some circumstances.

 

A Few Error Examples

We learn from our mistakes -- here are a few possible ones, with the error messages that Hypatia would give:

 

? 3 4 7 +

Error: argument count mismatch, remaining on stack: 1

(The + operator, adding 4 and 7, returns 11, this should be the result -- but there still remains a superfluous number to its left.)

 

? 3 5 * 4 * +

Error: argument(s) missing for operator +

(The first * multiplies 3 with 5, the second * multiplies the result with 4 and returns 60 -- but the + operator finds nothing to add.)

 

? 3 SQ 4 SQ - SQRT

Error: square root of negative number

(The first SQ returns 9, the second one 16, 9 minus 16 is minus 7 -- Hypatia cannot draw the square root of a negative number.)

 

Once you've gotten used to how RPN works, it is rather simple. Still, the reason for an error message may not always be obvious -- in that case you can use Hypatia's debugging mode, see next but one page "Debugging Calculations".

 

Home, Up: First Steps, Next: Chain Calculations, $ and $$