MathGroup Archive 2007

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

Search the Archive

Re: Problem with base 2 logs and Floor

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73014] Re: Problem with base 2 logs and Floor
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Mon, 29 Jan 2007 04:11:33 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <ephdk1$s2c$1@smc.vnet.net>

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