1 /*
2 Copyright (C) 2011 Fredrik Johansson
3
4 This file is part of FLINT.
5
6 FLINT is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <http://www.gnu.org/licenses/>.
10 */
11
12 #include "fmpz_mat.h"
13
14 void
fmpz_mat_CRT_ui(fmpz_mat_t res,const fmpz_mat_t mat1,const fmpz_t m1,const nmod_mat_t mat2,int sign)15 fmpz_mat_CRT_ui(fmpz_mat_t res, const fmpz_mat_t mat1,
16 const fmpz_t m1, const nmod_mat_t mat2, int sign)
17 {
18 slong i, j;
19 mp_limb_t c;
20 mp_limb_t m2 = mat2->mod.n;
21 mp_limb_t m2inv = mat2->mod.ninv;
22 fmpz_t m1m2;
23
24 c = fmpz_fdiv_ui(m1, m2);
25 c = n_invmod(c, m2);
26
27 if (c == 0)
28 {
29 flint_printf("Exception (fmpz_mat_CRT_ui). m1 not invertible modulo m2.\n");
30 flint_abort();
31 }
32
33 fmpz_init(m1m2);
34 fmpz_mul_ui(m1m2, m1, m2);
35
36 for (i = 0; i < mat1->r; i++)
37 {
38 for (j = 0; j < mat1->c; j++)
39 _fmpz_CRT_ui_precomp(fmpz_mat_entry(res, i, j),
40 fmpz_mat_entry(mat1, i, j), m1,
41 nmod_mat_entry(mat2, i, j), m2, m2inv, m1m2, c, sign);
42 }
43
44 fmpz_clear(m1m2);
45 }
46
47