My Project  debian-1:4.1.1-p2+ds-4build3
fac_util.cc
Go to the documentation of this file.
1 /* emacs edit mode for this file is -*- C++ -*- */
2 
3 
4 #include "config.h"
5 
6 
7 #include "cf_assert.h"
8 
9 #include "cf_defs.h"
10 #include "canonicalform.h"
11 #include "cf_iter.h"
12 #include "fac_util.h"
13 
15 
16 static CanonicalForm mappk ( const CanonicalForm& );
17 
19 
20 
22 {
23  p = 0;
24  k = 0;
25  pk = 1;
26  pkhalf = 0;
27 }
28 
29 modpk::modpk( int q, int l )
30 {
31  p = q;
32  k = l;
33  pk = power( CanonicalForm( p ), k );
34  pkhalf = pk / 2;
35 }
36 
37 modpk::modpk( const modpk & m )
38 {
39  p = m.p;
40  k = m.k;
41  pk = m.pk;
42  pkhalf = m.pkhalf;
43 }
44 
45 modpk&
47 {
48  if ( this != &m ) {
49  p = m.p;
50  k = m.k;
51  pk = m.pk;
52  pkhalf = m.pkhalf;
53  }
54  return *this;
55 }
56 
58 modpk::inverse( const CanonicalForm & f, bool symmetric ) const
59 {
60  CanonicalForm u, r0 = this->operator()( f, false ), r1 = pk, q0 = 1, q1 = 0;
61  while ( ( r0 > 0 ) && ( r1 > 0 ) ) {
62  u = r0 / r1;
63  r0 = r0 % r1;
64  q0 = u*q1 + q0;
65  if ( r0 > 0 ) {
66  u = r1 / r0;
67  r1 = r1 % r0;
68  q1 = u*q0 + q1;
69  }
70  }
71  if ( r0 == 0 )
72  return this->operator()( pk-q1, symmetric );
73  else
74  return this->operator()( q0, symmetric );
75 }
76 
78 modpk::operator() ( const CanonicalForm & f, bool symmetric ) const
79 {
80  PKHALF = pkhalf;
81  PK = pk;
82  if ( symmetric )
83  return mapdomain( f, mappksymmetric );
84  else
85  return mapdomain( f, mappk );
86 }
87 
89 replaceLc( const CanonicalForm & f, const CanonicalForm & c )
90 {
91  if ( f.inCoeffDomain() )
92  return c;
93  else
94  return f + ( c - LC( f ) ) * power( f.mvar(), degree( f ) );
95 }
96 
99 {
100  CanonicalForm result = mod( f, PK );
101  if ( result > PKHALF )
102  return result - PK;
103  else
104  return result;
105 }
106 
108 mappk ( const CanonicalForm & f )
109 {
110  return mod( f, PK );
111 }
112 
f
FILE * f
Definition: checklibs.c:9
canonicalform.h
result
return result
Definition: facAbsBiFact.cc:76
mappk
static CanonicalForm mappk(const CanonicalForm &)
Definition: fac_util.cc:108
modpk::operator=
modpk & operator=(const modpk &m)
Definition: fac_util.cc:46
power
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
Definition: canonicalform.cc:1837
modpk::operator()
CanonicalForm operator()(const CanonicalForm &f, bool symmetric=true) const
Definition: fac_util.cc:78
modpk::k
int k
Definition: fac_util.h:28
mod
CF_NO_INLINE CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:564
CanonicalForm
factory's main class
Definition: canonicalform.h:83
modpk::pkhalf
CanonicalForm pkhalf
Definition: fac_util.h:26
replaceLc
CanonicalForm replaceLc(const CanonicalForm &f, const CanonicalForm &c)
Definition: fac_util.cc:89
fac_util.h
modpk::modpk
modpk()
Definition: fac_util.cc:21
cf_defs.h
cf_iter.h
modpk::p
int p
Definition: fac_util.h:27
modpk
class to do operations mod p^k for int's p and k
Definition: fac_util.h:23
PKHALF
static CanonicalForm PKHALF
Definition: fac_util.cc:14
LC
CanonicalForm LC(const CanonicalForm &f)
Definition: canonicalform.h:303
mappksymmetric
static CanonicalForm mappksymmetric(const CanonicalForm &)
Definition: fac_util.cc:98
m
int m
Definition: cfEzgcd.cc:121
modpk::inverse
CanonicalForm inverse(const CanonicalForm &f, bool symmetric=true) const
Definition: fac_util.cc:58
l
int l
Definition: cfEzgcd.cc:93
cf_assert.h
PK
static CanonicalForm PK
Definition: fac_util.cc:14
mapdomain
CanonicalForm mapdomain(const CanonicalForm &f, CanonicalForm(*mf)(const CanonicalForm &))
CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) )
Definition: cf_ops.cc:440
degree
int degree(const CanonicalForm &f)
Definition: canonicalform.h:309
modpk::pk
CanonicalForm pk
Definition: fac_util.h:25