{-# LANGUAGE MultiParamTypeClasses #-}
module Data.Matroid.Typeclass.Defaults where
import Data.Set (Set)
import qualified Data.Set as S
rk :: (Set a -> Set a)
-> Set a
-> Int
rk :: (Set a -> Set a) -> Set a -> Int
rk Set a -> Set a
basis_m = Set a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (Set a -> Int) -> (Set a -> Set a) -> Set a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set a -> Set a
basis_m
indep :: (Set a -> Int)
-> Set a
-> Bool
indep :: (Set a -> Int) -> Set a -> Bool
indep Set a -> Int
rk_m Set a
x = Set a -> Int
rk_m Set a
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Set a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Set a
x
basis :: Ord a => (Set a -> Bool)
-> Set a
-> Set a
basis :: (Set a -> Bool) -> Set a -> Set a
basis Set a -> Bool
indep_m = (Set a -> a -> Set a) -> Set a -> Set a -> Set a
forall a b. (a -> b -> a) -> a -> Set b -> a
S.foldl' Set a -> a -> Set a
augmentIndep (forall a. Set a
S.empty :: Set a)
where
augmentIndep :: Set a -> a -> Set a
augmentIndep Set a
b0 a
x
| Set a -> Bool
indep_m Set a
b_aug = Set a
b_aug
| Bool
otherwise = Set a
b0
where
b_aug :: Set a
b_aug = a -> Set a -> Set a
forall a. Ord a => a -> Set a -> Set a
S.insert a
x Set a
b0
cl :: Ord a =>
(Set a -> Int)
-> Set a
-> Set a
-> Set a
cl :: (Set a -> Int) -> Set a -> Set a -> Set a
cl Set a -> Int
rk_m Set a
groundset_m Set a
x = (Set a -> a -> Set a) -> Set a -> Set a -> Set a
forall a b. (a -> b -> a) -> a -> Set b -> a
S.foldl' Set a -> a -> Set a
augmentDep Set a
x (Set a -> Set a) -> Set a -> Set a
forall a b. (a -> b) -> a -> b
$ Set a
groundset_m
where
rank_x :: Int
rank_x = Set a -> Int
rk_m Set a
x
augmentDep :: Set a -> a -> Set a
augmentDep Set a
f0 a
e
| Set a -> Int
rk_m Set a
f_aug Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
rank_x = Set a
f_aug
| Bool
otherwise = Set a
f0
where
f_aug :: Set a
f_aug = a -> Set a -> Set a
forall a. Ord a => a -> Set a -> Set a
S.insert a
e Set a
f0
loops :: (Set a -> Set a) -> Set a
loops :: (Set a -> Set a) -> Set a
loops Set a -> Set a
cl_m = Set a -> Set a
cl_m Set a
forall a. Set a
S.empty
coRk :: Ord a =>
(Set a -> Int)
-> Set a
-> Set a -> Int
coRk :: (Set a -> Int) -> Set a -> Set a -> Int
coRk Set a -> Int
rk_m Set a
groundset_m Set a
x = (Set a -> Int
rk_m Set a
e_minus_x) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Set a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Set a
x) Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Set a -> Int
rk_m Set a
groundset_m)
where e_minus_x :: Set a
e_minus_x = Set a
groundset_m Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
`S.difference` Set a
x
coloops :: Ord a =>
(Set a -> Int)
-> Set a
-> Set a
coloops :: (Set a -> Int) -> Set a -> Set a
coloops Set a -> Int
rk_m Set a
e = a -> Bool
isColoop (a -> Bool) -> Set a -> Set a
forall a. (a -> Bool) -> Set a -> Set a
`S.filter` Set a
e
where rkM :: Int
rkM = Set a -> Int
rk_m Set a
e
isColoop :: a -> Bool
isColoop a
x =
Set a -> Int
rk_m (Set a
e Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
`S.difference` a -> Set a
forall a. a -> Set a
S.singleton a
x) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
rkM Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1