From 308cc279067413f46f2ceda60431ba61089d8368 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Thu, 10 Feb 2000 21:56:25 +0000 Subject: [PATCH] - ex::numer() and ex::denom() now make use of the new normal() - improved power::normal() a bit with respect to negative exponents --- ginac/ex.cpp | 72 --------------------------------------- ginac/ex.h | 12 +++---- ginac/normal.cpp | 87 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 81 insertions(+), 90 deletions(-) diff --git a/ginac/ex.cpp b/ginac/ex.cpp index ec6e9649..6c51fe6e 100644 --- a/ginac/ex.cpp +++ b/ginac/ex.cpp @@ -277,78 +277,6 @@ ex ex::coeff(const symbol & s, int n) const return bp->coeff(s,n); } -ex ex::numer(bool normalize) const -{ - ex n; - if (normalize) - n = normal(); - else - n = *this; - - // number - if (is_ex_exactly_of_type(n, numeric)) - return ex_to_numeric(n).numer(); - - // polynomial - if (n.info(info_flags::cinteger_polynomial)) - return n; - - // something^(-int) - if (is_ex_exactly_of_type(n, power) && n.op(1).info(info_flags::negint)) - return _ex1(); - - // something^(int) * something^(int) * ... - if (!is_ex_exactly_of_type(n, mul)) - return n; - ex res = _ex1(); - for (unsigned i=0; inormal(sym_lst, repl_lst, level-1); - return (new lst(power(n.op(0), exponent), power(n.op(1), exponent)))->setflag(status_flags::dynallocated); - } else if (exponent.info(info_flags::negint)) { - // Integer powers are distributed - ex n = basis.bp->normal(sym_lst, repl_lst, level-1); - return (new lst(power(n.op(1), -exponent), power(n.op(0), -exponent)))->setflag(status_flags::dynallocated); - } else { - // Non-integer powers are replaced by temporary symbol (after normalizing basis) - ex n = basis.bp->normal(sym_lst, repl_lst, level-1); - return (new lst(replace_with_symbol(power(n.op(0) / n.op(1), exponent), sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated); + // Normalize basis + ex n = basis.bp->normal(sym_lst, repl_lst, level-1); + + if (exponent.info(info_flags::integer)) { + + if (exponent.info(info_flags::positive)) { + + // (a/b)^n -> {a^n, b^n} + return (new lst(power(n.op(0), exponent), power(n.op(1), exponent)))->setflag(status_flags::dynallocated); + + } else if (exponent.info(info_flags::negint)) { + + // (a/b)^-n -> {b^n, a^n} + return (new lst(power(n.op(1), -exponent), power(n.op(0), -exponent)))->setflag(status_flags::dynallocated); + } + + } else { + if (exponent.info(info_flags::positive)) { + + // (a/b)^z -> {sym((a/b)^z), 1} + return (new lst(replace_with_symbol(power(n.op(0) / n.op(1), exponent), sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated); + + } else { + + if (n.op(1).is_equal(_ex1())) { + + // a^-x -> {1, sym(a^x)} + return (new lst(_ex1(), replace_with_symbol(power(n.op(0), -exponent), sym_lst, repl_lst)))->setflag(status_flags::dynallocated); + + } else { + + // (a/b)^-x -> {(b/a)^x, 1} + return (new lst(replace_with_symbol(power(n.op(1) / n.op(0), -exponent), sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated); + } + } } } @@ -1618,6 +1641,46 @@ ex ex::normal(int level) const return e.op(0) / e.op(1); } +/** Numerator of an expression. If the expression is not of the normal form + * "numerator/denominator", it is first converted to this form and then the + * numerator is returned. + * + * @see ex::normal + * @return numerator */ +ex ex::numer(void) const +{ + lst sym_lst, repl_lst; + + ex e = bp->normal(sym_lst, repl_lst, 0); + GINAC_ASSERT(is_ex_of_type(e, lst)); + + // Re-insert replaced symbols + if (sym_lst.nops() > 0) + return e.op(0).subs(sym_lst, repl_lst); + else + return e.op(0); +} + +/** Denominator of an expression. If the expression is not of the normal form + * "numerator/denominator", it is first converted to this form and then the + * denominator is returned. + * + * @see ex::normal + * @return denominator */ +ex ex::denom(void) const +{ + lst sym_lst, repl_lst; + + ex e = bp->normal(sym_lst, repl_lst, 0); + GINAC_ASSERT(is_ex_of_type(e, lst)); + + // Re-insert replaced symbols + if (sym_lst.nops() > 0) + return e.op(1).subs(sym_lst, repl_lst); + else + return e.op(1); +} + #ifndef NO_NAMESPACE_GINAC } // namespace GiNaC #endif // ndef NO_NAMESPACE_GINAC -- 2.45.0