mirror of
https://github.com/vale981/arb
synced 2025-03-06 09:51:39 -05:00
135 lines
4.2 KiB
C
135 lines
4.2 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) 2012 Fredrik Johansson
|
|
|
|
******************************************************************************/
|
|
|
|
#include "acb_mat.h"
|
|
|
|
int main()
|
|
{
|
|
long iter;
|
|
flint_rand_t state;
|
|
|
|
printf("inv....");
|
|
fflush(stdout);
|
|
|
|
flint_randinit(state);
|
|
|
|
for (iter = 0; iter < 10000; iter++)
|
|
{
|
|
fmpq_mat_t Q, Qinv;
|
|
acb_mat_t A, Ainv;
|
|
long n, qbits, prec;
|
|
int q_invertible, r_invertible, r_invertible2;
|
|
|
|
n = n_randint(state, 8);
|
|
qbits = 1 + n_randint(state, 30);
|
|
prec = 2 + n_randint(state, 200);
|
|
|
|
fmpq_mat_init(Q, n, n);
|
|
fmpq_mat_init(Qinv, n, n);
|
|
|
|
acb_mat_init(A, n, n);
|
|
acb_mat_init(Ainv, n, n);
|
|
|
|
fmpq_mat_randtest(Q, state, qbits);
|
|
q_invertible = fmpq_mat_inv(Qinv, Q);
|
|
|
|
if (!q_invertible)
|
|
{
|
|
acb_mat_set_fmpq_mat(A, Q, prec);
|
|
r_invertible = acb_mat_inv(Ainv, A, prec);
|
|
if (r_invertible)
|
|
{
|
|
printf("FAIL: matrix is singular over Q but not over R\n");
|
|
printf("n = %ld, prec = %ld\n", n, prec);
|
|
printf("\n");
|
|
|
|
printf("Q = \n"); fmpq_mat_print(Q); printf("\n\n");
|
|
printf("A = \n"); acb_mat_printd(A, 15); printf("\n\n");
|
|
printf("Ainv = \n"); acb_mat_printd(Ainv, 15); printf("\n\n");
|
|
abort();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* now this must converge */
|
|
while (1)
|
|
{
|
|
acb_mat_set_fmpq_mat(A, Q, prec);
|
|
r_invertible = acb_mat_inv(Ainv, A, prec);
|
|
|
|
if (r_invertible)
|
|
{
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
if (prec > 10000)
|
|
{
|
|
printf("FAIL: failed to converge at 10000 bits\n");
|
|
printf("Q = \n"); fmpq_mat_print(Q); printf("\n\n");
|
|
printf("A = \n"); acb_mat_printd(A, 15); printf("\n\n");
|
|
abort();
|
|
}
|
|
prec *= 2;
|
|
}
|
|
}
|
|
|
|
if (!acb_mat_contains_fmpq_mat(Ainv, Qinv))
|
|
{
|
|
printf("FAIL (containment, iter = %ld)\n", iter);
|
|
printf("n = %ld, prec = %ld\n", n, prec);
|
|
printf("\n");
|
|
|
|
printf("Q = \n"); fmpq_mat_print(Q); printf("\n\n");
|
|
printf("Qinv = \n"); fmpq_mat_print(Qinv); printf("\n\n");
|
|
|
|
printf("A = \n"); acb_mat_printd(A, 15); printf("\n\n");
|
|
printf("Ainv = \n"); acb_mat_printd(Ainv, 15); printf("\n\n");
|
|
|
|
abort();
|
|
}
|
|
|
|
/* test aliasing */
|
|
r_invertible2 = acb_mat_inv(A, A, prec);
|
|
if (!acb_mat_equal(A, Ainv) || r_invertible != r_invertible2)
|
|
{
|
|
printf("FAIL (aliasing)\n");
|
|
printf("A = \n"); acb_mat_printd(A, 15); printf("\n\n");
|
|
printf("Ainv = \n"); acb_mat_printd(Ainv, 15); printf("\n\n");
|
|
abort();
|
|
}
|
|
}
|
|
|
|
fmpq_mat_clear(Q);
|
|
fmpq_mat_clear(Qinv);
|
|
acb_mat_clear(A);
|
|
acb_mat_clear(Ainv);
|
|
}
|
|
|
|
flint_randclear(state);
|
|
flint_cleanup();
|
|
printf("PASS\n");
|
|
return EXIT_SUCCESS;
|
|
}
|