Re: Problem with base 2 logs and Floor

*To*: mathgroup at smc.vnet.net*Subject*: [mg73020] Re: [mg73001] Problem with base 2 logs and Floor*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Mon, 29 Jan 2007 04:35:38 -0500 (EST)*Reply-to*: hanlonr at cox.net

f1[r_]:=r - Floor[Log[2, r]] - 1 f2[r_]:=r - Ceiling[Log[2, r]] - 1 Plot[{f1[r],f2[r]},{r,1,17},PlotStyle->{Blue,Red}]; Cases[Table[{r,f1[r],f2[r]},{r,1000}], x_?(#[[2]]==#[[3]]&):>x[[1]]] {1,2,4,8,16,32,64,128,256,512} Simplify[f1[2^n],Element[n, Integers]] -1 + 2^n - n Simplify[f1[2^n]==f2[2^n],Element[n, Integers]] True Bob Hanlon ---- neillclift at msn.com wrote: > Hi, > > When I use an expression like this: > > r - Floor[Log[2, r]] - 1 /. r -> 4 > > I get precision errors in Mathematica 5.2. If I use an expression like > this: > > N[r - Floor[Log[2, r]] - 1] /. r -> 4 > > I get a correct result of 1 and no errors. If I use an expression like > this I get the same result: > > N[r - Ceiling[Log[2, r]] - 1] /. r -> 4 > > This is to be expected as Floor[Log[2, r]] = Ceiling[Log[2, r]] when > r is a power of two. > Unfortunatly the expessions diverge for r=8: > > N[r - Floor[Log[2, r]] - 1] /. r -> 8 gives 5 > N[r - Ceiling[Log[2, r]] - 1] /. r -> 8 gives 4 > > How can I get exacts results for expessions like this? > Thanks. > Neill. >