![]() |
|
|
#2487 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
no. edit: but for me it fails at a(4651)
Last fiddled with by science_man_88 on 2014-10-04 at 11:58 |
|
|
|
|
|
#2488 |
|
Aug 2006
3·1,993 Posts |
|
|
|
|
|
|
#2489 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Code:
= ()->for(k=0,2^199,if((isprime(floor(log(6*k+2)/log(2)))||(issquare(floor(log(6*k+2)/log(2)))&&isprimepower(floor(log(6*k+2)/log(2)))==2 &&isprime(2^floor(sqrt(log(6*k+2)/log(2)))-1)))&&#factor(6*k+1)[,1]==2&&sum(x=1,#factor(6*k+1)[,2],factor(6*k+1)[x,2])==2,print1(floor(log(6*k+2)/log(2))","));k=4*k) Code:
floor(log(6*k+2)/log(2)) Last fiddled with by science_man_88 on 2014-10-18 at 17:58 |
|
|
|
|
|
#2490 |
|
Aug 2006
3×1,993 Posts |
Since your function is an unreadable single line I won't dissect it, but I notice that you're using floor(log(6*k+2)/log(2)) a lot. Let's define t = floor(log(6*k+2)/log(2)), which you'll notice stays the same for long streches of k and then goes up by 1. Why don't you loop over values of t directly, and then re-create the associated values of k if t passes your tests?
|
|
|
|
|
|
#2491 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Code:
try() ={
n=0;
m=vector(120,n,gcd(n-1,120)==1);
for(k=0,2^199,
p=logint(6*k+2,2);
if(
(
(
m[(p%120)+1] && core(p)==p && isprime(p)
)
||
(
issquare(p) && isprimepower(p,&n)==2 && isprime(2^n-1)
)
)
&& #factor(6*k+1)[,1]==2 && sum(x=1,2,factor(6*k+1)[x,2])==2,
print1(p",")
)
; k=4*k
)}
Last fiddled with by science_man_88 on 2014-10-19 at 17:01 |
|
|
|
|
|
|
#2492 |
|
Aug 2006
3×1,993 Posts |
OK, that gives me a lot more to go on.
First, you should always declare scope for your variables. In about 100% of cases this should be done with my(), with some residual cases using local() instead. Otherwise you overwrite global variables which is BAD and will cause unintended side-effects down the road. Code:
try()={
my(m=vector(120,n,gcd(n-1,120)==1), q);
for(k=0,2^199,
my(p=logint(6*k+2,2));
if(
(
(m[(p%120)+1] && core(p)==p && isprime(p))
||
(issquare(p) && isprimepower(p,&q)==2 && isprime(2^q-1))
) && #factor(6*k+1)[,1]==2 && sum(x=1,2,factor(6*k+1)[x,2])==2,
print1(p",")
);
k=4*k
)
};
Code:
m=vector(120,n,gcd(n-1,120)==1); \\ global
is(p,k)={
my(q);
(
(m[(p%120)+1] && core(p)==p && isprime(p))
||
(issquare(p) && isprimepower(p,&q)==2 && isprime(2^q-1))
) && #factor(6*k+1)[,1]==2 && sum(x=1,2,factor(6*k+1)[x,2])==2
};
try()={
for(k=0,2^199,
my(p=logint(6*k+2,2));
if(is(p, k),
print1(p",")
);
k=4*k
)
};
Code:
is(p,k)={
my(q);
(
(gcd(p,120)==1 && isprime(p))
||
(issquare(p, &q) && isprime(q) && isprime(2^q-1))
) && #factor(6*k+1)[,1]==2 && sum(x=1,2,factor(6*k+1)[x,2])==2
};
try()={
for(k=0,2^199,
my(p=logint(6*k+2,2));
if(is(p, k),
print1(p",")
);
k=4*k
)
};
Code:
logint(N,b)=my(k);while(N>=b,N\=b;k++);k;
is(p,k)={
my(q);
p>5 &&
(isprime(p) || (issquare(p, &q) && isprime(q) && isprime(2^q-1)))
&& factor(6*k+1)[,2]==[1,1]~
};
try()={
for(k=0,2^199,
my(p=logint(6*k+2,2));
if(is(p, k),
print1(p",")
);
k=4*k
)
};
Code:
is(p,k)={
my(n);
p>5 &&
(isprime(p) || (issquare(p, &n) && isprime(n) && isprime(2^n-1)))
&& factor(6*k+1)[,2]==[1,1]~
};
try()={
for(n=0,100,
my(k=(4^n-1)/3, p=2*n+1);
if(is(p, k),
print1(p",")
)
)
};
Code:
is(p)={
my(q);
if(p < 7, return(0));
if(issquare(p, &q) && isprime(q) && isprime(2^q-1)),
return(isprime((2^p-1)/(2^q-1)))
);
isprime(p) && factor(2^p-1)[,2]==[1,1]~
};
try()={
for(n=0,100,
my(p=2*n+1);
if(is(p),
print1(p",")
)
)
};
Code:
is(p)={
my(q);
if(issquare(p, &q) && isprime(q) && isprime(2^q-1),
return(isprime((2^p-1)/(2^q-1)))
);
isprime(p) && factor(2^p-1)[,2]==[1,1]~
};
try()={
forstep(p=7,201,2,
if(is(p), print1(p","))
)
};
Edit: Another good step would be to replace try() with try(lim=201) and using forstep(p=7,lim,2 so you can test different regions without editing the function. Last fiddled with by CRGreathouse on 2014-10-19 at 20:51 |
|
|
|
|
|
#2493 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
sometimes I think you know too much about PARI in the sense that my all inbuilt function using codes are half as fast as the ones you make. I was doing the other testing to decrease the number of checks but I guess my checks took so much time that the decrease didn't matter. I thought about using k as the exponent but could never get it to work. my code caught 9 but not 4 and yours appears to forget about 9. I'll see what I can implement of your further suggestions.
Last fiddled with by CRGreathouse on 2014-10-19 at 20:51 Reason: snip long quote |
|
|
|
|
|
#2494 |
|
Aug 2006
135338 Posts |
I get
Code:
9,11,23,37,41,49,59,67,83,97,101,103,109,131,137,139,149,167,197,199, Edit: I did have to remove a superfluous paren from my code, try it now to see if it works. Last fiddled with by CRGreathouse on 2014-10-19 at 20:56 |
|
|
|
|
|
#2495 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Code:
(16:51) gp > is(p)=my(q);if(issquare(p,&q)&&isprime(q)&&isprime(2^q-1),(isprime((2^p-1)/(2^q-1))));isprime(p)&&factor(2^p-1)[,2]==[1,1]~;
(17:57) gp > try(lim=201)={forstep(p=7,lim,2,if(is(p), print1(p",")))};
(17:57) gp > try()
11,23,37,41,59,67,83,97,101,103,109,131,137,139,149,167,197,199,
(17:58) gp > ##
*** last result computed in 3,970 ms.
|
|
|
|
|
|
|
#2497 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Code:
my(n=q);sum(k=0,n-1,binomial(n,k+1)*y^k) Last fiddled with by science_man_88 on 2014-10-20 at 14:17 |
|
|
|
|
![]() |
| Thread Tools | |
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 |