pqpq32
(Peter Quedens)
November 10, 2014, 10:42am
1
Hello,
my question is easy to understand:
Shouldn’t Mathematica produce the same output for the following two inputs?
Log[10^3]/Log[10] // FullSimplify // N // Floor
Log[10^3]/Log[10] // N // Floor
The corresponding output of mathematica version 8 and 9 are
3 (correct) and 2 (false) respectively.
You can see the problem mathematica has, when you use RealDigits instead of floor:
Log[10^3]/Log[10] // FullSimplify // N // RealDigits gives
{{3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 1}
Log[10^3]/Log[10] // N // RealDigits gives
{{2, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9}, 1}
From my understanding a CAS-system shouldn give here the same outputs.
What do you think about it? Thanks in advance for your answer.
Peter Quedens
iamorozov1
(Ivan Morozov)
November 10, 2014, 12:19pm
2
Hi,
Shouldn’t Mathematica produce the same output for the following two inputs?
It should not, since you use N[] this kind of behavior (round off error) is normal.
I.M.
pqpq32
(Peter Quedens)
November 10, 2014, 1:12pm
3
Hi,
yes, N is used, but it is used in both expressions and so it should give the same result, since the only difference ist the FullSimplify.
In any case: I think mathematica should know , that Log[10^3]/Log[10] is 3 without a FullSimplify.
P.Q.
iamorozov1
(Ivan Morozov)
November 10, 2014, 1:28pm
4
Even it is used in both expressions it is applied to different ones:
Log[10^3]/Log[10] // FullSimplify // N // Floor // Trace
Log[10^3]/Log[10] // N // Floor // Trace
I.M.
sukrause
(Udo Krause)
November 10, 2014, 10:00pm
5
From my understanding a CAS-system shouldn give here the same outputs.
And it does so. This problem arises solely from the mindless usage of N[]
In[27]:= Union[(Floor[N[FullSimplify[Log[10^3]/Log[10]], #]] - Floor[N[Log[10^3]/Log[10], #]]) & /@ RandomReal[{1., 100.}, 1000]]
Out[27]= {0}
if you consider that a sloppy argument, look at this
In[28]:= Floor[N[FullSimplify[Log[10^3]/Log[10]], 1.]] - Floor[N[Log[10^3]/Log[10], 1.]]
Out[28]= 0
even that works
In[31]:= Floor[N[FullSimplify[Log[10^3]/Log[10]], .0]] - Floor[N[Log[10^3]/Log[10], .0]]
Out[31]= 0
and this
In[32]:= Floor[N[FullSimplify[Log[10^3]/Log[10]], 0]] - Floor[N[Log[10^3]/Log[10], 0]]
Out[32]= 0
and this
In[35]:= Floor[N[FullSimplify[Log[10^3]/Log[10]], $MachinePrecision]] - Floor[N[Log[10^3]/Log[10], $MachinePrecision]]
Out[35]= 0
You hit seemingly the only case not working
In[34]:= Floor[N[FullSimplify[Log[10^3]/Log[10]]]] - Floor[N[Log[10^3]/Log[10]]]
Out[34]= 1
despite the description in the help, that In[35] is equivalent to In[34].
iliang
(Ilian Gachevski)
November 11, 2014, 1:52am
6
Carrying out the division with machine precision numbers is subject to floating point error .
This is not specific to Mathematica at all, for example numpy gives the exact same result:
>>> a=numpy.log(1000)
>>> b=numpy.log(10)
>>> a
6.9077552789821368
>>> b
2.3025850929940459
>>> a/b
2.9999999999999996
But in Mathematica we can also use arbitrary precision arithmetic, to any desired number of digits:
N[Log[1000]/Log[10], 200]