![]() |
|
|
#1 |
|
Aug 2002
26·5 Posts |
Hello all,
Recently I've tried to implement the IBDWT algorithm, with a mind to use it to perform the Lucas-Lehmer algorithm. I know any such implementation would probably be slow, but I'd like to learn how to perform it. I used the pseudocode found in "Prime Numbers: A Computational Perspective" by Pomerance as a guide. However I seem to have run in a couple problems, one conceptual, one a bug. The conceptual problem is that the algorithm seems to be performing squarings mod 2^p, instead of mod (2^p)-1. I think I've missed something in the description. The second I think is a bug. After a couple iterations, the square of the sum-in and the sum-out start to no longer match, and I get garbage results. I've wracked my brain trying to figure out what's causing it, but to no avail. (I'm sure it's something stupid I've overlooked) I'd appreciate it if anyone with some knowledge of the workings of the transformation could briefly look over my code and see if they spot any errors. I'd appreciate it. Here it is: http://cs-people.bu.edu/coldfury/fft.cpp Thanks! |
|
|
|
|
|
#2 |
|
P90 years forever!
Aug 2002
Yeehaw, FL
2×53×71 Posts |
My 10 second review:
1) Expecting square sum inputs to be equal to sum outputs plus-or-minus 0.1 may be unrealistic, depending on how many bits you are putting in each double. 2) Use a more accurate value of PI. Good luck. FFTs are a nightmare to debug. |
|
|
|
|
|
#3 |
|
Aug 2002
26×5 Posts |
Thanks!
I think I've fixed the sumin/sumout bug. I think I was adding the sums at the wrong time. Before I was computing sumin before multiplying the weights in the forward transform, and the sumout after diving out the weights in the inverse transform. I discovered today that if you take the sumin after multiplying by the weights in the forward, and the sumout before dividing out the weights, they seem to match. I'm not sure if this is the proper way, but they always seem to match. Speaking of bits in the doubles, right now I've got it set to 30 bits per double, but I have a feeling I could go higher. Is there any rule of thumb for the maximum number of bits you can use in a double as the base? Unfortunately, I still have the problem with the mod not being done correctly. In the degenerate case where the signal only has one element, the number is being done mod 2^p, instead of mod 2^p-1. If the signal has more than one element, the number seems to end up somewhere between mod 2^p and mod 2^p-1. I suspect the reason is because I'm skipping a step in the pseudo-code, mainly because the step is quite ambiguous, and I don't know what it means. The pseudo-code is as follows: <right after "modular reduction", z is the signal we're working with, and q=2^p-1> "z = z mod q" Now I thought the whole point of the IBWDT is that the mod is done automatically? In that case, why must it be reduced explicitely as well, after we've already performed the modular reduction? I suspect once I understand what that ambiguous line means, I can get it working. |
|
|
|
|
|
#4 | |||
|
∂2ω=0
Sep 2002
República de California
103×113 Posts |
Quote:
A more-detailed explanation of this behavior is available here. Quote:
Quote:
|
|||
|
|
|
|
|
#5 | |
|
Aug 2002
1010000002 Posts |
Quote:
|
|
|
|
|
|
|
#6 | |
|
∂2ω=0
Sep 2002
República de California
103×113 Posts |
Quote:
Actually, I should've used the word "wrapping" rather than folding, since when talking about the carryout of array[n-1] we're really talking about what is more-commonly referred to as the "wraparound carry." |
|
|
|
|
|
|
#7 | |
|
Aug 2002
32010 Posts |
Quote:
|
|
|
|
|
|
|
#8 | |
|
∂2ω=0
Sep 2002
República de California
103×113 Posts |
Quote:
One other note on the complex transform: When George was developing Prime95 he said the (j, n-j) index correlations in the complex/real wrappers were killing his cache performance, but it turns out there are ways to make this step quite cache-friendly as well. But it's nontrivial, and depends on how you do your forward and inverse FFTs. And remember, all of the folks that have written high-performance codes of this type have put literally thousands of hours into it. Writing a basic LL test program using the DWT isn't too bad - writing a world-class one is orders of magnitude more work. I don't want to discourage you, just to make you aware of the realities. |
|
|
|
|
|
|
#9 | |
|
Aug 2002
1010000002 Posts |
Something really weird is going on here with the phpBB software: I clicked "reply" to reply to Coldfury's last post. When the edit window containing the quoted text appeared, the quote="Coldfury" I expected to see in the first [] quote box was missing, so I added it, then typed my reply below the quoted text. When I submitted it, it appeared under ColdFury's name, as you can see at left!
Ernst (ewmayer) Quote:
Of course Fortran makes it very easy to use a zero-offset index (or any starting index one wishes, including negative ones), NR just went with the lazy programmer's default of 1 here. The NR FFT isn't great shakes, but is adequate for someone getting started (my orginal LL implementation used it) and who doesn't mind being restricted to power-of-2 vector lengths and having code that runs 2-5x slower than a really good FFT does. OTOH, NR's multiprecision arithmetic package, now that's horrendous. -Ernst (no, really!) (Weirdly enough, I can edit this post like I actually wrote it - ColdFury) Me, too (wierdly --> weirdly), but when I edit it, it doesn't add to the "edited xyz times counter. I do believe we've discovered a wormhole in the spacetime fabric of the forum. -EWM |
|
|
|
|
|
|
#10 | |
|
Banned
"Luigi"
Aug 2002
Team Italia
32×5×107 Posts |
Quote:
First version of Numerical Recipes was written in Pascal, and Pascal uses indexed arrays starting from position 1 :-) I should have that 5,25" floppy disk with the Pascal code somewhere in my messy storage room... Luigi |
|
|
|
|
|
|
#11 |
|
∂2ω=0
Sep 2002
República de California
103×113 Posts |
Whoa, is it just me, or am I actually seeing my reply to ColdFury's last post appearing under his name? That's really bizarre - better add some text to it to explain that it's really from me.
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Irrational Integers :) | a1call | Miscellaneous Math | 16 | 2017-05-13 22:50 |
| probability a number is prime with a weighted k. | Trilo | Homework Help | 12 | 2014-06-06 19:17 |
| Weighted Fermat factors Top 20 | Merfighters | Factoring | 0 | 2010-04-13 14:16 |
| Does Bush think God's irrational? | jasong | Soap Box | 8 | 2006-05-22 17:32 |
| Fast Odd Discrete Fourier Transform (ODFT) | dsouza123 | Miscellaneous Math | 1 | 2005-11-13 21:37 |