2 #include <symengine/printers/mathml.h>
4 #include <symengine/printers.h>
12 names[SYMENGINE_ASIN] =
"arcsin";
13 names[SYMENGINE_ACOS] =
"arccos";
14 names[SYMENGINE_ASEC] =
"arcsec";
15 names[SYMENGINE_ACSC] =
"arccsc";
16 names[SYMENGINE_ATAN] =
"arctan";
17 names[SYMENGINE_ACOT] =
"arccot";
18 names[SYMENGINE_ASINH] =
"arcsinh";
19 names[SYMENGINE_ACSCH] =
"arccsch";
20 names[SYMENGINE_ACOSH] =
"arccosh";
21 names[SYMENGINE_ATANH] =
"arctanh";
22 names[SYMENGINE_ACOTH] =
"arccoth";
23 names[SYMENGINE_ASECH] =
"arcsech";
27 void MathMLPrinter::bvisit(
const Basic &x)
29 throw SymEngineException(
"Error: not supported");
32 void MathMLPrinter::bvisit(
const Symbol &x)
34 s <<
"<ci>" << x.get_name() <<
"</ci>";
37 void MathMLPrinter::bvisit(
const Integer &x)
39 s <<
"<cn type=\"integer\">" << x.as_integer_class() <<
"</cn>";
42 void MathMLPrinter::bvisit(
const Rational &x)
44 const auto &
rational = x.as_rational_class();
45 s <<
"<cn type=\"rational\">" << get_num(
rational) <<
"<sep/>"
49 void MathMLPrinter::bvisit(
const RealDouble &x)
51 s <<
"<cn type=\"real\">" << x <<
"</cn>";
54 #ifdef HAVE_SYMENGINE_MPFR
55 void MathMLPrinter::bvisit(
const RealMPFR &x)
58 s <<
"<cn type=\"real\">" << x <<
"</cn>";
62 void MathMLPrinter::bvisit(
const ComplexBase &x)
64 s <<
"<apply><csymbol cd=\"nums1\">complex_cartesian</csymbol>";
65 x.real_part()->accept(*
this);
66 x.imaginary_part()->accept(*
this);
70 void MathMLPrinter::bvisit(
const Interval &x)
72 s <<
"<interval closure=";
73 if (x.get_left_open()) {
74 if (x.get_right_open()) {
77 s <<
"\"open-closed\">";
80 if (x.get_right_open()) {
81 s <<
"\"closed-open\">";
86 x.get_start()->accept(*
this);
87 x.get_end()->accept(*
this);
91 void MathMLPrinter::bvisit(
const Piecewise &x)
94 const auto &equations = x.get_vec();
95 for (
const auto &equation : equations) {
97 equation.first->accept(*
this);
98 equation.second->accept(*
this);
104 void MathMLPrinter::bvisit(
const EmptySet &x)
109 void MathMLPrinter::bvisit(
const Complexes &x)
114 void MathMLPrinter::bvisit(
const Reals &x)
119 void MathMLPrinter::bvisit(
const Rationals &x)
124 void MathMLPrinter::bvisit(
const Integers &x)
129 void MathMLPrinter::bvisit(
const FiniteSet &x)
132 const auto &args = x.get_args();
133 for (
const auto &arg : args) {
139 void MathMLPrinter::bvisit(
const ConditionSet &x)
142 x.get_symbol()->accept(*
this);
143 s <<
"</bvar><condition>";
144 x.get_condition()->accept(*
this);
146 x.get_symbol()->accept(*
this);
150 void MathMLPrinter::bvisit(
const Contains &x)
153 x.get_expr()->accept(*
this);
154 x.get_set()->accept(*
this);
158 void MathMLPrinter::bvisit(
const BooleanAtom &x)
167 void MathMLPrinter::bvisit(
const And &x)
169 s <<
"<apply><and/>";
170 const auto &conditions = x.get_args();
171 for (
const auto &condition : conditions) {
172 condition->accept(*
this);
177 void MathMLPrinter::bvisit(
const Or &x)
180 const auto &conditions = x.get_args();
181 for (
const auto &condition : conditions) {
182 condition->accept(*
this);
187 void MathMLPrinter::bvisit(
const Xor &x)
189 s <<
"<apply><xor/>";
190 const auto &conditions = x.get_args();
191 for (
const auto &condition : conditions) {
192 condition->accept(*
this);
197 void MathMLPrinter::bvisit(
const Not &x)
199 s <<
"<apply><not/>";
200 x.get_arg()->accept(*
this);
204 void MathMLPrinter::bvisit(
const Union &x)
206 s <<
"<apply><union/>";
207 const auto &sets = x.get_args();
208 for (
const auto &set : sets) {
214 void MathMLPrinter::bvisit(
const Complement &x)
216 s <<
"<apply><setdiff/>";
217 x.get_universe()->accept(*
this);
218 x.get_container()->accept(*
this);
222 void MathMLPrinter::bvisit(
const ImageSet &x)
225 x.get_expr()->accept(*
this);
226 s <<
"</bvar><condition><apply><in/>";
227 x.get_symbol()->accept(*
this);
228 x.get_baseset()->accept(*
this);
229 s <<
"</apply></condition>";
230 x.get_symbol()->accept(*
this);
234 void MathMLPrinter::bvisit(
const Add &x)
236 s <<
"<apply><plus/>";
237 auto args = x.get_args();
238 for (
auto arg : args) {
244 void MathMLPrinter::bvisit(
const Mul &x)
246 s <<
"<apply><times/>";
247 auto args = x.get_args();
248 for (
auto arg : args) {
254 void MathMLPrinter::bvisit(
const Pow &x)
256 s <<
"<apply><power/>";
257 x.get_base()->accept(*
this);
258 x.get_exp()->accept(*
this);
262 void MathMLPrinter::bvisit(
const Constant &x)
267 }
else if (
eq(x, *E)) {
268 s <<
"exponentiale/";
269 }
else if (
eq(x, *EulerGamma)) {
272 s <<
"cn type=\"real\">" << eval_double(x) <<
"</cn";
277 void MathMLPrinter::bvisit(
const Function &x)
281 s <<
"<" << names_[x.get_type_code()] <<
"/>";
282 const auto &args = x.get_args();
283 for (
const auto &arg : args) {
289 void MathMLPrinter::bvisit(
const UnevaluatedExpr &x)
294 void MathMLPrinter::bvisit(
const FunctionSymbol &x)
296 s <<
"<apply><ci>" << x.get_name() <<
"</ci>";
297 const auto &args = x.get_args();
298 for (
const auto &arg : args) {
304 void MathMLPrinter::bvisit(
const Equality &x)
307 x.get_arg1()->accept(*
this);
308 x.get_arg2()->accept(*
this);
312 void MathMLPrinter::bvisit(
const Unequality &x)
314 s <<
"<apply><neq/>";
315 x.get_arg1()->accept(*
this);
316 x.get_arg2()->accept(*
this);
320 void MathMLPrinter::bvisit(
const LessThan &x)
322 s <<
"<apply><leq/>";
323 x.get_arg1()->accept(*
this);
324 x.get_arg2()->accept(*
this);
328 void MathMLPrinter::bvisit(
const StrictLessThan &x)
331 x.get_arg1()->accept(*
this);
332 x.get_arg2()->accept(*
this);
336 void MathMLPrinter::bvisit(
const Derivative &x)
338 s <<
"<apply><partialdiff/><bvar>";
339 for (
const auto &elem : x.get_symbols()) {
343 x.get_arg()->accept(*
this);
Main namespace for SymEngine package.
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
RCP< const Number > rational(long n, long d)
convenience creator from two longs