![]() |
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 |
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.
|
[QUOTE=science_man_88;373699]does anyone know why they haven't merged Pol and Polrev ?[/QUOTE]
Why would they? |
[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 |
[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) |
You forgot my().
|
[QUOTE=CRGreathouse;374024]You forgot my().[/QUOTE]
It doesn't fully work as written even with my, what am I missing? |
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=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 ? |
[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. |
[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.