Re: Machine arithmetics Q?
- To: mathgroup at smc.vnet.net
- Subject: [mg3678] Re: Machine arithmetics Q?
- From: Robert Knapp <rknapp>
- Date: Fri, 5 Apr 1996 02:52:24 -0500
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
Arturas Acus wrote:
> It is known, that following two formulas
> give the same result.
> I want to demonstrate, that we must calculate correct.
> That is, if we use $MachinePrecision numbers after some
> steps we will get random numbers:
> This result is ok., because we
> have positive and negative differences in calculations.
> Now I want to show, that if we will use 20 digits, and
> machine arithmetic (Not Big Numbers Arithmetic !)
> we will get chaos later. Therefore I remove Big Numbers Arithmetic:
> and perform the same calculations. What I get is quite different!
> After some iterations I get only negative deviations!
> Can anybody explain why this happens?
> I use Mathematica 2.2.1 for Windows.
This raises some good questions. I hope some of the examples and
explanation below will be informative.
In Mathematica, machine numbers and bignums (arbitrary precision numers)
are used together. Generally, when machine numbers and bignums are
mixed together, the result will be a machine number. For example:
However, this will not happen when the result (or sometimes intermediate
results) is not representable by machine numbers:
Generally, when one uses N without a second argument, machine numbers
are produced, for example,
MachineNumberQ[a = N[Sin]]
however, there is no guarantee that this will happen--for eaxmple,
N[10^1000] will not be a machine number.
Now we get into the part that is more subtle. Bignums can also be
called arbitrary precision numbers because they can (within system
limits) any precision you want. In particular they can have precision
equal to $MachinePrecision. In contrast to N, the command SetPrecision
generally produces bignums. For example, on the result from the
We get a bignum with Precision equal to $MachinePrecision.
Now suppose we set:
$MinPrecision = $MaxPrecision = $MachinePrecision
This does not preclude the possibility of bignums because they can have
this precision. In fact, sometimes bignums are produced when they would
otherwise not have been. FOr example, with this setting, the same
command I ran before gives
MachineNumberQ[a = N[Sin]]
a bit of a surprise. The reason is that the quantity you see as
$MachinePrecision is rounded. On this machine (a SPARC 5),
$MachinePrecision is 16. In actuality, the machine precision is 53
bits, which is really like 15.95 digits. This discrepancy is what
causes the above result to be a bignum with the settings for
$MinPrecison and $MaxPrecision. In some places, the rounding is taken
into account, and so this does not preclude the possiblity of using a
MachineNumberQ[b = 1.23]
and they will still appear in arithmetic results:
The real effect of setting $MinPrecsion = $MaxPrecision = const
is to have the system do fixed precision arithmetic. When const is equal
to $MachinePrecision, and your calculation gives bignums, this will be
different than machine arithmetic because bignums employ guard bits to
ensure accuracy which machine numbers do not.
My guess is that what is occurring in your calculation is that the N is
producing bignums, so you arenot using machine arithmetic.
If you want to ensure that you are using machine numebrs at each stage,
I suggest you check with MachineNumberQ in your calculations to be sure.
Wolfram Research, Inc.
==== [MESSAGE SEPARATOR] ====
Prev by Date:
Re: Mathematica on CDE
Next by Date:
Large files from Graphics!!
Previous by thread:
Machine arithmetics Q?
Next by thread:
x' times O[x]?