#include "test_helpers.h"
#include "ulong_extras.h"
#include "gr_poly.h"
FLINT_DLL extern gr_static_method_table _ca_methods;
TEST_FUNCTION_START(gr_poly_compose, state)
{
slong iter;
for (iter = 0; iter < 1000; iter++)
{
int status;
gr_ctx_t ctx;
gr_poly_t F, G, FG;
gr_poly_t x, Fx, Gx, FxGx, FGx;
gr_ctx_init_random_commutative_ring(ctx, state);
while (ctx->methods == _ca_methods)
{
gr_ctx_clear(ctx);
gr_ctx_init_random_commutative_ring(ctx, state);
}
gr_poly_init(F, ctx);
gr_poly_init(G, ctx);
gr_poly_init(FG, ctx);
gr_poly_init(x, ctx);
gr_poly_init(Fx, ctx);
gr_poly_init(Gx, ctx);
gr_poly_init(FxGx, ctx);
gr_poly_init(FGx, ctx);
status = GR_SUCCESS;
status |= gr_poly_randtest(F, state, 1 + n_randint(state, 12), ctx);
status |= gr_poly_randtest(G, state, 1 + n_randint(state, 12), ctx);
status |= gr_poly_randtest(x, state, 1 + n_randint(state, 12), ctx);
status |= gr_poly_randtest(Fx, state, 1 + n_randint(state, 12), ctx);
status |= gr_poly_add(FG, F, G, ctx);
status |= gr_poly_compose(Fx, F, x, ctx);
status |= gr_poly_set(Gx, x, ctx);
status |= gr_poly_compose(Gx, G, Gx, ctx);
status |= gr_poly_add(FxGx, Fx, Gx, ctx);
status |= gr_poly_compose_horner(FGx, FG, x, ctx);
if (status == GR_SUCCESS && gr_poly_equal(FxGx, FGx, ctx) == T_FALSE)
{
flint_printf("FAIL\n\n");
flint_printf("F = "); gr_poly_print(F, ctx); flint_printf("\n");
flint_printf("G = "); gr_poly_print(G, ctx); flint_printf("\n");
flint_printf("x = "); gr_poly_print(x, ctx); flint_printf("\n");
flint_printf("Fx = "); gr_poly_print(Fx, ctx); flint_printf("\n");
flint_printf("Gx = "); gr_poly_print(Gx, ctx); flint_printf("\n");
flint_printf("FxGx = "); gr_poly_print(FxGx, ctx); flint_printf("\n");
flint_printf("FGx = "); gr_poly_print(FGx, ctx); flint_printf("\n");
flint_abort();
}
gr_poly_clear(F, ctx);
gr_poly_clear(G, ctx);
gr_poly_clear(FG, ctx);
gr_poly_clear(x, ctx);
gr_poly_clear(Fx, ctx);
gr_poly_clear(Gx, ctx);
gr_poly_clear(FxGx, ctx);
gr_poly_clear(FGx, ctx);
gr_ctx_clear(ctx);
}
TEST_FUNCTION_END(state);
}