File: fmpz_poly_factorxx.h

package info (click to toggle)
flint 2.5.2-19
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 30,308 kB
  • sloc: ansic: 289,367; cpp: 11,210; python: 1,280; sh: 649; makefile: 283
file content (157 lines) | stat: -rw-r--r-- 5,404 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*=============================================================================

    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) 2013 Tom Bachmann

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

#ifndef FMPZ_POLY_FACTORXX_H
#define FMPZ_POLY_FACTORXX_H


#include "fmpz_poly.h"
#include "nmod_polyxx.h"

namespace flint {
class fmpz_poly_factorxx
{
private:
    fmpz_poly_factor_t inner;

public:
    fmpz_poly_factorxx() {fmpz_poly_factor_init(inner);}
    explicit fmpz_poly_factorxx(slong alloc)
        {fmpz_poly_factor_init2(inner, alloc);}
    ~fmpz_poly_factorxx() {fmpz_poly_factor_clear(inner);}

    fmpz_poly_factorxx(const fmpz_poly_factorxx& o)
    {
        fmpz_poly_factor_init2(inner, o.size());
        fmpz_poly_factor_set(inner, o.inner);
    }

    bool operator==(const fmpz_poly_factorxx& o)
    {
        if(o.content() != content() || o.size() != size())
            return false;
        for(ulong i = 0;i < size();++i)
            if(p(i) != o.p(i) || exp(i) != o.exp(i))
            return false;
        return true;
    }

    fmpz_poly_factorxx& operator=(const fmpz_poly_factorxx& o)
    {
        fmpz_poly_factor_set(inner, o.inner);
        return *this;
    }

    ulong size() const {return inner->num;}
    slong exp(slong i) const {return inner->exp[i];}
    slong& exp(slong i) {return inner->exp[i];}
    fmpz_polyxx_srcref p(slong i) const
        {return fmpz_polyxx_srcref::make(inner->p + i);}
    fmpz_polyxx_ref p(slong i) {return fmpz_polyxx_ref::make(inner->p + i);}
    fmpzxx_srcref content() const
        {return fmpzxx_srcref::make(& inner->c);}
    fmpzxx_ref content() {return fmpzxx_ref::make(& inner->c);}

    fmpz_poly_factor_t& _data() {return inner;}
    const fmpz_poly_factor_t& _data() const {return inner;}

    void realloc(slong a) {fmpz_poly_factor_realloc(inner, a);}
    void fit_length(slong a) {fmpz_poly_factor_fit_length(inner, a);}

    void print() const {fmpz_poly_factor_print(inner);}

    template<class Fmpz_poly>
    void insert(const Fmpz_poly& p, slong e,
            typename mp::enable_if<traits::is_fmpz_polyxx<Fmpz_poly> >::type* = 0)
        {fmpz_poly_factor_insert(_data(), p.evaluate()._poly(), e);}

    void concat(const fmpz_poly_factorxx& o)
        {fmpz_poly_factor_concat(_data(), o._data());}

    template<class Fmpz_poly>
    void set_factor_squarefree(const Fmpz_poly& p,
            typename mp::enable_if<traits::is_fmpz_polyxx<Fmpz_poly> >::type* = 0)
        {fmpz_poly_factor_squarefree(_data(), p.evaluate()._poly());}

    template<class Fmpz_poly, class Fmpz>
    void set_factor_zassenhaus_recombination(
            const fmpz_poly_factorxx& lifted_fac, const Fmpz_poly& F,
            const Fmpz& P, slong exp,
            typename mp::enable_if<traits::is_fmpz_polyxx<Fmpz_poly> >::type* = 0,
            typename mp::enable_if<traits::is_fmpzxx<Fmpz> >::type* = 0)
    {
        fmpz_poly_factor_zassenhaus_recombination(_data(), lifted_fac._data(),
                F.evaluate()._poly(), P.evaluate()._fmpz(), exp);
    }

    template<class Fmpz_poly>
    void set_factor_zassenhaus(const Fmpz_poly& p,
            typename mp::enable_if<traits::is_fmpz_polyxx<Fmpz_poly> >::type* = 0)
        {fmpz_poly_factor_zassenhaus(_data(), p.evaluate()._poly());}

    template<class Fmpz_poly>
    void set_hensel_lift_once(const Fmpz_poly& f,
            const nmod_poly_factorxx& local_fac, slong N,
            typename mp::enable_if<traits::is_fmpz_polyxx<Fmpz_poly> >::type* = 0)
    {
        fmpz_poly_hensel_lift_once(_data(), f.evaluate()._poly(),
                local_fac._data(), N);
    }
};

template<class Fmpz_poly>
inline fmpz_poly_factorxx factor_squarefree(const Fmpz_poly& p,
        typename mp::enable_if<traits::is_fmpz_polyxx<Fmpz_poly> >* = 0)
{
    fmpz_poly_factorxx res;
    res.set_factor_squarefree(p);
    return res;
}
template<class Fmpz_poly>
inline fmpz_poly_factorxx factor_zassenhaus(const Fmpz_poly& p,
        typename mp::enable_if<traits::is_fmpz_polyxx<Fmpz_poly> >* = 0)
{
    fmpz_poly_factorxx res;
    res.set_factor_zassenhaus(p);
    return res;
}

template<class Fmpz_poly>
inline fmpz_poly_factorxx hensel_lift_once(const Fmpz_poly& f,
        const nmod_poly_factorxx& local_fac, slong N,
        typename mp::enable_if<traits::is_fmpz_polyxx<Fmpz_poly> >* = 0)
{
    fmpz_poly_factorxx res;
    res.set_hensel_lift_once(f, local_fac, N);
    return res;
}

inline void print(const fmpz_poly_factorxx& f)
{
    f.print();
}
} // flint

#endif