Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Possible bug in Floor function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132355] Re: Possible bug in Floor function?
  • From: Itai Seggev <itais at wolfram.com>
  • Date: Wed, 19 Feb 2014 02:00:51 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20140215090214.8888569D4@smc.vnet.net>

On Sat, Feb 15, 2014 at 04:02:14AM -0500, psycho_dad wrote:
> Hi,
> 
> I think I may have stumbled upon a possible bug in Floor. Evaluating the following gives the correct result: 
> 
> Floor[Log[10, 100.]]
> 2
> 
> Evaluating it with a replacement and //N gives a message and the wrong result:
> 
> Floor[Log[10, x]] /. x -> 100 // N
> 
> Floor::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating Floor[Log[100]/Log[10]]. >>
> 
> 1
> 
> I'm on Math 9.0 + Win7, but Math 8 gives the same (wrong) result as well. 

It's not a bug per se, but it is a somewhat unfortunate edge case.  No one has
really hit on the fundamental issue, so here it is:

In[37]:= Log[10, 100]

Out[37]= 2

In[38]:= Log[10, x]

Out[38]= Log[x]/Log[10]

Doing things symbollically has introduced an extra division.  This will come up
when trying to evaluate things numerically. 

If you introduce an arbitary precision x, it will compute to whatever precision
x is, round to 2 (of some precision), and give you that answer:

In[40]:= Floor[Log[x]/Log[10]] /. x -> 100`50

Out[40]= 2

If you give it a machine precision, it will perform the computation without
error checking, get a number slightly less than 2 due to rounding, and return 1:

In[39]:= Floor[Log[x]/Log[10]] /. x -> 100.

Out[39]= 1

When you substitue in 100, it attempts to calculate the answer to arbitrary
precision, reaches $MaxExtraPrecision, issues the message, and then returns
unevaluated: 

In[41]:= Floor[Log[x]/Log[10]] 

During evaluation of In[43]:= Floor::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating Floor[Log[100]/Log[10]]. >>

Out[41]= Floor[Log[100]/Log[10]]

When you then hit it with N, you get back to the In[39] case, and end up with 1.

One way to prevent this sort of premature evaluation which can lead to
confusing results is to use Block to temporarily reset variables at the
beginning of a computation, rather than substituting the values in at the end.
(Notice there's no mprec message, since we went streight to Log[10,100].)

In[44]:= Block[{x = 100}, Floor[Log[10, x]]]

Out[44]= 2

--
Itai Seggev
Mathematica Algorithms R&D
217-398-0700 



  • Prev by Date: NMinimize problem
  • Next by Date: Re: Minimization problem
  • Previous by thread: Re: Possible bug in Floor function?
  • Next by thread: Re: Possible bug in Floor function?