# error in N // Floor? (corrected version)

**URL:** <https://community.wolfram.com/t/error-in-n-floor-corrected-version/3944>\
**Category:** Questions\
**Tags:** mathematica, numerical-computation\
**Created:** [November 10, 2014, 10:42am UTC](https://community.wolfram.com/t/error-in-n-floor-corrected-version/3944 "2014-11-10T10:42:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pqpq32](https://avatars.discourse-cdn.com/v4/letter/p/71c47a/32.png) [@pqpq32](https://community.wolfram.com/u/pqpq32)\
**Post date:** [November 10, 2014, 10:42am UTC](https://community.wolfram.com/t/error-in-n-floor-corrected-version/3944/1 "2014-11-10T10:42:12Z")

</div>

Hello,

my question is easy to understand:  
Shouldn’t Mathematica produce the same output for the following two inputs?

1. Log[10^3]/Log[10] // FullSimplify // N // Floor
2. 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

---

<div class="post-metadata">

**Author:** ![iamorozov1](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/iamorozov1/32/17701_2.png) [@iamorozov1](https://community.wolfram.com/u/iamorozov1)\
**Post date:** [November 10, 2014, 12:19pm UTC](https://community.wolfram.com/t/error-in-n-floor-corrected-version/3944/2 "2014-11-10T12:19:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pqpq32](https://avatars.discourse-cdn.com/v4/letter/p/71c47a/32.png) [@pqpq32](https://community.wolfram.com/u/pqpq32)\
**Post date:** [November 10, 2014, 1:12pm UTC](https://community.wolfram.com/t/error-in-n-floor-corrected-version/3944/3 "2014-11-10T13:12:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iamorozov1](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/iamorozov1/32/17701_2.png) [@iamorozov1](https://community.wolfram.com/u/iamorozov1)\
**Post date:** [November 10, 2014, 1:28pm UTC](https://community.wolfram.com/t/error-in-n-floor-corrected-version/3944/4 "2014-11-10T13:28:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sukrause](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sukrause/32/41348_2.png) [@sukrause](https://community.wolfram.com/u/sukrause)\
**Post date:** [November 10, 2014, 10:00pm UTC](https://community.wolfram.com/t/error-in-n-floor-corrected-version/3944/5 "2014-11-10T22:00:21Z")

</div>

> 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]`.

---

<div class="post-metadata">

**Author:** ![iliang](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/iliang/32/11263_2.png) [@iliang](https://community.wolfram.com/u/iliang)\
**Post date:** [November 11, 2014, 1:52am UTC](https://community.wolfram.com/t/error-in-n-floor-corrected-version/3944/6 "2014-11-11T01:52:05Z")

</div>

Carrying out the division with machine precision numbers is subject to [floating point error](http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems).

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] 

```
