mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-08-14, 18:01   #441
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

they both work until M(1) but after that they climb to 35 and 70 for the next ones.

Last fiddled with by science_man_88 on 2010-08-14 at 18:03
science_man_88 is offline   Reply With Quote
Old 2010-08-14, 18:03   #442
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
I can't correct the program because I don't know what it's trying to do. But certainly the program isn't doing what you intend if it stores the value it returns but doesn't actually return a value.
it's doing the equivalent of the formula I gave above.

http://www.mersenneforum.org/cgi-bin...1}M(n)%20+%20x

Last fiddled with by science_man_88 on 2010-08-14 at 18:06
science_man_88 is offline   Reply With Quote
Old 2010-08-14, 18:19   #443
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Is x in the sum or out of the sum?
CRGreathouse is offline   Reply With Quote
Old 2010-08-14, 18:22   #444
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Is x in the sum or out of the sum?
out I know I wasn't sure how to make it obvious. sum all M(n) less than M(x) then add x to that sum.

I realize it should of been first now lol.

Last fiddled with by science_man_88 on 2010-08-14 at 18:29
science_man_88 is offline   Reply With Quote
Old 2010-08-14, 18:37   #445
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
out I know I wasn't sure how to make it obvious.
M(x)=x+\sum_{n=0}^{x-1}M(n) would be the usual way. Of course you could also use parentheses (in which case, in LaTeX, you would want to use \left and \right).

Code:
M(x)=x+sum(n=0,x-1,M(n))
is the literal translation into Pari.

Here's a solution with memoization. It stores the values rather than recalculating:
Code:
M(x)={
  if(x < 1, return(0));
  if(Mvec == 'Mvec,Mvec=[]);
  if(#Mvec < x,
    my(n=#Mvec);
    Mvec=vector(x,i,if(i<=n,Mvec[i]));
    for(i=n+1,x, Mvec[i]=i+sum(j=1,i-1,Mvec[j]))
  );
  Mvec[x]
};
Here's a more efficient version:
Code:
M(x)=(1<<x)-1
CRGreathouse is offline   Reply With Quote
Old 2010-08-14, 18:43   #446
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
M(x)=x+\sum_{n=0}^{x-1}M(n) would be the usual way. Of course you could also use parentheses (in which case, in LaTeX, you would want to use \left and \right).

Code:
M(x)=x+sum(n=0,x-1,M(n))
is the literal translation into Pari.

Here's a solution with memoization. It stores the values rather than recalculating:
Code:
M(x)={
  if(x < 1, return(0));
  if(Mvec == 'Mvec,Mvec=[]);
  if(#Mvec < x,
    my(n=#Mvec);
    Mvec=vector(x,i,if(i<=n,Mvec[i]));
    for(i=n+1,x, Mvec[i]=i+sum(j=1,i-1,Mvec[j]))
  );
  Mvec[x]
};
Here's a more efficient version:
Code:
M(x)=(1<<x)-1
memorization* and memorize* for the last few posts but thank's and I have proved it works yeah. is there a formula for the number list that contains the super-perfect numbers and perfect numbers as well like mine ?
science_man_88 is offline   Reply With Quote
Old 2010-08-14, 18:47   #447
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
memorization* and memorize*
No, memoization and memoize. Different words.

Quote:
Originally Posted by science_man_88 View Post
is there a formula for the number list that contains the super-perfect numbers and perfect numbers as well like mine ?
Not sure what you mean.
CRGreathouse is offline   Reply With Quote
Old 2010-08-14, 18:49   #448
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

M(x)=x+\sum_{n=0}^{x-1}M(n)

is there a similar formula for the sequences that hold super-perfect and perfect numbers respectively?

Last fiddled with by science_man_88 on 2010-08-14 at 18:51
science_man_88 is offline   Reply With Quote
Old 2010-08-14, 18:53   #449
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
M(x)=x+\sum_{n=0}^{x-1}M(n)

is there a similar formula for the sequences that hold super-perfect and perfect numbers respectively?
Yes, but what sequences? Certainly they're in A000027, but did you have a more specific sequence in mind? I don't know of an explicit formula for the (super-)perfect numbers, of course -- though I wouldn't be surprised if one could be formed with sin and floor.
CRGreathouse is offline   Reply With Quote
Old 2010-08-14, 18:56   #450
axn
 
axn's Avatar
 
Jun 2003

10011110111112 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
memorization* and memorize* for the last few posts
http://en.wikipedia.org/wiki/Memoization
axn is offline   Reply With Quote
Old 2010-08-14, 18:59   #451
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

135338 Posts
Default

Quote:
Originally Posted by axn View Post
Thanks, axn. I tend to forget that not everyone is a computer programmer.
CRGreathouse is offline   Reply With Quote
Reply



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:48.


Fri Aug 6 22:48:25 UTC 2021 up 14 days, 17:17, 1 user, load averages: 4.21, 4.24, 3.91

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.