OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
LinearFun.h
Go to the documentation of this file.
1 #ifndef CLASSIC_LinearFun_HH
2 #define CLASSIC_LinearFun_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: LinearFun.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: LinearFun<T,N>
13 //
14 // ------------------------------------------------------------------------
15 // Class category: FixedAlgebra
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2000/03/27 09:32:36 $
19 // $Author: fci $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include <iosfwd>
24 
25 template <class T, int N> class FVector;
26 template <class T, int N> class LinearMap;
27 template <class T, int M, int N> class FMatrix;
28 
29 
30 // Template class LinearFun<T,N>.
31 // ------------------------------------------------------------------------
33 // All divide operations throw DivideError,
34 // if the constant part of the divisor is zero.
35 // The copy constructor, destructor, and assignment operator generated
36 // by the compiler do the correct thing, and are not defined for speed.
37 
38 template <class T, int N>
39 class LinearFun {
40 
41 public:
42 
44  // Construct zero value.
45  LinearFun();
46 
48  LinearFun(const T &);
49 
51  LinearFun(int);
52 
54  LinearFun &operator=(const T &y);
55 
57  // Return value of the coefficient denoted by the index.
58  // The index zero stands for the constant term,
59  // any other value selects the derivative by the variable index+1.
60  // Return zero, if index is out of range.
61  const T getCoefficient(int index) const;
62 
64  // Assign value of the coefficient denoted by the index.
65  // The index zero stands for the constant term,
66  // any other value selects the derivative by the variable index+1.
67  // Ignore, if index is out of range.
68  void setCoefficient(int index, const T &value);
69 
71  // Return value of the coefficient denoted by the index.
72  // The index zero stands for the constant term,
73  // any other value selects the derivative by the variable index+1.
74  // Result is undefined, if index is out of range.
75  inline const T operator[](int index) const;
76 
78  // Return a reference to the coefficient denoted by the index.
79  // Result is undefined, if index is out of range.
80  // The index zero stands for the constant term,
81  // any other value selects the derivative by the variable index+1.
82  // Use as a lvalue is only allowed when the LinearFun is unique().
83  inline T &operator[](int index);
84 
86  // Construct the variable identified by the index [b]var[/b],
87  // with total of [b]nVar[/b] variables.
88  static LinearFun makeVariable(int var);
89 
91  LinearFun operator+() const;
92 
94  LinearFun operator-() const;
95 
97  LinearFun &operator+=(const LinearFun &y);
98 
100  LinearFun &operator-=(const LinearFun &y);
101 
103  LinearFun &operator*=(const LinearFun &y);
104 
106  LinearFun &operator/=(const LinearFun &y);
107 
109  LinearFun &operator+=(const T &y);
110 
112  LinearFun &operator-=(const T &y);
113 
115  LinearFun &operator*=(const T &y);
116 
118  LinearFun &operator/=(const T &y);
119 
121  bool operator==(const LinearFun &y) const;
122 
124  bool operator==(const T &y) const;
125 
127  bool operator!=(const LinearFun &y) const;
128 
130  bool operator!=(const T &y) const;
131 
133  LinearFun inverse() const;
134 
136  LinearFun multiply(const LinearFun &y) const;
137 
139  T evaluate(const FVector<T, N> &) const;
140 
142  // Substitute map [b]m[/b] in LinearFun, giving new LinearFun.
144 
146  // Substitute matrix [b]M[/b] in LinearFun, giving new LinearFun.
148 
150  // Expand Taylor series with coefficiens [b]series[/b] and order one.
151  LinearFun taylor(const T series[2]) const;
152 
154  std::istream &get(std::istream &is);
155 
157  std::ostream &put(std::ostream &os) const;
158 
159 private:
160 
162  // data[0] is the constant term,
163  // data[v+1] is the coefficient of variable [b]v[/b].
164  T data[N+1];
165 };
166 
167 
168 // Global functions.
169 // ------------------------------------------------------------------------
170 
172 template <class T, int N>
174 
176 template <class T, int N>
178 
180 template <class T, int N>
181 LinearFun<T, N> operator+(const LinearFun<T, N> &, const T &);
182 
184 template <class T, int N>
185 LinearFun<T, N> operator-(const LinearFun<T, N> &, const T &);
186 
188 template <class T, int N>
189 LinearFun<T, N> operator+(const T &, const LinearFun<T, N> &);
190 
192 template <class T, int N>
193 LinearFun<T, N> operator-(const T &, const LinearFun<T, N> &);
194 
196 template <class T, int N>
198 
200 template <class T, int N>
202 
204 template <class T, int N>
205 LinearFun<T, N> operator*(const LinearFun<T, N> &, const T &);
206 
208 template <class T, int N>
209 LinearFun<T, N> operator/(const LinearFun<T, N> &, const T &);
210 
212 template <class T, int N>
213 LinearFun<T, N> operator*(const T &, const LinearFun<T, N> &);
214 
216 template <class T, int N>
217 LinearFun<T, N> operator/(const T &, const LinearFun<T, N> &);
218 
220 template <class T, int N>
221 bool operator==(const T &, const LinearFun<T, N> &);
222 
224 template <class T, int N>
225 bool operator!=(const T &, const LinearFun<T, N> &);
226 
228 template <class T, int N>
229 std::istream &operator>>(std::istream &is, LinearFun<T, N> &);
230 
232 template <class T, int N>
233 std::ostream &operator<<(std::ostream &os, const LinearFun<T, N> &);
234 
235 
236 // Implementation.
238 #include "FixedAlgebra/LinearMap.h"
239 
240 #endif // CLASSIC_LinearFun_HH
Matrix< T > operator+(const Matrix< T > &, const Matrix< T > &)
Matrix addition.
Definition: Matrix.h:275
Matrix< T > operator/(const Matrix< T > &, const T &)
Matrix divided by scalar.
Definition: Matrix.h:329
Definition: rbendmap.h:8
A templated representation for matrices.
Definition: IdealMapper.h:26
LinearFun operator+() const
Unary plus.
Definition: LinearFun.hpp:100
std::ostream & put(std::ostream &os) const
Write LinearFun on the stream [b]os[/b].
Definition: LinearFun.hpp:343
LinearFun taylor(const T series[2]) const
Taylor series.
Definition: LinearFun.hpp:277
LinearFun multiply(const LinearFun &y) const
Multiplication truncated to order one.
Definition: LinearFun.hpp:226
A templated representation for vectors.
Definition: PartBunchBase.h:26
LinearFun inverse() const
Approximate reciprocal value 1/(*this).
Definition: LinearFun.hpp:211
Matrix< T > operator*(const Matrix< T > &, const Matrix< T > &)
Matrix multiply.
Definition: Matrix.h:297
LinearFun & operator/=(const LinearFun &y)
Approximate division and assignation.
Definition: LinearFun.hpp:134
LinearFun & operator+=(const LinearFun &y)
Add and assign.
Definition: LinearFun.hpp:114
const T operator[](int index) const
Get coefficient.
Definition: LinearFun.hpp:79
static LinearFun makeVariable(int var)
Make variable.
Definition: LinearFun.hpp:91
LinearFun< T, N > substitute(const LinearMap< T, N > &m) const
Substitute.
Definition: LinearFun.hpp:262
void setCoefficient(int index, const T &value)
Set coefficient.
Definition: LinearFun.hpp:73
Linear map with values of type [b]T[/b] in [b]N[/b] variables.
LinearFun & operator*=(const LinearFun &y)
Multiply and assign.
Definition: LinearFun.hpp:128
LinearFun & operator=(const T &y)
Convert and assign.
Definition: LinearFun.hpp:59
bool operator!=(const Offset &off1, const Offset &off2)
Definition: Offset.cpp:225
bool operator!=(const LinearFun &y) const
Inequality operator.
Definition: LinearFun.hpp:199
LinearFun()
Default constructor.
Definition: LinearFun.hpp:39
T data[N+1]
Representation.
Definition: LinearFun.h:164
T evaluate(const FVector< T, N > &) const
Evaluate LinearFun at point.
Definition: LinearFun.hpp:239
bool operator==(const LinearFun &y) const
Equality operator.
Definition: LinearFun.hpp:177
LinearFun & operator-=(const LinearFun &y)
Subtract and assign.
Definition: LinearFun.hpp:121
Linear function in N variables of type T.
Definition: LinearFun.h:39
Matrix< T > operator-(const Matrix< T > &, const Matrix< T > &)
Matrix subtraction.
Definition: Matrix.h:282
const T getCoefficient(int index) const
Get coefficient.
Definition: LinearFun.hpp:67
LinearFun operator-() const
Unary minus.
Definition: LinearFun.hpp:106
std::istream & operator>>(std::istream &, LieMap< T > &x)
Extract LieMap&lt;T&gt; from stream.
Definition: LieMap.h:231
bool operator==(const TwoPolynomial &left, const TwoPolynomial &right)