Skip to content

Commit

Permalink
Merge pull request #1428 from deinst/mpoly_ffmpz
Browse files Browse the repository at this point in the history
Added *_push_term_*_ffmpz functions to mpoly types
  • Loading branch information
fredrik-johansson authored Oct 9, 2023
2 parents 72ff155 + ce46061 commit 462d458
Show file tree
Hide file tree
Showing 20 changed files with 429 additions and 42 deletions.
4 changes: 4 additions & 0 deletions doc/source/fmpq_mpoly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,13 @@ Container operations
Set *M* to the monomial of the term of index *i* in *A*. The coefficient of *M* will be one.

.. function:: void fmpq_mpoly_push_term_fmpq_fmpz(fmpq_mpoly_t A, const fmpq_t c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_fmpq_ffmpz(fmpq_mpoly_t A, const fmpq_t c, const fmpz * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_fmpz_fmpz(fmpq_mpoly_t A, const fmpz_t c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_fmpz_ffmpz(fmpq_mpoly_t A, const fmpz_t c, const fmpz * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_ui_fmpz(fmpq_mpoly_t A, ulong c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_ui_ffmpz(fmpq_mpoly_t A, ulong c, const fmpz * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_si_fmpz(fmpq_mpoly_t A, slong c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_si_ffmpz(fmpq_mpoly_t A, slong c, const fmpz * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_fmpq_ui(fmpq_mpoly_t A, const fmpq_t c, const ulong * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_fmpz_ui(fmpq_mpoly_t A, const fmpz_t c, const ulong * exp, const fmpq_mpoly_ctx_t ctx)
void fmpq_mpoly_push_term_ui_ui(fmpq_mpoly_t A, ulong c, const ulong * exp, const fmpq_mpoly_ctx_t ctx)
Expand Down
3 changes: 3 additions & 0 deletions doc/source/fmpz_mod_mpoly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,11 @@ Container operations
Set *M* to the monomial of the term of index *i* in *A*. The coefficient of *M* will be one.

.. function:: void fmpz_mod_mpoly_push_term_fmpz_fmpz(fmpz_mod_mpoly_t A, const fmpz_t c, fmpz * const * exp, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_push_term_fmpz_ffmpz(fmpz_mod_mpoly_t A, const fmpz_t c, const fmpz * exp, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_push_term_ui_fmpz(fmpz_mod_mpoly_t A, ulong c, fmpz * const * exp, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_push_term_ui_ffmpz(fmpz_mod_mpoly_t A, ulong c, const fmpz * exp, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_push_term_si_fmpz(fmpz_mod_mpoly_t A, slong c, fmpz * const * exp, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_push_term_si_ffmpz(fmpz_mod_mpoly_t A, slong c, const fmpz * exp, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_push_term_fmpz_ui(fmpz_mod_mpoly_t A, const fmpz_t c, const ulong * exp, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_push_term_ui_ui(fmpz_mod_mpoly_t A, ulong c, const ulong * exp, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_push_term_si_ui(fmpz_mod_mpoly_t A, slong c, const ulong * exp, const fmpz_mod_mpoly_ctx_t ctx)
Expand Down
3 changes: 3 additions & 0 deletions doc/source/fmpz_mpoly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,11 @@ Container operations
Set `M` to the monomial of the term of index *i* in *A*. The coefficient of `M` will be one.

.. function:: void fmpz_mpoly_push_term_fmpz_fmpz(fmpz_mpoly_t A, const fmpz_t c, fmpz * const * exp, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_push_term_fmpz_ffmpz(fmpz_mpoly_t A, const fmpz_t c, const fmpz * exp, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_push_term_ui_fmpz(fmpz_mpoly_t A, ulong c, fmpz * const * exp, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_push_term_ui_ffmpz(fmpz_mpoly_t A, ulong c, const fmpz * exp, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_push_term_si_fmpz(fmpz_mpoly_t A, slong c, fmpz * const * exp, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_push_term_si_ffmpz(fmpz_mpoly_t A, slong c, const fmpz * exp, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_push_term_fmpz_ui(fmpz_mpoly_t A, const fmpz_t c, const ulong * exp, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_push_term_ui_ui(fmpz_mpoly_t A, ulong c, const ulong * exp, const fmpz_mpoly_ctx_t ctx)
void fmpz_mpoly_push_term_si_ui(fmpz_mpoly_t A, slong c, const ulong * exp, const fmpz_mpoly_ctx_t ctx)
Expand Down
1 change: 1 addition & 0 deletions doc/source/fq_nmod_mpoly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ Container operations
Set *M* to the monomial of the term of index *i* in *A*. The coefficient of *M* will be one.

.. function:: void fq_nmod_mpoly_push_term_fq_nmod_fmpz(fq_nmod_mpoly_t A, const fq_nmod_t c, fmpz * const * exp, const fq_nmod_mpoly_ctx_t ctx)
void fq_nmod_mpoly_push_term_fq_nmod_ffmpz(fq_nmod_mpoly_t A, const fq_nmod_t c, const fmpz * exp, const fq_nmod_mpoly_ctx_t ctx)
void fq_nmod_mpoly_push_term_fq_nmod_ui(fq_nmod_mpoly_t A, const fq_nmod_t c, const ulong * exp, const fq_nmod_mpoly_ctx_t ctx)

Append a term to *A* with coefficient *c* and exponent vector *exp*.
Expand Down
1 change: 1 addition & 0 deletions doc/source/nmod_mpoly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Container operations
Set *M* to the monomial of the term of index *i* in *A*. The coefficient of *M* will be one.

.. function:: void nmod_mpoly_push_term_ui_fmpz(nmod_mpoly_t A, ulong c, fmpz * const * exp, const nmod_mpoly_ctx_t ctx)
void nmod_mpoly_push_term_ui_ffmpz(nmod_mpoly_t A, ulong c, const fmpz * exp, const nmod_mpoly_ctx_t ctx)
void nmod_mpoly_push_term_ui_ui(nmod_mpoly_t A, ulong c, const ulong * exp, const nmod_mpoly_ctx_t ctx)

Append a term to *A* with coefficient *c* and exponent vector *exp*.
Expand Down
26 changes: 20 additions & 6 deletions src/fmpq_mpoly.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,28 @@ void fmpq_mpoly_get_term_monomial(fmpq_mpoly_t M, const fmpq_mpoly_t A,
void fmpq_mpoly_push_term_fmpq_fmpz(fmpq_mpoly_t A,
const fmpq_t c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx);

void fmpq_mpoly_push_term_fmpz_fmpz(fmpq_mpoly_t A,
const fmpz_t c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx);
void fmpq_mpoly_push_term_fmpq_ffmpz(fmpq_mpoly_t A, const fmpq_t c,
const fmpz *exp, const fmpq_mpoly_ctx_t ctx);

void fmpq_mpoly_push_term_ui_fmpz(fmpq_mpoly_t A,
ulong c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx);
void fmpq_mpoly_push_term_fmpz_fmpz(fmpq_mpoly_t A, const fmpz_t c,
fmpz *const *exp,
const fmpq_mpoly_ctx_t ctx);

void fmpq_mpoly_push_term_si_fmpz(fmpq_mpoly_t A,
slong c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx);
void fmpq_mpoly_push_term_fmpz_ffmpz(fmpq_mpoly_t A, const fmpz_t c,
const fmpz *exp,
const fmpq_mpoly_ctx_t ctx);

void fmpq_mpoly_push_term_ui_fmpz(fmpq_mpoly_t A, ulong c, fmpz *const *exp,
const fmpq_mpoly_ctx_t ctx);

void fmpq_mpoly_push_term_ui_ffmpz(fmpq_mpoly_t A, ulong c, const fmpz *exp,
const fmpq_mpoly_ctx_t ctx);

void fmpq_mpoly_push_term_si_fmpz(fmpq_mpoly_t A, slong c, fmpz *const *exp,
const fmpq_mpoly_ctx_t ctx);

void fmpq_mpoly_push_term_si_ffmpz(fmpq_mpoly_t A, slong c, const fmpz *exp,
const fmpq_mpoly_ctx_t ctx);

void fmpq_mpoly_push_term_fmpq_ui(fmpq_mpoly_t A,
const fmpq_t c, const ulong * exp, const fmpq_mpoly_ctx_t ctx);
Expand Down
48 changes: 48 additions & 0 deletions src/fmpq_mpoly/push_term_fmpq_fmpz.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ void fmpq_mpoly_push_term_fmpq_fmpz(fmpq_mpoly_t A,
fmpq_clear(C);
}

void fmpq_mpoly_push_term_fmpq_ffmpz(fmpq_mpoly_t A,
const fmpq_t c, const fmpz * exp, const fmpq_mpoly_ctx_t ctx)
{
fmpq_t C;
fmpz_init_set(fmpq_numref(C), fmpq_numref(c));
fmpz_init_set(fmpq_denref(C), fmpq_denref(c));
_fmpq_mpoly_push_rescale(A, C, ctx);
_fmpz_mpoly_push_exp_ffmpz(A->zpoly, exp, ctx->zctx);
fmpz_swap(A->zpoly->coeffs + A->zpoly->length - 1, fmpq_numref(C));
fmpq_clear(C);
}

void fmpq_mpoly_push_term_fmpz_fmpz(fmpq_mpoly_t A,
const fmpz_t c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx)
{
Expand All @@ -35,6 +47,18 @@ void fmpq_mpoly_push_term_fmpz_fmpz(fmpq_mpoly_t A,
fmpq_clear(C);
}

void fmpq_mpoly_push_term_fmpz_ffmpz(fmpq_mpoly_t A, const fmpz_t c,
const fmpz *exp, const fmpq_mpoly_ctx_t ctx)
{
fmpq_t C;
fmpz_init_set(fmpq_numref(C), c);
fmpz_init_set_ui(fmpq_denref(C), UWORD(1));
_fmpq_mpoly_push_rescale(A, C, ctx);
_fmpz_mpoly_push_exp_ffmpz(A->zpoly, exp, ctx->zctx);
fmpz_swap(A->zpoly->coeffs + A->zpoly->length - 1, fmpq_numref(C));
fmpq_clear(C);
}

void fmpq_mpoly_push_term_ui_fmpz(fmpq_mpoly_t A,
ulong c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx)
{
Expand All @@ -47,6 +71,18 @@ void fmpq_mpoly_push_term_ui_fmpz(fmpq_mpoly_t A,
fmpq_clear(C);
}

void fmpq_mpoly_push_term_ui_ffmpz(fmpq_mpoly_t A,
ulong c, const fmpz * exp, const fmpq_mpoly_ctx_t ctx)
{
fmpq_t C;
fmpz_init_set_ui(fmpq_numref(C), c);
fmpz_init_set_ui(fmpq_denref(C), UWORD(1));
_fmpq_mpoly_push_rescale(A, C, ctx);
_fmpz_mpoly_push_exp_ffmpz(A->zpoly, exp, ctx->zctx);
fmpz_swap(A->zpoly->coeffs + A->zpoly->length - 1, fmpq_numref(C));
fmpq_clear(C);
}

void fmpq_mpoly_push_term_si_fmpz(fmpq_mpoly_t A,
slong c, fmpz * const * exp, const fmpq_mpoly_ctx_t ctx)
{
Expand All @@ -58,3 +94,15 @@ void fmpq_mpoly_push_term_si_fmpz(fmpq_mpoly_t A,
fmpz_swap(A->zpoly->coeffs + A->zpoly->length - 1, fmpq_numref(C));
fmpq_clear(C);
}

void fmpq_mpoly_push_term_si_ffmpz(fmpq_mpoly_t A,
slong c, const fmpz * exp, const fmpq_mpoly_ctx_t ctx)
{
fmpq_t C;
fmpz_init_set_si(fmpq_numref(C), c);
fmpz_init_set_ui(fmpq_denref(C), UWORD(1));
_fmpq_mpoly_push_rescale(A, C, ctx);
_fmpz_mpoly_push_exp_ffmpz(A->zpoly, exp, ctx->zctx);
fmpz_swap(A->zpoly->coeffs + A->zpoly->length - 1, fmpq_numref(C));
fmpq_clear(C);
}
32 changes: 26 additions & 6 deletions src/fmpq_mpoly/test/t-push_term_fmpq_fmpz.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,32 @@ main(void)
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_mpoly_ctx_t ctx;
fmpq_mpoly_t f1, f2, m;
fmpq_mpoly_t f1, f2, f3, m;
flint_bitcnt_t coeff_bits, exp_bits;
fmpz ** exp, ** exp2;
fmpz **exp, **exp2, *exp3;
slong len, nvars;
fmpq_t c, c2;

fmpq_mpoly_ctx_init_rand(ctx, state, 10);
fmpq_mpoly_init(f1, ctx);
fmpq_mpoly_init(f2, ctx);
fmpq_mpoly_init(f3, ctx);
fmpq_mpoly_init(m, ctx);
fmpq_init(c);
fmpq_init(c2);

nvars = fmpq_mpoly_ctx_nvars(ctx);

exp = (fmpz **) flint_malloc(nvars*sizeof(fmpz *));
exp2 = (fmpz **) flint_malloc(nvars*sizeof(fmpz *));
exp = (fmpz **)flint_malloc(nvars * sizeof(fmpz *));
exp2 = (fmpz **)flint_malloc(nvars * sizeof(fmpz *));
exp3 = (fmpz *)flint_malloc(nvars * sizeof(fmpz));
for (k = 0; k < nvars; k++)
{
exp[k] = (fmpz *) flint_malloc(sizeof(fmpz));
fmpz_init(exp[k]);
exp2[k] = (fmpz *) flint_malloc(sizeof(fmpz));
fmpz_init(exp2[k]);
fmpz_init(exp3 + k);
}

len = n_randint(state, 20);
Expand All @@ -60,9 +63,10 @@ main(void)
{
/* get random term */
fmpq_randtest(c, state, coeff_bits + 1);
for (k = 0; k < nvars; k++)
for (k = 0; k < nvars; k++) {
fmpz_randtest_unsigned(exp[k], state, exp_bits);

fmpz_set(exp3 + k, exp[k]);
}
/* add it to f1 */
fmpq_mpoly_zero(m, ctx);
fmpq_mpoly_set_coeff_fmpq_fmpz(m, c, exp, ctx);
Expand All @@ -75,6 +79,7 @@ main(void)
else
fmpq_mpoly_push_term_fmpq_fmpz(f2, c, exp, ctx);

fmpq_mpoly_push_term_fmpq_ffmpz(f3, c, exp3, ctx);
/* make sure last term matches */
fmpq_mpoly_get_term_coeff_fmpq(c2, f2, fmpq_mpoly_length(f2, ctx) - 1, ctx);
fmpq_mpoly_get_term_exp_fmpz(exp2, f2, fmpq_mpoly_length(f2, ctx) - 1, ctx);
Expand All @@ -101,6 +106,10 @@ main(void)
fmpq_mpoly_combine_like_terms(f2, ctx);
fmpq_mpoly_assert_canonical(f2, ctx);

fmpq_mpoly_sort_terms(f3, ctx);
fmpq_mpoly_combine_like_terms(f3, ctx);
fmpq_mpoly_assert_canonical(f3, ctx);

if (!fmpq_mpoly_equal(f1, f2, ctx))
{
printf("FAIL\n");
Expand All @@ -109,10 +118,19 @@ main(void)
flint_abort();
}

if (!fmpq_mpoly_equal(f1, f3, ctx))
{
printf("FAIL\n");
flint_printf("Check pushed ffmpz polynomial matches add\ni = %wd\n",i);
fflush(stdout);
flint_abort();
}

fmpq_clear(c2);
fmpq_clear(c);
fmpq_mpoly_clear(f1, ctx);
fmpq_mpoly_clear(f2, ctx);
fmpq_mpoly_clear(f3, ctx);
fmpq_mpoly_clear(m, ctx);
fmpq_mpoly_ctx_clear(ctx);

Expand All @@ -122,7 +140,9 @@ main(void)
flint_free(exp2[k]);
fmpz_clear(exp[k]);
flint_free(exp[k]);
fmpz_clear(exp3 + k);
}
flint_free(exp3);
flint_free(exp2);
flint_free(exp);
}
Expand Down
9 changes: 9 additions & 0 deletions src/fmpz_mod_mpoly.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,21 @@ void fmpz_mod_mpoly_get_term_monomial(fmpz_mod_mpoly_t M,
void fmpz_mod_mpoly_push_term_fmpz_fmpz(fmpz_mod_mpoly_t A,
const fmpz_t c, fmpz * const * exp, const fmpz_mod_mpoly_ctx_t ctx);

void fmpz_mod_mpoly_push_term_fmpz_ffmpz(fmpz_mod_mpoly_t A,
const fmpz_t c, const fmpz * exp, const fmpz_mod_mpoly_ctx_t ctx);

void fmpz_mod_mpoly_push_term_ui_fmpz(fmpz_mod_mpoly_t A,
ulong c, fmpz * const * exp, const fmpz_mod_mpoly_ctx_t ctx);

void fmpz_mod_mpoly_push_term_ui_ffmpz(fmpz_mod_mpoly_t A,
ulong c, const fmpz * exp, const fmpz_mod_mpoly_ctx_t ctx);

void fmpz_mod_mpoly_push_term_si_fmpz(fmpz_mod_mpoly_t A,
slong c, fmpz * const * exp, const fmpz_mod_mpoly_ctx_t ctx);

void fmpz_mod_mpoly_push_term_si_ffmpz(fmpz_mod_mpoly_t A,
slong c, const fmpz * exp, const fmpz_mod_mpoly_ctx_t ctx);

void fmpz_mod_mpoly_push_term_fmpz_ui(fmpz_mod_mpoly_t A,
const fmpz_t c, const ulong * exp, const fmpz_mod_mpoly_ctx_t ctx);

Expand Down
29 changes: 29 additions & 0 deletions src/fmpz_mod_mpoly/push_term_fmpz_fmpz.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,32 @@ void fmpz_mod_mpoly_push_term_si_fmpz(
fmpz_mod_set_si(A->coeffs + A->length - 1, c, ctx->ffinfo);
}

void fmpz_mod_mpoly_push_term_fmpz_ffmpz(
fmpz_mod_mpoly_t A,
const fmpz_t c,
const fmpz * exp,
const fmpz_mod_mpoly_ctx_t ctx)
{
_fmpz_mod_mpoly_push_exp_ffmpz(A, exp, ctx);
fmpz_mod_set_fmpz(A->coeffs + A->length - 1, c, ctx->ffinfo);
}

void fmpz_mod_mpoly_push_term_ui_ffmpz(
fmpz_mod_mpoly_t A,
ulong c,
const fmpz * exp,
const fmpz_mod_mpoly_ctx_t ctx)
{
_fmpz_mod_mpoly_push_exp_ffmpz(A, exp, ctx);
fmpz_mod_set_ui(A->coeffs + A->length - 1, c, ctx->ffinfo);
}

void fmpz_mod_mpoly_push_term_si_ffmpz(
fmpz_mod_mpoly_t A,
slong c,
const fmpz * exp,
const fmpz_mod_mpoly_ctx_t ctx)
{
_fmpz_mod_mpoly_push_exp_ffmpz(A, exp, ctx);
fmpz_mod_set_si(A->coeffs + A->length - 1, c, ctx->ffinfo);
}
Loading

0 comments on commit 462d458

Please sign in to comment.