MathGroup Archive 2007

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

Search the Archive

Re: Problem with base 2 logs and Floor


In article <ephdk1$s2c$1 at smc.vnet.net>, 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. 

Actually, you get precision _warnings_, not errors.

> 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?

Use FullSimplify:

  r - Floor[Log[2, r]] - 1 /. r -> 8 // FullSimplify

  4

Alternatively, if r == 2^n, then simplify in general:

  FullSimplify[r - Ceiling[Log[2, r]] - 1 /.      
    r -> 2^n, Element[n, Integers]]

  -1 + 2^n - n

Cheers,
Paul

_______________________________________________________________________
Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Problem with base 2 logs and Floor
  • Next by Date: Re: Schlegel diagram
  • Previous by thread: Re: Problem with base 2 logs and Floor
  • Next by thread: Re: Problem with base 2 logs and Floor