in reply to Re^6: OT: Finding Factor Closest To Square Root
in thread OT: Finding Factor Closest To Square Root
The bug only seems to manifest itself when I add the sqrt() code. .... To see it go away, comment out the $sqrt definition and change the return statement to return $f.
Sorry Limbic~Region, I do not follow these instructions?
The only definition of $sqrt I can see is my $sqrt = sqrt( $N );
But I do not understand what you mean by "change the return statement to return $f."?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: OT: Finding Factor Closest To Square Root
by Limbic~Region (Chancellor) on Feb 26, 2005 at 14:10 UTC | |
Sorry - it was past my bedtime last night when I posted. The code in question (with a few extra lines for context looks like this: To see the problem, add the following line: And to see the problem go away: You can see the list of factors changes with the presence of the sqrt() code (at least it does on my machine). Cheers - L~R | [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Feb 26, 2005 at 15:00 UTC | |
Hmm. I get the same results both ways:
Which version of Parei do you have? I have
It's kind of hard to see how using the built in sqrt function would influence factorint()> but have you tried moving the call to sqrt after the call to factorint()? Anyway, trying to get beyond that, I picked a few ideas from tall_man's code (which is definitely the benchmark in this thread) and modified your code to read as:
As I understand it, ':int', makes all integers in the program Pari compatible?. And using sqrtint() ought to bypass any imcompatibilities. The fudge with $ARGV[ 0 ] at the top allows me to test the code on some really big numbers without having to type out all the digits--I applied the same hack to tall_man's code, and then ran a few tests. The following is the results from a few carefully chosen (particularly hard) examples timing both programs. Going by the time your program takes in comparison to tall_man's, you appear to be doing a similar amount of work, but your code is returning -1, which I do not understand?
The timings of these two particularly difficult runs, going by how long tall_man'code takes relative to most other runs like:
which despite being nearly as big a number, is solved in under a 1/5th of a second rather than 17+ seconds above. The very close similarity in timing between your code and tall_man's suggests that you are probably doing a very similar amount of work and possibly arriving at the same result, but for some reason, failing to display it?. Maybe a rounding error somewhere. I tried to follow this through--but as you know your code better than I, you might find the solution more quickly. Either way, your determination of the appropriate sequence of tests and short-ciruiting is very impressive. I congratulate you++ :). Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
| [reply] [d/l] [select] |
by Limbic~Region (Chancellor) on Feb 27, 2005 at 14:29 UTC | |
Hmm. I get the same results both ways: While I might expect a different environment not to expose the bug, I am suprised that neither run gave correct results. On my machine, for 24777695232, I get: Read more... (304 Bytes)
Which version of Parei do you have?
...have you tried moving the call to sqrt after the call to factorint()?
Anyway, trying to get beyond that, I picked a few ideas from tall_man's code (which is definitely the benchmark in this thread) and modified your code to read as:
Going by the time your program takes in comparison to tall_man's, you appear to be doing a similar amount of work, but your code is returning -1, which I do not understand?
...which despite being nearly as big a number, is solved in under a 1/5th of a second rather than 17+ seconds above. The very close similarity in timing between your code and tall_man's suggests that you are probably doing a very similar amount of work and possibly arriving at the same result, but for some reason, failing to display it?.
Read more... (387 Bytes)
And then just add a test at the top for $ARGV[0] and loop on the file if not present.
Either way, your determination of the appropriate sequence of tests and short-ciruiting is very impressive. I congratulate you++
Cheers - L~R | [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Feb 27, 2005 at 16:10 UTC | |