{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
module Numeric.LAPACK.Matrix.Function (
   SqRt, sqrt, sqrtSchur, sqrtDenmanBeavers,
   Exp, exp, expRealHermitian,
   Log, log, logUnipotentUpper,
   LiftReal, liftReal,
   ) where

import qualified Numeric.LAPACK.Matrix as Matrix
import qualified Numeric.LAPACK.Matrix.Lazy.UpperTriangular as LazyUpper
import qualified Numeric.LAPACK.Matrix.Array.Mosaic as ArrMosaic
import qualified Numeric.LAPACK.Matrix.Mosaic.Basic as Mosaic
import qualified Numeric.LAPACK.Matrix.Hermitian as Hermitian
import qualified Numeric.LAPACK.Matrix.Symmetric as Symmetric
import qualified Numeric.LAPACK.Matrix.Triangular as Triangular
import qualified Numeric.LAPACK.Matrix.Quadratic as Quad
import qualified Numeric.LAPACK.Matrix.Square as Square
import qualified Numeric.LAPACK.Matrix.Diagonal as Diagonal
import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Shape.Omni as Omni
import qualified Numeric.LAPACK.Matrix.Shape as MatrixShape
import qualified Numeric.LAPACK.Matrix.Layout.Private as Layout
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import qualified Numeric.LAPACK.Vector as Vector
import qualified Numeric.LAPACK.Scalar as Scalar
import qualified Numeric.LAPACK.Shape.Private as PrivShape
import qualified Numeric.LAPACK.Shape as ExtShape
import Numeric.LAPACK.Matrix.Array.Mosaic
         (UnitUpperP, LowerP, UpperP, FlexUpperP,
          HermitianP, HermitianPosSemidefP)
import Numeric.LAPACK.Matrix.Array (Quadratic, ArrayMatrix, packTag)
import Numeric.LAPACK.Matrix.Square (Square)
import Numeric.LAPACK.Matrix
         ((#!), (#+#), (#-#), (#\##), (#*\), (#*##), (##*#))
import Numeric.LAPACK.Vector ((|+|), (|-|))

import qualified Numeric.Netlib.Class as Class

import qualified Type.Data.Bool as Bool
import Type.Data.Bool (False, True)

import Foreign.Storable (Storable)

import qualified Data.Array.Comfort.Storable.Unchecked as Array
import qualified Data.Array.Comfort.Shape as Shape

import qualified Data.NonEmpty as NonEmpty
import qualified Data.Complex as Complex
import qualified Data.List.HT as ListHT
import qualified Data.Stream as Stream
import Data.Complex (Complex)
import Data.Semigroup ((<>))
import Data.Function.HT (nest)
import Data.Tuple.HT (mapFst, swap)
import Data.Stream (Stream)

import qualified Prelude as P
import Prelude hiding (sqrt, exp, log)


class (MatrixShape.Property property) => SqRt property where
   sqrt ::
      (Layout.Packing pack,
       MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
       Shape.C sh, Class.Real a) =>
      Quadratic pack property lower upper sh a ->
      Quadratic pack property lower upper sh a

instance SqRt Omni.Unit where
   sqrt :: Quadratic pack Unit lower upper sh a
-> Quadratic pack Unit lower upper sh a
sqrt Quadratic pack Unit lower upper sh a
a =
      case Omni pack Unit lower upper Shape Small Small sh sh
-> Power pack Unit lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni pack Unit lower upper Shape Small Small sh sh
 -> Power pack Unit lower upper Shape Small Small sh sh)
-> Omni pack Unit lower upper Shape Small Small sh sh
-> Power pack Unit lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack Unit lower upper sh a
-> Omni pack Unit lower upper 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 Quadratic pack Unit lower upper sh a
a of
         Power pack Unit lower upper Shape Small Small sh sh
Omni.PowerIdentity -> Quadratic pack Unit lower upper sh a
a
         Power pack Unit lower upper Shape Small Small sh sh
Omni.PowerUpperTriangular -> (a -> a) -> FlexUpperP pack Unit sh a -> FlexUpperP pack Unit sh a
forall pack diag sh a.
(Packing pack, TriDiag diag, C sh, Floating a) =>
(a -> a) -> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
sqrtUpper (a -> a -> a
forall a b. a -> b -> a
const a
forall a. Floating a => a
Scalar.one) Quadratic pack Unit lower upper sh a
FlexUpperP pack Unit sh a
a
         Power pack Unit lower upper Shape Small Small sh sh
Omni.PowerLowerTriangular ->
            FlexUpperP pack Unit sh a
-> TriangularP pack Filled Unit Empty sh a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a
-> TriangularP pack up diag lo sh a
Triangular.transpose (FlexUpperP pack Unit sh a
 -> TriangularP pack Filled Unit Empty sh a)
-> (TriangularP pack Filled Unit Empty sh a
    -> FlexUpperP pack Unit sh a)
-> TriangularP pack Filled Unit Empty sh a
-> TriangularP pack Filled Unit Empty sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            (a -> a) -> FlexUpperP pack Unit sh a -> FlexUpperP pack Unit sh a
forall pack diag sh a.
(Packing pack, TriDiag diag, C sh, Floating a) =>
(a -> a) -> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
sqrtUpper (a -> a -> a
forall a b. a -> b -> a
const a
forall a. Floating a => a
Scalar.one) (FlexUpperP pack Unit sh a -> FlexUpperP pack Unit sh a)
-> (TriangularP pack Filled Unit Empty sh a
    -> FlexUpperP pack Unit sh a)
-> TriangularP pack Filled Unit Empty sh a
-> FlexUpperP pack Unit sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            TriangularP pack Filled Unit Empty sh a
-> FlexUpperP pack Unit sh a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a
-> TriangularP pack up diag lo sh a
Triangular.transpose (TriangularP pack Filled Unit Empty sh a
 -> TriangularP pack Filled Unit Empty sh a)
-> TriangularP pack Filled Unit Empty sh a
-> TriangularP pack Filled Unit Empty sh a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Unit lower upper sh a
TriangularP pack Filled Unit Empty sh a
a
         Power pack Unit lower upper Shape Small Small sh sh
Omni.PowerDiagonal -> [Char] -> Quadratic pack Unit lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"non-unit diagonal impossible"
         Power pack Unit lower upper Shape Small Small sh sh
Omni.PowerFull -> [Char] -> Quadratic pack Unit lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"unit full matrix impossible"

{- |
For Full matrices:
Explicit solution for matrices up to size 2.
Solution via 'sqrtDenmanBeavers' for larger sizes.
-}
instance SqRt Omni.Arbitrary where
   sqrt :: Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
sqrt Quadratic pack Arbitrary lower upper sh a
m =
      case Omni pack Arbitrary lower upper Shape Small Small sh sh
-> Power pack Arbitrary lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni pack Arbitrary lower upper Shape Small Small sh sh
 -> Power pack Arbitrary lower upper Shape Small Small sh sh)
-> Omni pack Arbitrary lower upper Shape Small Small sh sh
-> Power pack Arbitrary lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper sh a
-> Omni pack Arbitrary lower upper 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 Quadratic pack Arbitrary lower upper sh a
m of
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerDiagonal -> (a -> a)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh a
forall pack sh a b.
(Packing pack, C sh, Floating a, Floating b) =>
(a -> b)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh b
liftDiagonal a -> a
forall a. Floating a => a -> a
P.sqrt Quadratic pack Arbitrary lower upper sh a
Quadratic pack Arbitrary Empty Empty sh a
m
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerUpperTriangular -> (a -> a)
-> FlexUpperP pack Arbitrary sh a -> FlexUpperP pack Arbitrary sh a
forall pack diag sh a.
(Packing pack, TriDiag diag, C sh, Floating a) =>
(a -> a) -> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
sqrtUpper a -> a
forall a. Floating a => a -> a
P.sqrt Quadratic pack Arbitrary lower upper sh a
FlexUpperP pack Arbitrary sh a
m
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerLowerTriangular ->
            FlexUpperP pack Arbitrary sh a
-> TriangularP pack Filled Arbitrary Empty sh a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a
-> TriangularP pack up diag lo sh a
Triangular.transpose (FlexUpperP pack Arbitrary sh a
 -> TriangularP pack Filled Arbitrary Empty sh a)
-> (TriangularP pack Filled Arbitrary Empty sh a
    -> FlexUpperP pack Arbitrary sh a)
-> TriangularP pack Filled Arbitrary Empty sh a
-> TriangularP pack Filled Arbitrary Empty sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a)
-> FlexUpperP pack Arbitrary sh a -> FlexUpperP pack Arbitrary sh a
forall pack diag sh a.
(Packing pack, TriDiag diag, C sh, Floating a) =>
(a -> a) -> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
sqrtUpper a -> a
forall a. Floating a => a -> a
P.sqrt (FlexUpperP pack Arbitrary sh a -> FlexUpperP pack Arbitrary sh a)
-> (TriangularP pack Filled Arbitrary Empty sh a
    -> FlexUpperP pack Arbitrary sh a)
-> TriangularP pack Filled Arbitrary Empty sh a
-> FlexUpperP pack Arbitrary sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TriangularP pack Filled Arbitrary Empty sh a
-> FlexUpperP pack Arbitrary sh a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a
-> TriangularP pack up diag lo sh a
Triangular.transpose (TriangularP pack Filled Arbitrary Empty sh a
 -> TriangularP pack Filled Arbitrary Empty sh a)
-> TriangularP pack Filled Arbitrary Empty sh a
-> TriangularP pack Filled Arbitrary Empty sh a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper sh a
TriangularP pack Filled Arbitrary Empty sh a
m
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerFull ->
            if sh -> Int
forall sh. C sh => sh -> Int
Shape.size (Quadratic pack Arbitrary lower upper sh a -> sh
forall pack property lower upper sh a.
Quadratic pack property lower upper sh a -> sh
Quad.size Quadratic pack Arbitrary lower upper sh a
m) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
2
               then
                  OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
-> Quadratic pack Arbitrary lower upper sh a
forall pack prop lower upper meas vert horiz height width a.
OmniArray pack prop lower upper meas vert horiz height width a
-> Matrix
     (Array pack prop) () () lower upper meas vert horiz height width a
ArrMatrix.Array (OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
 -> Quadratic pack Arbitrary lower upper sh a)
-> OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
-> Quadratic pack Arbitrary lower upper sh a
forall a b. (a -> b) -> a -> b
$ Omni pack Arbitrary lower upper Shape Small Small sh sh
-> [a]
-> OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
forall sh a. (C sh, Storable a) => sh -> [a] -> Array sh a
Array.fromList (Quadratic pack Arbitrary lower upper sh a
-> Omni pack Arbitrary lower upper 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 Quadratic pack Arbitrary lower upper sh a
m) ([a]
 -> OmniArray pack Arbitrary lower upper Shape Small Small sh sh a)
-> [a]
-> OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
forall a b. (a -> b) -> a -> b
$
                  case OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
-> [a]
forall sh a. (C sh, Storable a) => Array sh a -> [a]
Array.toList (OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
 -> [a])
-> OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
-> [a]
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper sh a
-> OmniArray pack Arbitrary lower upper Shape Small Small sh sh a
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> OmniArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.unwrap Quadratic pack Arbitrary lower upper sh a
m of
                     [a
qA,a
qB,a
qC,a
qD] ->
                        let ((a
a,a
b),(a
c,a
d)) = ((a, a), (a, a)) -> ((a, a), (a, a))
forall a. Floating a => ((a, a), (a, a)) -> ((a, a), (a, a))
sqrt2 ((a
qA,a
qB),(a
qC,a
qD))
                        in [a
a,a
b,a
c,a
d]
                     [a
qA] -> [a -> a
forall a. Floating a => a -> a
P.sqrt a
qA]
                     [a]
_ -> []
               else
                  case Quadratic pack Arbitrary lower upper sh a -> PrecisionSingleton a
forall a (f :: * -> *). Real a => f a -> PrecisionSingleton a
Scalar.precisionOfFunctor Quadratic pack Arbitrary lower upper sh a
m of
                     PrecisionSingleton a
Scalar.Float -> Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Additive prop, Packing pack, PowerStrip lower,
 PowerStrip upper, C sh, Floating a, RealOf a ~ ar, Real ar) =>
Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
sqrtDenmanBeavers Quadratic pack Arbitrary lower upper sh a
m
                     PrecisionSingleton a
Scalar.Double -> Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Additive prop, Packing pack, PowerStrip lower,
 PowerStrip upper, C sh, Floating a, RealOf a ~ ar, Real ar) =>
Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
sqrtDenmanBeavers Quadratic pack Arbitrary lower upper sh a
m

instance SqRt Omni.Symmetric where
   sqrt :: Quadratic pack Symmetric lower upper sh a
-> Quadratic pack Symmetric lower upper sh a
sqrt Quadratic pack Symmetric lower upper sh a
a =
      case Omni pack Symmetric lower upper Shape Small Small sh sh
-> Power pack Symmetric lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni pack Symmetric lower upper Shape Small Small sh sh
 -> Power pack Symmetric lower upper Shape Small Small sh sh)
-> Omni pack Symmetric lower upper Shape Small Small sh sh
-> Power pack Symmetric lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack Symmetric lower upper sh a
-> Omni pack Symmetric lower upper 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 Quadratic pack Symmetric lower upper sh a
a of
         Power pack Symmetric lower upper Shape Small Small sh sh
Omni.PowerSymmetric ->
            FlexHermitianP pack True True True sh a -> SymmetricP pack sh a
forall pack neg zero pos sh a.
(Packing pack, C neg, C zero, C pos, C sh, Real a) =>
FlexHermitianP pack neg zero pos sh a -> SymmetricP pack sh a
Symmetric.fromHermitian (FlexHermitianP pack True True True sh a -> SymmetricP pack sh a)
-> (SymmetricP pack sh a
    -> FlexHermitianP pack True True True sh a)
-> SymmetricP pack sh a
-> SymmetricP pack sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlexHermitianP pack True True True sh a
-> FlexHermitianP pack True True True sh a
forall pack neg zero pos herm sh a.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Real a) =>
Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
sqrtHermitian (FlexHermitianP pack True True True sh a
 -> FlexHermitianP pack True True True sh a)
-> (SymmetricP pack sh a
    -> FlexHermitianP pack True True True sh a)
-> SymmetricP pack sh a
-> FlexHermitianP pack True True True sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricP pack sh a -> FlexHermitianP pack True True True sh a
forall pack sh a.
(Packing pack, C sh, Real a) =>
SymmetricP pack sh a -> HermitianP pack sh a
Hermitian.fromSymmetric
               (SymmetricP pack sh a -> SymmetricP pack sh a)
-> SymmetricP pack sh a -> SymmetricP pack sh a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Symmetric lower upper sh a
SymmetricP pack sh a
a
         Power pack Symmetric lower upper Shape Small Small sh sh
_ -> [Char] -> Quadratic pack Symmetric lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"Symmetric.sqrt: impossible shape"

instance
   (neg ~ False, Bool.C zero, Bool.C pos) =>
      SqRt (Omni.Hermitian neg zero pos) where
   sqrt :: Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> Quadratic pack (Hermitian neg zero pos) lower upper sh a
sqrt Quadratic pack (Hermitian neg zero pos) lower upper sh a
a =
      case Omni
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
-> Power
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni
   pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
 -> Power
      pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh)
-> Omni
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
-> Power
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> Omni
     pack (Hermitian neg zero pos) lower upper 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 Quadratic pack (Hermitian neg zero pos) lower upper sh a
a of
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
Omni.PowerDiagonal -> (a -> a)
-> Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
-> Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
forall pack neg zero pos herm sh a b.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, Floating b) =>
(a -> b)
-> Quadratic pack herm Empty Empty sh a
-> Quadratic pack herm Empty Empty sh b
liftHermitianDiagonal a -> a
forall a. Floating a => a -> a
P.sqrt Quadratic pack (Hermitian neg zero pos) lower upper sh a
Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
a
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
Omni.PowerHermitian -> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
forall pack neg zero pos herm sh a.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Real a) =>
Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
sqrtHermitian Quadratic pack (Hermitian neg zero pos) lower upper sh a
Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
a
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
_ -> [Char] -> Quadratic pack (Hermitian neg zero pos) lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"Hermitian.sqrt: impossible shape"

sqrtHermitian ::
   (Layout.Packing pack,
    Bool.C neg, Bool.C zero, Bool.C pos, Omni.Hermitian neg zero pos ~ herm,
    Shape.C sh, Class.Real a) =>
   Quadratic pack herm Layout.Filled Layout.Filled sh a ->
   Quadratic pack herm Layout.Filled Layout.Filled sh a
sqrtHermitian :: Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
sqrtHermitian Quadratic pack herm Filled Filled sh a
a =
   case Quadratic pack herm Filled Filled sh a -> PrecisionSingleton a
forall a (f :: * -> *). Real a => f a -> PrecisionSingleton a
Scalar.precisionOfFunctor Quadratic pack herm Filled Filled sh a
a of
      PrecisionSingleton a
Scalar.Float -> (Float -> Float)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
forall pack neg zero pos herm sh a ar.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, RealOf a ~ ar, Storable ar) =>
(ar -> ar)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
liftHermitian Float -> Float
forall a. Floating a => a -> a
P.sqrt Quadratic pack herm Filled Filled sh a
a
      PrecisionSingleton a
Scalar.Double -> (Double -> Double)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
forall pack neg zero pos herm sh a ar.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, RealOf a ~ ar, Storable ar) =>
(ar -> ar)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
liftHermitian Double -> Double
forall a. Floating a => a -> a
P.sqrt Quadratic pack herm Filled Filled sh a
a

sqrtUpper ::
   (Layout.Packing pack, Omni.TriDiag diag, Shape.C sh, Class.Floating a) =>
    (a -> a) -> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
sqrtUpper :: (a -> a) -> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
sqrtUpper a -> a
sqrtF FlexUpperP pack diag sh a
a =
   FlexUpperP pack diag sh a
-> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a
-> TriangularP pack lo diag up sh a
-> TriangularP pack lo diag up sh a
Triangular.adaptOrder FlexUpperP pack diag sh a
a (FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a)
-> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
forall a b. (a -> b) -> a -> b
$ (PlainArray Packed Arbitrary Empty Filled Shape Small Small sh sh a
 -> PlainArray pack diag Empty Filled Shape Small Small sh sh a)
-> ArrayMatrix
     Packed Arbitrary Empty Filled Shape Small Small sh sh a
-> FlexUpperP pack diag 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 Packed Arbitrary Empty Filled Shape Small Small sh sh a
-> PlainArray pack diag Empty Filled Shape Small Small sh sh a
forall pack uplo sh a mirror.
(Packing pack, UpLo uplo, C sh, Floating a) =>
Mosaic mirror uplo sh a -> Mosaic pack mirror uplo sh a
Mosaic.reunpack (ArrayMatrix
   Packed Arbitrary Empty Filled Shape Small Small sh sh a
 -> FlexUpperP pack diag sh a)
-> ArrayMatrix
     Packed Arbitrary Empty Filled Shape Small Small sh sh a
-> FlexUpperP pack diag sh a
forall a b. (a -> b) -> a -> b
$
   Upper sh a
-> ArrayMatrix
     Packed Arbitrary Empty Filled Shape Small Small sh sh a
forall sh a. (C sh, Floating a) => Upper sh a -> Upper sh a
LazyUpper.toStorable (Upper sh a
 -> ArrayMatrix
      Packed Arbitrary Empty Filled Shape Small Small sh sh a)
-> Upper sh a
-> ArrayMatrix
     Packed Arbitrary Empty Filled Shape Small Small sh sh a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> Upper sh a -> Upper sh a
forall sh a.
(C sh, Fractional a) =>
(a -> a) -> Upper sh a -> Upper sh a
LazyUpper.sqrt a -> a
sqrtF (Upper sh a -> Upper sh a) -> Upper sh a -> Upper sh a
forall a b. (a -> b) -> a -> b
$ FlexUpperP pack diag sh a -> Upper sh a
forall sh a pack diag.
(C sh, Floating a) =>
FlexUpperP pack diag sh a -> Upper sh a
LazyUpper.fromStorable FlexUpperP pack diag sh a
a

{-
/A B\ = /a b\. /a b\ = /a*a+b*c a*b+b*d\ = /a²+b*c  b*(a+d)\
\C D/   \c d/  \c d/   \c*a+d*c c*b+d*d/   \c*(a+d) d²+b*c /

b/c = B/C   B*c = C*b
b*C/B = c
A=a²+b²*C/B
D=d²+b²*C/B

a²-d² = A-D
B = b*(a+d)
B*(a-d) = b*(a²-d²) = b*(A-D)
C*(a-d) = c*(a²-d²) = c*(A-D)

(4*B*C-(A+D)^2)*b^4 + 2*B^2*(A-D)*b^2 - B^4 = 0

with x = B/b = C/c = a+d:
maxima:
   poly_buchberger([a²+b*c-A,a*b+b*d-B,c*a+d*c-C,b*c+d²-D,x-(a+d)],[a,d,b,c,x]);

x^4-2*(A+D)*x^2+(A-D)^2+4*B*C = 0
c = C/x, b = B/x
a² = A - b*c = A - B*C/x²
-}
sqrt2 :: (Floating a) => ((a,a),(a,a)) -> ((a,a),(a,a))
sqrt2 :: ((a, a), (a, a)) -> ((a, a), (a, a))
sqrt2 ((a
a,a
b),(a
c,a
d)) =
   let x :: a
x = a -> a
forall a. Floating a => a -> a
P.sqrt (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a
aa -> a -> a
forall a. Num a => a -> a -> a
+a
d a -> a -> a
forall a. Num a => a -> a -> a
+ a
2 a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
P.sqrt (a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
d a -> a -> a
forall a. Num a => a -> a -> a
- a
ba -> a -> a
forall a. Num a => a -> a -> a
*a
c)
       y :: a
y = (a
da -> a -> a
forall a. Num a => a -> a -> a
-a
a)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
x
   in (((a
xa -> a -> a
forall a. Num a => a -> a -> a
-a
y)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
2, a
ba -> a -> a
forall a. Fractional a => a -> a -> a
/a
x), (a
ca -> a -> a
forall a. Fractional a => a -> a -> a
/a
x, (a
xa -> a -> a
forall a. Num a => a -> a -> a
+a
y)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
2))


{- |
Square root solver that works on the Schur decomposition.

Schur decomposition enables computing the square root
of (some) singular matrices like @((1,0),(0,0))@.
However, the Schur decomposition might emit small negative values
on the diagonal, where exact computation would yield zeros.
This would let the square root solver fail.
And there are singular matrices that have no square root, at all,
e.g. @((0,1),(0,0))@.

The solver is restricted to a real triangular Schur matrix.
The check for non-real eigenvalues may exclude matrices
that actually have a real-valued square root.
E.g. @sqrt ((0,-2),(2,0)) = ((1,-1),(1,-1))@

In the future we might fix this
by solving 2x2 blocks at the diagonal using 'sqrt2'.
-}
sqrtSchur :: (Shape.C sh, Class.Real a) => Square sh a -> Square sh a
sqrtSchur :: Square sh a -> Square sh a
sqrtSchur = (Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a)
-> Square sh a -> Square sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
  -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a)
 -> Square sh a -> Square sh a)
-> (Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
    -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a)
-> Square sh a
-> Square sh a
forall a b. (a -> b) -> a -> b
$ (Quadratic
   Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
 -> Quadratic
      Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a)
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (IntIndexed sh) a
 -> Quadratic pack prop lower upper (IntIndexed sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyPermutable ((Quadratic
    Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
  -> Quadratic
       Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a)
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a)
-> (Quadratic
      Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
    -> Quadratic
         Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a)
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ \Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
a ->
   let (Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
q,QuasiUpper (IntIndexed (Unchecked sh)) a
u) = Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
-> (Quadratic
      Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a,
    QuasiUpper (IntIndexed (Unchecked sh)) a)
forall sh a.
(Permutable sh, Floating a) =>
Square sh a -> (Square sh a, QuasiUpper sh a)
Square.schur (Quadratic
   Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
 -> (Quadratic
       Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a,
     QuasiUpper (IntIndexed (Unchecked sh)) a))
-> Quadratic
     Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
-> (Quadratic
      Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a,
    QuasiUpper (IntIndexed (Unchecked sh)) a)
forall a b. (a -> b) -> a -> b
$ Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
-> Quadratic
     Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
forall sh a pack prop lower upper.
(Indexed sh, Floating a) =>
Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
checkZeroOffDiagonal Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
a
   in Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
q Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
-> Quadratic
     Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
-> Quadratic
     Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
forall a. Semigroup a => a -> a -> a
<> (a -> a)
-> FlexUpperP Packed Arbitrary (IntIndexed (Unchecked sh)) a
-> FlexUpperP Packed Arbitrary (IntIndexed (Unchecked sh)) a
forall pack diag sh a.
(Packing pack, TriDiag diag, C sh, Floating a) =>
(a -> a) -> FlexUpperP pack diag sh a -> FlexUpperP pack diag sh a
sqrtUpper a -> a
forall a. Floating a => a -> a
P.sqrt (QuasiUpper (IntIndexed (Unchecked sh)) a
-> FlexUpperP Packed Arbitrary (IntIndexed (Unchecked sh)) a
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 QuasiUpper (IntIndexed (Unchecked sh)) a
u) FlexUpperP Packed Arbitrary (IntIndexed (Unchecked sh)) a
-> Quadratic
     Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
-> Quadratic
     Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
forall typ xl xu lowerA upperA lowerB upperB lowerC upperC measA
       measB measC vert horiz height fuse width a.
(MultiplySquare typ xl xu, ToQuadratic typ, Strip lowerA,
 Strip upperA, Strip lowerB, Strip upperB, Strip lowerC,
 Strip upperC, MultipliedBands lowerA lowerB ~ lowerC,
 MultipliedBands lowerB lowerA ~ lowerC,
 MultipliedBands upperA upperB ~ upperC,
 MultipliedBands upperB upperA ~ upperC, Measure measA,
 Measure measB, Measure measC, MultiplyMeasure measA measB ~ measC,
 C vert, C horiz, C height, C fuse, Eq fuse, C width, Floating a) =>
QuadraticMeas typ xl xu lowerA upperA measA height fuse a
-> Unpacked lowerB upperB measB vert horiz fuse width a
-> Unpacked lowerC upperC measC vert horiz height width a
#*## Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
-> Quadratic
     Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
forall sh a. (C sh, Floating a) => Square sh a -> Square sh a
Square.adjoint Quadratic
  Unpacked Arbitrary Filled Filled (IntIndexed (Unchecked sh)) a
q

checkZeroOffDiagonal ::
   (Shape.Indexed sh, Class.Floating a) =>
   Quadratic pack prop lower upper sh a ->
   Quadratic pack prop lower upper sh a
checkZeroOffDiagonal :: Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
checkZeroOffDiagonal Quadratic pack prop lower upper sh a
a =
   if ((Index sh, Index sh) -> Bool) -> [(Index sh, Index sh)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\(Index sh, Index sh)
ij -> a -> Bool
forall a. Floating a => a -> Bool
Scalar.isZero (Quadratic pack prop lower upper sh a
aQuadratic pack prop lower upper sh a -> (Index sh, Index sh) -> a
forall typ meas vert horiz height width a xl xu lower upper.
(Indexed typ, Measure meas, C vert, C horiz, Indexed height,
 Indexed width, Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> (Index height, Index width) -> a
#!(Index sh, Index sh)
ij)) ([(Index sh, Index sh)] -> Bool) -> [(Index sh, Index sh)] -> Bool
forall a b. (a -> b) -> a -> b
$
      (Index sh -> Index sh -> (Index sh, Index sh))
-> [Index sh] -> [(Index sh, Index sh)]
forall a b. (a -> a -> b) -> [a] -> [b]
ListHT.mapAdjacent ((Index sh -> Index sh -> (Index sh, Index sh))
-> Index sh -> Index sh -> (Index sh, Index sh)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,)) ([Index sh] -> [(Index sh, Index sh)])
-> [Index sh] -> [(Index sh, Index sh)]
forall a b. (a -> b) -> a -> b
$ sh -> [Index sh]
forall sh. Indexed sh => sh -> [Index sh]
Shape.indices (sh -> [Index sh]) -> sh -> [Index sh]
forall a b. (a -> b) -> a -> b
$ Quadratic pack prop lower upper sh a -> sh
forall pack property lower upper sh a.
Quadratic pack property lower upper sh a -> sh
Quad.size Quadratic pack prop lower upper sh a
a
      then Quadratic pack prop lower upper sh a
a
      else [Char] -> Quadratic pack prop lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"sqrtSchur: non-real eigenvalues"

{- |
Iterative square root solver, similar to Newton iteration.

Eigenvalues must all be positive,
otherwise, the iteration might loop forever,
or if an eigenvalue is zero, the computation of matrix inverse will fail.
-}
sqrtDenmanBeavers ::
   (ArrMatrix.Homogeneous prop, ArrMatrix.Additive prop) =>
   (Layout.Packing pack, Omni.PowerStrip lower, Omni.PowerStrip upper) =>
   (Shape.C sh, Class.Floating a, Scalar.RealOf a ~ ar, Class.Real ar) =>
   Quadratic pack prop lower upper sh a ->
   Quadratic pack prop lower upper sh a
sqrtDenmanBeavers :: Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
sqrtDenmanBeavers = (Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic pack prop lower upper (Unchecked sh) a
  -> Quadratic pack prop lower upper (Unchecked sh) a)
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> (Quadratic pack prop lower upper (Unchecked sh) a
    -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall a b. (a -> b) -> a -> b
$ \Quadratic pack prop lower upper (Unchecked sh) a
a ->
   ar
-> Stream (Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper (Unchecked sh) a
forall meas vert horiz height width a ar pack prop lower upper
       (m :: * -> *).
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Eq width, Floating a, RealOf a ~ ar, Real ar,
 ArrayMatrix pack prop lower upper meas vert horiz height width
 ~ m) =>
ar -> Stream (m a) -> m a
limit (Float -> Double -> ar
forall a. Real a => Float -> Double -> a
Scalar.selectReal Float
1e-6 Double
1e-14) (Stream (Quadratic pack prop lower upper (Unchecked sh) a)
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Stream (Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ ((Quadratic pack prop lower upper (Unchecked sh) a,
  Quadratic pack prop lower upper (Unchecked sh) a)
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Stream
     (Quadratic pack prop lower upper (Unchecked sh) a,
      Quadratic pack prop lower upper (Unchecked sh) a)
-> Stream (Quadratic pack prop lower upper (Unchecked sh) a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Quadratic pack prop lower upper (Unchecked sh) a,
 Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper (Unchecked sh) a
forall a b. (a, b) -> a
fst (Stream
   (Quadratic pack prop lower upper (Unchecked sh) a,
    Quadratic pack prop lower upper (Unchecked sh) a)
 -> Stream (Quadratic pack prop lower upper (Unchecked sh) a))
-> Stream
     (Quadratic pack prop lower upper (Unchecked sh) a,
      Quadratic pack prop lower upper (Unchecked sh) a)
-> Stream (Quadratic pack prop lower upper (Unchecked sh) a)
forall a b. (a -> b) -> a -> b
$
   ((Quadratic pack prop lower upper (Unchecked sh) a,
  Quadratic pack prop lower upper (Unchecked sh) a)
 -> (Quadratic pack prop lower upper (Unchecked sh) a,
     Quadratic pack prop lower upper (Unchecked sh) a))
-> (Quadratic pack prop lower upper (Unchecked sh) a,
    Quadratic pack prop lower upper (Unchecked sh) a)
-> Stream
     (Quadratic pack prop lower upper (Unchecked sh) a,
      Quadratic pack prop lower upper (Unchecked sh) a)
forall a. (a -> a) -> a -> Stream a
Stream.iterate
      (\(Quadratic pack prop lower upper (Unchecked sh) a
b,Quadratic pack prop lower upper (Unchecked sh) a
c) ->
         (RealOf a
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
RealOf a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
Matrix.scaleReal RealOf a
0.5 (Quadratic pack prop lower upper (Unchecked sh) a
b Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Additive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
#+# Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall typ xl xu lower upper meas height width a.
(Inverse typ xl xu, PowerStrip lower, PowerStrip upper,
 Measure meas, C height, C width, Floating a) =>
QuadraticMeas typ xl xu lower upper meas height width a
-> QuadraticMeas typ xl xu lower upper meas width height a
Matrix.inverse Quadratic pack prop lower upper (Unchecked sh) a
c),
          RealOf a
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
RealOf a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
Matrix.scaleReal RealOf a
0.5 (Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall typ xl xu lower upper meas height width a.
(Inverse typ xl xu, PowerStrip lower, PowerStrip upper,
 Measure meas, C height, C width, Floating a) =>
QuadraticMeas typ xl xu lower upper meas height width a
-> QuadraticMeas typ xl xu lower upper meas width height a
Matrix.inverse Quadratic pack prop lower upper (Unchecked sh) a
b Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Additive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
#+# Quadratic pack prop lower upper (Unchecked sh) a
c)))
      (Quadratic pack prop lower upper (Unchecked sh) a
a, Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall typ sh a xl xu lower upper.
(SquareShape typ, C sh, Floating a) =>
Quadratic typ xl xu lower upper sh a
-> Quadratic typ xl xu lower upper sh a
Matrix.identityFrom Quadratic pack prop lower upper (Unchecked sh) a
a)

limit ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Eq width,
    Class.Floating a, Scalar.RealOf a ~ ar, Class.Real ar,
    ArrMatrix.ArrayMatrix
      pack prop lower upper meas vert horiz height width ~ m) =>
   ar -> Stream (m a) -> m a
limit :: ar -> Stream (m a) -> m a
limit ar
eps =
   OmniArray pack prop lower upper meas vert horiz height width a
-> Matrix
     (Array pack prop) () () lower upper meas vert horiz height width a
forall pack prop lower upper meas vert horiz height width a.
OmniArray pack prop lower upper meas vert horiz height width a
-> Matrix
     (Array pack prop) () () lower upper meas vert horiz height width a
ArrMatrix.Array (OmniArray pack prop lower upper meas vert horiz height width a
 -> Matrix
      (Array pack prop) () () lower upper meas vert horiz height width a)
-> (Stream
      (Matrix
         (Array pack prop) () () lower upper meas vert horiz height width a)
    -> OmniArray pack prop lower upper meas vert horiz height width a)
-> Stream
     (Matrix
        (Array pack prop) () () lower upper meas vert horiz height width a)
-> Matrix
     (Array pack prop) () () lower upper meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OmniArray pack prop lower upper meas vert horiz height width a,
 OmniArray pack prop lower upper meas vert horiz height width a)
-> OmniArray pack prop lower upper meas vert horiz height width a
forall a b. (a, b) -> b
snd ((OmniArray pack prop lower upper meas vert horiz height width a,
  OmniArray pack prop lower upper meas vert horiz height width a)
 -> OmniArray pack prop lower upper meas vert horiz height width a)
-> (Stream
      (Matrix
         (Array pack prop) () () lower upper meas vert horiz height width a)
    -> (OmniArray pack prop lower upper meas vert horiz height width a,
        OmniArray pack prop lower upper meas vert horiz height width a))
-> Stream
     (Matrix
        (Array pack prop) () () lower upper meas vert horiz height width a)
-> OmniArray pack prop lower upper meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stream
  (OmniArray pack prop lower upper meas vert horiz height width a,
   OmniArray pack prop lower upper meas vert horiz height width a)
-> (OmniArray pack prop lower upper meas vert horiz height width a,
    OmniArray pack prop lower upper meas vert horiz height width a)
forall a. Stream a -> a
Stream.head (Stream
   (OmniArray pack prop lower upper meas vert horiz height width a,
    OmniArray pack prop lower upper meas vert horiz height width a)
 -> (OmniArray pack prop lower upper meas vert horiz height width a,
     OmniArray pack prop lower upper meas vert horiz height width a))
-> (Stream
      (Matrix
         (Array pack prop) () () lower upper meas vert horiz height width a)
    -> Stream
         (OmniArray pack prop lower upper meas vert horiz height width a,
          OmniArray pack prop lower upper meas vert horiz height width a))
-> Stream
     (Matrix
        (Array pack prop) () () lower upper meas vert horiz height width a)
-> (OmniArray pack prop lower upper meas vert horiz height width a,
    OmniArray pack prop lower upper meas vert horiz height width a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   ((OmniArray pack prop lower upper meas vert horiz height width a,
  OmniArray pack prop lower upper meas vert horiz height width a)
 -> Bool)
-> Stream
     (OmniArray pack prop lower upper meas vert horiz height width a,
      OmniArray pack prop lower upper meas vert horiz height width a)
-> Stream
     (OmniArray pack prop lower upper meas vert horiz height width a,
      OmniArray pack prop lower upper meas vert horiz height width a)
forall a. (a -> Bool) -> Stream a -> Stream a
Stream.dropWhile
      (\(OmniArray pack prop lower upper meas vert horiz height width a
b0,OmniArray pack prop lower upper meas vert horiz height width a
b1) ->
         OmniArray pack prop lower upper meas vert horiz height width a
-> RealOf a
forall sh a. (C sh, Floating a) => Vector sh a -> RealOf a
Vector.normInf (OmniArray pack prop lower upper meas vert horiz height width a
b0OmniArray pack prop lower upper meas vert horiz height width a
-> OmniArray pack prop lower upper meas vert horiz height width a
-> OmniArray pack prop lower upper meas vert horiz height width a
forall sh a.
(C sh, Eq sh, Floating a) =>
Vector sh a -> Vector sh a -> Vector sh a
|-|OmniArray pack prop lower upper meas vert horiz height width a
b1) ar -> ar -> Bool
forall a. Ord a => a -> a -> Bool
> ar
0.5ar -> ar -> ar
forall a. Num a => a -> a -> a
*ar
eps ar -> ar -> ar
forall a. Num a => a -> a -> a
* OmniArray pack prop lower upper meas vert horiz height width a
-> RealOf a
forall sh a. (C sh, Floating a) => Vector sh a -> RealOf a
Vector.normInf (OmniArray pack prop lower upper meas vert horiz height width a
b0OmniArray pack prop lower upper meas vert horiz height width a
-> OmniArray pack prop lower upper meas vert horiz height width a
-> OmniArray pack prop lower upper meas vert horiz height width a
forall sh a.
(C sh, Eq sh, Floating a) =>
Vector sh a -> Vector sh a -> Vector sh a
|+|OmniArray pack prop lower upper meas vert horiz height width a
b1)) (Stream
   (OmniArray pack prop lower upper meas vert horiz height width a,
    OmniArray pack prop lower upper meas vert horiz height width a)
 -> Stream
      (OmniArray pack prop lower upper meas vert horiz height width a,
       OmniArray pack prop lower upper meas vert horiz height width a))
-> (Stream
      (Matrix
         (Array pack prop) () () lower upper meas vert horiz height width a)
    -> Stream
         (OmniArray pack prop lower upper meas vert horiz height width a,
          OmniArray pack prop lower upper meas vert horiz height width a))
-> Stream
     (Matrix
        (Array pack prop) () () lower upper meas vert horiz height width a)
-> Stream
     (OmniArray pack prop lower upper meas vert horiz height width a,
      OmniArray pack prop lower upper meas vert horiz height width a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   (OmniArray pack prop lower upper meas vert horiz height width a
 -> OmniArray pack prop lower upper meas vert horiz height width a
 -> (OmniArray pack prop lower upper meas vert horiz height width a,
     OmniArray pack prop lower upper meas vert horiz height width a))
-> Stream
     (OmniArray pack prop lower upper meas vert horiz height width a)
-> Stream
     (OmniArray pack prop lower upper meas vert horiz height width a,
      OmniArray pack prop lower upper meas vert horiz height width a)
forall a b. (a -> a -> b) -> Stream a -> Stream b
streamMapAdjacent (,) (Stream
   (OmniArray pack prop lower upper meas vert horiz height width a)
 -> Stream
      (OmniArray pack prop lower upper meas vert horiz height width a,
       OmniArray pack prop lower upper meas vert horiz height width a))
-> (Stream
      (Matrix
         (Array pack prop) () () lower upper meas vert horiz height width a)
    -> Stream
         (OmniArray pack prop lower upper meas vert horiz height width a))
-> Stream
     (Matrix
        (Array pack prop) () () lower upper meas vert horiz height width a)
-> Stream
     (OmniArray pack prop lower upper meas vert horiz height width a,
      OmniArray pack prop lower upper meas vert horiz height width a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Matrix
   (Array pack prop) () () lower upper meas vert horiz height width a
 -> OmniArray pack prop lower upper meas vert horiz height width a)
-> Stream
     (Matrix
        (Array pack prop) () () lower upper meas vert horiz height width a)
-> Stream
     (OmniArray pack prop lower upper meas vert horiz height width a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Matrix
  (Array pack prop) () () lower upper meas vert horiz height width a
-> OmniArray pack prop lower upper meas vert horiz height width a
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> OmniArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.unwrap

streamMapAdjacent :: (a -> a -> b) -> Stream a -> Stream b
streamMapAdjacent :: (a -> a -> b) -> Stream a -> Stream b
streamMapAdjacent a -> a -> b
f Stream a
xs = (a -> a -> b) -> Stream a -> Stream a -> Stream b
forall a b c. (a -> b -> c) -> Stream a -> Stream b -> Stream c
Stream.zipWith a -> a -> b
f Stream a
xs (Stream a -> Stream a
forall a. Stream a -> Stream a
Stream.tail Stream a
xs)


class (MatrixShape.Property property) => Exp property where
   exp ::
      (Layout.Packing pack,
       MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
       Shape.C sh, Class.Floating a) =>
      Quadratic pack property lower upper sh a ->
      Quadratic pack property lower upper sh a

instance Exp Omni.Arbitrary where
   exp :: Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
exp Quadratic pack Arbitrary lower upper sh a
a =
      case Omni pack Arbitrary lower upper Shape Small Small sh sh
-> Power pack Arbitrary lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni pack Arbitrary lower upper Shape Small Small sh sh
 -> Power pack Arbitrary lower upper Shape Small Small sh sh)
-> Omni pack Arbitrary lower upper Shape Small Small sh sh
-> Power pack Arbitrary lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper sh a
-> Omni pack Arbitrary lower upper 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 Quadratic pack Arbitrary lower upper sh a
a of
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerDiagonal ->
            case Quadratic pack Arbitrary lower upper sh a -> ComplexSingleton a
forall a (f :: * -> *). Floating a => f a -> ComplexSingleton a
Scalar.complexSingletonOfFunctor Quadratic pack Arbitrary lower upper sh a
a of
               ComplexSingleton a
Scalar.Real -> (a -> a)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh a
forall pack sh a b.
(Packing pack, C sh, Floating a, Floating b) =>
(a -> b)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh b
liftDiagonal a -> a
forall a. Floating a => a -> a
P.exp Quadratic pack Arbitrary lower upper sh a
Quadratic pack Arbitrary Empty Empty sh a
a
               ComplexSingleton a
Scalar.Complex -> (a -> a)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh a
forall pack sh a b.
(Packing pack, C sh, Floating a, Floating b) =>
(a -> b)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh b
liftDiagonal a -> a
forall a. Floating a => a -> a
P.exp Quadratic pack Arbitrary lower upper sh a
Quadratic pack Arbitrary Empty Empty sh a
a
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerFull ->
            case Quadratic pack Arbitrary lower upper sh a -> ComplexSingleton a
forall a (f :: * -> *). Floating a => f a -> ComplexSingleton a
Scalar.complexSingletonOfFunctor Quadratic pack Arbitrary lower upper sh a
a of
               ComplexSingleton a
Scalar.Real ->
                  (FullArray Shape Small Small sh sh a
 -> FullArray Shape Small Small sh sh a)
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
-> UnpackedMatrix Arbitrary lower upper Shape Small Small sh sh a
forall propertyA lowerA upperA propertyB lowerB upperB measA vertA
       horizA heightA widthA a measB vertB horizB heightB widthB b.
(Property propertyA, Strip lowerA, Strip upperA,
 Property propertyB, Strip lowerB, Strip upperB) =>
(FullArray measA vertA horizA heightA widthA a
 -> FullArray measB vertB horizB heightB widthB b)
-> UnpackedMatrix
     propertyA lowerA upperA measA vertA horizA heightA widthA a
-> UnpackedMatrix
     propertyB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.liftUnpacked1 FullArray Shape Small Small sh sh a
-> FullArray Shape Small Small sh sh a
forall a. a -> a
id (UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
 -> UnpackedMatrix Arbitrary lower upper Shape Small Small sh sh a)
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
-> UnpackedMatrix Arbitrary lower upper Shape Small Small sh sh a
forall a b. (a -> b) -> a -> b
$
                  (Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a)
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a)
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Subtractive prop, Packing pack,
 PowerStrip lower, PowerStrip upper, C sh, Eq sh, Floating a,
 RealOf a ~ ar, Real ar) =>
(Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
expScaledPade Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
forall typ xl xu lower upper height width nrhs measA measB measC
       vert horiz a.
(Solve typ xl xu, ToQuadratic typ, Strip lower, Strip upper,
 C height, Eq height, C width, C nrhs, Measure measA, Measure measB,
 Measure measC, MultiplyMeasure measA measB ~ measC, C vert,
 C horiz, Floating a) =>
QuadraticMeas typ xl xu lower upper measA height width a
-> Full measB vert horiz height nrhs a
-> Full measC vert horiz width nrhs a
(#\##)) (UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
 -> UnpackedMatrix
      Arbitrary Filled Filled Shape Small Small sh sh a)
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper sh a
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
forall meas vert horiz height width a pack property lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
Matrix.toFull Quadratic pack Arbitrary lower upper sh a
a
               ComplexSingleton a
Scalar.Complex ->
                  (FullArray Shape Small Small sh sh a
 -> FullArray Shape Small Small sh sh a)
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
-> UnpackedMatrix Arbitrary lower upper Shape Small Small sh sh a
forall propertyA lowerA upperA propertyB lowerB upperB measA vertA
       horizA heightA widthA a measB vertB horizB heightB widthB b.
(Property propertyA, Strip lowerA, Strip upperA,
 Property propertyB, Strip lowerB, Strip upperB) =>
(FullArray measA vertA horizA heightA widthA a
 -> FullArray measB vertB horizB heightB widthB b)
-> UnpackedMatrix
     propertyA lowerA upperA measA vertA horizA heightA widthA a
-> UnpackedMatrix
     propertyB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.liftUnpacked1 FullArray Shape Small Small sh sh a
-> FullArray Shape Small Small sh sh a
forall a. a -> a
id (UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
 -> UnpackedMatrix Arbitrary lower upper Shape Small Small sh sh a)
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
-> UnpackedMatrix Arbitrary lower upper Shape Small Small sh sh a
forall a b. (a -> b) -> a -> b
$
                  (Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a)
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
 -> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a)
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Subtractive prop, Packing pack,
 PowerStrip lower, PowerStrip upper, C sh, Eq sh, Floating a,
 RealOf a ~ ar, Real ar) =>
(Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
expScaledPade Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
-> Quadratic Unpacked Arbitrary Filled Filled (Unchecked sh) a
forall typ xl xu lower upper height width nrhs measA measB measC
       vert horiz a.
(Solve typ xl xu, ToQuadratic typ, Strip lower, Strip upper,
 C height, Eq height, C width, C nrhs, Measure measA, Measure measB,
 Measure measC, MultiplyMeasure measA measB ~ measC, C vert,
 C horiz, Floating a) =>
QuadraticMeas typ xl xu lower upper measA height width a
-> Full measB vert horiz height nrhs a
-> Full measC vert horiz width nrhs a
(#\##)) (UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
 -> UnpackedMatrix
      Arbitrary Filled Filled Shape Small Small sh sh a)
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper sh a
-> UnpackedMatrix Arbitrary Filled Filled Shape Small Small sh sh a
forall meas vert horiz height width a pack property lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
Matrix.toFull Quadratic pack Arbitrary lower upper sh a
a
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerUpperTriangular ->
            case Quadratic pack Arbitrary lower upper sh a -> ComplexSingleton a
forall a (f :: * -> *). Floating a => f a -> ComplexSingleton a
Scalar.complexSingletonOfFunctor Quadratic pack Arbitrary lower upper sh a
a of
               ComplexSingleton a
Scalar.Real    -> (Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
 -> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a)
-> Quadratic pack Arbitrary Empty Filled sh a
-> Quadratic pack Arbitrary Empty Filled sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
 -> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
 -> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a)
-> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
-> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Subtractive prop, Packing pack,
 PowerStrip lower, PowerStrip upper, C sh, Eq sh, Floating a,
 RealOf a ~ ar, Real ar) =>
(Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
expScaledPade Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
-> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
-> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
forall pack sh a.
(Packing pack, C sh, Eq sh, Floating a) =>
UpperP pack sh a -> UpperP pack sh a -> UpperP pack sh a
solveUpper) Quadratic pack Arbitrary lower upper sh a
Quadratic pack Arbitrary Empty Filled sh a
a
               ComplexSingleton a
Scalar.Complex -> (Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
 -> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a)
-> Quadratic pack Arbitrary Empty Filled sh a
-> Quadratic pack Arbitrary Empty Filled sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
 -> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
 -> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a)
-> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
-> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Subtractive prop, Packing pack,
 PowerStrip lower, PowerStrip upper, C sh, Eq sh, Floating a,
 RealOf a ~ ar, Real ar) =>
(Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
expScaledPade Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
-> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
-> Quadratic pack Arbitrary Empty Filled (Unchecked sh) a
forall pack sh a.
(Packing pack, C sh, Eq sh, Floating a) =>
UpperP pack sh a -> UpperP pack sh a -> UpperP pack sh a
solveUpper) Quadratic pack Arbitrary lower upper sh a
Quadratic pack Arbitrary Empty Filled sh a
a
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerLowerTriangular ->
            case Quadratic pack Arbitrary lower upper sh a -> ComplexSingleton a
forall a (f :: * -> *). Floating a => f a -> ComplexSingleton a
Scalar.complexSingletonOfFunctor Quadratic pack Arbitrary lower upper sh a
a of
               ComplexSingleton a
Scalar.Real    -> (Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
 -> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a)
-> Quadratic pack Arbitrary Filled Empty sh a
-> Quadratic pack Arbitrary Filled Empty sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
 -> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
 -> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a)
-> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
-> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Subtractive prop, Packing pack,
 PowerStrip lower, PowerStrip upper, C sh, Eq sh, Floating a,
 RealOf a ~ ar, Real ar) =>
(Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
expScaledPade Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
-> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
-> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
forall pack sh a.
(Packing pack, C sh, Eq sh, Floating a) =>
LowerP pack sh a -> LowerP pack sh a -> LowerP pack sh a
solveLower) Quadratic pack Arbitrary lower upper sh a
Quadratic pack Arbitrary Filled Empty sh a
a
               ComplexSingleton a
Scalar.Complex -> (Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
 -> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a)
-> Quadratic pack Arbitrary Filled Empty sh a
-> Quadratic pack Arbitrary Filled Empty sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
 -> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
 -> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a)
-> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
-> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Subtractive prop, Packing pack,
 PowerStrip lower, PowerStrip upper, C sh, Eq sh, Floating a,
 RealOf a ~ ar, Real ar) =>
(Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
expScaledPade Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
-> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
-> Quadratic pack Arbitrary Filled Empty (Unchecked sh) a
forall pack sh a.
(Packing pack, C sh, Eq sh, Floating a) =>
LowerP pack sh a -> LowerP pack sh a -> LowerP pack sh a
solveLower) Quadratic pack Arbitrary lower upper sh a
Quadratic pack Arbitrary Filled Empty sh a
a

solveUpper ::
   (Layout.Packing pack, Shape.C sh, Eq sh, Class.Floating a) =>
   UpperP pack sh a -> UpperP pack sh a -> UpperP pack sh a
solveUpper :: UpperP pack sh a -> UpperP pack sh a -> UpperP pack sh a
solveUpper UpperP pack sh a
d UpperP pack sh a
n =
   Square sh a -> UpperP pack sh a
forall pack mirror uplo meas vert horiz prop lower upper sh a.
(Packing pack, Mirror mirror, UpLo uplo, meas ~ Shape,
 vert ~ Small, horiz ~ Small,
 FromPlain pack prop lower upper meas vert horiz sh sh,
 Plain pack prop lower upper meas vert horiz sh sh
 ~ Mosaic pack mirror uplo sh,
 C sh, Floating a) =>
Square sh a -> Quadratic pack prop lower upper sh a
ArrMosaic.assureMirrored (Square sh a -> UpperP pack sh a)
-> Square sh a -> UpperP pack sh a
forall a b. (a -> b) -> a -> b
$ UpperP pack sh a
d UpperP pack sh a -> Square sh a -> Square sh a
forall typ xl xu lower upper height width nrhs measA measB measC
       vert horiz a.
(Solve typ xl xu, ToQuadratic typ, Strip lower, Strip upper,
 C height, Eq height, C width, C nrhs, Measure measA, Measure measB,
 Measure measC, MultiplyMeasure measA measB ~ measC, C vert,
 C horiz, Floating a) =>
QuadraticMeas typ xl xu lower upper measA height width a
-> Full measB vert horiz height nrhs a
-> Full measC vert horiz width nrhs a
#\## UpperP pack sh a -> Square sh a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a -> Square sh a
Triangular.toSquare UpperP pack sh a
n

solveLower ::
   (Layout.Packing pack, Shape.C sh, Eq sh, Class.Floating a) =>
   LowerP pack sh a -> LowerP pack sh a -> LowerP pack sh a
solveLower :: LowerP pack sh a -> LowerP pack sh a -> LowerP pack sh a
solveLower LowerP pack sh a
d LowerP pack sh a
n =
   Square sh a -> LowerP pack sh a
forall pack mirror uplo meas vert horiz prop lower upper sh a.
(Packing pack, Mirror mirror, UpLo uplo, meas ~ Shape,
 vert ~ Small, horiz ~ Small,
 FromPlain pack prop lower upper meas vert horiz sh sh,
 Plain pack prop lower upper meas vert horiz sh sh
 ~ Mosaic pack mirror uplo sh,
 C sh, Floating a) =>
Square sh a -> Quadratic pack prop lower upper sh a
ArrMosaic.assureMirrored (Square sh a -> LowerP pack sh a)
-> Square sh a -> LowerP pack sh a
forall a b. (a -> b) -> a -> b
$ LowerP pack sh a
d LowerP pack sh a -> Square sh a -> Square sh a
forall typ xl xu lower upper height width nrhs measA measB measC
       vert horiz a.
(Solve typ xl xu, ToQuadratic typ, Strip lower, Strip upper,
 C height, Eq height, C width, C nrhs, Measure measA, Measure measB,
 Measure measC, MultiplyMeasure measA measB ~ measC, C vert,
 C horiz, Floating a) =>
QuadraticMeas typ xl xu lower upper measA height width a
-> Full measB vert horiz height nrhs a
-> Full measC vert horiz width nrhs a
#\## LowerP pack sh a -> Square sh a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a -> Square sh a
Triangular.toSquare LowerP pack sh a
n


instance
   (neg ~ True, zero ~ True, pos ~ True) =>
      Exp (Omni.Hermitian neg zero pos) where
   exp :: Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> Quadratic pack (Hermitian neg zero pos) lower upper sh a
exp Quadratic pack (Hermitian neg zero pos) lower upper sh a
a =
      case Omni
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
-> Power
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni
   pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
 -> Power
      pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh)
-> Omni
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
-> Power
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> Omni
     pack (Hermitian neg zero pos) lower upper 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 Quadratic pack (Hermitian neg zero pos) lower upper sh a
a of
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
Omni.PowerDiagonal ->
            case Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> ComplexSingleton a
forall a (f :: * -> *). Floating a => f a -> ComplexSingleton a
Scalar.complexSingletonOfFunctor Quadratic pack (Hermitian neg zero pos) lower upper sh a
a of
               ComplexSingleton a
Scalar.Real -> (a -> a)
-> Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
-> Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
forall pack neg zero pos herm sh a b.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, Floating b) =>
(a -> b)
-> Quadratic pack herm Empty Empty sh a
-> Quadratic pack herm Empty Empty sh b
liftHermitianDiagonal a -> a
forall a. Floating a => a -> a
P.exp Quadratic pack (Hermitian neg zero pos) lower upper sh a
Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
a
               ComplexSingleton a
Scalar.Complex -> (a -> a)
-> Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
-> Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
forall pack neg zero pos herm sh a b.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, Floating b) =>
(a -> b)
-> Quadratic pack herm Empty Empty sh a
-> Quadratic pack herm Empty Empty sh b
liftHermitianDiagonal a -> a
forall a. Floating a => a -> a
P.exp Quadratic pack (Hermitian neg zero pos) lower upper sh a
Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
a
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
Omni.PowerHermitian ->
            case Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> ComplexSingleton a
forall a (f :: * -> *). Floating a => f a -> ComplexSingleton a
Scalar.complexSingletonOfFunctor Quadratic pack (Hermitian neg zero pos) lower upper sh a
a of
               ComplexSingleton a
Scalar.Real -> (a -> a)
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
forall pack neg zero pos herm sh a ar.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, RealOf a ~ ar, Storable ar) =>
(ar -> ar)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
liftHermitian a -> a
forall a. Floating a => a -> a
P.exp Quadratic pack (Hermitian neg zero pos) lower upper sh a
Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
a
               ComplexSingleton a
Scalar.Complex -> (a -> a)
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
forall pack neg zero pos herm sh a ar.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, RealOf a ~ ar, Storable ar) =>
(ar -> ar)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
liftHermitian a -> a
forall a. Floating a => a -> a
P.exp Quadratic pack (Hermitian neg zero pos) lower upper sh a
Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
a
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
_ -> [Char] -> Quadratic pack (Hermitian neg zero pos) lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"Hermitian.exp: impossible shape"

instance Exp Omni.Symmetric where
   exp :: Quadratic pack Symmetric lower upper sh a
-> Quadratic pack Symmetric lower upper sh a
exp Quadratic pack Symmetric lower upper sh a
a =
      case Omni pack Symmetric lower upper Shape Small Small sh sh
-> Power pack Symmetric lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni pack Symmetric lower upper Shape Small Small sh sh
 -> Power pack Symmetric lower upper Shape Small Small sh sh)
-> Omni pack Symmetric lower upper Shape Small Small sh sh
-> Power pack Symmetric lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack Symmetric lower upper sh a
-> Omni pack Symmetric lower upper 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 Quadratic pack Symmetric lower upper sh a
a of
         Power pack Symmetric lower upper Shape Small Small sh sh
Omni.PowerSymmetric ->
            case Quadratic pack Symmetric lower upper sh a -> ComplexSingleton a
forall a (f :: * -> *). Floating a => f a -> ComplexSingleton a
Scalar.complexSingletonOfFunctor Quadratic pack Symmetric lower upper sh a
a of
               ComplexSingleton a
Scalar.Real ->
                  FlexHermitianP pack True True True sh a -> SymmetricP pack sh a
forall pack neg zero pos sh a.
(Packing pack, C neg, C zero, C pos, C sh, Real a) =>
FlexHermitianP pack neg zero pos sh a -> SymmetricP pack sh a
Symmetric.fromHermitian (FlexHermitianP pack True True True sh a -> SymmetricP pack sh a)
-> (SymmetricP pack sh a
    -> FlexHermitianP pack True True True sh a)
-> SymmetricP pack sh a
-> SymmetricP pack sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a)
-> FlexHermitianP pack True True True sh a
-> FlexHermitianP pack True True True sh a
forall pack neg zero pos herm sh a ar.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, RealOf a ~ ar, Storable ar) =>
(ar -> ar)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
liftHermitian a -> a
forall a. Floating a => a -> a
P.exp (FlexHermitianP pack True True True sh a
 -> FlexHermitianP pack True True True sh a)
-> (SymmetricP pack sh a
    -> FlexHermitianP pack True True True sh a)
-> SymmetricP pack sh a
-> FlexHermitianP pack True True True sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                  SymmetricP pack sh a -> FlexHermitianP pack True True True sh a
forall pack sh a.
(Packing pack, C sh, Real a) =>
SymmetricP pack sh a -> HermitianP pack sh a
Hermitian.fromSymmetric (SymmetricP pack sh a -> SymmetricP pack sh a)
-> SymmetricP pack sh a -> SymmetricP pack sh a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Symmetric lower upper sh a
SymmetricP pack sh a
a
               ComplexSingleton a
Scalar.Complex ->
                  (Quadratic pack Symmetric Filled Filled (Unchecked sh) a
 -> Quadratic pack Symmetric Filled Filled (Unchecked sh) a)
-> SymmetricP pack sh a -> SymmetricP pack sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked
                     ((Quadratic pack Symmetric Filled Filled (Unchecked sh) a
 -> Quadratic pack Symmetric Filled Filled (Unchecked sh) a
 -> Quadratic pack Symmetric Filled Filled (Unchecked sh) a)
-> Quadratic pack Symmetric Filled Filled (Unchecked sh) a
-> Quadratic pack Symmetric Filled Filled (Unchecked sh) a
forall prop pack lower upper sh a ar.
(Homogeneous prop, Subtractive prop, Packing pack,
 PowerStrip lower, PowerStrip upper, C sh, Eq sh, Floating a,
 RealOf a ~ ar, Real ar) =>
(Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
expScaledPade
                        (\Quadratic pack Symmetric Filled Filled (Unchecked sh) a
d Quadratic pack Symmetric Filled Filled (Unchecked sh) a
n ->
                           Square (Unchecked sh) a
-> Quadratic pack Symmetric Filled Filled (Unchecked sh) a
forall pack sh a.
(Packing pack, C sh, Floating a) =>
Square sh a -> SymmetricP pack sh a
Symmetric.assureSymmetry (Square (Unchecked sh) a
 -> Quadratic pack Symmetric Filled Filled (Unchecked sh) a)
-> Square (Unchecked sh) a
-> Quadratic pack Symmetric Filled Filled (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$
                              Quadratic pack Symmetric Filled Filled (Unchecked sh) a
d Quadratic pack Symmetric Filled Filled (Unchecked sh) a
-> Square (Unchecked sh) a -> Square (Unchecked sh) a
forall typ xl xu lower upper height width nrhs measA measB measC
       vert horiz a.
(Solve typ xl xu, ToQuadratic typ, Strip lower, Strip upper,
 C height, Eq height, C width, C nrhs, Measure measA, Measure measB,
 Measure measC, MultiplyMeasure measA measB ~ measC, C vert,
 C horiz, Floating a) =>
QuadraticMeas typ xl xu lower upper measA height width a
-> Full measB vert horiz height nrhs a
-> Full measC vert horiz width nrhs a
#\## Quadratic pack Symmetric Filled Filled (Unchecked sh) a
-> Square (Unchecked sh) a
forall pack sh a.
(Packing pack, C sh, Floating a) =>
SymmetricP pack sh a -> Square sh a
Symmetric.toSquare Quadratic pack Symmetric Filled Filled (Unchecked sh) a
n))
                     Quadratic pack Symmetric lower upper sh a
SymmetricP pack sh a
a
         Power pack Symmetric lower upper Shape Small Small sh sh
_ -> [Char] -> Quadratic pack Symmetric lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"Symmetric.exp: impossible shape"

{-
"Nineteen Dubious Ways to Compute the Exponential of a Matrix,
Twenty-Five Years Later."
by Cleve Moler and Charles Van Loan
11. Matrix Exponential in MATLAB.
-}
expScaledPade ::
   (ArrMatrix.Homogeneous prop, ArrMatrix.Subtractive prop) =>
   (Layout.Packing pack, Omni.PowerStrip lower, Omni.PowerStrip upper) =>
   (Shape.C sh, Eq sh,
    Class.Floating a, Scalar.RealOf a ~ ar, Class.Real ar) =>
   (Quadratic pack prop lower upper sh a ->
    Quadratic pack prop lower upper sh a ->
    Quadratic pack prop lower upper sh a) ->
   Quadratic pack prop lower upper sh a ->
   Quadratic pack prop lower upper sh a
expScaledPade :: (Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
expScaledPade Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
solve Quadratic pack prop lower upper sh a
a0 =
   let s :: Int
s = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
+) (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ ar -> Int
forall a b. (RealFrac a, Integral b) => a -> b
ceiling (ar -> Int) -> ar -> Int
forall a b. (a -> b) -> a -> b
$ ar -> ar -> ar
forall a. Floating a => a -> a -> a
logBase ar
2 (ar -> ar) -> ar -> ar
forall a b. (a -> b) -> a -> b
$ Quadratic pack prop lower upper sh a -> RealOf a
forall meas vert horiz height width a pack prop lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
ArrayMatrix pack prop lower upper meas vert horiz height width a
-> RealOf a
norm1 Quadratic pack prop lower upper sh a
a0
       a :: Quadratic pack prop lower upper sh a
a = RealOf a
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
RealOf a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
Matrix.scaleReal ((ar
1ar -> ar -> ar
forall a. Fractional a => a -> a -> a
/ar
2)ar -> Int -> ar
forall a b. (Num a, Integral b) => a -> b -> a
^Int
s) Quadratic pack prop lower upper sh a
a0
       ([ar]
odds,[ar]
evens) = [ar] -> ([ar], [ar])
forall a. [a] -> ([a], [a])
deinterleave ([ar] -> ([ar], [ar])) -> [ar] -> ([ar], [ar])
forall a b. (a -> b) -> a -> b
$ T [] ar -> [ar]
forall (f :: * -> *) a. T f a -> f a
NonEmpty.tail T [] ar
forall a. Real a => T [] a
expPadeCoefficients
       Stream.Cons Quadratic pack prop lower upper sh a
eye Stream (Quadratic pack prop lower upper sh a)
as = Quadratic pack prop lower upper sh a
-> Stream (Quadratic pack prop lower upper sh a)
forall typ xl xu lower upper sh a.
(Power typ xl xu, SquareShape typ, PowerStrip lower,
 PowerStrip upper, C sh, Floating a) =>
Quadratic typ xl xu lower upper sh a
-> Stream (Quadratic typ xl xu lower upper sh a)
Matrix.powers Quadratic pack prop lower upper sh a
a
       ([Quadratic pack prop lower upper sh a]
oddPowers,[Quadratic pack prop lower upper sh a]
evenPowers) = [Quadratic pack prop lower upper sh a]
-> ([Quadratic pack prop lower upper sh a],
    [Quadratic pack prop lower upper sh a])
forall a. [a] -> ([a], [a])
deinterleave ([Quadratic pack prop lower upper sh a]
 -> ([Quadratic pack prop lower upper sh a],
     [Quadratic pack prop lower upper sh a]))
-> [Quadratic pack prop lower upper sh a]
-> ([Quadratic pack prop lower upper sh a],
    [Quadratic pack prop lower upper sh a])
forall a b. (a -> b) -> a -> b
$ Stream (Quadratic pack prop lower upper sh a)
-> [Quadratic pack prop lower upper sh a]
forall a. Stream a -> [a]
Stream.toList Stream (Quadratic pack prop lower upper sh a)
as
       v :: Quadratic pack prop lower upper sh a
v = (Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> [Quadratic pack prop lower upper sh a]
-> Quadratic pack prop lower upper sh a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Additive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
(#+#) Quadratic pack prop lower upper sh a
eye ([Quadratic pack prop lower upper sh a]
 -> Quadratic pack prop lower upper sh a)
-> [Quadratic pack prop lower upper sh a]
-> Quadratic pack prop lower upper sh a
forall a b. (a -> b) -> a -> b
$ (ar
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> [ar]
-> [Quadratic pack prop lower upper sh a]
-> [Quadratic pack prop lower upper sh a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ar
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
RealOf a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
Matrix.scaleReal [ar]
evens [Quadratic pack prop lower upper sh a]
evenPowers
       u :: Maybe (Quadratic pack prop lower upper sh a)
u =
         (T [] (Quadratic pack prop lower upper sh a)
 -> Quadratic pack prop lower upper sh a)
-> Maybe (T [] (Quadratic pack prop lower upper sh a))
-> Maybe (Quadratic pack prop lower upper sh a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> T [] (Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
forall (f :: * -> *) a. Foldable f => (a -> a -> a) -> T f a -> a
NonEmpty.foldl1 Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Additive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
(#+#)) (Maybe (T [] (Quadratic pack prop lower upper sh a))
 -> Maybe (Quadratic pack prop lower upper sh a))
-> Maybe (T [] (Quadratic pack prop lower upper sh a))
-> Maybe (Quadratic pack prop lower upper sh a)
forall a b. (a -> b) -> a -> b
$ [Quadratic pack prop lower upper sh a]
-> Maybe (T [] (Quadratic pack prop lower upper sh a))
forall (f :: * -> *) a. ViewL f => f a -> Maybe (T f a)
NonEmpty.fetch ([Quadratic pack prop lower upper sh a]
 -> Maybe (T [] (Quadratic pack prop lower upper sh a)))
-> [Quadratic pack prop lower upper sh a]
-> Maybe (T [] (Quadratic pack prop lower upper sh a))
forall a b. (a -> b) -> a -> b
$
         (ar
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> [ar]
-> [Quadratic pack prop lower upper sh a]
-> [Quadratic pack prop lower upper sh a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ar
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
RealOf a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
Matrix.scaleReal [ar]
odds [Quadratic pack prop lower upper sh a]
oddPowers
       op :: t -> (t -> a -> t) -> Maybe a -> t
op t
vm t -> a -> t
f Maybe a
um = t -> (a -> t) -> Maybe a -> t
forall b a. b -> (a -> b) -> Maybe a -> b
maybe t
vm (t -> a -> t
f t
vm) Maybe a
um
   in Int
-> (Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall a. Int -> (a -> a) -> a -> a
nest Int
s Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall typ xl xu lower upper sh a.
(Power typ xl xu, PowerStrip lower, PowerStrip upper, C sh,
 Floating a) =>
Quadratic typ xl xu lower upper sh a
-> Quadratic typ xl xu lower upper sh a
Matrix.square (Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall a b. (a -> b) -> a -> b
$ Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
solve (Quadratic pack prop lower upper sh a
-> (Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper sh a)
-> Maybe (Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
forall t a. t -> (t -> a -> t) -> Maybe a -> t
op Quadratic pack prop lower upper sh a
v Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Subtractive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
(#-#) Maybe (Quadratic pack prop lower upper sh a)
u) (Quadratic pack prop lower upper sh a
-> (Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper sh a)
-> Maybe (Quadratic pack prop lower upper sh a)
-> Quadratic pack prop lower upper sh a
forall t a. t -> (t -> a -> t) -> Maybe a -> t
op Quadratic pack prop lower upper sh a
v Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Additive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
(#+#) Maybe (Quadratic pack prop lower upper sh a)
u)

{-
Move to utility-ht.
Cf. storable-vector, synthesizer-core.
However, they differ in details.
-}
deinterleave :: [a] -> ([a],[a])
deinterleave :: [a] -> ([a], [a])
deinterleave =
   let go :: [a] -> ([a], [a])
go [] = ([],[])
       go (a
x:[a]
xs) = ([a] -> [a]) -> ([a], [a]) -> ([a], [a])
forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:) (([a], [a]) -> ([a], [a])) -> ([a], [a]) -> ([a], [a])
forall a b. (a -> b) -> a -> b
$ ([a], [a]) -> ([a], [a])
forall a b. (a, b) -> (b, a)
swap (([a], [a]) -> ([a], [a])) -> ([a], [a]) -> ([a], [a])
forall a b. (a -> b) -> a -> b
$ [a] -> ([a], [a])
go [a]
xs
   in [a] -> ([a], [a])
forall a. [a] -> ([a], [a])
go

expPadeCoefficients :: (Class.Real a) => NonEmpty.T [] a
expPadeCoefficients :: T [] a
expPadeCoefficients =
   let eps :: a
eps = Float -> Double -> a
forall a. Real a => Float -> Double -> a
Scalar.selectReal Float
1e-8 Double
1e-16
       q :: Int
q = a -> Int
forall a. Real a => a -> Int
expPadeOrder a
eps
       coeff :: Int -> a
coeff Int
k = Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
qInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) a -> a -> a
forall a. Fractional a => a -> a -> a
/ Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
*(Int
2Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
qInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1))
   in (a -> a -> a) -> a -> [a] -> T [] a
forall (f :: * -> *) b a.
Traversable f =>
(b -> a -> b) -> b -> f a -> T f b
NonEmpty.scanl a -> a -> a
forall a. Num a => a -> a -> a
(*) (a
1 a -> a -> a
forall a. a -> a -> a
`asTypeOf` a
eps) ([a] -> T [] a) -> [a] -> T [] a
forall a b. (a -> b) -> a -> b
$ (Int -> a) -> [Int] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map Int -> a
coeff [Int
1..Int
q]

expPadeOrder :: (Class.Real a) => a -> Int
expPadeOrder :: a -> Int
expPadeOrder a
eps =
   let factorials :: [a]
factorials = (a -> a -> a) -> a -> [a] -> [a]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl a -> a -> a
forall a. Num a => a -> a -> a
(*) a
1 ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ (a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a
1a -> a -> a
forall a. Num a => a -> a -> a
+) a
1
   in Int -> Int -> Int
forall a. Num a => a -> a -> a
subtract Int
1 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ [Bool] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([Bool] -> Int) -> [Bool] -> Int
forall a b. (a -> b) -> a -> b
$ (Bool -> Bool) -> [Bool] -> [Bool]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile Bool -> Bool
forall a. a -> a
id ([Bool] -> [Bool]) -> [Bool] -> [Bool]
forall a b. (a -> b) -> a -> b
$
      (a -> a -> a -> Bool) -> [a] -> [a] -> [a] -> [Bool]
forall a b c d. (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3 (\a
num a
den a
twoPower -> a
num a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
dena -> a -> a
forall a. Num a => a -> a -> a
*a
twoPowera -> a -> a
forall a. Num a => a -> a -> a
*a
eps)
         [a]
factorials (Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
ListHT.sieve Int
2 [a]
factorials) ((a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a
2a -> a -> a
forall a. Num a => a -> a -> a
*) a
1)


{- |
Mathematically the name 'expRealSymmetric' would be more common,
but we support definiteness tags only for the 'Hermitian' type.
Formally the result is always positive definite,
but negative eigenvalues easily yield numerically singular matrices as result.
-}
expRealHermitian ::
   (Layout.Packing pack, Shape.C sh, Class.Real a) =>
   HermitianP pack sh a -> HermitianPosSemidefP pack sh a
expRealHermitian :: HermitianP pack sh a -> HermitianPosSemidefP pack sh a
expRealHermitian =
   AnyHermitianP pack False False True Filled sh a
-> HermitianPosSemidefP pack sh a
forall neg zero pos pack bands sh a.
(C neg, C zero, C pos) =>
AnyHermitianP pack neg False pos bands sh a
-> AnyHermitianP pack neg zero pos bands sh a
Hermitian.relaxSemidefinite (AnyHermitianP pack False False True Filled sh a
 -> HermitianPosSemidefP pack sh a)
-> (HermitianP pack sh a
    -> AnyHermitianP pack False False True Filled sh a)
-> HermitianP pack sh a
-> HermitianPosSemidefP pack sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   HermitianP pack sh a
-> AnyHermitianP pack False False True Filled sh a
forall neg zero pos pack bands sh a.
(C neg, C zero, C pos) =>
AnyHermitianP pack neg zero pos bands sh a
-> Quadratic pack HermitianPositiveDefinite bands bands sh a
Hermitian.assurePositiveDefiniteness (HermitianP pack sh a
 -> AnyHermitianP pack False False True Filled sh a)
-> (HermitianP pack sh a -> HermitianP pack sh a)
-> HermitianP pack sh a
-> AnyHermitianP pack False False True Filled sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   HermitianP pack sh a -> HermitianP pack sh a
forall property pack lower upper sh a.
(Exp property, Packing pack, PowerStrip lower, PowerStrip upper,
 C sh, Floating a) =>
Quadratic pack property lower upper sh a
-> Quadratic pack property lower upper sh a
exp


class (MatrixShape.Property property) => Log property where
   log ::
      (Layout.Packing pack,
       MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
       Shape.C sh, Class.Real a) =>
      Quadratic pack property lower upper sh a ->
      Quadratic pack property lower upper sh a

instance Log Omni.Arbitrary where
   log :: Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
log = (a -> a)
-> Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
forall property pack lower upper sh a.
(LiftReal property, Packing pack, PowerStrip lower,
 PowerStrip upper, C sh, Real a) =>
(a -> a)
-> Quadratic pack property lower upper sh a
-> Quadratic pack property lower upper sh a
liftReal a -> a
forall a. Floating a => a -> a
P.log

instance
   (neg ~ True, zero ~ True, pos ~ True) =>
      Log (Omni.Hermitian neg zero pos) where
   log :: Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> Quadratic pack (Hermitian neg zero pos) lower upper sh a
log = (a -> a)
-> Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> Quadratic pack (Hermitian neg zero pos) lower upper sh a
forall property pack lower upper sh a.
(LiftReal property, Packing pack, PowerStrip lower,
 PowerStrip upper, C sh, Real a) =>
(a -> a)
-> Quadratic pack property lower upper sh a
-> Quadratic pack property lower upper sh a
liftReal a -> a
forall a. Floating a => a -> a
P.log

instance Log Omni.Symmetric where
   log :: Quadratic pack Symmetric lower upper sh a
-> Quadratic pack Symmetric lower upper sh a
log = (a -> a)
-> Quadratic pack Symmetric lower upper sh a
-> Quadratic pack Symmetric lower upper sh a
forall property pack lower upper sh a.
(LiftReal property, Packing pack, PowerStrip lower,
 PowerStrip upper, C sh, Real a) =>
(a -> a)
-> Quadratic pack property lower upper sh a
-> Quadratic pack property lower upper sh a
liftReal a -> a
forall a. Floating a => a -> a
P.log


logUnipotentUpper ::
   (Layout.Packing pack, Shape.C sh, Class.Floating a) =>
   UnitUpperP pack sh a -> UpperP pack sh a
logUnipotentUpper :: UnitUpperP pack sh a -> UpperP pack sh a
logUnipotentUpper = UpperP pack sh a -> UpperP pack sh a
forall pack lower upper prop sh a.
(Packing pack, PowerStrip lower, PowerStrip upper, Scale prop,
 Subtractive prop, C sh, Floating a) =>
Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
logUnipotent (UpperP pack sh a -> UpperP pack sh a)
-> (UnitUpperP pack sh a -> UpperP pack sh a)
-> UnitUpperP pack sh a
-> UpperP pack sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnitUpperP pack sh a -> UpperP pack sh a
forall diag pack lo up sh a.
TriDiag diag =>
TriangularP pack lo Unit up sh a
-> TriangularP pack lo diag up sh a
Triangular.relaxUnitDiagonal

{- |
Logarithm for unipotent matrices.
It is an unchecked error, if the matrix is not unipotent.
-}
logUnipotent ::
   (Layout.Packing pack, Omni.PowerStrip lower, Omni.PowerStrip upper) =>
   (ArrMatrix.Scale prop, ArrMatrix.Subtractive prop) =>
   (Shape.C sh, Class.Floating a) =>
   Quadratic pack prop lower upper sh a ->
   Quadratic pack prop lower upper sh a
logUnipotent :: Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
logUnipotent Quadratic pack prop lower upper sh a
a =
   case Quadratic pack prop lower upper sh a -> ComplexSingleton a
forall a (f :: * -> *). Floating a => f a -> ComplexSingleton a
Scalar.complexSingletonOfFunctor Quadratic pack prop lower upper sh a
a of
      ComplexSingleton a
Scalar.Real    -> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall pack lower upper prop sh a ar.
(Packing pack, PowerStrip lower, PowerStrip upper, Scale prop,
 Subtractive prop, C sh, Floating a, RealOf a ~ ar, Real ar) =>
Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
logUnipotentAux Quadratic pack prop lower upper sh a
a
      ComplexSingleton a
Scalar.Complex -> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall pack lower upper prop sh a ar.
(Packing pack, PowerStrip lower, PowerStrip upper, Scale prop,
 Subtractive prop, C sh, Floating a, RealOf a ~ ar, Real ar) =>
Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
logUnipotentAux Quadratic pack prop lower upper sh a
a

-- cf. numeric-prelude:PowerSeries
logUnipotentAux ::
   (Layout.Packing pack, Omni.PowerStrip lower, Omni.PowerStrip upper) =>
   (ArrMatrix.Scale prop, ArrMatrix.Subtractive prop) =>
   (Shape.C sh, Class.Floating a, Scalar.RealOf a ~ ar, Class.Real ar) =>
   Quadratic pack prop lower upper sh a ->
   Quadratic pack prop lower upper sh a
logUnipotentAux :: Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
logUnipotentAux = (Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic pack prop lower upper (Unchecked sh) a
  -> Quadratic pack prop lower upper (Unchecked sh) a)
 -> Quadratic pack prop lower upper sh a
 -> Quadratic pack prop lower upper sh a)
-> (Quadratic pack prop lower upper (Unchecked sh) a
    -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall a b. (a -> b) -> a -> b
$ \Quadratic pack prop lower upper (Unchecked sh) a
a ->
   let b :: Quadratic pack prop lower upper (Unchecked sh) a
b = Quadratic pack prop lower upper (Unchecked sh) a
a Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Subtractive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
#-# Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall typ sh a xl xu lower upper.
(SquareShape typ, C sh, Floating a) =>
Quadratic typ xl xu lower upper sh a
-> Quadratic typ xl xu lower upper sh a
Matrix.identityFrom Quadratic pack prop lower upper (Unchecked sh) a
a
   in (Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper (Unchecked sh) a
-> [Quadratic pack prop lower upper (Unchecked sh) a]
-> Quadratic pack prop lower upper (Unchecked sh) a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Additive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
(#+#) (Omni
  pack
  prop
  lower
  upper
  Shape
  Small
  Small
  (Unchecked sh)
  (Unchecked sh)
-> Quadratic pack prop lower upper (Unchecked sh) a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
Omni pack property lower upper meas vert horiz height width
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
ArrMatrix.zero (Omni
   pack
   prop
   lower
   upper
   Shape
   Small
   Small
   (Unchecked sh)
   (Unchecked sh)
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Omni
     pack
     prop
     lower
     upper
     Shape
     Small
     Small
     (Unchecked sh)
     (Unchecked sh)
-> Quadratic pack prop lower upper (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ Quadratic pack prop lower upper (Unchecked sh) a
-> Omni
     pack
     prop
     lower
     upper
     Shape
     Small
     Small
     (Unchecked sh)
     (Unchecked 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 Quadratic pack prop lower upper (Unchecked sh) a
b) ([Quadratic pack prop lower upper (Unchecked sh) a]
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> [Quadratic pack prop lower upper (Unchecked sh) a]
-> Quadratic pack prop lower upper (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$
      (a
 -> Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> [a]
-> [Quadratic pack prop lower upper (Unchecked sh) a]
-> [Quadratic pack prop lower upper (Unchecked sh) a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Scale property, C height, C width,
 Floating a) =>
a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
ArrMatrix.scale
         ((a -> a -> a) -> [a] -> [a] -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> a
forall a. Fractional a => a -> a -> a
(/) ([a] -> [a]
forall a. [a] -> [a]
cycle [a
1,-a
1]) ((a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a
1a -> a -> a
forall a. Num a => a -> a -> a
+) a
1))
         ((Quadratic pack prop lower upper (Unchecked sh) a -> Bool)
-> Stream (Quadratic pack prop lower upper (Unchecked sh) a)
-> [Quadratic pack prop lower upper (Unchecked sh) a]
forall a. (a -> Bool) -> Stream a -> [a]
Stream.takeWhile ((ar
0ar -> ar -> Bool
forall a. Ord a => a -> a -> Bool
<) (ar -> Bool)
-> (Quadratic pack prop lower upper (Unchecked sh) a -> ar)
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Quadratic pack prop lower upper (Unchecked sh) a -> ar
forall meas vert horiz height width a pack prop lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
ArrayMatrix pack prop lower upper meas vert horiz height width a
-> RealOf a
normInf) (Stream (Quadratic pack prop lower upper (Unchecked sh) a)
 -> [Quadratic pack prop lower upper (Unchecked sh) a])
-> Stream (Quadratic pack prop lower upper (Unchecked sh) a)
-> [Quadratic pack prop lower upper (Unchecked sh) a]
forall a b. (a -> b) -> a -> b
$ Quadratic pack prop lower upper (Unchecked sh) a
-> Stream (Quadratic pack prop lower upper (Unchecked sh) a)
forall typ xl xu lower upper sh a.
(Power typ xl xu, PowerStrip lower, PowerStrip upper, C sh,
 Floating a) =>
Quadratic typ xl xu lower upper sh a
-> Stream (Quadratic typ xl xu lower upper sh a)
Matrix.powers1 Quadratic pack prop lower upper (Unchecked sh) a
b)


class (MatrixShape.Property property) => LiftReal property where
   {- |
   Lift any function with a Taylor expansion
   to a diagonalizable matrix.
   -}
   liftReal ::
      (Layout.Packing pack,
       MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
       Shape.C sh, Class.Real a) =>
      (a -> a) ->
      Quadratic pack property lower upper sh a ->
      Quadratic pack property lower upper sh a

{- |
Generic algorithm that applies a scalar function
to the elements of the diagonal factor
of a full, triangular or diagonal matrix with distinct eigenvalues.
It is not checked whether the matrix has distinct eigenvalues.
-}
instance LiftReal Omni.Arbitrary where
   liftReal :: (a -> a)
-> Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
liftReal a -> a
f Quadratic pack Arbitrary lower upper sh a
a =
      case Omni pack Arbitrary lower upper Shape Small Small sh sh
-> Power pack Arbitrary lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni pack Arbitrary lower upper Shape Small Small sh sh
 -> Power pack Arbitrary lower upper Shape Small Small sh sh)
-> Omni pack Arbitrary lower upper Shape Small Small sh sh
-> Power pack Arbitrary lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper sh a
-> Omni pack Arbitrary lower upper 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 Quadratic pack Arbitrary lower upper sh a
a of
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerDiagonal -> (a -> a)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh a
forall pack sh a b.
(Packing pack, C sh, Floating a, Floating b) =>
(a -> b)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh b
liftDiagonal a -> a
f Quadratic pack Arbitrary lower upper sh a
Quadratic pack Arbitrary Empty Empty sh a
a
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerUpperTriangular -> ((Quadratic pack Arbitrary lower upper (Unchecked sh) a
  -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
 -> Quadratic pack Arbitrary lower upper sh a
 -> Quadratic pack Arbitrary lower upper sh a)
-> Quadratic pack Arbitrary lower upper sh a
-> (Quadratic pack Arbitrary lower upper (Unchecked sh) a
    -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
-> Quadratic pack Arbitrary lower upper sh a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Quadratic pack Arbitrary lower upper (Unchecked sh) a
 -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
-> Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked Quadratic pack Arbitrary lower upper sh a
a ((Quadratic pack Arbitrary lower upper (Unchecked sh) a
  -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
 -> Quadratic pack Arbitrary lower upper sh a)
-> (Quadratic pack Arbitrary lower upper (Unchecked sh) a
    -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
-> Quadratic pack Arbitrary lower upper sh a
forall a b. (a -> b) -> a -> b
$ \Quadratic pack Arbitrary lower upper (Unchecked sh) a
b ->
            let (Quadratic pack Arbitrary lower upper (Unchecked sh) a
vr,Vector (Unchecked sh) a
d,Quadratic pack Arbitrary lower upper (Unchecked sh) a
vlAdj) = Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> (Quadratic pack Arbitrary lower upper (Unchecked sh) a,
    Vector (Unchecked sh) a,
    Quadratic pack Arbitrary lower upper (Unchecked sh) a)
forall pack lo up sh a.
(Packing pack, DiagUpLo lo up, C sh, Floating a) =>
TriangularP pack lo Arbitrary up sh a
-> (TriangularP pack lo Arbitrary up sh a, Vector sh a,
    TriangularP pack lo Arbitrary up sh a)
Triangular.eigensystem Quadratic pack Arbitrary lower upper (Unchecked sh) a
b
                scal :: Vector (Unchecked sh) a
scal = Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Vector (Unchecked sh) a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a -> Vector sh a
Triangular.takeDiagonal (Quadratic pack Arbitrary lower upper (Unchecked sh) a
 -> Vector (Unchecked sh) a)
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Vector (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper (Unchecked sh) a
vlAdj Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
forall a. Semigroup a => a -> a -> a
<> Quadratic pack Arbitrary lower upper (Unchecked sh) a
vr
            in Square (Unchecked sh) a
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
forall pack mirror uplo meas vert horiz prop lower upper sh a.
(Packing pack, Mirror mirror, UpLo uplo, meas ~ Shape,
 vert ~ Small, horiz ~ Small,
 FromPlain pack prop lower upper meas vert horiz sh sh,
 Plain pack prop lower upper meas vert horiz sh sh
 ~ Mosaic pack mirror uplo sh,
 C sh, Floating a) =>
Square sh a -> Quadratic pack prop lower upper sh a
ArrMosaic.assureMirrored (Square (Unchecked sh) a
 -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
-> Square (Unchecked sh) a
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$
               Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Square (Unchecked sh) a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a -> Square sh a
Triangular.toSquare Quadratic pack Arbitrary lower upper (Unchecked sh) a
vr
                  #*\ Vector.divide (Array.map f d) scal
                  ##*# vlAdj
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerLowerTriangular -> ((Quadratic pack Arbitrary lower upper (Unchecked sh) a
  -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
 -> Quadratic pack Arbitrary lower upper sh a
 -> Quadratic pack Arbitrary lower upper sh a)
-> Quadratic pack Arbitrary lower upper sh a
-> (Quadratic pack Arbitrary lower upper (Unchecked sh) a
    -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
-> Quadratic pack Arbitrary lower upper sh a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Quadratic pack Arbitrary lower upper (Unchecked sh) a
 -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
-> Quadratic pack Arbitrary lower upper sh a
-> Quadratic pack Arbitrary lower upper sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked Quadratic pack Arbitrary lower upper sh a
a ((Quadratic pack Arbitrary lower upper (Unchecked sh) a
  -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
 -> Quadratic pack Arbitrary lower upper sh a)
-> (Quadratic pack Arbitrary lower upper (Unchecked sh) a
    -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
-> Quadratic pack Arbitrary lower upper sh a
forall a b. (a -> b) -> a -> b
$ \Quadratic pack Arbitrary lower upper (Unchecked sh) a
b ->
            let (Quadratic pack Arbitrary lower upper (Unchecked sh) a
vr,Vector (Unchecked sh) a
d,Quadratic pack Arbitrary lower upper (Unchecked sh) a
vlAdj) = Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> (Quadratic pack Arbitrary lower upper (Unchecked sh) a,
    Vector (Unchecked sh) a,
    Quadratic pack Arbitrary lower upper (Unchecked sh) a)
forall pack lo up sh a.
(Packing pack, DiagUpLo lo up, C sh, Floating a) =>
TriangularP pack lo Arbitrary up sh a
-> (TriangularP pack lo Arbitrary up sh a, Vector sh a,
    TriangularP pack lo Arbitrary up sh a)
Triangular.eigensystem Quadratic pack Arbitrary lower upper (Unchecked sh) a
b
                scal :: Vector (Unchecked sh) a
scal = Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Vector (Unchecked sh) a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a -> Vector sh a
Triangular.takeDiagonal (Quadratic pack Arbitrary lower upper (Unchecked sh) a
 -> Vector (Unchecked sh) a)
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Vector (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Arbitrary lower upper (Unchecked sh) a
vlAdj Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
forall a. Semigroup a => a -> a -> a
<> Quadratic pack Arbitrary lower upper (Unchecked sh) a
vr
            in Square (Unchecked sh) a
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
forall pack mirror uplo meas vert horiz prop lower upper sh a.
(Packing pack, Mirror mirror, UpLo uplo, meas ~ Shape,
 vert ~ Small, horiz ~ Small,
 FromPlain pack prop lower upper meas vert horiz sh sh,
 Plain pack prop lower upper meas vert horiz sh sh
 ~ Mosaic pack mirror uplo sh,
 C sh, Floating a) =>
Square sh a -> Quadratic pack prop lower upper sh a
ArrMosaic.assureMirrored (Square (Unchecked sh) a
 -> Quadratic pack Arbitrary lower upper (Unchecked sh) a)
-> Square (Unchecked sh) a
-> Quadratic pack Arbitrary lower upper (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$
               Quadratic pack Arbitrary lower upper (Unchecked sh) a
-> Square (Unchecked sh) a
forall lo up diag sh a pack.
(PowerStrip lo, PowerStrip up, TriDiag diag, C sh, Floating a) =>
TriangularP pack lo diag up sh a -> Square sh a
Triangular.toSquare Quadratic pack Arbitrary lower upper (Unchecked sh) a
vr
                  #*\ Vector.divide (Array.map f d) scal
                  ##*# vlAdj
         Power pack Arbitrary lower upper Shape Small Small sh sh
Omni.PowerFull ->
            case Quadratic pack Arbitrary lower upper sh a -> PrecisionSingleton a
forall a (f :: * -> *). Real a => f a -> PrecisionSingleton a
Scalar.precisionOfFunctor Quadratic pack Arbitrary lower upper sh a
a of
               PrecisionSingleton a
Scalar.Float  -> (a -> a)
-> Quadratic Unpacked Arbitrary lower upper sh a
-> Quadratic Unpacked Arbitrary lower upper sh a
forall prop lower upper sh a.
(Property prop, PowerStrip lower, PowerStrip upper, C sh, Real a,
 RealOf a ~ a) =>
(a -> a)
-> Quadratic Unpacked prop lower upper sh a
-> Quadratic Unpacked prop lower upper sh a
liftRealFull a -> a
f Quadratic pack Arbitrary lower upper sh a
Quadratic Unpacked Arbitrary lower upper sh a
a
               PrecisionSingleton a
Scalar.Double -> (a -> a)
-> Quadratic Unpacked Arbitrary lower upper sh a
-> Quadratic Unpacked Arbitrary lower upper sh a
forall prop lower upper sh a.
(Property prop, PowerStrip lower, PowerStrip upper, C sh, Real a,
 RealOf a ~ a) =>
(a -> a)
-> Quadratic Unpacked prop lower upper sh a
-> Quadratic Unpacked prop lower upper sh a
liftRealFull a -> a
f Quadratic pack Arbitrary lower upper sh a
Quadratic Unpacked Arbitrary lower upper sh a
a

liftRealFull ::
   (MatrixShape.Property prop,
    MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
    Shape.C sh, Class.Real a, Scalar.RealOf a ~ a) =>
   (a -> a) ->
   Quadratic Layout.Unpacked prop lower upper sh a ->
   Quadratic Layout.Unpacked prop lower upper sh a
liftRealFull :: (a -> a)
-> Quadratic Unpacked prop lower upper sh a
-> Quadratic Unpacked prop lower upper sh a
liftRealFull a -> a
f = (Quadratic Unpacked prop lower upper (IntIndexed sh) a
 -> Quadratic Unpacked prop lower upper (IntIndexed sh) a)
-> Quadratic Unpacked prop lower upper sh a
-> Quadratic Unpacked prop lower upper sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (IntIndexed sh) a
 -> Quadratic pack prop lower upper (IntIndexed sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyPermutable ((Quadratic Unpacked prop lower upper (IntIndexed sh) a
  -> Quadratic Unpacked prop lower upper (IntIndexed sh) a)
 -> Quadratic Unpacked prop lower upper sh a
 -> Quadratic Unpacked prop lower upper sh a)
-> (Quadratic Unpacked prop lower upper (IntIndexed sh) a
    -> Quadratic Unpacked prop lower upper (IntIndexed sh) a)
-> Quadratic Unpacked prop lower upper sh a
-> Quadratic Unpacked prop lower upper sh a
forall a b. (a -> b) -> a -> b
$ (Quadratic Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
 -> Quadratic
      Unpacked prop lower upper (Unchecked (IntIndexed sh)) a)
-> Quadratic Unpacked prop lower upper (IntIndexed sh) a
-> Quadratic Unpacked prop lower upper (IntIndexed sh) a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
  -> Quadratic
       Unpacked prop lower upper (Unchecked (IntIndexed sh)) a)
 -> Quadratic Unpacked prop lower upper (IntIndexed sh) a
 -> Quadratic Unpacked prop lower upper (IntIndexed sh) a)
-> (Quadratic
      Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
    -> Quadratic
         Unpacked prop lower upper (Unchecked (IntIndexed sh)) a)
-> Quadratic Unpacked prop lower upper (IntIndexed sh) a
-> Quadratic Unpacked prop lower upper (IntIndexed sh) a
forall a b. (a -> b) -> a -> b
$ \Quadratic Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
a ->
   let (Square (Unchecked (IntIndexed sh)) (Complex a)
vr,Vector (Unchecked (IntIndexed sh)) (Complex a)
d,Square (Unchecked (IntIndexed sh)) (Complex a)
vlAdj) = Square (Unchecked (IntIndexed sh)) a
-> (Square (Unchecked (IntIndexed sh)) (Complex a),
    Vector (Unchecked (IntIndexed sh)) (Complex a),
    Square (Unchecked (IntIndexed sh)) (Complex a))
forall sh a ac.
(Permutable sh, Floating a, ComplexOf a ~ ac) =>
Square sh a -> (Square sh ac, Vector sh ac, Square sh ac)
Square.eigensystem (Square (Unchecked (IntIndexed sh)) a
 -> (Square (Unchecked (IntIndexed sh)) (Complex a),
     Vector (Unchecked (IntIndexed sh)) (Complex a),
     Square (Unchecked (IntIndexed sh)) (Complex a)))
-> Square (Unchecked (IntIndexed sh)) a
-> (Square (Unchecked (IntIndexed sh)) (Complex a),
    Vector (Unchecked (IntIndexed sh)) (Complex a),
    Square (Unchecked (IntIndexed sh)) (Complex a))
forall a b. (a -> b) -> a -> b
$ Quadratic Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
-> Square (Unchecked (IntIndexed sh)) a
forall meas vert horiz height width a pack property lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
Matrix.toFull Quadratic Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
a
       vrR :: Square (Unchecked (IntIndexed sh)) a
vrR = Square (Unchecked (IntIndexed sh)) (Complex a)
-> Square (Unchecked (IntIndexed sh)) a
forall pack property lower upper meas vert horiz height width
       (matrix :: * -> *) a.
(ArrayMatrix pack property lower upper meas vert horiz height width
 ~ matrix,
 Measure meas, C vert, C horiz, C height, C width, Real a) =>
matrix (Complex a) -> matrix a
matrixRealPart Square (Unchecked (IntIndexed sh)) (Complex a)
vr
       vlAdjR :: Square (Unchecked (IntIndexed sh)) a
vlAdjR = Square (Unchecked (IntIndexed sh)) (Complex a)
-> Square (Unchecked (IntIndexed sh)) a
forall pack property lower upper meas vert horiz height width
       (matrix :: * -> *) a.
(ArrayMatrix pack property lower upper meas vert horiz height width
 ~ matrix,
 Measure meas, C vert, C horiz, C height, C width, Real a) =>
matrix (Complex a) -> matrix a
matrixRealPart Square (Unchecked (IntIndexed sh)) (Complex a)
vlAdj
       dR :: Array (Unchecked (IntIndexed sh)) a
dR = (Complex a -> a)
-> Vector (Unchecked (IntIndexed sh)) (Complex a)
-> Array (Unchecked (IntIndexed sh)) a
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map Complex a -> a
forall a. Complex a -> a
Complex.realPart Vector (Unchecked (IntIndexed sh)) (Complex a)
d
       scal :: Array (Unchecked (IntIndexed sh)) a
scal = Square (Unchecked (IntIndexed sh)) a
-> Array (Unchecked (IntIndexed sh)) a
forall sh a. (C sh, Floating a) => Square sh a -> Vector sh a
Square.takeDiagonal (Square (Unchecked (IntIndexed sh)) a
 -> Array (Unchecked (IntIndexed sh)) a)
-> Square (Unchecked (IntIndexed sh)) a
-> Array (Unchecked (IntIndexed sh)) a
forall a b. (a -> b) -> a -> b
$ Square (Unchecked (IntIndexed sh)) a
vlAdjR Square (Unchecked (IntIndexed sh)) a
-> Square (Unchecked (IntIndexed sh)) a
-> Square (Unchecked (IntIndexed sh)) a
forall a. Semigroup a => a -> a -> a
<> Square (Unchecked (IntIndexed sh)) a
vrR
   in if a -> Bool
forall a. Floating a => a -> Bool
Scalar.isZero (a -> Bool) -> a -> Bool
forall a b. (a -> b) -> a -> b
$ Array (Unchecked (IntIndexed sh)) a -> RealOf a
forall sh a. (C sh, Floating a) => Vector sh a -> RealOf a
Vector.normInf (Array (Unchecked (IntIndexed sh)) a -> RealOf a)
-> Array (Unchecked (IntIndexed sh)) a -> RealOf a
forall a b. (a -> b) -> a -> b
$ (Complex a -> a)
-> Vector (Unchecked (IntIndexed sh)) (Complex a)
-> Array (Unchecked (IntIndexed sh)) a
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map Complex a -> a
forall a. Complex a -> a
Complex.imagPart Vector (Unchecked (IntIndexed sh)) (Complex a)
d
         then (FullArray
   Shape
   Small
   Small
   (Unchecked (IntIndexed sh))
   (Unchecked (IntIndexed sh))
   a
 -> FullArray
      Shape
      Small
      Small
      (Unchecked (IntIndexed sh))
      (Unchecked (IntIndexed sh))
      a)
-> Square (Unchecked (IntIndexed sh)) a
-> Quadratic
     Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
forall propertyA lowerA upperA propertyB lowerB upperB measA vertA
       horizA heightA widthA a measB vertB horizB heightB widthB b.
(Property propertyA, Strip lowerA, Strip upperA,
 Property propertyB, Strip lowerB, Strip upperB) =>
(FullArray measA vertA horizA heightA widthA a
 -> FullArray measB vertB horizB heightB widthB b)
-> UnpackedMatrix
     propertyA lowerA upperA measA vertA horizA heightA widthA a
-> UnpackedMatrix
     propertyB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.liftUnpacked1 FullArray
  Shape
  Small
  Small
  (Unchecked (IntIndexed sh))
  (Unchecked (IntIndexed sh))
  a
-> FullArray
     Shape
     Small
     Small
     (Unchecked (IntIndexed sh))
     (Unchecked (IntIndexed sh))
     a
forall a. a -> a
id (Square (Unchecked (IntIndexed sh)) a
 -> Quadratic
      Unpacked prop lower upper (Unchecked (IntIndexed sh)) a)
-> Square (Unchecked (IntIndexed sh)) a
-> Quadratic
     Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
forall a b. (a -> b) -> a -> b
$
              Square (Unchecked (IntIndexed sh)) a
vrR Square (Unchecked (IntIndexed sh)) a
-> Array (Unchecked (IntIndexed sh)) a
-> Square (Unchecked (IntIndexed sh)) a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, C width, Eq width,
 Floating a) =>
Full meas vert horiz height width a
-> Vector width a -> Full meas vert horiz height width a
#*\ Array (Unchecked (IntIndexed sh)) a
-> Array (Unchecked (IntIndexed sh)) a
-> Array (Unchecked (IntIndexed sh)) a
forall sh a.
(C sh, Eq sh, Floating a) =>
Vector sh a -> Vector sh a -> Vector sh a
Vector.divide ((a -> a)
-> Array (Unchecked (IntIndexed sh)) a
-> Array (Unchecked (IntIndexed sh)) a
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map a -> a
f Array (Unchecked (IntIndexed sh)) a
dR) Array (Unchecked (IntIndexed sh)) a
scal Square (Unchecked (IntIndexed sh)) a
-> Square (Unchecked (IntIndexed sh)) a
-> Square (Unchecked (IntIndexed sh)) a
forall typ xl xu lowerA upperA lowerB upperB lowerC upperC measA
       measB measC vert horiz height fuse width a.
(MultiplySquare typ xl xu, ToQuadratic typ, Strip lowerA,
 Strip upperA, Strip lowerB, Strip upperB, Strip lowerC,
 Strip upperC, MultipliedBands lowerA lowerB ~ lowerC,
 MultipliedBands lowerB lowerA ~ lowerC,
 MultipliedBands upperA upperB ~ upperC,
 MultipliedBands upperB upperA ~ upperC, Measure measA,
 Measure measB, Measure measC, MultiplyMeasure measA measB ~ measC,
 C vert, C horiz, C height, C fuse, Eq fuse, C width, Floating a) =>
Unpacked lowerB upperB measB vert horiz height fuse a
-> QuadraticMeas typ xl xu lowerA upperA measA fuse width a
-> Unpacked lowerC upperC measC vert horiz height width a
##*# Square (Unchecked (IntIndexed sh)) a
vlAdjR
         else [Char]
-> Quadratic
     Unpacked prop lower upper (Unchecked (IntIndexed sh)) a
forall a. HasCallStack => [Char] -> a
error [Char]
"liftReal: non-real eigenvalues"

matrixRealPart ::
   (ArrayMatrix pack property lower upper meas vert horiz height width ~ matrix,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Real a) =>
   matrix (Complex a) -> matrix a
matrixRealPart :: matrix (Complex a) -> matrix a
matrixRealPart =
   OmniArray pack property lower upper meas vert horiz height width a
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall pack prop lower upper meas vert horiz height width a.
OmniArray pack prop lower upper meas vert horiz height width a
-> Matrix
     (Array pack prop) () () lower upper meas vert horiz height width a
ArrMatrix.Array (OmniArray pack property lower upper meas vert horiz height width a
 -> Matrix
      (Array pack property)
      ()
      ()
      lower
      upper
      meas
      vert
      horiz
      height
      width
      a)
-> (ArrayMatrix
      pack property lower upper meas vert horiz height width (Complex a)
    -> OmniArray
         pack property lower upper meas vert horiz height width a)
-> ArrayMatrix
     pack property lower upper meas vert horiz height width (Complex a)
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Complex a -> a)
-> Array
     (Omni pack property lower upper meas vert horiz height width)
     (Complex a)
-> OmniArray
     pack property lower upper meas vert horiz height width a
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map Complex a -> a
forall a. Complex a -> a
Complex.realPart (Array
   (Omni pack property lower upper meas vert horiz height width)
   (Complex a)
 -> OmniArray
      pack property lower upper meas vert horiz height width a)
-> (ArrayMatrix
      pack property lower upper meas vert horiz height width (Complex a)
    -> Array
         (Omni pack property lower upper meas vert horiz height width)
         (Complex a))
-> ArrayMatrix
     pack property lower upper meas vert horiz height width (Complex a)
-> OmniArray
     pack property lower upper meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayMatrix
  pack property lower upper meas vert horiz height width (Complex a)
-> Array
     (Omni pack property lower upper meas vert horiz height width)
     (Complex a)
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> OmniArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.unwrap


instance
   (neg ~ True, zero ~ True, pos ~ True) =>
      LiftReal (Omni.Hermitian neg zero pos) where
   liftReal :: (a -> a)
-> Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> Quadratic pack (Hermitian neg zero pos) lower upper sh a
liftReal a -> a
f Quadratic pack (Hermitian neg zero pos) lower upper sh a
a =
      case Omni
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
-> Power
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni
   pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
 -> Power
      pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh)
-> Omni
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
-> Power
     pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack (Hermitian neg zero pos) lower upper sh a
-> Omni
     pack (Hermitian neg zero pos) lower upper 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 Quadratic pack (Hermitian neg zero pos) lower upper sh a
a of
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
Omni.PowerDiagonal -> (a -> a)
-> Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
-> Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
forall pack neg zero pos herm sh a b.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, Floating b) =>
(a -> b)
-> Quadratic pack herm Empty Empty sh a
-> Quadratic pack herm Empty Empty sh b
liftHermitianDiagonal a -> a
f Quadratic pack (Hermitian neg zero pos) lower upper sh a
Quadratic pack (Hermitian neg zero pos) Empty Empty sh a
a
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
Omni.PowerHermitian -> (a -> a) -> HermitianP pack sh a -> HermitianP pack sh a
forall pack sh a.
(Packing pack, C sh, Real a) =>
(a -> a) -> HermitianP pack sh a -> HermitianP pack sh a
liftHermitianReal a -> a
f Quadratic pack (Hermitian neg zero pos) lower upper sh a
HermitianP pack sh a
a
         Power
  pack (Hermitian neg zero pos) lower upper Shape Small Small sh sh
_ -> [Char] -> Quadratic pack (Hermitian neg zero pos) lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"Hermitian.liftReal: impossible shape"

instance LiftReal Omni.Symmetric where
   liftReal :: (a -> a)
-> Quadratic pack Symmetric lower upper sh a
-> Quadratic pack Symmetric lower upper sh a
liftReal a -> a
f Quadratic pack Symmetric lower upper sh a
a =
      case Omni pack Symmetric lower upper Shape Small Small sh sh
-> Power pack Symmetric lower upper Shape Small Small sh sh
forall pack property lower upper meas vert horiz height width.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C vert, C horiz) =>
Omni pack property lower upper meas vert horiz height width
-> Power pack property lower upper meas vert horiz height width
Omni.powerSingleton (Omni pack Symmetric lower upper Shape Small Small sh sh
 -> Power pack Symmetric lower upper Shape Small Small sh sh)
-> Omni pack Symmetric lower upper Shape Small Small sh sh
-> Power pack Symmetric lower upper Shape Small Small sh sh
forall a b. (a -> b) -> a -> b
$ Quadratic pack Symmetric lower upper sh a
-> Omni pack Symmetric lower upper 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 Quadratic pack Symmetric lower upper sh a
a of
         Power pack Symmetric lower upper Shape Small Small sh sh
Omni.PowerSymmetric ->
            FlexHermitianP pack True True True sh a -> SymmetricP pack sh a
forall pack neg zero pos sh a.
(Packing pack, C neg, C zero, C pos, C sh, Real a) =>
FlexHermitianP pack neg zero pos sh a -> SymmetricP pack sh a
Symmetric.fromHermitian (FlexHermitianP pack True True True sh a -> SymmetricP pack sh a)
-> (SymmetricP pack sh a
    -> FlexHermitianP pack True True True sh a)
-> SymmetricP pack sh a
-> SymmetricP pack sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            (a -> a)
-> FlexHermitianP pack True True True sh a
-> FlexHermitianP pack True True True sh a
forall pack sh a.
(Packing pack, C sh, Real a) =>
(a -> a) -> HermitianP pack sh a -> HermitianP pack sh a
liftHermitianReal a -> a
f (FlexHermitianP pack True True True sh a
 -> FlexHermitianP pack True True True sh a)
-> (SymmetricP pack sh a
    -> FlexHermitianP pack True True True sh a)
-> SymmetricP pack sh a
-> FlexHermitianP pack True True True sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricP pack sh a -> FlexHermitianP pack True True True sh a
forall pack sh a.
(Packing pack, C sh, Real a) =>
SymmetricP pack sh a -> HermitianP pack sh a
Hermitian.fromSymmetric (SymmetricP pack sh a -> SymmetricP pack sh a)
-> SymmetricP pack sh a -> SymmetricP pack sh a
forall a b. (a -> b) -> a -> b
$ Quadratic pack Symmetric lower upper sh a
SymmetricP pack sh a
a
         Power pack Symmetric lower upper Shape Small Small sh sh
_ -> [Char] -> Quadratic pack Symmetric lower upper sh a
forall a. HasCallStack => [Char] -> a
error [Char]
"Symmetric.liftReal: impossible shape"

liftHermitianReal ::
   (Layout.Packing pack, Shape.C sh, Class.Real a) =>
   (a -> a) -> HermitianP pack sh a -> HermitianP pack sh a
liftHermitianReal :: (a -> a) -> HermitianP pack sh a -> HermitianP pack sh a
liftHermitianReal a -> a
f HermitianP pack sh a
a =
   case HermitianP pack sh a -> PrecisionSingleton a
forall a (f :: * -> *). Real a => f a -> PrecisionSingleton a
Scalar.precisionOfFunctor HermitianP pack sh a
a of
      PrecisionSingleton a
Scalar.Float -> (a -> a) -> HermitianP pack sh a -> HermitianP pack sh a
forall pack neg zero pos herm sh a ar.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, RealOf a ~ ar, Storable ar) =>
(ar -> ar)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
liftHermitian a -> a
f HermitianP pack sh a
a
      PrecisionSingleton a
Scalar.Double -> (a -> a) -> HermitianP pack sh a -> HermitianP pack sh a
forall pack neg zero pos herm sh a ar.
(Packing pack, C neg, C zero, C pos, Hermitian neg zero pos ~ herm,
 C sh, Floating a, RealOf a ~ ar, Storable ar) =>
(ar -> ar)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
liftHermitian a -> a
f HermitianP pack sh a
a


norm1 ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   ArrMatrix.ArrayMatrix pack prop lower upper meas vert horiz height width a ->
   Scalar.RealOf a
norm1 :: ArrayMatrix pack prop lower upper meas vert horiz height width a
-> RealOf a
norm1 = Vector (Omni pack prop lower upper meas vert horiz height width) a
-> RealOf a
forall sh a. (C sh, Floating a) => Vector sh a -> RealOf a
Vector.norm1 (Vector (Omni pack prop lower upper meas vert horiz height width) a
 -> RealOf a)
-> (ArrayMatrix
      pack prop lower upper meas vert horiz height width a
    -> Vector
         (Omni pack prop lower upper meas vert horiz height width) a)
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
-> RealOf a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayMatrix pack prop lower upper meas vert horiz height width a
-> Vector
     (Omni pack prop lower upper meas vert horiz height width) a
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> OmniArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.unwrap

normInf ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   ArrMatrix.ArrayMatrix pack prop lower upper meas vert horiz height width a ->
   Scalar.RealOf a
normInf :: ArrayMatrix pack prop lower upper meas vert horiz height width a
-> RealOf a
normInf = Vector (Omni pack prop lower upper meas vert horiz height width) a
-> RealOf a
forall sh a. (C sh, Floating a) => Vector sh a -> RealOf a
Vector.normInf (Vector (Omni pack prop lower upper meas vert horiz height width) a
 -> RealOf a)
-> (ArrayMatrix
      pack prop lower upper meas vert horiz height width a
    -> Vector
         (Omni pack prop lower upper meas vert horiz height width) a)
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
-> RealOf a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayMatrix pack prop lower upper meas vert horiz height width a
-> Vector
     (Omni pack prop lower upper meas vert horiz height width) a
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> OmniArray
     pack property lower upper meas vert horiz height width a
ArrMatrix.unwrap


liftDiagonal ::
   (Layout.Packing pack, Shape.C sh, Class.Floating a, Class.Floating b) =>
   (a -> b) ->
   Quadratic pack Omni.Arbitrary Layout.Empty Layout.Empty sh a ->
   Quadratic pack Omni.Arbitrary Layout.Empty Layout.Empty sh b
liftDiagonal :: (a -> b)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh b
liftDiagonal a -> b
f = (Array sh a -> Array sh b)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh b
forall pack sha shb a b.
(Packing pack, C sha, C shb, Floating a, Floating b) =>
(Array sha a -> Array shb b)
-> FlexDiagonalP pack Arbitrary sha a
-> FlexDiagonalP pack Arbitrary shb b
Diagonal.lift ((Array sh a -> Array sh b)
 -> Quadratic pack Arbitrary Empty Empty sh a
 -> Quadratic pack Arbitrary Empty Empty sh b)
-> (Array sh a -> Array sh b)
-> Quadratic pack Arbitrary Empty Empty sh a
-> Quadratic pack Arbitrary Empty Empty sh b
forall a b. (a -> b) -> a -> b
$ (a -> b) -> Array sh a -> Array sh b
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map a -> b
f

liftHermitianDiagonal ::
   (Layout.Packing pack,
    Bool.C neg, Bool.C zero, Bool.C pos, Omni.Hermitian neg zero pos ~ herm,
    Shape.C sh, Class.Floating a, Class.Floating b) =>
   (a -> b) ->
   Quadratic pack herm Layout.Empty Layout.Empty sh a ->
   Quadratic pack herm Layout.Empty Layout.Empty sh b
liftHermitianDiagonal :: (a -> b)
-> Quadratic pack herm Empty Empty sh a
-> Quadratic pack herm Empty Empty sh b
liftHermitianDiagonal a -> b
f Quadratic pack herm Empty Empty sh a
a =
   case Quadratic pack herm Empty Empty sh a -> PackingSingleton pack
forall pack diag lower upper meas vert horiz height width a.
Packing pack =>
ArrayMatrix pack diag lower upper meas vert horiz height width a
-> PackingSingleton pack
packTag Quadratic pack herm Empty Empty sh a
a of
      PackingSingleton pack
Layout.Packed -> (PlainArray pack herm Empty Empty Shape Small Small sh sh a
 -> PlainArray pack herm Empty Empty Shape Small Small sh sh b)
-> Quadratic pack herm Empty Empty sh a
-> Quadratic pack herm Empty Empty sh b
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 ((a -> b)
-> Array (BandedHermitian Zero sh) a
-> Array (BandedHermitian Zero sh) b
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map a -> b
f) Quadratic pack herm Empty Empty sh a
a
      PackingSingleton pack
Layout.Unpacked ->
         let b :: Square sh b
b = Vector sh b -> Square sh b
forall sh a. (C sh, Floating a) => Vector sh a -> Square sh a
Square.diagonal (Vector sh b -> Square sh b) -> Vector sh b -> Square sh b
forall a b. (a -> b) -> a -> b
$ (a -> b) -> Array sh a -> Vector sh b
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map a -> b
f (Array sh a -> Vector sh b) -> Array sh a -> Vector sh b
forall a b. (a -> b) -> a -> b
$ Quadratic pack herm Empty Empty sh a -> Array sh a
forall sh a pack property lower upper.
(C sh, Floating a) =>
Quadratic pack property lower upper sh a -> Vector sh a
Quad.takeDiagonal Quadratic pack herm Empty Empty sh a
a
         in (FullArray Shape Small Small sh sh b
 -> FullArray Shape Small Small sh sh b)
-> Square sh b
-> UnpackedMatrix herm Empty Empty Shape Small Small sh sh b
forall propertyA lowerA upperA propertyB lowerB upperB measA vertA
       horizA heightA widthA a measB vertB horizB heightB widthB b.
(Property propertyA, Strip lowerA, Strip upperA,
 Property propertyB, Strip lowerB, Strip upperB) =>
(FullArray measA vertA horizA heightA widthA a
 -> FullArray measB vertB horizB heightB widthB b)
-> UnpackedMatrix
     propertyA lowerA upperA measA vertA horizA heightA widthA a
-> UnpackedMatrix
     propertyB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.liftUnpacked1 FullArray Shape Small Small sh sh b
-> FullArray Shape Small Small sh sh b
forall a. a -> a
id (Square sh b
 -> UnpackedMatrix herm Empty Empty Shape Small Small sh sh b)
-> Square sh b
-> UnpackedMatrix herm Empty Empty Shape Small Small sh sh b
forall a b. (a -> b) -> a -> b
$
            if Quadratic pack herm Empty Empty sh a -> Order
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Order
ArrMatrix.order Quadratic pack herm Empty Empty sh a
a Order -> Order -> Bool
forall a. Eq a => a -> a -> Bool
== Square sh b -> Order
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Order
ArrMatrix.order Square sh b
b
               then Square sh b
b
               else Square sh b -> Square sh b
forall sh a. Square sh a -> Square sh a
Square.transpose Square sh b
b

liftHermitian ::
   (Layout.Packing pack,
    Bool.C neg, Bool.C zero, Bool.C pos, Omni.Hermitian neg zero pos ~ herm,
    Shape.C sh, Class.Floating a, Scalar.RealOf a ~ ar, Storable ar) =>
   (ar -> ar) ->
   Quadratic pack herm Layout.Filled Layout.Filled sh a ->
   Quadratic pack herm Layout.Filled Layout.Filled sh a
liftHermitian :: (ar -> ar)
-> Quadratic pack herm Filled Filled sh a
-> Quadratic pack herm Filled Filled sh a
liftHermitian ar -> ar
f = (Quadratic
   pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a
 -> Quadratic
      pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a)
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (IntIndexed sh) a
 -> Quadratic pack prop lower upper (IntIndexed sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyPermutable ((Quadratic
    pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a
  -> Quadratic
       pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a)
 -> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
 -> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a)
-> (Quadratic
      pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a
    -> Quadratic
         pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a)
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
-> Quadratic pack (Hermitian neg zero pos) Filled Filled sh a
forall a b. (a -> b) -> a -> b
$ (Quadratic
   pack
   (Hermitian neg zero pos)
   Filled
   Filled
   (Unchecked (IntIndexed sh))
   a
 -> Quadratic
      pack
      (Hermitian neg zero pos)
      Filled
      Filled
      (Unchecked (IntIndexed sh))
      a)
-> Quadratic
     pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a
-> Quadratic
     pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a
forall sh a pack prop lower upper.
(C sh, Floating a) =>
(Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked ((Quadratic
    pack
    (Hermitian neg zero pos)
    Filled
    Filled
    (Unchecked (IntIndexed sh))
    a
  -> Quadratic
       pack
       (Hermitian neg zero pos)
       Filled
       Filled
       (Unchecked (IntIndexed sh))
       a)
 -> Quadratic
      pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a
 -> Quadratic
      pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a)
-> (Quadratic
      pack
      (Hermitian neg zero pos)
      Filled
      Filled
      (Unchecked (IntIndexed sh))
      a
    -> Quadratic
         pack
         (Hermitian neg zero pos)
         Filled
         Filled
         (Unchecked (IntIndexed sh))
         a)
-> Quadratic
     pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a
-> Quadratic
     pack (Hermitian neg zero pos) Filled Filled (IntIndexed sh) a
forall a b. (a -> b) -> a -> b
$ \Quadratic
  pack
  (Hermitian neg zero pos)
  Filled
  Filled
  (Unchecked (IntIndexed sh))
  a
a ->
   let (Square (Unchecked (IntIndexed sh)) a
q,Array (Unchecked (IntIndexed sh)) ar
d) = Quadratic
  pack
  (Hermitian neg zero pos)
  Filled
  Filled
  (Unchecked (IntIndexed sh))
  a
-> (Square (Unchecked (IntIndexed sh)) a,
    Vector (Unchecked (IntIndexed sh)) (RealOf a))
forall pack neg zero pos sh a.
(Packing pack, C neg, C zero, C pos, Permutable sh, Floating a) =>
FlexHermitianP pack neg zero pos sh a
-> (Square sh a, Vector sh (RealOf a))
Hermitian.eigensystem Quadratic
  pack
  (Hermitian neg zero pos)
  Filled
  Filled
  (Unchecked (IntIndexed sh))
  a
a
   in (PlainArray
   pack
   HermitianUnknownDefiniteness
   Filled
   Filled
   Shape
   Small
   Small
   (Unchecked (IntIndexed sh))
   (Unchecked (IntIndexed sh))
   a
 -> PlainArray
      pack
      (Hermitian neg zero pos)
      Filled
      Filled
      Shape
      Small
      Small
      (Unchecked (IntIndexed sh))
      (Unchecked (IntIndexed sh))
      a)
-> ArrayMatrix
     pack
     HermitianUnknownDefiniteness
     Filled
     Filled
     Shape
     Small
     Small
     (Unchecked (IntIndexed sh))
     (Unchecked (IntIndexed sh))
     a
-> Quadratic
     pack
     (Hermitian neg zero pos)
     Filled
     Filled
     (Unchecked (IntIndexed 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
  pack
  HermitianUnknownDefiniteness
  Filled
  Filled
  Shape
  Small
  Small
  (Unchecked (IntIndexed sh))
  (Unchecked (IntIndexed sh))
  a
-> PlainArray
     pack
     (Hermitian neg zero pos)
     Filled
     Filled
     Shape
     Small
     Small
     (Unchecked (IntIndexed sh))
     (Unchecked (IntIndexed sh))
     a
forall a. a -> a
id (ArrayMatrix
   pack
   HermitianUnknownDefiniteness
   Filled
   Filled
   Shape
   Small
   Small
   (Unchecked (IntIndexed sh))
   (Unchecked (IntIndexed sh))
   a
 -> Quadratic
      pack
      (Hermitian neg zero pos)
      Filled
      Filled
      (Unchecked (IntIndexed sh))
      a)
-> ArrayMatrix
     pack
     HermitianUnknownDefiniteness
     Filled
     Filled
     Shape
     Small
     Small
     (Unchecked (IntIndexed sh))
     (Unchecked (IntIndexed sh))
     a
-> Quadratic
     pack
     (Hermitian neg zero pos)
     Filled
     Filled
     (Unchecked (IntIndexed sh))
     a
forall a b. (a -> b) -> a -> b
$
      General (Unchecked (IntIndexed sh)) (Unchecked (IntIndexed sh)) a
-> Vector (Unchecked (IntIndexed sh)) (RealOf a)
-> ArrayMatrix
     pack
     HermitianUnknownDefiniteness
     Filled
     Filled
     Shape
     Small
     Small
     (Unchecked (IntIndexed sh))
     (Unchecked (IntIndexed sh))
     a
forall pack height width a.
(Packing pack, C height, C width, Eq width, Floating a) =>
General height width a
-> Vector width (RealOf a) -> HermitianP pack height a
Hermitian.congruenceDiagonalAdjoint (Square (Unchecked (IntIndexed sh)) a
-> General
     (Unchecked (IntIndexed sh)) (Unchecked (IntIndexed sh)) a
forall meas vert horiz sh a.
(Measured meas vert, Measured meas horiz) =>
Square sh a -> Full meas vert horiz sh sh a
Square.toFull Square (Unchecked (IntIndexed sh)) a
q) ((ar -> ar)
-> Array (Unchecked (IntIndexed sh)) ar
-> Array (Unchecked (IntIndexed sh)) ar
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map ar -> ar
f Array (Unchecked (IntIndexed sh)) ar
d)


applyPermutable ::
   (Shape.C sh, Class.Floating a) =>
   (Quadratic pack prop lower upper (ExtShape.IntIndexed sh) a ->
    Quadratic pack prop lower upper (ExtShape.IntIndexed sh) a) ->
   Quadratic pack prop lower upper sh a ->
   Quadratic pack prop lower upper sh a
applyPermutable :: (Quadratic pack prop lower upper (IntIndexed sh) a
 -> Quadratic pack prop lower upper (IntIndexed sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyPermutable Quadratic pack prop lower upper (IntIndexed sh) a
-> Quadratic pack prop lower upper (IntIndexed sh) a
f =
   (IntIndexed sh -> sh)
-> Quadratic pack prop lower upper (IntIndexed sh) a
-> Quadratic pack prop lower upper sh a
forall shA shB pack property lower upper a.
(C shA, C shB) =>
(shA -> shB)
-> Quadratic pack property lower upper shA a
-> Quadratic pack property lower upper shB a
Quad.mapSize IntIndexed sh -> sh
forall sh. IntIndexed sh -> sh
ExtShape.deconsIntIndexed (Quadratic pack prop lower upper (IntIndexed sh) a
 -> Quadratic pack prop lower upper sh a)
-> (Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper (IntIndexed sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   Quadratic pack prop lower upper (IntIndexed sh) a
-> Quadratic pack prop lower upper (IntIndexed sh) a
f (Quadratic pack prop lower upper (IntIndexed sh) a
 -> Quadratic pack prop lower upper (IntIndexed sh) a)
-> (Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper (IntIndexed sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper (IntIndexed sh) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   (sh -> IntIndexed sh)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper (IntIndexed sh) a
forall shA shB pack property lower upper a.
(C shA, C shB) =>
(shA -> shB)
-> Quadratic pack property lower upper shA a
-> Quadratic pack property lower upper shB a
Quad.mapSize sh -> IntIndexed sh
forall sh. sh -> IntIndexed sh
ExtShape.IntIndexed

applyUnchecked ::
   (Shape.C sh, Class.Floating a) =>
   (Quadratic pack prop lower upper (PrivShape.Unchecked sh) a ->
    Quadratic pack prop lower upper (PrivShape.Unchecked sh) a) ->
   Quadratic pack prop lower upper sh a ->
   Quadratic pack prop lower upper sh a
applyUnchecked :: (Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
applyUnchecked Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
f =
   (Unchecked sh -> sh)
-> Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper sh a
forall shA shB pack property lower upper a.
(C shA, C shB) =>
(shA -> shB)
-> Quadratic pack property lower upper shA a
-> Quadratic pack property lower upper shB a
Quad.mapSize Unchecked sh -> sh
forall sh. Unchecked sh -> sh
PrivShape.deconsUnchecked (Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper sh a)
-> (Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   Quadratic pack prop lower upper (Unchecked sh) a
-> Quadratic pack prop lower upper (Unchecked sh) a
f (Quadratic pack prop lower upper (Unchecked sh) a
 -> Quadratic pack prop lower upper (Unchecked sh) a)
-> (Quadratic pack prop lower upper sh a
    -> Quadratic pack prop lower upper (Unchecked sh) a)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   (sh -> Unchecked sh)
-> Quadratic pack prop lower upper sh a
-> Quadratic pack prop lower upper (Unchecked sh) a
forall shA shB pack property lower upper a.
(C shA, C shB) =>
(shA -> shB)
-> Quadratic pack property lower upper shA a
-> Quadratic pack property lower upper shB a
Quad.mapSize sh -> Unchecked sh
forall sh. sh -> Unchecked sh
PrivShape.Unchecked