diff --git a/src/gr/polynomial.c b/src/gr/polynomial.c index ed762953b1..6a3e698292 100644 --- a/src/gr/polynomial.c +++ b/src/gr/polynomial.c @@ -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) { @@ -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) { @@ -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},