forked from flintlib/flint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgso.c
86 lines (70 loc) · 2.02 KB
/
gso.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Copyright (C) 2014 Abhinav Baid
This file is part of FLINT.
FLINT 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 <https://www.gnu.org/licenses/>.
*/
#include "fmpq_mat.h"
void
fmpq_mat_gso(fmpq_mat_t B, const fmpq_mat_t A)
{
slong i, j, k;
fmpq_t num, den, mu;
if (B->r != A->r || B->c != A->c)
{
flint_printf("Exception (fmpq_mat_gso). Incompatible dimensions.\n");
flint_abort();
}
if (B == A)
{
fmpq_mat_t t;
fmpq_mat_init(t, B->r, B->c);
fmpq_mat_gso(t, A);
fmpq_mat_swap_entrywise(B, t);
fmpq_mat_clear(t);
return;
}
if (A->r == 0)
{
return;
}
fmpq_init(num);
fmpq_init(den);
fmpq_init(mu);
for (i = 0; i < A->c; i++)
{
for (j = 0; j < A->r; j++)
{
fmpq_set(fmpq_mat_entry(B, j, i), fmpq_mat_entry(A, j, i));
}
for (j = 0; j < i; j++)
{
fmpq_mul(num, fmpq_mat_entry(A, 0, i), fmpq_mat_entry(B, 0, j));
for (k = 1; k < A->r; k++)
{
fmpq_addmul(num,
fmpq_mat_entry(A, k, i), fmpq_mat_entry(B, k, j));
}
fmpq_mul(den, fmpq_mat_entry(B, 0, j), fmpq_mat_entry(B, 0, j));
for (k = 1; k < A->r; k++)
{
fmpq_addmul(den,
fmpq_mat_entry(B, k, j), fmpq_mat_entry(B, k, j));
}
if (!fmpq_is_zero(den))
{
fmpq_div(mu, num, den);
for (k = 0; k < A->r; k++)
{
fmpq_submul(fmpq_mat_entry(B, k, i),
mu, fmpq_mat_entry(B, k, j));
}
}
}
}
fmpq_clear(num);
fmpq_clear(den);
fmpq_clear(mu);
}