mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Other Mathematical Topics

Reply
 
Thread Tools
Old 2017-03-01, 04:39   #1
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3×372 Posts
Default Help with series convergence in Fermat method of factoring

First my apologies for not having the background to point to the previous works, which would allow me to find what I'm searching for a bit easier. I'm using a procedure based on Fermat's factorization method, but I'm searching for the squares by using the sums of the intervals of squares. Anyway, this is a little different look at the difference of two squares and I'm stuck.

I know that If I take a composite that is made up of two primes I can find those primes using the two squares which differ by the composite.

However, finding the two squares is the difficult part as the numbers get larger. I have an example C++ program further on. The variables in parentheses refer to the variables in the later program. By using the following method, the appropriate squares can be found:

-start with a composite (comp)

-find the closest squares below and above comp (hsq1 and hsq2, respectively)

-find the difference between hsq1 and hsq2 (hsqdiff)

-find the difference between hsq2 and comp (cdiff)

-find the closest two squares below and above cdiff (lsq1 and lsq2, respectively)

-find the difference between lsq1 and lsq2 (lsqdiff)

-add comp to lsq1 (clsq)

{start of loop}
-compare clsq with hsq2 (check)

--if check == 0, the two squares are hsq2 and clsq-comp
--break loop

--if check >0
---add 2 to hsqdiff (hsqdiff)
---add hsqdiff to hsq2
---go back to start of loop

--if check <0
---add lsqdiff to clsq
---add 2 to lsqdiff (lsqdiff)
---go back to start of loop
{end of loop}

A working c++ example:
Code:
#include <iostream>
#include <gmp.h>

using namespace std;

int main()
{
    mpz_t one, two, comp, hsq1, hsq2, hsqdiff, cdiff, lsq1, lsq2, lsqdiff, clsq, sqrt, sqrt2, factor1, factor2;
    mpz_inits(one, two, comp, hsq1, hsq2, hsqdiff, cdiff, lsq1, lsq2, lsqdiff, clsq, sqrt, sqrt2, factor1, factor2, NULL);
    int check;

    //initialize comp and two static variables
    mpz_set_str(comp, "152851016917", 10);
    mpz_set_str(one, "1", 10);
    mpz_set_str(two, "2", 10);
    gmp_printf("comp is: %Zd\n", comp);

    //find closest squares below and above comp
    mpz_sqrt(sqrt, comp);
    mpz_mul(hsq1, sqrt, sqrt);
    mpz_add(sqrt, sqrt, one);
    mpz_mul(hsq2, sqrt, sqrt);
    gmp_printf("hsq1 is: %Zd and hsq2 is: %Zd\n", hsq1, hsq2);

    //find difference between hsq1 and hsq2
    mpz_sub(hsqdiff, hsq2, hsq1);
    gmp_printf("The difference between hsq2 and hsq1 is: %Zd\n", hsqdiff);

    //find difference between hsq2 and comp
    mpz_sub(cdiff, hsq2, comp);
    gmp_printf("The difference between hsq2 and comp is: %Zd\n", cdiff);

    //find closest squares below and above cdiff
    mpz_sqrt(sqrt, cdiff);
    mpz_mul(lsq1, sqrt, sqrt);
    mpz_add(sqrt, sqrt, one);
    mpz_mul(lsq2, sqrt, sqrt);
    gmp_printf("lsq1 is: %Zd and lsq2 is: %Zd\n", lsq1, lsq2);

    //find difference between lsq1 and lsq2
    mpz_sub(lsqdiff, lsq2, lsq1);
    gmp_printf("The difference between lsq2 and lsq1 is: %Zd\n", lsqdiff);

    //add comp to lsq1
    mpz_add(clsq, comp, lsq1);
    gmp_printf("clsq is: %Zd\n", clsq);

    //loop to advance squares
    do{
        //compare sum of lsq2 and comp with hsq2
        check=mpz_cmp(clsq, hsq2);

        if (check>0){
            mpz_add(hsqdiff, hsqdiff, two);
            mpz_add(hsq2, hsq2, hsqdiff);
        }
        if (check<0){
            mpz_add(clsq, clsq, lsqdiff);
            mpz_add(lsqdiff, lsqdiff, two);
        }
    }while (check!=0);

    //retrieve low square
    mpz_sub(lsq2, clsq, comp);

    gmp_printf("The high square is: %Zd and the low square is: %Zd\n", hsq2, lsq2);

    //get square roots
    mpz_sqrt(sqrt2, hsq2);
    mpz_sqrt(sqrt, lsq2);
    gmp_printf("The square roots are %Zd and %Zd\n", sqrt, sqrt2);

    //calculate factors
    mpz_add(factor1, sqrt2, sqrt);
    mpz_sub(factor2, sqrt2, sqrt);
    gmp_printf("The factors are %Zd and %Zd\n", factor1, factor2);

    return 0;
}
The result of the above code is:
Code:
comp is: 152851016917
hsq1 is: 152850503521 and hsq2 is: 152851285444
The difference between hsq2 and hsq1 is: 781923
The difference between hsq2 and comp is: 268527
lsq1 is: 268324 and lsq2 is: 269361
The difference between lsq2 and lsq1 is: 1037
clsq is: 152851285241
The high square is: 44264790806041 and the low square is: 44111939789124
The square roots are 6641682 and 6653179
The factors are 13294861 and 11497
The above works, but is obviously slow compared to other methods. Where I'm stuck is that there should be a way to calculate the convergence point of the progressions of the two series, instead of advancing the series and testing. That method is what I'm looking for and I'm sure someone has already worked this out, but I don't know where to look.

In my do-while loop, I'm simply advancing the lower series by square differences and once the value has surpassed the high square, I advance the high square to the next square. The difference swings above and below 0, until at some point it equals 0. This zero point is what I'm looking for, but instead of stepping to that point, I'd like to calculate that point based on the series' intervals. The reason I'm having trouble is that the intervals increase by 2 for each step and the smaller series is increasing by smaller, more frequent steps.

In practice, using the above example, the higher series is:
Code:
hsq2, hsq2+hsqdiff+2, hsq2+hsqdiff*2+6, hsq2+hsqdiff*3+12, ...
152851285444, 152852067369, 152852849296, 152853631225, ..., 44264790806041
the lower series is:
Code:
clsq, clsq+lsqdiff, clsq+lsqdiff*2+2, clsq+lsqdiff*3+6, ...
152851285241, 152851286278, 152851287317, 152851288358, ..., 44264790806041
Knowing the starting values of hsq2 and clsq, and the element progression for each series, shouldn't I be able to calculate when/where they would be equal?

Thanks for all help...
EdH is offline   Reply With Quote
Old 2017-03-01, 19:20   #2
mahbel
 
"mahfoud belhadj"
Feb 2017
Kitchener, Ontario

1111002 Posts
Default

I don't know how helpful the following is but your number N=152851016917 is a (6k+1) type of number. So the squares in N + n^2 = m^2 must be of the following form: n=3k and m=10+3j. Then your number becomes N + 9k^2 = (10+3j)^2. You obviously don't need to start with m=10. You get the starting point from the sqrt(N). That is if your number is 217=7*31, your starting point is m=10+3=13 because 13^2 is the first square of the correct from below 217. This will allow you to discard a lot of squares that do not have the right form. The other simple trick is the fact that N and m^2 must have have the same sum of digits. In the case of N=217, you can jump straight to m^2=19^2 since 13^2 and 16^2 do not have the same sum of digits. Good luck to you.
mahbel is offline   Reply With Quote
Old 2017-03-01, 23:09   #3
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3×372 Posts
Default

Thanks for the reply. I'm more interested in the general concept than specific forms of composites right now. The number chosen was simply a composite that only had two primes and was handy. But, thank you for the effort in responding.
EdH is offline   Reply With Quote
Old 2017-03-02, 18:05   #4
fivemack
(loop (#_fork))
 
fivemack's Avatar
 
Feb 2006
Cambridge, England

22×32×179 Posts
Default

Quote:
Originally Posted by EdH View Post
In my do-while loop, I'm simply advancing the lower series by square differences and once the value has surpassed the high square, I advance the high square to the next square. The difference swings above and below 0, until at some point it equals 0
You don't need the lower series - you just need to advance the high series until the difference is _some_ square, and checking whether a number is a square isn't too difficult. If a number is a possible-square-mod-p for lots of p, it's pretty likely to be square, and each p rules out about half the numbers ... you can keep track of the values of the high series modulo lots of p quite efficiently since you're only doing addition.
fivemack is offline   Reply With Quote
Old 2017-03-02, 23:58   #5
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3·372 Posts
Default

Quote:
Originally Posted by fivemack View Post
You don't need the lower series - you just need to advance the high series until the difference is _some_ square, and checking whether a number is a square isn't too difficult. If a number is a possible-square-mod-p for lots of p, it's pretty likely to be square, and each p rules out about half the numbers ... you can keep track of the values of the high series modulo lots of p quite efficiently since you're only doing addition.
Thanks fivemack, but I realize that I can do addition/testing for a long time to find the right lower square. I'm looking for a way to calculate the coincidence rather than stepping to it, which would take a thousand years for some of the larger composites. I've been trying to see if I can find a way via modular means, but I'm too darn rusty with any background in math I may have had long ago. Maybe there isn't a way to do what I'm looking for and that's why I can't find it.

In a way, I'm picturing two graphs converging to the crossover, but the two series are really just two sections of the same graph, without the composite offset. If I can "visualize" a way to work this, maybe a function can be derived. I suspect, that function already is known by everyone, but I don't know enough to describe it properly or recognize it, yet.

Thank you very much for all your help.
EdH is offline   Reply With Quote
Old 2017-03-03, 07:58   #6
fivemack
(loop (#_fork))
 
fivemack's Avatar
 
Feb 2006
Cambridge, England

22×32×179 Posts
Default

Quote:
Originally Posted by EdH View Post
Thanks fivemack, but I realize that I can do addition/testing for a long time to find the right lower square. I'm looking for a way to calculate the coincidence rather than stepping to it, which would take a thousand years for some of the larger composites.
If you were stepping along the two sequences in perfect sequence, it's just a problem in quadratic equations; but the variable stepping rates make it much more difficult.

You're looking for a point on the conic Y^2-N=X^2, and there are good ways to do this iff you know the factorisation of N :)
fivemack is offline   Reply With Quote
Old 2017-03-03, 14:32   #7
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3×372 Posts
Default

Quote:
Originally Posted by fivemack View Post
If you were stepping along the two sequences in perfect sequence, it's just a problem in quadratic equations; but the variable stepping rates make it much more difficult.

You're looking for a point on the conic Y^2-N=X^2, and there are good ways to do this iff you know the factorisation of N :)
Thanks fivemack! This gives me an area for my next study...
EdH is offline   Reply With Quote
Old 2017-03-05, 16:31   #8
a1call
 
a1call's Avatar
 
"Rashid Naimi"
Oct 2015
Remote to Here/There

2·1,087 Posts
Default

Perhaps you shouldn't dismiss mahbel's remarks so quickly. I can't quite follow what he is stating but he is telling you that rather than blindly searching for squares, you can narrow your search to relevant forms.
It also helps to analyze routines with small numeric examples instead of astronomically large ones.
Suppose you want to factor 21,
5-2 | 21=5^2-2^2
You could build some intelligence into your search by knowing effective ranges and rules. You could also extend your search to powers other than 2.
For example:

n^5-m^3 | n^(5j)-m(3j)
3 and 5 are arbitrary and can be replaced by any integers (or primes if you prefer).
But generally there is a commonality to the form of the composite candidate and it's sub-power factors that can be built as intelligence into the search.

The Mersenne numbers are a subset of this rule of the form:

2^n-1^m | 2^(nj)-1^(mj)

Last fiddled with by a1call on 2017-03-05 at 16:37
a1call is offline   Reply With Quote
Old 2017-03-05, 16:46   #9
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3·372 Posts
Default

Quote:
Originally Posted by a1call View Post
Perhaps you shouldn't dismiss mahbel's remarks so quickly. I can't quite follow what he is stating but he is telling you that rather than blindly searching for squares, you can narrow your search to relevant forms.
It also helps to analyze routines with small numeric examples instead of astronomically large ones.
Suppose you want to factor 21,
5-2 | 21=5^2-2^2
You could build some intelligence into your search by knowing effective ranges and rules. You could also extend your search to powers other than 2.
For example:

n^5-m^3 | n^(5j)-m(3j)
3 and 5 are arbitrary and can be replaced by any integers.
But generally there is a commonality to the form of the composite candidate and it's sub-power factors that can be built as intelligence into the search.

The Mersenne numbers are a subset of this rule of the form:

2^n-1^m | 2^(nj)-1^(mj)
Thank you for your post. I'm not tossing everything aside, but I am trying to find something that doesn't really involve filtering search criteria, per se. It would seem that even though he shows a way to reduce the search squares, there will still be too many to effectively test each one for larger composites. As for size issues, I'm currently playing with a grid of numbers based from 0 through 1600 and am learning some very interesting (to me) things.

Thank you very much for your post.
EdH is offline   Reply With Quote
Old 2017-03-05, 17:14   #10
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

100000110000002 Posts
Default

Quote:
Originally Posted by EdH View Post
Thank you for your post. I'm not tossing everything aside, but I am trying to find something that doesn't really involve filtering search criteria, per se. It would seem that even though he shows a way to reduce the search squares, there will still be too many to effectively test each one for larger composites. As for size issues, I'm currently playing with a grid of numbers based from 0 through 1600 and am learning some very interesting (to me) things.

Thank you very much for your post.
at least fermat's idea isn't brute forcing the values such that 2kj+k+j = l such that 2l+1 = N like an inverse to the sieve of sundaram.
science_man_88 is offline   Reply With Quote
Old 2017-03-05, 19:46   #11
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

if N=p*q then N= ((p+q)/2)^2-((p-q)/2)^2 of course but without p and q these formulae are pointless.
science_man_88 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
radius of convergence of a complex power series wildrabbitt Math 3 2016-08-16 08:38
Modification of Fermat's method rdotson Miscellaneous Math 0 2007-07-27 10:32
Elliptic Curve Method factoring - Fermat numbers philmoore Math 131 2006-12-18 06:27
Fermat's factoring method with Gauss's inprovement Carlos Programming 0 2005-09-11 12:50
Convergence of infinite series LoKI.GuZ Math 10 2004-11-28 03:07

All times are UTC. The time now is 06:20.


Tue Nov 30 06:20:03 UTC 2021 up 130 days, 49 mins, 0 users, load averages: 1.16, 1.01, 1.00

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.