]> www.ginac.de Git - ginac.git/commitdiff
- added non-const operator[]
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 20 Feb 2003 03:33:18 +0000 (03:33 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 20 Feb 2003 03:33:18 +0000 (03:33 +0000)
- removed let_op() for power and relational
- removed redundant matrix::op()

14 files changed:
ginac/basic.cpp
ginac/basic.h
ginac/clifford.cpp
ginac/ex.cpp
ginac/ex.h
ginac/expairseq.cpp
ginac/matrix.cpp
ginac/matrix.h
ginac/power.cpp
ginac/power.h
ginac/pseries.cpp
ginac/pseries.h
ginac/relational.cpp
ginac/relational.h

index 74ffe98d089bc08907f002ec487116cd0b5f7ad8..9fd739822db5ec257a68efe2f2b0e67e592147ce 100644 (file)
@@ -185,7 +185,7 @@ ex basic::op(int i) const
 /** Return modifyable operand/member at position i. */
 ex & basic::let_op(int i)
 {
-       throw(std::out_of_range("op() out of range"));
+       throw(std::runtime_error(std::string("let_op() not implemented by ") + class_name()));
 }
 
 ex basic::operator[](const ex & index) const
@@ -201,6 +201,19 @@ ex basic::operator[](int i) const
        return op(i);
 }
 
+ex & basic::operator[](const ex & index)
+{
+       if (is_exactly_a<numeric>(index))
+               return let_op(ex_to<numeric>(index).to_int());
+
+       throw(std::invalid_argument("non-numeric indices not supported by this type"));
+}
+
+ex & basic::operator[](int i)
+{
+       return let_op(i);
+}
+
 /** Test for occurrence of a pattern.  An object 'has' a pattern if it matches
  *  the pattern itself or one of the children 'has' it.  As a consequence
  *  (according to the definition of children) given e=x+y+z, e.has(x) is true
index 320b247fd7d168587b58f6a5f96fe5b64ae3ecff..57cf573416a537c73fe1c98161cda1066c45f3a7 100644 (file)
@@ -98,9 +98,11 @@ public: // only const functions please (may break reference counting)
        virtual bool info(unsigned inf) const;
        virtual unsigned nops() const;
        virtual ex op(int i) const;
-       virtual ex & let_op(int i);
        virtual ex operator[](const ex & index) const;
        virtual ex operator[](int i) const;
+       virtual ex & let_op(int i);
+       virtual ex & operator[](const ex & index);
+       virtual ex & operator[](int i);
        virtual ex expand(unsigned options = 0) const;
        virtual bool has(const ex & other) const;
        virtual ex map(map_function & f) const;
index f1c710d5ac009c57d644a7b968c9ed8054b3a636..0918fe42d391a89eb60b3eed4de4fabda3f1e274 100644 (file)
@@ -705,7 +705,7 @@ ex canonicalize_clifford(const ex & e)
                        // Expand product, if necessary
                        ex rhs_expanded = rhs.expand();
                        if (!is_a<ncmul>(rhs_expanded)) {
-                               srl.let_op(i) = (lhs == canonicalize_clifford(rhs_expanded));
+                               srl[i] = (lhs == canonicalize_clifford(rhs_expanded));
                                continue;
 
                        } else if (!is_a<clifford>(rhs.op(0)))
@@ -732,7 +732,7 @@ ex canonicalize_clifford(const ex & e)
                                        it[0] = save1;
                                        it[1] = save0;
                                        sum -= ncmul(v, true);
-                                       srl.let_op(i) = (lhs == canonicalize_clifford(sum));
+                                       srl[i] = (lhs == canonicalize_clifford(sum));
                                        goto next_sym;
                                }
                                ++it;
index 8ed63d808cd52d9ecad6f7a5ab80622cc478e728..d4c37a0a113b1fa3557582d46fb97b5d2f1f2058 100644 (file)
@@ -130,24 +130,26 @@ bool ex::find(const ex & pattern, lst & found) const
        return any_found;
 }
 
-ex ex::operator[](const ex & index) const
+/** Return modifyable operand/member at position i. */
+ex & ex::let_op(int i)
 {
+       makewriteable();
        GINAC_ASSERT(bp!=0);
-       return (*bp)[index];
+       return bp->let_op(i);
 }
 
-ex ex::operator[](int i) const
+ex & ex::operator[](const ex & index)
 {
+       makewriteable();
        GINAC_ASSERT(bp!=0);
-       return (*bp)[i];
+       return (*bp)[index];
 }
 
-/** Return modifyable operand/member at position i. */
-ex & ex::let_op(int i)
+ex & ex::operator[](int i)
 {
        makewriteable();
        GINAC_ASSERT(bp!=0);
-       return bp->let_op(i);
+       return (*bp)[i];
 }
 
 /** Left hand side of relational expression. */
index 9d592c079dacea5ea52d6f1b6369142a9e5ef463..3d79c7acc7786d1b63244e1af15877926f347a6e 100644 (file)
@@ -159,10 +159,12 @@ public:
        ex symmetrize_cyclic(void) const;
        ex symmetrize_cyclic(const lst & l) const;
        ex eval_ncmul(const exvector & v) const { return bp->eval_ncmul(v); }
-       ex operator[](const ex & index) const;
-       ex operator[](int i) const;
        ex op(int i) const { return bp->op(i); }
+       ex operator[](const ex & index) const { return (*bp)[index]; }
+       ex operator[](int i) const { return (*bp)[i]; }
        ex & let_op(int i);
+       ex & operator[](const ex & index);
+       ex & operator[](int i);
        ex lhs(void) const;
        ex rhs(void) const;
        int compare(const ex & other) const;
index 70d91ebc379b3e334091e0f8986d47e76ca13b8e..228da90c6c61419d915a815599e4bdc039abdc1d 100644 (file)
@@ -292,9 +292,9 @@ ex expairseq::op(int i) const
        return overall_coeff;
 }
 
-ex &expairseq::let_op(int i)
+ex & expairseq::let_op(int i)
 {
-       throw(std::logic_error("let_op not defined for expairseq and derived classes (add,mul,...)"));
+       throw(std::logic_error("let_op not defined for expairseq and derived classes (add, mul, ...)"));
 }
 
 ex expairseq::map(map_function &f) const
index 49c37b1075e323327bb398e625f863885bcca2a3..57cd8894bab85d1aa17d60fd28b615c878b08b7b 100644 (file)
@@ -198,12 +198,6 @@ unsigned matrix::nops() const
        return row*col;
 }
 
-/** returns matrix entry at position (i/col, i%col). */
-ex matrix::op(int i) const
-{
-       return m[i];
-}
-
 /** returns matrix entry at position (i/col, i%col). */
 ex & matrix::let_op(int i)
 {
index 7fabe7099d0bdcd9e33a2f42f499307aba4a261e..5eb816bb1aeb1c1cfbb839670ed6f9d855026635 100644 (file)
@@ -45,7 +45,6 @@ public:
 public:
        void print(const print_context & c, unsigned level = 0) const;
        unsigned nops() const;
-       ex op(int i) const;
        ex & let_op(int i);
        ex eval(int level=0) const;
        ex evalm(void) const {return *this;}
index febcc4a7dff26d736f74ec7bdd5d3a25482db80c..718a26f745508a64eb97f82daf861aa0822210eb 100644 (file)
@@ -233,7 +233,7 @@ unsigned power::nops() const
        return 2;
 }
 
-ex & power::let_op(int i)
+ex power::op(int i) const
 {
        GINAC_ASSERT(i>=0);
        GINAC_ASSERT(i<2);
index 6759f597d516550c2519e06a183c9f8e9c913748..7a192c414756982f5ce5e990c58486951c40308d 100644 (file)
@@ -52,7 +52,7 @@ public:
        unsigned precedence(void) const {return 60;}
        bool info(unsigned inf) const;
        unsigned nops() const;
-       ex & let_op(int i);
+       ex op(int i) const;
        ex map(map_function & f) const;
        int degree(const ex & s) const;
        int ldegree(const ex & s) const;
index 1566d6ea5f550e1527d58485426b95fad3b154ef..6077fd72c003208b3c990cd83831ce754f62e969 100644 (file)
@@ -267,9 +267,9 @@ ex pseries::op(int i) const
        return seq[i].rest * power(var - point, seq[i].coeff);
 }
 
-ex &pseries::let_op(int i)
+ex & pseries::let_op(int i)
 {
-       throw (std::logic_error("let_op not defined for pseries"));
+       throw (std::logic_error("let_op() not defined for pseries"));
 }
 
 /** Return degree of highest power of the series.  This is usually the exponent
index a7f9037b80ff3d8caa68c060a21db4d0425f7b7d..37ac579633456ffa21b2756ff087a33c27f5ce98 100644 (file)
@@ -46,7 +46,7 @@ public:
        unsigned precedence(void) const {return 38;} // for clarity just below add::precedence
        unsigned nops(void) const;
        ex op(int i) const;
-       ex &let_op(int i);
+       ex & let_op(int i);
        int degree(const ex &s) const;
        int ldegree(const ex &s) const;
        ex coeff(const ex &s, int n = 1) const;
index dc7554a62d524bd7d4320d22071d195ca2a51378..7c395eeaa0085eaef49b4d6bdccd4fc2a84627ef 100644 (file)
@@ -165,7 +165,7 @@ unsigned relational::nops() const
        return 2;
 }
 
-ex & relational::let_op(int i)
+ex relational::op(int i) const
 {
        GINAC_ASSERT(i>=0);
        GINAC_ASSERT(i<2);
@@ -173,6 +173,11 @@ ex & relational::let_op(int i)
        return i==0 ? lh : rh;
 }
 
+ex relational::map(map_function & f) const
+{
+       return (new relational(f(lh), f(rh), o))->setflag(status_flags::dynallocated);
+}
+
 ex relational::eval(int level) const
 {
        if (level==1)
index ebad1f76bc84a34fae5e9fd3df81b24690d73bf4..133a25f3d9e882af2af4a9fc64b83088f8a419b1 100644 (file)
@@ -55,7 +55,8 @@ public:
        unsigned precedence(void) const {return 20;}
        bool info(unsigned inf) const;
        unsigned nops() const;
-       ex & let_op(int i);
+       ex op(int i) const;
+       ex map(map_function & f) const;
        ex eval(int level=0) const;
 
 protected: