23 #ifndef GINAC_MATRIX_H 24 #define GINAC_MATRIX_H 45 matrix(std::initializer_list<std::initializer_list<ex>> l);
52 size_t nops()
const override;
53 ex op(
size_t i)
const override;
87 matrix &
set(
unsigned ro,
unsigned co,
const ex &
value) { (*this)(ro, co) =
value;
return *
this; }
96 unsigned rank()
const;
106 int pivot(
unsigned ro,
unsigned co,
bool symbolic =
true);
108 void print_elements(
const print_context &
c,
const char *row_start,
const char *row_end,
const char *row_sep,
const char *col_sep)
const;
130 {
return m.evalf(); }
139 {
return m.transpose(); }
145 {
return m.trace(); }
148 {
return m.charpoly(lambda); }
153 {
return m.inverse(algo); }
167 extern ex
diag_matrix(std::initializer_list<ex> l);
179 extern ex
symbolic_matrix(
unsigned r,
unsigned c,
const std::string & base_name,
const std::string & tex_base_name);
186 extern ex
sub_matrix(
const matrix&
m,
unsigned r,
unsigned nr,
unsigned c,
unsigned nc);
195 #endif // ndef GINAC_MATRIX_H matrix transpose() const
Transposed of an m x n matrix, producing a new n x m matrix object that represents the transposed...
size_t nops(const ex &thisex)
ex & let_op(size_t i) override
returns writable matrix entry at position (i/col, icol).
matrix sub(const matrix &other) const
Difference of matrices.
ex eval_indexed(const basic &i) const override
Automatic symbolic evaluation of an indexed matrix.
ex scalar_mul_indexed(const ex &self, const numeric &other) const override
Product of an indexed matrix with a number.
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
void do_print(const print_context &c, unsigned level) const
ex trace(const matrix &m)
ex evalm() const override
Evaluate sums, products and integer powers of matrices.
matrix transpose(const matrix &m)
unsigned rows(const matrix &m)
ex diag_matrix(const lst &l)
Convert list of diagonal elements to matrix.
unsigned rank() const
Compute the rank of this matrix.
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.
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
ex unit_matrix(unsigned r, unsigned c)
Create an r times c unit matrix.
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...
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...
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...
Archiving of GiNaC expressions.
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Context for python-parsable output.
void print_elements(const print_context &c, const char *row_start, const char *row_end, const char *row_sep, const char *col_sep) const
unsigned rank(const matrix &m)
matrix mul_scalar(const ex &other) const
Product of matrix and scalar expression.
matrix add(const matrix &other) const
Sum of matrices.
bool contract_with(exvector::iterator self, exvector::iterator other, exvector &v) const override
Contraction of an indexed matrix with something else.
unsigned row
number of rows
container< std::list > lst
const ex & operator()(unsigned ro, unsigned co) const
operator() to access elements for reading.
ex evalf(const ex &thisex)
int pivot(unsigned ro, unsigned co, bool symbolic=true)
Partial pivoting method for matrix elimination schemes.
Definition of optimizing macros.
unsigned cols(const matrix &m)
unsigned cols() const
Get number of columns.
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Context for latex-parsable output.
bool is_zero_matrix() const
Function to check that all elements of the matrix are zero.
matrix mul(const matrix &other) const
Product of matrices.
ex conjugate() const override
Complex conjugate every matrix entry.
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...
exvector m
representation (cols indexed first)
matrix(unsigned r, unsigned c)
Very common ctor.
matrix pow(const ex &expn) const
Power of a matrix.
ex determinant(const matrix &m, unsigned options=determinant_algo::automatic)
std::vector< ex > exvector
std::map< ex, ex, ex_is_less > exmap
ex add_indexed(const ex &self, const ex &other) const override
Sum of two indexed matrices.
ex charpoly(const matrix &m, const ex &lambda)
unsigned col
number of columns
Interface to GiNaC's light-weight expression handles.
ex determinant(unsigned algo=determinant_algo::automatic) const
Determinant of square matrix.
Base class for print_contexts.
Interface to GiNaC's ABC.
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...
void do_print_latex(const print_latex &c, unsigned level) const
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Lightweight wrapper for GiNaC's symbolic objects.
ex determinant_minor() const
Recursive determinant for small matrices having at least one symbolic entry.
void do_print_python_repr(const print_python_repr &c, unsigned level) const
ex imag_part() const override
ex op(size_t i) const override
returns matrix entry at position (i/col, icol).
ex trace() const
Trace of a matrix.
matrix inverse() const
Inverse of this matrix, with automatic algorithm selection.
Wrapper template for making GiNaC classes out of STL containers.
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
std::vector< unsigned > echelon_form(unsigned algo, int n)
size_t nops() const override
nops is defined to be rows x columns.
Switch to control algorithm for linear system solving.
ex lst_to_matrix(const lst &l)
Convert list of lists to 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...
GINAC_DECLARE_UNARCHIVER(add)
void archive(archive_node &n) const override
Save (a.k.a.
unsigned rows() const
Get number of rows.
ex real_part() const override
ex charpoly(const ex &lambda) const
Characteristic Polynomial.
matrix inverse(const matrix &m)
std::vector< unsigned > markowitz_elimination(unsigned n)
ex expand(const ex &thisex, unsigned options=0)
unsigned return_type() const override