Re: Floor doesn't compute in some cases

*To*: mathgroup at smc.vnet.net*Subject*: [mg83379] Re: Floor doesn't compute in some cases*From*: "David W.Cantrell" <DWCantrell at sigmaxi.net>*Date*: Sun, 18 Nov 2007 04:59:32 -0500 (EST)*References*: <fhjqkk$3gq$1@smc.vnet.net> <fhmgg0$9q1$1@smc.vnet.net>

Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com> wrote: > Valeri Astanoff wrote: > > > Floor doesn't compute in some cases: > > > > Floor[Log[31]/Log[2]] > > > > 4 > > > > ok, but: > > > > Floor[Log[32]/Log[2]] > > > > Floor::meprec: Internal precision limit $MaxExtraPrecision = 50.` > > reached while evaluating Floor[Log[32]/Log[2]]. >> > > > > Floor[Log[32]/Log[2]] > > > > $Version > > > > 6.0 for Microsoft Windows (32-bit) (June 19, 2007) > > > > I don't see the reason why... > > Looking at In/Out[1], we can see that Log[32]/Log[2] is not simplified > to 5, and that we need to use FullSimplify or N to get this value. > Obviously Floor does not call either functions and uses arbitrary > precision arithmetic to compute its result. (And arbitrary precision > fails, this is the meaning of the error message.) > > In[1]:= {Identity[#], N[#], Simplify[#], FullSimplify[#], Floor[#]} &[ > Log[32]/Log[2]] > > During evaluation of In[1]:= Floor::meprec: Internal precision limit \ > $MaxExtraPrecision = 50.` reached while evaluating \ > Floor[Log[32]/Log[2]]. >> > > Out[1]= {Log[32]/Log[2], 5., Log[32]/Log[2], 5, > Floor[Log[32]/Log[2]]} > > So to get the expected result, we must force the evaluation or > simplification of the logarithms before calling Floor. I suppose that's true. However, note that (at least in version 5.2) as an alternative to your In[3] below, we may instead use FullSimplify _outside_ of Floor: In[7]:= FullSimplify[Floor[Log[32]/Log[2]]] Floor::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating Floor[Log[32]/Log[2]]. Out[7]= 5 But I prefer Floor[FullSimplify[]] since it generates no warning. > Note that even > though N returns a machine-precision number, 5., the answer returned by > Floor is still an exact (infinite-precision) number. > > In[2]:= Floor[N[Log[32]/Log[2]]] > > Out[2]= 5 As Bob H. already noted, using N in this way is perilous. I would suppose that we could just a easily have gotten 4 as the result. > In[3]:= Floor[FullSimplify[Log[32]/Log[2]]] > > Out[3]= 5 Another option is to use the fact that Log[x]/Log[2] is just the binary logarithm of x: In[6]:= Floor[Log[2, 32]] Out[6]= 5 and so we get no warning message and there is no need to invoke Simplify. David