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)

science_man_88 2014-05-07 16:42

one thing I realized was that x=vecsort(x,,8) eliminated more than #x=#vecsort(x), because it also asked setisset(x) effectively which allows use to only use ones that are in order already.

science_man_88 2014-05-07 18:11

[QUOTE=CRGreathouse;372876]

Additional thought: you're looking for a partition x1 > ... > xn equal to the proper divisors (> 1) of x1 * xk. So a faster method would be to loop through the primes p which might be the least member, look for partitions of n-p with all parts at least q = nextprime(p+1) and at most q*(n-q)\nextprime(q+1), and then add on p 'by hand'. This trims off a lot of partitions to check, I think.[/QUOTE]

I did have difficulty trying to get yours to work, actually the reason I'm doing n-1 instead of n is because 1 is already eliminated that way so if prime p gets eliminated I'd look for partitions of n-(p+1) I might just make an outer parforprime ( a parallel forprime) loop to do this after figuring out a limit , and technically if n-1 is prime [TEX](n-1)^2[/TEX] gets missed by your code.
edit: doh, what am I thinking I just realized something before I posted and forgot it already. [2,n-3] will catch all for primes above it as wells so unless I go down through the primes both the parforprime and others save none. edit2: nevermind I realized that I'm not looking up to n-1 again.

CRGreathouse 2014-05-08 14:04

[QUOTE=science_man_88;372886]one thing I realized was that x=vecsort(x,,8) eliminated more than #x=#vecsort(x), because it also asked setisset(x) effectively which allows use to only use ones that are in order already.[/QUOTE]

#x == #vecsort(x) is true for any vector x, since vecsort doesn't remove any elements unless you give it flag 8.

Set(x) is basically a better version of vecsort(x,,8) if your version is new enough that Set([1])==[1] .

CRGreathouse 2014-05-08 14:22

[QUOTE=science_man_88;372894]I did have difficulty trying to get yours to work, actually the reason I'm doing n-1 instead of n is because 1 is already eliminated that way so if prime p gets eliminated I'd look for partitions of n-(p+1)[/QUOTE]

Sounds good, that's what I figured.

[QUOTE=science_man_88;372894]parforprime ( a parallel forprime)[/QUOTE]

You should test this before using to make sure your version can actually make reasonable use of it. Try something like

parforprime(p=2,7, runs_for_10_seconds())

to see if it runs in ~10 seconds or ~40 seconds (assuming 4 cores, adjust to suit otherwise).

science_man_88 2014-05-08 18:04

parforprime still didn't make sense and seems to be slower for simple things. on another note:

[CODE]p=11;a=binary(2^((p-1)/2-1)-1);s=14;for(x=1,#a,s=(Mod(s,(2^p-1))^2-2)^2-2);s[/CODE]

here's another way to do the lucas lehmer test I was trying to make it close to:

[url]http://www.mersenne.org/various/math.php#trial_factoring[/url] , anyways off to make my other code better I guess.

CRGreathouse 2014-05-09 05:08

[QUOTE=science_man_88;372972]parforprime still didn't make sense and seems to be slower for simple things.[/QUOTE]

It's definitely slower for simple things -- lots of overhead. I wouldn't consider doing less than a million cycles with each iteration.

science_man_88 2014-05-09 12:40

[QUOTE=CRGreathouse;373004]It's definitely slower for simple things -- lots of overhead. I wouldn't consider doing less than a million cycles with each iteration.[/QUOTE]

well there's that, but also once p=2 is done it covers everything else because every value in the limits [amin,amax] will fall between 2,n-3 the only thing this misses is when n-1 is prime. So doing it first doesn't make sense but even doing it in reverse order doesn't either without a check on if it's already in c because as p decreases the range [p,n-(p+1)] is larger than [nextprime(p),n-(nextprime(p)+1)], for some reason I'm getting your code to be slower than mine overall.

CRGreathouse 2014-05-09 13:52

Which codes are you comparing? I think we've both posted several.

science_man_88 2014-05-09 14:14

[QUOTE=CRGreathouse;373027]Which codes are you comparing? I think we've both posted several.[/QUOTE]

I guess I made alterations that made my code faster:

[url]http://mersenneforum.org/showpost.php?p=372876&postcount=2453[/url]

if I take out the solve part you have that my original didn't yours takes 378 ms if I add your solve in my code takes 129 ms so it's really only the solve I can find as faster. if I add in the ( I typed it wrong before) improvement of using the check x==vecsort(x,,8) I get it down to ~111 ms for mine. and even with your solve back into it plus an equivalent to my check by using Vec(x)==Set(x) yours doesn't go below 200 ms.

CRGreathouse 2014-05-09 15:25

Since you didn't answer my question I won't bother doing my own analysis.

science_man_88 2014-05-09 18:31

[QUOTE=CRGreathouse;373038]Since you didn't answer my question I won't bother doing my own analysis.[/QUOTE]

I had a link to the codes I altered from, and how altering them changed things.


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

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