]> www.ginac.de Git - ginac.git/commitdiff
- carried on with felonious plot about making ex::bp private.
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Mon, 20 Aug 2001 22:00:45 +0000 (22:00 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Mon, 20 Aug 2001 22:00:45 +0000 (22:00 +0000)
ginac/add.cpp
ginac/constant.cpp
ginac/ex.h
ginac/matrix.cpp
ginac/mul.cpp
ginac/normal.cpp
ginac/power.cpp

index 0551dbc485fd8156bcbfc06364034115d2c86101..c14c1587481ae6c0806ceecd078138ab4f3a928d 100644 (file)
@@ -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<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
@@ -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)
index 60c3be247dea1e47c2123d37921026e5fca523de..844a08a285f073acc32b28aeb8985e9def6f26e6 100644 (file)
@@ -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<basic>(s)) ? 1 : 0;
 }
 
 int constant::ldegree(const ex & s) const
 {
-       return is_equal(*s.bp) ? 1 : 0;
+       return is_equal(ex_to<basic>(s)) ? 1 : 0;
 }
 
 ex constant::coeff(const ex & s, int n) const
 {
-       if (is_equal(*s.bp))
+       if (is_equal(ex_to<basic>(s)))
                return n==1 ? _ex1() : _ex0();
        else
                return n==0 ? *this : _ex0();
index 88f4e2ef40fd439e5afa349f57a3fe28dc60ebe3..aefb6af7808dd3c6171f95ed60069dba14853071 100644 (file)
@@ -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); }
index 60869f09fa709bbd17b051206fa4b32c29db0e73..e9c68175897daa5222ee8b0750fcc85333cb05cd 100644 (file)
@@ -229,7 +229,7 @@ ex matrix::subs(const lst & ls, const lst & lr, bool no_pattern) const
                for (unsigned c=0; c<col; ++c)
                        m2[r*col+c] = m[r*col+c].subs(ls, lr, no_pattern);
 
-       return ex(matrix(row, col, m2)).bp->basic::subs(ls, lr, no_pattern);
+       return matrix(row, col, m2).basic::subs(ls, lr, no_pattern);
 }
 
 // protected
index cac1ffb7a14e99b2c9a5825d3aac7ac17dd5eb5d..542e80236b048d9d5acdc3596e441eaa672775a3 100644 (file)
@@ -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 << "*";
                }
 
index 7a52c71d2914d331a0be314dd100a9e46dc155e6..c948680f6cb5231d4c3b3858a5a1b0500c030e02 100644 (file)
@@ -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<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++)
@@ -170,7 +170,7 @@ static void add_symbol(const symbol *s, sym_desc_vec &v)
 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);
@@ -1256,19 +1256,12 @@ numeric mul::max_coefficient(void) const
 }
 
 
-/** 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;
@@ -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<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());
@@ -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<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));
 
@@ -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<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)) {
@@ -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
index 4959525c4887223cecbeb9237e98ed1ae2f6e458..66181941feef1fbeb407922a2006b9263cf5d9df 100644 (file)
@@ -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