xc
ExprAlgebra.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //ExprAlgebra.h
22 
23 #ifndef EXPRALGEBRA_H
24 #define EXPRALGEBRA_H
25 
26 
27 #include "ArbolExpr.h"
28 
29 class Intervalo1D;
30 
32 class ExprAlgebra : public ArbolExpr
33  {
34  friend class ExpressionMatrix;
35  inline void eval(void)
36  {
37  expand();
38  Opera();
39  }
40  inline void eval(const std::string &palabra,const ExprAlgebra &a)
41  {
42  Asigna(palabra,a);
43  Opera();
44  }
45  void eval(const MapValores &);
46  inline void eval(const std::string &palabra,const double &d)
47  {
48  Asigna(palabra,d);
49  Opera();
50  }
51  void expand(void);
52 
53  public:
54  ExprAlgebra(void);
55  explicit ExprAlgebra(const std::string &);
56  ExprAlgebra(const ExprAlgebra &);
57  explicit ExprAlgebra(const double &);
58  ExprAlgebra &operator=(const ExprAlgebra &other)
59  {
60  ArbolExpr::operator=(other);
61  return *this;
62  }
63  ExprAlgebra &operator+=(const ExprAlgebra &a2)
64  {
65  ArbolExpr::operator+=(a2);
66  return *this;
67  }
68  ExprAlgebra &operator-=(const ExprAlgebra &a2)
69  {
70  ArbolExpr::operator-=(a2);
71  return *this;
72  }
73  ExprAlgebra &operator*=(const ExprAlgebra &a2)
74  {
75  ArbolExpr::operator*=(a2);
76  return *this;
77  }
78  ExprAlgebra &operator/=(const ExprAlgebra &a2)
79  {
80  ArbolExpr::operator/=(a2);
81  return *this;
82  }
83  inline ExprAlgebra operator-(void)
84  {
85  ExprAlgebra retval(*this);
86  retval.Neg();
87  return retval;
88  }
89  inline ExprAlgebra Eval(void) const
90  {
91  ExprAlgebra retval(*this);
92  retval.eval();
93  return retval;
94  }
95  inline ExprAlgebra Eval(const std::string &palabra,const ExprAlgebra &a) const
96  {
97  ExprAlgebra retval(*this);
98  retval.eval(palabra,a);
99  return retval;
100  }
101  inline ExprAlgebra Eval(const std::string &palabra,const double &d) const
102  {
103  ExprAlgebra retval(*this);
104  retval.eval(palabra,d);
105  return retval;
106  }
107  ExprAlgebra Eval(const std::string &valores) const;
108  inline ExprAlgebra Diferencia(const std::string &var) const
109  {
110  ExprAlgebra retval(*this);
111  retval.Dif(var);
112  return retval;
113  }
114  inline ExprAlgebra Colct(void) const
115  {
116  ExprAlgebra retval(*this);
117  retval.Simplifica();
118  return retval;
119  }
120  double RaizNewton(const double &tol,size_t max_iter,const std::string &var,const double &d,double &err);
121  inline ExprAlgebra operator()(const std::string &p,const ExprAlgebra &a) const
122  { return Eval(p,a); }
123  inline ExprAlgebra operator()(const std::string &p,const double &d) const
124  { return Eval(p,d); }
125  ExprAlgebra IntegTrapecio(const Intervalo1D &i) const;
126  ExprAlgebra IntegSimpson(const Intervalo1D &i) const;
127  friend ExprAlgebra operator+(const ExprAlgebra &a1,const ExprAlgebra &a2)
128  {
129  ExprAlgebra retval(a1);
130  return retval+=a2;
131  }
132  friend ExprAlgebra operator+(const ExprAlgebra &a1,const double &a2)
133  {
134  ExprAlgebra retval(a1);
135  return retval+= ExprAlgebra(a2);
136  }
137  friend ExprAlgebra operator+(const double &a1,const ExprAlgebra &a2)
138  {
139  ExprAlgebra retval(a1);
140  return retval+=a2;
141  }
142  friend ExprAlgebra operator-(const ExprAlgebra &a1,const ExprAlgebra &a2)
143  {
144  ExprAlgebra retval(a1);
145  return retval-=a2;
146  }
147  friend ExprAlgebra operator-(const ExprAlgebra &a1,const double &a2)
148  {
149  ExprAlgebra retval(a1);
150  return retval-= ExprAlgebra(a2);
151  }
152  friend ExprAlgebra operator-(const double &a1,const ExprAlgebra &a2)
153  {
154  ExprAlgebra retval(a1);
155  return retval-=a2;
156  }
157  friend ExprAlgebra operator*(const ExprAlgebra &a1,const ExprAlgebra &a2)
158  {
159  ExprAlgebra retval(a1);
160  return retval*=a2;
161  }
162  friend ExprAlgebra operator*(const ExprAlgebra &a1,const double &a2)
163  {
164  ExprAlgebra retval(a1);
165  return retval*= ExprAlgebra(a2);
166  }
167  friend ExprAlgebra operator*(const double &a1,const ExprAlgebra &a2)
168  {
169  ExprAlgebra retval(a1);
170  return retval*=a2;
171  }
172  friend ExprAlgebra operator/(const ExprAlgebra &a1,const ExprAlgebra &a2)
173  {
174  ExprAlgebra retval(a1);
175  return retval/=a2;
176  }
177  friend ExprAlgebra operator/(const ExprAlgebra &a1,const double &a2)
178  {
179  ExprAlgebra retval(a1);
180  return retval/= ExprAlgebra(a2);
181  }
182  friend ExprAlgebra operator/(const double &a1,const ExprAlgebra &a2)
183  {
184  ExprAlgebra retval(a1);
185  return retval/=a2;
186  }
187  friend ExprAlgebra expand(const ExprAlgebra &);
188  friend ExprAlgebra abs(const ExprAlgebra &);
189  friend ExprAlgebra sqrt(const ExprAlgebra &);
190  friend ExprAlgebra pow(const ExprAlgebra &a,const ExprAlgebra &b);
191  friend ExprAlgebra pow(const ExprAlgebra &a,const double &b);
192  friend ExprAlgebra pow(const double &a,const ExprAlgebra &b);
193  };
194 
195 ExprAlgebra expand(const ExprAlgebra &);
196 ExprAlgebra colct(const ExprAlgebra &);
197 
198 #endif
199 
200 
201 
202 
203 
204 
void Opera(void)
Opera todo el árbol.
Definition: ArbolExpr.cc:185
Árbol que representa una expresión matemática.
Definition: ArbolExpr.h:41
friend ExprAlgebra pow(const ExprAlgebra &a, const ExprAlgebra &b)
Devuelve a^b.
Definition: ExprAlgebra.cc:111
ExprAlgebra IntegSimpson(const Intervalo1D &i) const
Integrates the expresion using the Simpson rule.
Definition: ExprAlgebra.cc:155
Especifica valores de variables.
Definition: MapValores.h:32
ExprAlgebra IntegTrapecio(const Intervalo1D &i) const
Integrates the expresion using the trapezoidal rule.
Definition: ExprAlgebra.cc:149
void Dif(const std::string &var)
Diferencia la expresión respecto a la variable cuyo identificador se pasa como parámetro.
Definition: ArbolExpr.cc:248
double RaizNewton(const double &tol, size_t max_iter, const std::string &var, const double &d, double &err)
Devuelve la raiz de la expresion aproximandola por Newton.
Definition: ExprAlgebra.cc:73
Integration interval in one dimension.
Definition: num_integration.h:32
Definition: ExpressionMatrix.h:33
ExprAlgebra(void)
Constructor.
Definition: ExprAlgebra.cc:30
friend ExprAlgebra abs(const ExprAlgebra &)
Devuelve el valor absoluto del argumento.
Definition: ExprAlgebra.cc:95
ArbolExpr & operator=(const ArbolExpr &otro)
Operador asignación.
Definition: ArbolExpr.cc:82
friend ExprAlgebra sqrt(const ExprAlgebra &)
Devuelve la raía cuadrada del argumento.
Definition: ExprAlgebra.cc:103
Expresión algebraica.
Definition: ExprAlgebra.h:32
void Neg(void)
Cambia de signo la expresión contenida en el árbol.
Definition: ArbolExpr.cc:226