int fmpz_mat_solve_fflu(fmpz_mat_t X, fmpz_t den, const fmpz_mat_t A, const fmpz_mat_t B) { fmpz_mat_t LU; long dim, *perm; int result; if (fmpz_mat_is_empty(A) || fmpz_mat_is_empty(B)) { fmpz_one(den); return 1; } dim = fmpz_mat_nrows(A); perm = _perm_init(dim); fmpz_mat_init_set(LU, A); result = (fmpz_mat_fflu(LU, den, perm, LU, 1) == dim); if (result) fmpz_mat_solve_fflu_precomp(X, perm, LU, B); else fmpz_zero(den); _perm_clear(perm); fmpz_mat_clear(LU); return result; }
int fmpz_mat_solve_cramer(fmpz_mat_t X, fmpz_t den, const fmpz_mat_t A, const fmpz_mat_t B) { long i, dim = fmpz_mat_nrows(A); if (dim == 0) { fmpz_one(den); return 1; } else if (dim == 1) { fmpz_set(den, fmpz_mat_entry(A, 0, 0)); if (fmpz_is_zero(den)) return 0; if (!fmpz_mat_is_empty(B)) _fmpz_vec_set(X->rows[0], B->rows[0], fmpz_mat_ncols(B)); return 1; } else if (dim == 2) { fmpz_t t, u; _fmpz_mat_det_cofactor_2x2(den, A->rows); if (fmpz_is_zero(den)) return 0; fmpz_init(t); fmpz_init(u); for (i = 0; i < fmpz_mat_ncols(B); i++) { fmpz_mul (t, fmpz_mat_entry(A, 1, 1), fmpz_mat_entry(B, 0, i)); fmpz_submul(t, fmpz_mat_entry(A, 0, 1), fmpz_mat_entry(B, 1, i)); fmpz_mul (u, fmpz_mat_entry(A, 0, 0), fmpz_mat_entry(B, 1, i)); fmpz_submul(u, fmpz_mat_entry(A, 1, 0), fmpz_mat_entry(B, 0, i)); fmpz_swap(fmpz_mat_entry(X, 0, i), t); fmpz_swap(fmpz_mat_entry(X, 1, i), u); } fmpz_clear(t); fmpz_clear(u); return 1; } else if (dim == 3) { return _fmpz_mat_solve_cramer_3x3(X, den, A, B); } else { printf("Exception: fmpz_mat_solve_cramer: dim > 3 not implemented"); abort(); } }
void arith_stirling_matrix_1(fmpz_mat_t mat) { slong n; if (fmpz_mat_is_empty(mat)) return; for (n = 0; n < mat->r; n++) arith_stirling_number_1_vec_next(mat->rows[n], mat->rows[n - (n != 0)], n, mat->c); }
void dgsl_mp_clear(dgsl_mp_t *self) { if (!self) return; _fmpz_vec_clear(self->c_z, fmpz_mat_ncols(self->B)); _mpfr_vec_clear(self->c, fmpz_mat_ncols(self->B)); if (!fmpz_mat_is_empty(self->B)) { fmpz_mat_clear(self->B); } if (!mpfr_mat_is_empty(self->G)) { mpfr_mat_clear(self->G); } if(self->call == dgsl_mp_call_identity) { if(self->D) { dgs_disc_gauss_mp_clear(self->D[0]); free(self->D); } } mpfr_clear(self->sigma); free(self); }