1 #ifndef CoCoA_DenseUPolyClean_H
2 #define CoCoA_DenseUPolyClean_H
3 
4 //   Copyright (c)  2007  Anna Bigatti
5 
6 //   This file is part of the source of CoCoALib, the CoCoA Library.
7 
8 //   CoCoALib is free software: you can redistribute it and/or modify
9 //   it under the terms of the GNU General Public License as published by
10 //   the Free Software Foundation, either version 3 of the License, or
11 //   (at your option) any later version.
12 
13 //   CoCoALib is distributed in the hope that it will be useful,
14 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //   GNU General Public License for more details.
17 
18 //   You should have received a copy of the GNU General Public License
19 //   along with CoCoALib.  If not, see <http://www.gnu.org/licenses/>.
20 
21 
22 // Header file for the class DenseUPolyClean
23 
24 #include "CoCoA/assert.H"
25 #include "CoCoA/ring.H"
26 
27 #include <iosfwd>
28 // using std::ostream;
29 #include <vector>
30 // using std::vector;
31 
32 
33 namespace CoCoA
34 {
35 
36 
37 /*-- class DenseUPolyClean ----------------------------------------------*/
38 /**
39 
40   \brief Implementation of "clean" univariate polynomials
41 
42   \include DenseUPolyClean.txt
43 */
44 /*-----------------------------------------------------------------*/
45   class DenseUPolyClean
46   {
47   private:
48     const ring myCoeffRingValue;   ///< the ring to which all the coeffs belong
49     long myDegPlus1Value;   ///< always non-negative (zero only if poly is 0?)
50     long mySizeValue;       ///< always non-negative
51     std::vector<RingElem> myCoeffsValue;  ///< vector of coefficients
52 
53   public:
54     DenseUPolyClean(const ring& CoeffRing, long MinCapacity);
55     DenseUPolyClean(const DenseUPolyClean& copy, long MinCapacity);
56     DenseUPolyClean(const DenseUPolyClean& copy); ///< never defined, just to check
57     ~DenseUPolyClean();
58     DenseUPolyClean& operator=(const DenseUPolyClean& rhs);
59     DenseUPolyClean& operator=(const MachineInt& rhs);
60     DenseUPolyClean& operator=(const BigInt& rhs);
61     DenseUPolyClean& operator=(const BigRat& rhs);
62 
myDegPlus1()63     long myDegPlus1() const  { return myDegPlus1Value; }
mySize()64     long mySize() const  { return mySizeValue; }
65 
66     static void ourSwap(DenseUPolyClean&, DenseUPolyClean&);
67     void myAssignZero();
68     void myAssignZeroCoeff(long d); ///< f_d = 0, no check on size
69     void myAssignNonZeroCoeff(ConstRefRingElem c, long d); ///< f_d = c, no check on size
70     void myResize(long NewSize);
71     void myResetDeg(); ///< reset the correct value of deg (assumed to be less than the current value)
72     ConstRefRingElem myCoeff(long d) const;
73 
74     friend ring CoeffRing(const DenseUPolyClean& f);
75     friend long NumTerms(const DenseUPolyClean& f);
76     friend ConstRefRingElem LC(const DenseUPolyClean& f);
77     void myAddMulLM(ConstRefRingElem c, long d, const DenseUPolyClean& g);
78     //    void myAddClear(DenseUPolyClean& g);
79     void myMulByCoeff(ConstRefRingElem rawc);  // EXCEPTION SAFE?
80     void myDivByCoeff(ConstRefRingElem rawc);  // EXCEPTION SAFE?
81     void myMulByXExp(long n);
82     void myMulByXExp(const BigInt& N);
83     void myMulBy1MinusXExp(long n);
84     void myMulBy1MinusXExp(const BigInt& N);
85     void myNegate();
86 
87     friend void add(DenseUPolyClean& lhs, const DenseUPolyClean& g, const DenseUPolyClean& h);
88     friend void sub(DenseUPolyClean& lhs, const DenseUPolyClean& g, const DenseUPolyClean& h);
89     friend bool div(DenseUPolyClean& lhs, const DenseUPolyClean& g, const DenseUPolyClean& h);
90     friend bool IsCompatible(const DenseUPolyClean& f, const DenseUPolyClean& g);
91   };
92 
93   void deriv(DenseUPolyClean& lhs, const DenseUPolyClean&);
94 
95 
96   // Friend functions - must also be declared outside the class (how very tedious).
97   bool IsCompatible(const DenseUPolyClean& f, const DenseUPolyClean& g);
98   long NumTerms(const DenseUPolyClean& f);
99   ConstRefRingElem LC(const DenseUPolyClean& f);
100   void add(DenseUPolyClean& lhs, const DenseUPolyClean& g, const DenseUPolyClean& h);
101   void sub(DenseUPolyClean& lhs, const DenseUPolyClean& g, const DenseUPolyClean& h);
102   bool div(DenseUPolyClean& lhs, const DenseUPolyClean& g, const DenseUPolyClean& h);
103   bool IsZero(const DenseUPolyClean& f);
104   bool IsEqual(const DenseUPolyClean& f, const DenseUPolyClean& g);
105   void deriv(DenseUPolyClean& lhs, const DenseUPolyClean& f);
106 
107   // Inline functions.
108 
myCoeff(long d)109   inline ConstRefRingElem DenseUPolyClean::myCoeff(long d) const
110   {
111     return myCoeffsValue[d];
112   }
113 
114 
swap(DenseUPolyClean & f,DenseUPolyClean & g)115   inline void swap(DenseUPolyClean& f, DenseUPolyClean& g)
116   {
117     DenseUPolyClean::ourSwap(f, g);
118   }
119 
120 } // end of namespace CoCoA
121 
122 
123 // RCS header/log in the next few lines
124 // $Header: /Volumes/Home_1/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/DenseUPolyClean.H,v 1.18 2015/04/24 15:40:59 bigatti Exp $
125 // $Log: DenseUPolyClean.H,v $
126 // Revision 1.18  2015/04/24 15:40:59  bigatti
127 // -- renamed: myAddMul --> myAddMulLM
128 // -- renamed: myMoveLM --> myMoveLMToFront
129 // -- new myMoveLMToBack (used in ReductionCog --> bug in test-TmpMorseGraph??)
130 //
131 // Revision 1.17  2013/05/28 17:08:43  abbott
132 // A fair amount of cleaning (needs more, but it's not urgent).
133 //
134 // Revision 1.16  2013/05/22 13:25:49  bigatti
135 // -- removed CoeffRing and StdDeg from .H file (confusing with code for rings)
136 //
137 // Revision 1.15  2013/05/20 15:56:10  abbott
138 // Added new fns CoeffRing and StdDeg.
139 // Added impls for deriv, NumTerms, IsMonomial.
140 //
141 // Revision 1.14  2013/04/17 16:30:28  abbott
142 // Replaced size_t by long.
143 //
144 // Revision 1.13  2013/03/15 17:50:39  abbott
145 // Changed int parameter into long.
146 //
147 // Revision 1.12  2011/11/09 13:38:31  bigatti
148 // -- renamed MachineInteger --> MachineInt
149 //
150 // Revision 1.11  2011/08/24 10:20:28  bigatti
151 // -- renamed QQ --> BigRat
152 //
153 // Revision 1.10  2011/08/14 15:52:18  abbott
154 // Changed ZZ into BigInt (phase 1: just the library sources).
155 //
156 // Revision 1.9  2009/10/28 16:47:01  bigatti
157 // -- removed useless include MemPool.H
158 //
159 // Revision 1.8  2008/12/17 12:11:52  abbott
160 // Changed type from long to MachineInt in operations which use a machine integer
161 // in place of a RingElem.  The change is "superficial" but affects many files.
162 //
163 // Revision 1.7  2008/04/21 12:32:54  abbott
164 // Corrected size_t into std::size_t in several header files; in some cases,
165 // replaced size_t with MachineInt (with consequent changes to impl files).
166 //
167 // Revision 1.6  2008/01/29 16:38:47  bigatti
168 // -- changed: inlined myDegPlus1() and mySize()
169 //
170 // Revision 1.5  2007/11/29 17:43:58  bigatti
171 // -- fixed  operator=  which used automatic copy-ctor
172 // -- copy-ctor declared but not defined for checking
173 //
174 // Revision 1.4  2007/10/30 17:14:12  abbott
175 // Changed licence from GPL-2 only to GPL-3 or later.
176 // New version for such an important change.
177 //
178 // Revision 1.3  2007/10/19 10:04:23  bigatti
179 // -- RingDenseUPolyClean now allow to specify the MinCapacity for all
180 //    coeff vectors (to avoid too many reallocations)
181 //
182 // Revision 1.2  2007/10/10 14:02:37  bigatti
183 // -- added myMulBy1MinusXExp
184 // -- fixed a few little bugs
185 //
186 // Revision 1.1  2007/10/05 15:28:56  bigatti
187 // -- added abstract class DenseUPolyRing for representing dense
188 //    univariate polynomials
189 // -- added concrete class RingDenseUPolyClean, the cleanest
190 //    implementation
191 // -- just for testing, still horribly inefficient and incomplete
192 //
193 
194 #endif
195