mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-12-02, 00:25   #1893
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

110100100002 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Not allowed, see the problem description.
How about we simply apply the iterative definition?

Start with a.

a + 1

Let a + b = a + 1 + 1 + 1 + 1 + 1 + 1 + 1....

Let a * b = a + a + a + a + a + a + a + a + a + ....

Let a^b = a * a * a * a * a * a..

Etc.

Last fiddled with by 3.14159 on 2010-12-02 at 00:28
3.14159 is offline   Reply With Quote
Old 2010-12-02, 00:26   #1894
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

110100100002 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Wow, that's a lot of decimal places. Can we assume you were born at 7:19:00.00000000000000000006 PM, then?


Actually I learned something from my pi.age example: I had thought that member functions (somehow) returned lvalues, but it looks like they just give ordinary rvalues. As a result you can't actually do pi.age++.
Actually, I was born at 2:45 AM, on a Thursday.
3.14159 is offline   Reply With Quote
Old 2010-12-02, 00:28   #1895
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

http://rosettacode.org/wiki/Palindrome_detection

I think i have a way to do this:

1) create a Vec with the string
2) call a loop to check if v[i] and v[#v-i] or something like that if 1 based array to check if it's the same if so for all the ones around the center it proves it's a palindrome if I remember my definitions lol.

Last fiddled with by science_man_88 on 2010-12-02 at 00:28
science_man_88 is offline   Reply With Quote
Old 2010-12-02, 00:29   #1896
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

168010 Posts
Default

All that would have to be done to follow that nice iterative process would be to define a + 1.

Or would that also be disallowed? There would also be the problem of the opposites of those; a - 1, a - b, a/b, a^(1/b), etc.

Last fiddled with by 3.14159 on 2010-12-02 at 00:30
3.14159 is offline   Reply With Quote
Old 2010-12-02, 00:30   #1897
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

10111010110112 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
I think PARI/GP's too weak for those tasks.
It is for some -- listed at
http://rosettacode.org/wiki/Category:PARI/GP/Omit
though you're welcome to try even those if you have a mind to.

I put most of those there because Pari would be bad at them, but in some cases it's literally incapable of doing them without system() or extern() or the like.

But for many of the tasks Pari is well-suited.
CRGreathouse is offline   Reply With Quote
Old 2010-12-02, 00:31   #1898
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Create a two-dimensional array at runtime
I don't remember that problem description off the top of my head, but isn't that easy to do with matrix()?
CRGreathouse is offline   Reply With Quote
Old 2010-12-02, 00:34   #1899
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
How about we simply apply the iterative definition?

Start with a.

a + 1

Let a + b = a + 1 + 1 + 1 + 1 + 1 + 1 + 1....

Let a * b = a + a + a + a + a + a + a + a + a + ....

Let a^b = a * a * a * a * a * a..

Etc.
It's not at all clear how you'd code this. (Yes, I know of a way to code it, but I'm not sure that it's related to what you're saying.) And wouldn't that method be slow? If 2^1000 expands out into the (2^1000 - 1)-times-iterated successor of 1, it will take at least 2^1000 - 1 steps to compute...
CRGreathouse is offline   Reply With Quote
Old 2010-12-02, 00:36   #1900
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
It's not at all clear how you'd code this. (Yes, I know of a way to code it, but I'm not sure that it's related to what you're saying.) And wouldn't that method be slow? If 2^1000 expands out into the (2^1000 - 1)-times-iterated successor of 1, it will take at least 2^1000 - 1 steps to compute...
A solution would be to make each into its own operator, so the expansion of 2^1000 into 1 + 1 + 1 + 1 + 1 + 1 + 1 + ... (2^1000 terms) is avoided.

a + 1, a + b, a * b, a^b should be independent of each other. Albeit, I think I would have to defy the rule and use the built-in calculator.

Last fiddled with by 3.14159 on 2010-12-02 at 00:40
3.14159 is offline   Reply With Quote
Old 2010-12-02, 00:41   #1901
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
A solution would be to make each into its own operator, so the expansion of 2^1000 into 1 + 1 + 1 + 1 + 1 + 1 + 1 + ... (2^1000 terms) is avoided.
But if the exponentiation function calls the multiplication function, and the multiplication function calls the addition function, and the addition function calls the successor function, then you will have a total of 2^1000 - 1 calls to the successor function unless you memoize the results (etc.).
CRGreathouse is offline   Reply With Quote
Old 2010-12-02, 00:42   #1902
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
I don't remember that problem description off the top of my head, but isn't that easy to do with matrix()?
oh I read the done list lol.
science_man_88 is offline   Reply With Quote
Old 2010-12-02, 01:33   #1903
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

Code:
palindrome(string) ={ 
my(string=eval(Vec(Str(string))));
for(x=1,ceil(#string/2),
           if(string[x]!=string[#string-(x-1)],
              break(),
              print(string)
           )
   );
}
CRG approval ?
science_man_88 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:56.


Fri Aug 6 22:56:09 UTC 2021 up 14 days, 17:25, 1 user, load averages: 4.42, 4.23, 4.01

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.