2

The method described below is different from Euler sum of two squares factorization method. The method below does not require 2 sum of two squares representations to factor a number.

This post was inspired by the post on using the sum of two squares to determine if a number is square free (see Can the sum of two squares be used to determine if a number is square free?"). We will show below that the sum of two squares can definitely be used to factor integers. However, at this point in time, it is not known if this method is fast enough to factor large numbers (hundred digits).

We start with a simple example of $N=a^2+b^2=3*5=15$. We know that this number cannot be decomposed into a sum of two squares (2sq rep). So we square $N$ to get $N^2=M=3^2*5^2=225$. We calculate the two squares representation (2sq rep) of $M$ and find $M=9^2 + 12^2$. At this point we take the GCD of $GCD(9^2,12^2)=9$. So $9$ is a common factor and this means that $M$ can be rewritten as $M=3^2*3^2 + 3^2*4^2= 3^2*(3^2+ 4^2)=3^2*5^2$. The last step is not needed. Once a common factor is found, we know that it is a factor of M and its square root is a factor of N.

To show that the method works for an arbitrary numbers we will provide few more examples. However at this point we only consider numbers of the form $N=pq$ or numbers of the form $N=pq^2$.

Example #1. $N=7*37=259$, $N^2=259^2=67081=84^2 + 245^2$. We calculate $GCD(84^2,245^2)=7^2$. So we find that $7^2$ is a factor of $N^2$ and that $7$ is a factor of $N$.

Example #2. $N=13*17=221$, $N^2=221^2=48841=21^2 + 220^2=85^2 + 204^2= 104^2 + 195^2=140^2 + 171^2$. We calculate the GCD for each 2sq rep.

$$ \begin{split} \gcd(21^2,220^2)&=1\\ \gcd(85^2,204^2)&=289=17^2\\ \gcd(104^2,195^2)&=169=13^2\\ \gcd(140^2,171^2)&=1 \end{split} $$

We that the first and last 2sq rep give no information on the factors of $N^2$ but the 2nd and 3rd 2sq rep provide the squares of the factors of N. This example shows that the sum of two squares can factor an integer provided we consider all 2sq representations of $N^2$ since we don't know which one is going to provide us with the information on the factors.

We now provide an example where the sum of two squares does not work.

Example #3. $N=19*31=589$. This number does not have a sum of two squares. We square it to get $N^2=589^2=0^2 + 589^2$. This 2sq rep provides no information on the original factors of N.

The question is this: can the sum of two squares get the factors of $N^2$ in a reasonable amount of time?

user25406
  • 1,124
  • 1
  • 10
  • 17
  • thanks for the edit. – user25406 Jan 08 '19 at 18:28
  • Yes, I am aware of Euler method but the above method is different. It does not need 2 "sum of 2 squares representation". The first example of $N^2=7^2*37^2= 84^2 + 245^2$ has only one 2sq representation yet we were able to factor the number. Euler's method would not have been able to factor this one. – user25406 Jan 08 '19 at 18:58
  • What method are you using to express the number as a sum of squares? – caden-parajuli Jan 08 '19 at 19:28
  • @coDE_RP, I am using this site http://wims.unice.fr/wims/wims.cgi but I posted (on this site) a method using triangular numbers to express $N$ as a sum of 2 squares. It's simpler to use an online calculator (since I don't code, I would have to do everything by hand). Obviously, I have no idea what method the site uses. – user25406 Jan 08 '19 at 19:33
  • 1
    @user25406, I downloaded the PARI/GP source code for the tool you mentioned. When I ran it, I was able to compute the representation of 100 digit numbers as sums of squares. The only other step is to compute the gcd of each of the representations, which can be done fairly quickly (polynomial time). – caden-parajuli Jan 08 '19 at 20:01
  • thanks for your help – user25406 Jan 08 '19 at 20:53
  • If you dream of a method to factor large numbers efficiently with ONE representation as a sum of two squares, I must disappoint you. – Peter Jan 09 '19 at 09:07
  • @coDE_RP Do you want to say that we can factor each number being the sum of two squares efficiently ? I highly doubt that. – Peter Jan 09 '19 at 09:09
  • 2
    A representation $N=x^2+y^2$ is called primitive if $\gcd(x,y)=1$. It is well known that $N$ has no primitive representations if it is divisible by primes $p\equiv 3 \pmod 4$. What this means is if there are primes $p\equiv 3 \pmod 4$ that divides $N$ and you can find a sum of squares representation, $d =\gcd(x,y)\neq 1$ and $d$ always gives you a product of $p^2$. So yes you can factor certain integers efficiently this way. However for products of $p\equiv 1 \pmod 4$ I believe it is always possible to form primitive representations, so that $\gcd(x,y)=1$. – Yong Hao Ng Jan 09 '19 at 09:49
  • So there is no guarantee that $\gcd(x,y)$ gives you anything. Moreover, from my understanding there are no other obvious usage of the representation to factor $N$. However having such a representation means you can use the Special Number Field Sieve to factor $N$, which I think is faster than the general version in this case. – Yong Hao Ng Jan 09 '19 at 09:55
  • @YongHaoNg In fact the number field sieve is the best general known method. But if we only know one representation as the sum of two squares (for example we can trivially find one for every Fermat number) , this will be of very little use. – Peter Jan 09 '19 at 10:12
  • @Peter Right, I thought we could derive particularly good polynomials for GNFS if we know $N=a^2+b^2$ but upon a closer looking maybe that's not the case. – Yong Hao Ng Jan 09 '19 at 10:46
  • @Peter, we are not talking about using one representation of N. We are talking about representations of $N^2$. And we provided two examples where it was possible to factor $N^2$ and therefore $N$. The 1st example proves that it is possible to factor $N^2$ with just one representation. The 2nd example proves that in the case of $N$ having more than 1 representation, at least one of them can be used to factor $N^2$. Why would large numbers obey different laws? – user25406 Jan 09 '19 at 13:17
  • @YongHaoNg, when using $N$, I agree with you that the $gcd(x,y)$ cannot give a solution in general. But when we are using $N^2$, the $gcd(x,y)$ of at least one representation provides a factor. Please look at the two examples to convince yourself.
    I agree that this method cannot factor products of the form $pq=(4x-1)*(4y-1)$. That was shown in example $3$.
    – user25406 Jan 09 '19 at 13:22
  • @user25406 This requires to know a useful representation. And to find it, will take too long. – Peter Jan 09 '19 at 13:24
  • I agree however that there is a representation allowing the efficient factorization, but this cannot be used in pratice to actually factor huge numbers efficiently which are the sum of two squares. – Peter Jan 09 '19 at 13:27
  • @Peter, sorry Peter, I don't understand your comment before your last one. "This requires to know a useful represenation". Of course it's true. By squaring $N$ we always get at least one useful representation as shown in example 1 and 2 and in the many examples I tried but did not post. – user25406 Jan 09 '19 at 13:28
  • We need a representation for which the gcd is not $1$. Try to find it for large numbers , and you will see the problem. We cannot enumerate all representations for large numbers. – Peter Jan 09 '19 at 13:29
  • Use Fermat's factorization method – qwr Jan 27 '19 at 00:46
  • @qwr, the above method is very different from Fermat's factoring method. Fermat's method is sequential, meaning you test one square, then another, then another until you get the one that solves the problem. In that sense, if the two factors are close together, you converge fast to the right answer but if they are not, you will spend a long time searching for the right square. The method above is not sequential. Once you find the 2 squares representations and you take the gcd, you are done. – user25406 Jan 27 '19 at 00:52
  • Well Fermat's is the basis for very fast methods like quadratic sieve – qwr Jan 27 '19 at 01:14
  • I am familiar with that but I was trying to show that there are other methods that can factor a number without going through a difference of squares. The main drawback is that the above method cannot factor numbers of the form $N=(4x-1)*(4y-1)$. But I just posted a method using the 4 squares representations of an integer that can factor any number since any number can be represented as a sum of 4 squares. – user25406 Jan 27 '19 at 12:51

0 Answers0