My Project
Functions
facIrredTest.cc File Reference

This file implements a probabilistic irreducibility test for polynomials over Z/p. More...

#include "config.h"
#include <cmath>
#include "facIrredTest.h"
#include "cf_map.h"
#include "cf_random.h"

Go to the source code of this file.

Functions

double numZeros (const CanonicalForm &F, int k)
 evaluate F at k random points in Z/p^n and count the number of zeros that occur More...
 
double inverseERF (double d)
 
int probIrredTest (const CanonicalForm &F, double error)
 given some error probIrredTest detects irreducibility or reducibility of F with confidence level 1-error More...
 

Detailed Description

This file implements a probabilistic irreducibility test for polynomials over Z/p.

Author
Martin Lee

Definition in file facIrredTest.cc.

Function Documentation

◆ inverseERF()

double inverseERF ( double  d)

Definition at line 42 of file facIrredTest.cc.

43{
44 double pi= 3.141592653589793;
45 double a= 0.140012288;
46
47 double buf1;
48 double buf= 2.0/(pi*a)+log (1.0-d*d)/2.0;
49 buf1= buf;
50 buf *= buf;
51 buf -= log (1.0-d*d)/a;
52 buf= sqrt (buf);
53 buf -= buf1;
54 buf= sqrt (buf);
55
56 if (d < 0)
57 buf= -buf;
58
59 return buf;
60}
CanonicalForm buf1
Definition: facFqBivar.cc:73
#define pi
Definition: libparse.cc:1145
gmp_float sqrt(const gmp_float &a)
Definition: mpr_complex.cc:327
gmp_float log(const gmp_float &a)
Definition: mpr_complex.cc:343
int status int void * buf
Definition: si_signals.h:59

◆ numZeros()

double numZeros ( const CanonicalForm F,
int  k 
)

evaluate F at k random points in Z/p^n and count the number of zeros that occur

Returns
numZeros returns #zeros/trials
Parameters
[in]Fsome poly over Z/p with n variables
[in]knumber of trials

Definition at line 24 of file facIrredTest.cc.

25{
26 int result= 0;
27
28 FFRandom FFgen;
30 for (int i= 0; i < k; i++)
31 {
32 buf= F;
33 for (int j= F.level(); j > 0; j++)
34 buf= buf (FFgen.generate(), j);
35 if (buf.isZero())
36 result++;
37 }
38
39 return (double) result/k;
40}
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
factory's main class
Definition: canonicalform.h:86
int level() const
level() returns the level of CO.
generate random elements in F_p
Definition: cf_random.h:44
CanonicalForm generate() const
Definition: cf_random.cc:68
return result
Definition: facAbsBiFact.cc:75
int j
Definition: facHensel.cc:110

◆ probIrredTest()

int probIrredTest ( const CanonicalForm F,
double  error 
)

given some error probIrredTest detects irreducibility or reducibility of F with confidence level 1-error

Returns
probIrredTest returns 1 for irreducibility, -1 for reducibility or 0 if the test is not applicable
Parameters
[in]Fsome poly over Z/p
[in]error0 < error < 1

Definition at line 63 of file facIrredTest.cc.

64{
65 CFMap N;
67 int n= G.level();
68 int p= getCharacteristic();
69
70 double sqrtTrials= inverseERF (1-2.0*error)*sqrt (2.0);
71
72 double s= sqrtTrials;
73
74 double pn= pow ((double) p, (double) n);
75 double p1= (double) 1/p;
76 p1= p1*(1.0-p1);
77 p1= p1/(double) pn;
78 p1= sqrt (p1);
79 p1 *= s;
80 p1 += (double) 1/p;
81
82 double p2= (double) (2*p-1)/(p*p);
83 p2= p2*(1-p2);
84 p2= p2/(double) pn;
85 p2= sqrt (p2);
86 p2 *= s;
87 p2= (double) (2*p - 1)/(p*p)-p2;
88
89 //no testing possible
90 if (p2 < p1)
91 return 0;
92
93 double den= sqrt (p1*(1-p1))+sqrt (p2*(1-p2));
94 double num= p2-p1;
95
96 sqrtTrials *= den/num;
97
98 int trials= (int) floor (pow (sqrtTrials, 2.0));
99
100 double experimentalNumZeros= numZeros (G, trials);
101
102 double pmiddle= sqrt (p1*p2);
103
104 num= den;
105 den= sqrt (p1*(1.0-p2))+sqrt (p2*(1.0-p1));
106 pmiddle *= (den/num);
107
108 if (experimentalNumZeros < pmiddle)
109 return 1;
110 else
111 return -1;
112}
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:411
CanonicalForm num(const CanonicalForm &f)
CanonicalForm den(const CanonicalForm &f)
int FACTORY_PUBLIC getCharacteristic()
Definition: cf_char.cc:70
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
int p
Definition: cfModGcd.cc:4078
CanonicalForm compress(const CanonicalForm &f, CFMap &m)
CanonicalForm compress ( const CanonicalForm & f, CFMap & m )
Definition: cf_map.cc:210
class CFMap
Definition: cf_map.h:85
void error(const char *fmt,...)
Definition: emacs.cc:55
const CanonicalForm int s
Definition: facAbsFact.cc:51
double numZeros(const CanonicalForm &F, int k)
evaluate F at k random points in Z/p^n and count the number of zeros that occur
Definition: facIrredTest.cc:24
double inverseERF(double d)
Definition: facIrredTest.cc:42
STATIC_VAR TreeM * G
Definition: janet.cc:31
const signed long floor(const ampf< Precision > &x)
Definition: amp.h:773