X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fnormal.cpp;h=f985573a5f6da669dba179ba91049f6b242c6cac;hp=369e2c656449ff296385397b1bce19c1b1b356af;hb=b617b5cf86e6f8ac01a339d9747c535257fcf8d0;hpb=94c15f8b02a5a9e274d3aedcefd76565861b4219 diff --git a/ginac/normal.cpp b/ginac/normal.cpp index 369e2c65..f985573a 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -36,7 +36,6 @@ #include "inifcns.h" #include "lst.h" #include "mul.h" -#include "ncmul.h" #include "numeric.h" #include "power.h" #include "relational.h" @@ -2119,9 +2118,9 @@ 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. +/** Get 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 */ @@ -2139,9 +2138,9 @@ ex ex::numer(void) const 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. +/** Get 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 */ @@ -2159,6 +2158,26 @@ ex ex::denom(void) const return e.op(1); } +/** Get numerator and denominator of an expression. If the expresison is not + * of the normal form "numerator/denominator", it is first converted to this + * form and then a list [numerator, denominator] is returned. + * + * @see ex::normal + * @return a list [numerator, denominator] */ +ex ex::numer_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.subs(sym_lst, repl_lst); + else + return e; +} + /** Default implementation of ex::to_rational(). It replaces the object with a * temporary symbol.