mirror of
https://github.com/vale981/arb
synced 2025-03-06 09:51:39 -05:00
190 lines
5.3 KiB
C
190 lines
5.3 KiB
C
/*=============================================================================
|
|
|
|
This file is part of ARB.
|
|
|
|
ARB is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
ARB is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with ARB; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
=============================================================================*/
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2016 Arb authors
|
|
|
|
******************************************************************************/
|
|
|
|
#include "bool_mat.h"
|
|
|
|
int main()
|
|
{
|
|
slong iter;
|
|
flint_rand_t state;
|
|
|
|
flint_printf("trace....");
|
|
fflush(stdout);
|
|
|
|
flint_randinit(state);
|
|
|
|
/* trace(empty) == 0 */
|
|
{
|
|
bool_mat_t A;
|
|
bool_mat_init(A, 0, 0);
|
|
bool_mat_one(A);
|
|
if (bool_mat_trace(A) != 0)
|
|
{
|
|
flint_printf("FAIL (empty)\n");
|
|
flint_printf("A = \n"); bool_mat_print(A); flint_printf("\n\n");
|
|
abort();
|
|
}
|
|
bool_mat_clear(A);
|
|
}
|
|
|
|
/* trace(zero) == 0 */
|
|
{
|
|
slong n;
|
|
bool_mat_t A;
|
|
for (n = 1; n < 10; n++)
|
|
{
|
|
bool_mat_init(A, n, n);
|
|
bool_mat_zero(A);
|
|
if (bool_mat_trace(A) != 0)
|
|
{
|
|
flint_printf("FAIL (zero)\n");
|
|
flint_printf("A = \n"); bool_mat_print(A); flint_printf("\n\n");
|
|
abort();
|
|
}
|
|
bool_mat_clear(A);
|
|
}
|
|
}
|
|
|
|
/* trace(one) == 1 */
|
|
{
|
|
slong n;
|
|
bool_mat_t A;
|
|
for (n = 1; n < 10; n++)
|
|
{
|
|
bool_mat_init(A, n, n);
|
|
bool_mat_one(A);
|
|
if (bool_mat_trace(A) != 1)
|
|
{
|
|
flint_printf("FAIL (one)\n");
|
|
flint_printf("A = \n"); bool_mat_print(A); flint_printf("\n\n");
|
|
abort();
|
|
}
|
|
bool_mat_clear(A);
|
|
}
|
|
}
|
|
|
|
/* traces of random matrices with modified diagonal */
|
|
for (iter = 0; iter < 10000; iter++)
|
|
{
|
|
slong n, i;
|
|
bool_mat_t A;
|
|
|
|
n = n_randint(state, 10) + 1;
|
|
bool_mat_init(A, n, n);
|
|
bool_mat_randtest(A, state);
|
|
|
|
i = (slong) n_randint(state, n);
|
|
bool_mat_set_entry(A, i, i, 1);
|
|
if (bool_mat_trace(A) != 1)
|
|
{
|
|
flint_printf("FAIL (diagonal has a non-zero entry)\n");
|
|
flint_printf("A = \n"); bool_mat_print(A); flint_printf("\n\n");
|
|
abort();
|
|
}
|
|
|
|
for (i = 0; i < n; i++)
|
|
{
|
|
bool_mat_set_entry(A, i, i, 0);
|
|
}
|
|
if (bool_mat_trace(A) != 0)
|
|
{
|
|
flint_printf("FAIL (diagonal is zero)\n");
|
|
flint_printf("A = \n"); bool_mat_print(A); flint_printf("\n\n");
|
|
abort();
|
|
}
|
|
|
|
bool_mat_clear(A);
|
|
}
|
|
|
|
/* trace(A + B) == trace(A) + trace(B) */
|
|
for (iter = 0; iter < 10000; iter++)
|
|
{
|
|
slong n;
|
|
bool_mat_t A, B, C;
|
|
|
|
n = n_randint(state, 10);
|
|
|
|
bool_mat_init(A, n, n);
|
|
bool_mat_init(B, n, n);
|
|
bool_mat_init(C, n, n);
|
|
|
|
bool_mat_randtest(A, state);
|
|
bool_mat_randtest(B, state);
|
|
bool_mat_add(C, A, B);
|
|
|
|
if (bool_mat_trace(C) != (bool_mat_trace(A) | bool_mat_trace(B)))
|
|
{
|
|
flint_printf("FAIL (trace(A+B) == trace(A) | trace(B))\n");
|
|
flint_printf("A = \n"); bool_mat_print(A); flint_printf("\n\n");
|
|
flint_printf("B = \n"); bool_mat_print(B); flint_printf("\n\n");
|
|
flint_printf("A+B = \n"); bool_mat_print(C); flint_printf("\n\n");
|
|
abort();
|
|
}
|
|
|
|
bool_mat_clear(A);
|
|
bool_mat_clear(B);
|
|
bool_mat_clear(C);
|
|
}
|
|
|
|
/* trace(A*B) == trace(B*A) */
|
|
for (iter = 0; iter < 10000; iter++)
|
|
{
|
|
slong n, m;
|
|
bool_mat_t A, B, AB, BA;
|
|
|
|
n = n_randint(state, 10);
|
|
m = n_randint(state, 10);
|
|
|
|
bool_mat_init(A, n, m);
|
|
bool_mat_init(B, m, n);
|
|
bool_mat_init(AB, n, n);
|
|
bool_mat_init(BA, m, m);
|
|
|
|
bool_mat_randtest(A, state);
|
|
bool_mat_randtest(B, state);
|
|
bool_mat_mul(AB, A, B);
|
|
bool_mat_mul(BA, B, A);
|
|
|
|
if (bool_mat_trace(AB) != bool_mat_trace(BA))
|
|
{
|
|
flint_printf("FAIL (trace(AB) == trace(BA))\n");
|
|
flint_printf("A = \n"); bool_mat_print(A); flint_printf("\n\n");
|
|
flint_printf("B = \n"); bool_mat_print(B); flint_printf("\n\n");
|
|
flint_printf("AB = \n"); bool_mat_print(AB); flint_printf("\n\n");
|
|
flint_printf("BA = \n"); bool_mat_print(BA); flint_printf("\n\n");
|
|
abort();
|
|
}
|
|
|
|
bool_mat_clear(A);
|
|
bool_mat_clear(B);
|
|
bool_mat_clear(AB);
|
|
bool_mat_clear(BA);
|
|
}
|
|
|
|
flint_randclear(state);
|
|
flint_cleanup();
|
|
flint_printf("PASS\n");
|
|
return EXIT_SUCCESS;
|
|
}
|