{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Math.HypergeoMatrix.Internal where
import Data.Complex
import Data.Ratio
import Data.Maybe
import Data.Sequence (Seq ((:<|), (:|>), Empty), elemIndexL,
index, (!?), (><), (|>))
import qualified Data.Sequence as S
import Math.HypergeoMatrix.Gaussian
class BaseFrac a where
type family BaseFracType a
type BaseFracType a = a
inject :: BaseFracType a -> a
default inject :: BaseFracType a ~ a => BaseFracType a -> a
inject = BaseFracType a -> a
forall a. a -> a
id
instance Integral a => BaseFrac (Ratio a)
instance BaseFrac Float
instance BaseFrac Double
instance BaseFrac GaussianRational where
type BaseFracType GaussianRational = Rational
inject :: BaseFracType GaussianRational -> GaussianRational
inject BaseFracType GaussianRational
x = Rational
BaseFracType GaussianRational
x Rational -> Rational -> GaussianRational
+: Rational
0
instance Num a => BaseFrac (Complex a) where
type BaseFracType (Complex a) = a
inject :: BaseFracType (Complex a) -> Complex a
inject BaseFracType (Complex a)
x = a
BaseFracType (Complex a)
x a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
0
_diffSequence :: Seq Int -> Seq Int
_diffSequence :: Seq Int -> Seq Int
_diffSequence (Int
x :<| ys :: Seq Int
ys@(Int
y :<| Seq Int
_)) = (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
y) Int -> Seq Int -> Seq Int
forall a. a -> Seq a -> Seq a
:<| Seq Int -> Seq Int
_diffSequence Seq Int
ys
_diffSequence Seq Int
x = Seq Int
x
_dualPartition :: Seq Int -> Seq Int
_dualPartition :: Seq Int -> Seq Int
_dualPartition Seq Int
Empty = Seq Int
forall a. Seq a
S.empty
_dualPartition Seq Int
xs = Int -> Seq Int -> Seq Int -> Seq Int
forall t. Num t => t -> Seq Int -> Seq Int -> Seq t
go Int
0 (Seq Int -> Seq Int
_diffSequence Seq Int
xs) Seq Int
forall a. Seq a
S.empty
where
go :: t -> Seq Int -> Seq Int -> Seq t
go !t
i (Int
d :<| Seq Int
ds) Seq Int
acc = t -> Seq Int -> Seq Int -> Seq t
go (t
i t -> t -> t
forall a. Num a => a -> a -> a
+ t
1) Seq Int
ds (Int
d Int -> Seq Int -> Seq Int
forall a. a -> Seq a -> Seq a
:<| Seq Int
acc)
go t
n Seq Int
Empty Seq Int
acc = t -> Seq Int -> Seq t
forall t. Num t => t -> Seq Int -> Seq t
finish t
n Seq Int
acc
finish :: t -> Seq Int -> Seq t
finish !t
j (Int
k :<| Seq Int
ks) = Int -> t -> Seq t
forall a. Int -> a -> Seq a
S.replicate Int
k t
j Seq t -> Seq t -> Seq t
forall a. Seq a -> Seq a -> Seq a
>< t -> Seq Int -> Seq t
finish (t
j t -> t -> t
forall a. Num a => a -> a -> a
- t
1) Seq Int
ks
finish t
_ Seq Int
Empty = Seq t
forall a. Seq a
S.empty
_betaratio :: (Fractional a, BaseFrac a)
=> Seq Int -> Seq Int -> Int -> BaseFracType a -> a
_betaratio :: Seq Int -> Seq Int -> Int -> BaseFracType a -> a
_betaratio Seq Int
kappa Seq Int
mu Int
k BaseFracType a
alpha = a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
* a
prod1 a -> a -> a
forall a. Num a => a -> a -> a
* a
prod2 a -> a -> a
forall a. Num a => a -> a -> a
* a
prod3
where
alpha' :: a
alpha' = BaseFracType a -> a
forall a. BaseFrac a => BaseFracType a -> a
inject BaseFracType a
alpha
t :: a
t = Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
k a -> a -> a
forall a. Num a => a -> a -> a
- a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
* Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Seq Int
mu Seq Int -> Int -> Int
forall a. Seq a -> Int -> a
`index` (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
ss :: Seq Int
ss = [Int] -> Seq Int
forall a. [a] -> Seq a
S.fromList [Int
1 .. Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
sss :: Seq Int
sss = Seq Int
ss Seq Int -> Int -> Seq Int
forall a. Seq a -> a -> Seq a
|> Int
k
u :: Seq a
u =
(Int -> Int -> a) -> Seq Int -> Seq Int -> Seq a
forall a b c. (a -> b -> c) -> Seq a -> Seq b -> Seq c
S.zipWith
(\Int
s Int
kap -> a
t a -> a -> a
forall a. Num a => a -> a -> a
+ a
1 a -> a -> a
forall a. Num a => a -> a -> a
- Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
s a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
* Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
kap)
Seq Int
sss (Int -> Seq Int -> Seq Int
forall a. Int -> Seq a -> Seq a
S.take Int
k Seq Int
kappa)
v :: Seq a
v =
(Int -> Int -> a) -> Seq Int -> Seq Int -> Seq a
forall a b c. (a -> b -> c) -> Seq a -> Seq b -> Seq c
S.zipWith
(\Int
s Int
m -> a
t a -> a -> a
forall a. Num a => a -> a -> a
- Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
s a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
* Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
m)
Seq Int
ss (Int -> Seq Int -> Seq Int
forall a. Int -> Seq a -> Seq a
S.take (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Seq Int
mu)
l :: Int
l = Seq Int
mu Seq Int -> Int -> Int
forall a. Seq a -> Int -> a
`index` (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
mu' :: Seq Int
mu' = Int -> Seq Int -> Seq Int
forall a. Int -> Seq a -> Seq a
S.take Int
l (Seq Int -> Seq Int
_dualPartition Seq Int
mu)
w :: Seq a
w =
(Int -> Int -> a) -> Seq Int -> Seq Int -> Seq a
forall a b c. (a -> b -> c) -> Seq a -> Seq b -> Seq c
S.zipWith
(\Int
s Int
m -> Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
m a -> a -> a
forall a. Num a => a -> a -> a
- a
t a -> a -> a
forall a. Num a => a -> a -> a
- a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
* Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
s)
([Int] -> Seq Int
forall a. [a] -> Seq a
S.fromList [Int
1 .. Int
l]) Seq Int
mu'
prod1 :: a
prod1 = Seq a -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product (Seq a -> a) -> Seq a -> a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> Seq a -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
x -> a
x a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
- a
1)) Seq a
u
prod2 :: a
prod2 = Seq a -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product (Seq a -> a) -> Seq a -> a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> Seq a -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
x -> (a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha') a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
x) Seq a
v
prod3 :: a
prod3 = Seq a -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product (Seq a -> a) -> Seq a -> a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> Seq a -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
x -> (a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha') a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
x) Seq a
w
_T :: (Fractional a, Eq a, BaseFrac a)
=> BaseFracType a -> [a] -> [a] -> Seq Int -> a
_T :: BaseFracType a -> [a] -> [a] -> Seq Int -> a
_T BaseFracType a
alpha [a]
a [a]
b Seq Int
kappa
| Seq Int -> Bool
forall a. Seq a -> Bool
S.null Seq Int
kappa Bool -> Bool -> Bool
|| Seq Int
kappa Seq Int -> Int -> Maybe Int
forall a. Seq a -> Int -> Maybe a
!? Int
0 Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0 = a
1
| a
prod1_den a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 = a
0
| Bool
otherwise = a
prod1_numa -> a -> a
forall a. Fractional a => a -> a -> a
/a
prod1_den a -> a -> a
forall a. Num a => a -> a -> a
* a
prod2 a -> a -> a
forall a. Num a => a -> a -> a
* a
prod3
where
alpha' :: a
alpha' = BaseFracType a -> a
forall a. BaseFrac a => BaseFracType a -> a
inject BaseFracType a
alpha
lkappa :: Int
lkappa = Seq Int -> Int
forall a. Seq a -> Int
S.length Seq Int
kappa Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
kappai :: Int
kappai = Seq Int
kappa Seq Int -> Int -> Int
forall a. Seq a -> Int -> a
`index` Int
lkappa
kappai' :: a
kappai' = Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
kappai
i :: a
i = Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
lkappa
c :: a
c = a
kappai' a -> a -> a
forall a. Num a => a -> a -> a
- a
1 a -> a -> a
forall a. Num a => a -> a -> a
- a
i a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
alpha'
d :: a
d = a
kappai' a -> a -> a
forall a. Num a => a -> a -> a
* a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
- a
i a -> a -> a
forall a. Num a => a -> a -> a
- a
1
s :: Seq a
s = (Int -> a) -> Seq Int -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Int] -> Seq Int
forall a. [a] -> Seq a
S.fromList [Int
1 .. Int
kappai Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1])
kappa' :: Seq a
kappa' = Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> a) -> Seq Int -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Seq Int -> Seq Int
forall a. Int -> Seq a -> Seq a
S.take Int
kappai (Seq Int -> Seq Int
_dualPartition Seq Int
kappa)
e :: Seq a
e = (a -> a -> a) -> Seq a -> Seq a -> Seq a
forall a b c. (a -> b -> c) -> Seq a -> Seq b -> Seq c
S.zipWith (\a
x a
y -> a
d a -> a -> a
forall a. Num a => a -> a -> a
- a
x a -> a -> a
forall a. Num a => a -> a -> a
* a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
+ a
y) Seq a
s Seq a
kappa'
g :: Seq a
g = (a -> a) -> Seq a -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) Seq a
e
s' :: Seq a
s' = (Int -> a) -> Seq Int -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Int] -> Seq Int
forall a. [a] -> Seq a
S.fromList [Int
1 .. Int
lkappa])
f :: Seq a
f = (a -> a -> a) -> Seq a -> Seq a -> Seq a
forall a b c. (a -> b -> c) -> Seq a -> Seq b -> Seq c
S.zipWith (\a
x a
y -> a
y a -> a -> a
forall a. Num a => a -> a -> a
* a
alpha' a -> a -> a
forall a. Num a => a -> a -> a
- a
x a -> a -> a
forall a. Num a => a -> a -> a
- a
d) Seq a
s' ((Int -> a) -> Seq Int -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Seq Int
kappa)
h :: Seq a
h = (a -> a) -> Seq a -> Seq a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha') Seq a
f
l :: Seq a
l = (a -> a -> a) -> Seq a -> Seq a -> Seq a
forall a b c. (a -> b -> c) -> Seq a -> Seq b -> Seq c
S.zipWith a -> a -> a
forall a. Num a => a -> a -> a
(*) Seq a
h Seq a
f
prod1_num :: a
prod1_num = [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product ((a -> a) -> [a] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a -> a
forall a. Num a => a -> a -> a
+ a
c) [a]
a)
prod1_den :: a
prod1_den = [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product ((a -> a) -> [a] -> [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a -> a
forall a. Num a => a -> a -> a
+ a
c) [a]
b)
prod2 :: a
prod2 =
Seq a -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product (Seq a -> a) -> Seq a -> a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> Seq a -> Seq a -> Seq a
forall a b c. (a -> b -> c) -> Seq a -> Seq b -> Seq c
S.zipWith (\a
x a
y -> (a
y a -> a -> a
forall a. Num a => a -> a -> a
- a
alpha') a -> a -> a
forall a. Num a => a -> a -> a
* a
x a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
y a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha')) Seq a
e Seq a
g
prod3 :: a
prod3 = Seq a -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product (Seq a -> a) -> Seq a -> a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a -> a) -> Seq a -> Seq a -> Seq a -> Seq a
forall a b c d.
(a -> b -> c -> d) -> Seq a -> Seq b -> Seq c -> Seq d
S.zipWith3 (\a
x a
y a
z -> (a
z a -> a -> a
forall a. Num a => a -> a -> a
- a
x) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
z a -> a -> a
forall a. Num a => a -> a -> a
+ a
y)) Seq a
f Seq a
h Seq a
l
a008284 :: [[Int]]
a008284 :: [[Int]]
a008284 = [Int
1] [Int] -> [[Int]] -> [[Int]]
forall a. a -> [a] -> [a]
: [[Int]] -> [[Int]]
forall a. Num a => [[a]] -> [[a]]
f [[Int
1]]
where
f :: [[a]] -> [[a]]
f [[a]]
xss = [a]
ys [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]] -> [[a]]
f ([a]
ys [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]]
xss)
where
ys :: [a]
ys = ([a] -> a) -> [[a]] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ((Int -> [a] -> [a]) -> [Int] -> [[a]] -> [[a]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take [Int
1 ..] [[a]]
xss) [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a
1]
_P :: Int -> Int -> Int
_P :: Int -> Int -> Int
_P Int
m Int
n = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum (([Int] -> [Int]) -> [[Int]] -> [Int]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
m Int
n)) (Int -> [[Int]] -> [[Int]]
forall a. Int -> [a] -> [a]
take Int
m [[Int]]
a008284))
_dico :: Int -> Int -> Seq (Maybe Int)
_dico :: Int -> Int -> Seq (Maybe Int)
_dico Int
pmn Int
m = Bool -> Seq (Maybe Int) -> Seq (Maybe Int)
go Bool
False Seq (Maybe Int)
forall a. Seq a
S.empty
where
go :: Bool -> Seq (Maybe Int) -> Seq (Maybe Int)
go :: Bool -> Seq (Maybe Int) -> Seq (Maybe Int)
go Bool
k !Seq (Maybe Int)
d'
| Bool
k = Seq (Maybe Int)
d'
| Bool
otherwise = Int
-> [Int]
-> [Int]
-> [Int]
-> Int
-> Seq (Maybe Int)
-> Maybe Int
-> Seq (Maybe Int)
inner Int
0 [Int
0] [Int
m] [Int
m] Int
0 Seq (Maybe Int)
d' Maybe Int
forall a. Maybe a
Nothing
where
inner :: Int -> [Int] -> [Int] -> [Int] -> Int
-> Seq (Maybe Int) -> Maybe Int -> Seq (Maybe Int)
inner :: Int
-> [Int]
-> [Int]
-> [Int]
-> Int
-> Seq (Maybe Int)
-> Maybe Int
-> Seq (Maybe Int)
inner Int
i ![Int]
a ![Int]
b ![Int]
c !Int
end !Seq (Maybe Int)
d !Maybe Int
dlast
| Maybe Int
dlast Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Maybe Int
forall a. a -> Maybe a
Just Int
pmn = Bool -> Seq (Maybe Int) -> Seq (Maybe Int)
go Bool
True Seq (Maybe Int)
d
| Bool
otherwise =
let bi :: Int
bi = [Int]
b [Int] -> Int -> Int
forall a. [a] -> Int -> a
!! Int
i
in if Int
bi Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then let l :: Int
l = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
bi ([Int]
c [Int] -> Int -> Int
forall a. [a] -> Int -> a
!! Int
i)
in let ddlast :: Maybe Int
ddlast = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$ Int
end Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in let dd :: Seq (Maybe Int)
dd = Seq (Maybe Int)
d Seq (Maybe Int) -> Maybe Int -> Seq (Maybe Int)
forall a. Seq a -> a -> Seq a
|> Maybe Int
ddlast
in let range1l :: [Int]
range1l = [Int
1 .. Int
l]
in Int
-> [Int]
-> [Int]
-> [Int]
-> Int
-> Seq (Maybe Int)
-> Maybe Int
-> Seq (Maybe Int)
inner
(Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
([Int]
a [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ [Int
end Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 .. Int
end Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
l])
([Int]
b [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int
bi Int -> Int -> Int
forall a. Num a => a -> a -> a
-) [Int]
range1l)
([Int]
c [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ [Int]
range1l)
(Int
end Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
l)
Seq (Maybe Int)
dd
Maybe Int
ddlast
else Int
-> [Int]
-> [Int]
-> [Int]
-> Int
-> Seq (Maybe Int)
-> Maybe Int
-> Seq (Maybe Int)
inner (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [Int]
a [Int]
b [Int]
c Int
end (Seq (Maybe Int)
d Seq (Maybe Int) -> Maybe Int -> Seq (Maybe Int)
forall a. Seq a -> a -> Seq a
|> Maybe Int
forall a. Maybe a
Nothing) Maybe Int
forall a. Maybe a
Nothing
_nkappa :: Seq (Maybe Int) -> Seq Int -> Int
_nkappa :: Seq (Maybe Int) -> Seq Int -> Int
_nkappa Seq (Maybe Int)
dico (Seq Int
kappa0 :|> Int
kappan) =
Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust (Seq (Maybe Int)
dico Seq (Maybe Int) -> Int -> Maybe Int
forall a. Seq a -> Int -> a
`S.index` Seq (Maybe Int) -> Seq Int -> Int
_nkappa Seq (Maybe Int)
dico Seq Int
kappa0) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
kappan Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
_nkappa Seq (Maybe Int)
_ Seq Int
Empty = Int
0
cleanPart :: Seq Int -> Seq Int
cleanPart :: Seq Int -> Seq Int
cleanPart Seq Int
kappa =
let i :: Maybe Int
i = Int -> Seq Int -> Maybe Int
forall a. Eq a => a -> Seq a -> Maybe Int
elemIndexL Int
0 Seq Int
kappa
in if Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust Maybe Int
i
then Int -> Seq Int -> Seq Int
forall a. Int -> Seq a -> Seq a
S.take (Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust Maybe Int
i) Seq Int
kappa
else Seq Int
kappa