From: Richard Kreckel Date: Mon, 20 Aug 2001 22:00:45 +0000 (+0000) Subject: - carried on with felonious plot about making ex::bp private. X-Git-Tag: release_0-9-4~13 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=2862087ce55d944c1ac5d37283944b2b37507fd2 - carried on with felonious plot about making ex::bp private. --- diff --git a/ginac/add.cpp b/ginac/add.cpp index 0551dbc4..c14c1587 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -131,23 +131,23 @@ void add::print(const print_context & c, unsigned level) const // 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(it->coeff).numer().compare(_num1()) == 0) { - it->rest.bp->print(c, precedence()); + it->rest.print(c, precedence()); c.s << "/"; ex_to(it->coeff).denom().print(c, precedence()); } else if (ex_to(it->coeff).numer().compare(_num_1()) == 0) { c.s << "-"; - it->rest.bp->print(c, precedence()); + it->rest.print(c, precedence()); c.s << "/"; ex_to(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 @@ -159,7 +159,7 @@ void add::print(const print_context & c, unsigned level) const 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) diff --git a/ginac/constant.cpp b/ginac/constant.cpp index 60c3be24..844a08a2 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -152,17 +152,17 @@ void constant::print(const print_context & c, unsigned level) const int constant::degree(const ex & s) const { - return is_equal(*s.bp) ? 1 : 0; + return is_equal(ex_to(s)) ? 1 : 0; } int constant::ldegree(const ex & s) const { - return is_equal(*s.bp) ? 1 : 0; + return is_equal(ex_to(s)) ? 1 : 0; } ex constant::coeff(const ex & s, int n) const { - if (is_equal(*s.bp)) + if (is_equal(ex_to(s))) return n==1 ? _ex1() : _ex0(); else return n==0 ? *this : _ex0(); diff --git a/ginac/ex.h b/ginac/ex.h index 88f4e2ef..aefb6af7 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -98,8 +98,8 @@ public: ex primpart(const symbol &x) const; ex primpart(const symbol &x, const ex &cont) const; ex normal(int level = 0) const; - ex to_rational(lst &repl_lst) const; - ex smod(const numeric &xi) const; + ex to_rational(lst &repl_lst) const { return bp->to_rational(repl_lst); } + ex smod(const numeric &xi) const { return bp->smod(xi); } numeric max_coefficient(void) const; ex collect(const ex & s, bool distributed = false) const { return bp->collect(s, distributed); } ex eval(int level = 0) const { return bp->eval(level); } diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index 60869f09..e9c68175 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -229,7 +229,7 @@ ex matrix::subs(const lst & ls, const lst & lr, bool no_pattern) const for (unsigned c=0; cbasic::subs(ls, lr, no_pattern); + return matrix(row, col, m2).basic::subs(ls, lr, no_pattern); } // protected diff --git a/ginac/mul.cpp b/ginac/mul.cpp index cac1ffb7..542e8023 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -141,7 +141,7 @@ void mul::print(const print_context & c, unsigned level) const c.s << "("; if (!overall_coeff.is_equal(_ex1())) { - overall_coeff.bp->print(c, precedence()); + overall_coeff.print(c, precedence()); c.s << "*"; } diff --git a/ginac/normal.cpp b/ginac/normal.cpp index 7a52c71d..c948680f 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -93,7 +93,7 @@ static struct _stat_print { static bool get_first_symbol(const ex &e, const symbol *&x) { if (is_ex_exactly_of_type(e, symbol)) { - x = static_cast(e.bp); + x = &ex_to(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.bp), v); + add_symbol(&ex_to(e), v); } else if (is_ex_exactly_of_type(e, add) || is_ex_exactly_of_type(e, mul)) { for (unsigned i=0; ismod(xi); -} - ex basic::smod(const numeric &xi) const { return *this; @@ -1918,7 +1911,7 @@ static ex replace_with_symbol(const ex &e, lst &sym_lst, lst &repl_lst) /** 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 @@ -2066,12 +2059,12 @@ ex add::normal(lst &sym_lst, lst &repl_lst, int level) const 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(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(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()); @@ -2125,12 +2118,12 @@ ex mul::normal(lst &sym_lst, lst &repl_lst, int level) const 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(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(overall_coeff).normal(sym_lst, repl_lst, level-1); num.push_back(n.op(0)); den.push_back(n.op(1)); @@ -2152,8 +2145,8 @@ ex power::normal(lst &sym_lst, lst &repl_lst, int level) const 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(basis).normal(sym_lst, repl_lst, level-1); + ex n_exponent = ex_to(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)) { @@ -2304,9 +2297,20 @@ ex ex::numer_denom(void) const } -/** 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); @@ -2314,8 +2318,7 @@ ex basic::to_rational(lst &repl_lst) const /** 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; @@ -2324,8 +2327,7 @@ ex symbol::to_rational(lst &repl_lst) const /** 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()) { @@ -2343,8 +2345,7 @@ ex numeric::to_rational(lst &repl_lst) const /** 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)) @@ -2354,8 +2355,7 @@ ex power::to_rational(lst &repl_lst) const } -/** 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; @@ -2374,24 +2374,4 @@ ex expairseq::to_rational(lst &repl_lst) const } -/** 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 diff --git a/ginac/power.cpp b/ginac/power.cpp index 4959525c..66181941 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -520,7 +520,7 @@ ex power::subs(const lst & ls, const lst & lr, bool no_pattern) const && are_ex_trivially_equal(exponent, subsed_exponent)) return basic::subs(ls, lr, no_pattern); else - return ex(power(subsed_basis, subsed_exponent)).bp->basic::subs(ls, lr, no_pattern); + return power(subsed_basis, subsed_exponent).basic::subs(ls, lr, no_pattern); } ex power::simplify_ncmul(const exvector & v) const