* matrix::print(): Implement print_latex.
* Add unit_matrix(unsigend) and unit_matrix(unsigned,unsigned).
if (is_a<print_python_repr>(c))
c.s << class_name() << '(';
if (is_a<print_python_repr>(c))
c.s << class_name() << '(';
- c.s << "[";
- for (unsigned y=0; y<row-1; ++y) {
+ if (is_a<print_latex>(c))
+ c.s << "\\left(\\begin{array}{" << std::string(col,'c') << "}";
+ else
- for (unsigned x=0; x<col-1; ++x) {
- m[y*col+x].print(c);
- c.s << ",";
+
+ for (unsigned ro=0; ro<row; ++ro) {
+ if (!is_a<print_latex>(c))
+ c.s << "[";
+ for (unsigned co=0; co<col; ++co) {
+ m[ro*col+co].print(c);
+ if (co<col-1) {
+ if (is_a<print_latex>(c))
+ c.s << "&";
+ else
+ c.s << ",";
+ } else {
+ if (!is_a<print_latex>(c))
+ c.s << "]";
+ }
+ }
+ if (ro<row-1) {
+ if (is_a<print_latex>(c))
+ c.s << "\\\\";
+ else
+ c.s << ",";
- m[col*(y+1)-1].print(c);
- c.s << "],";
- }
- c.s << "[";
- for (unsigned x=0; x<col-1; ++x) {
- m[(row-1)*col+x].print(c);
- c.s << ",";
- m[row*col-1].print(c);
- c.s << "]]";
+
+ if (is_a<print_latex>(c))
+ c.s << "\\end{array}\\right)";
+ else
+ c.s << "]";
if (is_a<print_python_repr>(c))
c.s << ')';
if (is_a<print_python_repr>(c))
c.s << ')';
matrix C(row,col);
for (unsigned r=0; r<row; ++r)
C(r,r) = _ex1;
matrix C(row,col);
for (unsigned r=0; r<row; ++r)
C(r,r) = _ex1;
+ if (b.is_zero())
+ return C;
// This loop computes the representation of b in base 2 from right
// to left and multiplies the factors whenever needed. Note
// that this is not entirely optimal but close to optimal and
// "better" algorithms are much harder to implement. (See Knuth,
// TAoCP2, section "Evaluation of Powers" for a good discussion.)
// This loop computes the representation of b in base 2 from right
// to left and multiplies the factors whenever needed. Note
// that this is not entirely optimal but close to optimal and
// "better" algorithms are much harder to implement. (See Knuth,
// TAoCP2, section "Evaluation of Powers" for a good discussion.)
if (b.is_odd()) {
C = C.mul(A);
if (b.is_odd()) {
C = C.mul(A);
- b *= _num1_2; // b /= 2, still integer.
+ b /= _num2; // still integer.
A = A.mul(A);
}
return A.mul(C);
A = A.mul(A);
}
return A.mul(C);
+ex unit_matrix(unsigned r, unsigned c)
+{
+ matrix Id(r,c);
+ for (unsigned i=0; i<r && i<c; ++i)
+ Id(i,i) = _ex1;
+ return Id;
+}
+
/** Convert list of diagonal elements to matrix. */
extern ex diag_matrix(const lst & l);
/** Convert list of diagonal elements to matrix. */
extern ex diag_matrix(const lst & l);
+/** Create a r times c unit matrix. */
+extern ex unit_matrix(unsigned r, unsigned c);
+
+/** Create a x times x unit matrix. */
+inline ex unit_matrix(unsigned x)
+{ return unit_matrix(x, x); }
+
} // namespace GiNaC
#endif // ndef __GINAC_MATRIX_H__
} // namespace GiNaC
#endif // ndef __GINAC_MATRIX_H__