File: solve_fflu_precomp.c

package info (click to toggle)
flint 2.4.4-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,904 kB
  • ctags: 13,326
  • sloc: ansic: 208,848; cpp: 11,358; sh: 564; makefile: 250
file content (103 lines) | stat: -rw-r--r-- 3,097 bytes parent folder | download | duplicates (4)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*=============================================================================

    This file is part of FLINT.

    FLINT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    FLINT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FLINT; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

=============================================================================*/
/******************************************************************************

    Copyright (C) 2010 Fredrik Johansson

******************************************************************************/

#include <stdlib.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
#include "fmpz_poly_mat.h"
#include "perm.h"

#define XX(ii,jj) fmpz_poly_mat_entry(X,(ii),(jj))
#define BB(ii,jj) fmpz_poly_mat_entry(B,(ii),(jj))
#define LU(ii,jj) fmpz_poly_mat_entry(FFLU,(ii),(jj))

void
fmpz_poly_mat_set_perm(fmpz_poly_mat_t X, const slong * perm,
    const fmpz_poly_mat_t B)
{
    if (X == B)
    {
        /* Not implemented */
        abort();
    }
    else
    {
        slong i, j;

        if (perm == NULL)
            abort();

        for (i = 0; i < fmpz_poly_mat_nrows(B); i++)
            for (j = 0; j < fmpz_poly_mat_ncols(B); j++)
                fmpz_poly_set(fmpz_poly_mat_entry(X, i, j),
                              fmpz_poly_mat_entry(B, perm[i], j));
    }
}

void
fmpz_poly_mat_solve_fflu_precomp(fmpz_poly_mat_t X,
                    const slong * perm,
                    const fmpz_poly_mat_t FFLU, const fmpz_poly_mat_t B)
{
    fmpz_poly_t T;
    slong i, j, k, m, n;

    n = X->r;
    m = X->c;

    fmpz_poly_init(T);
    fmpz_poly_mat_set_perm(X, perm, B);

    for (k = 0; k < m; k++)
    {
        /* Fraction-free forward substitution */
        for (i = 0; i < n - 1; i++)
        {
            for (j = i + 1; j < n; j++)
            {
                fmpz_poly_mul(XX(j, k), XX(j, k), LU(i, i));
                fmpz_poly_mul(T, LU(j, i), XX(i, k));
                fmpz_poly_sub(XX(j, k), XX(j, k), T);
                if (i > 0)
                    fmpz_poly_div(XX(j, k), XX(j, k), LU(i-1, i-1));
            }
        }

        /* Fraction-free back substitution */
        for (i = n - 2; i >= 0; i--)
        {
            fmpz_poly_mul(XX(i, k), XX(i, k), LU(n-1, n-1));
            for (j = i + 1; j < n; j++)
            {
                fmpz_poly_mul(T, XX(j, k), LU(i, j));
                fmpz_poly_sub(XX(i, k), XX(i, k), T);
            }
            fmpz_poly_div(XX(i, k), XX(i, k), LU(i, i));
        }
    }

    fmpz_poly_clear(T);
}