1 /*
2     Copyright (C) 2014 Alex J. Best
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 
fmpz_mat_is_in_snf(const fmpz_mat_t A)14 int fmpz_mat_is_in_snf(const fmpz_mat_t A)
15 {
16     slong i, j;
17     for (i = 0; i < A->r; i++)
18     {
19         for (j = 0; j < A->c; j++)
20         {
21             if (i == j)
22             {
23                 if (fmpz_sgn(fmpz_mat_entry(A, i, i)) < 0)
24                     return 0;
25                 if (i > 0)
26                 {
27                     if (!fmpz_is_zero(fmpz_mat_entry(A, i, i)) &&
28                             fmpz_is_zero(fmpz_mat_entry(A, i - 1, i - 1)))
29                         return 0;
30                     if (!fmpz_divisible(fmpz_mat_entry(A, i, i),
31                             fmpz_mat_entry(A, i - 1, i - 1)))
32                         return 0;
33                 }
34             }
35             else if (!fmpz_is_zero(fmpz_mat_entry(A, i, j)))
36                 return 0;
37         }
38     }
39 
40     return 1;
41 }
42