![]() |
|
|
#2432 |
|
"Forget I exist"
Jul 2009
Dumbassville
838410 Posts |
reading a possibly old manual it seems there's so many different ways to get the same answer:
squaring x ( it seems) Code:
norm(x) \\ for integers at least sqr(x) x^2 Code:
trace(x) 2*x x<<1 Last fiddled with by science_man_88 on 2013-07-29 at 20:34 |
|
|
|
|
|
#2433 | |
|
Aug 2006
3·1,993 Posts |
Quote:
|
|
|
|
|
|
|
#2434 |
|
Jul 2013
Brazil
238 Posts |
So, about the highlight, I couldn't make it, since it's necessary JSON and I don't know nothing about it.
Now, about the fractional part to integer, I could make this: Code:
r2i(a)={
my(b=Vec(Str(a)),c=b[#Str(ceil(a))+2..#b],d=eval(c));
forstep(x=#d,1,-1,if(d[x]!=0,h=x;break;));
e=vecextract(c,[1..h]);
x=eval(e);
v2i1d(x)
}
Code:
v2i1d(a)=subst(Pol(a), 'x, 10) |
|
|
|
|
|
#2435 |
|
Aug 2006
3×1,993 Posts |
If the last part of your script is just removing trailing zeros, you can do that faster with
Code:
removeTrailingZeros(n)={
n / 10^valuation(n, 10)
};
|
|
|
|
|
|
#2436 | |
|
Jul 2013
Brazil
19 Posts |
Quote:
Code:
removeTrailingZeros(n)={
n / 10^valuation(n, 10)
};
v2i1d(a)=subst(Pol(a), 'x, 10);
r2i(a)={
my(b=Vec(Str(a)),c=b[#Str(ceil(a))+2..#b],d=eval(c));
removeTrailingZeros(v2i1d(d))
}.;
|
|
|
|
|
|
|
#2437 |
|
Feb 2014
2 Posts |
Hi, i just started learning pari and im trying to use store the prime factor of a value. im using a=factor(1599) but it stores only the results of the prime factor. can someone give me some guidance on how i could store any of the prime factor value to a variable?
|
|
|
|
|
|
#2438 |
|
Feb 2014
2 Posts |
hi, im new to pari/gp and i need some guidance on how to go about storing my factor value into a variable. i have for example 192384 and i need to get 1 of the prime factor of this value.
i tried storing it to a variable "a=factor(192384)" but it stores all the prime value to it. can anyone guide me how i could get 1 of the prime factor please. |
|
|
|
|
|
#2439 |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
I was trying to look up a list of mersenne factors somewhere else online and by Google search got to this code on rosettacode.org but there's some parts I don't understand can anyone help explain it ?
Code:
factorMersenne(p)={
forstep(q=2*p+1,sqrt(2)<<(p\2),2*p,
[1,0,0,0,0,0,1][q%8] && Mod(2, q)^p==1 && return(q)
);
1<<p-1
};
Last fiddled with by science_man_88 on 2014-04-26 at 01:54 |
|
|
|
|
|
#2440 |
|
Jun 2003
508710 Posts |
sqrt(2)<<(p\2) = sqrt(2) * 2^((p-1)/2)which is a fancy way of saying sqrt(Mp). [a << b = a left shifted b bits]
[1,0,0,0,0,0,1][q%8] is a shorthand way of saying v=[1,0,0,0,0,0,1]; v[q%8]. Just a way to test if q%8 == 1 or 7 |
|
|
|
|
|
#2441 |
|
Romulan Interpreter
Jun 2011
Thailand
26·151 Posts |
When you check for factors of a number, you only need to check up to square root of the number. The limit is an obfuscated way to write sqrt(2^p-1), or sqrt(1<<p-1), if you like, which might be a bit faster because of the internal pari representation. In fact, its speed depends on the number of decimals, and it could be much faster if you first set default(realprecision,5), get the root and set the realprecision back. The backslash is integer division. Anyhow, the speed of this calculus is not relevant, because it is only executed once in the beginning, and only takes few milliseconds.
The "vectored" part you can understand it better if you write: v=[9,8,7,6]; a=v[2] This will return 8. Now imagine you don't use v, but write directly the constant, as "a=[9,8,7,6][2]", this will still return 8. (indexing starts with 1) The faster way to write "if x%8==1 or x%8==7" is what you see marked red in your text. There is no faster way, this involve a modulus and a selection (pointer). If you do "y=x%8, if y==1 or y==7", you may do the calculus only once, but still do the comparison two times at each loop. So, this loop is very fast, but due to the fact that it tests all 2kp+1 candidates, it is still about 3-4 times slower than the "tf_420c" function which I posted here around, which tests only the candidates in the right classes (which stand a miniscule chance to be prime). Even that function is much slower that other stuff like mfaktc because it does not do sieving, it does not run multithreaded, and pari is not compiled, but interpreted.edit: Grrrr axn! Last fiddled with by LaurV on 2014-04-26 at 04:19 |
|
|
|
|
|
#2442 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Code:
? a=[1,2,3,4,5]; forstep(x=1,100,v=eval(a), print(x","a); a=vector(#a,n,a[#a-n+1]+a[n%#a+1]) ;v=eval(a) ) 1,[1, 2, 3, 4, 5] 2,[7, 7, 7, 7, 2] 16,[9, 14, 14, 9, 14] 39,[28, 23, 23, 28, 18] 67,[41, 51, 51, 41, 56] |
|
|
|
|
![]() |
| 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 |