ALL: Add flint
This commit is contained in:
183
external/flint-2.4.3/nmod_poly_mat/test/t-add.c
vendored
Normal file
183
external/flint-2.4.3/nmod_poly_mat/test/t-add.c
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("add....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check evaluation homomorphism */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
nmod_mat_t a, b, c, d;
|
||||
mp_limb_t mod, x;
|
||||
slong m, n, deg;
|
||||
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
mod = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_mat_init(a, m, n, mod);
|
||||
nmod_mat_init(b, m, n, mod);
|
||||
nmod_mat_init(c, m, n, mod);
|
||||
nmod_mat_init(d, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_add(C, A, B);
|
||||
|
||||
x = n_randint(state, mod);
|
||||
|
||||
nmod_poly_mat_evaluate_nmod(a, A, x);
|
||||
nmod_poly_mat_evaluate_nmod(b, B, x);
|
||||
nmod_poly_mat_evaluate_nmod(d, C, x);
|
||||
nmod_mat_add(c, a, b);
|
||||
|
||||
if (!nmod_mat_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
|
||||
nmod_mat_clear(a);
|
||||
nmod_mat_clear(b);
|
||||
nmod_mat_clear(c);
|
||||
nmod_mat_clear(d);
|
||||
}
|
||||
|
||||
/* Check aliasing C and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
|
||||
nmod_poly_mat_add(C, A, B);
|
||||
nmod_poly_mat_add(A, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, A))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Check aliasing C and B */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
|
||||
nmod_poly_mat_add(C, A, B);
|
||||
nmod_poly_mat_add(B, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, B))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
110
external/flint-2.4.3/nmod_poly_mat/test/t-det.c
vendored
Normal file
110
external/flint-2.4.3/nmod_poly_mat/test/t-det.c
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("det....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
nmod_poly_t a, b, ab, c;
|
||||
slong n, deg;
|
||||
mp_limb_t mod;
|
||||
float density;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
n = n_randint(state, 10);
|
||||
deg = 1 + n_randint(state, 5);
|
||||
density = n_randint(state, 100) * 0.01;
|
||||
|
||||
nmod_poly_mat_init(A, n, n, mod);
|
||||
nmod_poly_mat_init(B, n, n, mod);
|
||||
nmod_poly_mat_init(C, n, n, mod);
|
||||
|
||||
nmod_poly_init(a, mod);
|
||||
nmod_poly_init(b, mod);
|
||||
nmod_poly_init(ab, mod);
|
||||
nmod_poly_init(c, mod);
|
||||
|
||||
nmod_poly_mat_randtest_sparse(A, state, deg, density);
|
||||
nmod_poly_mat_randtest_sparse(B, state, deg, density);
|
||||
nmod_poly_mat_mul(C, A, B);
|
||||
|
||||
nmod_poly_mat_det(a, A);
|
||||
nmod_poly_mat_det(b, B);
|
||||
nmod_poly_mat_det(c, C);
|
||||
nmod_poly_mul(ab, a, b);
|
||||
|
||||
if (!nmod_poly_equal(c, ab))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("determinants don't agree!\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("det(A):\n");
|
||||
nmod_poly_print(a);
|
||||
flint_printf("\ndet(B):\n");
|
||||
nmod_poly_print(b);
|
||||
flint_printf("\ndet(C):\n");
|
||||
nmod_poly_print(c);
|
||||
flint_printf("\ndet(A)*det(B):\n");
|
||||
nmod_poly_print(ab);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(a);
|
||||
nmod_poly_clear(b);
|
||||
nmod_poly_clear(ab);
|
||||
nmod_poly_clear(c);
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
88
external/flint-2.4.3/nmod_poly_mat/test/t-det_interpolate.c
vendored
Normal file
88
external/flint-2.4.3/nmod_poly_mat/test/t-det_interpolate.c
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("det_interpolate....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A;
|
||||
nmod_poly_t a, b;
|
||||
slong n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
n = n_randint(state, 10);
|
||||
deg = 1 + n_randint(state, 5);
|
||||
|
||||
nmod_poly_mat_init(A, n, n, mod);
|
||||
|
||||
nmod_poly_init(a, mod);
|
||||
nmod_poly_init(b, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
|
||||
nmod_poly_mat_det(a, A);
|
||||
nmod_poly_mat_det_interpolate(b, A);
|
||||
|
||||
if (!nmod_poly_equal(a, b))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("determinants don't agree!\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("det(A):\n");
|
||||
nmod_poly_print(a);
|
||||
flint_printf("\ndet_interpolate(A):\n");
|
||||
nmod_poly_print(b);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(a);
|
||||
nmod_poly_clear(b);
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
67
external/flint-2.4.3/nmod_poly_mat/test/t-init_clear.c
vendored
Normal file
67
external/flint-2.4.3/nmod_poly_mat/test/t-init_clear.c
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 William Hart
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("init/clear....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t a;
|
||||
mp_limb_t mod;
|
||||
slong j, k;
|
||||
slong rows = n_randint(state, 100);
|
||||
slong cols = n_randint(state, 100);
|
||||
mod = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_mat_init(a, rows, cols, mod);
|
||||
|
||||
for (j = 0; j < rows; j++)
|
||||
for (k = 0; k < cols; k++)
|
||||
nmod_poly_zero(nmod_poly_mat_entry(a, j, k));
|
||||
|
||||
nmod_poly_mat_clear(a);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
164
external/flint-2.4.3/nmod_poly_mat/test/t-inv.c
vendored
Normal file
164
external/flint-2.4.3/nmod_poly_mat/test/t-inv.c
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("inv....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Test aliasing */
|
||||
for (i = 0; i < 40 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, Ainv;
|
||||
nmod_poly_t den1, den2;
|
||||
slong n, deg;
|
||||
float density;
|
||||
int ns1, ns2, result;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
n = n_randint(state, 8);
|
||||
deg = 1 + n_randint(state, 5);
|
||||
density = n_randint(state, 100) * 0.01;
|
||||
|
||||
nmod_poly_mat_init(A, n, n, mod);
|
||||
nmod_poly_mat_init(Ainv, n, n, mod);
|
||||
nmod_poly_init(den1, mod);
|
||||
nmod_poly_init(den2, mod);
|
||||
|
||||
nmod_poly_mat_randtest_sparse(A, state, deg, density);
|
||||
|
||||
ns1 = nmod_poly_mat_inv(Ainv, den1, A);
|
||||
ns2 = nmod_poly_mat_inv(A, den2, A);
|
||||
|
||||
result = ns1 == ns2;
|
||||
|
||||
if (result && ns1 != 0)
|
||||
{
|
||||
result = nmod_poly_equal(den1, den2) &&
|
||||
nmod_poly_mat_equal(A, Ainv);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (aliasing)!\n");
|
||||
nmod_poly_mat_print(A, "x"); flint_printf("\n");
|
||||
nmod_poly_mat_print(Ainv, "x"); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(Ainv);
|
||||
nmod_poly_clear(den1);
|
||||
nmod_poly_clear(den2);
|
||||
}
|
||||
|
||||
/* Check A^(-1) = A = 1 */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, Ainv, B, Iden;
|
||||
nmod_poly_t den, det;
|
||||
slong n, deg;
|
||||
float density;
|
||||
int nonsingular;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
n = n_randint(state, 10);
|
||||
deg = 1 + n_randint(state, 5);
|
||||
density = n_randint(state, 100) * 0.01;
|
||||
|
||||
nmod_poly_mat_init(A, n, n, mod);
|
||||
nmod_poly_mat_init(Ainv, n, n, mod);
|
||||
nmod_poly_mat_init(B, n, n, mod);
|
||||
nmod_poly_mat_init(Iden, n, n, mod);
|
||||
nmod_poly_init(den, mod);
|
||||
nmod_poly_init(det, mod);
|
||||
|
||||
nmod_poly_mat_randtest_sparse(A, state, deg, density);
|
||||
nonsingular = nmod_poly_mat_inv(Ainv, den, A);
|
||||
nmod_poly_mat_det_interpolate(det, A);
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
if (nonsingular == 0 || !nmod_poly_is_one(den))
|
||||
{
|
||||
flint_printf("FAIL: expected empty matrix to pass\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!nmod_poly_equal(den, det))
|
||||
{
|
||||
nmod_poly_neg(det, det);
|
||||
flint_printf("FAIL: den != det(A)\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_mul(B, Ainv, A);
|
||||
nmod_poly_mat_one(Iden);
|
||||
nmod_poly_mat_scalar_mul_nmod_poly(Iden, Iden, den);
|
||||
|
||||
if (!nmod_poly_mat_equal(B, Iden))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("Ainv:\n");
|
||||
nmod_poly_mat_print(Ainv, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("den:\n");
|
||||
nmod_poly_print(den);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_clear(den);
|
||||
nmod_poly_clear(det);
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(Ainv);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(Iden);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
189
external/flint-2.4.3/nmod_poly_mat/test/t-mul.c
vendored
Normal file
189
external/flint-2.4.3/nmod_poly_mat/test/t-mul.c
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("mul....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check evaluation homomorphism */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
nmod_mat_t a, b, c, d;
|
||||
mp_limb_t mod, x;
|
||||
slong m, n, k, deg;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
k = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, n, k, mod);
|
||||
nmod_poly_mat_init(C, m, k, mod);
|
||||
|
||||
nmod_mat_init(a, m, n, mod);
|
||||
nmod_mat_init(b, n, k, mod);
|
||||
nmod_mat_init(c, m, k, mod);
|
||||
nmod_mat_init(d, m, k, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_mul(C, A, B);
|
||||
|
||||
x = n_randint(state, mod);
|
||||
|
||||
nmod_poly_mat_evaluate_nmod(a, A, x);
|
||||
nmod_poly_mat_evaluate_nmod(b, B, x);
|
||||
nmod_poly_mat_evaluate_nmod(d, C, x);
|
||||
nmod_mat_mul(c, a, b);
|
||||
|
||||
if (!nmod_mat_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
|
||||
nmod_mat_clear(a);
|
||||
nmod_mat_clear(b);
|
||||
nmod_mat_clear(c);
|
||||
nmod_mat_clear(d);
|
||||
}
|
||||
|
||||
/* Check aliasing C and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, n, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_mul(C, A, B);
|
||||
nmod_poly_mat_mul(A, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, A))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Check aliasing C and B */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_mul(C, A, B);
|
||||
nmod_poly_mat_mul(B, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, B))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
175
external/flint-2.4.3/nmod_poly_mat/test/t-mul_KS.c
vendored
Normal file
175
external/flint-2.4.3/nmod_poly_mat/test/t-mul_KS.c
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("mul_KS....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 200 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C, D;
|
||||
slong m, n, k, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 15);
|
||||
n = n_randint(state, 15);
|
||||
k = n_randint(state, 15);
|
||||
deg = 1 + n_randint(state, 15);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, n, k, mod);
|
||||
nmod_poly_mat_init(C, m, k, mod);
|
||||
nmod_poly_mat_init(D, m, k, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_mul_classical(C, A, B);
|
||||
nmod_poly_mat_mul_KS(D, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, D))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("products don't agree!\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("D:\n");
|
||||
nmod_poly_mat_print(D, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
nmod_poly_mat_clear(D);
|
||||
}
|
||||
|
||||
/* Check aliasing C and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, n, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_mul_KS(C, A, B);
|
||||
nmod_poly_mat_mul_KS(A, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, A))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Check aliasing C and B */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_mul_KS(C, A, B);
|
||||
nmod_poly_mat_mul_KS(B, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, B))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
202
external/flint-2.4.3/nmod_poly_mat/test/t-mul_interpolate.c
vendored
Normal file
202
external/flint-2.4.3/nmod_poly_mat/test/t-mul_interpolate.c
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("mul_interpolate....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check evaluation homomorphism */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
nmod_mat_t a, b, c, d;
|
||||
mp_limb_t mod, x;
|
||||
slong m, n, k, deg;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
k = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, n, k, mod);
|
||||
nmod_poly_mat_init(C, m, k, mod);
|
||||
|
||||
nmod_mat_init(a, m, n, mod);
|
||||
nmod_mat_init(b, n, k, mod);
|
||||
nmod_mat_init(c, m, k, mod);
|
||||
nmod_mat_init(d, m, k, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
if (nmod_poly_mat_max_length(A)
|
||||
+ nmod_poly_mat_max_length(B) - 1 <= mod)
|
||||
{
|
||||
nmod_poly_mat_mul_interpolate(C, A, B);
|
||||
|
||||
x = n_randint(state, mod);
|
||||
|
||||
nmod_poly_mat_evaluate_nmod(a, A, x);
|
||||
nmod_poly_mat_evaluate_nmod(b, B, x);
|
||||
nmod_poly_mat_evaluate_nmod(d, C, x);
|
||||
nmod_mat_mul(c, a, b);
|
||||
|
||||
if (!nmod_mat_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
|
||||
nmod_mat_clear(a);
|
||||
nmod_mat_clear(b);
|
||||
nmod_mat_clear(c);
|
||||
nmod_mat_clear(d);
|
||||
}
|
||||
|
||||
/* Check aliasing C and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, n, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
if (nmod_poly_mat_max_length(A)
|
||||
+ nmod_poly_mat_max_length(B) - 1 <= mod)
|
||||
{
|
||||
|
||||
nmod_poly_mat_mul_interpolate(C, A, B);
|
||||
nmod_poly_mat_mul_interpolate(A, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, A))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Check aliasing C and B */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
if (nmod_poly_mat_max_length(A)
|
||||
+ nmod_poly_mat_max_length(B) - 1 <= mod)
|
||||
{
|
||||
nmod_poly_mat_mul_interpolate(C, A, B);
|
||||
nmod_poly_mat_mul_interpolate(B, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, B))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
130
external/flint-2.4.3/nmod_poly_mat/test/t-neg.c
vendored
Normal file
130
external/flint-2.4.3/nmod_poly_mat/test/t-neg.c
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("neg....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check evaluation homomorphism */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B;
|
||||
nmod_mat_t a, b, c;
|
||||
mp_limb_t x, mod;
|
||||
slong m, n, deg;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
|
||||
nmod_mat_init(a, m, n, mod);
|
||||
nmod_mat_init(b, m, n, mod);
|
||||
nmod_mat_init(c, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_neg(B, A);
|
||||
|
||||
x = n_randint(state, mod);
|
||||
|
||||
nmod_poly_mat_evaluate_nmod(a, A, x);
|
||||
nmod_poly_mat_evaluate_nmod(b, B, x);
|
||||
nmod_mat_neg(c, a);
|
||||
|
||||
if (!nmod_mat_equal(b, c))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
|
||||
nmod_mat_clear(a);
|
||||
nmod_mat_clear(b);
|
||||
nmod_mat_clear(c);
|
||||
}
|
||||
|
||||
/* Check aliasing B and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
|
||||
nmod_poly_mat_neg(B, A);
|
||||
nmod_poly_mat_neg(A, A);
|
||||
|
||||
if (!nmod_poly_mat_equal(B, A))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
100
external/flint-2.4.3/nmod_poly_mat/test/t-nullspace.c
vendored
Normal file
100
external/flint-2.4.3/nmod_poly_mat/test/t-nullspace.c
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("nullspace....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 200 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, N, AN;
|
||||
slong n, m, deg, rank, nullity;
|
||||
float density;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 13);
|
||||
n = n_randint(state, 13);
|
||||
deg = 1 + n_randint(state, 5);
|
||||
density = n_randint(state, 100) * 0.01;
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(N, n, n, mod);
|
||||
nmod_poly_mat_init(AN, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest_sparse(A, state, deg, density);
|
||||
|
||||
rank = nmod_poly_mat_rank(A);
|
||||
nullity = nmod_poly_mat_nullspace(N, A);
|
||||
|
||||
if (nullity + rank != n)
|
||||
{
|
||||
flint_printf("FAIL: wrong nullity!\n");
|
||||
flint_printf("rank = %wd\n", rank);
|
||||
flint_printf("nullity = %wd\n", nullity);
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("\n");
|
||||
nmod_poly_mat_print(N, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (nmod_poly_mat_rank(N) != nullity)
|
||||
{
|
||||
flint_printf("FAIL: wrong rank(N) != nullity!\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_mul(AN, A, N);
|
||||
|
||||
if (!nmod_poly_mat_is_zero(AN))
|
||||
{
|
||||
flint_printf("FAIL: A * N != 0\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(N);
|
||||
nmod_poly_mat_clear(AN);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
91
external/flint-2.4.3/nmod_poly_mat/test/t-one.c
vendored
Normal file
91
external/flint-2.4.3/nmod_poly_mat/test/t-one.c
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("one/is_one....");
|
||||
fflush(stdout);
|
||||
|
||||
for (iter = 0; iter < 100 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
nmod_poly_mat_t A;
|
||||
slong m, n;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_randtest(A, state, n_randint(state, 5));
|
||||
nmod_poly_mat_one(A);
|
||||
|
||||
if (!nmod_poly_mat_is_one(A))
|
||||
{
|
||||
flint_printf("FAIL: expected matrix to be one\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (m > 0 && n > 0)
|
||||
{
|
||||
m = n_randint(state, m);
|
||||
n = n_randint(state, n);
|
||||
|
||||
if (m != n)
|
||||
nmod_poly_randtest_not_zero(nmod_poly_mat_entry(A, m, n),
|
||||
state, 5);
|
||||
else
|
||||
do { nmod_poly_randtest_not_zero(nmod_poly_mat_entry(A, m, n),
|
||||
state, 5); }
|
||||
while (nmod_poly_is_one(nmod_poly_mat_entry(A, m, n)));
|
||||
|
||||
if (nmod_poly_mat_is_one(A))
|
||||
{
|
||||
flint_printf("FAIL: expected matrix not to be one\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
125
external/flint-2.4.3/nmod_poly_mat/test/t-pow.c
vendored
Normal file
125
external/flint-2.4.3/nmod_poly_mat/test/t-pow.c
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("pow....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, j, exp, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 6);
|
||||
deg = 1 + n_randint(state, 6);
|
||||
exp = n_randint(state, 20);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(B, m, m, mod);
|
||||
nmod_poly_mat_init(C, m, m, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
|
||||
nmod_poly_mat_pow(B, A, exp);
|
||||
|
||||
nmod_poly_mat_one(C);
|
||||
for (j = 0; j < exp; j++)
|
||||
nmod_poly_mat_mul(C, C, A);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, B))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("exp = %wd\n", exp);
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Check aliasing B and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B;
|
||||
slong m, exp, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 6);
|
||||
deg = 1 + n_randint(state, 6);
|
||||
exp = n_randint(state, 20);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(B, m, m, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
|
||||
nmod_poly_mat_pow(B, A, exp);
|
||||
nmod_poly_mat_pow(A, A, exp);
|
||||
|
||||
if (!nmod_poly_mat_equal(A, B))
|
||||
{
|
||||
flint_printf("FAIL (aliasing)\n");
|
||||
flint_printf("exp = %wd\n", exp);
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
99
external/flint-2.4.3/nmod_poly_mat/test/t-rank.c
vendored
Normal file
99
external/flint-2.4.3/nmod_poly_mat/test/t-rank.c
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("rank....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A;
|
||||
nmod_mat_t Ax;
|
||||
mp_limb_t mod, x;
|
||||
slong j, m, n, deg, rank, zrank;
|
||||
float density;
|
||||
|
||||
/* Don't pick a too small modulus, to avoid failure in
|
||||
the probabilistic rank computation (todo: test
|
||||
for small moduli) */
|
||||
do {
|
||||
mod = n_randtest_prime(state, 0);
|
||||
} while (mod < 20);
|
||||
|
||||
m = n_randint(state, 15);
|
||||
n = n_randint(state, 15);
|
||||
deg = 1 + n_randint(state, 5);
|
||||
density = n_randint(state, 100) * 0.01;
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_mat_init(Ax, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest_sparse(A, state, deg, density);
|
||||
|
||||
/* Probabilistic rank computation */
|
||||
zrank = 0;
|
||||
for (j = 0; j < 5; j++)
|
||||
{
|
||||
slong r;
|
||||
x = n_randint(state, mod);
|
||||
nmod_poly_mat_evaluate_nmod(Ax, A, x);
|
||||
r = nmod_mat_rank(Ax);
|
||||
zrank = FLINT_MAX(zrank, r);
|
||||
}
|
||||
|
||||
rank = nmod_poly_mat_rank(A);
|
||||
|
||||
if (rank != zrank)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("Computed rank: %wd (zrank = %wd)\n", rank, zrank);
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_mat_clear(Ax);
|
||||
nmod_poly_mat_clear(A);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
180
external/flint-2.4.3/nmod_poly_mat/test/t-rref.c
vendored
Normal file
180
external/flint-2.4.3/nmod_poly_mat/test/t-rref.c
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010-2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "perm.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
/* checks that the rref has the right form */
|
||||
int check_rref(const nmod_poly_mat_t A, const nmod_poly_t den, slong rank)
|
||||
{
|
||||
slong i, j, k, prev_pivot;
|
||||
|
||||
/* bottom should be zero */
|
||||
for (i = rank; i < A->r; i++)
|
||||
for (j = 0; j < A->c; j++)
|
||||
if (!nmod_poly_is_zero(nmod_poly_mat_entry(A, i, j)))
|
||||
return 0;
|
||||
|
||||
prev_pivot = -1;
|
||||
|
||||
for (i = 0; i < rank; i++)
|
||||
{
|
||||
for (j = 0; j < A->c; j++)
|
||||
{
|
||||
if (!nmod_poly_is_zero(nmod_poly_mat_entry(A, i, j)))
|
||||
{
|
||||
/* pivot should have a higher column index than previous */
|
||||
if (j <= prev_pivot)
|
||||
return 0;
|
||||
|
||||
/* column should be 0 ... 0 1 0 ... 0 */
|
||||
for (k = 0; k < rank; k++)
|
||||
{
|
||||
if (i == k && !nmod_poly_equal(nmod_poly_mat_entry(A, k, j), den))
|
||||
return 0;
|
||||
if (i != k && !nmod_poly_is_zero(nmod_poly_mat_entry(A, k, j)))
|
||||
return 0;
|
||||
}
|
||||
|
||||
prev_pivot = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong iter;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("rref....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
for (iter = 0; iter < 1000 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
nmod_poly_mat_t A, R, B, R2;
|
||||
nmod_poly_t den, c, den2;
|
||||
slong j, k, m, n, deg, rank1, rank2;
|
||||
slong *perm;
|
||||
float density;
|
||||
int equal;
|
||||
mp_limb_t p;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
deg = 1 + n_randint(state, 5);
|
||||
density = n_randint(state, 100) * 0.01;
|
||||
p = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, p);
|
||||
nmod_poly_mat_init(R, m, n, p);
|
||||
nmod_poly_mat_init(B, 2 * m, n, p);
|
||||
nmod_poly_mat_init(R2, 2 * m, n, p);
|
||||
|
||||
nmod_poly_init(c, p);
|
||||
nmod_poly_init(den, p);
|
||||
nmod_poly_init(den2, p);
|
||||
|
||||
perm = _perm_init(2 * m);
|
||||
|
||||
nmod_poly_mat_randtest_sparse(A, state, deg, density);
|
||||
|
||||
rank1 = nmod_poly_mat_rref(R, den, A);
|
||||
|
||||
check_rref(R, den, rank1);
|
||||
|
||||
/* Concatenate the original matrix with the rref, scramble the rows,
|
||||
and check that the rref is the same */
|
||||
_perm_randtest(perm, 2 * m, state);
|
||||
|
||||
for (j = 0; j < m; j++)
|
||||
{
|
||||
nmod_poly_randtest_not_zero(c, state, deg);
|
||||
for (k = 0; k < n; k++)
|
||||
nmod_poly_mul(nmod_poly_mat_entry(B, perm[j], k), nmod_poly_mat_entry(A, j, k), c);
|
||||
}
|
||||
|
||||
for (j = 0; j < m; j++)
|
||||
{
|
||||
nmod_poly_randtest_not_zero(c, state, deg);
|
||||
for (k = 0; k < n; k++)
|
||||
nmod_poly_mul(nmod_poly_mat_entry(B, perm[m + j], k), nmod_poly_mat_entry(R, j, k), c);
|
||||
}
|
||||
|
||||
rank2 = nmod_poly_mat_rref(R2, den2, B);
|
||||
equal = (rank1 == rank2);
|
||||
|
||||
if (equal)
|
||||
{
|
||||
nmod_poly_mat_scalar_mul_nmod_poly(R, R, den2);
|
||||
nmod_poly_mat_scalar_mul_nmod_poly(R2, R2, den);
|
||||
|
||||
for (j = 0; j < rank2; j++)
|
||||
for (k = 0; k < n; k++)
|
||||
equal = equal &&
|
||||
nmod_poly_equal(nmod_poly_mat_entry(R, j, k), nmod_poly_mat_entry(R2, j, k));
|
||||
for (j = rank2; j < 2 * rank2; j++)
|
||||
for (k = 0; k < n; k++)
|
||||
equal = equal && nmod_poly_is_zero(nmod_poly_mat_entry(R2, j, k));
|
||||
}
|
||||
|
||||
if (!equal)
|
||||
{
|
||||
flint_printf("FAIL (rank1 = %wd, rank2 = %wd)!\n", rank1, rank2);
|
||||
nmod_poly_mat_print(A, "x"); flint_printf("\n\n");
|
||||
nmod_poly_mat_print(R, "x"); flint_printf("\n\n");
|
||||
nmod_poly_mat_print(R2, "x"); flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(c);
|
||||
nmod_poly_clear(den);
|
||||
nmod_poly_clear(den2);
|
||||
|
||||
_perm_clear(perm);
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(R);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(R2);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
142
external/flint-2.4.3/nmod_poly_mat/test/t-solve_fflu.c
vendored
Normal file
142
external/flint-2.4.3/nmod_poly_mat/test/t-solve_fflu.c
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("solve....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 200 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, X, B, AX, Bden;
|
||||
nmod_poly_t den, det;
|
||||
slong n, m, deg;
|
||||
float density;
|
||||
int solved;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
n = n_randint(state, 15);
|
||||
m = n_randint(state, 5);
|
||||
deg = 1 + n_randint(state, 5);
|
||||
density = n_randint(state, 100) * 0.01;
|
||||
|
||||
nmod_poly_mat_init(A, n, n, mod);
|
||||
nmod_poly_mat_init(B, n, m, mod);
|
||||
nmod_poly_mat_init(X, n, m, mod);
|
||||
nmod_poly_mat_init(AX, n, m, mod);
|
||||
nmod_poly_mat_init(Bden, n, m, mod);
|
||||
nmod_poly_init(den, mod);
|
||||
nmod_poly_init(det, mod);
|
||||
|
||||
nmod_poly_mat_randtest_sparse(A, state, deg, density);
|
||||
nmod_poly_mat_randtest_sparse(B, state, deg, density);
|
||||
|
||||
solved = nmod_poly_mat_solve_fflu(X, den, A, B);
|
||||
nmod_poly_mat_det_interpolate(det, A);
|
||||
|
||||
if (m == 0 || n == 0)
|
||||
{
|
||||
if (solved == 0)
|
||||
{
|
||||
flint_printf("FAIL: expected empty system to pass\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!nmod_poly_equal(den, det))
|
||||
{
|
||||
nmod_poly_neg(det, det);
|
||||
if (!nmod_poly_equal(den, det))
|
||||
{
|
||||
nmod_poly_neg(det, det);
|
||||
flint_printf("FAIL: den != +/- det(A)\n");
|
||||
flint_printf("den:\n"); nmod_poly_print(den);
|
||||
flint_printf("\n\n");
|
||||
flint_printf("det:\n"); nmod_poly_print(det);
|
||||
flint_printf("\n\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("X:\n");
|
||||
nmod_poly_mat_print(X, "x");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (solved != !nmod_poly_is_zero(den))
|
||||
{
|
||||
flint_printf("FAIL: return value does not match denominator\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_mul(AX, A, X);
|
||||
nmod_poly_mat_scalar_mul_nmod_poly(Bden, B, den);
|
||||
|
||||
if (!nmod_poly_mat_equal(AX, Bden))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("X:\n");
|
||||
nmod_poly_mat_print(X, "x");
|
||||
flint_printf("AX:\n");
|
||||
nmod_poly_mat_print(AX, "x");
|
||||
flint_printf("Bden:\n");
|
||||
nmod_poly_mat_print(Bden, "x");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(den);
|
||||
nmod_poly_clear(det);
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(X);
|
||||
nmod_poly_mat_clear(AX);
|
||||
nmod_poly_mat_clear(Bden);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
132
external/flint-2.4.3/nmod_poly_mat/test/t-sqr.c
vendored
Normal file
132
external/flint-2.4.3/nmod_poly_mat/test/t-sqr.c
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("sqr....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check evaluation homomorphism */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, C;
|
||||
nmod_mat_t a, c, d;
|
||||
mp_limb_t x, mod;
|
||||
slong m, deg;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(C, m, m, mod);
|
||||
|
||||
nmod_mat_init(a, m, m, mod);
|
||||
nmod_mat_init(c, m, m, mod);
|
||||
nmod_mat_init(d, m, m, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_sqr(C, A);
|
||||
|
||||
x = n_randint(state, 0);
|
||||
|
||||
nmod_poly_mat_evaluate_nmod(a, A, x);
|
||||
nmod_poly_mat_evaluate_nmod(d, C, x);
|
||||
nmod_mat_mul(c, a, a);
|
||||
|
||||
if (!nmod_mat_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(C);
|
||||
|
||||
nmod_mat_clear(a);
|
||||
nmod_mat_clear(c);
|
||||
nmod_mat_clear(d);
|
||||
}
|
||||
|
||||
/* Check aliasing B and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B;
|
||||
slong m, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(B, m, m, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_sqr(B, A);
|
||||
nmod_poly_mat_sqr(A, A);
|
||||
|
||||
if (!nmod_poly_mat_equal(B, A))
|
||||
{
|
||||
flint_printf("FAIL (aliasing):\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
122
external/flint-2.4.3/nmod_poly_mat/test/t-sqr_KS.c
vendored
Normal file
122
external/flint-2.4.3/nmod_poly_mat/test/t-sqr_KS.c
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("sqr_KS....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 200 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
n = n_randint(state, 15);
|
||||
deg = 1 + n_randint(state, 15);
|
||||
|
||||
nmod_poly_mat_init(A, n, n, mod);
|
||||
nmod_poly_mat_init(B, n, n, mod);
|
||||
nmod_poly_mat_init(C, n, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_sqr_classical(B, A);
|
||||
nmod_poly_mat_sqr_KS(C, A);
|
||||
|
||||
if (!nmod_poly_mat_equal(B, C))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("products don't agree!\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Check aliasing B and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B;
|
||||
slong m, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(B, m, m, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg); /* noise in output */
|
||||
|
||||
nmod_poly_mat_sqr_KS(B, A);
|
||||
nmod_poly_mat_sqr_KS(A, A);
|
||||
|
||||
if (!nmod_poly_mat_equal(B, A))
|
||||
{
|
||||
flint_printf("FAIL (aliasing):\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
138
external/flint-2.4.3/nmod_poly_mat/test/t-sqr_interpolate.c
vendored
Normal file
138
external/flint-2.4.3/nmod_poly_mat/test/t-sqr_interpolate.c
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "fmpz.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("sqr_interpolate....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check evaluation homomorphism */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, C;
|
||||
nmod_mat_t a, c, d;
|
||||
mp_limb_t x, mod;
|
||||
slong m, deg;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(C, m, m, mod);
|
||||
|
||||
nmod_mat_init(a, m, m, mod);
|
||||
nmod_mat_init(c, m, m, mod);
|
||||
nmod_mat_init(d, m, m, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(C, state, deg); /* noise in output */
|
||||
|
||||
if (2 * nmod_poly_mat_max_length(A) - 1 <= mod)
|
||||
{
|
||||
nmod_poly_mat_sqr_interpolate(C, A);
|
||||
|
||||
x = n_randint(state, 0);
|
||||
|
||||
nmod_poly_mat_evaluate_nmod(a, A, x);
|
||||
nmod_poly_mat_evaluate_nmod(d, C, x);
|
||||
nmod_mat_mul(c, a, a);
|
||||
|
||||
if (!nmod_mat_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(C);
|
||||
|
||||
nmod_mat_clear(a);
|
||||
nmod_mat_clear(c);
|
||||
nmod_mat_clear(d);
|
||||
}
|
||||
|
||||
/* Check aliasing B and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B;
|
||||
slong m, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, m, mod);
|
||||
nmod_poly_mat_init(B, m, m, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg); /* noise in output */
|
||||
|
||||
if (2 * nmod_poly_mat_max_length(A) - 1 <= mod)
|
||||
{
|
||||
nmod_poly_mat_sqr_interpolate(B, A);
|
||||
nmod_poly_mat_sqr_interpolate(A, A);
|
||||
|
||||
if (!nmod_poly_mat_equal(B, A))
|
||||
{
|
||||
flint_printf("FAIL (aliasing):\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
183
external/flint-2.4.3/nmod_poly_mat/test/t-sub.c
vendored
Normal file
183
external/flint-2.4.3/nmod_poly_mat/test/t-sub.c
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("sub....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check evaluation homomorphism */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
nmod_mat_t a, b, c, d;
|
||||
mp_limb_t mod, x;
|
||||
slong m, n, deg;
|
||||
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
mod = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_mat_init(a, m, n, mod);
|
||||
nmod_mat_init(b, m, n, mod);
|
||||
nmod_mat_init(c, m, n, mod);
|
||||
nmod_mat_init(d, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
nmod_poly_mat_sub(C, A, B);
|
||||
|
||||
x = n_randint(state, mod);
|
||||
|
||||
nmod_poly_mat_evaluate_nmod(a, A, x);
|
||||
nmod_poly_mat_evaluate_nmod(b, B, x);
|
||||
nmod_poly_mat_evaluate_nmod(d, C, x);
|
||||
nmod_mat_sub(c, a, b);
|
||||
|
||||
if (!nmod_mat_equal(c, d))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
|
||||
nmod_mat_clear(a);
|
||||
nmod_mat_clear(b);
|
||||
nmod_mat_clear(c);
|
||||
nmod_mat_clear(d);
|
||||
}
|
||||
|
||||
/* Check aliasing C and A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
|
||||
nmod_poly_mat_sub(C, A, B);
|
||||
nmod_poly_mat_sub(A, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, A))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Check aliasing C and B */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, C;
|
||||
slong m, n, deg;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 20);
|
||||
n = n_randint(state, 20);
|
||||
deg = 1 + n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, m, n, mod);
|
||||
nmod_poly_mat_init(C, m, n, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, deg);
|
||||
nmod_poly_mat_randtest(B, state, deg);
|
||||
|
||||
nmod_poly_mat_sub(C, A, B);
|
||||
nmod_poly_mat_sub(B, A, B);
|
||||
|
||||
if (!nmod_poly_mat_equal(C, B))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
nmod_poly_mat_print(A, "x");
|
||||
flint_printf("B:\n");
|
||||
nmod_poly_mat_print(B, "x");
|
||||
flint_printf("C:\n");
|
||||
nmod_poly_mat_print(C, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(C);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
99
external/flint-2.4.3/nmod_poly_mat/test/t-trace.c
vendored
Normal file
99
external/flint-2.4.3/nmod_poly_mat/test/t-trace.c
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
slong i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("trace....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Test trace(AB) = trace(BA) */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
nmod_poly_mat_t A, B, AB, BA;
|
||||
nmod_poly_t trab, trba;
|
||||
mp_limb_t mod;
|
||||
slong m, n;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_init(B, n, m, mod);
|
||||
nmod_poly_mat_init(AB, m, m, mod);
|
||||
nmod_poly_mat_init(BA, n, n, mod);
|
||||
|
||||
nmod_poly_init(trab, mod);
|
||||
nmod_poly_init(trba, mod);
|
||||
|
||||
nmod_poly_mat_randtest(A, state, 1 + n_randint(state, 10));
|
||||
nmod_poly_mat_randtest(B, state, 1 + n_randint(state, 10));
|
||||
|
||||
nmod_poly_mat_mul(AB, A, B);
|
||||
nmod_poly_mat_mul(BA, B, A);
|
||||
|
||||
nmod_poly_mat_trace(trab, AB);
|
||||
nmod_poly_mat_trace(trba, BA);
|
||||
|
||||
if (!nmod_poly_equal(trab, trba))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
nmod_poly_mat_print(A, "x"), flint_printf("\n");
|
||||
nmod_poly_mat_print(B, "x"), flint_printf("\n");
|
||||
nmod_poly_mat_print(AB, "x"), flint_printf("\n");
|
||||
nmod_poly_mat_print(BA, "x"), flint_printf("\n");
|
||||
flint_printf("tr(AB): "), nmod_poly_print(trab), flint_printf("\n");
|
||||
flint_printf("tr(BA): "), nmod_poly_print(trba), flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
nmod_poly_mat_clear(B);
|
||||
nmod_poly_mat_clear(AB);
|
||||
nmod_poly_mat_clear(BA);
|
||||
nmod_poly_clear(trab);
|
||||
nmod_poly_clear(trba);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
83
external/flint-2.4.3/nmod_poly_mat/test/t-zero.c
vendored
Normal file
83
external/flint-2.4.3/nmod_poly_mat/test/t-zero.c
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT 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.
|
||||
|
||||
FLINT 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 FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_mat.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "nmod_poly_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("zero/is_zero....");
|
||||
fflush(stdout);
|
||||
|
||||
for (iter = 0; iter < 100 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
nmod_poly_mat_t A;
|
||||
slong m, n;
|
||||
mp_limb_t mod;
|
||||
|
||||
mod = n_randtest_prime(state, 0);
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
nmod_poly_mat_init(A, m, n, mod);
|
||||
nmod_poly_mat_randtest(A, state, n_randint(state, 5));
|
||||
nmod_poly_mat_zero(A);
|
||||
|
||||
if (!nmod_poly_mat_is_zero(A))
|
||||
{
|
||||
flint_printf("FAIL: expected matrix to be zero\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (m > 0 && n > 0)
|
||||
{
|
||||
m = n_randint(state, m);
|
||||
n = n_randint(state, n);
|
||||
nmod_poly_randtest_not_zero(nmod_poly_mat_entry(A, m, n), state, 5);
|
||||
|
||||
if (nmod_poly_mat_is_zero(A))
|
||||
{
|
||||
flint_printf("FAIL: expected matrix not to be zero\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_mat_clear(A);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user