- maximum number of arguments for lists bumped to 16 (for making 4x4 matrices)
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 7 Jun 2001 20:09:21 +0000 (20:09 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 7 Jun 2001 20:09:21 +0000 (20:09 +0000)
- added non-const operator() for setting matrix elements

ginac/basic.cpp
ginac/container.pl
ginac/inifcns.cpp
ginac/matrix.cpp
ginac/matrix.h

index eb8e8ca90605c12d7a84f0ed4608353293acfcb8..2b1b68b0cf82c193b958c0864df2f652e948a74a 100644 (file)
@@ -363,7 +363,7 @@ ex basic::evalf(int level) const
        return *this;
 }
 
-/** Evaluate sums and products of matrices. */
+/** Evaluate sums, products and integer powers of matrices. */
 ex basic::evalm(void) const
 {
        if (nops() == 0)
index 93c5918294b25f6213445f2a1ea277d0875235df..480d5a565cd32caad51a9b4011dc3a1d54ca811c 100755 (executable)
@@ -13,7 +13,7 @@ if ($ARGV[0] eq 'lst') {
 if ($#ARGV==1) {
        $maxargs=$ARGV[1];
 } else {
-       $maxargs=15; # must be greater or equal than the value used in function.pl
+       $maxargs=16; # must be greater or equal than the value used in function.pl
 }
 
 if ($type eq 'exprseq') {
index de5522ad119ef9e2b30a392a8122bb8e74683f1c..4d1c978b716a6b2c2ba456acd26a2d7dfcf66b02 100644 (file)
@@ -475,15 +475,15 @@ ex lsolve(const ex &eqns, const ex &symbols)
                for (unsigned c=0; c<symbols.nops(); c++) {
                        ex co = eq.coeff(ex_to_symbol(symbols.op(c)),1);
                        linpart -= co*symbols.op(c);
-                       sys.set(r,c,co);
+                       sys(r,c) = co;
                }
                linpart = linpart.expand();
-               rhs.set(r,0,-linpart);
+               rhs(r,0) = -linpart;
        }
        
        // test if system is linear and fill vars matrix
        for (unsigned i=0; i<symbols.nops(); i++) {
-               vars.set(i,0,symbols.op(i));
+               vars(i,0) = symbols.op(i);
                if (sys.has(symbols.op(i)))
                        throw(std::logic_error("lsolve: system is not linear"));
                if (rhs.has(symbols.op(i)))
index 28c2f1d25a853faf7750220d1a82867d9f425775..9998a3918ab7d50eb3c4685aad29b952db04c392 100644 (file)
@@ -636,7 +636,7 @@ matrix matrix::pow(const ex & expn) const
                        }
                        matrix result(row,col);
                        for (unsigned r=0; r<row; ++r)
-                               result.set(r,r,_ex1());
+                               result(r,r) = _ex1();
                        numeric b(1);
                        // this loop computes the representation of k in base 2 and multiplies
                        // the factors whenever needed:
@@ -656,7 +656,7 @@ matrix matrix::pow(const ex & expn) const
 }
 
 
-/** operator() to access elements.
+/** operator() to access elements for reading.
  *
  *  @param ro row of element
  *  @param co column of element
@@ -670,19 +670,19 @@ const ex & matrix::operator() (unsigned ro, unsigned co) const
 }
 
 
-/** Set individual elements manually.
+/** operator() to access elements for writing.
  *
+ *  @param ro row of element
+ *  @param co column of element
  *  @exception range_error (index out of range) */
-matrix & matrix::set(unsigned ro, unsigned co, ex value)
+ex & matrix::operator() (unsigned ro, unsigned co)
 {
        if (ro>=row || co>=col)
-               throw (std::range_error("matrix::set(): index out of range"));
-       if (value.return_type() != return_types::commutative)
-               throw std::runtime_error("matrix::set(): non-commutative argument");
-    
+               throw (std::range_error("matrix::operator(): index out of range"));
+
        ensure_if_modifiable();
-       m[ro*col+co] = value;
-       return *this;
+       clearflag(status_flags::hash_calculated);
+       return m[ro*col+co];
 }
 
 
@@ -924,7 +924,7 @@ matrix matrix::inverse(void) const
        // First populate the identity matrix supposed to become the right hand side.
        matrix identity(row,col);
        for (unsigned i=0; i<row; ++i)
-               identity.set(i,i,_ex1());
+               identity(i,i) = _ex1();
        
        // Populate a dummy matrix of variables, just because of compatibility with
        // matrix::solve() which wants this (for compatibility with under-determined
@@ -932,7 +932,7 @@ matrix matrix::inverse(void) const
        matrix vars(row,col);
        for (unsigned r=0; r<row; ++r)
                for (unsigned c=0; c<col; ++c)
-                       vars.set(r,c,symbol());
+                       vars(r,c) = symbol();
        
        matrix sol(row,col);
        try {
@@ -1032,19 +1032,18 @@ matrix matrix::solve(const matrix & vars,
                                // assign solutions for vars between fnz+1 and
                                // last_assigned_sol-1: free parameters
                                for (unsigned c=fnz; c<last_assigned_sol-1; ++c)
-                                       sol.set(c,co,vars.m[c*p+co]);
+                                       sol(c,co) = vars.m[c*p+co];
                                ex e = aug.m[r*(n+p)+n+co];
                                for (unsigned c=fnz; c<n; ++c)
                                        e -= aug.m[r*(n+p)+c]*sol.m[c*p+co];
-                               sol.set(fnz-1,co,
-                                               (e/(aug.m[r*(n+p)+(fnz-1)])).normal());
+                               sol(fnz-1,co) = (e/(aug.m[r*(n+p)+(fnz-1)])).normal();
                                last_assigned_sol = fnz;
                        }
                }
                // assign solutions for vars between 1 and
                // last_assigned_sol-1: free parameters
                for (unsigned ro=0; ro<last_assigned_sol-1; ++ro)
-                       sol.set(ro,co,vars(ro,co));
+                       sol(ro,co) = vars(ro,co);
        }
        
        return sol;
@@ -1088,9 +1087,9 @@ ex matrix::determinant_minor(void) const
        //     for (unsigned r=0; r<minorM.rows(); ++r) {
        //         for (unsigned c=0; c<minorM.cols(); ++c) {
        //             if (r<r1)
-       //                 minorM.set(r,c,m[r*col+c+1]);
+       //                 minorM(r,c) = m[r*col+c+1];
        //             else
-       //                 minorM.set(r,c,m[(r+1)*col+c+1]);
+       //                 minorM(r,c) = m[(r+1)*col+c+1];
        //         }
        //     }
        //     // recurse down and care for sign:
@@ -1467,9 +1466,9 @@ ex lst_to_matrix(const lst & l)
        for (i=0; i<rows; i++)
                for (j=0; j<cols; j++)
                        if (l.op(i).nops() > j)
-                               m.set(i, j, l.op(i).op(j));
+                               m(i, j) = l.op(i).op(j);
                        else
-                               m.set(i, j, ex(0));
+                               m(i, j) = _ex0();
        return m;
 }
 
@@ -1480,7 +1479,7 @@ ex diag_matrix(const lst & l)
        matrix &m = *new matrix(dim, dim);
        m.setflag(status_flags::dynallocated);
        for (unsigned i=0; i<dim; i++)
-               m.set(i, i, l.op(i));
+               m(i, i) = l.op(i);
 
        return m;
 }
index 4a267885a8ef0bc85721661328e2ace1deb257ee..0cb7a71c487d41f45a28fdce7f3f2500a052a290 100644 (file)
@@ -73,7 +73,8 @@ public:
        matrix mul_scalar(const ex & other) const;
        matrix pow(const ex & expn) const;
        const ex & operator() (unsigned ro, unsigned co) const;
-       matrix & set(unsigned ro, unsigned co, ex value);
+       ex & operator() (unsigned ro, unsigned co);
+       matrix & set(unsigned ro, unsigned co, const ex & value) { (*this)(ro, co) = value; return *this; }
        matrix transpose(void) const;
        ex determinant(unsigned algo = determinant_algo::automatic) const;
        ex trace(void) const;