7 #ifndef SYMENGINE_EXPRESSION_H
8 #define SYMENGINE_EXPRESSION_H
13 #include <symengine/complex_double.h>
15 #include <symengine/printers.h>
23 RCP<const Basic> diff(
const RCP<const Basic> &arg,
const RCP<const Symbol> &x,
27 RCP<const Basic> sdiff(
const RCP<const Basic> &arg,
const RCP<const Basic> &x,
33 RCP<const Basic> m_basic;
42 typename std::enable_if<std::is_integral<T>::value>::type * =
nullptr)
49 typename std::enable_if<std::is_floating_point<T>::value>::type
51 : m_basic(real_double(n))
57 typename std::enable_if<std::is_floating_point<T>::value>::type
59 : m_basic(complex_double(n))
65 Expression(
const rational_class &n) : m_basic(Rational::from_mpq(n)) {}
67 Expression(RCP<const Basic> &&o) : m_basic(o) {}
69 Expression(
const RCP<const Basic> &o) : m_basic(o) {}
71 Expression(
const std::string &s);
77 : m_basic(std::move(other.m_basic))
86 this->m_basic = std::move(other.m_basic);
95 os << expr.m_basic->__str__();
107 friend Expression operator+(
const Expression &a,
const RCP<const Basic> &b)
109 return Expression(
add(a.m_basic, b));
114 m_basic =
add(m_basic, other.m_basic);
117 Expression &operator+=(
const RCP<const Basic> &other)
119 m_basic =
add(m_basic, other);
131 friend Expression operator-(
const Expression &a,
const RCP<const Basic> &b)
133 return Expression(
sub(a.m_basic, b));
135 operator const RCP<const Basic> &()
const
142 return Expression(SymEngine::diff(m_basic, x, cache));
155 template <
typename T,
157 =
typename std::enable_if<std::is_arithmetic<T>::value>::type>
158 explicit operator T()
const
160 return T(eval_double(*get_basic()));
163 template <
typename T,
165 =
typename std::enable_if<std::is_arithmetic<T>::value>::type>
166 explicit operator std::complex<T>()
const
168 return std::complex<T>(eval_complex_double(*get_basic()));
170 operator const Basic &()
const
184 m_basic =
sub(m_basic, other.m_basic);
187 Expression &operator-=(
const RCP<const Basic> &other)
189 m_basic =
sub(m_basic, other);
201 friend Expression operator*(
const Expression &a,
const RCP<const Basic> &b)
203 return Expression(
mul(a.m_basic, b));
208 m_basic =
mul(m_basic, other.m_basic);
211 Expression &operator*=(
const RCP<const Basic> &other)
213 m_basic =
mul(m_basic, other);
225 friend Expression operator/(
const Expression &a,
const RCP<const Basic> &b)
227 return Expression(
div(a.m_basic, b));
232 m_basic =
div(m_basic, other.m_basic);
235 Expression &operator/=(
const RCP<const Basic> &other)
237 m_basic =
div(m_basic, other);
243 return eq(*m_basic, *other.m_basic);
245 bool operator==(
const RCP<const Basic> &other)
const
247 return eq(*m_basic, *other);
253 return not(*
this == other);
255 bool operator!=(
const RCP<const Basic> &other)
const
257 return not(*
this == other);
267 inline Expression pow(
const Expression &base,
const Expression &
exp)
269 return pow(base.get_basic(),
exp.get_basic());
272 inline void mp_pow_ui(Expression &res,
const Expression &base,
275 res = pow(base, Expression(
integer(
static_cast<signed long>(
exp))));
278 inline Expression
expand(
const Expression &arg)
280 return expand(arg.get_basic());
283 inline bool unified_eq(
const Expression &a,
const Expression &b)
298 SYMENGINE_EXPORT std::string poly_print(
const Expression &x);
303 #ifdef HAVE_SYMENGINE_PIRANHA
305 #include <piranha/math.hpp>
306 #include <piranha/pow.hpp>
307 #include <piranha/print_coefficient.hpp>
313 template <
typename T>
314 struct partial_impl<T, typename std::enable_if<std::is_same<
315 T, SymEngine::Expression>::value>::type> {
321 const std::string &)
const
327 template <
typename T,
typename U>
330 typename std::enable_if<std::is_same<T, SymEngine::Expression>::value
331 && std::is_integral<U>::value>::type> {
341 template <
typename U>
342 struct print_coefficient_impl<U, typename std::enable_if<std::is_same<
343 U, SymEngine::Expression>::value>::type> {
344 auto operator()(std::ostream &os,
const U &cf)
const -> decltype(os << cf)
346 return os << SymEngine::detail::poly_print(cf);
353 #if defined(__CLING__) || (defined(__CLANG_REPL__) && defined(__EMSCRIPTEN__))
356 #if defined(__has_include) && __has_include(<nlohmann/json.hpp>)
358 #include <nlohmann/json.hpp>
363 inline nlohmann::json mime_bundle_repr(
const Expression &i)
365 auto bundle = nlohmann::json::object();
366 bundle[
"text/plain"] = str(i);
367 bundle[
"text/latex"] =
"$" + latex(i) +
"$";
Classes and functions relating to the binary operation of addition.
The lowest unit of symbolic representation.
Expression(T n, typename std::enable_if< std::is_floating_point< T >::value >::type *=nullptr)
Construct Expression from floating point types.
Expression & operator-=(const Expression &other)
Overload subtraction and assignment(-=)
Expression(const Expression &)=default
Construct Expression from Expression.
Expression(T n, typename std::enable_if< std::is_integral< T >::value >::type *=nullptr)
Construct Expression from integral types.
friend Expression operator+(const Expression &a, const Expression &b)
Overload addition.
Expression diff(const RCP< const Symbol > &x, bool cache=true) const
Differentiation.
Expression subs(const map_basic_basic &subs_map) const
Substitution.
const RCP< const Basic > & get_basic() const
Method to get Basic from Expression.
friend Expression operator/(const Expression &a, const Expression &b)
Overload Division.
Expression & operator=(Expression &&other) SYMENGINE_NOEXCEPT
Overload assignment operator for reference.
friend Expression operator-(const Expression &a, const Expression &b)
Overload subtraction.
Expression diff(const RCP< const Basic > &x, bool cache=true) const
Differentiation.
friend Expression operator*(const Expression &a, const Expression &b)
Overload multiplication.
Expression & operator/=(const Expression &other)
Overload Division and assignment (/=)
virtual ~Expression() SYMENGINE_NOEXCEPT
Destructor of Expression.
friend std::ostream & operator<<(std::ostream &os, const Expression &expr)
Overload stream operator.
bool operator==(const Expression &other) const
Overload check equality (==)
Expression & operator=(const Expression &)=default
Overload assignment operator.
Expression & operator*=(const Expression &other)
Overload multiplication and assignment (*=)
Expression operator-() const
Overload unary negative.
Expression(Expression &&other) SYMENGINE_NOEXCEPT
Construct Expression from reference to Expression.
Expression()
Plain constructor of Expression.
Expression & operator+=(const Expression &other)
Overload addition and assignment(+=)
Expression(std::complex< T > n, typename std::enable_if< std::is_floating_point< T >::value >::type *=nullptr)
Construct Expression from std::complex<> types.
bool operator!=(const Expression &other) const
Overload check not equal (!=)
Main namespace for SymEngine package.
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
RCP< const Basic > sub(const RCP< const Basic > &a, const RCP< const Basic > &b)
Substracts b from a.
RCP< const Basic > div(const RCP< const Basic > &a, const RCP< const Basic > &b)
Division.
int unified_compare(const T &a, const T &b)
SYMENGINE_EXPORT RCP< const Basic > expand(const RCP< const Basic > &self, bool deep=true)
Expands self