mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2011-11-28, 06:15   #2333
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

It's so much nicer if you format the code!
Code:
{b=2;
forprime(p=2,2281,
  for(y=1,p-1,
    trap(,
      print("break here, p="p", y="y);
      break
    ,
      b=sqrt(Mod(b,1<<p-1))
    );
    if(y==p-1,print(p))
  );
  b=2
)}
I can't figure out the intent either.
CRGreathouse is offline   Reply With Quote
Old 2011-12-04, 22:40   #2334
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

after coming across a comment at:

https://oeis.org/A002450

I did some searching about the topic and came across a reference to Sierpinski triangle and rule 90 with that I was able to get to this:
Code:
(n)->
a=[[[1,1,1],0],[[1,1,0],1],[[1,0,1],0],[[1,0,0],1],[[0,1,1],1],[[0,1,0],0],[[0,0,1],1],[[0,0,0],0]];
b=matrix(2^(n-1)+2,2^n-1+2);
b[2,(#b+1)/2]=1;
for(x=3,2^(n-1)-1,
    for(y=2,#b-3,
        for(z=1,#a,
             if(a[z][2]==1,
                b[x,y+1]=a[z][2]
               )
            )
        )
    )
;b
as a almost working code to make the Sierpinski triangle Wikipedia helped in my understanding a bit as well as playing around, but my problem is the if statement in the last for loop I want to check the three I need to get the ones and zeroes in the correct placement for what my layout should be ( and yes my layout has a border, no that's actually not what I checked before I just did that as a test case). according to http://rosettacode.org/wiki/Reports:...ted_in_PARI/GP the triangle has still not been done.

Last fiddled with by science_man_88 on 2011-12-04 at 22:55
science_man_88 is offline   Reply With Quote
Old 2011-12-04, 23:38   #2335
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Code:
(19:29)>Sierpinski(4)
%352 =
[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 1 0 0 0 0 0 0 0 0]

[0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0]

[0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0]

[0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0]

[0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0]

[0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0]

[0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0]

[0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0]

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
just realized this wasn't it,
Code:
(n)->
a=[[[1,1,1],0],[[1,1,0],1],[[1,0,1],0],[[1,0,0],1],[[0,1,1],1],[[0,1,0],0],[[0,0,1],1],[[0,0,0],0]];
b=matrix(2^(n-1)+2,2^n-1+2);
b[2,(#b+1)/2]=1;
for(x=3,2^(n-1)+1,
    for(y=1,#b-2,
        for(z=1,#a,
             if(eval(Vec(Str(b[x-1,y]b[x-1,y+1]b[x-1,y+2])))==a[z][1],
                b[x,y+1]=a[z][2]
               )
            )
        )
    )
;b
never mind it's the way I printed it that got me confused this is it. and it works for all n>=1 I believe.

Last fiddled with by science_man_88 on 2011-12-04 at 23:39
science_man_88 is offline   Reply With Quote
Old 2011-12-14, 01:49   #2336
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Quote:
Originally Posted by cmd View Post
3 .. Spring roll s in ..

Code:
x=1000000000;d=#divisors(x);for(y=1,ceil(d/2),print(divisors(x)[y]"\t\t\t "divisors(x)[d-(y-1)]))
is my best version of it except I only list everything once.
science_man_88 is offline   Reply With Quote
Old 2011-12-20, 13:34   #2337
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default working with matrices

Code:
(09:30)>a=matrix(10,2);print(#a[,1]);print(#a);
10
2
science_man_88 is offline   Reply With Quote
Old 2011-12-30, 16:27   #2338
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

is there an easy way to create all the distinct partitions of a number n without the number 1 involved ( though I also have a way with 1 involved I think) ? because I'm trying to speed up my aligen function and it's based on partitions.
science_man_88 is offline   Reply With Quote
Old 2011-12-30, 18:03   #2339
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
is there an easy way to create all the distinct partitions of a number n without the number 1 involved ( though I also have a way with 1 involved I think) ? because I'm trying to speed up my aligen function and it's based on partitions.
looks to be a no there's ways of counting them but I want the partitions themselves because working backwards through aliquot sequences can be based in partitions of n-1 where n is the number we are saying is sigma(x)-x ( my current script does checks) for example:

n=6; a=n-1=5;

a=5=4+1=3+2 the 5 is by itself so square it, then we without duplicating the 1 we took off we get get 5^2,3*2 , gives you 25 and 6 and only those as 5 can't be partitioned in h>3 parts without a 1 being involved. a sigma check on both shows they both work out .

Last fiddled with by science_man_88 on 2011-12-30 at 18:04
science_man_88 is offline   Reply With Quote
Old 2012-02-29, 16:48   #2340
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Code:
homeprime(n)= s=n;until(isprime(s),a=factor(s);b="";for(x=1,#a[,2],until(a[x,2]==0,b=concat(b,Str(a[x,1]));a[x,2]=a[x,2]-1));print(b);s=eval(b))
made this after reading in the HP(49) thread. which gave me links to learn about home primes.

Last fiddled with by science_man_88 on 2012-02-29 at 17:02
science_man_88 is offline   Reply With Quote
Old 2012-03-04, 04:59   #2341
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
is there an easy way to create all the distinct partitions of a number n without the number 1 involved ( though I also have a way with 1 involved I think) ? because I'm trying to speed up my aligen function and it's based on partitions.
Here's some naive code:

Code:
partNo1(n)={
  select(v->vecmin(v)>1,partitions(n))
};
partNo1Count(n)=polcoeff((1-'x)/eta('x+'x*O('x^n)), n);
If you're running an old version of gp (you probably are), you'll need to change the order of the arguments in select. If you don't like the Vecsmall appearing in the output, apply Vec to each member. Both changes:
Code:
partNo1(n)={
  apply(Vec,select(partitions(n),v->vecmin(v)>1))
};
CRGreathouse is offline   Reply With Quote
Old 2012-03-04, 14:04   #2342
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Here's some naive code:

Code:
partNo1(n)={
  select(v->vecmin(v)>1,partitions(n))
};
partNo1Count(n)=polcoeff((1-'x)/eta('x+'x*O('x^n)), n);
If you're running an old version of gp (you probably are), you'll need to change the order of the arguments in select. If you don't like the Vecsmall appearing in the output, apply Vec to each member. Both changes:
Code:
partNo1(n)={
  apply(Vec,select(partitions(n),v->vecmin(v)>1))
};
I got back that partitions is not a function.
science_man_88 is offline   Reply With Quote
Old 2012-03-04, 15:17   #2343
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I got back that partitions is not a function.
this gets too complicated really quick:

duplication through permutation is a problem that can up, so was the avoiding using 1's so are the ones with 2 of the same number. so many things to consider, no wonder a lot of people take the other routes.

for my purposes 2,3==3,2 1's are unnecessary because I already subtract it from n, the duplicate part means any partition with x,x in it becomes unwanted.
science_man_88 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I sometimes see all the <> formatting commands when I quote or edit? cheesehead Forum Feedback 3 2013-05-25 12:56
Passing commands to PARI on Windows James Heinrich Software 2 2012-05-13 19:19
Ubiquity commands Mini-Geek Aliquot Sequences 1 2009-09-22 19:33
64-bit Pari? CRGreathouse Software 2 2009-03-13 04:22
Are these commands correct? jasong Linux 2 2007-10-18 23:40

All times are UTC. The time now is 22:04.


Fri Aug 6 22:04:27 UTC 2021 up 14 days, 16:33, 1 user, load averages: 3.01, 2.83, 2.71

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

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.