arb/acb_mat.h

429 lines
12 KiB
C
Raw Normal View History

/*
2014-05-15 19:56:11 +02:00
Copyright (C) 2012 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
2014-05-15 19:56:11 +02:00
#ifndef ACB_MAT_H
#define ACB_MAT_H
2014-12-25 15:50:37 +01:00
#ifdef ACB_MAT_INLINES_C
#define ACB_MAT_INLINE
#else
#define ACB_MAT_INLINE static __inline__
#endif
#include <stdio.h>
2016-03-03 15:42:23 +01:00
#include "flint/fmpz_mat.h"
#include "flint/fmpq_mat.h"
2014-05-15 19:56:11 +02:00
#include "arb.h"
#include "acb.h"
#include "arb_mat.h"
#include "acb_poly.h"
2014-05-15 19:56:11 +02:00
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
acb_ptr entries;
2015-11-06 11:12:43 +00:00
slong r;
slong c;
2014-05-15 19:56:11 +02:00
acb_ptr * rows;
}
acb_mat_struct;
typedef acb_mat_struct acb_mat_t[1];
#define acb_mat_entry(mat,i,j) ((mat)->rows[i] + (j))
#define acb_mat_nrows(mat) ((mat)->r)
#define acb_mat_ncols(mat) ((mat)->c)
2015-10-02 09:46:02 +02:00
ACB_MAT_INLINE acb_ptr
2015-11-06 11:12:43 +00:00
acb_mat_entry_ptr(acb_mat_t mat, slong i, slong j)
2015-10-02 09:46:02 +02:00
{
return acb_mat_entry(mat, i, j);
}
2014-05-15 19:56:11 +02:00
/* Memory management */
2015-11-06 11:12:43 +00:00
void acb_mat_init(acb_mat_t mat, slong r, slong c);
2014-05-15 19:56:11 +02:00
void acb_mat_clear(acb_mat_t mat);
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2014-05-15 19:56:11 +02:00
acb_mat_swap(acb_mat_t mat1, acb_mat_t mat2)
{
acb_mat_struct t = *mat1;
*mat1 = *mat2;
*mat2 = t;
}
2018-07-03 14:17:31 +02:00
/* Window matrices */
void acb_mat_window_init(acb_mat_t window, const acb_mat_t mat, slong r1, slong c1, slong r2, slong c2);
ARB_MAT_INLINE void
acb_mat_window_clear(acb_mat_t window)
{
flint_free(window->rows);
}
2014-05-15 19:56:11 +02:00
/* Conversions */
void acb_mat_set(acb_mat_t dest, const acb_mat_t src);
void acb_mat_set_fmpz_mat(acb_mat_t dest, const fmpz_mat_t src);
2015-11-06 11:12:43 +00:00
void acb_mat_set_round_fmpz_mat(acb_mat_t dest, const fmpz_mat_t src, slong prec);
2015-10-02 09:46:02 +02:00
2015-11-06 11:12:43 +00:00
void acb_mat_set_fmpq_mat(acb_mat_t dest, const fmpq_mat_t src, slong prec);
2014-05-15 19:56:11 +02:00
2015-10-09 15:57:11 +02:00
void acb_mat_set_arb_mat(acb_mat_t dest, const arb_mat_t src);
2015-11-06 11:12:43 +00:00
void acb_mat_set_round_arb_mat(acb_mat_t dest, const arb_mat_t src, slong prec);
2015-10-09 15:57:11 +02:00
/* Random generation */
2015-11-06 11:12:43 +00:00
void acb_mat_randtest(acb_mat_t mat, flint_rand_t state, slong prec, slong mag_bits);
2014-05-15 19:56:11 +02:00
/* I/O */
2015-12-31 18:26:05 -05:00
void acb_mat_fprintd(FILE * file, const acb_mat_t mat, slong digits);
ACB_MAT_INLINE void
acb_mat_printd(const acb_mat_t mat, slong digits)
{
acb_mat_fprintd(stdout, mat, digits);
}
2014-05-15 19:56:11 +02:00
/* Comparisons */
2015-10-09 15:57:11 +02:00
int acb_mat_eq(const acb_mat_t mat1, const acb_mat_t mat2);
int acb_mat_ne(const acb_mat_t mat1, const acb_mat_t mat2);
2014-05-15 19:56:11 +02:00
int acb_mat_equal(const acb_mat_t mat1, const acb_mat_t mat2);
int acb_mat_overlaps(const acb_mat_t mat1, const acb_mat_t mat2);
int acb_mat_contains(const acb_mat_t mat1, const acb_mat_t mat2);
int acb_mat_contains_fmpq_mat(const acb_mat_t mat1, const fmpq_mat_t mat2);
int acb_mat_contains_fmpz_mat(const acb_mat_t mat1, const fmpz_mat_t mat2);
int acb_mat_is_real(const acb_mat_t mat);
ACB_MAT_INLINE int
acb_mat_is_empty(const acb_mat_t mat)
{
return (mat->r == 0) || (mat->c == 0);
}
ACB_MAT_INLINE int
acb_mat_is_square(const acb_mat_t mat)
{
return (mat->r == mat->c);
}
2018-04-10 17:52:06 +02:00
/* Radius and interval operations */
ACB_MAT_INLINE void
acb_mat_get_mid(acb_mat_t B, const acb_mat_t A)
{
slong i, j;
for (i = 0; i < acb_mat_nrows(A); i++)
{
for (j = 0; j < acb_mat_ncols(A); j++)
{
arb_get_mid_arb(acb_realref(acb_mat_entry(B, i, j)), acb_realref(acb_mat_entry(A, i, j)));
arb_get_mid_arb(acb_imagref(acb_mat_entry(B, i, j)), acb_imagref(acb_mat_entry(A, i, j)));
}
}
}
ACB_MAT_INLINE void
acb_mat_add_error_mag(acb_mat_t mat, const mag_t err)
{
slong i, j;
for (i = 0; i < acb_mat_nrows(mat); i++)
for (j = 0; j < acb_mat_ncols(mat); j++)
acb_add_error_mag(acb_mat_entry(mat, i, j), err);
}
2014-05-15 19:56:11 +02:00
/* Special matrices */
void acb_mat_zero(acb_mat_t mat);
void acb_mat_one(acb_mat_t mat);
void acb_mat_ones(acb_mat_t mat);
void acb_mat_dft(acb_mat_t res, int kind, slong prec);
2015-10-02 09:46:02 +02:00
void acb_mat_transpose(acb_mat_t mat1, const acb_mat_t mat2);
void acb_mat_conjugate(acb_mat_t mat1, const acb_mat_t mat2);
ACB_MAT_INLINE void
acb_mat_conjugate_transpose(acb_mat_t mat1, const acb_mat_t mat2)
{
acb_mat_transpose(mat1, mat2);
acb_mat_conjugate(mat1, mat1);
}
2014-05-15 19:56:11 +02:00
/* Norms */
void acb_mat_bound_inf_norm(mag_t b, const acb_mat_t A);
2014-05-15 19:56:11 +02:00
2016-04-06 12:25:57 -04:00
void acb_mat_frobenius_norm(arb_t res, const acb_mat_t A, slong prec);
2016-04-06 11:32:51 -04:00
void acb_mat_bound_frobenius_norm(mag_t b, const acb_mat_t A);
2016-04-05 18:47:36 -04:00
2014-05-15 19:56:11 +02:00
/* Arithmetic */
void acb_mat_neg(acb_mat_t dest, const acb_mat_t src);
2015-11-06 11:12:43 +00:00
void acb_mat_add(acb_mat_t res, const acb_mat_t mat1, const acb_mat_t mat2, slong prec);
2014-05-15 19:56:11 +02:00
2015-11-06 11:12:43 +00:00
void acb_mat_sub(acb_mat_t res, const acb_mat_t mat1, const acb_mat_t mat2, slong prec);
2014-05-15 19:56:11 +02:00
2017-08-01 14:01:05 +02:00
void acb_mat_mul_classical(acb_mat_t res, const acb_mat_t mat1, const acb_mat_t mat2, slong prec);
void acb_mat_mul_threaded(acb_mat_t res, const acb_mat_t mat1, const acb_mat_t mat2, slong prec);
2018-07-02 22:06:53 +02:00
void acb_mat_mul_reorder(acb_mat_t res, const acb_mat_t mat1, const acb_mat_t mat2, slong prec);
void acb_mat_mul(acb_mat_t res, const acb_mat_t mat1, const acb_mat_t mat2, slong prec);
2017-08-01 14:01:05 +02:00
2016-02-23 18:16:20 -05:00
void acb_mat_mul_entrywise(acb_mat_t res, const acb_mat_t mat1, const acb_mat_t mat2, slong prec);
void acb_mat_sqr_classical(acb_mat_t res, const acb_mat_t mat, slong prec);
2015-11-24 11:19:53 -05:00
void acb_mat_sqr(acb_mat_t res, const acb_mat_t mat, slong prec);
2014-05-15 19:56:11 +02:00
2015-11-06 11:12:43 +00:00
void acb_mat_pow_ui(acb_mat_t B, const acb_mat_t A, ulong exp, slong prec);
2014-05-15 19:56:11 +02:00
/* Scalar arithmetic */
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_mul_2exp_si(acb_mat_t B, const acb_mat_t A, slong c)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_mul_2exp_si(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_addmul_si(acb_mat_t B, const acb_mat_t A, slong c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_addmul_si(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_mul_si(acb_mat_t B, const acb_mat_t A, slong c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_mul_si(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_div_si(acb_mat_t B, const acb_mat_t A, slong c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_div_si(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_addmul_fmpz(acb_mat_t B, const acb_mat_t A, const fmpz_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_addmul_fmpz(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_mul_fmpz(acb_mat_t B, const acb_mat_t A, const fmpz_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_mul_fmpz(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_div_fmpz(acb_mat_t B, const acb_mat_t A, const fmpz_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_div_fmpz(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_addmul_acb(acb_mat_t B, const acb_mat_t A, const acb_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_addmul(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_mul_acb(acb_mat_t B, const acb_mat_t A, const acb_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_mul(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_div_acb(acb_mat_t B, const acb_mat_t A, const acb_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_div(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_addmul_arb(acb_mat_t B, const acb_mat_t A, const arb_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_addmul_arb(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_mul_arb(acb_mat_t B, const acb_mat_t A, const arb_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_mul_arb(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_scalar_div_arb(acb_mat_t B, const acb_mat_t A, const arb_t c, slong prec)
2014-05-15 19:56:11 +02:00
{
2015-11-06 11:12:43 +00:00
slong i, j;
2014-05-15 19:56:11 +02:00
for (i = 0; i < acb_mat_nrows(A); i++)
for (j = 0; j < acb_mat_ncols(A); j++)
acb_div_arb(acb_mat_entry(B, i, j), acb_mat_entry(A, i, j), c, prec);
}
/* Solving */
2014-12-25 15:50:37 +01:00
ACB_MAT_INLINE void
2015-11-06 11:12:43 +00:00
acb_mat_swap_rows(acb_mat_t mat, slong * perm, slong r, slong s)
2014-05-15 19:56:11 +02:00
{
if (r != s)
{
acb_ptr u;
2015-11-06 11:12:43 +00:00
slong t;
2014-05-15 19:56:11 +02:00
if (perm != NULL)
{
t = perm[s];
perm[s] = perm[r];
perm[r] = t;
}
u = mat->rows[s];
mat->rows[s] = mat->rows[r];
mat->rows[r] = u;
}
}
2015-11-10 13:41:43 +00:00
slong acb_mat_find_pivot_partial(const acb_mat_t mat,
2015-11-06 11:12:43 +00:00
slong start_row, slong end_row, slong c);
2014-05-15 19:56:11 +02:00
2018-07-03 14:17:31 +02:00
void acb_mat_solve_tril_classical(acb_mat_t X, const acb_mat_t L, const acb_mat_t B, int unit, slong prec);
void acb_mat_solve_tril_recursive(acb_mat_t X, const acb_mat_t L, const acb_mat_t B, int unit, slong prec);
void acb_mat_solve_tril(acb_mat_t X, const acb_mat_t L, const acb_mat_t B, int unit, slong prec);
void acb_mat_solve_triu_classical(acb_mat_t X, const acb_mat_t U, const acb_mat_t B, int unit, slong prec);
void acb_mat_solve_triu_recursive(acb_mat_t X, const acb_mat_t U, const acb_mat_t B, int unit, slong prec);
void acb_mat_solve_triu(acb_mat_t X, const acb_mat_t U, const acb_mat_t B, int unit, slong prec);
int acb_mat_lu_classical(slong * P, acb_mat_t LU, const acb_mat_t A, slong prec);
int acb_mat_lu_recursive(slong * P, acb_mat_t LU, const acb_mat_t A, slong prec);
2015-11-06 11:12:43 +00:00
int acb_mat_lu(slong * P, acb_mat_t LU, const acb_mat_t A, slong prec);
2014-05-15 19:56:11 +02:00
2015-11-06 11:12:43 +00:00
void acb_mat_solve_lu_precomp(acb_mat_t X, const slong * perm,
const acb_mat_t A, const acb_mat_t B, slong prec);
2014-05-15 19:56:11 +02:00
2018-04-10 17:52:06 +02:00
int acb_mat_solve_lu(acb_mat_t X, const acb_mat_t A, const acb_mat_t B, slong prec);
2015-11-06 11:12:43 +00:00
int acb_mat_solve(acb_mat_t X, const acb_mat_t A, const acb_mat_t B, slong prec);
2014-05-15 19:56:11 +02:00
2018-04-10 17:52:06 +02:00
int acb_mat_solve_precond(acb_mat_t X, const acb_mat_t A, const acb_mat_t B, slong prec);
void acb_mat_approx_mul(acb_mat_t C, const acb_mat_t A, const acb_mat_t B, slong prec);
void acb_mat_approx_solve_triu(acb_mat_t X, const acb_mat_t U, const acb_mat_t B, int unit, slong prec);
void acb_mat_approx_solve_tril(acb_mat_t X, const acb_mat_t L, const acb_mat_t B, int unit, slong prec);
2018-04-10 17:52:06 +02:00
int acb_mat_approx_lu(slong * P, acb_mat_t LU, const acb_mat_t A, slong prec);
void acb_mat_approx_solve_lu_precomp(acb_mat_t X, const slong * perm, const acb_mat_t A, const acb_mat_t B, slong prec);
int acb_mat_approx_solve(acb_mat_t X, const acb_mat_t A, const acb_mat_t B, slong prec);
2018-04-10 17:52:06 +02:00
2015-11-06 11:12:43 +00:00
int acb_mat_inv(acb_mat_t X, const acb_mat_t A, slong prec);
2014-05-15 19:56:11 +02:00
void acb_mat_det_lu(acb_t det, const acb_mat_t A, slong prec);
void acb_mat_det_precond(acb_t det, const acb_mat_t A, slong prec);
2015-11-06 11:12:43 +00:00
void acb_mat_det(acb_t det, const acb_mat_t A, slong prec);
2014-05-15 19:56:11 +02:00
/* Special functions */
void acb_mat_exp_taylor_sum(acb_mat_t S, const acb_mat_t A, slong N, slong prec);
2015-11-06 11:12:43 +00:00
void acb_mat_exp(acb_mat_t B, const acb_mat_t A, slong prec);
2014-05-15 19:56:11 +02:00
2015-11-06 11:12:43 +00:00
void _acb_mat_charpoly(acb_ptr cp, const acb_mat_t mat, slong prec);
2015-11-06 11:12:43 +00:00
void acb_mat_charpoly(acb_poly_t cp, const acb_mat_t mat, slong prec);
2015-11-28 16:12:33 -05:00
void acb_mat_trace(acb_t trace, const acb_mat_t mat, slong prec);
ACB_MAT_INLINE slong
acb_mat_allocated_bytes(const acb_mat_t x)
{
return _acb_vec_allocated_bytes(x->entries, x->r * x->c) + x->r * sizeof(acb_ptr);
}
2014-05-15 19:56:11 +02:00
#ifdef __cplusplus
}
#endif
#endif