68matrix::matrix(
unsigned r,
unsigned c) : row(
r), col(
c),
m(
r*
c,
_ex0)
97 : row(l.size()), col(l.begin()->size())
102 for (
const auto &
r : l) {
104 for (
const auto & e :
r) {
109 throw std::invalid_argument(
"matrix::matrix{{}}: wrong dimension");
117 : row(
r), col(
c),
m(m2)
122 : row(
r), col(
c),
m(
std::move(m2))
133 inherited::read_archive(
n, sym_lst);
135 if (!(
n.find_unsigned(
"row",
row)) || !(
n.find_unsigned(
"col",
col)))
136 throw (std::runtime_error(
"unknown matrix dimensions in archive"));
140 auto range =
n.find_property_range(
"m",
"m");
141 for (
auto i=range.begin; i != range.end; ++i) {
143 n.find_ex_by_loc(i, e, sym_lst);
151 inherited::archive(
n);
152 n.add_unsigned(
"row",
row);
153 n.add_unsigned(
"col",
col);
167 for (
unsigned ro=0; ro<
row; ++ro) {
169 for (
unsigned co=0; co<
col; ++co) {
170 m[ro*
col+co].print(
c);
190 c.s <<
"\\left(\\begin{array}{" << std::string(
col,
'c') <<
"}";
192 c.s <<
"\\end{array}\\right)";
197 c.s << class_name() <<
'(';
205 return static_cast<size_t>(
row) *
static_cast<size_t>(
col);
228 for (
unsigned r=0;
r<
row; ++
r)
229 for (
unsigned c=0;
c<
col; ++
c)
238 std::unique_ptr<exvector> ev(
nullptr);
239 for (
auto i=
m.begin(); i!=
m.end(); ++i) {
249 ev->reserve(
m.size());
250 for (
auto j=
m.begin(); j!=i; ++j) {
266 v.push_back(i.real_part());
275 v.push_back(i.imag_part());
288 return row < o.
rows() ? -1 : 1;
292 return col < o.
cols() ? -1 : 1;
296 for (
unsigned r=0;
r<
row; ++
r) {
297 for (
unsigned c=0;
c<
col; ++
c) {
298 cmpval = ((*this)(
r,
c)).compare(o(
r,
c));
299 if (cmpval!=0)
return cmpval;
329 throw (std::runtime_error(
"matrix::eval_indexed(): vector must have exactly 1 index"));
331 const idx & i1 = ex_to<idx>(i.
op(1));
337 throw (std::runtime_error(
"matrix::eval_indexed(): dimension of index must match number of vector elements"));
340 if (all_indices_unsigned) {
341 unsigned n1 = ex_to<numeric>(i1.
get_value()).to_int();
343 throw (std::runtime_error(
"matrix::eval_indexed(): value of index exceeds number of vector elements"));
344 return (*
this)(n1, 0);
351 throw (std::runtime_error(
"matrix::eval_indexed(): dimension of index must match number of vector elements"));
354 if (all_indices_unsigned) {
355 unsigned n1 = ex_to<numeric>(i1.
get_value()).to_int();
357 throw (std::runtime_error(
"matrix::eval_indexed(): value of index exceeds number of vector elements"));
358 return (*
this)(0, n1);
362 }
else if (i.
nops() == 3) {
365 const idx & i1 = ex_to<idx>(i.
op(1));
366 const idx & i2 = ex_to<idx>(i.
op(2));
369 throw (std::runtime_error(
"matrix::eval_indexed(): dimension of first index must match number of rows"));
371 throw (std::runtime_error(
"matrix::eval_indexed(): dimension of second index must match number of columns"));
378 if (all_indices_unsigned) {
379 unsigned n1 = ex_to<numeric>(i1.
get_value()).to_int(), n2 = ex_to<numeric>(i2.
get_value()).to_int();
381 throw (std::runtime_error(
"matrix::eval_indexed(): value of first index exceeds number of rows"));
383 throw (std::runtime_error(
"matrix::eval_indexed(): value of second index exceeds number of columns"));
384 return (*
this)(n1, n2);
388 throw (std::runtime_error(
"matrix::eval_indexed(): matrix must have exactly 2 indices"));
402 if (is_a<matrix>(other.
op(0))) {
405 const matrix &self_matrix = ex_to<matrix>(self.
op(0));
406 const matrix &other_matrix = ex_to<matrix>(other.
op(0));
408 if (self.
nops() == 2 && other.
nops() == 2) {
410 if (self_matrix.
row == other_matrix.
row)
411 return indexed(self_matrix.
add(other_matrix), self.
op(1));
412 else if (self_matrix.
row == other_matrix.
col)
415 }
else if (self.
nops() == 3 && other.
nops() == 3) {
418 return indexed(self_matrix.
add(other_matrix), self.
op(1), self.
op(2));
436 const matrix &self_matrix = ex_to<matrix>(self.
op(0));
438 if (self.
nops() == 2)
453 if (!is_a<matrix>(other->op(0)))
458 const matrix &self_matrix = ex_to<matrix>(self->op(0));
459 const matrix &other_matrix = ex_to<matrix>(other->op(0));
461 if (self->nops() == 2) {
463 if (other->nops() == 2) {
465 if (self_matrix.
col == 1) {
466 if (other_matrix.
col == 1) {
468 *self = self_matrix.
transpose().
mul(other_matrix)(0, 0);
471 *self = other_matrix.
mul(self_matrix)(0, 0);
474 if (other_matrix.
col == 1) {
476 *self = self_matrix.
mul(other_matrix)(0, 0);
479 *self = self_matrix.
mul(other_matrix.
transpose())(0, 0);
489 if (self_matrix.
row == 1)
490 *self =
indexed(self_matrix.
mul(other_matrix), other->
op(2));
499 if (self_matrix.
col == 1)
500 *self =
indexed(other_matrix.
mul(self_matrix), other->
op(1));
508 }
else if (other->nops() == 3) {
512 *self =
indexed(self_matrix.
mul(other_matrix), self->
op(1), other->
op(2));
533 *self =
indexed(other_matrix.
mul(self_matrix), other->
op(1), self->
op(2));
555 throw std::logic_error(
"matrix::add(): incompatible matrices");
558 auto ci = other.
m.begin();
572 throw std::logic_error(
"matrix::sub(): incompatible matrices");
575 auto ci = other.
m.begin();
589 throw std::logic_error(
"matrix::mul(): incompatible matrices");
593 for (
unsigned r1=0; r1<this->
rows(); ++r1) {
594 for (
unsigned c=0;
c<this->
cols(); ++
c) {
598 for (
unsigned r2=0; r2<other.
cols(); ++r2)
599 prod[r1*other.
col+r2] += (
m[r1*
col+
c] * other.
m[
c*other.
col+r2]);
611 for (
unsigned r=0;
r<
row; ++
r)
612 for (
unsigned c=0;
c<
col; ++
c)
623 throw std::runtime_error(
"matrix::mul_scalar(): non-commutative scalar");
627 for (
unsigned r=0;
r<
row; ++
r)
628 for (
unsigned c=0;
c<
col; ++
c)
639 throw (std::logic_error(
"matrix::pow(): matrix not square"));
641 if (is_exactly_a<numeric>(expn)) {
645 numeric b = ex_to<numeric>(expn);
654 for (
unsigned r=0;
r<
row; ++
r)
674 throw (std::runtime_error(
"matrix::pow(): don't know how to handle exponent"));
686 throw (std::range_error(
"matrix::operator(): index out of range"));
700 throw (std::range_error(
"matrix::operator(): index out of range"));
713 for (
unsigned r=0;
r<this->
cols(); ++
r)
714 for (
unsigned c=0;
c<this->
rows(); ++
c)
737 throw (std::logic_error(
"matrix::determinant(): matrix not square"));
741 bool numeric_flag =
true;
742 bool normal_flag =
false;
743 unsigned sparse_count = 0;
746 numeric_flag =
false;
785 for (
unsigned d=0; d<
row; ++d)
786 det *= tmp.
m[d*
col+d];
788 return (sign*det).normal();
790 return (sign*det).normal().expand();
797 return (sign*tmp.
m[
row*
col-1]).normal();
799 return (sign*tmp.
m[
row*
col-1]).expand();
809 for (
unsigned d=0; d<
row-2; ++d)
810 for (
unsigned j=0; j<
row-d-2; ++j)
825 typedef std::pair<unsigned,unsigned> uintpair;
826 std::vector<uintpair> c_zeros;
827 for (
unsigned c=0;
c<
col; ++
c) {
829 for (
unsigned r=0;
r<
row; ++
r)
832 c_zeros.push_back(uintpair(acc,
c));
834 std::sort(c_zeros.begin(),c_zeros.end());
835 std::vector<unsigned> pre_sort;
836 for (
auto & i : c_zeros)
837 pre_sort.push_back(i.second);
838 std::vector<unsigned> pre_sort_test(pre_sort);
842 for (
auto & it : pre_sort) {
843 for (
unsigned r=0;
r<
row; ++
r)
866 throw (std::logic_error(
"matrix::trace(): matrix not square"));
869 for (
unsigned r=0;
r<
col; ++
r)
894 throw (std::logic_error(
"matrix::charpoly(): matrix not square"));
896 bool numeric_flag =
true;
899 numeric_flag =
false;
912 for (
unsigned i=1; i<
row; ++i) {
913 for (
unsigned j=0; j<
row; ++j)
927 for (
unsigned r=0;
r<
col; ++
r)
950 throw (std::logic_error(
"matrix::inverse(): matrix not square"));
957 for (
unsigned i=0; i<
row; ++i)
958 identity(i,i) =
_ex1;
964 for (
unsigned r=0;
r<
row; ++
r)
965 for (
unsigned c=0;
c<
col; ++
c)
970 sol = this->
solve(vars, identity, algo);
971 }
catch (
const std::runtime_error & e) {
972 if (e.what()==std::string(
"matrix::solve(): inconsistent linear system"))
973 throw (std::runtime_error(
"matrix::inverse(): singular matrix"));
996 const unsigned m = this->
rows();
997 const unsigned n = this->
cols();
998 const unsigned p =
rhs.cols();
1001 if ((
rhs.rows() !=
m) || (vars.
rows() !=
n) || (vars.
cols() != p))
1002 throw (std::logic_error(
"matrix::solve(): incompatible matrices"));
1003 for (
unsigned ro=0; ro<
n; ++ro)
1004 for (
unsigned co=0; co<p; ++co)
1006 throw (std::invalid_argument(
"matrix::solve(): 1st argument must be matrix of symbols"));
1010 for (
unsigned r=0;
r<
m; ++
r) {
1011 for (
unsigned c=0;
c<
n; ++
c)
1012 aug.
m[
r*(
n+p)+
c] = this->m[
r*
n+
c];
1013 for (
unsigned c=0;
c<p; ++
c)
1022 for (
unsigned co=0; co<p; ++co) {
1023 unsigned last_assigned_sol =
n+1;
1024 for (
int r=
m-1;
r>=0; --
r) {
1026 while ((fnz<=
n) && (aug.
m[
r*(
n+p)+(fnz-1)].normal().is_zero()))
1030 if (!aug.
m[
r*(
n+p)+
n+co].normal().is_zero()) {
1031 throw (std::runtime_error(
"matrix::solve(): inconsistent linear system"));
1036 for (
unsigned c=fnz;
c<last_assigned_sol-1; ++
c)
1037 sol(colid[
c],co) = vars.
m[colid[
c]*p+co];
1038 ex e = aug.
m[
r*(
n+p)+
n+co];
1039 for (
unsigned c=fnz;
c<
n; ++
c)
1040 e -= aug.
m[
r*(
n+p)+
c]*sol.
m[colid[
c]*p+co];
1041 sol(colid[fnz-1],co) = (e/(aug.
m[
r*(
n+p)+fnz-1])).
normal();
1042 last_assigned_sol = fnz;
1047 for (
unsigned ro=0; ro<last_assigned_sol-1; ++ro)
1048 sol(colid[ro],co) = vars(colid[ro],co);
1069 matrix to_eliminate = *
this;
1074 if (!to_eliminate.
m[
r].is_zero())
1095 const unsigned n = this->
cols();
1130 typedef std::vector<unsigned> keyseq;
1131 typedef std::map<keyseq, ex> Rmap;
1144 for (
int c=
n-1;
c>=0; --
c) {
1147 for (
unsigned i=0; i<
n-
c; ++i)
1152 for (
unsigned r=0;
r<
n-
c; ++
r) {
1158 Mkey.insert(Mkey.begin(), Nkey.begin(), Nkey.begin() +
r);
1159 Mkey.insert(Mkey.end(), Nkey.begin() +
r + 1, Nkey.end());
1162 det -=
m[Nkey[
r]*
n+
c]*M[Mkey];
1164 det +=
m[Nkey[
r]*
n+
c]*M[Mkey];
1173 for (fc=
n-
c; fc>0; --fc) {
1175 if (Nkey[fc-1]<fc+
c)
1179 for (
unsigned j=fc; j<
n-
c; ++j)
1180 Nkey[j] = Nkey[j-1]+1;
1193std::vector<unsigned>
1199 bool numeric_flag =
true;
1200 for (
const auto &
r :
m) {
1202 numeric_flag =
false;
1206 unsigned density = 0;
1207 for (
const auto &
r :
m) {
1210 unsigned ncells =
col*
row;
1214 if ((ncells > 200) && (density < ncells/2)) {
1222 if ((ncells < 120) && (density*5 > ncells*3)) {
1234 std::vector<unsigned> colid(
col);
1235 for (
unsigned c = 0;
c <
col;
c++) {
1252 throw std::invalid_argument(
"matrix::echelon_form(): 'algo' is not one of the solve_algo enum");
1269 const unsigned m = this->
rows();
1270 const unsigned n = this->
cols();
1275 for (
unsigned c0=0; c0<
n && r0<
m-1; ++c0) {
1276 int indx =
pivot(r0, c0,
true);
1285 for (
unsigned r2=r0+1; r2<
m; ++r2) {
1288 ex piv = this->m[r2*
n+c0] / this->m[r0*
n+c0];
1289 for (
unsigned c=c0+1;
c<
n; ++
c) {
1290 this->m[r2*
n+
c] = (this->m[r2*
n+
c] - piv * this->m[r0*
n+
c]).
normal();
1294 for (
unsigned c=r0;
c<=c0; ++
c)
1299 for (
unsigned c=r0+1;
c<
n; ++
c)
1306 for (
unsigned r=r0+1;
r<
m; ++
r) {
1307 for (
unsigned c=0;
c<
n; ++
c)
1320std::vector<unsigned>
1324 std::vector<int> rowcnt(
row, 0);
1325 std::vector<int> colcnt(
col, 0);
1329 for (
unsigned r = 0;
r <
row;
r++) {
1330 for (
unsigned c = 0;
c <
col;
c++) {
1338 std::vector<unsigned> colid(
col);
1339 for (
unsigned c = 0;
c <
col;
c++) {
1343 for (
unsigned k = 0; (
k <
col) && (
k <
row - 1);
k++) {
1345 unsigned pivot_r =
row + 1;
1346 unsigned pivot_c =
col + 1;
1348 for (
unsigned r =
k;
r <
row;
r++) {
1349 for (
unsigned c =
k;
c <
n;
c++) {
1355 int measure = (rowcnt[
r] - 1)*(colcnt[
c] - 1);
1356 if (measure < pivot_m) {
1363 if (pivot_m ==
row*
col) {
1371 for (
unsigned r = 0;
r <
row;
r++) {
1378 for (
unsigned c =
k;
c <
col;
c++) {
1392 for (
unsigned r =
k + 1;
r <
row;
r++) {
1399 colcnt[
k] = rowcnt[
k] = 0;
1400 for (
unsigned c =
k + 1;
c <
col;
c++) {
1405 for (
unsigned r =
k + 1;
r <
row;
r++) {
1411 if (waszero && !iszero) {
1415 if (!waszero && iszero) {
1421 for (
unsigned r =
k + 1;
r <
row;
r++) {
1439 const unsigned m = this->
rows();
1440 const unsigned n = this->
cols();
1445 for (
unsigned c0=0; c0<
n && r0<
m-1; ++c0) {
1446 int indx =
pivot(r0, c0,
true);
1455 for (
unsigned r2=r0+1; r2<
m; ++r2) {
1456 for (
unsigned c=c0+1;
c<
n; ++
c)
1457 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();
1459 for (
unsigned c=r0;
c<=c0; ++
c)
1464 for (
unsigned c=r0+1;
c<
n; ++
c)
1471 for (
unsigned r=r0+1;
r<
m; ++
r) {
1472 for (
unsigned c=0;
c<
n; ++
c)
1517 const unsigned m = this->
rows();
1518 const unsigned n = this->
cols();
1538 auto tmp_n_it = tmp_n.
m.begin(), tmp_d_it = tmp_d.
m.begin();
1539 for (
auto & it : this->
m) {
1541 *tmp_n_it++ = nd.
op(0);
1542 *tmp_d_it++ = nd.
op(1);
1546 for (
unsigned c0=0; c0<
n && r0<
m-1; ++c0) {
1564 for (
unsigned c=c0;
c<
n; ++
c) {
1565 tmp_n.
m[
n*indx+
c].swap(tmp_n.
m[
n*r0+
c]);
1566 tmp_d.
m[
n*indx+
c].swap(tmp_d.
m[
n*r0+
c]);
1569 for (
unsigned r2=r0+1; r2<
m; ++r2) {
1570 for (
unsigned c=c0+1;
c<
n; ++
c) {
1571 dividend_n = (tmp_n.
m[r0*
n+c0]*tmp_n.
m[r2*
n+
c]*
1572 tmp_d.
m[r2*
n+c0]*tmp_d.
m[r0*
n+
c]
1573 -tmp_n.
m[r2*
n+c0]*tmp_n.
m[r0*
n+
c]*
1575 dividend_d = (tmp_d.
m[r2*
n+c0]*tmp_d.
m[r0*
n+
c]*
1577 bool check =
divide(dividend_n, divisor_n,
1578 tmp_n.
m[r2*
n+
c],
true);
1579 check &=
divide(dividend_d, divisor_d,
1580 tmp_d.
m[r2*
n+
c],
true);
1584 for (
unsigned c=r0;
c<=c0; ++
c)
1587 if (c0<
n && r0<
m-1) {
1589 divisor_n = tmp_n.
m[r0*
n+c0].expand();
1590 divisor_d = tmp_d.
m[r0*
n+c0].expand();
1593 for (
unsigned c=0;
c<
n; ++
c) {
1603 for (
unsigned r=r0+1;
r<
m; ++
r) {
1604 for (
unsigned c=0;
c<
n; ++
c)
1609 tmp_n_it = tmp_n.
m.begin();
1610 tmp_d_it = tmp_d.
m.begin();
1611 for (
auto & it : this->
m)
1641 unsigned kmax =
k+1;
1645 numeric tmp = ex_to<numeric>(this->
m[kmax*
col+co]);
1646 if (
abs(tmp) > mmax) {
1663 for (
unsigned c=0;
c<
col; ++
c)
1683 for (
auto & itr : l) {
1684 if (!is_a<lst>(itr))
1685 throw (std::invalid_argument(
"lst_to_matrix: argument must be a list of lists"));
1686 if (itr.nops() >
cols)
1694 for (
auto & itr : l) {
1696 for (
auto & itc : ex_to<lst>(itr)) {
1708 size_t dim = l.
nops();
1711 matrix & M = dynallocate<matrix>(dim, dim);
1714 for (
auto & it : l) {
1724 size_t dim = l.size();
1727 matrix & M = dynallocate<matrix>(dim, dim);
1730 for (
auto & it : l) {
1740 matrix & Id = dynallocate<matrix>(
r,
c);
1742 for (
unsigned i=0; i<
r && i<
c; i++)
1750 matrix & M = dynallocate<matrix>(
r,
c);
1753 bool long_format = (
r > 10 ||
c > 10);
1754 bool single_row = (
r == 1 ||
c == 1);
1756 for (
unsigned i=0; i<
r; i++) {
1757 for (
unsigned j=0; j<
c; j++) {
1758 std::ostringstream s1, s2;
1760 s2 << tex_base_name <<
"_{";
1771 s1 <<
'_' << i <<
'_' << j;
1772 s2 << i <<
';' << j <<
"}";
1775 s2 << i << j <<
'}';
1778 M(i, j) =
symbol(s1.str(), s2.str());
1787 if (
r+1>
m.rows() ||
c+1>
m.cols() ||
m.cols()<2 ||
m.rows()<2)
1788 throw std::runtime_error(
"minor_matrix(): index out of bounds");
1790 const unsigned rows =
m.rows()-1;
1791 const unsigned cols =
m.cols()-1;
1805 M(ro2,co2) =
m(ro, co);
1818 if (
r+nr>
m.rows() ||
c+nc>
m.cols())
1819 throw std::runtime_error(
"sub_matrix(): index out of bounds");
1821 matrix & M = dynallocate<matrix>(nr, nc);
1824 for (
unsigned ro=0; ro<nr; ++ro) {
1825 for (
unsigned co=0; co<nc; ++co) {
1826 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...