9 Ptr<RCP<const Basic>> numer_, denom_;
13 const Ptr<RCP<const Basic>> &denom)
14 : numer_{numer}, denom_{denom}
18 void apply(
const Basic &b)
23 void bvisit(
const Mul &x)
25 RCP<const Basic> curr = one;
26 RCP<const Basic> arg_num, arg_den, t;
28 for (
const auto &arg : x.
get_args()) {
29 as_numer_denom(arg, outArg(arg_num), outArg(arg_den));
30 curr =
div(
mul(curr, arg_num), arg_den);
33 if (not is_a<Mul>(*curr)) {
38 RCP<const Basic> curr_num = one, curr_den = one;
39 for (
const auto &arg : curr->get_args()) {
40 as_numer_denom(arg, outArg(arg_num), outArg(arg_den));
41 curr_num =
mul(curr_num, arg_num);
42 curr_den =
mul(curr_den, arg_den);
49 void bvisit(
const Add &x)
52 RCP<const Basic> curr_num = zero;
53 RCP<const Basic> curr_den = one;
54 RCP<const Basic> arg_num, arg_den, den_mul, divx;
55 RCP<const Basic> divx_num, divx_den;
57 for (
const auto &arg : x.
get_args()) {
59 as_numer_denom(arg, outArg(arg_num), outArg(arg_den));
61 divx =
div(arg_den, curr_den);
62 as_numer_denom(divx, outArg(divx_num), outArg(divx_den));
63 if (
eq(*divx_den, *one)) {
66 curr_num =
add(
mul(curr_num, divx), arg_num);
70 divx =
div(curr_den, arg_den);
71 as_numer_denom(divx, outArg(divx_num), outArg(divx_den));
74 curr_den =
mul(curr_den, divx_den);
75 curr_num =
add(
mul(curr_num, divx_den),
mul(arg_num, divx_num));
82 void bvisit(
const Pow &x)
85 RCP<const Basic> base_, exp_, num, den;
88 as_numer_denom(base_, outArg(num), outArg(den));
91 if (handle_minus(exp_, outArg(exp_))) {
92 *numer_ = pow(den, exp_);
93 *denom_ = pow(num, exp_);
95 *numer_ = pow(num, exp_);
96 *denom_ = pow(den, exp_);
103 RCP<const Integer> den, den1, den2;
104 RCP<const Integer> num1, num2;
107 num2 =
integer(get_num(x.imaginary_));
110 den2 =
integer(get_den(x.imaginary_));
111 den =
lcm(*den1, *den2);
113 num1 = rcp_static_cast<const Integer>(
mul(num1,
div(den, den1)));
114 num2 = rcp_static_cast<const Integer>(
mul(num2,
div(den, den2)));
122 *numer_ = x.get_num();
123 *denom_ = x.get_den();
126 void bvisit(
const Basic &x)
133 void as_numer_denom(
const RCP<const Basic> &x,
134 const Ptr<RCP<const Basic>> &numer,
135 const Ptr<RCP<const Basic>> &denom)
The base class for representing addition in symbolic expressions.
vec_basic get_args() const override
Returns the arguments of the Add.
The lowest unit of symbolic representation.
static RCP< const Number > from_two_nums(const Number &re, const Number &im)
RCP< T > rcp_from_this()
Get RCP<T> pointer to self (it will cast the pointer to T)
vec_basic get_args() const override
Returns the list of arguments.
RCP< const Basic > get_exp() const
RCP< const Basic > get_base() const
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 Integer > lcm(const Integer &a, const Integer &b)
Least Common Multiple.
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).