69matrix::matrix(
unsigned r,
unsigned c) : row(
r), col(
c),
m(
r*
c,
_ex0)
98 : row(l.size()), col(l.begin()->size())
103 for (
const auto &
r : l) {
105 for (
const auto & e :
r) {
110 throw std::invalid_argument(
"matrix::matrix{{}}: wrong dimension");
118 : row(
r), col(
c),
m(m2)
123 : row(
r), col(
c),
m(
std::move(m2))
134 inherited::read_archive(
n, sym_lst);
136 if (!(
n.find_unsigned(
"row",
row)) || !(
n.find_unsigned(
"col",
col)))
137 throw (std::runtime_error(
"unknown matrix dimensions in archive"));
141 auto range =
n.find_property_range(
"m",
"m");
142 for (
auto i=range.begin; i != range.end; ++i) {
144 n.find_ex_by_loc(i, e, sym_lst);
152 inherited::archive(
n);
153 n.add_unsigned(
"row",
row);
154 n.add_unsigned(
"col",
col);
168 for (
unsigned ro=0; ro<
row; ++ro) {
170 for (
unsigned co=0; co<
col; ++co) {
171 m[ro*
col+co].print(
c);
191 c.s <<
"\\left(\\begin{array}{" << std::string(
col,
'c') <<
"}";
193 c.s <<
"\\end{array}\\right)";
198 c.s << class_name() <<
'(';
206 return static_cast<size_t>(
row) *
static_cast<size_t>(
col);
229 for (
unsigned r=0;
r<
row; ++
r)
230 for (
unsigned c=0;
c<
col; ++
c)
239 std::unique_ptr<exvector> ev(
nullptr);
240 for (
auto i=
m.begin(); i!=
m.end(); ++i) {
250 ev->reserve(
m.size());
251 for (
auto j=
m.begin(); j!=i; ++j) {
267 v.push_back(i.real_part());
276 v.push_back(i.imag_part());
289 return row < o.
rows() ? -1 : 1;
293 return col < o.
cols() ? -1 : 1;
297 for (
unsigned r=0;
r<
row; ++
r) {
298 for (
unsigned c=0;
c<
col; ++
c) {
299 cmpval = ((*this)(
r,
c)).compare(o(
r,
c));
300 if (cmpval!=0)
return cmpval;
330 throw (std::runtime_error(
"matrix::eval_indexed(): vector must have exactly 1 index"));
332 const idx & i1 = ex_to<idx>(i.
op(1));
338 throw (std::runtime_error(
"matrix::eval_indexed(): dimension of index must match number of vector elements"));
341 if (all_indices_unsigned) {
342 unsigned n1 = ex_to<numeric>(i1.
get_value()).to_int();
344 throw (std::runtime_error(
"matrix::eval_indexed(): value of index exceeds number of vector elements"));
345 return (*
this)(n1, 0);
352 throw (std::runtime_error(
"matrix::eval_indexed(): dimension of index must match number of vector elements"));
355 if (all_indices_unsigned) {
356 unsigned n1 = ex_to<numeric>(i1.
get_value()).to_int();
358 throw (std::runtime_error(
"matrix::eval_indexed(): value of index exceeds number of vector elements"));
359 return (*
this)(0, n1);
363 }
else if (i.
nops() == 3) {
366 const idx & i1 = ex_to<idx>(i.
op(1));
367 const idx & i2 = ex_to<idx>(i.
op(2));
370 throw (std::runtime_error(
"matrix::eval_indexed(): dimension of first index must match number of rows"));
372 throw (std::runtime_error(
"matrix::eval_indexed(): dimension of second index must match number of columns"));
379 if (all_indices_unsigned) {
380 unsigned n1 = ex_to<numeric>(i1.
get_value()).to_int(), n2 = ex_to<numeric>(i2.
get_value()).to_int();
382 throw (std::runtime_error(
"matrix::eval_indexed(): value of first index exceeds number of rows"));
384 throw (std::runtime_error(
"matrix::eval_indexed(): value of second index exceeds number of columns"));
385 return (*
this)(n1, n2);
389 throw (std::runtime_error(
"matrix::eval_indexed(): matrix must have exactly 2 indices"));
403 if (is_a<matrix>(other.
op(0))) {
406 const matrix &self_matrix = ex_to<matrix>(self.
op(0));
407 const matrix &other_matrix = ex_to<matrix>(other.
op(0));
409 if (self.
nops() == 2 && other.
nops() == 2) {
411 if (self_matrix.
row == other_matrix.
row)
412 return indexed(self_matrix.
add(other_matrix), self.
op(1));
413 else if (self_matrix.
row == other_matrix.
col)
416 }
else if (self.
nops() == 3 && other.
nops() == 3) {
419 return indexed(self_matrix.
add(other_matrix), self.
op(1), self.
op(2));
437 const matrix &self_matrix = ex_to<matrix>(self.
op(0));
439 if (self.
nops() == 2)
454 if (!is_a<matrix>(other->op(0)))
459 const matrix &self_matrix = ex_to<matrix>(self->op(0));
460 const matrix &other_matrix = ex_to<matrix>(other->op(0));
462 if (self->nops() == 2) {
464 if (other->nops() == 2) {
466 if (self_matrix.
col == 1) {
467 if (other_matrix.
col == 1) {
469 *self = self_matrix.
transpose().
mul(other_matrix)(0, 0);
472 *self = other_matrix.
mul(self_matrix)(0, 0);
475 if (other_matrix.
col == 1) {
477 *self = self_matrix.
mul(other_matrix)(0, 0);
480 *self = self_matrix.
mul(other_matrix.
transpose())(0, 0);
490 if (self_matrix.
row == 1)
491 *self =
indexed(self_matrix.
mul(other_matrix), other->
op(2));
500 if (self_matrix.
col == 1)
501 *self =
indexed(other_matrix.
mul(self_matrix), other->
op(1));
509 }
else if (other->nops() == 3) {
513 *self =
indexed(self_matrix.
mul(other_matrix), self->
op(1), other->
op(2));
534 *self =
indexed(other_matrix.
mul(self_matrix), other->
op(1), self->
op(2));
556 throw std::logic_error(
"matrix::add(): incompatible matrices");
559 auto ci = other.
m.begin();
573 throw std::logic_error(
"matrix::sub(): incompatible matrices");
576 auto ci = other.
m.begin();
590 throw std::logic_error(
"matrix::mul(): incompatible matrices");
594 for (
unsigned r1=0; r1<this->
rows(); ++r1) {
595 for (
unsigned c=0;
c<this->
cols(); ++
c) {
599 for (
unsigned r2=0; r2<other.
cols(); ++r2)
600 prod[r1*other.
col+r2] += (
m[r1*
col+
c] * other.
m[
c*other.
col+r2]);
612 for (
unsigned r=0;
r<
row; ++
r)
613 for (
unsigned c=0;
c<
col; ++
c)
624 throw std::runtime_error(
"matrix::mul_scalar(): non-commutative scalar");
628 for (
unsigned r=0;
r<
row; ++
r)
629 for (
unsigned c=0;
c<
col; ++
c)
640 throw (std::logic_error(
"matrix::pow(): matrix not square"));
642 if (is_exactly_a<numeric>(expn)) {
646 numeric b = ex_to<numeric>(expn);
655 for (
unsigned r=0;
r<
row; ++
r)
675 throw (std::runtime_error(
"matrix::pow(): don't know how to handle exponent"));
687 throw (std::range_error(
"matrix::operator(): index out of range"));
701 throw (std::range_error(
"matrix::operator(): index out of range"));
714 for (
unsigned r=0;
r<this->
cols(); ++
r)
715 for (
unsigned c=0;
c<this->
rows(); ++
c)
738 throw (std::logic_error(
"matrix::determinant(): matrix not square"));
742 bool numeric_flag =
true;
743 bool normal_flag =
false;
744 unsigned sparse_count = 0;
747 numeric_flag =
false;
786 for (
unsigned d=0; d<
row; ++d)
787 det *= tmp.
m[d*
col+d];
789 return (sign*det).normal();
791 return (sign*det).normal().expand();
798 return (sign*tmp.
m[
row*
col-1]).normal();
800 return (sign*tmp.
m[
row*
col-1]).expand();
810 for (
unsigned d=0; d<
row-2; ++d)
811 for (
unsigned j=0; j<
row-d-2; ++j)
826 typedef std::pair<unsigned,unsigned> uintpair;
827 std::vector<uintpair> c_zeros;
828 for (
unsigned c=0;
c<
col; ++
c) {
830 for (
unsigned r=0;
r<
row; ++
r)
833 c_zeros.push_back(uintpair(acc,
c));
835 std::sort(c_zeros.begin(),c_zeros.end());
836 std::vector<unsigned> pre_sort;
837 for (
auto & i : c_zeros)
838 pre_sort.push_back(i.second);
839 std::vector<unsigned> pre_sort_test(pre_sort);
843 for (
auto & it : pre_sort) {
844 for (
unsigned r=0;
r<
row; ++
r)
867 throw (std::logic_error(
"matrix::trace(): matrix not square"));
870 for (
unsigned r=0;
r<
col; ++
r)
895 throw (std::logic_error(
"matrix::charpoly(): matrix not square"));
897 bool numeric_flag =
true;
900 numeric_flag =
false;
913 for (
unsigned i=1; i<
row; ++i) {
914 for (
unsigned j=0; j<
row; ++j)
928 for (
unsigned r=0;
r<
col; ++
r)
951 throw (std::logic_error(
"matrix::inverse(): matrix not square"));
958 for (
unsigned i=0; i<
row; ++i)
959 identity(i,i) =
_ex1;
965 for (
unsigned r=0;
r<
row; ++
r)
966 for (
unsigned c=0;
c<
col; ++
c)
971 sol = this->
solve(vars, identity, algo);
972 }
catch (
const std::runtime_error & e) {
973 if (e.what()==std::string(
"matrix::solve(): inconsistent linear system"))
974 throw (std::runtime_error(
"matrix::inverse(): singular matrix"));
997 const unsigned m = this->
rows();
998 const unsigned n = this->
cols();
999 const unsigned p =
rhs.cols();
1002 if ((
rhs.rows() !=
m) || (vars.
rows() !=
n) || (vars.
cols() != p))
1003 throw (std::logic_error(
"matrix::solve(): incompatible matrices"));
1004 for (
unsigned ro=0; ro<
n; ++ro)
1005 for (
unsigned co=0; co<p; ++co)
1007 throw (std::invalid_argument(
"matrix::solve(): 1st argument must be matrix of symbols"));
1011 for (
unsigned r=0;
r<
m; ++
r) {
1012 for (
unsigned c=0;
c<
n; ++
c)
1013 aug.
m[
r*(
n+p)+
c] = this->m[
r*
n+
c];
1014 for (
unsigned c=0;
c<p; ++
c)
1023 for (
unsigned co=0; co<p; ++co) {
1024 unsigned last_assigned_sol =
n+1;
1025 for (
int r=
m-1;
r>=0; --
r) {
1027 while ((fnz<=
n) && (aug.
m[
r*(
n+p)+(fnz-1)].normal().is_zero()))
1031 if (!aug.
m[
r*(
n+p)+
n+co].normal().is_zero()) {
1032 throw (std::runtime_error(
"matrix::solve(): inconsistent linear system"));
1037 for (
unsigned c=fnz;
c<last_assigned_sol-1; ++
c)
1038 sol(colid[
c],co) = vars.
m[colid[
c]*p+co];
1039 ex e = aug.
m[
r*(
n+p)+
n+co];
1040 for (
unsigned c=fnz;
c<
n; ++
c)
1041 e -= aug.
m[
r*(
n+p)+
c]*sol.
m[colid[
c]*p+co];
1042 sol(colid[fnz-1],co) = (e/(aug.
m[
r*(
n+p)+fnz-1])).
normal();
1043 last_assigned_sol = fnz;
1048 for (
unsigned ro=0; ro<last_assigned_sol-1; ++ro)
1049 sol(colid[ro],co) = vars(colid[ro],co);
1070 matrix to_eliminate = *
this;
1075 if (!to_eliminate.
m[
r].is_zero())
1096 const unsigned n = this->
cols();
1131 typedef std::vector<unsigned> keyseq;
1132 typedef std::map<keyseq, ex> Rmap;
1145 for (
int c=
n-1;
c>=0; --
c) {
1148 for (
unsigned i=0; i<
n-
c; ++i)
1153 for (
unsigned r=0;
r<
n-
c; ++
r) {
1159 Mkey.insert(Mkey.begin(), Nkey.begin(), Nkey.begin() +
r);
1160 Mkey.insert(Mkey.end(), Nkey.begin() +
r + 1, Nkey.end());
1163 det -=
m[Nkey[
r]*
n+
c]*M[Mkey];
1165 det +=
m[Nkey[
r]*
n+
c]*M[Mkey];
1174 for (fc=
n-
c; fc>0; --fc) {
1176 if (Nkey[fc-1]<fc+
c)
1180 for (
unsigned j=fc; j<
n-
c; ++j)
1181 Nkey[j] = Nkey[j-1]+1;
1194std::vector<unsigned>
1200 bool numeric_flag =
true;
1201 for (
const auto &
r :
m) {
1203 numeric_flag =
false;
1207 unsigned density = 0;
1208 for (
const auto &
r :
m) {
1211 unsigned ncells =
col*
row;
1215 if ((ncells > 200) && (density < ncells/2)) {
1223 if ((ncells < 120) && (density*5 > ncells*3)) {
1235 std::vector<unsigned> colid(
col);
1236 for (
unsigned c = 0;
c <
col;
c++) {
1253 throw std::invalid_argument(
"matrix::echelon_form(): 'algo' is not one of the solve_algo enum");
1270 const unsigned m = this->
rows();
1271 const unsigned n = this->
cols();
1276 for (
unsigned c0=0; c0<
n && r0<
m-1; ++c0) {
1277 int indx =
pivot(r0, c0,
true);
1286 for (
unsigned r2=r0+1; r2<
m; ++r2) {
1289 ex piv = this->m[r2*
n+c0] / this->m[r0*
n+c0];
1290 for (
unsigned c=c0+1;
c<
n; ++
c) {
1291 this->m[r2*
n+
c] -= piv * this->m[r0*
n+
c];
1297 for (
unsigned c=r0;
c<=c0; ++
c)
1302 for (
unsigned c=r0+1;
c<
n; ++
c)
1309 for (
unsigned r=r0+1;
r<
m; ++
r) {
1310 for (
unsigned c=0;
c<
n; ++
c)
1323std::vector<unsigned>
1327 std::vector<int> rowcnt(
row, 0);
1328 std::vector<int> colcnt(
col, 0);
1332 for (
unsigned r = 0;
r <
row;
r++) {
1333 for (
unsigned c = 0;
c <
col;
c++) {
1341 std::vector<unsigned> colid(
col);
1342 for (
unsigned c = 0;
c <
col;
c++) {
1346 for (
unsigned k = 0; (
k <
col) && (
k <
row - 1);
k++) {
1348 unsigned pivot_r =
row + 1;
1349 unsigned pivot_c =
col + 1;
1351 for (
unsigned r =
k;
r <
row;
r++) {
1352 for (
unsigned c =
k;
c <
n;
c++) {
1358 int measure = (rowcnt[
r] - 1)*(colcnt[
c] - 1);
1359 if (measure < pivot_m) {
1366 if (pivot_m ==
row*
col) {
1374 for (
unsigned r = 0;
r <
row;
r++) {
1381 for (
unsigned c =
k;
c <
col;
c++) {
1395 for (
unsigned r =
k + 1;
r <
row;
r++) {
1402 colcnt[
k] = rowcnt[
k] = 0;
1403 for (
unsigned c =
k + 1;
c <
col;
c++) {
1408 for (
unsigned r =
k + 1;
r <
row;
r++) {
1414 if (waszero && !iszero) {
1418 if (!waszero && iszero) {
1424 for (
unsigned r =
k + 1;
r <
row;
r++) {
1442 const unsigned m = this->
rows();
1443 const unsigned n = this->
cols();
1448 for (
unsigned c0=0; c0<
n && r0<
m-1; ++c0) {
1449 int indx =
pivot(r0, c0,
true);
1458 for (
unsigned r2=r0+1; r2<
m; ++r2) {
1459 for (
unsigned c=c0+1;
c<
n; ++
c)
1460 this->m[r2*
n+
c] = (this->m[r0*
n+c0]*this->m[r2*
n+
c] - this->m[r2*
n+c0]*this->m[r0*
n+
c]).normal();
1462 for (
unsigned c=r0;
c<=c0; ++
c)
1467 for (
unsigned c=r0+1;
c<
n; ++
c)
1474 for (
unsigned r=r0+1;
r<
m; ++
r) {
1475 for (
unsigned c=0;
c<
n; ++
c)
1520 const unsigned m = this->
rows();
1521 const unsigned n = this->
cols();
1541 auto tmp_n_it = tmp_n.
m.begin(), tmp_d_it = tmp_d.
m.begin();
1542 for (
auto & it : this->
m) {
1544 *tmp_n_it++ = nd.
op(0);
1545 *tmp_d_it++ = nd.
op(1);
1549 for (
unsigned c0=0; c0<
n && r0<
m-1; ++c0) {
1567 for (
unsigned c=c0;
c<
n; ++
c) {
1568 tmp_n.
m[
n*indx+
c].swap(tmp_n.
m[
n*r0+
c]);
1569 tmp_d.
m[
n*indx+
c].swap(tmp_d.
m[
n*r0+
c]);
1572 for (
unsigned r2=r0+1; r2<
m; ++r2) {
1573 for (
unsigned c=c0+1;
c<
n; ++
c) {
1574 dividend_n = (tmp_n.
m[r0*
n+c0]*tmp_n.
m[r2*
n+
c]*
1575 tmp_d.
m[r2*
n+c0]*tmp_d.
m[r0*
n+
c]
1576 -tmp_n.
m[r2*
n+c0]*tmp_n.
m[r0*
n+
c]*
1578 dividend_d = (tmp_d.
m[r2*
n+c0]*tmp_d.
m[r0*
n+
c]*
1580 bool check =
divide(dividend_n, divisor_n,
1581 tmp_n.
m[r2*
n+
c],
true);
1582 check &=
divide(dividend_d, divisor_d,
1583 tmp_d.
m[r2*
n+
c],
true);
1587 for (
unsigned c=r0;
c<=c0; ++
c)
1590 if (c0<
n && r0<
m-1) {
1592 divisor_n = tmp_n.
m[r0*
n+c0].expand();
1593 divisor_d = tmp_d.
m[r0*
n+c0].expand();
1596 for (
unsigned c=0;
c<
n; ++
c) {
1606 for (
unsigned r=r0+1;
r<
m; ++
r) {
1607 for (
unsigned c=0;
c<
n; ++
c)
1612 tmp_n_it = tmp_n.
m.begin();
1613 tmp_d_it = tmp_d.
m.begin();
1614 for (
auto & it : this->
m)
1644 unsigned kmax =
k+1;
1648 numeric tmp = ex_to<numeric>(this->
m[kmax*
col+co]);
1649 if (
abs(tmp) > mmax) {
1666 for (
unsigned c=0;
c<
col; ++
c)
1686 for (
auto & itr : l) {
1687 if (!is_a<lst>(itr))
1688 throw (std::invalid_argument(
"lst_to_matrix: argument must be a list of lists"));
1689 if (itr.nops() >
cols)
1697 for (
auto & itr : l) {
1699 for (
auto & itc : ex_to<lst>(itr)) {
1711 size_t dim = l.
nops();
1714 matrix & M = dynallocate<matrix>(dim, dim);
1717 for (
auto & it : l) {
1727 size_t dim = l.size();
1730 matrix & M = dynallocate<matrix>(dim, dim);
1733 for (
auto & it : l) {
1743 matrix & Id = dynallocate<matrix>(
r,
c);
1745 for (
unsigned i=0; i<
r && i<
c; i++)
1753 matrix & M = dynallocate<matrix>(
r,
c);
1756 bool long_format = (
r > 10 ||
c > 10);
1757 bool single_row = (
r == 1 ||
c == 1);
1759 for (
unsigned i=0; i<
r; i++) {
1760 for (
unsigned j=0; j<
c; j++) {
1761 std::ostringstream s1, s2;
1763 s2 << tex_base_name <<
"_{";
1774 s1 <<
'_' << i <<
'_' << j;
1775 s2 << i <<
';' << j <<
"}";
1778 s2 << i << j <<
'}';
1781 M(i, j) =
symbol(s1.str(), s2.str());
1790 if (
r+1>
m.rows() ||
c+1>
m.cols() ||
m.cols()<2 ||
m.rows()<2)
1791 throw std::runtime_error(
"minor_matrix(): index out of bounds");
1793 const unsigned rows =
m.rows()-1;
1794 const unsigned cols =
m.cols()-1;
1808 M(ro2,co2) =
m(ro, co);
1821 if (
r+nr>
m.rows() ||
c+nc>
m.cols())
1822 throw std::runtime_error(
"sub_matrix(): index out of bounds");
1824 matrix & M = dynallocate<matrix>(nr, nc);
1827 for (
unsigned ro=0; ro<nr; ++ro) {
1828 for (
unsigned co=0; co<nc; ++co) {
1829 M(ro,co) =
m(ro+
r,co+
c);
Interface to GiNaC's sums of expressions.
Archiving of GiNaC expressions.
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
virtual size_t nops() const
Number of operands/members.
const basic & setflag(unsigned f) const
Set some status_flags.
virtual bool info(unsigned inf) const
Information about the object.
void ensure_if_modifiable() const
Ensure the object may be modified without hurting others, throws if this is not the case.
virtual ex op(size_t i) const
Return operand/member at position i.
ex subs_one_level(const exmap &m, unsigned options) const
Helper function for subs().
const basic & hold() const
Stop further evaluation.
virtual int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
void do_print_tree(const print_tree &c, unsigned level) const
Tree output to stream.
virtual ex expand(unsigned options=0) const
Expand expression, i.e.
virtual ex normal(exmap &repl, exmap &rev_lookup, lst &modifier) const
Default implementation of ex::normal().
Wrapper template for making GiNaC classes out of STL containers.
size_t nops() const override
Number of operands/members.
@ automatic
Let the system choose.
@ divfree
Division-free elimination.
@ laplace
Laplace elimination.
@ gauss
Gauss elimination.
@ bareiss
Bareiss fraction-free elimination.
Lightweight wrapper for GiNaC's symbolic objects.
ex to_rational(exmap &repl) const
Rationalization of non-rational functions.
ex expand(unsigned options=0) const
Expand an expression.
ex numer_denom() const
Get numerator and denominator of an expression.
bool is_equal(const ex &other) const
ex normal() const
Normalization of rational functions.
unsigned return_type() const
bool info(unsigned inf) const
ex collect(const ex &s, bool distributed=false) const
This class holds one index of an indexed object.
ex get_dim() const
Get dimension of index space.
ex get_value() const
Get value of index.
This class holds an indexed expression.
matrix inverse() const
Inverse of this matrix, with automatic algorithm selection.
int gauss_elimination(const bool det=false)
Perform the steps of an ordinary Gaussian elimination to bring the m x n matrix into an upper echelon...
ex scalar_mul_indexed(const ex &self, const numeric &other) const override
Product of an indexed matrix with a number.
ex eval_indexed(const basic &i) const override
Automatic symbolic evaluation of an indexed matrix.
unsigned cols() const
Get number of columns.
ex charpoly(const ex &lambda) const
Characteristic Polynomial.
void do_print_latex(const print_latex &c, unsigned level) const
exvector m
representation (cols indexed first)
ex determinant(unsigned algo=determinant_algo::automatic) const
Determinant of square matrix.
const ex & operator()(unsigned ro, unsigned co) const
operator() to access elements for reading.
void archive(archive_node &n) const override
Save (a.k.a.
ex add_indexed(const ex &self, const ex &other) const override
Sum of two indexed matrices.
bool is_zero_matrix() const
Function to check that all elements of the matrix are zero.
ex trace() const
Trace of a matrix.
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
matrix add(const matrix &other) const
Sum of matrices.
matrix pow(const ex &expn) const
Power of a matrix.
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
matrix(unsigned r, unsigned c)
Very common ctor.
std::vector< unsigned > markowitz_elimination(unsigned n)
matrix solve(const matrix &vars, const matrix &rhs, unsigned algo=solve_algo::automatic) const
Solve a linear system consisting of a m x n matrix and a m x p right hand side by applying an elimina...
void do_print_python_repr(const print_python_repr &c, unsigned level) const
ex imag_part() const override
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
matrix mul_scalar(const ex &other) const
Product of matrix and scalar expression.
void do_print(const print_context &c, unsigned level) const
void print_elements(const print_context &c, const char *row_start, const char *row_end, const char *row_sep, const char *col_sep) const
size_t nops() const override
nops is defined to be rows x columns.
ex real_part() const override
unsigned rank() const
Compute the rank of this matrix.
ex determinant_minor() const
Recursive determinant for small matrices having at least one symbolic entry.
matrix mul(const matrix &other) const
Product of matrices.
bool contract_with(exvector::iterator self, exvector::iterator other, exvector &v) const override
Contraction of an indexed matrix with something else.
unsigned rows() const
Get number of rows.
ex op(size_t i) const override
returns matrix entry at position (i/col, icol).
int division_free_elimination(const bool det=false)
Perform the steps of division free elimination to bring the m x n matrix into an upper echelon form.
unsigned col
number of columns
ex & let_op(size_t i) override
returns writable matrix entry at position (i/col, icol).
matrix transpose() const
Transposed of an m x n matrix, producing a new n x m matrix object that represents the transposed.
matrix sub(const matrix &other) const
Difference of matrices.
std::vector< unsigned > echelon_form(unsigned algo, int n)
ex conjugate() const override
Complex conjugate every matrix entry.
int pivot(unsigned ro, unsigned co, bool symbolic=true)
Partial pivoting method for matrix elimination schemes.
int fraction_free_elimination(const bool det=false)
Perform the steps of Bareiss' one-step fraction free elimination to bring the matrix into an upper ec...
unsigned row
number of rows
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
bool is_odd() const
True if object is an exact odd integer.
bool is_zero() const
True if object is zero.
This class holds a two-component object, a basis and and exponent representing exponentiation.
Base class for print_contexts.
Context for latex-parsable output.
Context for python-parsable output.
Switch to control algorithm for linear system solving.
@ bareiss
Bareiss fraction-free elimination.
@ markowitz
Markowitz-ordered Gaussian elimination.
@ automatic
Let the system choose.
@ divfree
Division-free elimination.
@ gauss
Gauss elimination.
@ evaluated
.eval() has already done its job
@ not_shareable
don't share instances of this object between different expressions unless explicitly asked to (used b...
@ no_pattern
disable pattern matching
Interface to GiNaC's indices.
Interface to GiNaC's indexed expressions.
Definition of GiNaC's lst.
Interface to symbolic matrices.
bool is_zero(const ex &thisex)
ex symbolic_matrix(unsigned r, unsigned c, const std::string &base_name, const std::string &tex_base_name)
Create an r times c matrix of newly generated symbols consisting of the given base name plus the nume...
ex sub_matrix(const matrix &m, unsigned r, unsigned nr, unsigned c, unsigned nc)
Return the nr times nc submatrix starting at position r, c of matrix m.
std::map< ex, ex, ex_is_less > exmap
const numeric abs(const numeric &x)
Absolute value.
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
ex diag_matrix(const lst &l)
Convert list of diagonal elements to matrix.
unsigned rows(const matrix &m)
bool is_dummy_pair(const idx &i1, const idx &i2)
Check whether two indices form a dummy pair.
print_func< print_context >(&varidx::do_print). print_func< print_latex >(&varidx
unsigned cols(const matrix &m)
void swap(ex &e1, ex &e2)
int permutation_sign(It first, It last)
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func< print_context >(&lst::do_print). print_func< print_tree >(&lst::do_print_tree)) template<> bool lst GINAC_BIND_UNARCHIVER(lst)
Specialization of container::info() for lst.
ex lst_to_matrix(const lst &l)
Convert list of lists to matrix.
bool divide(const ex &a, const ex &b, ex &q, bool check_args)
Exact polynomial division of a(X) by b(X) in Q[X].
std::vector< ex > exvector
ex unit_matrix(unsigned r, unsigned c)
Create an r times c unit matrix.
ex reduced_matrix(const matrix &m, unsigned r, unsigned c)
Return the reduced matrix that is formed by deleting the rth row and cth column of matrix m.
void swap(GiNaC::ex &a, GiNaC::ex &b)
Specialization of std::swap() for ex objects.
This file defines several functions that work on univariate and multivariate polynomials and rational...
Makes the interface to the underlying bignum package available.
Interface to GiNaC's overloaded operators.
Interface to GiNaC's symbolic exponentiation (basis^exponent).
#define GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(classname, supername, options)
Macro for inclusion in the implementation of each registered class.
Interface to GiNaC's symbolic objects.
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...