My Project
Loading...
Searching...
No Matches
cf_roots.cc
Go to the documentation of this file.
1//*****************************************************************************
2
3
4#include "config.h"
5
6
7#include "cf_assert.h"
8#include "debug.h"
9
10#include "canonicalform.h"
11#include "cf_util.h"
12#include "imm.h"
13#include "cf_iter.h"
14
15#ifdef HAVE_NTL
16#include "NTLconvert.h"
17#endif
18
19#ifdef HAVE_FLINT
20#include "FLINTconvert.h"
21#endif
22
23#include "cf_roots.h"
24
26{
27 int p= getCharacteristic ();
28 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20503)
29 nmod_poly_t FLINT_f;
31 nmod_poly_factor_t fac;
32 nmod_poly_factor_init(fac);
33 nmod_poly_roots(fac,FLINT_f,0);
34 int *res=NEW_ARRAY(int,1+fac->num);
35
36 int j=1;
37 for(int i=fac->num-1; i>=0;i--)
38 {
39 // root of (linear) factor: -absolute Term
40 if (nmod_poly_length(fac->p+i)==2)
41 {
42 res[j]=p-nmod_poly_get_coeff_ui(fac->p+i,0);
43 j++;
44 }
45 }
46 res[0]=j-1;
47 // cleanup
48 nmod_poly_clear(FLINT_f);
49 nmod_poly_factor_clear(fac);
50 return res;
51 #elif defined(HAVE_NTL)
52 if (fac_NTL_char != p)
53 {
55 zz_p::init (p);
56 }
57 zz_pX NTL_f= convertFacCF2NTLzzpX (f);
58 vec_zz_p roots= FindRoots (NTL_f);
59 int *res=NEW_ARRAY(int,1+roots.length());
60 res[0]=roots.length();
61 for(int i=roots.length()-1;i>=0;i--)
62 {
63 res[i+1]=to_long(rep(roots[i]));
64 }
65 return res;
66 #else
67 factoryError("NTL/FLINT missing: Zp_roots");
68 return NULL;
69 #endif
70}
71
This file defines functions for conversion to FLINT (www.flintlib.org) and back.
zz_pX convertFacCF2NTLzzpX(const CanonicalForm &f)
Definition: NTLconvert.cc:105
VAR long fac_NTL_char
Definition: NTLconvert.cc:46
Conversion to and from NTL.
Header for factory's main class CanonicalForm.
int FACTORY_PUBLIC getCharacteristic()
Definition: cf_char.cc:70
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
assertions for Factory
#define NEW_ARRAY(T, N)
Definition: cf_defs.h:64
Iterators for CanonicalForm's.
int * Zp_roots(const CanonicalForm f)
Definition: cf_roots.cc:25
VAR void(* factoryError)(const char *s)
Definition: cf_util.cc:80
FILE * f
Definition: checklibs.c:9
factory's main class
Definition: canonicalform.h:86
functions to print debug output
CanonicalForm res
Definition: facAbsFact.cc:60
int j
Definition: facHensel.cc:110
convertFacCF2nmod_poly_t(FLINTmipo, M)
nmod_poly_clear(FLINTmipo)
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
#define NULL
Definition: omList.c:12