Group Abstract Group Abstract

Message Boards Message Boards

0
|
2K Views
|
4 Replies
|
1 Total Like
View groups...
Share
Share this post:

Replacing Module with Block without scoping issues?

I am wondering if I could safely replace Module with the Block scoring construct without having scoping issues in this function that computes the number of trailing zeroes in the factorial in arbitrary bases.

factorialZeros[n_Integer, b_Integer] /; n > 1 && b > 1 := 
 Module[{pfacs, pexpons},
  {pfacs, pexpons} = Transpose[FactorInteger[b]];
  Min[Floor[
    Map[Sum[Floor[n/#^j], {j, Floor[Log[#, n]]}] &, pfacs]/pexpons]]
  ]

I try to use Block because it's faster than Module.

POSTED BY: Peter Burbery
4 Replies

My point is that you are proposing a speed optimization that will be unlikely to serve any practical purpose. The code inside a scoping construct is almost always the slow part as compared to the overhead of the construct.

POSTED BY: Daniel Lichtblau
POSTED BY: Peter Burbery

No, I learned this at a Wolfram Study Group.

POSTED BY: Peter Burbery
POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard