{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Numeric.LAPACK.Matrix.Square (
   Square,
   size,
   mapSize,
   toFull,
   toGeneral,
   fromFull,
   liberalFromFull,
   fromScalar,
   toScalar,
   fromList,
   autoFromList,

   transpose,
   adjoint,

   identity,
   identityFrom,
   identityFromWidth,
   identityFromHeight,
   diagonal,
   takeDiagonal,
   trace,

   stack, (|=|),
   split, takeTopLeft, takeBottomRight,

   multiply,
   square,
   power,
   congruence,
   congruenceAdjoint,

   solve,
   inverse,
   determinant,

   eigenvalues,
   schur,
   schurComplex,
   eigensystem,
   ComplexOf,
   ) where

import qualified Numeric.LAPACK.Matrix.Triangular as Triangular
import qualified Numeric.LAPACK.Matrix.Square.Eigen as Eigen
import qualified Numeric.LAPACK.Matrix.Square.Linear as Linear
import qualified Numeric.LAPACK.Matrix.Square.Basic as Basic
import qualified Numeric.LAPACK.Matrix.Basic as FullBasic

import qualified Numeric.LAPACK.Matrix.Array.Private as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Shape.Omni as Omni
import qualified Numeric.LAPACK.Matrix.Extent as Extent
import qualified Numeric.LAPACK.Shape as ExtShape
import Numeric.LAPACK.Matrix.Array.Private
         (Full, General, Square, SquareMeas, LiberalSquare)
import Numeric.LAPACK.Matrix.Private (ShapeInt)
import Numeric.LAPACK.Vector (Vector)
import Numeric.LAPACK.Scalar (ComplexOf)

import qualified Numeric.Netlib.Class as Class

import qualified Data.Array.Comfort.Shape as Shape
import Data.Array.Comfort.Shape ((::+))

import Foreign.Storable (Storable)

import Data.Tuple.HT (mapPair, mapSnd, mapTriple)
import Data.Complex (Complex)


size :: Square sh a -> sh
size :: Square sh a -> sh
size = Omni Unpacked Arbitrary Filled Filled Shape Small Small sh sh -> sh
forall pack property lower upper sh.
Omni pack property lower upper Shape Small Small sh sh -> sh
Omni.squareSize (Omni Unpacked Arbitrary Filled Filled Shape Small Small sh sh
 -> sh)
-> (Square sh a
    -> Omni Unpacked Arbitrary Filled Filled Shape Small Small sh sh)
-> Square sh a
-> sh
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sh a
-> Omni Unpacked Arbitrary Filled Filled Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Omni pack property lower upper meas vert horiz height width
ArrMatrix.shape

mapSize :: (sh0 -> sh1) -> Square sh0 a -> Square sh1 a
mapSize :: (sh0 -> sh1) -> Square sh0 a -> Square sh1 a
mapSize = (Array (Full Shape Small Small sh0 sh0) a
 -> Array (Full Shape Small Small sh1 sh1) a)
-> Square sh0 a -> Square sh1 a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 ((Array (Full Shape Small Small sh0 sh0) a
  -> Array (Full Shape Small Small sh1 sh1) a)
 -> Square sh0 a -> Square sh1 a)
-> ((sh0 -> sh1)
    -> Array (Full Shape Small Small sh0 sh0) a
    -> Array (Full Shape Small Small sh1 sh1) a)
-> (sh0 -> sh1)
-> Square sh0 a
-> Square sh1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (sh0 -> sh1)
-> Array (Full Shape Small Small sh0 sh0) a
-> Array (Full Shape Small Small sh1 sh1) a
forall sh0 sh1 a. (sh0 -> sh1) -> Square sh0 a -> Square sh1 a
Basic.mapSize

toGeneral :: Square sh a -> General sh sh a
toGeneral :: Square sh a -> General sh sh a
toGeneral = Square sh a -> General sh sh a
forall meas vert horiz sh a.
(Measured meas vert, Measured meas horiz) =>
Square sh a -> Full meas vert horiz sh sh a
toFull

toFull ::
   (Extent.Measured meas vert, Extent.Measured meas horiz) =>
   Square sh a -> Full meas vert horiz sh sh a
toFull :: Square sh a -> Full meas vert horiz sh sh a
toFull = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz sh sh a)
-> Square sh a -> Full meas vert horiz sh sh a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled meas vert horiz sh sh a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz) =>
Square sh a -> Full meas vert horiz sh sh a
Basic.toFull

fromFull ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz, Eq sh) =>
   Full meas vert horiz sh sh a -> Square sh a
fromFull :: Full meas vert horiz sh sh a -> Square sh a
fromFull = (PlainArray
   Unpacked Arbitrary Filled Filled meas vert horiz sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sh sh a)
-> Full meas vert horiz sh sh a -> Square sh a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray Unpacked Arbitrary Filled Filled meas vert horiz sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz, Eq sh) =>
Full meas vert horiz sh sh a -> Square sh a
Basic.fromFull

liberalFromFull ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width) =>
   Full meas vert horiz height width a -> LiberalSquare height width a
liberalFromFull :: Full meas vert horiz height width a -> LiberalSquare height width a
liberalFromFull = (PlainArray
   Unpacked Arbitrary Filled Filled meas vert horiz height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Size Small Small height width a)
-> Full meas vert horiz height width a
-> LiberalSquare height width a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled meas vert horiz height width a
-> PlainArray
     Unpacked Arbitrary Filled Filled Size Small Small height width a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, C width) =>
Full meas vert horiz height width a -> LiberalSquare height width a
Basic.liberalFromFull


fromScalar :: (Storable a) => a -> Square () a
fromScalar :: a -> Square () a
fromScalar = Array (Full Shape Small Small () ()) a -> Square () a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (Array (Full Shape Small Small () ()) a -> Square () a)
-> (a -> Array (Full Shape Small Small () ()) a)
-> a
-> Square () a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Array (Full Shape Small Small () ()) a
forall a. Storable a => a -> Square () a
Basic.fromScalar

toScalar :: (Storable a) => Square () a -> a
toScalar :: Square () a -> a
toScalar = Square () a -> a
forall a. Storable a => Square () a -> a
Basic.toScalar (Square () a -> a)
-> (Square () a -> Square () a) -> Square () a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square () a -> Square () a
forall pack property lower upper meas vert horiz height width a.
ToPlain pack property lower upper meas vert horiz height width =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> PlainArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.toVector

fromList :: (Shape.C sh, Storable a) => sh -> [a] -> Square sh a
fromList :: sh -> [a] -> Square sh a
fromList sh
sh = Array (Full Shape Small Small sh sh) a -> Square sh a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (Array (Full Shape Small Small sh sh) a -> Square sh a)
-> ([a] -> Array (Full Shape Small Small sh sh) a)
-> [a]
-> Square sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. sh -> [a] -> Array (Full Shape Small Small sh sh) a
forall sh a. (C sh, Storable a) => sh -> [a] -> Square sh a
Basic.fromList sh
sh

autoFromList :: (Storable a) => [a] -> Square ShapeInt a
autoFromList :: [a] -> Square ShapeInt a
autoFromList = Array (Full Shape Small Small ShapeInt ShapeInt) a
-> Square ShapeInt a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (Array (Full Shape Small Small ShapeInt ShapeInt) a
 -> Square ShapeInt a)
-> ([a] -> Array (Full Shape Small Small ShapeInt ShapeInt) a)
-> [a]
-> Square ShapeInt a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Array (Full Shape Small Small ShapeInt ShapeInt) a
forall a. Storable a => [a] -> Square ShapeInt a
Basic.autoFromList

transpose :: Square sh a -> Square sh a
transpose :: Square sh a -> Square sh a
transpose = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sh sh a)
-> Square sh a -> Square sh a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
forall sh a. Square sh a -> Square sh a
Basic.transpose

{- |
conjugate transpose
-}
adjoint :: (Shape.C sh, Class.Floating a) => Square sh a -> Square sh a
adjoint :: Square sh a -> Square sh a
adjoint = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sh sh a)
-> Square sh a -> Square sh a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
forall sh a. (C sh, Floating a) => Square sh a -> Square sh a
Basic.adjoint

identity :: (Shape.C sh, Class.Floating a) => sh -> Square sh a
identity :: sh -> Square sh a
identity = Array (Full Shape Small Small sh sh) a -> Square sh a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (Array (Full Shape Small Small sh sh) a -> Square sh a)
-> (sh -> Array (Full Shape Small Small sh sh) a)
-> sh
-> Square sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. sh -> Array (Full Shape Small Small sh sh) a
forall sh a. (C sh, Floating a) => sh -> Square sh a
Basic.identity

identityFrom :: (Shape.C sh, Class.Floating a) => Square sh a -> Square sh a
identityFrom :: Square sh a -> Square sh a
identityFrom = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sh sh a)
-> Square sh a -> Square sh a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
forall sh a. (C sh, Floating a) => Square sh a -> Square sh a
Basic.identityFrom

identityFromWidth ::
   (Shape.C height, Shape.C width, Class.Floating a) =>
   General height width a -> Square width a
identityFromWidth :: General height width a -> Square width a
identityFromWidth = (PlainArray
   Unpacked Arbitrary Filled Filled Size Big Big height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small width width a)
-> General height width a -> Square width a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled Size Big Big height width a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small width width a
forall height width a.
(C height, C width, Floating a) =>
General height width a -> Square width a
Basic.identityFromWidth

identityFromHeight ::
   (Shape.C height, Shape.C width, Class.Floating a) =>
   General height width a -> Square height a
identityFromHeight :: General height width a -> Square height a
identityFromHeight = (PlainArray
   Unpacked Arbitrary Filled Filled Size Big Big height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small height height a)
-> General height width a -> Square height a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled Size Big Big height width a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small height height a
forall height width a.
(C height, C width, Floating a) =>
General height width a -> Square height a
Basic.identityFromHeight

diagonal :: (Shape.C sh, Class.Floating a) => Vector sh a -> Square sh a
diagonal :: Vector sh a -> Square sh a
diagonal = Array (Full Shape Small Small sh sh) a -> Square sh a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (Array (Full Shape Small Small sh sh) a -> Square sh a)
-> (Vector sh a -> Array (Full Shape Small Small sh sh) a)
-> Vector sh a
-> Square sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector sh a -> Array (Full Shape Small Small sh sh) a
forall sh a. (C sh, Floating a) => Vector sh a -> Square sh a
Basic.diagonal

takeDiagonal :: (Shape.C sh, Class.Floating a) => Square sh a -> Vector sh a
takeDiagonal :: Square sh a -> Vector sh a
takeDiagonal = Square sh a -> Vector sh a
forall sh a. (C sh, Floating a) => Square sh a -> Vector sh a
Basic.takeDiagonal (Square sh a -> Vector sh a)
-> (Square sh a -> Square sh a) -> Square sh a -> Vector sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sh a -> Square sh a
forall pack property lower upper meas vert horiz height width a.
ToPlain pack property lower upper meas vert horiz height width =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> PlainArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.toVector

trace :: (Shape.C sh, Class.Floating a) => Square sh a -> a
trace :: Square sh a -> a
trace = Square sh a -> a
forall sh a. (C sh, Floating a) => Square sh a -> a
Basic.trace (Square sh a -> a)
-> (Square sh a -> Square sh a) -> Square sh a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sh a -> Square sh a
forall pack property lower upper meas vert horiz height width a.
ToPlain pack property lower upper meas vert horiz height width =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> PlainArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.toVector

infix 3 |=|

(|=|) ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C sizeA, Eq sizeA, Shape.C sizeB, Eq sizeB, Class.Floating a) =>
   (Square sizeA a, Full meas vert horiz sizeA sizeB a) ->
   (Full meas horiz vert sizeB sizeA a, Square sizeB a) ->
   Square (sizeA::+sizeB) a
(Square sizeA a
a,Full meas vert horiz sizeA sizeB a
b) |=| :: (Square sizeA a, Full meas vert horiz sizeA sizeB a)
-> (Full meas horiz vert sizeB sizeA a, Square sizeB a)
-> Square (sizeA ::+ sizeB) a
|=| (Full meas horiz vert sizeB sizeA a
c,Square sizeB a
d)  =  Square sizeA a
-> Full meas vert horiz sizeA sizeB a
-> Full meas horiz vert sizeB sizeA a
-> Square sizeB a
-> Square (sizeA ::+ sizeB) a
forall meas vert horiz sizeA sizeB a.
(Measure meas, C vert, C horiz, C sizeA, Eq sizeA, C sizeB,
 Eq sizeB, Floating a) =>
Square sizeA a
-> Full meas vert horiz sizeA sizeB a
-> Full meas horiz vert sizeB sizeA a
-> Square sizeB a
-> Square (sizeA ::+ sizeB) a
stack Square sizeA a
a Full meas vert horiz sizeA sizeB a
b Full meas horiz vert sizeB sizeA a
c Square sizeB a
d

stack ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C sizeA, Eq sizeA, Shape.C sizeB, Eq sizeB, Class.Floating a) =>
   Square sizeA a -> Full meas vert horiz sizeA sizeB a ->
   Full meas horiz vert sizeB sizeA a -> Square sizeB a ->
   Square (sizeA::+sizeB) a
stack :: Square sizeA a
-> Full meas vert horiz sizeA sizeB a
-> Full meas horiz vert sizeB sizeA a
-> Square sizeB a
-> Square (sizeA ::+ sizeB) a
stack = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sizeA sizeA a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz sizeA sizeB a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas horiz vert sizeB sizeA a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sizeB sizeB a
 -> PlainArray
      Unpacked
      Arbitrary
      Filled
      Filled
      Shape
      Small
      Small
      (sizeA ::+ sizeB)
      (sizeA ::+ sizeB)
      a)
-> Square sizeA a
-> Full meas vert horiz sizeA sizeB a
-> Full meas horiz vert sizeB sizeA a
-> Square sizeB a
-> Square (sizeA ::+ sizeB) a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB packC
       propC lowerC upperC measC vertC horizC heightC widthC packD propD
       lowerD upperD measD vertD horizD heightD widthD packE propE lowerE
       upperE measE vertE horizE heightE widthE a b c d e.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 ToPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB,
 ToPlain
   packC propC lowerC upperC measC vertC horizC heightC widthC,
 ToPlain
   packD propD lowerD upperD measD vertD horizD heightD widthD,
 FromPlain
   packE propE lowerE upperE measE vertE horizE heightE widthE) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b
 -> PlainArray
      packC propC lowerC upperC measC vertC horizC heightC widthC c
 -> PlainArray
      packD propD lowerD upperD measD vertD horizD heightD widthD d
 -> PlainArray
      packE propE lowerE upperE measE vertE horizE heightE widthE e)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
-> ArrayMatrix
     packC propC lowerC upperC measC vertC horizC heightC widthC c
-> ArrayMatrix
     packD propD lowerD upperD measD vertD horizD heightD widthD d
-> ArrayMatrix
     packE propE lowerE upperE measE vertE horizE heightE widthE e
ArrMatrix.lift4 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sizeA sizeA a
-> PlainArray
     Unpacked Arbitrary Filled Filled meas vert horiz sizeA sizeB a
-> PlainArray
     Unpacked Arbitrary Filled Filled meas horiz vert sizeB sizeA a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sizeB sizeB a
-> PlainArray
     Unpacked
     Arbitrary
     Filled
     Filled
     Shape
     Small
     Small
     (sizeA ::+ sizeB)
     (sizeA ::+ sizeB)
     a
forall meas vert horiz sizeA sizeB a.
(Measure meas, C vert, C horiz, C sizeA, Eq sizeA, C sizeB,
 Eq sizeB, Floating a) =>
Square sizeA a
-> Full meas vert horiz sizeA sizeB a
-> Full meas horiz vert sizeB sizeA a
-> Square sizeB a
-> Square (sizeA ::+ sizeB) a
Basic.stack

split ::
   (Shape.C sizeA, Shape.C sizeB, Class.Floating a) =>
   Square (sizeA::+sizeB) a ->
   (Square sizeA a, General sizeA sizeB a,
    General sizeB sizeA a, Square sizeB a)
split :: Square (sizeA ::+ sizeB) a
-> (Square sizeA a, General sizeA sizeB a, General sizeB sizeA a,
    Square sizeB a)
split Square (sizeA ::+ sizeB) a
a =
   let af :: Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
af = Square (sizeA ::+ sizeB) a
-> Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz) =>
Square sh a -> Full meas vert horiz sh sh a
Basic.toFull (Square (sizeA ::+ sizeB) a
 -> Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a)
-> Square (sizeA ::+ sizeB) a
-> Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
forall a b. (a -> b) -> a -> b
$ Square (sizeA ::+ sizeB) a
-> PlainArray
     Unpacked
     Arbitrary
     Filled
     Filled
     Shape
     Small
     Small
     (sizeA ::+ sizeB)
     (sizeA ::+ sizeB)
     a
forall pack property lower upper meas vert horiz height width a.
ToPlain pack property lower upper meas vert horiz height width =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> PlainArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.toVector Square (sizeA ::+ sizeB) a
a
       top :: Full Size Big Big sizeA (sizeA ::+ sizeB) a
top = Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
-> Full Size Big Big sizeA (sizeA ::+ sizeB) a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height0 width a
FullBasic.takeTop Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
af
       bottom :: Full Size Big Big sizeB (sizeA ::+ sizeB) a
bottom = Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
-> Full Size Big Big sizeB (sizeA ::+ sizeB) a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height1 width a
FullBasic.takeBottom Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
af
   in (PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sizeA sizeA a
-> Square sizeA a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sizeA sizeA a
 -> Square sizeA a)
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sizeA sizeA a
-> Square sizeA a
forall a b. (a -> b) -> a -> b
$ Full Size Big Big sizeA sizeA a -> Square sizeA a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz sh sh a -> Square sh a
Basic.fromFullUnchecked (Full Size Big Big sizeA sizeA a -> Square sizeA a)
-> Full Size Big Big sizeA sizeA a -> Square sizeA a
forall a b. (a -> b) -> a -> b
$ Full Size Big Big sizeA (sizeA ::+ sizeB) a
-> Full Size Big Big sizeA sizeA a
forall vert height width0 width1 a.
(C vert, C height, C width0, C width1, Floating a) =>
Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width0 a
FullBasic.takeLeft Full Size Big Big sizeA (sizeA ::+ sizeB) a
top,
       PlainArray
  Unpacked Arbitrary Filled Filled Size Big Big sizeA sizeB a
-> General sizeA sizeB a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (PlainArray
   Unpacked Arbitrary Filled Filled Size Big Big sizeA sizeB a
 -> General sizeA sizeB a)
-> PlainArray
     Unpacked Arbitrary Filled Filled Size Big Big sizeA sizeB a
-> General sizeA sizeB a
forall a b. (a -> b) -> a -> b
$ Full Size Big Big sizeA (sizeA ::+ sizeB) a
-> Full Size Big Big sizeA sizeB a
forall vert height width0 width1 a.
(C vert, C height, C width0, C width1, Floating a) =>
Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width1 a
FullBasic.takeRight Full Size Big Big sizeA (sizeA ::+ sizeB) a
top,
       PlainArray
  Unpacked Arbitrary Filled Filled Size Big Big sizeB sizeA a
-> General sizeB sizeA a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (PlainArray
   Unpacked Arbitrary Filled Filled Size Big Big sizeB sizeA a
 -> General sizeB sizeA a)
-> PlainArray
     Unpacked Arbitrary Filled Filled Size Big Big sizeB sizeA a
-> General sizeB sizeA a
forall a b. (a -> b) -> a -> b
$ Full Size Big Big sizeB (sizeA ::+ sizeB) a
-> Full Size Big Big sizeB sizeA a
forall vert height width0 width1 a.
(C vert, C height, C width0, C width1, Floating a) =>
Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width0 a
FullBasic.takeLeft Full Size Big Big sizeB (sizeA ::+ sizeB) a
bottom,
       PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sizeB sizeB a
-> Square sizeB a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sizeB sizeB a
 -> Square sizeB a)
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sizeB sizeB a
-> Square sizeB a
forall a b. (a -> b) -> a -> b
$ Full Size Big Big sizeB sizeB a -> Square sizeB a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz sh sh a -> Square sh a
Basic.fromFullUnchecked (Full Size Big Big sizeB sizeB a -> Square sizeB a)
-> Full Size Big Big sizeB sizeB a -> Square sizeB a
forall a b. (a -> b) -> a -> b
$ Full Size Big Big sizeB (sizeA ::+ sizeB) a
-> Full Size Big Big sizeB sizeB a
forall vert height width0 width1 a.
(C vert, C height, C width0, C width1, Floating a) =>
Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width1 a
FullBasic.takeRight Full Size Big Big sizeB (sizeA ::+ sizeB) a
bottom)

takeTopLeft ::
   (Shape.C sizeA, Shape.C sizeB, Class.Floating a) =>
   Square (sizeA::+sizeB) a -> Square sizeA a
takeTopLeft :: Square (sizeA ::+ sizeB) a -> Square sizeA a
takeTopLeft =
   (PlainArray
   Unpacked
   Arbitrary
   Filled
   Filled
   Shape
   Small
   Small
   (sizeA ::+ sizeB)
   (sizeA ::+ sizeB)
   a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sizeA sizeA a)
-> Square (sizeA ::+ sizeB) a -> Square sizeA a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1
      (Full Size Big Big sizeA sizeA a -> Square sizeA a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz sh sh a -> Square sh a
Basic.fromFullUnchecked (Full Size Big Big sizeA sizeA a -> Square sizeA a)
-> (Square (sizeA ::+ sizeB) a -> Full Size Big Big sizeA sizeA a)
-> Square (sizeA ::+ sizeB) a
-> Square sizeA a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Full Size Big Big sizeA (sizeA ::+ sizeB) a
-> Full Size Big Big sizeA sizeA a
forall vert height width0 width1 a.
(C vert, C height, C width0, C width1, Floating a) =>
Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width0 a
FullBasic.takeLeft (Full Size Big Big sizeA (sizeA ::+ sizeB) a
 -> Full Size Big Big sizeA sizeA a)
-> (Square (sizeA ::+ sizeB) a
    -> Full Size Big Big sizeA (sizeA ::+ sizeB) a)
-> Square (sizeA ::+ sizeB) a
-> Full Size Big Big sizeA sizeA a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
-> Full Size Big Big sizeA (sizeA ::+ sizeB) a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height0 width a
FullBasic.takeTop (Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
 -> Full Size Big Big sizeA (sizeA ::+ sizeB) a)
-> (Square (sizeA ::+ sizeB) a
    -> Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a)
-> Square (sizeA ::+ sizeB) a
-> Full Size Big Big sizeA (sizeA ::+ sizeB) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square (sizeA ::+ sizeB) a
-> Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz) =>
Square sh a -> Full meas vert horiz sh sh a
Basic.toFull)

takeBottomRight ::
   (Shape.C sizeA, Shape.C sizeB, Class.Floating a) =>
   Square (sizeA::+sizeB) a -> Square sizeB a
takeBottomRight :: Square (sizeA ::+ sizeB) a -> Square sizeB a
takeBottomRight =
   (PlainArray
   Unpacked
   Arbitrary
   Filled
   Filled
   Shape
   Small
   Small
   (sizeA ::+ sizeB)
   (sizeA ::+ sizeB)
   a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sizeB sizeB a)
-> Square (sizeA ::+ sizeB) a -> Square sizeB a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1
      (Full Size Big Big sizeB sizeB a -> Square sizeB a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz sh sh a -> Square sh a
Basic.fromFullUnchecked (Full Size Big Big sizeB sizeB a -> Square sizeB a)
-> (Square (sizeA ::+ sizeB) a -> Full Size Big Big sizeB sizeB a)
-> Square (sizeA ::+ sizeB) a
-> Square sizeB a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Full Size Big Big sizeB (sizeA ::+ sizeB) a
-> Full Size Big Big sizeB sizeB a
forall vert height width0 width1 a.
(C vert, C height, C width0, C width1, Floating a) =>
Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width1 a
FullBasic.takeRight (Full Size Big Big sizeB (sizeA ::+ sizeB) a
 -> Full Size Big Big sizeB sizeB a)
-> (Square (sizeA ::+ sizeB) a
    -> Full Size Big Big sizeB (sizeA ::+ sizeB) a)
-> Square (sizeA ::+ sizeB) a
-> Full Size Big Big sizeB sizeB a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
-> Full Size Big Big sizeB (sizeA ::+ sizeB) a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height1 width a
FullBasic.takeBottom (Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
 -> Full Size Big Big sizeB (sizeA ::+ sizeB) a)
-> (Square (sizeA ::+ sizeB) a
    -> Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a)
-> Square (sizeA ::+ sizeB) a
-> Full Size Big Big sizeB (sizeA ::+ sizeB) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square (sizeA ::+ sizeB) a
-> Full Size Big Big (sizeA ::+ sizeB) (sizeA ::+ sizeB) a
forall meas vert horiz sh a.
(Measure meas, C vert, C horiz) =>
Square sh a -> Full meas vert horiz sh sh a
Basic.toFull)

multiply ::
   (Shape.C sh, Eq sh, Class.Floating a) =>
   Square sh a -> Square sh a -> Square sh a
multiply :: Square sh a -> Square sh a -> Square sh a
multiply = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sh sh a)
-> Square sh a -> Square sh a -> Square sh a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB packC
       propC lowerC upperC measC vertC horizC heightC widthC a b c.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 ToPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB,
 FromPlain
   packC propC lowerC upperC measC vertC horizC heightC widthC) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b
 -> PlainArray
      packC propC lowerC upperC measC vertC horizC heightC widthC c)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
-> ArrayMatrix
     packC propC lowerC upperC measC vertC horizC heightC widthC c
ArrMatrix.lift2 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
forall meas vert horiz height fuse width a.
(Measure meas, C vert, C horiz, C height, C fuse, Eq fuse, C width,
 Floating a) =>
Full meas vert horiz height fuse a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
FullBasic.multiply

square :: (Shape.C sh, Class.Floating a) => Square sh a -> Square sh a
square :: Square sh a -> Square sh a
square = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small sh sh a)
-> Square sh a -> Square sh a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
forall sh a. (C sh, Floating a) => Square sh a -> Square sh a
Basic.square

power ::
   (Shape.C sh, Class.Floating a) =>
   Integer -> Square sh a -> Square sh a
power :: Integer -> Square sh a -> Square sh a
power = (Array (Full Shape Small Small sh sh) a
 -> Array (Full Shape Small Small sh sh) a)
-> Square sh a -> Square sh a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 ((Array (Full Shape Small Small sh sh) a
  -> Array (Full Shape Small Small sh sh) a)
 -> Square sh a -> Square sh a)
-> (Integer
    -> Array (Full Shape Small Small sh sh) a
    -> Array (Full Shape Small Small sh sh) a)
-> Integer
-> Square sh a
-> Square sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer
-> Array (Full Shape Small Small sh sh) a
-> Array (Full Shape Small Small sh sh) a
forall sh a.
(C sh, Floating a) =>
Integer -> Square sh a -> Square sh a
Basic.power

{- |
congruence B A = A^H * B * A


The meaning and order of matrix factors of these functions is consistent:

* 'Numeric.LAPACK.Matrix.Square.congruence'
* 'Numeric.LAPACK.Matrix.Hermitian.gramian'
* 'Numeric.LAPACK.Matrix.Hermitian.anticommutator'
* 'Numeric.LAPACK.Matrix.Hermitian.congruence'
* 'Numeric.LAPACK.Matrix.Hermitian.congruenceDiagonal'
-}
congruence ::
   (Shape.C height, Eq height, Shape.C width, Class.Floating a) =>
   Square height a -> General height width a -> Square width a
congruence :: Square height a -> General height width a -> Square width a
congruence = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small height height a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Size Big Big height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small width width a)
-> Square height a -> General height width a -> Square width a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB packC
       propC lowerC upperC measC vertC horizC heightC widthC a b c.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 ToPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB,
 FromPlain
   packC propC lowerC upperC measC vertC horizC heightC widthC) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b
 -> PlainArray
      packC propC lowerC upperC measC vertC horizC heightC widthC c)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
-> ArrayMatrix
     packC propC lowerC upperC measC vertC horizC heightC widthC c
ArrMatrix.lift2 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small height height a
-> PlainArray
     Unpacked Arbitrary Filled Filled Size Big Big height width a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small width width a
forall height width a.
(C height, Eq height, C width, Floating a) =>
Square height a -> General height width a -> Square width a
Basic.congruence

{- |
congruenceAdjoint A B = A * B * A^H
-}
congruenceAdjoint ::
   (Shape.C height, Shape.C width, Eq width, Class.Floating a) =>
   General height width a -> Square width a -> Square height a
congruenceAdjoint :: General height width a -> Square width a -> Square height a
congruenceAdjoint = (PlainArray
   Unpacked Arbitrary Filled Filled Size Big Big height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small width width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled Shape Small Small height height a)
-> General height width a -> Square width a -> Square height a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB packC
       propC lowerC upperC measC vertC horizC heightC widthC a b c.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 ToPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB,
 FromPlain
   packC propC lowerC upperC measC vertC horizC heightC widthC) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b
 -> PlainArray
      packC propC lowerC upperC measC vertC horizC heightC widthC c)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
-> ArrayMatrix
     packC propC lowerC upperC measC vertC horizC heightC widthC c
ArrMatrix.lift2 PlainArray
  Unpacked Arbitrary Filled Filled Size Big Big height width a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small width width a
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small height height a
forall height width a.
(C height, C width, Eq width, Floating a) =>
General height width a -> Square width a -> Square height a
Basic.congruenceAdjoint



solve ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C sh, Eq sh, Shape.C nrhs, Class.Floating a) =>
   Square sh a ->
   Full meas vert horiz sh nrhs a -> Full meas vert horiz sh nrhs a
solve :: Square sh a
-> Full meas vert horiz sh nrhs a -> Full meas vert horiz sh nrhs a
solve = (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz sh nrhs a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz sh nrhs a)
-> Square sh a
-> Full meas vert horiz sh nrhs a
-> Full meas vert horiz sh nrhs a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB packC
       propC lowerC upperC measC vertC horizC heightC widthC a b c.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 ToPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB,
 FromPlain
   packC propC lowerC upperC measC vertC horizC heightC widthC) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b
 -> PlainArray
      packC propC lowerC upperC measC vertC horizC heightC widthC c)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
-> ArrayMatrix
     packC propC lowerC upperC measC vertC horizC heightC widthC c
ArrMatrix.lift2 PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> PlainArray
     Unpacked Arbitrary Filled Filled meas vert horiz sh nrhs a
-> PlainArray
     Unpacked Arbitrary Filled Filled meas vert horiz sh nrhs a
forall meas vert horiz sh nrhs a.
(Measure meas, C vert, C horiz, C sh, Eq sh, C nrhs, Floating a) =>
Square sh a
-> Full meas vert horiz sh nrhs a -> Full meas vert horiz sh nrhs a
Linear.solve

inverse ::
   (Extent.Measure meas, Shape.C height, Shape.C width, Class.Floating a) =>
   SquareMeas meas height width a -> SquareMeas meas width height a
inverse :: SquareMeas meas height width a -> SquareMeas meas width height a
inverse = (PlainArray
   Unpacked Arbitrary Filled Filled meas Small Small height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas Small Small width height a)
-> SquareMeas meas height width a -> SquareMeas meas width height a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 PlainArray
  Unpacked Arbitrary Filled Filled meas Small Small height width a
-> PlainArray
     Unpacked Arbitrary Filled Filled meas Small Small width height a
forall meas height width a.
(Measure meas, C height, C width, Floating a) =>
SquareMeas meas height width a -> SquareMeas meas width height a
Linear.inverse

determinant :: (Shape.C sh, Class.Floating a) => Square sh a -> a
determinant :: Square sh a -> a
determinant = Square sh a -> a
forall sh a. (C sh, Floating a) => Square sh a -> a
Linear.determinant (Square sh a -> a)
-> (Square sh a -> Square sh a) -> Square sh a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sh a -> Square sh a
forall pack property lower upper meas vert horiz height width a.
ToPlain pack property lower upper meas vert horiz height width =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> PlainArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.toVector



eigenvalues ::
   (ExtShape.Permutable sh, Class.Floating a) =>
   Square sh a -> Vector sh (ComplexOf a)
eigenvalues :: Square sh a -> Vector sh (ComplexOf a)
eigenvalues = Square sh a -> Vector sh (ComplexOf a)
forall sh a.
(Permutable sh, Floating a) =>
Square sh a -> Vector sh (ComplexOf a)
Eigen.values (Square sh a -> Vector sh (ComplexOf a))
-> (Square sh a -> Square sh a)
-> Square sh a
-> Vector sh (ComplexOf a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sh a -> Square sh a
forall pack property lower upper meas vert horiz height width a.
ToPlain pack property lower upper meas vert horiz height width =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> PlainArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.toVector

{- |
If @(q,r) = schur a@, then @a = q \<\> r \<\> adjoint q@,
where @q@ is unitary (orthogonal)
and @r@ is a right-upper triangular matrix for complex @a@
and a 1x1-or-2x2-block upper triangular matrix for real @a@.
With @takeDiagonal r@ you get all eigenvalues of @a@ if @a@ is complex
and the real parts of the eigenvalues if @a@ is real.
Complex conjugated eigenvalues of a real matrix @a@
are encoded as 2x2 blocks along the diagonal.


The meaning and order of matrix factors of these functions is consistent:

* 'Numeric.LAPACK.Matrix.Square.schur'
* 'Numeric.LAPACK.Matrix.Square.schurComplex'
* 'Numeric.LAPACK.Matrix.Hermitian.eigensystem'
* 'Numeric.LAPACK.Matrix.BandedHermitian.eigensystem'
* 'Numeric.LAPACK.Matrix.Square.congruenceAdjoint'
* 'Numeric.LAPACK.Matrix.Hermitian.gramianAdjoint'
* 'Numeric.LAPACK.Matrix.Hermitian.anticommutatorAdjoint'
* 'Numeric.LAPACK.Matrix.Hermitian.congruenceAdjoint'
* 'Numeric.LAPACK.Matrix.Hermitian.congruenceDiagonalAdjoint'
-}
schur ::
   (ExtShape.Permutable sh, Class.Floating a) =>
   Square sh a -> (Square sh a, Triangular.QuasiUpper sh a)
schur :: Square sh a -> (Square sh a, QuasiUpper sh a)
schur =
   (Square sh a -> Square sh a, Square sh a -> QuasiUpper sh a)
-> (Square sh a, Square sh a) -> (Square sh a, QuasiUpper sh a)
forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
mapPair (Square sh a -> Square sh a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0, Square sh a -> QuasiUpper sh a
forall propertyA lowerA upperA measA vertA horizA heightA widthA a.
(Property propertyA, Strip lowerA, Strip upperA) =>
FullArray measA vertA horizA heightA widthA a
-> UnpackedMatrix
     propertyA lowerA upperA measA vertA horizA heightA widthA a
ArrMatrix.liftUnpacked0) ((Square sh a, Square sh a) -> (Square sh a, QuasiUpper sh a))
-> (Square sh a -> (Square sh a, Square sh a))
-> Square sh a
-> (Square sh a, QuasiUpper sh a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   Square sh a -> (Square sh a, Square sh a)
forall sh a.
(Permutable sh, Floating a) =>
Square sh a -> (Square sh a, Square sh a)
Eigen.schur (Square sh a -> (Square sh a, Square sh a))
-> (Square sh a -> Square sh a)
-> Square sh a
-> (Square sh a, Square sh a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sh a -> Square sh a
forall pack property lower upper meas vert horiz height width a.
ToPlain pack property lower upper meas vert horiz height width =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> PlainArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.toVector

schurComplex ::
   (ExtShape.Permutable sh, Class.Real a, Complex a ~ ac) =>
   Square sh ac -> (Square sh ac, Triangular.Upper sh ac)
schurComplex :: Square sh ac -> (Square sh ac, Upper sh ac)
schurComplex = (Unpacked Arbitrary (Bands U1) Filled Shape Small Small sh sh ac
 -> Upper sh ac)
-> (Square sh ac,
    Unpacked Arbitrary (Bands U1) Filled Shape Small Small sh sh ac)
-> (Square sh ac, Upper sh ac)
forall b c a. (b -> c) -> (a, b) -> (a, c)
mapSnd Unpacked Arbitrary (Bands U1) Filled Shape Small Small sh sh ac
-> Upper sh ac
forall property lower meas vert height width a.
(Property property, Strip lower, Measure meas, C vert, C height,
 C width, Floating a) =>
Unpacked property lower Filled meas vert Small height width a
-> Upper width a
Triangular.takeUpper ((Square sh ac,
  Unpacked Arbitrary (Bands U1) Filled Shape Small Small sh sh ac)
 -> (Square sh ac, Upper sh ac))
-> (Square sh ac
    -> (Square sh ac,
        Unpacked Arbitrary (Bands U1) Filled Shape Small Small sh sh ac))
-> Square sh ac
-> (Square sh ac, Upper sh ac)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sh ac
-> (Square sh ac,
    Unpacked Arbitrary (Bands U1) Filled Shape Small Small sh sh ac)
forall sh a.
(Permutable sh, Floating a) =>
Square sh a -> (Square sh a, QuasiUpper sh a)
schur


{- |
@(vr,d,vlAdj) = eigensystem a@

Counterintuitively, @vr@ contains the right eigenvectors as columns
and @vlAdj@ contains the left conjugated eigenvectors as rows.
The idea is to provide a decomposition of @a@.
If @a@ is diagonalizable, then @vr@ and @vlAdj@
are almost inverse to each other.
More precisely, @vlAdj \<\> vr@ is a diagonal matrix,
but not necessarily an identity matrix.
This is because all eigenvectors are normalized to Euclidean norm 1.
With the following scaling, the decomposition becomes perfect:

> let scal = takeDiagonal $ vlAdj <> vr
> a == vr #*\ Vector.divide d scal ##*# vlAdj

If @a@ is non-diagonalizable
then some columns of @vr@ and corresponding rows of @vlAdj@ are left zero
and the above property does not hold.


The meaning and order of result matrices of these functions is consistent:

* 'Numeric.LAPACK.Matrix.Square.eigensystem'
* 'Numeric.LAPACK.Matrix.Triangular.eigensystem'
* 'Numeric.LAPACK.Singular.decompose'
* 'Numeric.LAPACK.Singular.decomposeTall'
* 'Numeric.LAPACK.Singular.decomposeWide'
-}
eigensystem ::
   (ExtShape.Permutable sh, Class.Floating a, ComplexOf a ~ ac) =>
   Square sh a -> (Square sh ac, Vector sh ac, Square sh ac)
eigensystem :: Square sh a -> (Square sh ac, Vector sh ac, Square sh ac)
eigensystem =
   (Square sh ac -> Square sh ac, Vector sh ac -> Vector sh ac,
 Square sh ac -> Square sh ac)
-> (Square sh ac, Vector sh ac, Square sh ac)
-> (Square sh ac, Vector sh ac, Square sh ac)
forall a d b e c f.
(a -> d, b -> e, c -> f) -> (a, b, c) -> (d, e, f)
mapTriple (Square sh ac -> Square sh ac
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0, Vector sh ac -> Vector sh ac
forall a. a -> a
id, Square sh ac -> Square sh ac
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0) ((Square sh ac, Vector sh ac, Square sh ac)
 -> (Square sh ac, Vector sh ac, Square sh ac))
-> (Square sh a -> (Square sh ac, Vector sh ac, Square sh ac))
-> Square sh a
-> (Square sh ac, Vector sh ac, Square sh ac)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   Square sh a -> (Square sh ac, Vector sh ac, Square sh ac)
forall sh a ac.
(Permutable sh, Floating a, ComplexOf a ~ ac) =>
Square sh a -> System sh ac
Eigen.decompose (Square sh a -> (Square sh ac, Vector sh ac, Square sh ac))
-> (Square sh a -> Square sh a)
-> Square sh a
-> (Square sh ac, Vector sh ac, Square sh ac)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Square sh a -> Square sh a
forall pack property lower upper meas vert horiz height width a.
ToPlain pack property lower upper meas vert horiz height width =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> PlainArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.toVector