Just like your pocket calculator, Mathematica can do more than simple arithmetic.
For example, if you'd like to determine the square root of 4, you can simply
do
Sqrt[4]
This is an example of the use of a Mathematica built-in function. How is a function
used differently from a binary operator?
Click here for the answer
Let's play around with Sqrt a bit more. What do you suppose will happen
if you try to take the square root of 2? Keep in mind what you already know
about Mathematica's treatment of integers.
Sqrt[2]
Since you asked a question involving an integer, Mathematica refuses to compromise
accuracy when reporting an answer. Unfortunately, the square root of two is
neither an integer or a rational number. The best that Mathematica can do is to tell
you, in effect, that the square root of two is the square root of two. If what
you really want is a floating-point approximation, pose the question with a
floating point number.
Sqrt[2.0]
As we explained in the last section, one of the benefits of complete accuracy
is that inverse functions work as you might expect. Thus
Sqrt[2.0] * Sqrt[2.0]
yields something that may not be quite 2 due to round-off error (so Mathematica returns the answer as a floating point number), but
Sqrt[2] * Sqrt[2]
yields the answer that you would expect. What do you suppose we will get if we
take the square root of the integer 8? Think about it before trying it out.
Sqrt[8]
As you should have expected we got an exact answer, but it is expressed in
lowest terms as two times the square root of two.
The more that you use Mathematica, the more you'll find it has the capacity to
surprise. What do you suppose we'll get if we take the square root of -4?
Think about it before trying it out.
Sqrt[-4]
We get a complex number as a result! Mathematica uses I to stand for the
square root of -1, as opposed to i (which is commonly used by mathematicians)
and j (which is commonly used by engineers). You can also use complex
numbers in your questions. For example, let's square I:
I*I