Skip to content

Commit

Permalink
Merge pull request #1618 from albinahlback/qsieve_binary
Browse files Browse the repository at this point in the history
Use binary represention for relations in qsieve
  • Loading branch information
albinahlback authored Nov 15, 2023
2 parents cc5fbd2 + be04d86 commit 9b81673
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 82 deletions.
19 changes: 12 additions & 7 deletions doc/source/qsieve.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,18 @@
Call for initialization of polynomial, sieving, and scanning of sieve
for all the possible polynomials for particular hypercube i.e. `A`.

.. function:: void qsieve_write_to_file(qs_t qs_inf, mp_limb_t prime, fmpz_t Y, qs_poly_t poly)

Write a relation to the file. Format is as follows,
first write large prime, in case of full relation it is 1, then write exponent
of small primes, then write number of factor followed by offset of factor in
factor base and their exponent and at last value of `Q(x)` for particular relation.
each relation is written in new line.
.. function:: void qsieve_write_to_file(qs_t qs_inf, mp_limb_t prime, const fmpz_t Y, const qs_poly_t poly)

Write a relation to the file in a binary format as follows. First, write
large prime of size ``sizeof(mp_limb_t)``, in case of full relation it is 1.
After this, write the number of small primes with size ``sizeof(slong)``.
Then, write the small primes, with a total size of
``number_of_small_primes * sizeof(slong)``. Then, write the number of
factors with a size of ``sizeof(slong)``. After that, write the factors and
their exponents in the format ``factor_1, exponent_1, factor_2, ...``, all
with a total size of ``2 * number_of_factors * sizeof(slong)``. Then write
``Y`` with the size of ``Y`` first (size ``sizeof(slong)``, that may be
negative), and then its limbs (size ``Y_size * sizeof(mp_limb_t)``).

.. function:: hash_t * qsieve_get_table_entry(qs_t qs_inf, mp_limb_t prime)

Expand Down
6 changes: 3 additions & 3 deletions src/qsieve.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "fmpz_types.h"

#ifdef __cplusplus
extern "C" {
extern "C" {
#endif

#define QS_DEBUG 0 /* level of debug information printed, 0 = none */
Expand Down Expand Up @@ -351,13 +351,13 @@ int qsieve_relations_cmp(const void * a, const void * b);
slong qsieve_merge_relations(qs_t qs_inf);

void qsieve_write_to_file(qs_t qs_inf, mp_limb_t prime,
fmpz_t Y, qs_poly_t poly);
const fmpz_t Y, const qs_poly_t poly);

hash_t * qsieve_get_table_entry(qs_t qs_inf, mp_limb_t prime);

void qsieve_add_to_hashtable(qs_t qs_inf, mp_limb_t prime);

relation_t qsieve_parse_relation(qs_t qs_inf, char * str);
relation_t qsieve_parse_relation(qs_t qs_inf);

relation_t qsieve_merge_relation(qs_t qs_inf, relation_t a, relation_t b);

Expand Down
6 changes: 3 additions & 3 deletions src/qsieve/collect_relations.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ slong qsieve_evaluate_candidate(qs_t qs_inf, ulong i, unsigned char * sieve, qs_
fmpz_add(res, res, C); /* res = AX^2 + 2BX + C */

#if QS_DEBUG & 128
printf("res = "); fmpz_print(res); printf("\n");
flint_printf("res = "); fmpz_print(res); flint_printf("\n");
flint_printf("Poly: "); fmpz_print(qs_inf->A); flint_printf("*x^2 + 2*");
fmpz_print(poly->B); flint_printf("*x + "); fmpz_print(C); printf("\n");
fmpz_print(poly->B); flint_printf("*x + "); fmpz_print(C); flint_printf("\n");
flint_printf("x = %wd\n", i - qs_inf->sieve_size / 2);
#endif

Expand Down Expand Up @@ -356,7 +356,7 @@ slong qsieve_evaluate_candidate(qs_t qs_inf, ulong i, unsigned char * sieve, qs_
{
#if QS_DEBUG
if (qs_inf->full_relation % 100 == 0)
printf("%ld relations\n", qs_inf->full_relation);
flint_printf("%ld relations\n", qs_inf->full_relation);
#endif
/* set sign amongst small factors */
if (fmpz_cmp_si(res, -1) == 0)
Expand Down
16 changes: 8 additions & 8 deletions src/qsieve/compute_poly_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ int qsieve_init_A(qs_t qs_inf)
first_subset[j] = curr_subset[j]; /* save 1st tuple for restarts */

#if QS_DEBUG
printf("First A_ind = (");
flint_printf("First A_ind = (");
for (i = 0; i < s - 1; i++)
printf("%ld, ", A_ind[i]);
printf("%ld", A_ind[s - 1]);
printf(")\n");
flint_printf("%ld, ", A_ind[i]);
flint_printf("%ld", A_ind[s - 1]);
flint_printf(")\n");
#endif
}

Expand Down Expand Up @@ -509,11 +509,11 @@ int qsieve_next_A(qs_t qs_inf)
}

#if QS_DEBUG
printf("A_ind = (");
flint_printf("A_ind = (");
for (i = 0; i < s - 1; i++)
printf("%ld, ", A_ind[i]);
printf("%ld", A_ind[s - 1]);
printf(")\n");
flint_printf("%ld, ", A_ind[i]);
flint_printf("%ld", A_ind[s - 1]);
flint_printf(")\n");
#endif

qs_inf->h = h;
Expand Down
10 changes: 5 additions & 5 deletions src/qsieve/factor.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void qsieve_factor(fmpz_factor_t factors, const fmpz_t n)
flint_printf("Exception (qsieve_factor). GetTempFileNameA() failed.\n");
flint_abort();
}
qs_inf->siqs = (FLINT_FILE *) fopen(qs_inf->fname, "w");
qs_inf->siqs = (FLINT_FILE *) fopen(qs_inf->fname, "wb");
if (qs_inf->siqs == NULL)
flint_throw(FLINT_ERROR, "fopen failed\n");
#else
Expand All @@ -235,7 +235,7 @@ void qsieve_factor(fmpz_factor_t factors, const fmpz_t n)
if (fd == -1)
flint_throw(FLINT_ERROR, "mkstemp failed\n");

qs_inf->siqs = (FLINT_FILE *) fdopen(fd, "w");
qs_inf->siqs = (FLINT_FILE *) fdopen(fd, "wb");
if (qs_inf->siqs == NULL)
flint_throw(FLINT_ERROR, "fdopen failed\n");
#endif
Expand Down Expand Up @@ -406,7 +406,7 @@ void qsieve_factor(fmpz_factor_t factors, const fmpz_t n)

_fmpz_vec_clear(facs, 100);

qs_inf->siqs = (FLINT_FILE *) fopen(qs_inf->fname, "w");
qs_inf->siqs = (FLINT_FILE *) fopen(qs_inf->fname, "wb");
if (qs_inf->siqs == NULL)
flint_throw(FLINT_ERROR, "fopen fail\n");
qs_inf->num_primes = num_primes; /* linear algebra adjusts this */
Expand All @@ -418,7 +418,7 @@ void qsieve_factor(fmpz_factor_t factors, const fmpz_t n)
more_primes: /* ran out of A's in init/sieving of linalg failed, increase FB */

#if QS_DEBUG
printf("Increasing factor base.\n");
flint_printf("Increasing factor base.\n");
#endif

delta = qs_inf->num_primes / 10;
Expand All @@ -442,7 +442,7 @@ void qsieve_factor(fmpz_factor_t factors, const fmpz_t n)
qs_inf->s = 0; /* indicate polynomials need setting up again */

#if QS_DEBUG
printf("Now %ld primes\n", qs_inf->num_primes);
flint_printf("Now %ld primes\n", qs_inf->num_primes);
#endif

if (small_factor)
Expand Down
Loading

0 comments on commit 9b81673

Please sign in to comment.