| ||||||||||||||||||||
Decimal Numbers
Normally, Algebra UltimaCalc uses fractions to represent numbers that are not integers. This allows an exact representation to be stored. However, it is sometimes useful to be able to use decimals, in spite of the fact that their internal representation usually limits their precision to 128 bits, or about 38 digits.
Note that some functions are unable to handle numbers represented as decimals. One example is factors, which finds the factors of a polynomial.
decimal(expr)
This function makes a copy of the original expression, converting all fractions into decimals.
Example:
When using fractions, 2/9-0.22222222 is understood to
mean 2/9-22222222/100000000. This is simplified to give the exact
result 1/45e7
When using decimals, the expression 2/9-0.22222222 is taken as being one decimal number subtracted from another decimal number. The two numbers are converted to decimals before the subtraction is made. At maximum
display precision, the result is shown as 2.2222222222222222222222222222216135 e-9.
Some precision has been lost in the subtraction.
On the other hand, when using fractions, the expression decimal(2/9-0.22222222) is taken as one
exact fraction being subtracted from another exact fraction to give the exact result 1/45e7. This
result is passed to the function decimal which converts the exact fraction to an approximate decimal
number. There is no loss of precision in the subtraction. The result, when displayed at maximum precision,
is 2.22222222222222222222222222222222222 e-9.
evaluate(expr)
This function evaluates as much as possible, converts the result into text, and passes this text to the evaluation engine used by UltimaCalc's main window for further processing. All variables must have values, either in Algebra or in UltimaCalc. Do not confuse this function with eval.
Example:
When using fractions, taylor(sin(x), x, 0, x, 5) generates a 5th order Taylor
series for sin(x) to give the result x - 1/6*x^3 + 1/120*x^5.
If the symbol x has no value inside the Algebra module, the
expression evaluate(taylor(sin(x), x, 0, x, 5)) passes the text "x - 1/6*x^3 + 1/120*x^5" to the
UltimaCalc calculation engine. If the symbol x has the value 0.1 in UltimaCalc, the
result will be something like 0.0998334166667.
Alternatively, you could substitute the number 0.1 for x into the result
of taylor(sin(x), x, 0, x, 5). This is done by the
expression subs(taylor(sin(x), x, 0, x, 5), x=0.1), which gives the result 1198001/12e6.
eval(expr, n)
This function evaluates (simplifies) the expression, but the depth of recursive evaluation of symbols is
limited to the value of n (which has a maximum value of 20). Do not confuse this function with
evaluate.
Example:
Evaluate the following line, to assign a value to the symbol k:
k := 2*k
This is a recursive definition. Delete the line and evaluate k. If the options for
evaluation depth are at their original defaults, (10, and with
the 'None' checkbox not ticked), the result will be 1024*k. The value
of k was evaluated repeatedly until the depth limit came into effect and stopped further recursion.
Compare the following:
eval(k, 0) returns k - no evaluation of symbol values was performed.
eval(k, 1) returns 2*k - the value of k was only looked up once.
eval(k, 2) returns 4*k - the value of k was looked up, and found to
be 2*k. This expression was evaluated (the second evaluation), replacing k with
its value, yielding 2*2*k which automatically simplified to 4*k.
Similarly, eval(k, 5) returns 32*k.
