{-# LANGUAGE BangPatterns #-}
module Math.Algebra.Jack.Internal
  where
import qualified Algebra.Ring    as AR
import           Data.List.Index ( iconcatMap )

type Partition = [Int]

_isPartition :: Partition -> Bool
_isPartition :: Partition -> Bool
_isPartition []  = Bool
True
_isPartition [Int
x] = Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
_isPartition (Int
x:xs :: Partition
xs@(Int
y:Partition
_)) = (Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
y) Bool -> Bool -> Bool
&& Partition -> Bool
_isPartition Partition
xs

_diffSequence :: [Int] -> [Int]
_diffSequence :: Partition -> Partition
_diffSequence = Partition -> Partition
forall a. Num a => [a] -> [a]
go where
  go :: [a] -> [a]
go (a
x:ys :: [a]
ys@(a
y:[a]
_)) = (a
xa -> a -> a
forall a. Num a => a -> a -> a
-a
y) a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
go [a]
ys 
  go [a
x] = [a
x]
  go []  = []

_dualPartition :: Partition -> Partition
_dualPartition :: Partition -> Partition
_dualPartition [] = []
_dualPartition Partition
xs = Int -> Partition -> Partition -> Partition
forall t. Num t => t -> Partition -> Partition -> [t]
go Int
0 (Partition -> Partition
_diffSequence Partition
xs) [] where
  go :: t -> Partition -> Partition -> [t]
go !t
i (Int
d:Partition
ds) Partition
acc = t -> Partition -> Partition -> [t]
go (t
it -> t -> t
forall a. Num a => a -> a -> a
+t
1) Partition
ds (Int
dInt -> Partition -> Partition
forall a. a -> [a] -> [a]
:Partition
acc)
  go t
n  []     Partition
acc = t -> Partition -> [t]
forall t. Num t => t -> Partition -> [t]
finish t
n Partition
acc 
  finish :: t -> Partition -> [t]
finish !t
j (Int
k:Partition
ks) = Int -> t -> [t]
forall a. Int -> a -> [a]
replicate Int
k t
j [t] -> [t] -> [t]
forall a. [a] -> [a] -> [a]
++ t -> Partition -> [t]
finish (t
jt -> t -> t
forall a. Num a => a -> a -> a
-t
1) Partition
ks
  finish t
_  []     = []

_ij :: Partition -> ([Int], [Int])
_ij :: Partition -> (Partition, Partition)
_ij Partition
lambda =
  (
    (Int -> Int -> Partition) -> Partition -> Partition
forall a b. (Int -> a -> [b]) -> [a] -> [b]
iconcatMap (\Int
i Int
a ->  Int -> Int -> Partition
forall a. Int -> a -> [a]
replicate Int
a (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)) Partition
lambda,
    (Int -> Partition) -> Partition -> Partition
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\Int
a -> [Int
1 .. Int
a]) ((Int -> Bool) -> Partition -> Partition
forall a. (a -> Bool) -> [a] -> [a]
filter (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>Int
0) Partition
lambda)
  )

_convParts :: Num b => [Int] -> ([b], [b])
_convParts :: Partition -> ([b], [b])
_convParts Partition
lambda =
  ((Int -> b) -> Partition -> [b]
forall a b. (a -> b) -> [a] -> [b]
map Int -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral Partition
lambda, (Int -> b) -> Partition -> [b]
forall a b. (a -> b) -> [a] -> [b]
map Int -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Partition -> Partition
_dualPartition Partition
lambda))

_N :: [Int] -> [Int] -> Int
_N :: Partition -> Partition -> Int
_N Partition
lambda Partition
mu = Partition -> Int
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum (Partition -> Int) -> Partition -> Int
forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int) -> Partition -> Partition -> Partition
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Int -> Int -> Int
forall a. Num a => a -> a -> a
(*) Partition
mu Partition
prods
  where
  prods :: Partition
prods = (Int -> Int) -> Partition -> Partition
forall a b. (a -> b) -> [a] -> [b]
map (\Int
i -> Partition -> Int
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product (Partition -> Int) -> Partition -> Int
forall a b. (a -> b) -> a -> b
$ Int -> Partition -> Partition
forall a. Int -> [a] -> [a]
drop Int
i ((Int -> Int) -> Partition -> Partition
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) Partition
lambda)) [Int
1 .. Partition -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Partition
lambda]

hookLengths :: Fractional a => Partition -> a -> [a]
hookLengths :: Partition -> a -> [a]
hookLengths Partition
lambda a
alpha = [a]
upper [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a]
lower
  where
    (Partition
i, Partition
j) = Partition -> (Partition, Partition)
_ij Partition
lambda
    ([a]
lambda', [a]
lambdaConj') = Partition -> ([a], [a])
forall b. Num b => Partition -> ([b], [b])
_convParts Partition
lambda
    upper :: [a]
upper = (Int -> Int -> a) -> Partition -> Partition -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ([a] -> [a] -> Int -> Int -> a
fup [a]
lambdaConj' [a]
lambda') Partition
i Partition
j
      where
        fup :: [a] -> [a] -> Int -> Int -> a
fup [a]
x [a]
y Int
ii Int
jj =
          [a]
x[a] -> Int -> a
forall a. [a] -> Int -> a
!!(Int
jjInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) a -> a -> a
forall a. Num a => a -> a -> a
- Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ii a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha a -> a -> a
forall a. Num a => a -> a -> a
* ([a]
y[a] -> Int -> a
forall a. [a] -> Int -> a
!!(Int
iiInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) a -> a -> a
forall a. Num a => a -> a -> a
- Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
jj a -> a -> a
forall a. Num a => a -> a -> a
+ a
1)
    lower :: [a]
lower = (Int -> Int -> a) -> Partition -> Partition -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ([a] -> [a] -> Int -> Int -> a
flow [a]
lambdaConj' [a]
lambda') Partition
i Partition
j
      where
        flow :: [a] -> [a] -> Int -> Int -> a
flow [a]
x [a]
y Int
ii Int
jj =
          [a]
x[a] -> Int -> a
forall a. [a] -> Int -> a
!!(Int
jjInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) a -> a -> a
forall a. Num a => a -> a -> a
- Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ii a -> a -> a
forall a. Num a => a -> a -> a
+ a
1 a -> a -> a
forall a. Num a => a -> a -> a
+ a
alpha a -> a -> a
forall a. Num a => a -> a -> a
* ([a]
y[a] -> Int -> a
forall a. [a] -> Int -> a
!!(Int
iiInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) a -> a -> a
forall a. Num a => a -> a -> a
- Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
jj)

hookLengths' :: (Fractional a, AR.C a) => Partition -> a -> [a]
hookLengths' :: Partition -> a -> [a]
hookLengths' = Partition -> a -> [a]
forall a. Fractional a => Partition -> a -> [a]
hookLengths

_betaratio :: Fractional a => Partition -> Partition -> Int -> a -> a
_betaratio :: Partition -> Partition -> Int -> a -> a
_betaratio Partition
kappa Partition
mu Int
k 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
    mukm1 :: Int
mukm1 = Partition
mu Partition -> Int -> Int
forall a. [a] -> Int -> a
!! (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)
    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 Int
mukm1
    u :: [a]
u = (Int -> Int -> a) -> Partition -> Partition -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
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)
                [Int
1 .. Int
k] Partition
kappa 
    v :: [a]
v = (Int -> Int -> a) -> Partition -> Partition -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
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)
                [Int
1 .. Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] Partition
mu 
    w :: [a]
w = (Int -> Int -> a) -> Partition -> Partition -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
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
1 .. Int
mukm1Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1] (Partition -> Partition
_dualPartition Partition
mu)
    prod1 :: a
prod1 = [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (\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)) [a]
u
    prod2 :: a
prod2 = [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (\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) [a]
v
    prod3 :: a
prod3 = [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
product ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (\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) [a]
w

_betaratio' :: (Fractional a, AR.C a) => [Int] -> [Int] -> Int -> a -> a
_betaratio' :: Partition -> Partition -> Int -> a -> a
_betaratio' = Partition -> Partition -> Int -> a -> a
forall a. Fractional a => Partition -> Partition -> Int -> a -> a
_betaratio