stator
A math, geometry, and utility library
integrate.hpp
Go to the documentation of this file.
1 
4 /*
5  Copyright (C) 2017 Marcus N Campbell Bannerman <[email protected]>
6 
7  This file is part of stator.
8 
9  stator is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  stator is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with stator. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #pragma once
24 
25 //stator
26 #include "stator/exception.hpp"
27 #include "stator/config.hpp"
28 
29 
30 namespace sym {
31 #define IS_CONSTANT(f, Var) std::is_same<decltype(store(derivative(f, Var()))), Null>::value
32 
38  template<class T, class Var>
39  auto integrate(const T& a, Var)
40  -> typename std::enable_if<IS_CONSTANT(a, Var), decltype(store(a * Var()))>::type
41  { return a * Var(); }
42 
44  template<class ...VarArgs, class LHS, class RHS>
45  auto integrate(const AddOp<LHS, RHS>& a, Var<VarArgs...> x)
46  -> STATOR_AUTORETURN(integrate(a._l, x) + integrate(a._r, x));
47 
49  template<class ...VarArgs, class LHS, class RHS>
51  -> STATOR_AUTORETURN(integrate(a._l, x) - integrate(a._r, x));
52 
54  template<class ...VarArgs, class LHS, class RHS>
56  -> typename std::enable_if<IS_CONSTANT(a._l, Var<VarArgs...>), decltype(store(a._l * integrate(a._r, x)))>::type
57  { return a._l * integrate(a._r, x); }
58 
60  template<class ...VarArgs, class LHS, class RHS>
62  -> typename std::enable_if<IS_CONSTANT(a._r, Var<VarArgs...>), decltype(store(integrate(a._l, x) * a._r))>::type
63  { return integrate(a._l, x) * a._r; }
64 
66  template<class ...VarArgs1, class ...VarArgs2,
67  typename = typename enable_if_var_in<Var<VarArgs1...>, Var<VarArgs2...> >::type>
69  -> STATOR_AUTORETURN((C<1,2>() * pow<2>(typename variable_combine<Var<VarArgs1...>, Var<VarArgs2...> >::type())));
70 
72  template<class ...VarArgs1, class ...VarArgs2, std::intmax_t Power,
73  typename = typename enable_if_var_in<Var<VarArgs1...>, Var<VarArgs2...> >::type>
76 
77 } // namespace symbolic
auto integrate(const T &a, Var) -> typename std::enable_if< std::is_same< decltype(store(derivative(a, Var()))), Null >::value, decltype(store(a *Var()))>::type
Integration of any constant/independent expression.
Definition: integrate.hpp:39
Symbolic representation of a variable.
Definition: symbolic.hpp:94
#define IS_CONSTANT(f, Var)
Definition: integrate.hpp:31
Fundamental typedef&#39;s and macros for stator.
A class representing a compile-time rational constant (i.e., std::ratio).
Definition: constants.hpp:31
Symbolic representation of a binary symbolic operation.
Definition: binary_ops.hpp:33
#define STATOR_AUTORETURN(EXPR)
A convenience Macro for defining auto return type functions.
Definition: config.hpp:51
The stator symbolic math library.
const RHS _r
Definition: binary_ops.hpp:35
const LHS _l
Definition: binary_ops.hpp:34
auto pow(const LHS &l, const RHS &r) -> STATOR_AUTORETURN(std::pow(l, r))
auto store(const T &val) -> decltype(store_impl(val, select_overload
Definition: config.hpp:94