Copyright | (c) Andrew Lelechenko 2014-2020 |
---|---|
License | GPL-3 |
Maintainer | andrew.lelechenko@gmail.com |
Safe Haskell | Safe |
Language | Haskell2010 |
Matrices of order 3 and efficient multiplication algorithms.
Synopsis
- data Matrix3 t = Matrix3 {}
- fromList :: [t] -> Matrix3 t
- det :: Num t => Matrix3 t -> t
- multCol :: Num t => Matrix3 t -> (t, t, t) -> (t, t, t)
- normalize :: Integral t => Matrix3 t -> Matrix3 t
- makarovMult :: Num t => Matrix3 t -> Matrix3 t -> Matrix3 t
- ladermanMult :: Num t => Matrix3 t -> Matrix3 t -> Matrix3 t
Documentation
Matrix of order 3.
Instances
multCol :: Num t => Matrix3 t -> (t, t, t) -> (t, t, t) Source #
Multiplicate a matrix by a column vector.
normalize :: Integral t => Matrix3 t -> Matrix3 t Source #
Divide all elements of the matrix by their greatest common divisor. This is useful for matrices of projective transformations to reduce the magnitude of computations.
makarovMult :: Num t => Matrix3 t -> Matrix3 t -> Matrix3 t Source #
Multiplicate matrices under assumption that multiplication of elements is commutative. Requires 22 multiplications and 66 additions. It becomes faster than vanilla multiplication '(*)', which requires 27 multiplications and 18 additions, when matrix's elements are large (> 700 digits) integers.
An algorithm follows O. M. Makarov. An algorithm for multiplication of \( 3 \times 3 \) matrices. Zh. Vychisl. Mat. i Mat. Fiz., 26(2):293–294, 320, 1986. Our contribution is reducing the number of additions from 105 to 66 by well-thought choice of intermediate variables.
ladermanMult :: Num t => Matrix3 t -> Matrix3 t -> Matrix3 t Source #
Multiplicate matrices. Requires 23 multiplications and 62 additions. It becomes faster than vanilla multiplication '(*)', which requires 27 multiplications and 18 additions, when matrix's elements are large (> 700 digits) integers.
An algorithm follows J. Laderman. A noncommutative algorithm for multiplying \( 3 \times 3 \) matrices using 23 multiplications. Bull. Amer. Math. Soc., 82:126–128, 1976. Our contribution is reducing the number of additions from 98 to 62 by well-thought choice of intermediate variables.