mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PARI/GP (https://www.mersenneforum.org/forumdisplay.php?f=155)
-   -   PARI's commands (https://www.mersenneforum.org/showthread.php?t=13636)

kar_bon 2010-09-06 22:17

[QUOTE=science_man_88;228723]so in other terms:

[CODE]forprime(p=1,1500,if(isprime(p*10^2+1),print(p*10^2+1)))[/CODE][/QUOTE]

NO!

"print(p)" and that will give the correct answers!

3.14159 2010-09-06 22:20

Title is corrected.

science_man_88 2010-09-06 22:21

his sequence he gave is A180469 (already up by him) and it's not the p values it's the full values he listed.

kar_bon 2010-09-06 22:27

The title says "Primes such that p * 100 + 1 is also prime."

But to which value is p*100+1 [b]also[/b] prime?

The word "Primes" and "p*100+1 also prime" refer to different values!

"also prime" to the value p obviously meant, so p has to be listed here, not p*100+1!

PS:
And the given PARI code is also false
[code]
p10n(a, x) = { for(n=a, x, if(isprime(n)&isprime(n*10^2+1), print(10^2+1)) )};
[/code]

This will ouput only 101 evertime a value is found!

Correct [url=http://factordb.com/new/index.php?query=n*100%2B1&use=n&n=1&VP=on&PR=on&perpage=20&format=1&sent=Show]like this[/url]:
"Primes p such that p*100+1 also prime"
"Values: 7, 13, 19, 37, 61, 67, ..."

science_man_88 2010-09-06 22:45

[QUOTE=kar_bon;228730]
PS:
And the given PARI code is also false
[code]
p10n(a, x) = { for(n=a, x, if(isprime(n)&isprime(n*10^2+1), print(10^2+1)) )};
[/code]

This will ouput only 101 evertime a value is found![/QUOTE]

yeah I know I've been experimenting with it lol

science_man_88 2010-09-06 22:50

[QUOTE=kar_bon;228730]

Correct [url=http://factordb.com/new/index.php?query=n*100%2B1&use=n&n=1&VP=on&PR=on&perpage=20&format=1&sent=Show]like this[/url]:
"Primes p such that p*100+1 also prime"
"Values: 7, 13, 19, 37, 61, 67, ..."[/QUOTE]

also I could see using another if to branch if(p<default(primelimit),code1,code2) type idea.

CRGreathouse 2010-09-06 23:35

[QUOTE=science_man_88;228732]also I could see using another if to branch if(p<default(primelimit),code1,code2) type idea.[/QUOTE]

How about this, for your usual preoccupation with looping over primes that 'may' be huge:

[code]forallprime(start,stop,ff)={
my(d=default(primelimit));
if (type(ff) != "T_CLOSURE", error("ff must be a function! For example, forallprime(10,100,n->print(n))"));
forprime(p=start,min(stop,d), ff(p));
if(stop > d,
print("\nWarning, "stop" > primelimit, calculation may be slow");
for(n=precprime(d)+1, stop,
if(isprime(n), ff(n))
)
)
};
addhelp(forallprime, "forallprime(start, stop, ff): Executes the closure (function) ff for all the primes between start and stop.");[/code]

science_man_88 2010-09-07 00:17

I'm useless as this code appears to do nothing useful no matter what I do if i try to print the result it give me an error oddly if i use next() as well it doesn't give me that error but it only prints once and only exactly what I type even if it's a variable you use, plus the added bonus of not throwing a out of limits error if i go over primelimit.

CRGreathouse 2010-09-07 02:28

Sorry, typo... replace T_CLOSURE with t_CLOSURE. (That'll teach me to post without checking my programs!)

science_man_88 2010-09-07 20:59

[QUOTE=CRGreathouse;228748]Sorry, typo... replace T_CLOSURE with t_CLOSURE. (That'll teach me to post without checking my programs!)[/QUOTE]

yeah I got it working under that lol. wonder how many primes I could fit on my drives lol using my ipod and a few other removables + main drive I get

211,474,722,816
249,515,175,936
008,002,691,072
[U]006,624,665,600[/U]
475,617,255,424 bytes if i did the math right

apparently doing math visually on here isn't a good way although I got nearly accurate I get 372 as the ending by calculator.

CRGreathouse 2010-09-07 21:58

Depends on what size primes you store and how you store them, naturally.


All times are UTC. The time now is 23:15.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.