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)

3.14159 2010-08-17 15:43

Idea:
 
I defined the function em2 to return b-values that are divisible by a user-specified number.

I thought of a new function that gets rid of the b-values divisible by any prime in a range of primes. simply save these to a file, remove every duplicate, remove the b-values from the range that happen to be divisible by p, and test the remainder. It's already defined.

To make it somewhat better: I'm going to need a further command that prints the numbers that are [B]not[/B] in the set of em2 for any of the primes specified. The primelimit is set to 2147483648, so it's going to be somewhat useful.
Excellent idea, amirite?

3.14159 2010-08-17 15:51

The code snippet I scribbled on paper for the next command:

nonmem(a,x,m,b) = {
for(n=a,x,
if(n=!mem(a,x,m,b), print(n))
);
}

(Please tell whether or not there are any errors there.)

For mem:
mem(a,x,m,b) = {
forprime(p=a,x,
print(em2(p,m!,b))
);
}

(Where b = 10[sup]b[/sup]).

CRGreathouse 2010-08-17 15:56

[QUOTE=3.14159;225844]Need to proofread more often, there.[/QUOTE]

I'm sure I scanned that portion of the code at least two or three times, but it wasn't clear that there was anything wrong. (The other parts where I thought the problem was I looked at a dozen times at least... although that did help me optimize those parts.)

In any case that project is running now. It's about 100 times faster than my old version at these sizes, and should be about 1000 times faster as the numbers grow large. I'm still actively looking to optimize the program -- I'm hoping for at least a 20% improvement, maybe a 50% improvement if I missed something big. But compared to the improvements I already have that's peanuts.

3.14159 2010-08-17 15:58

[QUOTE=CRGreathouse]I'm sure I scanned that portion of the code at least two or three times, but it wasn't clear that there was anything wrong. (The other parts where I thought the problem was I looked at a dozen times at least... although that did help me optimize those parts.)
[/QUOTE]

Mistakes can sometimes be right under your nose, and you probably won't notice them until the most random of times.

[QUOTE=CRGreathouse]In any case that project is running now. It's about 100 times faster than my old version at these sizes, and should be about 1000 times faster as the numbers grow large. I'm still actively looking to optimize the program -- I'm hoping for at least a 20% improvement, maybe a 50% improvement if I missed something big. But compared to the improvements I already have that's peanuts.
[/QUOTE]

10000% improvement? Excellent.

CRGreathouse 2010-08-17 16:00

[QUOTE=3.14159;225849]I defined the function em2 to return b-values that are divisible by a user-specified number.

I thought of a new function that gets rid of the b-values divisible by any prime in a range of primes. simply save these to a file, remove every duplicate, remove the b-values from the range that happen to be divisible by p, and test the remainder. It's already defined.

To make it somewhat better: I'm going to need a further command that prints the numbers that are [B]not[/B] in the set of em2 for any of the primes specified. The primelimit is set to 2147483648, so it's going to be somewhat useful.[/QUOTE]

Just make a vector with a member for every number in the range you're considering, and set the value to 314159 if you find a prime that divides the number. Then take all the values that aren't 314159 and test them to see if they're prime.

CRGreathouse 2010-08-17 16:01

[QUOTE=3.14159;225853]10000% improvement? Excellent.[/QUOTE]

Yes, I did more work last night than in the month of calculation I put in earlier.

3.14159 2010-08-17 16:03

[QUOTE=CRGreathouse]Just make a vector with a member for every number in the range you're considering, and set the value to 314159 if you find a prime that divides the number. Then take all the values that aren't 314159 and test them to see if they're prime.
[/QUOTE]

A vector with the smallest k * n! + 1 that's divided by p, for a range of p?

Also: Anything regarding the code snippets I thought up a few minutes ago?

CRGreathouse 2010-08-17 16:10

[QUOTE=3.14159;225856]A vector with the smallest k * n! + 1 that's divided by p, for a range of p?[/QUOTE]

A vector v where v[1] represents k = 1, v[2] represents k = 2, etc. Mark off entries when you know they're bad, and test only the unmarked entries.

[QUOTE=3.14159;225856]Also: Anything regarding the code snippets I thought up a few minutes ago?[/QUOTE]

I don't know exactly how em2 works so I can't say much. But try my idea, it works much better. :razz: Printing is bad, don't do it if you can avoid it.

3.14159 2010-08-17 16:13

[QUOTE=CRGreathouse]I don't know exactly how em2 works so I can't say much. But try my idea, it works much better. Printing is bad, don't do it if you can avoid it.
[/QUOTE]

em2 removes all the k-values divisible by a user-specified number.

3.14159 2010-08-17 16:16

[QUOTE=CRGreathouse]A vector v where v[1] represents k = 1, v[2] represents k = 2, etc. Mark off entries when you know they're bad, and test only the unmarked entries.
[/QUOTE]

A vector of the integers?

CRGreathouse 2010-08-17 16:19

[QUOTE=3.14159;225858]em2 removes all the k-values divisible by a user-specified number.[/QUOTE]

I read that in your post. It doesn't tell me enough that I can comment on code using it.

[QUOTE=3.14159;225859]A vector of the integers?[/QUOTE]

Not really important here. The best of all the easy solutions in Pari is to use a VECSMALL, which is created by vectorsmall just like a VEC is created by vector.


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

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