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-14 23:16

polynomial form
 
I know that:
2x+1 single mersennes when x is the previous single mersenne
2x^2+4x+1 double mersennes when x is the previous double mersenne

I know the relation of the exponents of a triple mersenne as they are the double mersennes but does anyone know of a general form other than (2^y+1)*(2^x-1) for triple, quadruple, quintuple, etc. mersennes ? edit: sorry wrong thread for some reason I thought this was the theory of mersenne primes thread

science_man_88 2014-05-17 16:57

does anyone know why they haven't merged Pol and Polrev ? I could see a newer version with {n=1} being a switch where n=1 makes it Pol and -1 makes it Polrev, though I guess that's because I'm trying to make my own version that does something like both.

CRGreathouse 2014-05-17 19:42

[QUOTE=science_man_88;373699]does anyone know why they haven't merged Pol and Polrev ?[/QUOTE]

Why would they?

science_man_88 2014-05-17 19:44

[QUOTE=CRGreathouse;373708]Why would they?[/QUOTE]

I was just thinking that it would reduce the number of functions, but I can't make anything that quick my best attempt involved parsum:

[CODE]Pols(t,v='x,{n=1})=if(n==1,parsum(w=1,#t-1,t[w]*v^(#t-w),t[#t]),parsum(w=2,#t,t[w]*v^(#t-(#t-w+1)),t[1]))[/CODE]

edit: which is about 1200 times as slow for a vector of length 10000

science_man_88 2014-05-22 22:04

[code]parmatrix(m,n,{X},{Y},{expr=0})={
a=matrix(m,n,x,y,0);
parfor(x=1,n,
parvector(m,y,
a[x,y]=eval(expr)
)
)
;a
}[/code]

I was trying to make a parallel function for matrices ( in case it might ever be useful)

CRGreathouse 2014-05-22 23:40

You forgot my().

science_man_88 2014-05-22 23:43

[QUOTE=CRGreathouse;374024]You forgot my().[/QUOTE]

It doesn't fully work as written even with my, what am I missing?

CRGreathouse 2014-05-23 13:33

I would do
[code]parmatrix(m,n,expr=(a,b)->0)={
my(a=matrix(m,n));
parfor(x=1,m,
for(y=1,n,
a[x,y]=expr(x,y)
)
);
a
};[/code]

with the understanding that the third argument needs to be given as a closure:

[code]f(x,y)=x^2+sigma(y);
parmatrix(5, 5, f) \\ user function called by name
parmatrix(4, 6, gcd) \\ built-in function called by name
parmatrix(4, 4, (x,y) -> x+y) \\ anonymous function[/code]

You can't define a function in gp with a true expr argument (you'd need to use the PARI library directly in C).

science_man_88 2014-05-23 14:03

[QUOTE=CRGreathouse;374081]I would do
[code]parmatrix(m,n,expr=(a,b)->0)={
my(a=matrix(m,n));
parfor(x=1,m,
for(y=1,n,
a[x,y]=expr(x,y)
)
);
a
};[/code]

with the understanding that the third argument needs to be given as a closure:

[code]f(x,y)=x^2+sigma(y);
parmatrix(5, 5, f) \\ user function called by name
parmatrix(4, 6, gcd) \\ built-in function called by name
parmatrix(4, 4, (x,y) -> x+y) \\ anonymous function[/code]

You can't define a function in gp with a true expr argument (you'd need to use the PARI library directly in C).[/QUOTE]

Okay, Thanks for the code and hint. One further question what function won't return all 0's from the matrix default of 0's ?

CRGreathouse 2014-05-23 15:01

[QUOTE=science_man_88;374086]One further question what function won't return all 0's from the matrix default of 0's ?[/QUOTE]

I don't know what you mean. I gave three examples of functions that don't return all 0s.

science_man_88 2014-05-23 15:14

[QUOTE=CRGreathouse;374090]I don't know what you mean. I gave three examples of functions that don't return all 0s.[/QUOTE]

I tried every one of those and got back 0's:

[CODE](11:48) gp > parmatrix(m,n,expr=(a,b)->0)={
my(a=matrix(m,n));
parfor(x=1,m,
for(y=1,n,
a[x,y]=expr(x,y)
)
);
a
};
(12:12) gp > f(x,y)=x^2+sigma(y);
(12:13) gp > parmatrix(5, 5, f)
%67 =
[0 0 0 0 0]

[0 0 0 0 0]

[0 0 0 0 0]

[0 0 0 0 0]

[0 0 0 0 0]

(12:13) gp > parmatrix(4, 6, gcd)
%68 =
[0 0 0 0 0 0]

[0 0 0 0 0 0]

[0 0 0 0 0 0]

[0 0 0 0 0 0]

(12:13) gp > parmatrix(4, 4, (x,y) -> x+y)
%69 =
[0 0 0 0]

[0 0 0 0]

[0 0 0 0]

[0 0 0 0][/CODE]


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

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