mersenneforum.org  

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

Reply
 
Thread Tools
Old 2010-11-27, 18:41   #1717
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Sure.
the important part is this:

Code:
1. Determine the integer square root of N.

    sqrN = Int(Sqr(n))

2. Determine the square of Step 1.

    sqrN2 = sqrN * sqrN

    (Note that sqrN2 is initially the greatest perfect square less than N.)

3. Determine the integer square root of Step 2 minus N.

    PCS = Int(Sqr(Abs(sqrN2 - n)))

      (Let's say PCS means 'perfected counting square'.)

4. Determine if the sum of Step 2 and Step 3 is a factor of N.

    If mod(n, PCS + sqrN) = 0 then we have a factor, and we're done.

      (Similarly, PCS minus sqrN would produce the same result.)

5. If not, add 1 to Step 1 (that is, sqrN+1) and repeat.

I think you can start with a for loop setting the minimum to floor(sqrt(n)) and looping until the number if needed (don't worry there will be a break command). sqrN2 = sqrN * sqrN then set this up as another variable just in the loop( it depends on the loop variable). PCS = Int(Sqr(Abs(sqrN2 - n))) also set in the loop(in th order shown, replacing Int() with floor()). Make and if statement(in the loop) to check the modulus. If it is false do nothing if it is 0 break(1) ( however best practice I think is to use the reverse jmp of asm so may have to reverse something).
science_man_88 is offline   Reply With Quote
Old 2010-11-27, 18:49   #1718
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
the important part is this:

Code:
1. Determine the integer square root of N.

    sqrN = Int(Sqr(n))

2. Determine the square of Step 1.

    sqrN2 = sqrN * sqrN

    (Note that sqrN2 is initially the greatest perfect square less than N.)

3. Determine the integer square root of Step 2 minus N.

    PCS = Int(Sqr(Abs(sqrN2 - n)))

      (Let's say PCS means 'perfected counting square'.)

4. Determine if the sum of Step 2 and Step 3 is a factor of N.

    If mod(n, PCS + sqrN) = 0 then we have a factor, and we're done.

      (Similarly, PCS minus sqrN would produce the same result.)

5. If not, add 1 to Step 1 (that is, sqrN+1) and repeat.

I think you can start with a for loop setting the minimum to floor(sqrt(n)) and looping until the number if needed (don't worry there will be a break command). sqrN2 = sqrN * sqrN then set this up as another variable just in the loop( it depends on the loop variable). PCS = Int(Sqr(Abs(sqrN2 - n))) also set in the loop(in th order shown, replacing Int() with floor()). Make and if statement(in the loop) to check the modulus. If it is false do nothing if it is 0 break(1) ( however best practice I think is to use the reverse jmp of asm so may have to reverse something).
Without all their fluffy language, I understand it as:

1. sqrtint(n).
2. (sqrtint(n))^2.
3. n - (sqrtint(n))^2.
4. (sqrtint(n))^2 + (n -(sqrtint(n))^2) mod n.
5. If (sqrtint(n))^2 + (n -(sqrtint(n))^2) mod n = 0, factors found.
6. If (sqrtint(n))^2 + (n -(sqrtint(n))^2) mod n !=0, repeat steps 1-5 until factors are found.

Last fiddled with by 3.14159 on 2010-11-27 at 18:51
3.14159 is offline   Reply With Quote
Old 2010-11-27, 18:52   #1719
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

I understand it as:

Code:
test(n)=for(sqrN=floor(sqrt(n)),n,sqrN2=sqrn^2;PCS=floor(sqrt(abs(sqrN2-n)));if(Mod(sqrN2+PCS,n)!=0,,break()))
but Pari tells me:

Code:
 *** floor: incorrect type in gfloor.
science_man_88 is offline   Reply With Quote
Old 2010-11-27, 18:53   #1720
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I understand it as:

Code:
test(n)=for(sqrN=floor(sqrt(n)),n,sqrN2=sqrn^2;PCS=floor(sqrt(abs(sqrN2-n)));if(Mod(sqrN2+PCS,n)!=0,,break()))
but Pari tells me:

Code:
 *** floor: incorrect type in gfloor.
Just use sqrtint(n), and n. There's no need to toss in unnecessary variables.

Since they call it "Improved squares", I'll title it, "impsqs".

I'll have to follow the six steps.

Last fiddled with by 3.14159 on 2010-11-27 at 18:56
3.14159 is offline   Reply With Quote
Old 2010-11-27, 18:57   #1721
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Code:
test(n)=for(sqrN=sqrtint(n),n,sqrN2=sqrN^2;PCS=sqrtint(sqrN2-n);if(Mod(sqrN2+PCS,n)!=0,,break()))
now I get:

Code:
*** sqrtint: negative integer in sqrtint.
science_man_88 is offline   Reply With Quote
Old 2010-11-27, 19:00   #1722
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Code:
test(n)=for(sqrN=sqrtint(n),n,sqrN2=sqrN^2;PCS=sqrtint(sqrN2-n);if(Mod(sqrN2+PCS,n)!=0,,break()))
now I get:

Code:
*** sqrtint: negative integer in sqrtint.
Take a closer look at the script. There's a mistake there, and it might be right under your nose.
3.14159 is offline   Reply With Quote
Old 2010-11-27, 19:03   #1723
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Take a closer look at the script. There's a mistake there, and it might be right under your nose.
I don't see it. they have PCS= sqrtint(sqrN2-n).

oh reversed the modulo dah lol.

Last fiddled with by science_man_88 on 2010-11-27 at 19:05
science_man_88 is offline   Reply With Quote
Old 2010-11-27, 19:05   #1724
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I don't see it. they have PCS= sqrtint(sqrN2-n).
Here's how to do it without using a script, in PARI/GP;

Code:
(14:03) gp > 3926696294764459
%203 = 3926696294764459
(14:03) gp > sqrtint(%)
%204 = 62663356
(14:03) gp > %204^2
%205 = 3926696185182736
(14:03) gp > %203-%205
%206 = 109581723
(14:04) gp > Mod(%203, %206 + %204)
%207 = Mod(81019925, 172245079)
Okay, I just realized that was incorrect.

Last fiddled with by 3.14159 on 2010-11-27 at 19:09
3.14159 is offline   Reply With Quote
Old 2010-11-27, 19:09   #1725
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Here's how to do it without using a script, in PARI/GP;

Code:
(14:03) gp > 3926696294764459
%203 = 3926696294764459
(14:03) gp > sqrtint(%)
%204 = 62663356
(14:03) gp > %204^2
%205 = 3926696185182736
(14:03) gp > %203-%205
%206 = 109581723
(14:04) gp > Mod(%203, %206 + %204)
%207 = Mod(81019925, 172245079)
Yeah they point out subtraction should work must of confused me lol.

Quote:
Int(Sqr(Abs(sqrN2 - n)))

Last fiddled with by science_man_88 on 2010-11-27 at 19:10
science_man_88 is offline   Reply With Quote
Old 2010-11-27, 19:13   #1726
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
Yeah they point out subtraction should work must of confused me lol.
The "Abs", means, "The absolute value of".

Therefore, there are no negative numbers involved.

Perhaps you can develop a script from that piece of information.

Last fiddled with by 3.14159 on 2010-11-27 at 19:14
3.14159 is offline   Reply With Quote
Old 2010-11-27, 19:28   #1727
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

I've only got one factor properly, for the number they originally give the example with. The the other factor became 37 though.
science_man_88 is offline   Reply With Quote
Reply

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

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


Fri Aug 6 23:05:49 UTC 2021 up 14 days, 17:34, 1 user, load averages: 3.96, 3.82, 3.89

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.