R1 — Five minutes
Goal: see what Leonardo is for, before learning anything about it.
Open the browser REPL in another tab. There is nothing to install and nothing to configure: type the lines below at the > prompt and compare.
It is a calculator
> 2 + 3 * 4
14.0
> (1 + 2)^10
59049.0
> sin(pi/2)
1.0
Precedence, brackets and the usual constants — pi and e are built in.
Why 14.0 and not 14? Every ordinary number here is a decimal, so a whole result still prints with its decimal part. That is worth noticing now rather than wondering about later, and R8 shows how to get 14 — and exact fractions — when you want them.
It is not only a calculator
Now ask for something a calculator cannot answer:
> derive(x^2 + 3x, x)
((2.0 * x) + 3.0)
There is no value of x here, so there is no number to give. Leonardo answered with the derivative itself — an expression, not a measurement.
That is the whole idea, and it is the one thing worth taking from this lesson:
When it can compute a number it does. When it cannot, it does the algebra and hands you back an expression.
Give it numbers and it goes the other way:
> integral(sin(x), x, 0, pi)
2.0
Same command shape — integral(what, variable, from, to) — and this time everything was known, so the answer is a number.
It does work you would otherwise look up
> integral(x * exp(x), x)
((x * exp(x)) + (-1.0 * exp(x)))
> limit(sin(x)/x, x, 0)
1.0
The first is an integration by parts, chosen without being asked. The second is the standard first-year limit that 0/0 makes awkward by hand.
And it draws
plot puts a curve on the page — in the browser only, which is why this page shows the command rather than its result:
> plot sin(x) x 0 6.28
(plotted 200 points)
Type it in the tab you opened. Then try plot x^3 - 2x x -3 3. The arguments are the same shape again: what, which variable, from, to.
Try it yourself
- What is
2^10? - Differentiate
x^3with respect tox. - Integrate
cos(x)from0topi.
Answers
```text > 2^10 1024.0 > derive(x^3, x) (3.0 * (x ^ 2.0)) > integral(cos(x), x, 0, pi) 0.0 ``` *[run this session](https://lycogrypho.github.io/Leonardo/app/#s=precision%205%0Acolors%20dark%0Apretty%20off%0Alatex%20off%0Anames%20off%0Alogic%20minmax%0Alogic%20symmetric%20off%0Aexact%20precision%2030%0Aexact%20off)* The third is zero because the positive and negative halves of the cosine cancel over `0 … π`. Note that `2^10` came back as `1024.0` — the decimal point again.What you learned
- An answer is a number when one exists and an expression when it does not. Nothing failed when you got an expression back.
derive,integral,limitandplotall name the variable explicitly:derive(f, x).- Whole numbers print as
14.0, because ordinary arithmetic here is decimal. plotis browser-only.