Here's how you can enter your formulas. It's almost but not quite
like ordinary math notation from the textbooks; there are differences
because you have to type into input boxes instead of writing things
out freehand. For instance, to express x2+1 you type in
x^2+1
.
Adding and subtracting work as you'd expect: x+5
, 1-x
.
To multiply, use *
: 7*x
means 7 times x.
To divide, use /
: x/3
means x divided by 3.
x n is written x^n
.
The square root of x is written sqrt(x)
.
Putting all this together, here's a bigger example, a solution to the
quadratic equation:sqrt(b^2 - 4*a*c) / (2*a)
.
Feature | Syntax | Examples |
Numbers | 1 |
|
Variables | x |
|
x y | x ^ y |
|
Multiply, divide | x * y |
|
x / y |
| |
Add, subtract, negate | x + y |
|
x - y |
| |
-x |
| |
Comparison | x < y |
|
x <= y |
| |
x = y |
| |
x <> y |
| |
x >= y |
| |
x > y |
| |
Conjunction | x and y |
|
Disjunction | x or y |
|
Absolute value | abs(x) |
|
Arc-cosine | acos(x) |
|
Arc-sine | asin(x) |
|
Arc-tangent | atan(x) |
|
atan2(x, y) |
| |
Ceiling | ceil(x) |
|
Cosine | cos(x) |
|
e x | exp(x) |
|
Floor | floor(x) |
|
Conditional | if(x, y, z) |
|
Natural logarithm | log(x) |
|
Maximum | max(x, y) |
|
Minimum | min(x, y) |
|
Rounding | round(x) |
|
Sine | sin(x) |
|
Square root | sqrt(x) |
|
Tangent | tan(x) |
|
When you write a+b*c
, should that mean to add a and b, and then multiply by c? Or is it add a to the result of
multiplying b and c? In other words, which goes first, the
+
or the *
? The answer is clear if you look at the
original math notation, a+bc: the b and c go together,
then we add their product to a. What if you wanted it the other
way? In pencil-and-paper math, that'd be (a+b)c, and you can do
the same thing at the computer as (a+b)*c
. In general,
operators listed earlier in the reference manual above, like *
, come before later ones, like +
.
Write 0 < x and x < 5
, rather than 0 < x < 5
. The
latter is interpreted as (0 < x) < 5
, which first evaluates
0 < x
yielding a truth value (1 or 0 for true or false), then
compares that truth value to 5. Don't do that!
a/b*c
is not a/(b*c)
. In handwritten math notation
you could write that with a
above the division line and b*c
vertically below it, but we can't do that here: everything is
horizontal and so the program can't tell if you meant (a/b)*c
or a/(b*c)
. (It chooses the first, in fact.) When in doubt,
use parentheses.
The program does not understand sin x
, but requires sin(x)
instead. This is because, if you said sin x * y
, it'd
be uncertain whether you meant sin(x * y)
or (sin(x)) *
y
. So all the functions need parentheses; the lessened ambiguity is
worth the extra typing.
While you can refer to real numbers like pi and e and the square root
of 2, this program can't represent them exactly; it only holds onto a
fixed number of digits. For example, computing tan(pi/4)
doesn't give 1 exactly, but 0.99999999999999989. You can get
completely bogus answers if your formulas are too sensitive to these
imprecisions; there isn't space here to treat this issue.