![]() |
|
|
#2388 | |
|
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
9,497 Posts |
Quote:
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! |
|
|
|
|
|
|
#2389 |
|
Romulan Interpreter
Jun 2011
Thailand
966410 Posts |
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 |
|
|
|
|
|
#2390 |
|
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
9,497 Posts |
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; |
|
|
|
|
|
#2391 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
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 |
|
|
|
|
|
|
#2392 | |
|
Aug 2006
597910 Posts |
Quote:
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 |
|
|
|
|
|
|
#2393 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Quote:
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)) |
|
|
|
|
|
|
#2394 |
|
Aug 2006
3·1,993 Posts |
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 |
|
|
|
|
|
#2395 |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
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 |
|
|
|
|
|
#2396 | |
|
Aug 2006
135338 Posts |
Quote:
Code:
> for(x=1,1e6,bitneg(bitxor(bitneg(x),2))) time = 734 ms. > for(x=1,1e6,x+2) time = 428 ms. |
|
|
|
|
|
|
#2397 |
|
Jul 2013
Brazil
1910 Posts |
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.
|
|
|
|
|
|
#2398 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
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]) to go the same way as your digits function: Code:
a=123;a=eval(Vec(Str(a))) Last fiddled with by science_man_88 on 2013-07-22 at 13:27 |
|
|
|
|
![]() |
| 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 |