23 template<
class Config = DefaultReprConfig, std::
intmax_t Num, std::
intmax_t Denom>
26 if (Config::Debug_output)
27 return "C<" +
repr(Num) + ((Denom!=1) ? (std::string(
", ") +
repr(Denom) +
">") : std::string(
">"));
29 return (Denom!=1) ? (
"("+
repr(Num)+
"/"+
repr(Denom)+
")") :
repr(Num);
35 return std::string(1, v.
getidx());
38 template<
class Config = DefaultReprConfig,
class Var,
class Arg>
40 return repr<Config>(sub.
_var) <<
"=" << repr<Config>(sub.
_val);
43 template<
class Config = DefaultReprConfig,
class Arg>
46 return std::string((Config::Latex_output) ?
"\\sin\\left(" :
"sin(")
47 + repr<Config>(f.
_arg)
48 + std::string((Config::Latex_output) ?
"\\right)" :
")")
52 template<
class Config = DefaultReprConfig,
class Arg>
55 return std::string((Config::Latex_output) ?
"\\cos\\left(" :
"cos(")
56 + repr<Config>(f.
_arg)
57 + std::string((Config::Latex_output) ?
"\\right)" :
")")
61 template<
class Config = DefaultReprConfig,
class Arg>
65 std::string((Config::Latex_output) ?
"\\mathrm{e}^{" :
"exp(")
66 + repr<Config>(f.
_arg)
67 + std::string((Config::Latex_output) ?
"}" :
")")
71 template<
class Config = DefaultReprConfig,
class Arg>
75 std::string((Config::Latex_output) ?
"\\ln\\left(" :
"ln(")
76 + repr<Config>(f.
_arg)
77 + std::string((Config::Latex_output) ?
"\\right)" :
")")
81 template<
class Config = DefaultReprConfig,
class Arg>
85 std::string((Config::Latex_output) ?
"\\left|" :
"|")
86 + repr<Config>(f.
_arg)
87 + std::string((Config::Latex_output) ?
"\\right|" :
"|")
91 template<
class Config = DefaultReprConfig,
class Arg>
95 std::string((Config::Latex_output) ?
"\\pm\\left|" :
"|")
96 + repr<Config>(f.
_arg)
97 + std::string((Config::Latex_output) ?
"\\right|" :
"|")
101 template<
class Config = DefaultReprConfig,
class T,
typename =
typename std::enable_if<std::is_base_of<Eigen::EigenBase<T>, T>::value>::type>
102 std::string
repr(
const T& val) {
103 std::ostringstream os;
104 if ((val.cols() == 1) && (val.rows()==1))
105 os << repr<Config>(val(0,0));
106 else if (val.cols() == 1) {
108 for (
int i(0); i < val.rows(); ++i)
109 os << repr<Config>(val(i, 0)) <<
" ";
113 for (
int i(0); i < val.cols(); ++i) {
115 for (
int j(0); j < val.rows(); ++j)
116 os << repr<Config>(val(i, j)) <<
" ";
129 template<
class Config = DefaultReprConfig,
class Coeff_t,
size_t N,
class PolyVar>
131 std::ostringstream oss;
134 for (
size_t i(
N); i != 0; --i) {
139 oss << repr<Config>(poly[i]) <<
"*" << PolyVar::idx;
147 oss << repr<Config>(poly[0]);
163 std::pair<int, int>
BP (
const T& v)
164 {
return std::make_pair(std::numeric_limits<int>::max(), std::numeric_limits<int>::max()); }
169 template<
class LHS,
class Op,
class RHS>
171 const int L = Op::leftBindingPower;
172 const int R = sym::detail::RBP<Op>();
173 return std::make_pair(L, R);
182 LBP = Op::leftBindingPower;
183 RBP = sym::detail::RBP<Op>();
187 int LBP = std::numeric_limits<int>::max();
188 int RBP = std::numeric_limits<int>::max();
197 return std::make_pair(vis.
LBP, vis.
RBP);
200 template<
class Config>
202 return ((Config::Latex_output) ?
"\\left(" :
"(") + arg + ((Config::Latex_output) ?
"\\right)" :
")");
206 template<
class Config = DefaultReprConfig,
class LHS,
class RHS,
class Op>
212 std::string LHS_repr = repr<Config>(op.
_l);
213 if (LHS_BP.second < this_BP.first) LHS_repr = detail::paren_wrap<Config>(LHS_repr);
215 std::string RHS_repr = repr<Config>(op.
_r);
216 if (this_BP.second > RHS_BP.first) RHS_repr = detail::paren_wrap<Config>(RHS_repr);
218 return LHS_repr +
Op::repr() + RHS_repr;
221 template<
class Config = DefaultReprConfig,
class LHS,
class RHS>
227 std::string LHS_repr = repr<Config>(op.
_l);
228 if (LHS_BP.second < this_BP.first) LHS_repr = detail::paren_wrap<Config>(LHS_repr);
230 std::string RHS_repr = repr<Config>(op.
_r);
231 if (!Config::Latex_output) {
232 if (this_BP.second > RHS_BP.first) RHS_repr = detail::paren_wrap<Config>(RHS_repr);
234 RHS_repr =
"{" + RHS_repr +
"}";
240 template<
class Config = DefaultReprConfig,
class LHS,
class RHS>
246 std::string LHS_repr = repr<Config>(op.
_l);
247 std::string RHS_repr = repr<Config>(op.
_r);
249 if (!Config::Latex_output) {
250 if (LHS_BP.second < this_BP.first) LHS_repr = detail::paren_wrap<Config>(LHS_repr);
251 if (this_BP.second > RHS_BP.first) RHS_repr = detail::paren_wrap<Config>(RHS_repr);
254 return "\\frac{" + LHS_repr +
"}{" + RHS_repr +
"}";
258 template<
class Config = DefaultReprConfig,
class LHS,
class RHS>
264 std::string LHS_repr = repr<Config>(op.
_l);
265 std::string RHS_repr = repr<Config>(op.
_r);
267 if (LHS_BP.second < this_BP.first) LHS_repr = detail::paren_wrap<Config>(LHS_repr);
268 if (this_BP.second > RHS_BP.first) RHS_repr = detail::paren_wrap<Config>(RHS_repr);
270 if (!Config::Latex_output) {
274 return LHS_repr +
"\\times " + RHS_repr;
276 return LHS_repr +
"\\," + RHS_repr;
281 template<
class Config>
284 _repr = repr<Config>(rhs);
292 template<
class Config>
296 return visitor.
_repr;
299 template<
class Config>
301 return repr<Config>(*b);
306 template<class T, typename = typename std::enable_if<sym::IsSymbolic<T>::value>::type>
A CRTP helper base class which transforms the visitor interface into a call to the derived classes ap...
bool is_constant(const Expr &a)
Symbolic representation of a variable.
auto N(const T &a) -> STATOR_AUTORETURN(simplify< NConfig >(a))
A variant of simplify that converts compile time symbols into numbers.
virtual Expr visit(detail::VisitorInterface &c) const =0
ReprConfig<> DefaultReprConfig
Abstract interface class for all runtime symbolic classes.
std::enable_if< std::is_integral< T >::value, std::string >::type repr(T a)
sym::Expr apply(const T &rhs)
A class representing a compile-time rational constant (i.e., std::ratio).
std::string repr(const sym::Expr &b)
Symbolic representation of a binary symbolic operation.
static std::string repr()
static std::string repr()
Symbolic representation of a variable substitution.
The generic holder/smart pointer for a runtime Abstract Syntax Tree (AST) (expression).
The stator symbolic math library.
T empty_sum(const T &)
Returns the empty sum of a type.
sym::Expr apply(const T &rhs)
Binding power visitor for sym::detail::BP(const Expr&).
std::ostream & operator<<(std::ostream &os, const T &v)
static std::string repr()
auto sub(BinaryOp< LHS, Op, RHS > f, Relation< Var, Arg > x) -> STATOR_AUTORETURN_BYVALUE(Op::apply(sub(f._l, x), sub(f._r, x)))
The stator library namespace.
sym::Expr apply(const sym::BinaryOp< sym::Expr, Op, sym::Expr > &op)
Symbolic representation of a unary operator (i.e., sin(x)).
std::pair< int, int > BP(const T &v)
Returns the binding powers (precedence) of binary operators.
std::string paren_wrap(std::string arg)
Array representation of Polynomial.