mersenneforum.org  

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

Reply
 
Thread Tools
Old 2013-06-22, 08:02   #2388
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

9,497 Posts
Default

Quote:
Originally Posted by LaurV View Post
That was a system malfunction... How the programmer decided if the cabbages have eggs? Anyhow, the result is wrong in all cases: if no eggs, he should come with two cabbages. If someone had eggs (the grocery, the cabbage, the seller, whatever), then the guy should return with 14 cabbages...
The seller didn't have eggs... he had balls!

Last fiddled with by Batalov on 2013-06-22 at 08:07 Reason: Must clarify for non-slavic people: the same word for both in some slavic languages!
Batalov is offline   Reply With Quote
Old 2013-06-22, 08:09   #2389
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
Jun 2011
Thailand

26×151 Posts
Default

And that is how your world turns upside-down

As a programmer-for-living for few decades, changing my tools many times (sometime few times per year, depending of the projects I was working for) I learned a good lesson: you have to know your tools. You would be surprised how many other languages "fsck up with logic". As I already mentioned MQL, you can see for yourself that || take precedence to && (which, to my feeling, hurts more than putting all in the same bowl). But well, everything has a reason. However, after people insisted (we were discussing there, same as me and you discussing here now) they changed it in version 5 of the language, to a more mathematical way.

Staying on pari, you will be even more confused when you will find out that there are no bitwise & and | operators, and in fact they are equivalent to && and respective ||, hehe.

Last fiddled with by LaurV on 2013-06-22 at 08:16
LaurV is offline   Reply With Quote
Old 2013-06-22, 08:16   #2390
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

9,497 Posts
Default

Yes, but you don't see them break their own written rules, right?
Run the code with different Pari binaries, and you will see what upsets me.

Most wonderful of course is perl! "There's more than one way to do it! " (c)
Because sometimes they wanted "and" and "or" to have lowest possible precedence*, they have added "and" and "or" in addition to "&&" and "||", and all the difference is precedence. And they didn't break the rules, they just made more rules. But that's honest in my book.

_________
* obligatory example:
Code:
open IN, "<file" or die;
;-)
Batalov is offline   Reply With Quote
Old 2013-06-22, 12:10   #2391
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by Batalov View Post
Yes, but you don't see them break their own written rules, right?
Run the code with different Pari binaries, and you will see what upsets me.

Most wonderful of course is perl! "There's more than one way to do it! " (c)
Because sometimes they wanted "and" and "or" to have lowest possible precedence*, they have added "and" and "or" in addition to "&&" and "||", and all the difference is precedence. And they didn't break the rules, they just made more rules. But that's honest in my book.

_________
* obligatory example:
Code:
open IN, "<file" or die;
;-)
Code:
? n=5678027;s=0;forstep(p=n*(n-1)/2+4,n*(n+1)/2-1,[2,4],if(isprime(p),\
  if(p%6==1,a1=isprime(p+n-1);a3=isprime(p+n+1);if(a1&&(a3||isprime(p-2)||isprime(p+n+n))||(a3&&isprime(p+n+n+2)),s+=p),
  a1=isprime(p+n+1);a2=isprime(p-n+1);if(a2&&(a1||isprime(p-n*2+4))||(a1&&(isprime(p+2)||isprime(p+n+n+2))),s+=p) )));s
%5 = 79697256800321526
? n=5678027;s=0;forstep(p=n*(n-1)/2+4,n*(n+1)/2-1,[2,4],if(isprime(p),\
  if(p%6==1,a1=isprime(p+n-1);a3=isprime(p+n+1);if(a1&&(a3||isprime(p-2)||isprime(p+n+n))||(a3&&isprime(p+n+n+2)),s+=p),
  a1=isprime(p+n+1);a2=isprime(p-n+1);if((a2&&(a1||isprime(p-n*2+4)))||(a1&&(isprime(p+2)||isprime(p+n+n+2))),s+=p) )));
%6 = 79697256800321526
works in 2.5.3
science_man_88 is offline   Reply With Quote
Old 2013-06-23, 01:47   #2392
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by LaurV View Post
Staying on pari, you will be even more confused when you will find out that there are no bitwise & and | operators, and in fact they are equivalent to && and respective ||, hehe.
& and | are deprecated, and have been removed in recent versions.

GP does have bitwise operators, just not convenient C-style ones: bitor, bitand, bitxor, bitnegimply.

Last fiddled with by CRGreathouse on 2013-06-23 at 01:48
CRGreathouse is offline   Reply With Quote
Old 2013-06-25, 22:36   #2393
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
& and | are deprecated, and have been removed in recent versions.

GP does have bitwise operators, just not convenient C-style ones: bitor, bitand, bitxor, bitnegimply.

I've been playing around with these, is there a more reliable way using them to add 2 to a number than:


Code:
 
bitneg(bitxor(bitneg(x),2))
?
science_man_88 is offline   Reply With Quote
Old 2013-06-25, 22:38   #2394
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

175B16 Posts
Default

Code:
x+2
?

Maybe if you tell me what you're trying to accomplish...

Last fiddled with by CRGreathouse on 2013-06-25 at 22:40
CRGreathouse is offline   Reply With Quote
Old 2013-06-25, 22:40   #2395
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
Code:
x+2
?
I was thinking more with the bit operators since in some cases it seems quicker with them. I'm just simply trying to accomplish an addition of 2 just seemed to be fun instead of a forstep loop. edit:though using it for gaps between primes might be fun ( since they divide by 2)

Last fiddled with by science_man_88 on 2013-06-25 at 22:43
science_man_88 is offline   Reply With Quote
Old 2013-06-25, 22:42   #2396
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I was thinking more with the bit operators since in some cases it seems quicker with them.
Doubtful.

Code:
> for(x=1,1e6,bitneg(bitxor(bitneg(x),2)))
time = 734 ms.
> for(x=1,1e6,x+2)
time = 428 ms.
The bitwise versions need to allocate space and then copy three times instead of once, so asymptotically I expect them to take nearly three times as long.
CRGreathouse is offline   Reply With Quote
Old 2013-07-22, 00:53   #2397
ismillo
 
Jul 2013
Brazil

19 Posts
Default

Few weeks ago, I started learning PARI, then some day, I was needed to make a vector turns into an integer, I know it's possible to make an integer turn into an array using the function "digits(n)", but I need to know if somehow I can reverse it. For example: if the vector a=[1,2,3], it will turn into a=123. If the vector b=[12,3,45], it will turn into b=12345.

Thanks for anyone who can help me.
ismillo is offline   Reply With Quote
Old 2013-07-22, 13:14   #2398
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by ismillo View Post
Few weeks ago, I started learning PARI, then some day, I was needed to make a vector turns into an integer, I know it's possible to make an integer turn into an array using the function "digits(n)", but I need to know if somehow I can reverse it. For example: if the vector a=[1,2,3], it will turn into a=123. If the vector b=[12,3,45], it will turn into b=12345.

Thanks for anyone who can help me.
function names depend on version of pari and I'm no expert but:

Code:
 
a=[1,2,3];b=#a;until(#a==1,a[1]=concat(Str(a[1]),Str(a[2]));if(#a==b,a[b-1]=a[b]);a=vector(#a-1,n,a[n]));a=eval(a[1])
appears to work for me ( but is pretty complicated in my mind) ( edit:no it doesn't I made an error):

to go the same way as your digits function:

Code:
a=123;a=eval(Vec(Str(a)))
works

Last fiddled with by science_man_88 on 2013-07-22 at 13:27
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 21:15.


Fri Aug 6 21:15:06 UTC 2021 up 14 days, 15:44, 1 user, load averages: 2.56, 2.52, 2.52

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.