// If the coefficient is -1, it is replaced by a single minus sign
if (it->coeff.compare(_num1()) == 0) {
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
} else if (it->coeff.compare(_num_1()) == 0) {
c.s << "-";
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
} else if (ex_to<numeric>(it->coeff).numer().compare(_num1()) == 0) {
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
c.s << "/";
ex_to<numeric>(it->coeff).denom().print(c, precedence());
} else if (ex_to<numeric>(it->coeff).numer().compare(_num_1()) == 0) {
c.s << "-";
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
c.s << "/";
ex_to<numeric>(it->coeff).denom().print(c, precedence());
} else {
- it->coeff.bp->print(c, precedence());
+ it->coeff.print(c, precedence());
c.s << "*";
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
}
// Separator is "+", except if the following expression would have a leading minus sign
if (!overall_coeff.is_zero()) {
if (overall_coeff.info(info_flags::positive))
c.s << '+';
- overall_coeff.bp->print(c, precedence());
+ overall_coeff.print(c, precedence());
}
if (precedence() <= level)
static bool get_first_symbol(const ex &e, const symbol *&x)
{
if (is_ex_exactly_of_type(e, symbol)) {
- x = static_cast<symbol *>(e.bp);
+ x = &ex_to<symbol>(e);
return true;
} else if (is_ex_exactly_of_type(e, add) || is_ex_exactly_of_type(e, mul)) {
for (unsigned i=0; i<e.nops(); i++)
static void collect_symbols(const ex &e, sym_desc_vec &v)
{
if (is_ex_exactly_of_type(e, symbol)) {
- add_symbol(static_cast<symbol *>(e.bp), v);
+ add_symbol(&ex_to<symbol>(e), v);
} else if (is_ex_exactly_of_type(e, add) || is_ex_exactly_of_type(e, mul)) {
for (unsigned i=0; i<e.nops(); i++)
collect_symbols(e.op(i), v);
}
-/** Apply symmetric modular homomorphism to a multivariate polynomial.
- * This function is used internally by heur_gcd().
+/** Apply symmetric modular homomorphism to an expanded multivariate
+ * polynomial. This function is usually used internally by heur_gcd().
*
- * @param e expanded multivariate polynomial
* @param xi modulus
* @return mapped polynomial
* @see heur_gcd */
-ex ex::smod(const numeric &xi) const
-{
- GINAC_ASSERT(bp!=0);
- return bp->smod(xi);
-}
-
ex basic::smod(const numeric &xi) const
{
return *this;
/** Create a symbol for replacing the expression "e" (or return a previously
* assigned symbol). An expression of the form "symbol == expression" is added
* to repl_lst and the symbol is returned.
- * @see ex::to_rational */
+ * @see basic::to_rational */
static ex replace_with_symbol(const ex &e, lst &repl_lst)
{
// Expression already in repl_lst? Then return the assigned symbol
dens.reserve(seq.size()+1);
epvector::const_iterator it = seq.begin(), itend = seq.end();
while (it != itend) {
- ex n = recombine_pair_to_ex(*it).bp->normal(sym_lst, repl_lst, level-1);
+ ex n = ex_to<basic>(recombine_pair_to_ex(*it)).normal(sym_lst, repl_lst, level-1);
nums.push_back(n.op(0));
dens.push_back(n.op(1));
it++;
}
- ex n = overall_coeff.bp->normal(sym_lst, repl_lst, level-1);
+ ex n = ex_to<numeric>(overall_coeff).normal(sym_lst, repl_lst, level-1);
nums.push_back(n.op(0));
dens.push_back(n.op(1));
GINAC_ASSERT(nums.size() == dens.size());
ex n;
epvector::const_iterator it = seq.begin(), itend = seq.end();
while (it != itend) {
- n = recombine_pair_to_ex(*it).bp->normal(sym_lst, repl_lst, level-1);
+ n = ex_to<basic>(recombine_pair_to_ex(*it)).normal(sym_lst, repl_lst, level-1);
num.push_back(n.op(0));
den.push_back(n.op(1));
it++;
}
- n = overall_coeff.bp->normal(sym_lst, repl_lst, level-1);
+ n = ex_to<numeric>(overall_coeff).normal(sym_lst, repl_lst, level-1);
num.push_back(n.op(0));
den.push_back(n.op(1));
throw(std::runtime_error("max recursion level reached"));
// Normalize basis and exponent (exponent gets reassembled)
- ex n_basis = basis.bp->normal(sym_lst, repl_lst, level-1);
- ex n_exponent = exponent.bp->normal(sym_lst, repl_lst, level-1);
+ ex n_basis = ex_to<basic>(basis).normal(sym_lst, repl_lst, level-1);
+ ex n_exponent = ex_to<basic>(exponent).normal(sym_lst, repl_lst, level-1);
n_exponent = n_exponent.op(0) / n_exponent.op(1);
if (n_exponent.info(info_flags::integer)) {
}
-/** Default implementation of ex::to_rational(). It replaces the object with a
- * temporary symbol.
- * @see ex::to_rational */
+/** Rationalization of non-rational functions.
+ * This function converts a general expression to a rational polynomial
+ * by replacing all non-rational subexpressions (like non-rational numbers,
+ * non-integer powers or functions like sin(), cos() etc.) to temporary
+ * symbols. This makes it possible to use functions like gcd() and divide()
+ * on non-rational functions by applying to_rational() on the arguments,
+ * calling the desired function and re-substituting the temporary symbols
+ * in the result. To make the last step possible, all temporary symbols and
+ * their associated expressions are collected in the list specified by the
+ * repl_lst parameter in the form {symbol == expression}, ready to be passed
+ * as an argument to ex::subs().
+ *
+ * @param repl_lst collects a list of all temporary symbols and their replacements
+ * @return rationalized expression */
ex basic::to_rational(lst &repl_lst) const
{
return replace_with_symbol(*this, repl_lst);
/** Implementation of ex::to_rational() for symbols. This returns the
- * unmodified symbol.
- * @see ex::to_rational */
+ * unmodified symbol. */
ex symbol::to_rational(lst &repl_lst) const
{
return *this;
/** Implementation of ex::to_rational() for a numeric. It splits complex
* numbers into re+I*im and replaces I and non-rational real numbers with a
- * temporary symbol.
- * @see ex::to_rational */
+ * temporary symbol. */
ex numeric::to_rational(lst &repl_lst) const
{
if (is_real()) {
/** Implementation of ex::to_rational() for powers. It replaces non-integer
- * powers by temporary symbols.
- * @see ex::to_rational */
+ * powers by temporary symbols. */
ex power::to_rational(lst &repl_lst) const
{
if (exponent.info(info_flags::integer))
}
-/** Implementation of ex::to_rational() for expairseqs.
- * @see ex::to_rational */
+/** Implementation of ex::to_rational() for expairseqs. */
ex expairseq::to_rational(lst &repl_lst) const
{
epvector s;
}
-/** Rationalization of non-rational functions.
- * This function converts a general expression to a rational polynomial
- * by replacing all non-rational subexpressions (like non-rational numbers,
- * non-integer powers or functions like sin(), cos() etc.) to temporary
- * symbols. This makes it possible to use functions like gcd() and divide()
- * on non-rational functions by applying to_rational() on the arguments,
- * calling the desired function and re-substituting the temporary symbols
- * in the result. To make the last step possible, all temporary symbols and
- * their associated expressions are collected in the list specified by the
- * repl_lst parameter in the form {symbol == expression}, ready to be passed
- * as an argument to ex::subs().
- *
- * @param repl_lst collects a list of all temporary symbols and their replacements
- * @return rationalized expression */
-ex ex::to_rational(lst &repl_lst) const
-{
- return bp->to_rational(repl_lst);
-}
-
-
} // namespace GiNaC