![]() |
|
|
#12 |
|
Oct 2012
8210 Posts |
I've changed the "gaussian elimination" algorithm, after finding a 1 in the first column, and doing the elimination, I swap the (pivot?) row with the top row.
However the algorithm just runs and runs, without finding any zero vectors. |
|
|
|
|
|
#13 | |
|
"Ben"
Feb 2007
1101101110012 Posts |
Quote:
See here. Sieving involves first solving congruences of the form x^2 == n mod p for each prime p in the factor base. Also, each prime p in the factor base should be a quadratic residue mod n. I'm not sure if you've placed this restriction on your factor base or not, but you should. You can conduct quadratic residue tests using the Legendre symbol, and there are various methods for solving quadratic congruences. |
|
|
|
|
|
|
#14 | ||
|
Basketry That Evening!
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88
3·29·83 Posts |
Okay, lets try this from the top.
First, watch the first 14:30 of this lecture about Gaussian elimination. He talks about it in the context of solving systems of equations, but our use case is slightly different.* (The rest of the lecture is about other, perhaps more common/useful applications of elimination, but aren't necessary for QS purposes.) AFTER you've watched the first 14:30: What he demonstrates is elimination on a square matrix, reducing it to an upper triangular matrix (i.e., zeros below all pivots, for an arbitrary (non-square) matrix it's called row echelon form). In our case, we need the reduced row echelon form. We do this by performing Gauss-Jordan elimination, which is the same except that we keep going after row echelon form. Instead of eliminating below the pivots, we know eliminate above the pivots, starting with the very last row/pivot/equation. (So it's as if we rotate the matrix 180 degrees and do Gaussian elimination over again; in the terminology of the lecture, we do backwards elimination after having done forward elimination.) After this is done, we can read the nullspace off of the reduced row echelon form of the matrix. (By the way, we don't need to augment our matrix with the identity matrix and track that -- that's how we compute the inverse, but that's not what we're trying to do.) Actually, just watch this second lecture (this time, the entirety of it). I couldn't remember how to read the nullspace off the rref form of the matrix, so I watched it myself, but there's little point in me writing it down when you can watch it yourself. (He's good at explaining things.) ____________________________________________________________________________________________________________________ Quote:
Quote:
Last fiddled with by Dubslow on 2012-11-07 at 22:57 |
||
|
|
|
|
|
#15 | |
|
Oct 2012
2·41 Posts |
I did have a section of code which only allowed primes with a legendre symbol of +1 to be in the factor base, but I found this reduced the size of the factor base quite a bit, and it was harder to get an n by n+1 matrix.
My problem with the 'real' sieve is that I don't know how much data to collect before running the sieve, I might end up with too few values. I guess my code needs a complete overhaul, follow the method properly, then I can worry about entering the correct parameters later ![]() Thank you for the links to those video lectures, the first one really cleared up what I'm supposed to be doing, I'm about to watch the second one now :) For solving the quadratic congruences, could I use this function? Quote:
Last fiddled with by Sam Kennedy on 2012-11-08 at 00:07 |
|
|
|
|
|
|
#16 | |
|
Sep 2012
416 Posts |
I'm trying to understand how this matrix thing works and I think I've got it until the backwards elimination.
Let's take this for example : N=2041 FB=2,3,5,7 So, starting from (sqroot N) ^ 2 - N I get this values : 168 -> 47 360 -> 49 768 -> 53 1440 -> 59 ok, so without using matrix I can solve this by 368x1440 = 518400 which is a square (720) mod N (2041) = 720 , then 49x59 = 2891 mod N (2041) = 850 then finding factors gcd(850+720,2041) = 157 , gcd(850-720,2041) = 13 Now, solving that via matrix is what I can't figure out quite right. So I build matrix like this (168 is the first row (3101), then 360 etc.) : 3 1 0 1 3 2 1 0 8 1 0 0 5 2 1 0 mod 2 : 1 1 0 1 1 0 1 0 0 1 0 0 1 0 1 0 with identity on the right it should be like this : 1101 1000 1010 0100 0100 0010 1010 0001 From what I could figure out from this thread now I start by adding rows with 1 in the first column, so without me writing down all those operations from top to bottom this is what I get in the end : 1101 1000 0111 1100 0100 0010 0111 1001 And this is where I'm stuck and don't know really how to continue. Also I'm not sure whether identity matrix on the right should even be used or not (from Dubslow post above) Quote:
Thanks. |
|
|
|
|
|
|
#17 |
|
Romulan Interpreter
Jun 2011
Thailand
7·1,373 Posts |
Your goal is to get a line to be all zeros in the matrix (see post #2). For this, usually you need more lines then columns.
N=2041 FB=2,3,5,7 int(sqrt(n))=45 (I will use code tag for alignment) Code:
46^2 = 75 = 2^0 * 3^1 * 5^2 * 7^0 (mod 2041) 47^2 = 168 = 2^3 * 3^1 * 5^0 * 7^1 (mod 2041) 49^2 = 360 = 2^3 * 3^2 * 5^1 * 7^0 (mod 2041) 51^2 = 560 = 2^4 * 3^0 * 5^1 * 7^1 (mod 2041) 53^2 = 768 = 2^8 * 3^1 * 5^0 * 7^0 (mod 2041) 0,1,0,0 1,1,0,1 1,0,1,0 0,0,1,1 0,1,0,0 You put the identity on the right (the identity represent how many times you considered/added each equation, and it is a 5x5 matrix), and after a couple of additions you get (one possibility, remember the goal is to get a line of zeroes on the left) 0,1,0,0 | 1,0,0,0,0 1,1,0,1 | 0,1,0,0,0 1,0,1,0 | 0,0,1,0,0 0,0,1,1 | 0,0,0,1,0 0,1,0,0 | 0,0,0,0,1 ==> (added second line to the first to get a 1 in first col, you could get that by sorting too, but we talk about concept, not optimization) 1,0,0,1 | 1,1,0,0,0 1,1,0,1 | 0,1,0,0,0 1,0,1,0 | 0,0,1,0,0 0,0,1,1 | 0,0,0,1,0 0,1,0,0 | 0,0,0,0,1 ==> (added first line to all which have 1 in first column, to get rid of the 1's) 1,0,0,1 | 1,1,0,0,0 0,1,0,0 | 1,0,0,0,0 0,0,1,1 | 1,1,1,0,0 0,0,1,1 | 0,0,0,1,0 0,1,0,0 | 0,0,0,0,1 ==> 1,0,0,1 | 1,1,0,0,0 0,1,0,0 | 1,0,0,0,0 0,0,1,1 | 1,1,1,0,0 0,0,1,1 | 0,0,0,1,0 0,0,0,0 | 1,0,0,0,1 ==> 1,0,0,1 | 1,1,0,0,0 0,1,0,0 | 1,0,0,0,0 0,0,1,1 | 1,1,1,0,0 0,0,0,0 | 1,1,1,1,0 0,0,0,0 | 1,0,0,0,1 So, if you multiply first 4 together, or the first and the last one (this you see from the right side, of course you can stop when you get first red line, I continued one step more for clarity) then you get a square. From here is solving by congruences of squares. (46*56)^2=(2^4*3*5)^2 397^2-240^2=0 (mod 2041) gcd(397-240,2041)=157 gcd(397+240,2041)=13 Last fiddled with by LaurV on 2013-01-09 at 07:27 |
|
|
|
|
|
#18 |
|
Tribal Bullet
Oct 2004
3,541 Posts |
Another way to think about LaurV's example is that when you've changed the matrix on the left to have one or more rows of all-zero, the value of the corresponding solution variable can be anything and all the other rows will still wok. So in his example you can set the last two variables of the solution to random 0 or 1 bits, then proceed with the back substitution to find what the other rows should be once the last two variables have been chosen.
The result is a vector in the nullspace of the matrix. An advantage of this method is that you don't have to track any right-hand-side matrix while the elimination is in progress. |
|
|
|
|
|
#19 | |
|
Sep 2012
22 Posts |
Quote:
|
|
|
|
|
|
|
#20 | |
|
Romulan Interpreter
Jun 2011
Thailand
100101100010112 Posts |
Quote:
-added third line to all the rows below it which have 1 in the third column, to get rid of the ones in the third column (all lines after and including the third have 0 on the first 2 columns) -..... -added n-th line to all the rows below it which have 1 in the n-th column, to get rid of the ones in the n-th column (all lines after and including the n-th have 0 on the first n-1 columns). After you do the n-th step, all rows below the n-th are all zero on the left. That is why you need more then n rows. This is how the Gauss elimination works (well, particularized for this thing). Last fiddled with by LaurV on 2013-01-09 at 16:21 |
|
|
|
|
|
|
#21 |
|
Sep 2012
22 Posts |
I understand, thank you very much sir.
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Java Quadratic Sieve | Ilya Gazman | Factoring | 3 | 2016-02-22 11:32 |
| Finding B in Quadratic Sieve | paul0 | Factoring | 3 | 2011-09-22 17:12 |
| Possible improvement of quadratic sieve | Random Poster | Factoring | 4 | 2010-02-12 03:09 |
| Factoring in the Quadratic Sieve | ThiloHarich | Factoring | 47 | 2007-01-08 14:12 |
| Quadratic Sieve in wikipedia.de | ThiloHarich | Factoring | 5 | 2006-07-14 09:51 |