# Matrix Expressions

## Matrix Expression

#### Description

The templated class `matrix_expression<E>` forms the base for all static derived matrix expression classes including class `matrix` itself.

#### Definition

Defined in the header matrix_expression.hpp.

#### Template parameters

Parameter | Description | Default
--- | --- | ---
`E` | The type of the matrix expression. |

#### Model of

None.

#### Type requirements

None.

#### Public base classes

None.

#### Members

Member | Description
--- | ---
`const expression_type &operator () () const` | Returns a `const` reference of the expression.
`expression_type &operator () ()` | Returns a reference of the expression.

#### Interface

        // Base class for the Barton Nackman trick
        template<class E>
        struct matrix_expression {
            typedef E expression_type;
            typedef matrix_tag type_category;

            // This class could define an common interface for all
            // statically derived expression type classes.
            // Due to a compiler deficiency - one can not reference class typedefs of E
            // on MSVC 6.0 (error C2027) - we only implement the casts.

            const expression_type &operator () () const;
            expression_type &operator () ();
        };

## Matrix References

### Constant Reference

#### Description

The templated class `matrix_const_reference<E>` contains a constant reference to a matrix expression.

#### Definition

Defined in the header matrix_expression.hpp.

#### Template parameters

Parameter | Description | Default
--- | --- | ---
`E` | The type of the matrix expression. |

#### Model of

Matrix Expression.

#### Type requirements

None, except for those imposed by the requirements of Matrix Expression.

#### Public base classes

`matrix_expression<matrix_const_reference<E> >`

#### Members

Member | Description
--- | ---
`matrix_const_reference (const expression_type &e)` | Constructs a constant reference of the expression.
`size_type size1 () const` | Returns the number of rows.
`size_type size2 () const` | Returns the number of columns.
`const_reference operator () (size_type i, size_type j) const` | Returns the value of the `j`-th element in the`i`-th row.
`const_iterator1 begin1 () const` | Returns a `const_iterator1` pointing to the beginning of the expression.
`const_iterator1 end1 () const` | Returns a `const_iterator1` pointing to the end of the expression.
`const_iterator2 begin2 () const` | Returns a `const_iterator2` pointing to the beginning of the expression.
`const_iterator2 end2 () const` | Returns a `const_iterator2` pointing to the end of the expression.
`const_reverse_iterator1 rbegin1 () const` | Returns a `const_reverse_iterator1` pointing to the beginning of the reversed expression.
`const_reverse_iterator1 rend1 () const` | Returns a `const_reverse_iterator1` pointing to the end of the reversed expression.
`const_reverse_iterator2 rbegin2 () const` | Returns a `const_reverse_iterator2` pointing to the beginning of the reversed expression.
`const_reverse_iterator2 rend2 () const` | Returns a `const_reverse_iterator2` pointing to the end of the reversed expression.

Interface

        template<class E>
        class matrix_const_reference:
            public matrix_expression<matrix_const_reference<E> > {
        public:
            typedef E expression_type;
            typedef typename E::size_type size_type;
            typedef typename E::difference_type difference_type;
            typedef typename E::value_type value_type;
            typedef typename E::const_reference const_reference;
            typedef const_reference reference;
            typedef typename E::const_pointer const_pointer;
            typedef const_pointer pointer;
            typedef typename E::orientation_category orientation_category;
            typedef typename E::const_iterator1 const_iterator1_type;
            typedef typename E::const_iterator2 const_iterator2_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_const_reference ();
            matrix_const_reference (const expression_type &e);

            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const expression_type &expression () const;

            // Element access
            const_reference operator () (size_type i, size_type j) const;

            typedef const_iterator1_type const_iterator1;
            typedef const_iterator1 iterator1;
            typedef const_iterator2_type const_iterator2;
            typedef const_iterator2 iterator2;

            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;

            // Iterators are the iterators of the referenced expression.

            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;

            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;

            // Reverse iterators

            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;

            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;

            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;

            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
        };

### Reference

#### Description

The templated class `matrix_reference<E>` contains a reference to a matrix expression.

#### Definition

Defined in the header matrix_expression.hpp.

#### Template parameters

Parameter | Description | Default
--- | --- | ---
`E` | The type of the matrix expression. |

#### Model of

Matrix Expression.

#### Type requirements

None, except for those imposed by the requirements of Matrix Expression.

#### Public base classes

`matrix_expression<matrix_reference<E> >`

#### Members

Member | Description
--- | ---
`matrix_reference (expression_type &e)` | Constructs a constant reference of the expression.
`void resize (size_type size1, size2)` | Resizes the expression to hold at most `size1` rows of `size2` elements.
`size_type size1 () const` | Returns the number of rows.
`size_type size2 () const` | Returns the number of columns.
`const_reference operator () (size_type i, size_type j) const` | Returns the value of the `j`-th element in the`i`-th row.
`reference operator () (size_type i, size_type j)` | Returns a reference of the `j`-th element in the`i`-th row.
`const_iterator1 begin1 () const` | Returns a `const_iterator1` pointing to the beginning of the expression.
`const_iterator1 end1 () const` | Returns a `const_iterator1` pointing to the end of the expression.
`iterator1 begin1 ()` | Returns a `iterator1` pointing to the beginning of the expression.
`iterator1 end1 ()` | Returns a `iterator1` pointing to the end of the expression.
`const_iterator2 begin2 () const` | Returns a `const_iterator2` pointing to the beginning of the expression.
`const_iterator2 end2 () const` | Returns a `const_iterator2` pointing to the end of the expression.
`iterator2 begin2 ()` | Returns a `iterator2` pointing to the beginning of the expression.
`iterator2 end2 ()` | Returns a `iterator2` pointing to the end of the expression.
`const_reverse_iterator1 rbegin1 () const` | Returns a `const_reverse_iterator1` pointing to the beginning of the reversed expression.
`const_reverse_iterator1 rend1 () const` | Returns a `const_reverse_iterator1` pointing to the end of the reversed expression.
`reverse_iterator1 rbegin1 ()` | Returns a `reverse_iterator1` pointing to the beginning of the reversed expression.
`reverse_iterator1 rend1 ()` | Returns a `reverse_iterator1` pointing to the end of the reversed expression.
`const_reverse_iterator2 rbegin2 () const` | Returns a `const_reverse_iterator2` pointing to the beginning of the reversed expression.
`const_reverse_iterator2 rend2 () const` | Returns a `const_reverse_iterator2` pointing to the end of the reversed expression.
`reverse_iterator2 rbegin2 ()` | Returns a `reverse_iterator2` pointing to the beginning of the reversed expression.
`reverse_iterator2 rend2 ()` | Returns a `reverse_iterator2` pointing to the end of the reversed expression.

#### Interface

        template<class E>
        class matrix_reference:
            public matrix_expression<matrix_reference<E> > {
        public:
            typedef E expression_type;
            typedef typename E::size_type size_type;
            typedef typename E::difference_type difference_type;
            typedef typename E::value_type value_type;
            typedef typename E::const_reference const_reference;
            typedef typename E::reference reference;
            typedef typename E::const_pointer const_pointer;
            typedef typename E::pointer pointer;
            typedef typename E::orientation_category orientation_category;
            typedef typename E::const_iterator1 const_iterator1_type;
            typedef typename E::iterator1 iterator1_type;
            typedef typename E::const_iterator2 const_iterator2_type;
            typedef typename E::iterator2 iterator2_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_reference ();
            matrix_reference (expression_type &e);

            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const expression_type &expression () const;
            expression_type &expression ();

            // Resizing
            void resize (size_type size1, size_type size2);

            // Element access
            const_reference operator () (size_type i, size_type j) const;
            reference operator () (size_type i, size_type j);

            typedef const_iterator1_type const_iterator1;
            typedef iterator1_type iterator1;
            typedef const_iterator2_type const_iterator2;
            typedef iterator2_type iterator2;

            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            iterator1 find_first1 (int rank, size_type i, size_type j);
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            iterator1 find_last1 (int rank, size_type i, size_type j);
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            iterator2 find_first2 (int rank, size_type i, size_type j);
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;
            iterator2 find_last2 (int rank, size_type i, size_type j);

            // Iterators are the iterators of the referenced expression.

            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;

            iterator1 begin1 ();
            iterator1 end1 ();

            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;

            iterator2 begin2 ();
            iterator2 end2 ();

            // Reverse iterators

            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;

            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;

            typedef reverse_iterator_base1<iterator1> reverse_iterator1;

            reverse_iterator1 rbegin1 ();
            reverse_iterator1 rend1 ();

            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;

            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;

            typedef reverse_iterator_base2<iterator2> reverse_iterator2;

            reverse_iterator2 rbegin2 ();
            reverse_iterator2 rend2 ();
        };

## Matrix Operations

### Unary Operation Description

#### Description

The templated classes `matrix_unary1<E, F>` and `matrix_unary2<E, F>` describe unary matrix operations.

#### Definition

Defined in the header matrix_expression.hpp.

#### Template parameters

Parameter | Description | Default
--- | --- | ---
`E` | The type of the matrix expression. |
`F` | The type of the operation. |

#### Model of

Matrix Expression.

#### Type requirements

None, except for those imposed by the requirements of Matrix Expression.

#### Public base classes

`matrix_expression<matrix_unary1<E, F> >` and`matrix_expression<matrix_unary2<E, F> >` resp.

#### Members

Member | Description
--- | ---
`matrix_unary1 (const expression_type &e)` | Constructs a description of the expression.
`matrix_unary2 (const expression_type &e)` | Constructs a description of the expression.
`size_type size1 () const` | Returns the number of rows.
`size_type size2 () const` | Returns the number of columns.
`const_reference operator () (size_type i, size_type j) const` | Returns the value of the `j`-th element in the`i`-th row.
`const_iterator1 begin1 () const` | Returns a `const_iterator1` pointing to the beginning of the expression.
`const_iterator1 end1 () const` | Returns a `const_iterator1` pointing to the end of the expression.
`const_iterator2 begin2 () const` | Returns a `const_iterator2` pointing to the beginning of the expression.
`const_iterator2 end2 () const` | Returns a `const_iterator2` pointing to the end of the expression.
`const_reverse_iterator1 rbegin1 () const` | Returns a `const_reverse_iterator1` pointing to the beginning of the reversed expression.
`const_reverse_iterator1 rend1 () const` | Returns a `const_reverse_iterator1` pointing to the end of the reversed expression.
`const_reverse_iterator2 rbegin2 () const` | Returns a `const_reverse_iterator2` pointing to the beginning of the reversed expression.
`const_reverse_iterator2 rend2 () const` | Returns a `const_reverse_iterator2` pointing to the end of the reversed expression.

#### Interface

        template<class E, class F>
        class matrix_unary1:
            public matrix_expression<matrix_unary1<E, F> > {
        public:
            typedef E expression_type;
            typedef F functor_type;
            typedef typename E::size_type size_type;
            typedef typename E::difference_type difference_type;
            typedef typename F::result_type value_type;
            typedef value_type const_reference;
            typedef const_reference reference;
            typedef const value_type *const_pointer;
            typedef const_pointer pointer;
            typedef const matrix_unary1<E, F> const_closure_type;
            typedef typename E::orientation_category orientation_category;
            typedef typename E::const_iterator1 const_iterator1_type;
            typedef typename E::const_iterator2 const_iterator2_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_unary1 ();
            matrix_unary1 (const expression_type &e);

            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const expression_type &expression () const;

            // Element access
            const_reference operator () (size_type i, size_type j) const;

            class const_iterator1;
            typedef const_iterator1 iterator1;
            class const_iterator2;
            typedef const_iterator2 iterator2;
            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;

            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;

            // Iterators enhance the iterators of the referenced expression
            // with the unary functor.

            class const_iterator1:
                public container_const_reference<matrix_unary1>,
                public random_access_iterator_base<const_iterator1, value_type> {
            public:
                typedef typename E::const_iterator1::iterator_category iterator_category;
                typedef typename matrix_unary1::difference_type difference_type;
                typedef typename matrix_unary1::value_type value_type;
                typedef typename matrix_unary1::const_reference reference;
                typedef typename matrix_unary1::const_pointer pointer;
                typedef const_iterator2 dual_iterator_type;
                typedef const_reverse_iterator2 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator1 ();
                const_iterator1 (const matrix_unary1 &mu, const const_iterator1_type &it);

                // Arithmetic
                const_iterator1 &operator ++ ();
                const_iterator1 &operator -- ();
                const_iterator1 &operator += (difference_type n);
                const_iterator1 &operator -= (difference_type n);
                difference_type operator - (const const_iterator1 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator2 begin () const;
                const_iterator2 end () const;
                const_reverse_iterator2 rbegin () const;
                const_reverse_iterator2 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator1 &operator = (const const_iterator1 &it);

                // Comparison
                bool operator == (const const_iterator1 &it) const;
                bool operator <(const const_iterator1 &it) const;
            };

            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;

            class const_iterator2:
                public container_const_reference<matrix_unary1>,
                public random_access_iterator_base<const_iterator2, value_type> {
            public:
                typedef typename E::const_iterator2::iterator_category iterator_category;
                typedef typename matrix_unary1::difference_type difference_type;
                typedef typename matrix_unary1::value_type value_type;
                typedef typename matrix_unary1::const_reference reference;
                typedef typename matrix_unary1::const_pointer pointer;
                typedef const_iterator1 dual_iterator_type;
                typedef const_reverse_iterator1 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator2 ();
                const_iterator2 (const matrix_unary1 &mu, const const_iterator2_type &it);

                // Arithmetic
                const_iterator2 &operator ++ ();
                const_iterator2 &operator -- ();
                const_iterator2 &operator += (difference_type n);
                const_iterator2 &operator -= (difference_type n);
                difference_type operator - (const const_iterator2 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator1 begin () const;
                const_iterator1 end () const;
                const_reverse_iterator1 rbegin () const;
                const_reverse_iterator1 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator2 &operator = (const const_iterator2 &it);

                // Comparison
                bool operator == (const const_iterator2 &it) const;
                bool operator <(const const_iterator2 &it) const;
            };

            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;

            // Reverse iterators

            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;

            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
        };

        template<class E, class F>
        class matrix_unary2:
            public matrix_expression<matrix_unary2<E, F> > {
        public:
            typedef E expression_type;
            typedef F functor_type;
            typedef typename E::size_type size_type;
            typedef typename E::difference_type difference_type;
            typedef typename F::result_type value_type;
            typedef value_type const_reference;
            typedef const_reference reference;
            typedef const value_type *const_pointer;
            typedef const_pointer pointer;
            typedef const matrix_unary2<E, F> const_closure_type;
            typedef typename E::orientation_category orientation_category;
            typedef typename E::const_iterator1 const_iterator2_type;
            typedef typename E::const_iterator2 const_iterator1_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_unary2 ();
            matrix_unary2 (const expression_type &e);

            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const expression_type &expression () const;

            // Element access
            const_reference operator () (size_type i, size_type j) const;

            class const_iterator1;
            typedef const_iterator1 iterator1;
            class const_iterator2;
            typedef const_iterator2 iterator2;
            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;

            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;

            // Iterators enhance the iterators of the referenced expression
            // with the unary functor.

            class const_iterator1:
                public container_const_reference<matrix_unary2>,
                public random_access_iterator_base<const_iterator1, value_type> {
            public:
                typedef typename E::const_iterator2::iterator_category iterator_category;
                typedef typename matrix_unary2::difference_type difference_type;
                typedef typename matrix_unary2::value_type value_type;
                typedef typename matrix_unary2::const_reference reference;
                typedef typename matrix_unary2::const_pointer pointer;
                typedef const_iterator2 dual_iterator_type;
                typedef const_reverse_iterator2 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator1 ();
                const_iterator1 (const matrix_unary2 &mu, const const_iterator1_type &it);

                // Arithmetic
                const_iterator1 &operator ++ ();
                const_iterator1 &operator -- ();
                const_iterator1 &operator += (difference_type n);
                const_iterator1 &operator -= (difference_type n);
                difference_type operator - (const const_iterator1 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator2 begin () const;
                const_iterator2 end () const;
                const_reverse_iterator2 rbegin () const;
                const_reverse_iterator2 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator1 &operator = (const const_iterator1 &it);

                // Comparison
                bool operator == (const const_iterator1 &it) const;
                bool operator <(const const_iterator1 &it) const;
            };

            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;

            class const_iterator2:
                public container_const_reference<matrix_unary2>,
                public random_access_iterator_base<const_iterator2, value_type> {
            public:
                typedef typename E::const_iterator1::iterator_category iterator_category;
                typedef typename matrix_unary2::difference_type difference_type;
                typedef typename matrix_unary2::value_type value_type;
                typedef typename matrix_unary2::const_reference reference;
                typedef typename matrix_unary2::const_pointer pointer;
                typedef const_iterator1 dual_iterator_type;
                typedef const_reverse_iterator1 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator2 ();
                const_iterator2 (const matrix_unary2 &mu, const const_iterator2_type &it);

                // Arithmetic
                const_iterator2 &operator ++ ();
                const_iterator2 &operator -- ();
                const_iterator2 &operator += (difference_type n);
                const_iterator2 &operator -= (difference_type n);
                difference_type operator - (const const_iterator2 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator1 begin () const;
                const_iterator1 end () const;
                const_reverse_iterator1 rbegin () const;
                const_reverse_iterator1 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator2 &operator = (const const_iterator2 &it);

                // Comparison
                bool operator == (const const_iterator2 &it) const;
                bool operator <(const const_iterator2 &it) const;
            };

            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;

            // Reverse iterators

            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;

            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
        };

### Unary Operations

#### Prototypes

        template<class E, class F>
        struct matrix_unary1_traits {
            typedef matrix_unary1<typename E::const_closure_type, F> expression_type;
            typedef expression_type result_type;
        };

        // (- m) [i] [j] = - m [i] [j]
        template<class E>
        typename matrix_unary1_traits<E, scalar_negate<typename E::value_type> >::result_type
        operator - (const matrix_expression<E> &e);

        // (conj m) [i] [j] = conj (m [i] [j])
        template<class E>
        typename matrix_unary1_traits<E, scalar_conj<typename E::value_type> >::result_type
        conj (const matrix_expression<E> &e);

        // (real m) [i] [j] = real (m [i] [j])
        template<class E>
        typename matrix_unary1_traits<E, scalar_real<typename E::value_type> >::result_type
        real (const matrix_expression<E> &e);

        // (imag m) [i] [j] = imag (m [i] [j])
        template<class E>
        typename matrix_unary1_traits<E, scalar_imag<typename E::value_type> >::result_type
        imag (const matrix_expression<E> &e);

        template<class E, class F>
        struct matrix_unary2_traits {
            typedef matrix_unary2<typename E::const_closure_type, F> expression_type;
            typedef expression_type result_type;
        };

        // (trans m) [i] [j] = m [j] [i]
        template<class E>
        typename matrix_unary2_traits<E, scalar_identity<typename E::value_type> >::result_type
        trans (const matrix_expression<E> &e);

        // (herm m) [i] [j] = conj (m [j] [i])
        template<class E>
        typename matrix_unary2_traits<E, scalar_conj<typename E::value_type> >::result_type
        herm (const matrix_expression<E> &e);

#### Description

`operator -` computes the additive inverse of a matrix expression. `conj` computes the complex conjugate of a matrix expression.`real` and `imag` compute the real and imaginary parts of a matrix expression. `trans` computes the transpose of a matrix expression. `herm` computes the hermitian, i.e. the complex conjugate of the transpose of a matrix expression.

#### Definition

Defined in the header matrix_expression.hpp.

#### Type requirements

- `E` is a model of Matrix Expression.

#### Preconditions

None.

#### Complexity

Quadratic depending from the size of the matrix expression.

#### Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<std::complex<double> > m (3, 3);
        for (int i = 0; i < m.size1 (); ++ i)
            for (int j = 0; j < m.size2 (); ++ j)
                m (i, j) = std::complex (3 * i + j, 3 * i + j);

        std::cout << - m << std::endl;
        std::cout << conj (m) << std::endl;
        std::cout << real (m) << std::endl;
        std::cout << imag (m) << std::endl;
        std::cout << trans (m) << std::endl;
        std::cout << herm (m) << std::endl;
    }

### Binary Operation Description

#### Description

The templated class `matrix_binary<E1, E2, F>` describes a binary matrix operation.

#### Definition

Defined in the header matrix_expression.hpp.

#### Template parameters

Parameter | Description | Default
--- | --- | ---
`E1` | The type of the first matrix expression. |
`E2` | The type of the second matrix expression. |
`F` | The type of the operation. |

#### Model of

Matrix Expression.

#### Type requirements

None, except for those imposed by the requirements of Matrix Expression.

#### Public base classes

`matrix_expression<matrix_binary<E1, E2, F> >`.

#### Members

Member | Description
--- | ---
`matrix_binary (const expression1_type &e1, const expression2_type &e2)` | Constructs a description of the expression.
`size_type size1 () const` | Returns the number of rows.
`size_type size2 () const` | Returns the number of columns.
`const_reference operator () (size_type i, size_type j) const` | Returns the value of the `j`-th element in the`i`-th row.
`const_iterator1 begin1 () const` | Returns a `const_iterator1` pointing to the beginning of the expression.
`const_iterator1 end1 () const` | Returns a `const_iterator1` pointing to the end of the expression.
`const_iterator2 begin2 () const` | Returns a `const_iterator2` pointing to the beginning of the expression.
`const_iterator2 end2 () const` | Returns a `const_iterator2` pointing to the end of the expression.
`const_reverse_iterator1 rbegin1 () const` | Returns a `const_reverse_iterator1` pointing to the beginning of the reversed expression.
`const_reverse_iterator1 rend1 () const` | Returns a `const_reverse_iterator1` pointing to the end of the reversed expression.
`const_reverse_iterator2 rbegin2 () const` | Returns a `const_reverse_iterator2` pointing to the beginning of the reversed expression.
`const_reverse_iterator2 rend2 () const` | Returns a `const_reverse_iterator2` pointing to the end of the reversed expression.

#### Interface

        template<class E1, class E2, class F>
        class matrix_binary:
            public matrix_expression<matrix_binary<E1, E2, F> > {
        public:
            typedef E1 expression1_type;
            typedef E2 expression2_type;
            typedef F functor_type;
            typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
            typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
            typedef typename F::result_type value_type;
            typedef value_type const_reference;
            typedef const_reference reference;
            typedef const value_type *const_pointer;
            typedef const_pointer pointer;
            typedef const matrix_binary<E1, E2, F> const_closure_type;
            typedef unknown_orientation_tag orientation_category;
            typedef typename E1::const_iterator1 const_iterator11_type;
            typedef typename E1::const_iterator2 const_iterator12_type;
            typedef typename E2::const_iterator1 const_iterator21_type;
            typedef typename E2::const_iterator2 const_iterator22_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_binary ();
            matrix_binary (const E1 &e1, const E2 &e2);

            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const expression1_type &expression1 () const;
            const expression2_type &expression2 () const;

            // Element access
            const_reference operator () (size_type i, size_type j) const;

            class const_iterator1;
            typedef const_iterator1 iterator1;
            class const_iterator2;
            typedef const_iterator2 iterator2;
            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;

            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;

            // Iterators enhance the iterators of the referenced expression
            // with the binary functor.

            class const_iterator1:
                public container_const_reference<matrix_binary>,
                public random_access_iterator_base<const_iterator1, value_type> {
            public:
                typedef typename restrict_traits<typename E1::const_iterator1::iterator_category,
                                                 typename E2::const_iterator1::iterator_category>::iterator_category iterator_category;
                typedef typename matrix_binary::difference_type difference_type;
                typedef typename matrix_binary::value_type value_type;
                typedef typename matrix_binary::const_reference reference;
                typedef typename matrix_binary::const_pointer pointer;
                typedef const_iterator2 dual_iterator_type;
                typedef const_reverse_iterator2 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator1 ();
                const_iterator1 (const matrix_binary &mb, size_type i, size_type j,
                                 const const_iterator11_type &it1, const const_iterator11_type &it1_end,
                                 const const_iterator21_type &it2, const const_iterator21_type &it2_end);

                // Dense specializations
                void increment (dense_random_access_iterator_tag);
                void decrement (dense_random_access_iterator_tag);
                value_type dereference (dense_random_access_iterator_tag) const;

                // Packed specializations
                void increment (packed_random_access_iterator_tag);
                void decrement (packed_random_access_iterator_tag);
                value_type dereference (packed_random_access_iterator_tag) const;

                // Sparse specializations
                void increment (sparse_bidirectional_iterator_tag);
                void decrement (sparse_bidirectional_iterator_tag);
                value_type dereference (sparse_bidirectional_iterator_tag) const;

                // Arithmetic
                const_iterator1 &operator ++ ();
                const_iterator1 &operator -- ();
                const_iterator1 &operator += (difference_type n);
                const_iterator1 &operator -= (difference_type n);
                difference_type operator - (const const_iterator1 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator2 begin () const;
                const_iterator2 end () const;
                const_reverse_iterator2 rbegin () const;
                const_reverse_iterator2 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator1 &operator = (const const_iterator1 &it);

                // Comparison
                bool operator == (const const_iterator1 &it) const;
                bool operator <(const const_iterator1 &it) const;
            };

            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;

            class const_iterator2:
                public container_const_reference<matrix_binary>,
                public random_access_iterator_base<const_iterator2, value_type> {
            public:
                typedef typename restrict_traits<typename E1::const_iterator2::iterator_category,
                                                 typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
                typedef typename matrix_binary::difference_type difference_type;
                typedef typename matrix_binary::value_type value_type;
                typedef typename matrix_binary::const_reference reference;
                typedef typename matrix_binary::const_pointer pointer;
                typedef const_iterator1 dual_iterator_type;
                typedef const_reverse_iterator1 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator2 ();
                const_iterator2 (const matrix_binary &mb, size_type i, size_type j,
                                 const const_iterator12_type &it1, const const_iterator12_type &it1_end,
                                 const const_iterator22_type &it2, const const_iterator22_type &it2_end);

                // Dense specializations
                void increment (dense_random_access_iterator_tag);
                void decrement (dense_random_access_iterator_tag);
                value_type dereference (dense_random_access_iterator_tag) const;

                // Packed specializations
                void increment (packed_random_access_iterator_tag);
                void decrement (packed_random_access_iterator_tag);
                value_type dereference (packed_random_access_iterator_tag) const;

                // Sparse specializations
                void increment (sparse_bidirectional_iterator_tag);
                void decrement (sparse_bidirectional_iterator_tag);
                value_type dereference (sparse_bidirectional_iterator_tag) const;

                // Arithmetic
                const_iterator2 &operator ++ ();
                const_iterator2 &operator -- ();
                const_iterator2 &operator += (difference_type n);
                const_iterator2 &operator -= (difference_type n);
                difference_type operator - (const const_iterator2 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator1 begin () const;
                const_iterator1 end () const;
                const_reverse_iterator1 rbegin () const;
                const_reverse_iterator1 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator2 &operator = (const const_iterator2 &it);

                // Comparison
                bool operator == (const const_iterator2 &it) const;
                bool operator <(const const_iterator2 &it) const;
            };

            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;

            // Reverse iterators

            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;

            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
        };

### Binary Operations

#### Prototypes

        template<class E1, class E2, class F>
        struct matrix_binary_traits {
            typedef matrix_binary<typename E1::const_closure_type,
                                  typename E2::const_closure_type, F> expression_type;
            typedef expression_type result_type;
        };

        // (m1 + m2) [i] [j] = m1 [i] [j] + m2 [i] [j]
        template<class E1, class E2>
        typename matrix_binary_traits<E1, E2, scalar_plus<typename E1::value_type,
                                                          typename E2::value_type> >::result_type
        operator + (const matrix_expression<E1> &e1,
                    const matrix_expression<E2> &e2);

        // (m1 - m2) [i] [j] = m1 [i] [j] - m2 [i] [j]
        template<class E1, class E2>
        typename matrix_binary_traits<E1, E2, scalar_minus<typename E1::value_type,
                                                           typename E2::value_type> >::result_type
        operator - (const matrix_expression<E1> &e1,
                    const matrix_expression<E2> &e2);

#### Description

`operator +` computes the sum of two matrix expressions. `operator -` computes the difference of two matrix expressions.

#### Definition

Defined in the header matrix_expression.hpp.

#### Type requirements

- `E1` is a model of Matrix Expression.
- `E2` is a model of Matrix Expression.

#### Preconditions

- `e1 ().size1 () == e2 ().size1 ()`
- `e1 ().size2 () == e2 ().size2 ()`

#### Complexity

Quadratic depending from the size of the matrix expressions.

#### Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double > m1 (3, 3), m (3, 3);
        for (int i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i)
            for (int j = 0; j < std::min (m1.size2 (), m2.size2 ()); ++ j)
                m1 (i, j) = m2 (i, j) = 3 * i + j;

        std::cout << m1 + m2 << std::endl;
        std::cout << m1 - m2 << std::endl;
    }

### Scalar Matrix Operation Description

#### Description

The templated classes `matrix_binary_scalar1<E1, E2, F>` and `matrix_binary_scalar2<E1, E2, F>` describe binary operations between a scalar and a matrix.

#### Definition

Defined in the header matrix_expression.hpp.

#### Template parameters

Parameter | Description | Default
--- | --- | ---
`E1/E2` | The type of the scalar expression. |
`E2/E1` | The type of the matrix expression. |
`F` | The type of the operation. |

#### Model of

Matrix Expression.

#### Type requirements

None, except for those imposed by the requirements of Matrix Expression.

#### Public base classes

`matrix_expression<matrix_binary_scalar1<E1, E2, F> >` and`matrix_expression<matrix_binary_scalar2<E1, E2, F> >` resp.

#### Members

Member | Description
--- | ---
`matrix_binary_scalar1 (const expression1_type &e1, const expression2_type &e2)` | Constructs a description of the expression.
`matrix_binary_scalar1 (const expression1_type &e1, const expression2_type &e2)` | Constructs a description of the expression.
`size_type size1 () const` | Returns the number of rows.
`size_type size2 () const` | Returns the number of columns.
`const_reference operator () (size_type i, size_type j) const` | Returns the value of the `j`-th element in the`i`-th row.
`const_iterator1 begin1 () const` | Returns a `const_iterator1` pointing to the beginning of the expression.
`const_iterator1 end1 () const` | Returns a `const_iterator1` pointing to the end of the expression.
`const_iterator2 begin2 () const` | Returns a `const_iterator2` pointing to the beginning of the expression.
`const_iterator2 end2 () const` | Returns a `const_iterator2` pointing to the end of the expression.
`const_reverse_iterator1 rbegin1 () const` | Returns a `const_reverse_iterator1` pointing to the beginning of the reversed expression.
`const_reverse_iterator1 rend1 () const` | Returns a `const_reverse_iterator1` pointing to the end of the reversed expression.
`const_reverse_iterator2 rbegin2 () const` | Returns a `const_reverse_iterator2` pointing to the beginning of the reversed expression.
`const_reverse_iterator2 rend2 () const` | Returns a `const_reverse_iterator2` pointing to the end of the reversed expression.

#### Interface

        template<class E1, class E2, class F>
        class matrix_binary_scalar1:
            public matrix_expression<matrix_binary_scalar1<E1, E2, F> > {
        public:
            typedef E1 expression1_type;
            typedef E2 expression2_type;
            typedef F functor_type;
            typedef typename E2::size_type size_type;
            typedef typename E2::difference_type difference_type;
            typedef typename F::result_type value_type;
            typedef value_type const_reference;
            typedef const_reference reference;
            typedef const value_type *const_pointer;
            typedef const_pointer pointer;
            typedef const matrix_binary_scalar1<E1, E2, F> const_closure_type;
            typedef typename E2::orientation_category orientation_category;
            typedef typename E1::value_type const_iterator1_type;
            typedef typename E2::const_iterator1 const_iterator21_type;
            typedef typename E2::const_iterator2 const_iterator22_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_binary_scalar1 ();
            matrix_binary_scalar1 (const expression1_type &e1, const expression2_type &e2);

            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const expression1_type &expression1 () const;
            const expression2_type &expression2 () const;

            // Element access
            const_reference operator () (size_type i, size_type j) const;

            class const_iterator1;
            typedef const_iterator1 iterator1;
            class const_iterator2;
            typedef const_iterator2 iterator2;
            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;

            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;

            // Iterators enhance the iterators of the referenced expression
            // with the binary functor.

            class const_iterator1:
                public container_const_reference<matrix_binary_scalar1>,
                public random_access_iterator_base<const_iterator1, value_type> {
            public:
                typedef typename E2::const_iterator1::iterator_category iterator_category;
                typedef typename matrix_binary_scalar1::difference_type difference_type;
                typedef typename matrix_binary_scalar1::value_type value_type;
                typedef typename matrix_binary_scalar1::const_reference reference;
                typedef typename matrix_binary_scalar1::const_pointer pointer;
                typedef const_iterator2 dual_iterator_type;
                typedef const_reverse_iterator2 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator1 ();
                const_iterator1 (const matrix_binary_scalar1 &mbs, const const_iterator1_type &it1, const const_iterator21_type &it2);

                // Arithmetic
                const_iterator1 &operator ++ ();
                const_iterator1 &operator -- ();
                const_iterator1 &operator += (difference_type n);
                const_iterator1 &operator -= (difference_type n);
                difference_type operator - (const const_iterator1 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator2 begin () const;
                const_iterator2 end () const;
                const_reverse_iterator2 rbegin () const;
                const_reverse_iterator2 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator1 &operator = (const const_iterator1 &it);

                // Comparison
                bool operator == (const const_iterator1 &it) const;
                bool operator <(const const_iterator1 &it) const;
            };

            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;

            class const_iterator2:
                public container_const_reference<matrix_binary_scalar1>,
                public random_access_iterator_base<const_iterator2, value_type> {
            public:
                typedef typename E2::const_iterator2::iterator_category iterator_category;
                typedef typename matrix_binary_scalar1::difference_type difference_type;
                typedef typename matrix_binary_scalar1::value_type value_type;
                typedef typename matrix_binary_scalar1::const_reference reference;
                typedef typename matrix_binary_scalar1::const_pointer pointer;
                typedef const_iterator1 dual_iterator_type;
                typedef const_reverse_iterator1 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator2 ();
                const_iterator2 (const matrix_binary_scalar1 &mbs, const const_iterator1_type &it1, const const_iterator22_type &it2);

                // Arithmetic
                const_iterator2 &operator ++ ();
                const_iterator2 &operator -- ();
                const_iterator2 &operator += (difference_type n);
                const_iterator2 &operator -= (difference_type n);
                difference_type operator - (const const_iterator2 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator1 begin () const;
                const_iterator1 end () const;
                const_reverse_iterator1 rbegin () const;
                const_reverse_iterator1 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator2 &operator = (const const_iterator2 &it);

                // Comparison
                bool operator == (const const_iterator2 &it) const;
                bool operator <(const const_iterator2 &it) const;
            };

            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;

            // Reverse iterators

            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;

            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
        };

        template<class E1, class E2, class F>
        class matrix_binary_scalar2:
            public matrix_expression<matrix_binary_scalar2<E1, E2, F> > {
        public:
            typedef E1 expression1_type;
            typedef E2 expression2_type;
            typedef F functor_type;
            typedef typename E1::size_type size_type;
            typedef typename E1::difference_type difference_type;
            typedef typename F::result_type value_type;
            typedef value_type const_reference;
            typedef const_reference reference;
            typedef const value_type *const_pointer;
            typedef const_pointer pointer;
            typedef const matrix_binary_scalar2<E1, E2, F> const_closure_type;
            typedef typename E1::orientation_category orientation_category;
            typedef typename E1::const_iterator1 const_iterator11_type;
            typedef typename E1::const_iterator2 const_iterator12_type;
            typedef typename E2::value_type const_iterator2_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_binary_scalar2 ();
            matrix_binary_scalar2 (const expression1_type &e1, const expression2_type &e2);

            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const expression1_type &expression1 () const;
            const expression2_type &expression2 () const;

            // Element access
            const_reference operator () (size_type i, size_type j) const;

            class const_iterator1;
            typedef const_iterator1 iterator1;
            class const_iterator2;
            typedef const_iterator2 iterator2;
            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;

            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;

            // Iterators enhance the iterators of the referenced expression
            // with the binary functor.

            class const_iterator1:
                public container_const_reference<matrix_binary_scalar2>,
                public random_access_iterator_base<const_iterator1, value_type> {
            public:
                typedef typename E1::const_iterator1::iterator_category iterator_category;
                typedef typename matrix_binary_scalar2::difference_type difference_type;
                typedef typename matrix_binary_scalar2::value_type value_type;
                typedef typename matrix_binary_scalar2::const_reference reference;
                typedef typename matrix_binary_scalar2::const_pointer pointer;
                typedef const_iterator2 dual_iterator_type;
                typedef const_reverse_iterator2 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator1 ();
                const_iterator1 (const matrix_binary_scalar2 &mbs, const const_iterator11_type &it1, const const_iterator2_type &it2);

                // Arithmetic
                const_iterator1 &operator ++ ();
                const_iterator1 &operator -- ();
                const_iterator1 &operator += (difference_type n);
                const_iterator1 &operator -= (difference_type n);
                difference_type operator - (const const_iterator1 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator2 begin () const;
                const_iterator2 end () const;
                const_reverse_iterator2 rbegin () const;
                const_reverse_iterator2 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator1 &operator = (const const_iterator1 &it);

                // Comparison
                bool operator == (const const_iterator1 &it) const;
                bool operator <(const const_iterator1 &it) const;
            };

            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;

            class const_iterator2:
                public container_const_reference<matrix_binary_scalar2>,
                public random_access_iterator_base<const_iterator2, value_type> {
            public:
                typedef typename E1::const_iterator2::iterator_category iterator_category;
                typedef typename matrix_binary_scalar2::difference_type difference_type;
                typedef typename matrix_binary_scalar2::value_type value_type;
                typedef typename matrix_binary_scalar2::const_reference reference;
                typedef typename matrix_binary_scalar2::const_pointer pointer;
                typedef const_iterator1 dual_iterator_type;
                typedef const_reverse_iterator1 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator2 ();
                const_iterator2 (const matrix_binary_scalar2 &mbs, const const_iterator12_type &it1, const const_iterator2_type &it2);

                // Arithmetic
                const_iterator2 &operator ++ ();
                const_iterator2 &operator -- ();
                const_iterator2 &operator += (difference_type n);
                const_iterator2 &operator -= (difference_type n);
                difference_type operator - (const const_iterator2 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator1 begin () const;
                const_iterator1 end () const;
                const_reverse_iterator1 rbegin () const;
                const_reverse_iterator1 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator2 &operator = (const const_iterator2 &it);

                // Comparison
                bool operator == (const const_iterator2 &it) const;
                bool operator <(const const_iterator2 &it) const;
            };

            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;

            // Reverse iterators

            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;

            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
        };

### Scalar Matrix Operations

#### Prototypes

        template<class T1, class E2, class F>
        struct matrix_binary_scalar1_traits {
            typedef matrix_binary_scalar1<scalar_const_reference<T1>,
                                         typename E2::const_closure_type, F> expression_type;
            typedef expression_type result_type;
        };

        // (t * m) [i] [j] = t * m [i] [j]
        template<class T1, class E2>
        typename matrix_binary_scalar1_traits<T1, E2, scalar_multiplies<T1, typename E2::value_type> >::result_type
        operator * (const T1 &e1,
                    const matrix_expression<E2> &e2);

        template<class E1, class T2, class F>
        struct matrix_binary_scalar2_traits {
            typedef matrix_binary_scalar2<typename E1::const_closure_type,
                                          scalar_const_reference<T2>, F> expression_type;
            typedef expression_type result_type;
        };

        // (m * t) [i] [j] = m [i] [j] * t
        template<class E1, class T2>
        typename matrix_binary_scalar2_traits<E1, T2, scalar_multiplies<typename E1::value_type, T2> >::result_type
        operator * (const matrix_expression<E1> &e1,
                    const T2 &e2);

        // (m / t) [i] [j] = m [i] [j] / t
        template<class E1, class T2>
        typename matrix_binary_scalar2_traits<E1, T2, scalar_divides<typename E1::value_type, T2> >::result_type
        operator / (const matrix_expression<E1> &e1,
                    const T2 &e2);

#### Description

`operator *` computes the product of a scalar and a matrix expression. `operator /` multiplies the matrix with the reciprocal of the scalar.

#### Definition

Defined in the header matrix_expression.hpp.

#### Type requirements

- `T1/T2` is a model of Scalar Expression.
- `E2/E1` is a model of Matrix Expression.

#### Preconditions

None.

#### Complexity

Quadratic depending from the size of the matrix expression.

#### Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double > m (3, 3);
        for (int i = 0; i < m.size1 (); ++ i)
            for (int j = 0; j < m.size2 (); ++ j)
                m (i, j) = 3 * i + j;

        std::cout << 2.0 * m << std::endl;
        std::cout << m * 2.0 << std::endl;
    }

## Matrix Reductions

### Operations

#### Prototypes

        template<class M>
        matrix_row<M> row (M &data, std::size_t i);

        template<class M>
        matrix_column<M> column (M &data, std::size_t j);

#### Description

`row` returns the the `i`-th row of a matrix expression. `column` returns the the j-th row of a matrix expression.

#### Definition

Defined in the header matrix_proxy.hpp.

#### Type requirements

- `E` is a model of Matrix Expression.

#### Preconditions

- `i < e ().size1 ()`
- `j < e ().size2 ()`

#### Complexity

Linear depending from the size of the matrix expression.

#### Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double > m (3, 3);
        for (int i = 0; i < m.size1 (); ++ i)
            for (int j = 0; j < m.size2 (); ++ j)
                m (i, j) = 3 * i + j;

        for (int i = 0; i < m.size1 (); ++ i)
            std::cout << row (m, i) << std::endl;
        for (int j = 0; j < m.size2 (); ++ j)
            std::cout << column (m, j) << std::endl;
    }

## Matrix Vector Operations

### Binary Operation Description

#### Description

The templated classes `matrix_vector_binary1<E1, E2, F>` and `matrix_vector_binary2<E1, E2, F>` describe binary matrix vector operations.

#### Definition

Defined in the header matrix_expression.hpp.

#### Template parameters

Parameter | Description | Default
--- | --- | ---
`E1` | The type of the matrix or vector expression. |
`E2` | The type of the vector or matrix expression. |
`F` | The type of the operation. |

#### Model of

Vector Expression.

#### Type requirements

None, except for those imposed by the requirements of Vector Expression.

#### Public base classes

`vector_expression<matrix_vector_binary1<E1, E2, F> >` and `vector_expression<matrix_vector_binary2<E1, E2, F> >` resp.

#### Members

Member | Description
--- | ---
`matrix_vector_binary1 (const expression1_type &e1, const expression2_type &e2)` | Constructs a description of the expression.
`matrix_vector_binary2 (const expression1_type &e1, const expression2_type &e2)` | Constructs a description of the expression.
`size_type size () const` | Returns the size of the expression.
`const_reference operator () (size_type i) const` | Returns the value of the `i`-th element.
`const_iterator begin () const` | Returns a `const_iterator` pointing to the beginning of the expression.
`const_iterator end () const` | Returns a `const_iterator` pointing to the end of the expression.
`const_reverse_iterator rbegin () const` | Returns a `const_reverse_iterator` pointing to the beginning of the reversed expression.
`const_reverse_iterator rend () const` | Returns a `const_reverse_iterator` pointing to the end of the reversed expression.

#### Interface

        template<class E1, class E2, class F>
        class matrix_vector_binary1:
            public vector_expression<matrix_vector_binary1<E1, E2, F> > {
        public:
            typedef E1 expression1_type;
            typedef E2 expression2_type;
            typedef F functor_type;
            typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
            typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
            typedef typename F::result_type value_type;
            typedef value_type const_reference;
            typedef const_reference reference;
            typedef const value_type *const_pointer;
            typedef const_pointer pointer;
            typedef const matrix_vector_binary1<E1, E2, F> const_closure_type;
            typedef typename E1::const_iterator1 const_iterator1_type;
            typedef typename E2::const_iterator const_iterator2_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_vector_binary1 ();
            matrix_vector_binary1 (const expression1_type &e1, const expression2_type &e2);

            // Accessors
            size_type size () const;
            const expression1_type &expression1 () const;
            const expression2_type &expression2 () const;

            // Element access
            const_reference operator () (size_type i) const;

            class const_iterator;
            typedef const_iterator iterator;

            // Element lookup
            const_iterator find_first (size_type i) const;
            const_iterator find_last (size_type i) const;

            // Iterator simply is a pointer.

            class const_iterator:
                public container_const_reference<matrix_vector_binary1>,
                public random_access_iterator_base<const_iterator, value_type> {
            public:
                typedef typename restrict_traits<typename E1::const_iterator1::iterator_category,
                                                 typename E2::const_iterator::iterator_category>::iterator_category iterator_category;
                typedef typename matrix_vector_binary1::difference_type difference_type;
                typedef typename matrix_vector_binary1::value_type value_type;
                typedef typename matrix_vector_binary1::const_reference reference;
                typedef typename matrix_vector_binary1::const_pointer pointer;

                // Construction and destruction
                const_iterator ();
                const_iterator (const matrix_vector_binary1 &mvb, const const_iterator1_type &it1);

                // Dense random access specialization
                value_type dereference (dense_random_access_iterator_tag) const;

                // Packed bidirectional specialization
                value_type dereference (packed_bidirectional_iterator_tag) const;

                // Sparse bidirectional specialization
                value_type dereference (sparse_bidirectional_iterator_tag) const;

                // Arithmetic
                const_iterator &operator ++ ();
                const_iterator &operator -- ();
                const_iterator &operator += (difference_type n);
                const_iterator &operator -= (difference_type n);
                difference_type operator - (const const_iterator &it) const;

                // Dereference
                reference operator * () const;

                // Index
                size_type index () const;

                // Assignment
                const_iterator &operator = (const const_iterator &it);

                // Comparison
                bool operator == (const const_iterator &it) const;
                bool operator <(const const_iterator &it) const;
            };

            const_iterator begin () const;
            const_iterator end () const;

            // Reverse iterator

            typedef reverse_iterator_base<const_iterator> const_reverse_iterator;

            const_reverse_iterator rbegin () const;
            const_reverse_iterator rend () const;
        };

        template<class E1, class E2, class F>
        class matrix_vector_binary2:
            public vector_expression<matrix_vector_binary2<E1, E2, F> > {
        public:
            typedef E1 expression1_type;
            typedef E2 expression2_type;
            typedef F functor_type;
            typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
            typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
            typedef typename F::result_type value_type;
            typedef value_type const_reference;
            typedef const_reference reference;
            typedef const value_type *const_pointer;
            typedef const_pointer pointer;
            typedef const matrix_vector_binary2<E1, E2, F> const_closure_type;
            typedef typename E1::const_iterator const_iterator1_type;
            typedef typename E2::const_iterator2 const_iterator2_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_vector_binary2 ();
            matrix_vector_binary2 (const expression1_type &e1, const expression2_type &e2);

            // Accessors
            size_type size () const;
            const expression1_type &expression1 () const;
            const expression2_type &expression2 () const;

            // Element access
            const_reference operator () (size_type j) const;

            class const_iterator;
            typedef const_iterator iterator;

            // Element lookup
            const_iterator find_first (size_type j) const;
            const_iterator find_last (size_type j) const;

            // Iterator simply is a pointer.

            class const_iterator:
                public container_const_reference<matrix_vector_binary2>,
                public random_access_iterator_base<const_iterator, value_type> {
            public:
                typedef typename restrict_traits<typename E1::const_iterator::iterator_category,
                                                 typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
                typedef typename matrix_vector_binary2::difference_type difference_type;
                typedef typename matrix_vector_binary2::value_type value_type;
                typedef typename matrix_vector_binary2::const_reference reference;
                typedef typename matrix_vector_binary2::const_pointer pointer;

                // Construction and destruction
                const_iterator ();
                const_iterator (const matrix_vector_binary2 &mvb, const const_iterator2_type &it2);

                // Dense random access specialization
                value_type dereference (dense_random_access_iterator_tag) const;

                // Packed bidirectional specialization
                value_type dereference (packed_bidirectional_iterator_tag) const;

                // Sparse bidirectional specialization
                value_type dereference (sparse_bidirectional_iterator_tag) const;

                // Arithmetic
                const_iterator &operator ++ ();
                const_iterator &operator -- ();
                const_iterator &operator += (difference_type n);
                const_iterator &operator -= (difference_type n);
                difference_type operator - (const const_iterator &it) const;

                // Dereference
                reference operator * () const;

                // Index
                size_type index () const;

                // Assignment
                const_iterator &operator = (const const_iterator &it);

                // Comparison
                bool operator == (const const_iterator &it) const;
                bool operator <(const const_iterator &it) const;
            };

            const_iterator begin () const;
            const_iterator end () const;

            // Reverse iterator

            typedef reverse_iterator_base<const_iterator> const_reverse_iterator;

            const_reverse_iterator rbegin () const;
            const_reverse_iterator rend () const;
        };

### Binary Operations

#### Prototypes

        template<class T1, class E1, class T2, class E2>
        struct matrix_vector_binary1_traits {
            typedef row_major_tag dispatch_category;
            typedef typename promote_traits<T1, T2>::promote_type promote_type;
            typedef matrix_vector_binary1<typename E1::const_closure_type,
                                          typename E2::const_closure_type,
                                          matrix_vector_prod1<T1, T2, promote_type> > expression_type;
            typedef expression_type result_type;
        };

        template<class E1, class E2>
        typename matrix_vector_binary1_traits<typename E1::value_type, E1,
                                              typename E2::value_type, E2>::result_type
        prod (const matrix_expression<E1> &e1,
              const vector_expression<E2> &e2,
              row_major_tag);

        // Dispatcher
        template<class E1, class E2>
        typename matrix_vector_binary1_traits<typename E1::value_type, E1,
                                              typename E2::value_type, E2>::result_type
        prod (const matrix_expression<E1> &e1,
              const vector_expression<E2> &e2);

        template<class E1, class E2>
        typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
                                              typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
        prec_prod (const matrix_expression<E1> &e1,
                   const vector_expression<E2> &e2,
                   row_major_tag);

        // Dispatcher
        template<class E1, class E2>
        typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
                                              typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
        prec_prod (const matrix_expression<E1> &e1,
                   const vector_expression<E2> &e2);

        template<class V, class E1, class E2>
        V
        prod (const matrix_expression<E1> &e1,
              const vector_expression<E2> &e2);

        template<class V, class E1, class E2>
        V
        prec_prod (const matrix_expression<E1> &e1,
                   const vector_expression<E2> &e2);

        template<class T1, class E1, class T2, class E2>
        struct matrix_vector_binary2_traits {
            typedef column_major_tag dispatch_category;
            typedef typename promote_traits<T1, T2>::promote_type promote_type;
            typedef matrix_vector_binary2<typename E1::const_closure_type,
                                          typename E2::const_closure_type,
                                          matrix_vector_prod2<T1, T2, promote_type> > expression_type;
            typedef expression_type result_type;
        };

        template<class E1, class E2>
        typename matrix_vector_binary2_traits<typename E1::value_type, E1,
                                              typename E2::value_type, E2>::result_type
        prod (const vector_expression<E1> &e1,
              const matrix_expression<E2> &e2,
              column_major_tag);

        // Dispatcher
        template<class E1, class E2>
        typename matrix_vector_binary2_traits<typename E1::value_type, E1,
                                              typename E2::value_type, E2>::result_type
        prod (const vector_expression<E1> &e1,
              const matrix_expression<E2> &e2);

        template<class E1, class E2>
        typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
                                              typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
        prec_prod (const vector_expression<E1> &e1,
                   const matrix_expression<E2> &e2,
                   column_major_tag);

        // Dispatcher
        template<class E1, class E2>
        typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
                                              typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
        prec_prod (const vector_expression<E1> &e1,
                   const matrix_expression<E2> &e2);

        template<class V, class E1, class E2>
        V
        prod (const vector_expression<E1> &e1,
              const matrix_expression<E2> &e2);

        template<class V, class E1, class E2>
        V
        prec_prod (const vector_expression<E1> &e1,
                   const matrix_expression<E2> &e2);

#### Description

`prod` computes the product of the matrix and the vector expression.`prec_prod` computes the double precision product of the matrix and the vector expression.

#### Definition

Defined in the header matrix_expression.hpp.

#### Type requirements

- `E1` is a model of Matrix Expression or Vector Expression.
- `E2` is a model of Vector Expression or Matrix Expression.

#### Preconditions

- `e1 ().size2 () == e2 ().size ()`
- `e1 ().size () == e2 ().size1 ()`

#### Complexity

Quadratic depending from the size of the matrix expression.

#### Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double > m (3, 3), v (3);
        for (int i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
            for (int j = 0; j < m.size2 (); ++ j)
                m (i, j) = 3 * i + j;
            v (i) = i
        }

        std::cout << prod (m, v) << std::endl;
        std::cout << prod (v, m) << std::endl;
    }

### Triangular Solver

#### Prototypes

        template<class E1, class E2>
        struct matrix_vector_solve_traits {
            typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
            typedef vector<promote_type> result_type;
        };

        template<class E1, class E2>
        void inplace_solve (const matrix_expression<E1> &e1,
                            E2 &e2,
                            lower_tag,
                            vector_tag);
        template<class E1, class E2>
        void inplace_solve (const matrix_expression<E1> &e1,
                            E2 &e2,
                            upper_tag,
                            vector_tag);
        template<class E1, class E2>
        void inplace_solve (const matrix_expression<E1> &e1,
                            E2 &e2,
                            unit_lower_tag,
                            vector_tag);
        template<class E1, class E2>
        void inplace_solve (const matrix_expression<E1> &e1,
                            E2 &e2,
                            unit_upper_tag,
                            vector_tag);

        template<class E1, class E2, class C>
        typename matrix_vector_solve_traits<E1, E2>::result_type
        solve (const matrix_expression<E1> &e1,
               const vector_expression<E2> &e2,
               C);

        template<class E1, class E2>
        void inplace_solve (E1 &e1,
                            const matrix_expression<E2> &e2,
                            vector_tag,
                            lower_tag);
        template<class E1, class E2>
        void inplace_solve (E1 &e1,
                            const matrix_expression<E2> &e2,
                            vector_tag,
                            upper_tag);
        template<class E1, class E2>
        void inplace_solve (E1 &e1,
                            const matrix_expression<E2> &e2,
                            vector_tag,
                            unit_lower_tag);
        template<class E1, class E2>
        void inplace_solve (E1 &e1,
                            const matrix_expression<E2> &e2,
                            vector_tag,
                            unit_upper_tag);

        template<class E1, class E2, class C>
        typename matrix_vector_solve_traits<E1, E2>::result_type
        solve (const vector_expression<E1> &e1,
               const matrix_expression<E2> &e2,
               C);

#### Description

`solve` solves a linear equation for lower or upper (unit) triangular matrices.

#### Definition

Defined in the header triangular.hpp.

#### Type requirements

- `E1` is a model of Matrix Expression or Vector Expression.
- `E2` is a model of Vector Expression or Matrix Expression.

#### Preconditions

- `e1 ().size1 () == e1 ().size2 ()`
- `e1 ().size2 () == e2 ().size ()`
- `e1 ().size () == e2 ().size1 ()`
- `e2 ().size1 () == e2 ().size2 ()`

#### Complexity

Quadratic depending from the size of the matrix expression.

#### Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double > m (3, 3), v (3);
        for (int i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
            for (int j = 0; j <= i; ++ j)
                m (i, j) = 3 * i + j;
            v (i) = i
        }

        std::cout << solve (m, v, lower_tag ()) << std::endl;
        std::cout << solve (v, m, lower_tag ()) << std::endl;
    }

## Matrix Matrix Operations

### Binary Operation Description

#### Description

The templated class `matrix_matrix_binary<E1, E2, F>` describes a binary matrix operation.

#### Definition

Defined in the header matrix_expression.hpp.

#### Template parameters

Parameter | Description | Default
--- | --- | ---
`E1` | The type of the first matrix expression. |
`E2` | The type of the second matrix expression. |
`F` | The type of the operation. |

#### Model of

Matrix Expression.

#### Type requirements

None, except for those imposed by the requirements of Matrix Expression.

#### Public base classes

`matrix_expression<matrix_matrix_binary<E1, E2, F> >`.

#### Members

Member | Description
--- | ---
`matrix_matrix_binary (const expression1_type &e1, const expression2_type &e2)` | Constructs a description of the expression.
`size_type size1 () const` | Returns the number of rows.
`size_type size2 () const` | Returns the number of columns.
`const_reference operator () (size_type i, size_type j) const` | Returns the value of the `j`-th element in the`i`-th row.
`const_iterator1 begin1 () const` | Returns a `const_iterator1` pointing to the beginning of the expression.
`const_iterator1 end1 () const` | Returns a `const_iterator1` pointing to the end of the expression.
`const_iterator2 begin2 () const` | Returns a `const_iterator2` pointing to the beginning of the expression.
`const_iterator2 end2 () const` | Returns a `const_iterator2` pointing to the end of the expression.
`const_reverse_iterator1 rbegin1 () const` | Returns a `const_reverse_iterator1` pointing to the beginning of the reversed expression.
`const_reverse_iterator1 rend1 () const` | Returns a `const_reverse_iterator1` pointing to the end of the reversed expression.
`const_reverse_iterator2 rbegin2 () const` | Returns a `const_reverse_iterator2` pointing to the beginning of the reversed expression.
`const_reverse_iterator2 rend2 () const` | Returns a `const_reverse_iterator2` pointing to the end of the reversed expression.

#### Interface

        template<class E1, class E2, class F>
        class matrix_matrix_binary:
            public matrix_expression<matrix_matrix_binary<E1, E2, F> > {
        public:
            typedef E1 expression1_type;
            typedef E2 expression2_type;
            typedef F functor_type;
            typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
            typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
            typedef typename F::result_type value_type;
            typedef value_type const_reference;
            typedef const_reference reference;
            typedef const value_type *const_pointer;
            typedef const_pointer pointer;
            typedef const matrix_matrix_binary<E1, E2, F> const_closure_type;
            typedef unknown_orientation_tag orientation_category;
            typedef typename E1::const_iterator1 const_iterator11_type;
            typedef typename E1::const_iterator2 const_iterator12_type;
            typedef typename E2::const_iterator1 const_iterator21_type;
            typedef typename E2::const_iterator2 const_iterator22_type;
            typedef unknown_storage_tag storage_category;

            // Construction and destruction
            matrix_matrix_binary ();
            matrix_matrix_binary (const expression1_type &e1, const expression2_type &e2);

            // Accessors
            size_type size1 () const;
            size_type size2 () const;
            const expression1_type &expression1 () const;
            const expression2_type &expression2 () const;

            // Element access
            const_reference operator () (size_type i, size_type j) const;

            class const_iterator1;
            typedef const_iterator1 iterator1;
            class const_iterator2;
            typedef const_iterator2 iterator2;
            typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
            typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;

            // Element lookup
            const_iterator1 find_first1 (int rank, size_type i, size_type j) const;
            const_iterator1 find_last1 (int rank, size_type i, size_type j) const;
            const_iterator2 find_first2 (int rank, size_type i, size_type j) const;
            const_iterator2 find_last2 (int rank, size_type i, size_type j) const;

            // Iterators simply are pointers.

            class const_iterator1:
                public container_const_reference<matrix_matrix_binary>,
                public random_access_iterator_base<const_iterator1, value_type> {
            public:
                typedef typename restrict_traits<typename E1::const_iterator1::iterator_category,
                                                 typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
                typedef typename matrix_matrix_binary::difference_type difference_type;
                typedef typename matrix_matrix_binary::value_type value_type;
                typedef typename matrix_matrix_binary::const_reference reference;
                typedef typename matrix_matrix_binary::const_pointer pointer;
                typedef const_iterator2 dual_iterator_type;
                typedef const_reverse_iterator2 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator1 ();
                const_iterator1 (const matrix_matrix_binary &mmb, const const_iterator11_type &it1, const const_iterator22_type &it2);

                // Random access specialization
                value_type dereference (dense_random_access_iterator_tag) const;

                // Packed bidirectional specialization
                value_type dereference (packed_bidirectional_iterator_tag) const;

                // Sparse bidirectional specialization
                value_type dereference (sparse_bidirectional_iterator_tag) const;

                // Arithmetic
                const_iterator1 &operator ++ ();
                const_iterator1 &operator -- ();
                const_iterator1 &operator += (difference_type n);
                const_iterator1 &operator -= (difference_type n);
                difference_type operator - (const const_iterator1 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator2 begin () const;
                const_iterator2 end () const;
                const_reverse_iterator2 rbegin () const;
                const_reverse_iterator2 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator1 &operator = (const const_iterator1 &it);

                // Comparison
                bool operator == (const const_iterator1 &it) const;
                bool operator <(const const_iterator1 &it) const;
            };

            const_iterator1 begin1 () const;
            const_iterator1 end1 () const;

            class const_iterator2:
                public container_const_reference<matrix_matrix_binary>,
                public random_access_iterator_base<const_iterator2, value_type> {
            public:
                typedef typename restrict_traits<typename E1::const_iterator1::iterator_category,
                                                 typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
                typedef typename matrix_matrix_binary::difference_type difference_type;
                typedef typename matrix_matrix_binary::value_type value_type;
                typedef typename matrix_matrix_binary::const_reference reference;
                typedef typename matrix_matrix_binary::const_pointer pointer;
                typedef const_iterator1 dual_iterator_type;
                typedef const_reverse_iterator1 dual_reverse_iterator_type;

                // Construction and destruction
                const_iterator2 ();
                const_iterator2 (const matrix_matrix_binary &mmb, const const_iterator11_type &it1, const const_iterator22_type &it2);

                // Random access specialization
                value_type dereference (dense_random_access_iterator_tag) const;

                // Packed bidirectional specialization
                value_type dereference (packed_bidirectional_iterator_tag) const;

                // Sparse bidirectional specialization
                value_type dereference (sparse_bidirectional_iterator_tag) const;

                // Arithmetic
                const_iterator2 &operator ++ ();
                const_iterator2 &operator -- ();
                const_iterator2 &operator += (difference_type n);
                const_iterator2 &operator -= (difference_type n);
                difference_type operator - (const const_iterator2 &it) const;

                // Dereference
                reference operator * () const;

                const_iterator1 begin () const;
                const_iterator1 end () const;
                const_reverse_iterator1 rbegin () const;
                const_reverse_iterator1 rend () const;

                // Indices
                size_type index1 () const;
                size_type index2 () const;

                // Assignment
                const_iterator2 &operator = (const const_iterator2 &it);

                // Comparison
                bool operator == (const const_iterator2 &it) const;
                bool operator <(const const_iterator2 &it) const;
            };

            const_iterator2 begin2 () const;
            const_iterator2 end2 () const;

            // Reverse iterators

            const_reverse_iterator1 rbegin1 () const;
            const_reverse_iterator1 rend1 () const;

            const_reverse_iterator2 rbegin2 () const;
            const_reverse_iterator2 rend2 () const;
        };

### Binary Operations

#### Prototypes

        template<class T1, class E1, class T2, class E2>
        struct matrix_matrix_binary_traits {
            typedef unknown_orientation_tag dispatch_category;
            typedef typename promote_traits<T1, T2>::promote_type promote_type;
            typedef matrix_matrix_binary<typename E1::const_closure_type,
                                         typename E2::const_closure_type,
                                         matrix_matrix_prod<T1, T2, promote_type> > expression_type;
            typedef expression_type result_type;
        };

        template<class E1, class E2>
        typename matrix_matrix_binary_traits<typename E1::value_type, E1,
                                             typename E2::value_type, E2>::result_type
        prod (const matrix_expression<E1> &e1,
              const matrix_expression<E2> &e2,
              unknown_orientation_tag);

        // Dispatcher
        template<class E1, class E2>
        typename matrix_matrix_binary_traits<typename E1::value_type, E1,
                                             typename E2::value_type, E2>::result_type
        prod (const matrix_expression<E1> &e1,
              const matrix_expression<E2> &e2);

        template<class E1, class E2>
        typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
                                             typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
        prec_prod (const matrix_expression<E1> &e1,
                   const matrix_expression<E2> &e2,
                   unknown_orientation_tag);

        // Dispatcher
        template<class E1, class E2>
        typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
                                             typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
        prec_prod (const matrix_expression<E1> &e1,
                   const matrix_expression<E2> &e2);

        template<class M, class E1, class E2>
        M
        prod (const matrix_expression<E1> &e1,
              const matrix_expression<E2> &e2);

        template<class M, class E1, class E2>
        M
        prec_prod (const matrix_expression<E1> &e1,
                   const matrix_expression<E2> &e2);

#### Description

`prod` computes the product of the matrix expressions.`prec_prod` computes the double precision product of the matrix expressions.

#### Definition

Defined in the header matrix_expression.hpp.

#### Type requirements

- `E1` is a model of Matrix Expression.
- `E2` is a model of Matrix Expression.

#### Preconditions

- `e1 ().size2 () == e2 ().size1 ()`

#### Complexity

Cubic depending from the size of the matrix expression.

#### Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double > m1 (3, 3), m2 (3, 3);
        for (int i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i)
            for (int j = 0; j < std::min (m1.size2 (), m2.size2 ()); ++ j)
                m1 (i, j) = m2 (i, j) = 3 * i + j;

        std::cout << prod (m1, m2) << std::endl;
    }

### Triangular Solvers

#### Prototypes

        template<class E1, class E2>
        struct matrix_matrix_solve_traits {
            typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
            typedef matrix<promote_type> result_type;
        };

        template<class E1, class E2>
        void inplace_solve (const matrix_expression<E1> &e1,
                            E2 &e2,
                            lower_tag,
                            matrix_tag);
        template<class E1, class E2>
        void inplace_solve (const matrix_expression<E1> &e1,
                            E2 &e2,
                            upper_tag,
                            matrix_tag);
        template<class E1, class E2>
        void inplace_solve (const matrix_expression<E1> &e1,
                            E2 &e2,
                            unit_lower_tag,
                            matrix_tag);
        template<class E1, class E2>
        void inplace_solve (const matrix_expression<E1> &e1,
                            E2 &e2,
                            unit_upper_tag,
                            matrix_tag);

        template<class E1, class E2, class C>
        typename matrix_matrix_solve_traits<E1, E2>::result_type
        solve (const matrix_expression<E1> &e1,
               const matrix_expression<E2> &e2,
               C);

#### Description

`solve` solves a linear equation for lower or upper (unit) triangular matrices.

#### Definition

Defined in the header triangular.hpp.

#### Type requirements

- `E1` is a model of Matrix Expression.
- `E2` is a model of Matrix Expression.

#### Preconditions

- `e1 ().size1 () == e1 ().size2 ()`
- `e1 ().size2 () == e2 ().size1 ()`

#### Complexity

Cubic depending from the size of the matrix expressions.

#### Examples

    int main () {
        using namespace boost::numeric::ublas;
        matrix<double > m1 (3, 3), m2 (3, 3);
        for (int i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i)
            for (int j = 0; j <= i; ++ j)
                m1 (i, j) = m2 (i, j) = 3 * i + j;

        std::cout << solve (m1, m2, lower_tag ()) << std::endl;
    }

Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided ``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Last revised: 8/3/2002