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)

3.14159 2010-12-02 00:25

[QUOTE=CRGreathouse;239564]Not allowed, see the problem description.[/QUOTE]

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.

3.14159 2010-12-02 00:26

[QUOTE=CRGreathouse;239566]Wow, that's a lot of decimal places. Can we assume you were born at 7:19:00.00000000000000000006 PM, then? :razz:


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++.[/QUOTE]

Actually, I was born at 2:45 AM, on a Thursday.

science_man_88 2010-12-02 00:28

[url]http://rosettacode.org/wiki/Palindrome_detection[/url]

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.

3.14159 2010-12-02 00:29

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.

CRGreathouse 2010-12-02 00:30

[QUOTE=3.14159;239556]I think PARI/GP's too weak for those tasks.[/QUOTE]

It is for some -- listed at
[url]http://rosettacode.org/wiki/Category:PARI/GP/Omit[/url]
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 2010-12-02 00:31

[QUOTE=science_man_88;239568]Create a two-dimensional array at runtime[/QUOTE]

I don't remember that problem description off the top of my head, but isn't that easy to do with matrix()?

CRGreathouse 2010-12-02 00:34

[QUOTE=3.14159;239569]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.[/QUOTE]

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

3.14159 2010-12-02 00:36

[QUOTE=CRGreathouse;239576]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...[/QUOTE]

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.

CRGreathouse 2010-12-02 00:41

[QUOTE=3.14159;239577]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.[/QUOTE]

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.).

science_man_88 2010-12-02 00:42

[QUOTE=CRGreathouse;239575]I don't remember that problem description off the top of my head, but isn't that easy to do with matrix()?[/QUOTE]

oh I read the done list lol.

science_man_88 2010-12-02 01:33

[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)
)
);
}
[/CODE]

CRG approval ?


All times are UTC. The time now is 23:09.

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