1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Copyright (C) 2025 Fredrik Johansson
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "test_helpers.h"
#include "gr_mat.h"
TEST_FUNCTION_START(gr_mat_permanent, state)
{
slong iter;
for (iter = 0; iter < 1000; iter++)
{
int status = GR_SUCCESS;
ulong m;
slong n;
gr_ctx_t ctx;
gr_mat_t A;
gr_ptr a, b;
int algorithm;
switch (n_randint(state, 3) % 3)
{
case 0:
gr_ctx_init_fmpz(ctx);
n = n_randint(state, 7);
break;
case 1:
gr_ctx_init_fmpq(ctx);
n = n_randint(state, 3);
break;
default:
m = n_randtest_not_zero(state);
gr_ctx_init_nmod(ctx, m);
n = n_randint(state, 7);
break;
}
gr_mat_init(A, n, n, ctx);
a = gr_heap_init(ctx);
b = gr_heap_init(ctx);
GR_MUST_SUCCEED(gr_mat_randtest(A, state, ctx));
status |= gr_mat_permanent_cofactor(a, A, ctx);
for (algorithm = 0; algorithm < 4; algorithm++)
{
status = GR_SUCCESS;
switch (algorithm)
{
case 0:
status |= gr_mat_permanent_ryser(b, A, ctx);
break;
case 1:
status |= gr_mat_permanent_glynn(b, A, ctx);
break;
case 2:
flint_set_num_threads(1 + n_randint(state, 5));
status |= gr_mat_permanent_glynn_threaded(b, A, ctx);
break;
default:
status |= gr_mat_permanent(b, A, ctx);
break;
}
if (status == GR_SUCCESS && gr_equal(a, b, ctx) == T_FALSE)
{
flint_printf("FAIL\n");
flint_printf("algorithm = %d\n", algorithm);
gr_ctx_println(ctx);
flint_printf("A = "), gr_mat_print(A, ctx); flint_printf("\n");
flint_printf("a = "), gr_println(a, ctx);
flint_printf("b = "), gr_println(b, ctx);
flint_abort();
}
}
gr_mat_clear(A, ctx);
gr_heap_clear(a, ctx);
gr_heap_clear(b, ctx);
gr_ctx_clear(ctx);
}
TEST_FUNCTION_END(state);
}