9#ifndef LINE_NUM_SYM_NUMBER_H
10#define LINE_NUM_SYM_NUMBER_H
12#ifdef LINE_MP_USE_SYMENGINE
18#include <symengine/basic.h>
19#include <symengine/eval_double.h>
20#include <symengine/expression.h>
21#include <symengine/symbol.h>
22#include <symengine/visitor.h>
56 Sym() : e_(SymEngine::integer(0)) {}
57 explicit Sym(
const SymEngine::Expression& e) : e_(e) {}
58 Sym(
int v) : e_(SymEngine::integer(v)) {}
59 Sym(
long v) : e_(SymEngine::integer(v)) {}
60 Sym(
const SymEngine::RCP<const SymEngine::Basic>& b) : e_(b) {}
63 static Sym
var(
const std::string& name) {
64 return Sym(SymEngine::Expression(SymEngine::symbol(name)));
68 static Sym from_double_exact(
double v) {
69 return Sym(SymEngine::Expression(SymEngine::real_double(v)));
72 const SymEngine::Expression& expr()
const {
return e_; }
74 Sym operator+(
const Sym& o)
const {
return Sym(e_ + o.e_); }
75 Sym operator-(
const Sym& o)
const {
return Sym(e_ - o.e_); }
76 Sym operator*(
const Sym& o)
const {
return Sym(e_ * o.e_); }
77 Sym operator/(
const Sym& o)
const {
return Sym(e_ / o.e_); }
78 Sym operator-()
const {
return Sym(-e_); }
80 Sym& operator+=(
const Sym& o) { e_ = e_ + o.e_;
return *
this; }
81 Sym& operator-=(
const Sym& o) { e_ = e_ - o.e_;
return *
this; }
82 Sym& operator*=(
const Sym& o) { e_ = e_ * o.e_;
return *
this; }
83 Sym& operator/=(
const Sym& o) { e_ = e_ / o.e_;
return *
this; }
86 bool operator==(
const Sym& o)
const {
return e_ == o.e_; }
87 bool operator!=(
const Sym& o)
const {
return !(*
this == o); }
89 std::string str()
const {
return SymEngine::str(e_); }
92 SymEngine::Expression e_;
95inline std::string to_string(
const Sym& v) {
return v.str(); }
100 static constexpr bool is_exact =
true;
107 static constexpr bool has_transcendental =
false;
108 static const char*
name() {
return "symbolic"; }
110 static Sym from_int(
long v) {
return Sym(v); }
111 static Sym from_rational(
long num,
long den) {
112 return Sym(SymEngine::Expression(SymEngine::integer(num)) /
113 SymEngine::Expression(SymEngine::integer(den)));
115 static Sym from_double(
double v) {
return Sym::from_double_exact(v); }
122 static double to_double(
const Sym& v) {
123 return SymEngine::eval_double(*v.expr().get_basic());
140 static double log_as_double(
const Sym& v) {
141 if (!SymEngine::free_symbols(*v.expr().get_basic()).empty()) {
142 return std::numeric_limits<double>::quiet_NaN();
144 return std::log(to_double(v));
146 static std::string to_string(
const Sym& v) {
return v.str(); }
std::string name(const Element *el, const std::string &key="name")
double var(const std::vector< double > &x)
Sample variance with the n - 1 denominator.
Conservation laws of a layered queueing network, enumerated from its structure.
Number-type abstraction for the templated API port.