Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
483 views

Writing simple arithmetic expressions and performing basic math operations

basic arithmetic operators are + add, - subtract, asterisk multiply, / divide. Multiplication is NEVER implied! You must use the asterisk.

Make heavy use of parentheses especially when creating fractions! If you want to compute 2X354\frac{2X3}{5-4}, enter this:

(2*3)/(5-4)
6

To do square roots, use the syntax, sqrt(). For higher roots, use fractional exponents

sqrt(16)
4
3^(1/4)
3^(1/4)

Can we get sage to write the last result using a radical sign? Answer: Any time we want to see a pretty answer, we use the show() command, by wrapping your entire calculation in parentheses. Take f'rinstance our last expression.

show(3^(1/4))
314\displaystyle 3^{\frac{1}{4}}

no radical sign, but it still looks prettier.

I wonder what sage does if you ask it to do an even root if a negative number?

show(sqrt(-2))
2\displaystyle \sqrt{-2}
simplify(sqrt(-2))
I*sqrt(2)

Sometimes you might want SAGE to round. Here's one way:

3^(1/4).n(digits=1) 3^(1/4).n(digits=2) 3^(1/4).n(digits=3) 3^(1/4).n(digits=4) 3^(1/4).n(digits=5) 3^(1/4).n(digits=25)
1.3 1.3 1.32 1.316 1.3161 1.316074012952492460819219
pi.n(digits=3)

Another way to approximate is the function, numerical_approx(). Use it like this:

show(numerical_approx(sqrt(2),digits=10))
1.414213562\displaystyle 1.414213562
︠7bf04c01-7b09-4d46-8cff-0bf401bf9778︠ ︠f198a3bc-eeb0-4090-b317-fb80968dda97︠ ︠b0de4f67-a856-4c76-975a-4134a8fe6f5e︠