]> www.ginac.de Git - ginac.git/commitdiff
* Methods of class ex which do absolutely nothing than type dispatch should
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Mon, 7 May 2001 20:41:41 +0000 (20:41 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Mon, 7 May 2001 20:41:41 +0000 (20:41 +0000)
  be inlined for obvious reasons.

ginac/basic.cpp
ginac/ex.cpp
ginac/ex.h
ginac/inifcns_gamma.cpp
ginac/power.cpp

index a92dd9ede24b8e7f2ae37657aa3e082b031c7115..5b0b180378bc24df6bd95dbf671ece9f95bc6e56 100644 (file)
@@ -542,7 +542,7 @@ ex basic::subs(const ex & e) const
        for (unsigned i=0; i<e.nops(); i++) {
                ex r = e.op(i);
                if (!r.info(info_flags::relation_equal)) {
        for (unsigned i=0; i<e.nops(); i++) {
                ex r = e.op(i);
                if (!r.info(info_flags::relation_equal)) {
-                       throw(std::invalid_argument("basic::subs(ex): argument must be a list or equations"));
+                       throw(std::invalid_argument("basic::subs(ex): argument must be a list of equations"));
                }
                ls.append(r.op(0));
                lr.append(r.op(1));
                }
                ls.append(r.op(0));
                lr.append(r.op(1));
index 646053b8001a89b2619841cd038b36d760e3a8a8..77c7983300ed10edc670ea076be17a481be8e313 100644 (file)
@@ -112,17 +112,6 @@ void ex::dbgprinttree(void) const
        bp->dbgprinttree();
 }
 
        bp->dbgprinttree();
 }
 
-bool ex::info(unsigned inf) const
-{
-       return bp->info(inf);
-}
-
-unsigned ex::nops() const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->nops();
-}
-
 ex ex::expand(unsigned options) const
 {
        GINAC_ASSERT(bp!=0);
 ex ex::expand(unsigned options) const
 {
        GINAC_ASSERT(bp!=0);
@@ -132,48 +121,6 @@ ex ex::expand(unsigned options) const
                return bp->expand(options);
 }
 
                return bp->expand(options);
 }
 
-bool ex::has(const ex & other) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->has(other);
-}
-
-int ex::degree(const ex & s) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->degree(s);
-}
-
-int ex::ldegree(const ex & s) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->ldegree(s);
-}
-
-ex ex::coeff(const ex & s, int n) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->coeff(s,n);
-}
-
-ex ex::collect(const ex & s, bool distributed) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->collect(s, distributed);
-}
-
-ex ex::eval(int level) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->eval(level);
-}
-
-ex ex::evalf(int level) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->evalf(level);
-}
-
 /** Compute partial derivative of an expression.
  *
  *  @param s  symbol by which the expression is derived
 /** Compute partial derivative of an expression.
  *
  *  @param s  symbol by which the expression is derived
@@ -189,25 +136,6 @@ ex ex::diff(const symbol & s, unsigned nth) const
                return bp->diff(s, nth);
 }
 
                return bp->diff(s, nth);
 }
 
-ex ex::subs(const lst & ls, const lst & lr) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->subs(ls,lr);
-}
-
-ex ex::subs(const ex & e) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->subs(e);
-}
-
-/** Return a vector containing the free indices of the object. */
-exvector ex::get_free_indices(void) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->get_free_indices();
-}
-
 /** Simplify/canonicalize expression containing indexed objects. This
  *  performs contraction of dummy indices where possible and checks whether
  *  the free indices in sums are consistent.
 /** Simplify/canonicalize expression containing indexed objects. This
  *  performs contraction of dummy indices where possible and checks whether
  *  the free indices in sums are consistent.
@@ -230,12 +158,6 @@ ex ex::simplify_indexed(const scalar_products & sp) const
        return GiNaC::simplify_indexed(*this, sp);
 }
 
        return GiNaC::simplify_indexed(*this, sp);
 }
 
-ex ex::simplify_ncmul(const exvector & v) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->simplify_ncmul(v);
-}
-
 ex ex::operator[](const ex & index) const
 {
        debugmsg("ex operator[ex]",LOGLEVEL_OPERATOR);
 ex ex::operator[](const ex & index) const
 {
        debugmsg("ex operator[ex]",LOGLEVEL_OPERATOR);
@@ -250,14 +172,6 @@ ex ex::operator[](int i) const
        return (*bp)[i];
 }
 
        return (*bp)[i];
 }
 
-/** Return operand/member at position i. */
-ex ex::op(int i) const
-{
-       debugmsg("ex op()",LOGLEVEL_MEMBER_FUNCTION);
-       GINAC_ASSERT(bp!=0);
-       return bp->op(i);
-}
-
 /** Return modifyable operand/member at position i. */
 ex & ex::let_op(int i)
 {
 /** Return modifyable operand/member at position i. */
 ex & ex::let_op(int i)
 {
@@ -271,7 +185,8 @@ ex & ex::let_op(int i)
 ex ex::lhs(void) const
 {
        debugmsg("ex lhs()",LOGLEVEL_MEMBER_FUNCTION);
 ex ex::lhs(void) const
 {
        debugmsg("ex lhs()",LOGLEVEL_MEMBER_FUNCTION);
-       GINAC_ASSERT(is_ex_of_type(*this,relational));
+       if (!is_ex_of_type(*this,relational))
+               throw std::runtime_error("ex::lhs(): not a relation");
        return (*static_cast<relational *>(bp)).lhs();
 }
 
        return (*static_cast<relational *>(bp)).lhs();
 }
 
@@ -279,28 +194,11 @@ ex ex::lhs(void) const
 ex ex::rhs(void) const
 {
        debugmsg("ex rhs()",LOGLEVEL_MEMBER_FUNCTION);
 ex ex::rhs(void) const
 {
        debugmsg("ex rhs()",LOGLEVEL_MEMBER_FUNCTION);
-       GINAC_ASSERT(is_ex_of_type(*this,relational));
+       if (!is_ex_of_type(*this,relational))
+               throw std::runtime_error("ex::rhs(): not a relation");
        return (*static_cast<relational *>(bp)).rhs();
 }
 
        return (*static_cast<relational *>(bp)).rhs();
 }
 
-unsigned ex::return_type(void) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->return_type();
-}
-
-unsigned ex::return_type_tinfo(void) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->return_type_tinfo();
-}
-
-unsigned ex::gethash(void) const
-{
-       GINAC_ASSERT(bp!=0);
-       return bp->gethash();
-}
-
 /** Used internally by operator+() to add two ex objects together. */
 ex ex::exadd(const ex & rh) const
 {
 /** Used internally by operator+() to add two ex objects together. */
 ex ex::exadd(const ex & rh) const
 {
index 9d054f52d3f65c4a39346622f165e2939945b88e..8ade899b06136f1479a982834547fae35503a3ba 100644 (file)
@@ -80,13 +80,13 @@ public:
        void printtree(std::ostream & os) const;
        void dbgprint(void) const;
        void dbgprinttree(void) const;
        void printtree(std::ostream & os) const;
        void dbgprint(void) const;
        void dbgprinttree(void) const;
-       bool info(unsigned inf) const;
-       unsigned nops() const;
+       bool info(unsigned inf) const { return bp->info(inf); }
+       unsigned nops() const { return bp->nops(); }
        ex expand(unsigned options=0) const;
        ex expand(unsigned options=0) const;
-       bool has(const ex & other) const;
-       int degree(const ex & s) const;
-       int ldegree(const ex & s) const;
-       ex coeff(const ex & s, int n=1) const;
+       bool has(const ex & other) const { return bp->has(other); }
+       int degree(const ex & s) const { return bp->degree(s); }
+       int ldegree(const ex & s) const { return bp->ldegree(s); }
+       ex coeff(const ex & s, int n = 1) const { return bp->coeff(s, n); }
        ex lcoeff(const ex & s) const { return coeff(s, degree(s)); }
        ex tcoeff(const ex & s) const { return coeff(s, ldegree(s)); }
        ex numer(void) const;
        ex lcoeff(const ex & s) const { return coeff(s, degree(s)); }
        ex tcoeff(const ex & s) const { return coeff(s, ldegree(s)); }
        ex numer(void) const;
@@ -100,20 +100,20 @@ public:
        ex to_rational(lst &repl_lst) const;
        ex smod(const numeric &xi) const;
        numeric max_coefficient(void) const;
        ex to_rational(lst &repl_lst) const;
        ex smod(const numeric &xi) const;
        numeric max_coefficient(void) const;
-       ex collect(const ex & s, bool distributed = false) const;
-       ex eval(int level = 0) const;
-       ex evalf(int level = 0) 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); }
+       ex evalf(int level = 0) const { return bp->evalf(level); }
        ex diff(const symbol & s, unsigned nth = 1) const;
        ex series(const ex & r, int order, unsigned options = 0) const;
        ex diff(const symbol & s, unsigned nth = 1) const;
        ex series(const ex & r, int order, unsigned options = 0) const;
-       ex subs(const lst & ls, const lst & lr) const;
-       ex subs(const ex & e) const;
-       exvector get_free_indices(void) const;
+       ex subs(const lst & ls, const lst & lr) const { return bp->subs(ls, lr); }
+       ex subs(const ex & e) const { return bp->subs(e); }
+       exvector get_free_indices(void) const { return bp->get_free_indices(); }
        ex simplify_indexed(void) const;
        ex simplify_indexed(const scalar_products & sp) const;
        ex simplify_indexed(void) const;
        ex simplify_indexed(const scalar_products & sp) const;
-       ex simplify_ncmul(const exvector & v) const;
+       ex simplify_ncmul(const exvector & v) const { return bp->simplify_ncmul(v); }
        ex operator[](const ex & index) const;
        ex operator[](int i) const;
        ex operator[](const ex & index) const;
        ex operator[](int i) const;
-       ex op(int i) const;
+       ex op(int i) const { return bp->op(i); }
        ex & let_op(int i);
        ex lhs(void) const;
        ex rhs(void) const;
        ex & let_op(int i);
        ex lhs(void) const;
        ex rhs(void) const;
@@ -121,9 +121,9 @@ public:
        bool is_equal(const ex & other) const;
        bool is_zero(void) const { return is_equal(_ex0()); }
        
        bool is_equal(const ex & other) const;
        bool is_zero(void) const { return is_equal(_ex0()); }
        
-       unsigned return_type(void) const;
-       unsigned return_type_tinfo(void) const;
-       unsigned gethash(void) const;
+       unsigned return_type(void) const { return bp->return_type(); }
+       unsigned return_type_tinfo(void) const { return bp->return_type_tinfo(); }
+       unsigned gethash(void) const { return bp->gethash(); }
        
        ex exadd(const ex & rh) const;
        ex exmul(const ex & rh) const;
        
        ex exadd(const ex & rh) const;
        ex exmul(const ex & rh) const;
index 014ae939ee260e542c0a3828a80f9874a5bdd553..c4f4f1a9aec248c2b1c1aaba4549925188e829de 100644 (file)
@@ -61,7 +61,7 @@ static ex lgamma_eval(const ex & x)
                if (x.info(info_flags::integer)) {
                        // lgamma(n) -> log((n-1)!) for postitive n
                        if (x.info(info_flags::posint))
                if (x.info(info_flags::integer)) {
                        // lgamma(n) -> log((n-1)!) for postitive n
                        if (x.info(info_flags::posint))
-                               return log(factorial(x.exadd(_ex_1())));
+                               return log(factorial(x + _ex_1()));
                        else
                                throw (pole_error("lgamma_eval(): logarithmic pole",0));
                }
                        else
                                throw (pole_error("lgamma_eval(): logarithmic pole",0));
                }
index 6b8c184ef7a1e031bd4347771aa5b370120d91dc..660a9faba03824416edb000f86be96a655e96b06 100644 (file)
@@ -71,6 +71,8 @@ power::power(const ex & lh, const ex & rh) : basic(TINFO_power), basis(lh), expo
        GINAC_ASSERT(basis.return_type()==return_types::commutative);
 }
 
        GINAC_ASSERT(basis.return_type()==return_types::commutative);
 }
 
+/** Ctor from an ex and a bare numeric.  This is somewhat more efficient than
+ *  the normal ctor from two ex whenever it can be used. */
 power::power(const ex & lh, const numeric & rh) : basic(TINFO_power), basis(lh), exponent(rh)
 {
        debugmsg("power ctor from ex,numeric",LOGLEVEL_CONSTRUCT);
 power::power(const ex & lh, const numeric & rh) : basic(TINFO_power), basis(lh), exponent(rh)
 {
        debugmsg("power ctor from ex,numeric",LOGLEVEL_CONSTRUCT);