7 #ifndef SYMENGINE_EXPRESSION_H
8 #define SYMENGINE_EXPRESSION_H
13 #include <symengine/complex_double.h>
15 #include <symengine/printers.h>
22 RCP<const Basic> diff(
const RCP<const Basic> &arg,
const RCP<const Symbol> &x,
25 RCP<const Basic> sdiff(
const RCP<const Basic> &arg,
const RCP<const Basic> &x,
31 RCP<const Basic> m_basic;
49 : m_basic(real_double(n))
57 : m_basic(complex_double(n))
63 Expression(
const rational_class &n) : m_basic(Rational::from_mpq(n)) {}
65 Expression(RCP<const Basic> &&o) : m_basic(o) {}
67 Expression(
const RCP<const Basic> &o) : m_basic(o) {}
93 os << expr.m_basic->__str__();
112 m_basic =
add(m_basic, other.m_basic);
117 m_basic =
add(m_basic, other);
133 operator const RCP<const Basic> &()
const
140 return Expression(SymEngine::diff(m_basic, x, cache));
153 template <
typename T,
156 explicit operator T()
const
161 template <
typename T,
168 operator const Basic &()
const
182 m_basic =
sub(m_basic, other.m_basic);
187 m_basic =
sub(m_basic, other);
206 m_basic =
mul(m_basic, other.m_basic);
211 m_basic =
mul(m_basic, other);
230 m_basic =
div(m_basic, other.m_basic);
235 m_basic =
div(m_basic, other);
241 return eq(*m_basic, *other.m_basic);
243 bool operator==(
const RCP<const Basic> &other)
const
245 return eq(*m_basic, *other);
251 return not(*
this == other);
253 bool operator!=(
const RCP<const Basic> &other)
const
255 return not(*
this == other);
265 inline Expression pow(
const Expression &base,
const Expression &
exp)
267 return pow(base.get_basic(),
exp.get_basic());
270 inline Expression
expand(
const Expression &arg)
272 return expand(arg.get_basic());
275 inline bool unified_eq(
const Expression &a,
const Expression &b)
295 #ifdef HAVE_SYMENGINE_PIRANHA
297 #include <piranha/math.hpp>
298 #include <piranha/pow.hpp>
299 #include <piranha/print_coefficient.hpp>
305 template <
typename T>
306 struct partial_impl<T, typename
std::enable_if<std::is_same<
307 T, SymEngine::Expression>::value>::type> {
319 template <
typename T,
typename U>
322 typename
std::enable_if<std::is_same<T, SymEngine::Expression>::value
323 && std::is_integral<U>::value>::type> {
333 template <
typename U>
334 struct print_coefficient_impl<U, typename
std::enable_if<std::is_same<
335 U, SymEngine::Expression>::value>::type> {
336 auto operator()(
std::ostream &os,
const U &cf)
const -> decltype(os << cf)
338 return os << SymEngine::detail::poly_print(cf);
350 #if defined(__has_include) && __has_include(<nlohmann/json.hpp>)
352 #include <nlohmann/json.hpp>
354 inline nlohmann::json mime_bundle_repr(
const Expression &i)
356 auto bundle = nlohmann::json::object();
357 bundle[
"text/plain"] = str(i);
358 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 > div(const RCP< const Basic > &a, const RCP< const Basic > &b)
Division.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
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 > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
int unified_compare(const T &a, const T &b)
RCP< const Basic > expand(const RCP< const Basic > &self, bool deep=true)
Expands self