![]() |
|
|
#1101 |
|
Mar 2006
Germany
22·727 Posts |
The expression "if ((a==true) * (b==true) * (c==true) == 1)" depends also on the interpreter/compiler.
If the first expression is false (a=false), the whole expression won't be true anymore (if true treated as '1' and false as '0')! So the other two comparisons (b and c) could be omitted and that would be really faster! Last fiddled with by kar_bon on 2010-08-29 at 19:44 |
|
|
|
|
|
#1102 | |
|
Aug 2006
3·1,993 Posts |
Edit: kar_bon explains this above, see post #1101.
Quote:
But if you want fast code you can do better. Try Code:
forprime(p=2,1e9,n=p-1;if(isprime(n^2+1)&isprime(n^4+1),print1(n","))) Last fiddled with by CRGreathouse on 2010-08-29 at 19:45 |
|
|
|
|
|
|
#1103 | |
|
May 2010
Prime hunting commission.
24·3·5·7 Posts |
Quote:
Not every square number is a fourth power. Fourth powers are a subset of squares. Nevermind. This is getting me nowhere. Fine, you win. You can keep the smug expression on your face. Last fiddled with by 3.14159 on 2010-08-29 at 19:49 |
|
|
|
|
|
|
#1104 |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
the code is for pari and no regardless of if the first is one this code uses imul() 2 times and a cmp so about 9 cmp equivalent regardless mine uses 3 cmp and 2 and commands equivalent so unless each and is triggered every time and takes 3 cmp each my code is faster karsten.
Last fiddled with by science_man_88 on 2010-08-29 at 19:48 |
|
|
|
|
|
#1105 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
this only does better under primelimit if it goes over it throws an error mine can go to at least primelimit^2 but I could check if I can speed mine up more lol. also this is about same timing as mine for one test and unless there's a law if n^2+1 is prime and n^4+1 is prime then n+1 is prime this isn't what solves it and you use & not && why ?
Last fiddled with by science_man_88 on 2010-08-29 at 19:54 |
|
|
|
|
|
#1106 | |
|
Aug 2006
3×1,993 Posts |
Quote:
Nah, I really only look smug when I'm showing a trivial (counter)example. Last fiddled with by CRGreathouse on 2010-08-29 at 20:01 |
|
|
|
|
|
|
#1107 | |
|
Aug 2006
10111010110112 Posts |
Quote:
But in this case that's not really the point -- the point is that your code is better than the one given in the sequence because it does less work (not checking the larger numbers for primality if the smaller ones fail), *not* because of the cmp vs. imul. That difference would be too small to measure with that few iterations. |
|
|
|
|
|
|
#1108 | |
|
Aug 2006
3×1,993 Posts |
Quote:
Edit: I could have reduced the time needed for the primelimit calculation to 90 ms by reducing the bound to 31370407... They're exactly the same in Pari; I occasionally use one and occasionally the other. I'm betting that if you look at my code more closely you'll be able to figure this one out. Last fiddled with by CRGreathouse on 2010-08-29 at 20:13 |
|
|
|
|
|
|
#1109 |
|
Mar 2006
Germany
1011010111002 Posts |
|
|
|
|
|
|
#1110 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
|
|
|
|
|
|
#1111 |
|
Aug 2006
3×1,993 Posts |
Instead of testing if n+1 is a prime, I loop through the primes, choosing n = p-1 so that n+1 is prime. Because I'm using Pari's precalculated list instead of testing numbers, the search is much faster. (This occurs even if I have to generate the whole list myself -- sieving is much faster than testing.)
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why do I sometimes see all the <> formatting commands when I quote or edit? | cheesehead | Forum Feedback | 3 | 2013-05-25 12:56 |
| Passing commands to PARI on Windows | James Heinrich | Software | 2 | 2012-05-13 19:19 |
| Ubiquity commands | Mini-Geek | Aliquot Sequences | 1 | 2009-09-22 19:33 |
| 64-bit Pari? | CRGreathouse | Software | 2 | 2009-03-13 04:22 |
| Are these commands correct? | jasong | Linux | 2 | 2007-10-18 23:40 |