Skip to content

Commit

Permalink
add mul_other method
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Jan 14, 2025
1 parent 7c613d4 commit 96c6801
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/gr/polynomial.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,6 @@ polynomial_sub(gr_poly_t res, const gr_poly_t poly1, const gr_poly_t poly2, gr_c
return gr_poly_sub(res, poly1, poly2, POLYNOMIAL_ELEM_CTX(ctx));
}

int
polynomial_mul_scalar(gr_poly_t res, const gr_poly_t poly, gr_srcptr c, gr_ctx_t ctx)
{
return gr_poly_mul_scalar(res, poly, c, POLYNOMIAL_ELEM_CTX(ctx));
}

int
polynomial_mul_ui(gr_poly_t res, const gr_poly_t poly, ulong c, gr_ctx_t ctx)
{
Expand Down Expand Up @@ -421,6 +415,33 @@ polynomial_mul(gr_poly_t res, const gr_poly_t poly1, const gr_poly_t poly2, gr_c
return gr_poly_mul(res, poly1, poly2, POLYNOMIAL_ELEM_CTX(ctx));
}

int
polynomial_mul_other(gr_poly_t res, const gr_poly_t f, gr_srcptr x, gr_ctx_t x_ctx, gr_ctx_t ctx)
{
if (x_ctx == POLYNOMIAL_ELEM_CTX(ctx))
{
return gr_poly_mul_scalar(res, f, x, x_ctx);
}
else if (x_ctx->which_ring == GR_CTX_GR_POLY &&
POLYNOMIAL_ELEM_CTX(x_ctx) == POLYNOMIAL_ELEM_CTX(ctx) &&
!strcmp(POLYNOMIAL_CTX(x_ctx)->var, POLYNOMIAL_CTX(ctx)->var))
{
return polynomial_mul(res, f, x, ctx);
}
else
{
gr_poly_t t;
int status = GR_SUCCESS;

polynomial_init(t, ctx);
status = polynomial_set_other(t, x, x_ctx, ctx);
if (status == GR_SUCCESS)
status = polynomial_mul(res, f, t, ctx);
polynomial_clear(t, ctx);
return status;
}
}

int
polynomial_div(gr_poly_t res, const gr_poly_t x, const gr_poly_t y, const gr_ctx_t ctx)
{
Expand Down Expand Up @@ -579,7 +600,7 @@ gr_method_tab_input _gr_poly_methods_input[] =
{GR_METHOD_ADD, (gr_funcptr) polynomial_add},
{GR_METHOD_SUB, (gr_funcptr) polynomial_sub},
{GR_METHOD_MUL, (gr_funcptr) polynomial_mul},
/* {GR_METHOD_MUL, (gr_funcptr) polynomial_mul_scalar}, */
{GR_METHOD_MUL_OTHER, (gr_funcptr) polynomial_mul_other},
{GR_METHOD_MUL_UI, (gr_funcptr) polynomial_mul_ui},
{GR_METHOD_MUL_SI, (gr_funcptr) polynomial_mul_si},
{GR_METHOD_MUL_FMPZ, (gr_funcptr) polynomial_mul_fmpz},
Expand Down

0 comments on commit 96c6801

Please sign in to comment.