ALL: Add flint
This commit is contained in:
37
external/flint-2.4.3/fmpq_mat/add.c
vendored
Normal file
37
external/flint-2.4.3/fmpq_mat/add.c
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_add(fmpq_mat_t mat, const fmpq_mat_t mat1, const fmpq_mat_t mat2)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
for (j = 0; j < mat->c; j++)
|
||||
fmpq_add(fmpq_mat_entry(mat, i, j),
|
||||
fmpq_mat_entry(mat1, i, j), fmpq_mat_entry(mat2, i, j));
|
||||
}
|
||||
|
||||
40
external/flint-2.4.3/fmpq_mat/clear.c
vendored
Normal file
40
external/flint-2.4.3/fmpq_mat/clear.c
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_clear(fmpq_mat_t mat)
|
||||
{
|
||||
if (mat->entries)
|
||||
{
|
||||
slong i;
|
||||
|
||||
for (i = 0; i < mat->r * mat->c; i++)
|
||||
fmpq_clear(mat->entries + i);
|
||||
|
||||
flint_free(mat->entries);
|
||||
flint_free(mat->rows);
|
||||
}
|
||||
}
|
||||
73
external/flint-2.4.3/fmpq_mat/det.c
vendored
Normal file
73
external/flint-2.4.3/fmpq_mat/det.c
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_det(fmpq_t det, const fmpq_mat_t mat)
|
||||
{
|
||||
slong n = mat->r;
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
fmpq_set_si(det, WORD(1), WORD(1));
|
||||
return;
|
||||
}
|
||||
else if (n == 1)
|
||||
{
|
||||
fmpq_set(det, fmpq_mat_entry(mat, 0, 0));
|
||||
}
|
||||
else if (n == 2)
|
||||
{
|
||||
fmpq_t t;
|
||||
fmpq_init(t);
|
||||
|
||||
fmpq_mul(t, fmpq_mat_entry(mat, 0, 0), fmpq_mat_entry(mat, 1, 1));
|
||||
fmpq_submul(t, fmpq_mat_entry(mat, 0, 1), fmpq_mat_entry(mat, 1, 0));
|
||||
|
||||
fmpq_set(det, t);
|
||||
fmpq_clear(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_mat_t num;
|
||||
fmpz * den;
|
||||
slong i;
|
||||
|
||||
fmpz_mat_init(num, mat->r, mat->c);
|
||||
den = _fmpz_vec_init(mat->r);
|
||||
|
||||
fmpq_mat_get_fmpz_mat_rowwise(num, den, mat);
|
||||
fmpz_mat_det(&det->num, num);
|
||||
|
||||
fmpz_one(&det->den);
|
||||
for (i = 0; i < mat->r; i++)
|
||||
fmpz_mul(&det->den, &det->den, den + i);
|
||||
|
||||
fmpq_canonicalise(det);
|
||||
|
||||
fmpz_mat_clear(num);
|
||||
_fmpz_vec_clear(den, mat->r);
|
||||
}
|
||||
}
|
||||
428
external/flint-2.4.3/fmpq_mat/doc/fmpq_mat.txt
vendored
Normal file
428
external/flint-2.4.3/fmpq_mat/doc/fmpq_mat.txt
vendored
Normal file
@@ -0,0 +1,428 @@
|
||||
/*=============================================================================
|
||||
|
||||
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
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Memory management
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_init(fmpq_mat_t mat, slong rows, slong cols)
|
||||
|
||||
Initialises a matrix with the given number of rows and columns for use.
|
||||
|
||||
void fmpq_mat_clear(fmpq_mat_t mat)
|
||||
|
||||
Frees all memory associated with the matrix. The matrix must be
|
||||
reinitialised if it is to be used again.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Entry access
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
MACRO fmpq_mat_entry(mat,i,j)
|
||||
|
||||
Gives a reference to the entry at row \code{i} and column \code{j}.
|
||||
The reference can be passed as an input or output variable to any
|
||||
\code{fmpq} function for direct manipulation of the matrix element.
|
||||
No bounds checking is performed.
|
||||
|
||||
MACRO fmpq_mat_entry_num(mat,i,j)
|
||||
|
||||
Gives a reference to the numerator of the entry at row \code{i} and
|
||||
column \code{j}. The reference can be passed as an input or output
|
||||
variable to any \code{fmpz} function for direct manipulation of the
|
||||
matrix element. No bounds checking is performed.
|
||||
|
||||
MACRO fmpq_mat_entry_den(mat,i,j)
|
||||
|
||||
Gives a reference to the denominator of the entry at row \code{i} and
|
||||
column \code{j}. The reference can be passed as an input or output
|
||||
variable to any \code{fmpz} function for direct manipulation of the
|
||||
matrix element. No bounds checking is performed.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Basic assignment
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_set(fmpq_mat_t dest, const fmpq_mat_t src)
|
||||
|
||||
Sets the entries in \code{dest} to the same values as in \code{src},
|
||||
assuming the two matrices have the same dimensions.
|
||||
|
||||
void fmpq_mat_zero(fmpq_mat_t mat)
|
||||
|
||||
Sets \code{mat} to the zero matrix.
|
||||
|
||||
void fmpq_mat_one(fmpq_mat_t mat)
|
||||
|
||||
Let $m$ be the minimum of the number of rows and columns
|
||||
in the matrix \code{mat}. This function sets the first
|
||||
$m \times m$ block to the identity matrix, and the remaining
|
||||
block to zero.
|
||||
|
||||
void fmpq_mat_transpose(fmpq_mat_t rop, const fmpq_mat_t op)
|
||||
|
||||
Sets the matrix \code{rop} to the tranpose of the matrix \code{op},
|
||||
assuming that their dimensios are compatible.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Addition, scalar multiplication
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_add(fmpq_mat_t mat,
|
||||
const fmpq_mat_t mat1, const fmpq_mat_t mat2)
|
||||
|
||||
Sets \code{mat} to the sum of \code{mat1} and \code{mat2},
|
||||
assuming that all three matrices have the same dimensions.
|
||||
|
||||
void fmpq_mat_sub(fmpq_mat_t mat,
|
||||
const fmpq_mat_t mat1, const fmpq_mat_t mat2)
|
||||
|
||||
Sets \code{mat} to the difference of \code{mat1} and \code{mat2},
|
||||
assuming that all three matrices have the same dimensions.
|
||||
|
||||
void fmpq_mat_neg(fmpq_mat_t rop, const fmpq_mat_t op)
|
||||
|
||||
Sets \code{rop} to the negative of \code{op}, assuming that
|
||||
the two matrices have the same dimensions.
|
||||
|
||||
void fmpq_mat_scalar_mul_fmpz(fmpq_mat_t rop,
|
||||
const fmpq_mat_t op, const fmpz_t x)
|
||||
|
||||
Sets \code{rop} to \code{op} multiplied by the integer $x$,
|
||||
assuming that the two matrices have the same dimensions.
|
||||
|
||||
Note that the integer $x$ may not be aliased with any part of
|
||||
the entries of \code{rop}.
|
||||
|
||||
void fmpq_mat_scalar_div_fmpz(fmpq_mat_t rop,
|
||||
const fmpq_mat_t op, const fmpz_t x)
|
||||
|
||||
Sets \code{rop} to \code{op} divided by the integer $x$,
|
||||
assuming that the two matrices have the same dimensions
|
||||
and that $x$ is non-zero.
|
||||
|
||||
Note that the integer $x$ may not be aliased with any part of
|
||||
the entries of \code{rop}.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Input and output
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_print(const fmpq_mat_t mat)
|
||||
|
||||
Prints the matrix \code{mat} to standard output.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Random matrix generation
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_randbits(fmpq_mat_t mat, flint_rand_t state, mp_bitcnt_t bits)
|
||||
|
||||
This is equivalent to applying \code{fmpq_randbits} to all entries
|
||||
in the matrix.
|
||||
|
||||
void fmpq_mat_randtest(fmpq_mat_t mat, flint_rand_t state, mp_bitcnt_t bits)
|
||||
|
||||
This is equivalent to applying \code{fmpq_randtest} to all entries
|
||||
in the matrix.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Special matrices
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_hilbert_matrix(fmpq_mat_t mat)
|
||||
|
||||
Sets \code{mat} to a Hilbert matrix of the given size. That is,
|
||||
the entry at row $i$ and column $j$ is set to $1/(i+j+1)$.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Basic comparison and properties
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
int fmpq_mat_equal(const fmpq_mat_t mat1, const fmpq_mat_t mat2)
|
||||
|
||||
Returns nonzero if \code{mat1} and \code{mat2} have the same shape and
|
||||
all their entries agree, and returns zero otherwise. Assumes the
|
||||
entries in both \code{mat1} and \code{mat2} are in canonical form.
|
||||
|
||||
int fmpq_mat_is_integral(const fmpq_mat_t mat)
|
||||
|
||||
Returns nonzero if all entries in \code{mat} are integer-valued, and
|
||||
returns zero otherwise. Assumes that the entries in \code{mat}
|
||||
are in canonical form.
|
||||
|
||||
int fmpq_mat_is_zero(const fmpq_mat_t mat)
|
||||
|
||||
Returns nonzero if all entries in \code{mat} are zero, and returns
|
||||
zero otherwise.
|
||||
|
||||
int fmpq_mat_is_empty(const fmpq_mat_t mat)
|
||||
|
||||
Returns a non-zero value if the number of rows or the number of
|
||||
columns in \code{mat} is zero, and otherwise returns
|
||||
zero.
|
||||
|
||||
int fmpq_mat_is_square(const fmpq_mat_t mat)
|
||||
|
||||
Returns a non-zero value if the number of rows is equal to the
|
||||
number of columns in \code{mat}, and otherwise returns zero.
|
||||
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Integer matrix conversion
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
int fmpq_mat_get_fmpz_mat(fmpz_mat_t dest, const fmpq_mat_t mat)
|
||||
|
||||
Sets \code{dest} to \code{mat} and returns nonzero if all entries
|
||||
in \code{mat} are integer-valued. If not all entries in \code{mat}
|
||||
are integer-valued, sets \code{dest} to an undefined matrix
|
||||
and returns zero. Assumes that the entries in \code{mat} are
|
||||
in canonical form.
|
||||
|
||||
void fmpq_mat_get_fmpz_mat_entrywise(fmpz_mat_t num, fmpz_mat_t den,
|
||||
const fmpq_mat_t mat)
|
||||
|
||||
Sets the integer matrices \code{num} and \code{den} respectively
|
||||
to the numerators and denominators of the entries in \code{mat}.
|
||||
|
||||
void fmpq_mat_get_fmpz_mat_matwise(fmpz_mat_t num, fmpz_t den,
|
||||
const fmpq_mat_t mat)
|
||||
|
||||
Converts all entries in \code{mat} to a common denominator,
|
||||
storing the rescaled numerators in \code{num} and the
|
||||
denominator in \code{den}. The denominator will be minimal
|
||||
if the entries in \code{mat} are in canonical form.
|
||||
|
||||
void fmpq_mat_get_fmpz_mat_rowwise(fmpz_mat_t num, fmpz * den,
|
||||
const fmpq_mat_t mat)
|
||||
|
||||
Clears denominators in \code{mat} row by row. The rescaled
|
||||
numerators are written to \code{num}, and the denominator
|
||||
of row \code{i} is written to position \code{i} in \code{den}
|
||||
which can be a preinitialised \code{fmpz} vector. Alternatively,
|
||||
\code{NULL} can be passed as the \code{den} variable, in which
|
||||
case the denominators will not be stored.
|
||||
|
||||
void fmpq_mat_get_fmpz_mat_rowwise_2(fmpz_mat_t num, fmpz_mat_t num2,
|
||||
fmpz * den, const fmpq_mat_t mat, const fmpq_mat_t mat2)
|
||||
|
||||
Clears denominators row by row of both \code{mat} and \code{mat2},
|
||||
writing the respective numerators to \code{num} and \code{num2}.
|
||||
This is equivalent to concatenating \code{mat} and \code{mat2}
|
||||
horizontally, calling \code{fmpq_mat_get_fmpz_mat_rowwise},
|
||||
and extracting the two submatrices in the result.
|
||||
|
||||
void fmpq_mat_get_fmpz_mat_colwise(fmpz_mat_t num, fmpz * den,
|
||||
const fmpq_mat_t mat)
|
||||
|
||||
Clears denominators in \code{mat} column by column. The rescaled
|
||||
numerators are written to \code{num}, and the denominator
|
||||
of column \code{i} is written to position \code{i} in \code{den}
|
||||
which can be a preinitialised \code{fmpz} vector. Alternatively,
|
||||
\code{NULL} can be passed as the \code{den} variable, in which
|
||||
case the denominators will not be stored.
|
||||
|
||||
void fmpq_mat_set_fmpz_mat(fmpq_mat_t dest, const fmpz_mat_t src)
|
||||
|
||||
Sets \code{dest} to \code{src}.
|
||||
|
||||
void fmpq_mat_set_fmpz_mat_div_fmpz(fmpq_mat_t mat, const fmpz_mat_t num,
|
||||
const fmpz_t den)
|
||||
|
||||
Sets \code{mat} to the integer matrix \code{num} divided by the
|
||||
common denominator \code{den}.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Modular reduction and rational reconstruction
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_get_fmpz_mat_mod_fmpz(fmpz_mat_t dest, const fmpq_mat_t mat,
|
||||
const fmpz_t mod)
|
||||
|
||||
Sets each entry in \code{dest} to the corresponding entry in \code{mat},
|
||||
reduced modulo \code{mod}.
|
||||
|
||||
int fmpq_mat_set_fmpz_mat_mod_fmpz(fmpq_mat_t X, const fmpz_mat_t Xmod,
|
||||
const fmpz_t mod)
|
||||
|
||||
Set \code{X} to the entrywise rational reconstruction integer matrix
|
||||
\code{Xmod} modulo \code{mod}, and returns nonzero if the reconstruction
|
||||
is successful. If rational reconstruction fails for any element,
|
||||
returns zero and sets the entries in \code{X} to undefined values.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Matrix multiplication
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_mul_direct(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B)
|
||||
|
||||
Sets \code{C} to the matrix product \code{AB}, computed
|
||||
naively using rational arithmetic. This is typically very slow and
|
||||
should only be used in circumstances where clearing denominators
|
||||
would consume too much memory.
|
||||
|
||||
void fmpq_mat_mul_cleared(fmpq_mat_t C, const fmpq_mat_t A,
|
||||
const fmpq_mat_t B)
|
||||
|
||||
Sets \code{C} to the matrix product \code{AB}, computed
|
||||
by clearing denominators and multiplying over the integers.
|
||||
|
||||
void fmpq_mat_mul(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B)
|
||||
|
||||
Sets \code{C} to the matrix product \code{AB}. This
|
||||
simply calls \code{fmpq_mat_mul_cleared}.
|
||||
|
||||
void fmpq_mat_mul_fmpz_mat(fmpq_mat_t C, const fmpq_mat_t A,
|
||||
const fmpz_mat_t B)
|
||||
|
||||
Sets \code{C} to the matrix product \code{AB}, with \code{B}
|
||||
an integer matrix. This function works efficiently by clearing
|
||||
denominators of \code{A}.
|
||||
|
||||
void fmpq_mat_mul_r_fmpz_mat(fmpq_mat_t C, const fmpz_mat_t A,
|
||||
const fmpq_mat_t B)
|
||||
|
||||
Sets \code{C} to the matrix product \code{AB}, with \code{A}
|
||||
an integer matrix. This function works efficiently by clearing
|
||||
denominators of \code{B}.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Trace
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_trace(fmpq_t trace, const fmpq_mat_t mat)
|
||||
|
||||
Computes the trace of the matrix, i.e. the sum of the entries on
|
||||
the main diagonal. The matrix is required to be square.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Determinant
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
void fmpq_mat_det(fmpq_t det, const fmpq_mat_t mat)
|
||||
|
||||
Sets \code{det} to the determinant of \code{mat}. In the general case,
|
||||
the determinant is computed by clearing denominators and computing a
|
||||
determinant over the integers. Matrices of size 0, 1 or 2 are handled
|
||||
directly.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Nonsingular solving
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
int fmpq_mat_solve_fraction_free(fmpq_mat_t X, const fmpq_mat_t A,
|
||||
const fmpq_mat_t B)
|
||||
|
||||
Solves \code{AX = B} for nonsingular \code{A} by clearing denominators
|
||||
and solving the rescaled system over the integers using a fraction-free
|
||||
algorithm. This is usually the fastest algorithm for small systems.
|
||||
Returns nonzero if \code{X} is nonsingular or if the right hand side
|
||||
is empty, and zero otherwise.
|
||||
|
||||
int fmpq_mat_solve_dixon(fmpq_mat_t X, const fmpq_mat_t A, const fmpq_mat_t B)
|
||||
|
||||
Solves \code{AX = B} for nonsingular \code{A} by clearing denominators
|
||||
and solving the rescaled system over the integers using Dixon's algorithm.
|
||||
The rational solution matrix is generated using rational reconstruction.
|
||||
This is usually the fastest algorithm for large systems.
|
||||
Returns nonzero if \code{X} is nonsingular or if the right hand side
|
||||
is empty, and zero otherwise.
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Inverse
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
int fmpq_mat_inv(fmpq_mat_t B, const fmpq_mat_t A)
|
||||
|
||||
Sets \code{B} to the inverse matrix of \code{A} and returns nonzero.
|
||||
Returns zero if \code{A} is singular. \code{A} must be a square matrix.
|
||||
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
Echelon form
|
||||
|
||||
*******************************************************************************
|
||||
|
||||
int fmpq_mat_pivot(slong * perm, fmpq_mat_t mat, slong r, slong c)
|
||||
|
||||
Helper function for row reduction. Returns 1 if the entry of \code{mat}
|
||||
at row $r$ and column $c$ is nonzero. Otherwise searches for a nonzero
|
||||
entry in the same column among rows $r+1, r+2, \ldots$. If a nonzero
|
||||
entry is found at row $s$, swaps rows $r$ and $s$ and the corresponding
|
||||
entries in \code{perm} (unless \code{NULL}) and returns -1. If no
|
||||
nonzero pivot entry is found, leaves the inputs unchanged and returns 0.
|
||||
|
||||
slong fmpq_mat_rref_classical(fmpq_mat_t B, const fmpq_mat_t A)
|
||||
|
||||
Sets \code{B} to the reduced row echelon form of \code{A} and returns
|
||||
the rank. Performs Gauss-Jordan elimination directly over the rational
|
||||
numbers. This algorithm is usually inefficient and is mainly intended
|
||||
to be used for testing purposes.
|
||||
|
||||
slong fmpq_mat_rref_fraction_free(fmpq_mat_t B, const fmpq_mat_t A)
|
||||
|
||||
Sets \code{B} to the reduced row echelon form of \code{A} and returns
|
||||
the rank. Clears denominators and performs fraction-free Gauss-Jordan
|
||||
elimination using \code{fmpz_mat} functions.
|
||||
|
||||
slong fmpq_mat_rref(fmpq_mat_t B, const fmpq_mat_t A)
|
||||
|
||||
Sets \code{B} to the reduced row echelon form of \code{A} and returns
|
||||
the rank. This function automatically chooses between the classical and
|
||||
fraction-free algorithms depending on the size of the matrix.
|
||||
|
||||
48
external/flint-2.4.3/fmpq_mat/equal.c
vendored
Normal file
48
external/flint-2.4.3/fmpq_mat/equal.c
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
int
|
||||
fmpq_mat_equal(const fmpq_mat_t mat1, const fmpq_mat_t mat2)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
if (mat1->r != mat2->r || mat1->c != mat2->c)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < mat1->r; i++)
|
||||
{
|
||||
for (j = 0; j < mat1->c; j++)
|
||||
{
|
||||
if (!fmpq_equal(fmpq_mat_entry(mat1, i, j),
|
||||
fmpq_mat_entry(mat2, i, j)))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
45
external/flint-2.4.3/fmpq_mat/get_fmpz_mat.c
vendored
Normal file
45
external/flint-2.4.3/fmpq_mat/get_fmpz_mat.c
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
int
|
||||
fmpq_mat_get_fmpz_mat(fmpz_mat_t dest, const fmpq_mat_t mat)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
{
|
||||
for (j = 0; j < mat->c; j++)
|
||||
{
|
||||
if (fmpz_is_one(fmpq_mat_entry_den(mat, i, j)))
|
||||
fmpz_set(fmpz_mat_entry(dest, i, j),
|
||||
fmpq_mat_entry_num(mat, i, j));
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
71
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_colwise.c
vendored
Normal file
71
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_colwise.c
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void
|
||||
fmpq_mat_get_fmpz_mat_colwise(fmpz_mat_t num, fmpz * den, const fmpq_mat_t mat)
|
||||
{
|
||||
fmpz_t t, lcm;
|
||||
slong i, j;
|
||||
|
||||
if (fmpq_mat_is_empty(mat))
|
||||
return;
|
||||
|
||||
fmpz_init(t);
|
||||
fmpz_init(lcm);
|
||||
|
||||
for (j = 0; j < mat->c; j++)
|
||||
{
|
||||
/* Compute common denominator of column */
|
||||
fmpz_set(lcm, fmpq_mat_entry_den(mat, 0, j));
|
||||
|
||||
for (i = 1; i < mat->r; i++)
|
||||
fmpz_lcm(lcm, lcm, fmpq_mat_entry_den(mat, i, j));
|
||||
|
||||
if (den != NULL)
|
||||
fmpz_set(den + j, lcm);
|
||||
|
||||
/* Rescale numerators in column */
|
||||
if (fmpz_is_one(lcm))
|
||||
{
|
||||
for (i = 0; i < mat->r; i++)
|
||||
fmpz_set(fmpz_mat_entry(num, i, j),
|
||||
fmpq_mat_entry_num(mat, i, j));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < mat->r; i++)
|
||||
{
|
||||
fmpz_divexact(t, lcm, fmpq_mat_entry_den(mat, i, j));
|
||||
fmpz_mul(fmpz_mat_entry(num, i, j),
|
||||
fmpq_mat_entry_num(mat, i, j), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(t);
|
||||
fmpz_clear(lcm);
|
||||
}
|
||||
42
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_entrywise.c
vendored
Normal file
42
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_entrywise.c
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void
|
||||
fmpq_mat_get_fmpz_mat_entrywise(fmpz_mat_t num, fmpz_mat_t den,
|
||||
const fmpq_mat_t mat)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
{
|
||||
for (j = 0; j < mat->c; j++)
|
||||
{
|
||||
fmpz_set(fmpz_mat_entry(num, i, j), fmpq_mat_entry_num(mat, i, j));
|
||||
fmpz_set(fmpz_mat_entry(den, i, j), fmpq_mat_entry_den(mat, i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
69
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_matwise.c
vendored
Normal file
69
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_matwise.c
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void
|
||||
fmpq_mat_get_fmpz_mat_matwise(fmpz_mat_t num, fmpz_t den, const fmpq_mat_t mat)
|
||||
{
|
||||
fmpz_t t, lcm;
|
||||
slong i, j;
|
||||
|
||||
if (fmpq_mat_is_empty(mat))
|
||||
return;
|
||||
|
||||
fmpz_init(t);
|
||||
fmpz_init(lcm);
|
||||
fmpz_one(lcm);
|
||||
|
||||
/* Compute common denominator of matrix */
|
||||
for (i = 0; i < mat->r; i++)
|
||||
for (j = 0; j < mat->c; j++)
|
||||
fmpz_lcm(lcm, lcm, fmpq_mat_entry_den(mat, i, j));
|
||||
|
||||
fmpz_set(den, lcm);
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
{
|
||||
for (j = 0; j < mat->c; j++)
|
||||
{
|
||||
/* Rescale numerators */
|
||||
if (fmpz_is_one(lcm))
|
||||
{
|
||||
fmpz_set(fmpz_mat_entry(num, i, j),
|
||||
fmpq_mat_entry_num(mat, i, j));
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_divexact(t, lcm, fmpq_mat_entry_den(mat, i, j));
|
||||
fmpz_mul(fmpz_mat_entry(num, i, j),
|
||||
fmpq_mat_entry_num(mat, i, j), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(t);
|
||||
fmpz_clear(lcm);
|
||||
}
|
||||
43
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_mod_fmpz.c
vendored
Normal file
43
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_mod_fmpz.c
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
/* TODO: we may want to clear denominators to avoid expensive invmods */
|
||||
void
|
||||
fmpq_mat_get_fmpz_mat_mod_fmpz(fmpz_mat_t dest, const fmpq_mat_t mat,
|
||||
const fmpz_t mod)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
{
|
||||
for (j = 0; j < mat->c; j++)
|
||||
{
|
||||
fmpq_mod_fmpz(fmpz_mat_entry(dest, i, j),
|
||||
fmpq_mat_entry(mat, i, j), mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
97
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_rowwise.c
vendored
Normal file
97
external/flint-2.4.3/fmpq_mat/get_fmpz_mat_rowwise.c
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void
|
||||
_fmpq_mat_get_fmpz_mat_rowwise(fmpz_mat_struct ** num, fmpz * den,
|
||||
const fmpq_mat_struct ** mat, slong n)
|
||||
{
|
||||
fmpz_t t, lcm;
|
||||
slong i, j, k;
|
||||
|
||||
if (fmpq_mat_is_empty(mat[0]))
|
||||
return;
|
||||
|
||||
fmpz_init(t);
|
||||
fmpz_init(lcm);
|
||||
|
||||
for (i = 0; i < mat[0]->r; i++)
|
||||
{
|
||||
/* Compute common denominator of row */
|
||||
fmpz_set(lcm, fmpq_mat_entry_den(mat[0], i, 0));
|
||||
|
||||
for (k = 0; k < n; k++)
|
||||
for (j = (k == 0); j < mat[k]->c; j++)
|
||||
fmpz_lcm(lcm, lcm, fmpq_mat_entry_den(mat[k], i, j));
|
||||
|
||||
if (den != NULL)
|
||||
fmpz_set(den + i, lcm);
|
||||
|
||||
for (k = 0; k < n; k++)
|
||||
{
|
||||
/* Rescale numerators in row */
|
||||
if (fmpz_is_one(lcm))
|
||||
{
|
||||
for (j = 0; j < mat[k]->c; j++)
|
||||
fmpz_set(fmpz_mat_entry(num[k], i, j),
|
||||
fmpq_mat_entry_num(mat[k], i, j));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < mat[k]->c; j++)
|
||||
{
|
||||
fmpz_divexact(t, lcm, fmpq_mat_entry_den(mat[k], i, j));
|
||||
fmpz_mul(fmpz_mat_entry(num[k], i, j),
|
||||
fmpq_mat_entry_num(mat[k], i, j), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(t);
|
||||
fmpz_clear(lcm);
|
||||
}
|
||||
|
||||
void
|
||||
fmpq_mat_get_fmpz_mat_rowwise(fmpz_mat_t num, fmpz * den, const fmpq_mat_t mat)
|
||||
{
|
||||
_fmpq_mat_get_fmpz_mat_rowwise(&num, den, &mat, 1);
|
||||
}
|
||||
|
||||
void
|
||||
fmpq_mat_get_fmpz_mat_rowwise_2(fmpz_mat_t num, fmpz_mat_t num2, fmpz * den,
|
||||
const fmpq_mat_t mat, const fmpq_mat_t mat2)
|
||||
{
|
||||
fmpz_mat_struct * nums[2];
|
||||
fmpq_mat_struct * mats[2];
|
||||
|
||||
nums[0] = num;
|
||||
nums[1] = num2;
|
||||
mats[0] = (fmpq_mat_struct *) mat;
|
||||
mats[1] = (fmpq_mat_struct *) mat2;
|
||||
|
||||
_fmpq_mat_get_fmpz_mat_rowwise(nums, den, (const fmpq_mat_struct **) mats, 2);
|
||||
}
|
||||
35
external/flint-2.4.3/fmpq_mat/hilbert_matrix.c
vendored
Normal file
35
external/flint-2.4.3/fmpq_mat/hilbert_matrix.c
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_hilbert_matrix(fmpq_mat_t mat)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
for (j = 0; j < mat->c; j++)
|
||||
fmpq_set_si(fmpq_mat_entry(mat, i, j), 1, i + j + 1);
|
||||
}
|
||||
49
external/flint-2.4.3/fmpq_mat/init.c
vendored
Normal file
49
external/flint-2.4.3/fmpq_mat/init.c
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_init(fmpq_mat_t mat, slong rows, slong cols)
|
||||
{
|
||||
if ((rows) && (cols))
|
||||
{
|
||||
slong i;
|
||||
mat->entries = (fmpq *) flint_calloc(rows * cols, sizeof(fmpq));
|
||||
mat->rows = (fmpq **) flint_malloc(rows * sizeof(fmpq *));
|
||||
|
||||
/* Set denominators */
|
||||
for (i = 0; i < rows * cols; i++)
|
||||
mat->entries[i].den = WORD(1);
|
||||
|
||||
for (i = 0; i < rows; i++)
|
||||
mat->rows[i] = mat->entries + i * cols;
|
||||
}
|
||||
else
|
||||
mat->entries = NULL;
|
||||
|
||||
mat->r = rows;
|
||||
mat->c = cols;
|
||||
}
|
||||
110
external/flint-2.4.3/fmpq_mat/inv.c
vendored
Normal file
110
external/flint-2.4.3/fmpq_mat/inv.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 "fmpq_mat.h"
|
||||
|
||||
int fmpq_mat_inv(fmpq_mat_t B, const fmpq_mat_t A)
|
||||
{
|
||||
slong n = A->r;
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (n == 1)
|
||||
{
|
||||
if (fmpq_is_zero(fmpq_mat_entry(A, 0, 0)))
|
||||
return 0;
|
||||
fmpq_inv(fmpq_mat_entry(B, 0, 0), fmpq_mat_entry(A, 0, 0));
|
||||
return 1;
|
||||
}
|
||||
else if (n == 2)
|
||||
{
|
||||
fmpq_t d;
|
||||
int success;
|
||||
|
||||
fmpq_init(d);
|
||||
|
||||
fmpq_mul(d, fmpq_mat_entry(A, 0, 0), fmpq_mat_entry(A, 1, 1));
|
||||
fmpq_submul(d, fmpq_mat_entry(A, 0, 1), fmpq_mat_entry(A, 1, 0));
|
||||
success = !fmpq_is_zero(d);
|
||||
|
||||
if (success)
|
||||
{
|
||||
fmpq_t t00, t01, t10, t11;
|
||||
fmpq_inv(d, d);
|
||||
|
||||
fmpq_init(t00);
|
||||
fmpq_init(t01);
|
||||
fmpq_init(t10);
|
||||
fmpq_init(t11);
|
||||
|
||||
fmpq_mul(t00, fmpq_mat_entry(A, 1, 1), d);
|
||||
fmpq_mul(t01, fmpq_mat_entry(A, 0, 1), d);
|
||||
fmpq_mul(t10, fmpq_mat_entry(A, 1, 0), d);
|
||||
fmpq_mul(t11, fmpq_mat_entry(A, 0, 0), d);
|
||||
|
||||
fmpq_set(fmpq_mat_entry(B, 0, 0), t00);
|
||||
fmpq_neg(fmpq_mat_entry(B, 0, 1), t01);
|
||||
fmpq_neg(fmpq_mat_entry(B, 1, 0), t10);
|
||||
fmpq_set(fmpq_mat_entry(B, 1, 1), t11);
|
||||
|
||||
fmpq_clear(t00);
|
||||
fmpq_clear(t01);
|
||||
fmpq_clear(t10);
|
||||
fmpq_clear(t11);
|
||||
}
|
||||
|
||||
fmpq_clear(d);
|
||||
return success;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_mat_t Aclear, Bclear, I;
|
||||
fmpz * den;
|
||||
slong i;
|
||||
int success;
|
||||
|
||||
fmpz_mat_init(Aclear, n, n);
|
||||
fmpz_mat_init(Bclear, n, n);
|
||||
fmpz_mat_init(I, n, n);
|
||||
den = _fmpz_vec_init(n);
|
||||
|
||||
fmpq_mat_get_fmpz_mat_rowwise(Aclear, den, A);
|
||||
for (i = 0; i < n; i++)
|
||||
fmpz_set(fmpz_mat_entry(I, i, i), den + i);
|
||||
|
||||
success = fmpz_mat_solve(Bclear, den, Aclear, I);
|
||||
if (success)
|
||||
fmpq_mat_set_fmpz_mat_div_fmpz(B, Bclear, den);
|
||||
|
||||
fmpz_mat_clear(Aclear);
|
||||
fmpz_mat_clear(Bclear);
|
||||
fmpz_mat_clear(I);
|
||||
_fmpz_vec_clear(den, A->r);
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
42
external/flint-2.4.3/fmpq_mat/is_integral.c
vendored
Normal file
42
external/flint-2.4.3/fmpq_mat/is_integral.c
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
int fmpq_mat_is_integral(const fmpq_mat_t mat)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
{
|
||||
for (j = 0; j < mat->c; j++)
|
||||
{
|
||||
if (!fmpz_is_one(fmpq_mat_entry_den(mat, i, j)))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
42
external/flint-2.4.3/fmpq_mat/is_zero.c
vendored
Normal file
42
external/flint-2.4.3/fmpq_mat/is_zero.c
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
int fmpq_mat_is_zero(const fmpq_mat_t mat)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
{
|
||||
for (j = 0; j < mat->c; j++)
|
||||
{
|
||||
if (!fmpq_is_zero(fmpq_mat_entry(mat, i, j)))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
32
external/flint-2.4.3/fmpq_mat/mul.c
vendored
Normal file
32
external/flint-2.4.3/fmpq_mat/mul.c
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_mul(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B)
|
||||
{
|
||||
/* This is faster except maybe for 1x1 or 2x2 matrices */
|
||||
fmpq_mat_mul_cleared(C, A, B);
|
||||
}
|
||||
67
external/flint-2.4.3/fmpq_mat/mul_cleared.c
vendored
Normal file
67
external/flint-2.4.3/fmpq_mat/mul_cleared.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) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_mul_cleared(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
fmpz_mat_t Aclear;
|
||||
fmpz_mat_t Bclear;
|
||||
fmpz_mat_t Cclear;
|
||||
|
||||
fmpz * Aden;
|
||||
fmpz * Bden;
|
||||
|
||||
fmpz_mat_init(Aclear, A->r, A->c);
|
||||
fmpz_mat_init(Bclear, B->r, B->c);
|
||||
fmpz_mat_init(Cclear, A->r, B->c);
|
||||
|
||||
Aden = _fmpz_vec_init(A->r);
|
||||
Bden = _fmpz_vec_init(B->c);
|
||||
|
||||
fmpq_mat_get_fmpz_mat_rowwise(Aclear, Aden, A);
|
||||
fmpq_mat_get_fmpz_mat_colwise(Bclear, Bden, B);
|
||||
|
||||
fmpz_mat_mul(Cclear, Aclear, Bclear);
|
||||
|
||||
for (i = 0; i < C->r; i++)
|
||||
{
|
||||
for (j = 0; j < C->c; j++)
|
||||
{
|
||||
fmpz_set(fmpq_mat_entry_num(C, i, j), fmpz_mat_entry(Cclear, i, j));
|
||||
fmpz_mul(fmpq_mat_entry_den(C, i, j), Aden + i, Bden + j);
|
||||
fmpq_canonicalise(fmpq_mat_entry(C, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_mat_clear(Aclear);
|
||||
fmpz_mat_clear(Bclear);
|
||||
fmpz_mat_clear(Cclear);
|
||||
|
||||
_fmpz_vec_clear(Aden, A->r);
|
||||
_fmpz_vec_clear(Bden, B->c);
|
||||
}
|
||||
60
external/flint-2.4.3/fmpq_mat/mul_direct.c
vendored
Normal file
60
external/flint-2.4.3/fmpq_mat/mul_direct.c
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_mul_direct(fmpq_mat_t C, const fmpq_mat_t A, const fmpq_mat_t B)
|
||||
{
|
||||
slong i, j, k;
|
||||
|
||||
if (A == C || B == C)
|
||||
{
|
||||
flint_printf("Exception (fmpq_mat_mul_direct). Aliasing not implemented.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (A->c == 0)
|
||||
{
|
||||
fmpq_mat_zero(C);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < A->r; i++)
|
||||
{
|
||||
for (j = 0; j < B->c; j++)
|
||||
{
|
||||
fmpq_mul(fmpq_mat_entry(C, i, j),
|
||||
fmpq_mat_entry(A, i, 0),
|
||||
fmpq_mat_entry(B, 0, j));
|
||||
|
||||
for (k = 1; k < A->c; k++)
|
||||
{
|
||||
fmpq_addmul(fmpq_mat_entry(C, i, j),
|
||||
fmpq_mat_entry(A, i, k),
|
||||
fmpq_mat_entry(B, k, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
external/flint-2.4.3/fmpq_mat/mul_fmpz_mat.c
vendored
Normal file
60
external/flint-2.4.3/fmpq_mat/mul_fmpz_mat.c
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void
|
||||
fmpq_mat_mul_fmpz_mat(fmpq_mat_t C, const fmpq_mat_t A, const fmpz_mat_t B)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
fmpz_mat_t Aclear;
|
||||
fmpz_mat_t Cclear;
|
||||
|
||||
fmpz * Aden;
|
||||
|
||||
fmpz_mat_init(Aclear, A->r, A->c);
|
||||
fmpz_mat_init(Cclear, A->r, B->c);
|
||||
|
||||
Aden = _fmpz_vec_init(A->r);
|
||||
|
||||
fmpq_mat_get_fmpz_mat_rowwise(Aclear, Aden, A);
|
||||
fmpz_mat_mul(Cclear, Aclear, B);
|
||||
|
||||
for (i = 0; i < C->r; i++)
|
||||
{
|
||||
for (j = 0; j < C->c; j++)
|
||||
{
|
||||
fmpz_set(fmpq_mat_entry_num(C, i, j), fmpz_mat_entry(Cclear, i, j));
|
||||
fmpz_set(fmpq_mat_entry_den(C, i, j), Aden + i);
|
||||
fmpq_canonicalise(fmpq_mat_entry(C, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_mat_clear(Aclear);
|
||||
fmpz_mat_clear(Cclear);
|
||||
|
||||
_fmpz_vec_clear(Aden, A->r);
|
||||
}
|
||||
60
external/flint-2.4.3/fmpq_mat/mul_r_fmpz_mat.c
vendored
Normal file
60
external/flint-2.4.3/fmpq_mat/mul_r_fmpz_mat.c
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void
|
||||
fmpq_mat_mul_r_fmpz_mat(fmpq_mat_t C, const fmpz_mat_t A, const fmpq_mat_t B)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
fmpz_mat_t Bclear;
|
||||
fmpz_mat_t Cclear;
|
||||
|
||||
fmpz * Bden;
|
||||
|
||||
fmpz_mat_init(Bclear, B->r, B->c);
|
||||
fmpz_mat_init(Cclear, A->r, B->c);
|
||||
|
||||
Bden = _fmpz_vec_init(B->c);
|
||||
|
||||
fmpq_mat_get_fmpz_mat_colwise(Bclear, Bden, B);
|
||||
fmpz_mat_mul(Cclear, A, Bclear);
|
||||
|
||||
for (i = 0; i < C->r; i++)
|
||||
{
|
||||
for (j = 0; j < C->c; j++)
|
||||
{
|
||||
fmpz_set(fmpq_mat_entry_num(C, i, j), fmpz_mat_entry(Cclear, i, j));
|
||||
fmpz_set(fmpq_mat_entry_den(C, i, j), Bden + j);
|
||||
fmpq_canonicalise(fmpq_mat_entry(C, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_mat_clear(Bclear);
|
||||
fmpz_mat_clear(Cclear);
|
||||
|
||||
_fmpz_vec_clear(Bden, B->c);
|
||||
}
|
||||
37
external/flint-2.4.3/fmpq_mat/neg.c
vendored
Normal file
37
external/flint-2.4.3/fmpq_mat/neg.c
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_neg(fmpq_mat_t rop, const fmpq_mat_t op)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < op->r; i++)
|
||||
for (j = 0; j < op->c; j++)
|
||||
fmpq_neg(fmpq_mat_entry(rop, i, j),
|
||||
fmpq_mat_entry(op, i, j));
|
||||
}
|
||||
|
||||
41
external/flint-2.4.3/fmpq_mat/one.c
vendored
Normal file
41
external/flint-2.4.3/fmpq_mat/one.c
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_one(fmpq_mat_t mat)
|
||||
{
|
||||
slong i, j, min;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
for (j = 0; j < mat->c; j++)
|
||||
fmpq_zero(fmpq_mat_entry(mat, i, j));
|
||||
|
||||
min = FLINT_MIN(mat->r, mat->c);
|
||||
|
||||
for (i = 0; i < min; i++)
|
||||
fmpq_one(fmpq_mat_entry(mat, i, i));
|
||||
}
|
||||
|
||||
55
external/flint-2.4.3/fmpq_mat/pivot.c
vendored
Normal file
55
external/flint-2.4.3/fmpq_mat/pivot.c
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
int
|
||||
fmpq_mat_pivot(slong * perm, fmpq_mat_t mat, slong r, slong c)
|
||||
{
|
||||
slong t, j;
|
||||
fmpq * u;
|
||||
|
||||
if (!fmpq_is_zero(fmpq_mat_entry(mat, r, c)))
|
||||
return 1;
|
||||
|
||||
for (j = r + 1; j < mat->r; j++)
|
||||
{
|
||||
if (!fmpq_is_zero(fmpq_mat_entry(mat, j, c)))
|
||||
{
|
||||
if (perm)
|
||||
{
|
||||
t = perm[j];
|
||||
perm[j] = perm[r];
|
||||
perm[r] = t;
|
||||
}
|
||||
|
||||
u = mat->rows[j];
|
||||
mat->rows[j] = mat->rows[r];
|
||||
mat->rows[r] = u;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
46
external/flint-2.4.3/fmpq_mat/print.c
vendored
Normal file
46
external/flint-2.4.3/fmpq_mat/print.c
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_print(const fmpq_mat_t mat)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
flint_printf("<%wd x %wd matrix over Q>\n", mat->r, mat->c);
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
{
|
||||
flint_printf("[");
|
||||
for (j = 0; j < mat->c; j++)
|
||||
{
|
||||
fmpq_print(fmpq_mat_entry(mat, i, j));
|
||||
if (j + 1 < mat->c)
|
||||
flint_printf(", ");
|
||||
}
|
||||
flint_printf("]\n");
|
||||
}
|
||||
flint_printf("\n");
|
||||
}
|
||||
35
external/flint-2.4.3/fmpq_mat/randbits.c
vendored
Normal file
35
external/flint-2.4.3/fmpq_mat/randbits.c
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_randbits(fmpq_mat_t mat, flint_rand_t state, mp_bitcnt_t bits)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
for (j = 0; j < mat->c; j++)
|
||||
fmpq_randbits(fmpq_mat_entry(mat,i,j), state, bits);
|
||||
}
|
||||
35
external/flint-2.4.3/fmpq_mat/randtest.c
vendored
Normal file
35
external/flint-2.4.3/fmpq_mat/randtest.c
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_randtest(fmpq_mat_t mat, flint_rand_t state, mp_bitcnt_t bits)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
for (j = 0; j < mat->c; j++)
|
||||
fmpq_randtest(fmpq_mat_entry(mat,i,j), state, bits);
|
||||
}
|
||||
35
external/flint-2.4.3/fmpq_mat/rref.c
vendored
Normal file
35
external/flint-2.4.3/fmpq_mat/rref.c
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
slong
|
||||
fmpq_mat_rref(fmpq_mat_t B, const fmpq_mat_t A)
|
||||
{
|
||||
if (A->r <= 2 || A->c <= 2)
|
||||
return fmpq_mat_rref_classical(B, A);
|
||||
else
|
||||
return fmpq_mat_rref_fraction_free(B, A);
|
||||
}
|
||||
86
external/flint-2.4.3/fmpq_mat/rref_classical.c
vendored
Normal file
86
external/flint-2.4.3/fmpq_mat/rref_classical.c
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
slong
|
||||
fmpq_mat_rref_classical(fmpq_mat_t B, const fmpq_mat_t A)
|
||||
{
|
||||
slong m, n, i, j, pivot_row, pivot_col, rank;
|
||||
|
||||
m = A->r;
|
||||
n = A->c;
|
||||
|
||||
if (m == 0 || n == 0)
|
||||
return 0;
|
||||
|
||||
if (A != B)
|
||||
fmpq_mat_set(B, A);
|
||||
|
||||
rank = 0;
|
||||
pivot_row = 0;
|
||||
pivot_col = 0;
|
||||
|
||||
while (pivot_row < m && pivot_col < n)
|
||||
{
|
||||
if (!fmpq_mat_pivot(NULL, B, pivot_row, pivot_col))
|
||||
{
|
||||
pivot_col++;
|
||||
continue;
|
||||
}
|
||||
|
||||
rank++;
|
||||
|
||||
/* Scale row to have 1 as leading entry */
|
||||
for (j = pivot_col + 1; j < n; j++)
|
||||
{
|
||||
fmpq_div(fmpq_mat_entry(B, pivot_row, j),
|
||||
fmpq_mat_entry(B, pivot_row, j),
|
||||
fmpq_mat_entry(B, pivot_row, pivot_col));
|
||||
}
|
||||
|
||||
/* Eliminate rows above and below */
|
||||
for (i = 0; i < m; i++)
|
||||
{
|
||||
if (i == pivot_row ||
|
||||
fmpq_is_zero(fmpq_mat_entry(B, i, pivot_col)))
|
||||
continue;
|
||||
|
||||
for (j = pivot_col + 1; j < n; j++)
|
||||
fmpq_submul(fmpq_mat_entry(B, i, j),
|
||||
fmpq_mat_entry(B, pivot_row, j),
|
||||
fmpq_mat_entry(B, i, pivot_col));
|
||||
}
|
||||
|
||||
/* Clear pivot column */
|
||||
for (i = 0; i < m; i++)
|
||||
fmpq_set_si(fmpq_mat_entry(B, i, pivot_col), i == pivot_row, 1);
|
||||
|
||||
pivot_row++;
|
||||
pivot_col++;
|
||||
}
|
||||
|
||||
return rank;
|
||||
}
|
||||
53
external/flint-2.4.3/fmpq_mat/rref_fraction_free.c
vendored
Normal file
53
external/flint-2.4.3/fmpq_mat/rref_fraction_free.c
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
slong
|
||||
fmpq_mat_rref_fraction_free(fmpq_mat_t B, const fmpq_mat_t A)
|
||||
{
|
||||
fmpz_mat_t Aclear;
|
||||
fmpz_t den;
|
||||
slong rank;
|
||||
|
||||
if (fmpq_mat_is_empty(A))
|
||||
return 0;
|
||||
|
||||
fmpz_mat_init(Aclear, A->r, A->c);
|
||||
fmpq_mat_get_fmpz_mat_rowwise(Aclear, NULL, A);
|
||||
fmpz_init(den);
|
||||
|
||||
rank = fmpz_mat_rref(Aclear, den, Aclear);
|
||||
|
||||
if (rank == 0)
|
||||
fmpq_mat_zero(B);
|
||||
else
|
||||
fmpq_mat_set_fmpz_mat_div_fmpz(B, Aclear, den);
|
||||
|
||||
fmpz_mat_clear(Aclear);
|
||||
fmpz_clear(den);
|
||||
|
||||
return rank;
|
||||
}
|
||||
38
external/flint-2.4.3/fmpq_mat/scalar_div_fmpz.c
vendored
Normal file
38
external/flint-2.4.3/fmpq_mat/scalar_div_fmpz.c
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_scalar_div_fmpz(fmpq_mat_t rop,
|
||||
const fmpq_mat_t op, const fmpz_t x)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < op->r; i++)
|
||||
for (j = 0; j < op->c; j++)
|
||||
fmpq_div_fmpz(fmpq_mat_entry(rop, i, j),
|
||||
fmpq_mat_entry(op, i, j), x);
|
||||
}
|
||||
|
||||
38
external/flint-2.4.3/fmpq_mat/scalar_mul_fmpz.c
vendored
Normal file
38
external/flint-2.4.3/fmpq_mat/scalar_mul_fmpz.c
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_scalar_mul_fmpz(fmpq_mat_t rop,
|
||||
const fmpq_mat_t op, const fmpz_t x)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < op->r; i++)
|
||||
for (j = 0; j < op->c; j++)
|
||||
fmpq_mul_fmpz(fmpq_mat_entry(rop, i, j),
|
||||
fmpq_mat_entry(op, i, j), x);
|
||||
}
|
||||
|
||||
35
external/flint-2.4.3/fmpq_mat/set.c
vendored
Normal file
35
external/flint-2.4.3/fmpq_mat/set.c
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_set(fmpq_mat_t dest, const fmpq_mat_t src)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < src->r; i++)
|
||||
for (j = 0; j < src->c; j++)
|
||||
fmpq_set(fmpq_mat_entry(dest,i,j), fmpq_mat_entry(src,i,j));
|
||||
}
|
||||
40
external/flint-2.4.3/fmpq_mat/set_fmpz_mat.c
vendored
Normal file
40
external/flint-2.4.3/fmpq_mat/set_fmpz_mat.c
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_set_fmpz_mat(fmpq_mat_t dest, const fmpz_mat_t src)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < src->r; i++)
|
||||
{
|
||||
for (j = 0; j < src->c; j++)
|
||||
{
|
||||
fmpz_set(fmpq_mat_entry_num(dest, i, j), fmpz_mat_entry(src, i, j));
|
||||
fmpz_one(fmpq_mat_entry_den(dest, i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
69
external/flint-2.4.3/fmpq_mat/set_fmpz_mat_div_fmpz.c
vendored
Normal file
69
external/flint-2.4.3/fmpq_mat/set_fmpz_mat_div_fmpz.c
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void
|
||||
fmpq_mat_set_fmpz_mat_div_fmpz(fmpq_mat_t X, const fmpz_mat_t Xnum,
|
||||
const fmpz_t den)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
if (fmpz_is_one(den))
|
||||
{
|
||||
fmpq_mat_set_fmpz_mat(X, Xnum);
|
||||
}
|
||||
else if (*den == WORD(-1))
|
||||
{
|
||||
fmpz_t t;
|
||||
fmpz_init(t);
|
||||
fmpz_set(t, den);
|
||||
|
||||
for (i = 0; i < Xnum->r; i++)
|
||||
{
|
||||
for (j = 0; j < Xnum->c; j++)
|
||||
{
|
||||
fmpz_neg(fmpq_mat_entry_num(X, i, j),
|
||||
fmpz_mat_entry(Xnum, i, j));
|
||||
fmpz_one(fmpq_mat_entry_den(X, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < Xnum->r; i++)
|
||||
{
|
||||
for (j = 0; j < Xnum->c; j++)
|
||||
{
|
||||
fmpz_set(fmpq_mat_entry_num(X, i, j),
|
||||
fmpz_mat_entry(Xnum, i, j));
|
||||
fmpz_set(fmpq_mat_entry_den(X, i, j), den);
|
||||
fmpq_canonicalise(fmpq_mat_entry(X, i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
76
external/flint-2.4.3/fmpq_mat/set_fmpz_mat_mod_fmpz.c
vendored
Normal file
76
external/flint-2.4.3/fmpq_mat/set_fmpz_mat_mod_fmpz.c
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
int
|
||||
fmpq_mat_set_fmpz_mat_mod_fmpz(fmpq_mat_t X,
|
||||
const fmpz_mat_t Xmod, const fmpz_t mod)
|
||||
{
|
||||
fmpz_t num, den, t, u, d;
|
||||
slong i, j;
|
||||
|
||||
int success = 1;
|
||||
|
||||
fmpz_init(num);
|
||||
fmpz_init(den);
|
||||
fmpz_init(d);
|
||||
fmpz_init(t);
|
||||
fmpz_init(u);
|
||||
|
||||
fmpz_one(d);
|
||||
|
||||
for (i = 0; i < Xmod->r; i++)
|
||||
{
|
||||
for (j = 0; j < Xmod->c; j++)
|
||||
{
|
||||
/* TODO: handle various special cases efficiently; zeros,
|
||||
small integers, etc. */
|
||||
fmpz_mul(t, d, fmpz_mat_entry(Xmod, i, j));
|
||||
fmpz_fdiv_qr(u, t, t, mod);
|
||||
|
||||
success = _fmpq_reconstruct_fmpz(num, den, t, mod);
|
||||
|
||||
fmpz_mul(den, den, d);
|
||||
fmpz_set(d, den);
|
||||
|
||||
if (!success)
|
||||
goto cleanup;
|
||||
|
||||
fmpz_set(fmpq_mat_entry_num(X, i, j), num);
|
||||
fmpz_set(fmpq_mat_entry_den(X, i, j), den);
|
||||
fmpq_canonicalise(fmpq_mat_entry(X, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
fmpz_clear(num);
|
||||
fmpz_clear(den);
|
||||
fmpz_clear(d);
|
||||
fmpz_clear(t);
|
||||
fmpz_clear(u);
|
||||
|
||||
return success;
|
||||
}
|
||||
53
external/flint-2.4.3/fmpq_mat/solve_dixon.c
vendored
Normal file
53
external/flint-2.4.3/fmpq_mat/solve_dixon.c
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
int
|
||||
fmpq_mat_solve_dixon(fmpq_mat_t X, const fmpq_mat_t A, const fmpq_mat_t B)
|
||||
{
|
||||
fmpz_mat_t Anum;
|
||||
fmpz_mat_t Bnum;
|
||||
fmpz_mat_t Xnum;
|
||||
fmpz_t mod;
|
||||
int success;
|
||||
|
||||
fmpz_mat_init(Anum, A->r, A->c);
|
||||
fmpz_mat_init(Bnum, B->r, B->c);
|
||||
fmpz_mat_init(Xnum, B->r, B->c);
|
||||
fmpz_init(mod);
|
||||
|
||||
fmpq_mat_get_fmpz_mat_rowwise_2(Anum, Bnum, NULL, A, B);
|
||||
success = fmpz_mat_solve_dixon(Xnum, mod, Anum, Bnum);
|
||||
if (success)
|
||||
success = fmpq_mat_set_fmpz_mat_mod_fmpz(X, Xnum, mod);
|
||||
|
||||
fmpz_mat_clear(Anum);
|
||||
fmpz_mat_clear(Bnum);
|
||||
fmpz_mat_clear(Xnum);
|
||||
fmpz_clear(mod);
|
||||
|
||||
return success;
|
||||
}
|
||||
55
external/flint-2.4.3/fmpq_mat/solve_fraction_free.c
vendored
Normal file
55
external/flint-2.4.3/fmpq_mat/solve_fraction_free.c
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
int
|
||||
fmpq_mat_solve_fraction_free(fmpq_mat_t X, const fmpq_mat_t A,
|
||||
const fmpq_mat_t B)
|
||||
{
|
||||
fmpz_mat_t Anum;
|
||||
fmpz_mat_t Bnum;
|
||||
fmpz_mat_t Xnum;
|
||||
fmpz_t den;
|
||||
int success;
|
||||
|
||||
fmpz_mat_init(Anum, A->r, A->c);
|
||||
fmpz_mat_init(Bnum, B->r, B->c);
|
||||
fmpz_mat_init(Xnum, B->r, B->c);
|
||||
fmpz_init(den);
|
||||
|
||||
fmpq_mat_get_fmpz_mat_rowwise_2(Anum, Bnum, NULL, A, B);
|
||||
success = fmpz_mat_solve(Xnum, den, Anum, Bnum);
|
||||
|
||||
if (success)
|
||||
fmpq_mat_set_fmpz_mat_div_fmpz(X, Xnum, den);
|
||||
|
||||
fmpz_mat_clear(Anum);
|
||||
fmpz_mat_clear(Bnum);
|
||||
fmpz_mat_clear(Xnum);
|
||||
fmpz_clear(den);
|
||||
|
||||
return success;
|
||||
}
|
||||
37
external/flint-2.4.3/fmpq_mat/sub.c
vendored
Normal file
37
external/flint-2.4.3/fmpq_mat/sub.c
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_sub(fmpq_mat_t mat, const fmpq_mat_t mat1, const fmpq_mat_t mat2)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
for (j = 0; j < mat->c; j++)
|
||||
fmpq_sub(fmpq_mat_entry(mat, i, j),
|
||||
fmpq_mat_entry(mat1, i, j), fmpq_mat_entry(mat2, i, j));
|
||||
}
|
||||
|
||||
171
external/flint-2.4.3/fmpq_mat/test/t-add.c
vendored
Normal file
171
external/flint-2.4.3/fmpq_mat/test/t-add.c
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("add....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Aliasing, B = B + C */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpq_mat_randtest(C, state, bits);
|
||||
|
||||
fmpq_mat_add(A, B, C);
|
||||
fmpq_mat_add(B, B, C);
|
||||
|
||||
result = fmpq_mat_equal(A, B);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (B = B + C):\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Aliasing, C = B + C */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpq_mat_randtest(C, state, bits);
|
||||
|
||||
fmpq_mat_add(A, B, C);
|
||||
fmpq_mat_add(C, B, C);
|
||||
|
||||
result = fmpq_mat_equal(A, C);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (C = B + C):\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
}
|
||||
|
||||
/* A + B == B + A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C, D;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
fmpq_mat_init(D, m, n);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
|
||||
fmpq_mat_add(C, A, B);
|
||||
fmpq_mat_add(D, B, A);
|
||||
|
||||
result = fmpq_mat_equal(C, D);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (A + B == B + A):\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
flint_printf("D:\n");
|
||||
fmpq_mat_print(D);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
fmpq_mat_clear(D);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
105
external/flint-2.4.3/fmpq_mat/test/t-det.c
vendored
Normal file
105
external/flint-2.4.3/fmpq_mat/test/t-det.c
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("det....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C;
|
||||
fmpq_t a, b, ab, c;
|
||||
|
||||
slong n, bits;
|
||||
|
||||
n = n_randint(state, 10);
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_init(B, n, n);
|
||||
fmpq_mat_init(C, n, n);
|
||||
|
||||
fmpq_init(a);
|
||||
fmpq_init(b);
|
||||
fmpq_init(ab);
|
||||
fmpq_init(c);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpq_mat_mul(C, A, B);
|
||||
|
||||
fmpq_mat_det(a, A);
|
||||
fmpq_mat_det(b, B);
|
||||
fmpq_mat_det(c, C);
|
||||
|
||||
fmpq_mul(ab, a, b);
|
||||
|
||||
if (!fmpq_equal(ab, c))
|
||||
{
|
||||
flint_printf("FAIL!\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
flint_printf("\ndet(A):\n");
|
||||
fmpq_print(a);
|
||||
flint_printf("\ndet(B):\n");
|
||||
fmpq_print(b);
|
||||
flint_printf("\ndet(C):\n");
|
||||
fmpq_print(c);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_clear(a);
|
||||
fmpq_clear(b);
|
||||
fmpq_clear(ab);
|
||||
fmpq_clear(c);
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
66
external/flint-2.4.3/fmpq_mat/test/t-init_clear.c
vendored
Normal file
66
external/flint-2.4.3/fmpq_mat/test/t-init_clear.c
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq.h"
|
||||
#include "fmpq_mat.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++)
|
||||
{
|
||||
fmpq_mat_t a;
|
||||
slong j, k;
|
||||
slong rows = n_randint(state, 100);
|
||||
slong cols = n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(a, rows, cols);
|
||||
|
||||
for (j = 0; j < rows; j++)
|
||||
for (k = 0; k < cols; k++)
|
||||
fmpq_zero(fmpq_mat_entry(a, j, k));
|
||||
|
||||
fmpq_mat_clear(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
191
external/flint-2.4.3/fmpq_mat/test/t-inv.c
vendored
Normal file
191
external/flint-2.4.3/fmpq_mat/test/t-inv.c
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("inv....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C;
|
||||
fmpq_t d;
|
||||
|
||||
int success1, success2;
|
||||
slong n, bits;
|
||||
|
||||
n = n_randint(state, 10);
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_init(B, n, n);
|
||||
fmpq_mat_init(C, n, n);
|
||||
|
||||
fmpq_init(d);
|
||||
|
||||
/* XXX: replace with a randtest function */
|
||||
{
|
||||
slong k;
|
||||
|
||||
for (k = 0; (k < 100) && fmpq_is_zero(d); k++)
|
||||
{
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_det(d, A);
|
||||
}
|
||||
if (fmpq_is_zero(d))
|
||||
{
|
||||
fmpq_mat_one(A);
|
||||
}
|
||||
}
|
||||
|
||||
fmpq_clear(d);
|
||||
|
||||
success1 = fmpq_mat_inv(B, A);
|
||||
success2 = fmpq_mat_inv(C, B);
|
||||
|
||||
if (!fmpq_mat_equal(A, C) || !success1 || !success2)
|
||||
{
|
||||
flint_printf("FAIL!\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Test aliasing */
|
||||
for (i = 0; i < 10 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B;
|
||||
fmpq_t d;
|
||||
|
||||
int success1, success2;
|
||||
slong n, bits;
|
||||
|
||||
n = n_randint(state, 10);
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_init(B, n, n);
|
||||
|
||||
fmpq_init(d);
|
||||
|
||||
/* XXX: replace with a randtest function */
|
||||
do {
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_det(d, A);
|
||||
} while (fmpq_is_zero(d));
|
||||
|
||||
fmpq_clear(d);
|
||||
|
||||
success1 = fmpq_mat_inv(B, A);
|
||||
success2 = fmpq_mat_inv(A, A);
|
||||
|
||||
if (!fmpq_mat_equal(A, B) || !success1 || !success2)
|
||||
{
|
||||
flint_printf("FAIL!\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
}
|
||||
|
||||
/* Test singular matrices */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
slong n, r, b, d;
|
||||
fmpq_mat_t A, B;
|
||||
fmpz_mat_t M;
|
||||
fmpz_t den;
|
||||
int success;
|
||||
|
||||
n = n_randint(state, 10);
|
||||
|
||||
fmpz_init(den);
|
||||
|
||||
for (r = 0; r < n; r++)
|
||||
{
|
||||
b = 1 + n_randint(state, 10) * n_randint(state, 10);
|
||||
d = n_randint(state, 2*n*n + 1);
|
||||
|
||||
fmpz_mat_init(M, n, n);
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_init(B, n, n);
|
||||
|
||||
fmpz_mat_randrank(M, state, r, b);
|
||||
|
||||
if (i % 2 == 0)
|
||||
fmpz_mat_randops(M, state, d);
|
||||
|
||||
fmpz_randtest_not_zero(den, state, b);
|
||||
fmpq_mat_set_fmpz_mat_div_fmpz(A, M, den);
|
||||
|
||||
success = fmpq_mat_inv(B, A);
|
||||
|
||||
if (success)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("matrix reported as invertible:\n");
|
||||
fmpq_mat_print(A);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mat_clear(M);
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
}
|
||||
|
||||
fmpz_clear(den);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
89
external/flint-2.4.3/fmpq_mat/test/t-is_integral.c
vendored
Normal file
89
external/flint-2.4.3/fmpq_mat/test/t-is_integral.c
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("is_integral....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A;
|
||||
fmpz_mat_t B;
|
||||
slong n, m;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpz_mat_init(B, m, n);
|
||||
|
||||
fmpz_mat_randtest(B, state, 10);
|
||||
fmpq_mat_set_fmpz_mat(A, B);
|
||||
|
||||
if (!fmpq_mat_is_integral(A))
|
||||
{
|
||||
flint_printf("FAIL\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (m && n)
|
||||
{
|
||||
slong i, j;
|
||||
i = n_randint(state, m);
|
||||
j = n_randint(state, n);
|
||||
|
||||
fmpq_set_si(fmpq_mat_entry(A, i, j), 1, 2);
|
||||
|
||||
if (fmpq_mat_is_integral(A))
|
||||
{
|
||||
flint_printf("FAIL\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpz_mat_clear(B);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
92
external/flint-2.4.3/fmpq_mat/test/t-mul.c
vendored
Normal file
92
external/flint-2.4.3/fmpq_mat/test/t-mul.c
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("mul....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C, D;
|
||||
|
||||
slong m, n, k, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
k = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, k);
|
||||
fmpq_mat_init(B, k, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
fmpq_mat_init(D, m, n);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpq_mat_randtest(C, state, bits); /* noise in output */
|
||||
|
||||
fmpq_mat_mul_direct(C, A, B);
|
||||
fmpq_mat_mul_cleared(D, A, B);
|
||||
|
||||
result = fmpq_mat_equal(C, D);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
flint_printf("D:\n");
|
||||
fmpq_mat_print(D);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
fmpq_mat_clear(D);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
118
external/flint-2.4.3/fmpq_mat/test/t-neg.c
vendored
Normal file
118
external/flint-2.4.3/fmpq_mat/test/t-neg.c
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("neg....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Aliasing */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
|
||||
fmpq_mat_neg(A, B);
|
||||
fmpq_mat_neg(B, B);
|
||||
|
||||
result = fmpq_mat_equal(A, B);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
}
|
||||
|
||||
/* --A == A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
|
||||
fmpq_mat_neg(A, B);
|
||||
fmpq_mat_neg(A, A);
|
||||
|
||||
result = fmpq_mat_equal(A, B);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
91
external/flint-2.4.3/fmpq_mat/test/t-one.c
vendored
Normal file
91
external/flint-2.4.3/fmpq_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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("one....");
|
||||
fflush(stdout);
|
||||
|
||||
/* 1 * A == A * 1 == A */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C, I;
|
||||
|
||||
slong n, bits;
|
||||
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_init(B, n, n);
|
||||
fmpq_mat_init(C, n, n);
|
||||
fmpq_mat_init(I, n, n);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_one(I);
|
||||
|
||||
fmpq_mat_mul(B, I, A);
|
||||
fmpq_mat_mul(C, A, I);
|
||||
|
||||
result = fmpq_mat_equal(A, B) && fmpq_mat_equal(A, C);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
flint_printf("I:\n");
|
||||
fmpq_mat_print(I);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
fmpq_mat_clear(I);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
117
external/flint-2.4.3/fmpq_mat/test/t-rref.c
vendored
Normal file
117
external/flint-2.4.3/fmpq_mat/test/t-rref.c
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("rref....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
|
||||
{
|
||||
slong m, n, r, rank, b, d;
|
||||
fmpq_mat_t A, B, C;
|
||||
fmpz_mat_t M;
|
||||
fmpz_t den;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
fmpz_init(den);
|
||||
|
||||
for (r = 0; r <= FLINT_MIN(m,n); r++)
|
||||
{
|
||||
b = 1 + n_randint(state, 10) * n_randint(state, 10);
|
||||
d = n_randint(state, 2*m*n + 1);
|
||||
|
||||
fmpz_mat_init(M, m, n);
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
|
||||
fmpz_mat_randrank(M, state, r, b);
|
||||
|
||||
if (i % 2 == 0)
|
||||
fmpz_mat_randops(M, state, d);
|
||||
|
||||
fmpz_randtest_not_zero(den, state, b);
|
||||
fmpq_mat_set_fmpz_mat_div_fmpz(A, M, den);
|
||||
|
||||
rank = fmpq_mat_rref_classical(B, A);
|
||||
if (r != rank)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("fmpq_mat_rref_classical: wrong rank!\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("\nrank: %wd computed: %wd\n", r, rank);
|
||||
abort();
|
||||
}
|
||||
|
||||
rank = fmpq_mat_rref_fraction_free(C, A);
|
||||
if (r != rank)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("fmpq_mat_rref_fraction_free: wrong rank!\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (!fmpq_mat_equal(B, C))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("different results!\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("\nB:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("\nC:\n");
|
||||
fmpq_mat_print(C);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mat_clear(M);
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
}
|
||||
|
||||
fmpz_clear(den);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
131
external/flint-2.4.3/fmpq_mat/test/t-scalar_div_fmpz.c
vendored
Normal file
131
external/flint-2.4.3/fmpq_mat/test/t-scalar_div_fmpz.c
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("scalar_div_fmpz....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Aliasing */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B;
|
||||
fmpz_t x;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpz_init(x);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpz_randtest_not_zero(x, state, bits);
|
||||
|
||||
fmpq_mat_scalar_div_fmpz(A, B, x);
|
||||
fmpq_mat_scalar_div_fmpz(B, B, x);
|
||||
|
||||
result = fmpq_mat_equal(A, B);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n"), fmpq_mat_print(A);
|
||||
flint_printf("B:\n"), fmpq_mat_print(B);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpz_clear(x);
|
||||
}
|
||||
|
||||
/* (A + B) / x == A / x + B / x */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C, D;
|
||||
fmpz_t x;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
fmpq_mat_init(D, m, n);
|
||||
fmpz_init(x);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpz_randtest_not_zero(x, state, bits);
|
||||
|
||||
fmpq_mat_scalar_div_fmpz(C, A, x);
|
||||
fmpq_mat_scalar_div_fmpz(D, B, x);
|
||||
fmpq_mat_add(D, C, D);
|
||||
|
||||
fmpq_mat_add(C, A, B);
|
||||
fmpq_mat_scalar_div_fmpz(C, C, x);
|
||||
|
||||
result = fmpq_mat_equal(C, D);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n"), fmpq_mat_print(A);
|
||||
flint_printf("B:\n"), fmpq_mat_print(B);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
fmpq_mat_clear(D);
|
||||
fmpz_clear(x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
131
external/flint-2.4.3/fmpq_mat/test/t-scalar_mul_fmpz.c
vendored
Normal file
131
external/flint-2.4.3/fmpq_mat/test/t-scalar_mul_fmpz.c
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("scalar_mul_fmpz....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Aliasing */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B;
|
||||
fmpz_t x;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpz_init(x);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpz_randtest(x, state, bits);
|
||||
|
||||
fmpq_mat_scalar_mul_fmpz(A, B, x);
|
||||
fmpq_mat_scalar_mul_fmpz(B, B, x);
|
||||
|
||||
result = fmpq_mat_equal(A, B);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n"), fmpq_mat_print(A);
|
||||
flint_printf("B:\n"), fmpq_mat_print(B);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpz_clear(x);
|
||||
}
|
||||
|
||||
/* (A + B) * x == A * x + B * x */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C, D;
|
||||
fmpz_t x;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
fmpq_mat_init(D, m, n);
|
||||
fmpz_init(x);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpz_randtest(x, state, bits);
|
||||
|
||||
fmpq_mat_scalar_mul_fmpz(C, A, x);
|
||||
fmpq_mat_scalar_mul_fmpz(D, B, x);
|
||||
fmpq_mat_add(D, C, D);
|
||||
|
||||
fmpq_mat_add(C, A, B);
|
||||
fmpq_mat_scalar_mul_fmpz(C, C, x);
|
||||
|
||||
result = fmpq_mat_equal(C, D);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("A:\n"), fmpq_mat_print(A);
|
||||
flint_printf("B:\n"), fmpq_mat_print(B);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
fmpq_mat_clear(D);
|
||||
fmpz_clear(x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
142
external/flint-2.4.3/fmpq_mat/test/t-solve_dixon.c
vendored
Normal file
142
external/flint-2.4.3/fmpq_mat/test/t-solve_dixon.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 <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("solve_dixon....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Solve nonsingular systems */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, X, AX;
|
||||
fmpq_t d;
|
||||
int success;
|
||||
slong n, m, bits;
|
||||
|
||||
n = n_randint(state, 10);
|
||||
m = n_randint(state, 10);
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_init(B, n, m);
|
||||
fmpq_mat_init(X, n, m);
|
||||
fmpq_mat_init(AX, n, m);
|
||||
|
||||
fmpq_init(d);
|
||||
/* XXX: replace with a randtest function */
|
||||
do {
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_det(d, A);
|
||||
} while (fmpq_is_zero(d));
|
||||
fmpq_clear(d);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
|
||||
success = fmpq_mat_solve_dixon(X, A, B);
|
||||
fmpq_mat_mul(AX, A, X);
|
||||
|
||||
if (!fmpq_mat_equal(AX, B) || !success)
|
||||
{
|
||||
flint_printf("FAIL!\n");
|
||||
flint_printf("success: %d\n", success);
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("X:\n");
|
||||
fmpq_mat_print(X);
|
||||
flint_printf("AX:\n");
|
||||
fmpq_mat_print(AX);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(X);
|
||||
fmpq_mat_clear(AX);
|
||||
}
|
||||
|
||||
/* Check singular systems */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, X;
|
||||
fmpz_mat_t M;
|
||||
fmpz_t den;
|
||||
slong n, m, bits;
|
||||
int success;
|
||||
|
||||
n = 1 + n_randint(state, 10);
|
||||
m = 1 + n_randint(state, 10);
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpz_init(den);
|
||||
fmpz_mat_init(M, n, n);
|
||||
fmpz_mat_randrank(M, state, n_randint(state, n), bits);
|
||||
if (i % 2)
|
||||
fmpz_mat_randops(M, state, n_randint(state, 2*m*n + 1));
|
||||
fmpz_randtest_not_zero(den, state, bits);
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_set_fmpz_mat_div_fmpz(A, M, den);
|
||||
|
||||
fmpq_mat_init(B, n, m);
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpq_mat_init(X, n, m);
|
||||
|
||||
success = fmpq_mat_solve_dixon(X, A, B);
|
||||
|
||||
if (success != 0)
|
||||
{
|
||||
flint_printf("FAIL!\n");
|
||||
flint_printf("Expected success = 0\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(X);
|
||||
fmpz_mat_clear(M);
|
||||
fmpz_clear(den);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
143
external/flint-2.4.3/fmpq_mat/test/t-solve_fraction_free.c
vendored
Normal file
143
external/flint-2.4.3/fmpq_mat/test/t-solve_fraction_free.c
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("solve_fraction_free....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, X, AX;
|
||||
fmpq_t d;
|
||||
int success;
|
||||
|
||||
slong n, m, bits;
|
||||
|
||||
n = n_randint(state, 10);
|
||||
m = n_randint(state, 10);
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_init(B, n, m);
|
||||
fmpq_mat_init(X, n, m);
|
||||
fmpq_mat_init(AX, n, m);
|
||||
|
||||
fmpq_init(d);
|
||||
/* XXX: replace with a randtest function */
|
||||
do {
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_det(d, A);
|
||||
} while (fmpq_is_zero(d));
|
||||
fmpq_clear(d);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
|
||||
success = fmpq_mat_solve_fraction_free(X, A, B);
|
||||
fmpq_mat_mul(AX, A, X);
|
||||
|
||||
if (!fmpq_mat_equal(AX, B) || !success)
|
||||
{
|
||||
flint_printf("FAIL!\n");
|
||||
flint_printf("success: %d\n", success);
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("X:\n");
|
||||
fmpq_mat_print(X);
|
||||
flint_printf("AX:\n");
|
||||
fmpq_mat_print(AX);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(X);
|
||||
fmpq_mat_clear(AX);
|
||||
}
|
||||
|
||||
/* Check singular systems */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, X;
|
||||
fmpz_mat_t M;
|
||||
fmpz_t den;
|
||||
slong n, m, bits;
|
||||
int success;
|
||||
|
||||
n = 1 + n_randint(state, 10);
|
||||
m = 1 + n_randint(state, 10);
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpz_init(den);
|
||||
fmpz_mat_init(M, n, n);
|
||||
fmpz_mat_randrank(M, state, n_randint(state, n), bits);
|
||||
if (i % 2)
|
||||
fmpz_mat_randops(M, state, n_randint(state, 2*m*n + 1));
|
||||
fmpz_randtest_not_zero(den, state, bits);
|
||||
fmpq_mat_init(A, n, n);
|
||||
fmpq_mat_set_fmpz_mat_div_fmpz(A, M, den);
|
||||
|
||||
fmpq_mat_init(B, n, m);
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpq_mat_init(X, n, m);
|
||||
|
||||
success = fmpq_mat_solve_fraction_free(X, A, B);
|
||||
|
||||
if (success != 0)
|
||||
{
|
||||
flint_printf("FAIL!\n");
|
||||
flint_printf("Expected success = 0\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(X);
|
||||
fmpz_mat_clear(M);
|
||||
fmpz_clear(den);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
173
external/flint-2.4.3/fmpq_mat/test/t-sub.c
vendored
Normal file
173
external/flint-2.4.3/fmpq_mat/test/t-sub.c
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("sub....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Aliasing, B = B - C */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpq_mat_randtest(C, state, bits);
|
||||
|
||||
fmpq_mat_sub(A, B, C);
|
||||
fmpq_mat_sub(B, B, C);
|
||||
|
||||
result = fmpq_mat_equal(A, B);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (B = B - C):\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
}
|
||||
|
||||
/* Aliasing, C = B - C */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
fmpq_mat_randtest(C, state, bits);
|
||||
|
||||
fmpq_mat_sub(A, B, C);
|
||||
fmpq_mat_sub(C, B, C);
|
||||
|
||||
result = fmpq_mat_equal(A, C);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (C = B - C):\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
}
|
||||
|
||||
/* A - B == -(B - A) */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C, D;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
fmpq_mat_init(D, m, n);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_randtest(B, state, bits);
|
||||
|
||||
fmpq_mat_sub(C, A, B);
|
||||
fmpq_mat_sub(D, B, A);
|
||||
fmpq_mat_neg(D, D);
|
||||
|
||||
result = fmpq_mat_equal(C, D);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (A + B == B + A):\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
flint_printf("D:\n");
|
||||
fmpq_mat_print(D);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
fmpq_mat_clear(D);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
96
external/flint-2.4.3/fmpq_mat/test/t-trace.c
vendored
Normal file
96
external/flint-2.4.3/fmpq_mat/test/t-trace.c
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq.h"
|
||||
#include "fmpq_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++)
|
||||
{
|
||||
fmpq_mat_t A, B, AB, BA;
|
||||
fmpq_t trab, trba;
|
||||
slong m, n;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, n, m);
|
||||
fmpq_mat_init(AB, m, m);
|
||||
fmpq_mat_init(BA, n, n);
|
||||
|
||||
fmpq_init(trab);
|
||||
fmpq_init(trba);
|
||||
|
||||
fmpq_mat_randtest(A, state, 1 + n_randint(state, 100));
|
||||
fmpq_mat_randtest(B, state, 1 + n_randint(state, 100));
|
||||
|
||||
fmpq_mat_mul(AB, A, B);
|
||||
fmpq_mat_mul(BA, B, A);
|
||||
|
||||
fmpq_mat_trace(trab, AB);
|
||||
fmpq_mat_trace(trba, BA);
|
||||
|
||||
if (!fmpq_equal(trab, trba))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpq_mat_print(A), flint_printf("\n");
|
||||
fmpq_mat_print(B), flint_printf("\n");
|
||||
fmpq_mat_print(AB), flint_printf("\n");
|
||||
fmpq_mat_print(BA), flint_printf("\n");
|
||||
flint_printf("tr(AB): "), fmpq_print(trab), flint_printf("\n");
|
||||
flint_printf("tr(BA): "), fmpq_print(trba), flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(AB);
|
||||
fmpq_mat_clear(BA);
|
||||
fmpq_clear(trab);
|
||||
fmpq_clear(trba);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
124
external/flint-2.4.3/fmpq_mat/test/t-transpose.c
vendored
Normal file
124
external/flint-2.4.3/fmpq_mat/test/t-transpose.c
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpq.h"
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("transpose....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Aliasing, B = B^t */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B, C;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = m;
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
fmpq_mat_init(C, m, n);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
fmpq_mat_set(B, A);
|
||||
|
||||
fmpq_mat_transpose(C, B);
|
||||
fmpq_mat_transpose(B, B);
|
||||
|
||||
result = fmpq_mat_equal(B, C);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (B = B^t):\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
flint_printf("C:\n");
|
||||
fmpq_mat_print(C);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
fmpq_mat_clear(C);
|
||||
}
|
||||
|
||||
/* ((B^t)^t) == B */
|
||||
for (i = 0; i < 100 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpq_mat_t A, B;
|
||||
|
||||
slong m, n, bits;
|
||||
|
||||
m = n_randint(state, 10);
|
||||
n = m;
|
||||
|
||||
bits = 1 + n_randint(state, 100);
|
||||
|
||||
fmpq_mat_init(A, m, n);
|
||||
fmpq_mat_init(B, m, n);
|
||||
|
||||
fmpq_mat_randtest(A, state, bits);
|
||||
|
||||
fmpq_mat_transpose(B, A);
|
||||
fmpq_mat_transpose(B, B);
|
||||
|
||||
result = fmpq_mat_equal(A, B);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL ((B^t)^t == B):\n");
|
||||
flint_printf("A:\n");
|
||||
fmpq_mat_print(A);
|
||||
flint_printf("B:\n");
|
||||
fmpq_mat_print(B);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_mat_clear(A);
|
||||
fmpq_mat_clear(B);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
41
external/flint-2.4.3/fmpq_mat/trace.c
vendored
Normal file
41
external/flint-2.4.3/fmpq_mat/trace.c
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void
|
||||
fmpq_mat_trace(fmpq_t trace, const fmpq_mat_t mat)
|
||||
{
|
||||
slong i, n = fmpq_mat_nrows(mat);
|
||||
|
||||
if (n == 0)
|
||||
fmpq_zero(trace);
|
||||
else
|
||||
{
|
||||
fmpq_set(trace, fmpq_mat_entry(mat, 0, 0));
|
||||
for (i = 1; i < n; i++)
|
||||
fmpq_add(trace, trace, fmpq_mat_entry(mat, i, i));
|
||||
}
|
||||
}
|
||||
47
external/flint-2.4.3/fmpq_mat/transpose.c
vendored
Normal file
47
external/flint-2.4.3/fmpq_mat/transpose.c
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_transpose(fmpq_mat_t rop, const fmpq_mat_t op)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
if (rop == op)
|
||||
{
|
||||
for (i = 0; i < rop->r; i++)
|
||||
for (j = 0; j < i; j++)
|
||||
fmpq_swap(fmpq_mat_entry(rop, i, j),
|
||||
fmpq_mat_entry(rop, j, i));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < rop->r; i++)
|
||||
for (j = 0; j < rop->c; j++)
|
||||
fmpq_set(fmpq_mat_entry(rop, i, j),
|
||||
fmpq_mat_entry(op, j, i));
|
||||
}
|
||||
}
|
||||
|
||||
35
external/flint-2.4.3/fmpq_mat/zero.c
vendored
Normal file
35
external/flint-2.4.3/fmpq_mat/zero.c
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpq_mat.h"
|
||||
|
||||
void fmpq_mat_zero(fmpq_mat_t mat)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
for (i = 0; i < mat->r; i++)
|
||||
for (j = 0; j < mat->c; j++)
|
||||
fmpq_zero(fmpq_mat_entry(mat, i, j));
|
||||
}
|
||||
Reference in New Issue
Block a user