#include "test_helpers.h"
#include "gr_mat.h"
#include "gr_poly.h"
FLINT_DLL extern gr_static_method_table _ca_methods;
TEST_GR_FUNCTION_START(gr_mat_charpoly_householder, state, count_success, count_unable, count_domain)
{
slong iter;
for (iter = 0; iter < 1000; iter++)
{
int status = GR_SUCCESS;
slong n;
gr_ctx_t ctx;
gr_mat_t A;
gr_poly_t f, g;
gr_ctx_init_random_commutative_ring(ctx, state);
while (ctx->methods == _ca_methods)
{
gr_ctx_clear(ctx);
gr_ctx_init_random(ctx, state);
}
n = n_randint(state, 8);
gr_mat_init(A, n, n, ctx);
gr_poly_init(f, ctx);
gr_poly_init(g, ctx);
status |= gr_mat_randtest(A, state, ctx);
gr_poly_randtest(f, state, n_randint(state, 10), ctx);
gr_poly_randtest(g, state, n_randint(state, 10), ctx);
status |= gr_mat_charpoly_berkowitz(f, A, ctx);
status |= gr_mat_charpoly_householder(g, A, ctx);
if (status == GR_SUCCESS && gr_poly_equal(f, g, ctx) == T_FALSE)
{
flint_printf("FAIL\n\n");
gr_ctx_println(ctx);
flint_printf("A = "); gr_mat_print(A, ctx); flint_printf("\n");
flint_printf("f = "); gr_poly_print(f, ctx); flint_printf("\n");
flint_printf("g = "); gr_poly_print(g, ctx); flint_printf("\n");
flint_abort();
}
count_success += (status == GR_SUCCESS);
count_domain += ((status & GR_DOMAIN) != 0);
count_unable += ((status & GR_UNABLE) != 0);
gr_mat_clear(A, ctx);
gr_poly_clear(f, ctx);
gr_poly_clear(g, ctx);
gr_ctx_clear(ctx);
}
TEST_GR_FUNCTION_END(state, count_success, count_unable, count_domain);
}