arithmoi-0.12.1.0: Efficient basic number-theoretic functions.

Copyright | (c) 2020 Andrew Lelechenko
License | MIT
Maintainer | Andrew Lelechenko <andrew.lelechenko@gmail.com>
Safe Haskell | Safe-Inferred
Language | Haskell2010

Math.NumberTheory.Primes.IntSet

Contents

- Set type
- Construction
- Insertion
- Deletion
- Query
- Combine
- Filter
- Folds
- Min/Max
- Conversion

Description

A newtype wrapper around `IntSet`.

This module is intended to be imported qualified, e. g.,

    import Math.NumberTheory.Primes.IntSet (PrimeIntSet)
    import qualified Math.NumberTheory.Primes.IntSet as PrimeIntSet

Synopsis

- data PrimeIntSet
- unPrimeIntSet :: PrimeIntSet -> IntSet
- singleton :: Prime Int -> PrimeIntSet
- fromList :: [Prime Int] -> PrimeIntSet
- fromAscList :: [Prime Int] -> PrimeIntSet
- fromDistinctAscList :: [Prime Int] -> PrimeIntSet
- insert :: Prime Int -> PrimeIntSet -> PrimeIntSet
- delete :: Int -> PrimeIntSet -> PrimeIntSet
- member :: Prime Int -> PrimeIntSet -> Bool
- notMember :: Prime Int -> PrimeIntSet -> Bool
- lookupEQ :: Int -> PrimeIntSet -> Maybe (Prime Int)
- lookupLT :: Int -> PrimeIntSet -> Maybe (Prime Int)
- lookupGT :: Int -> PrimeIntSet -> Maybe (Prime Int)
- lookupLE :: Int -> PrimeIntSet -> Maybe (Prime Int)
- lookupGE :: Int -> PrimeIntSet -> Maybe (Prime Int)
- null :: PrimeIntSet -> Bool
- size :: PrimeIntSet -> Int
- isSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool
- isProperSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool
- disjoint :: PrimeIntSet -> PrimeIntSet -> Bool
- difference :: PrimeIntSet -> IntSet -> PrimeIntSet
- (\\) :: PrimeIntSet -> IntSet -> PrimeIntSet
- symmetricDifference :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet
- intersection :: PrimeIntSet -> IntSet -> PrimeIntSet
- filter :: (Prime Int -> Bool) -> PrimeIntSet -> PrimeIntSet
- partition :: (Prime Int -> Bool) -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet)
- split :: Int -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet)
- splitMember :: Prime Int -> PrimeIntSet -> (PrimeIntSet, Bool, PrimeIntSet)
- splitLookupEQ :: Int -> PrimeIntSet -> (PrimeIntSet, Maybe (Prime Int), PrimeIntSet)
- splitRoot :: PrimeIntSet -> [PrimeIntSet]
- foldr :: forall b. (Prime Int -> b -> b) -> b -> PrimeIntSet -> b
- foldl :: forall a. (a -> Prime Int -> a) -> a -> PrimeIntSet -> a
- foldr' :: forall b. (Prime Int -> b -> b) -> b -> PrimeIntSet -> b
- foldl' :: forall a. (a -> Prime Int -> a) -> a -> PrimeIntSet -> a
- deleteMin :: PrimeIntSet -> PrimeIntSet
- deleteMax :: PrimeIntSet -> PrimeIntSet
- minView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet)
- maxView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet)
- toAscList :: PrimeIntSet -> [Prime Int]
- toDescList :: PrimeIntSet -> [Prime Int]

# Set type

data PrimeIntSet Source #

A set of `Prime` integers.

#### Instances

Instances details

Data PrimeIntSet Source # |

Instance details

Defined in Math.NumberTheory.Primes.IntSet

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PrimeIntSet -> c PrimeIntSet Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PrimeIntSet Source #

toConstr :: PrimeIntSet -> Constr Source #

dataTypeOf :: PrimeIntSet -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PrimeIntSet) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PrimeIntSet) Source #

gmapT :: (forall b. Data b => b -> b) -> PrimeIntSet -> PrimeIntSet Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PrimeIntSet -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PrimeIntSet -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> PrimeIntSet -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> PrimeIntSet -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> PrimeIntSet -> m PrimeIntSet Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PrimeIntSet -> m PrimeIntSet Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PrimeIntSet -> m PrimeIntSet Source #

Monoid PrimeIntSet Source # |
Instance details Defined in Math.NumberTheory.Primes.IntSet Methods mempty :: PrimeIntSet Source # mappend :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet Source # mconcat :: [PrimeIntSet] -> PrimeIntSet Source #
Semigroup PrimeIntSet Source # |
Instance details Defined in Math.NumberTheory.Primes.IntSet Methods (<>) :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet Source # sconcat :: NonEmpty PrimeIntSet -> PrimeIntSet Source # stimes :: Integral b => b -> PrimeIntSet -> PrimeIntSet Source #
IsList PrimeIntSet Source # |
Instance details Defined in Math.NumberTheory.Primes.IntSet Associated Types type Item PrimeIntSet Source # Methods fromList :: [Item PrimeIntSet] -> PrimeIntSet Source # fromListN :: Int -> [Item PrimeIntSet] -> PrimeIntSet Source # toList :: PrimeIntSet -> [Item PrimeIntSet] Source #
Show PrimeIntSet Source # |
Instance details Defined in Math.NumberTheory.Primes.IntSet Methods showsPrec :: Int -> PrimeIntSet -> ShowS Source # show :: PrimeIntSet -> String Source # showList :: [PrimeIntSet] -> ShowS Source #
NFData PrimeIntSet Source # |
Instance details Defined in Math.NumberTheory.Primes.IntSet Methods rnf :: PrimeIntSet -> () Source #
Eq PrimeIntSet Source # |
Instance details Defined in Math.NumberTheory.Primes.IntSet Methods (==) :: PrimeIntSet -> PrimeIntSet -> Bool Source # (/=) :: PrimeIntSet -> PrimeIntSet -> Bool Source #
Ord PrimeIntSet Source # |

Instance details

Defined in Math.NumberTheory.Primes.IntSet

Methods

compare :: PrimeIntSet -> PrimeIntSet -> Ordering Source #

(<) :: PrimeIntSet -> PrimeIntSet -> Bool Source #

(<=) :: PrimeIntSet -> PrimeIntSet -> Bool Source #

(>) :: PrimeIntSet -> PrimeIntSet -> Bool Source #

(>=) :: PrimeIntSet -> PrimeIntSet -> Bool Source #

max :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet Source #

min :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet Source #

type Item PrimeIntSet Source # |
Instance details Defined in Math.NumberTheory.Primes.IntSet type Item PrimeIntSet = Prime Int

unPrimeIntSet :: PrimeIntSet -> IntSet Source #

Convert to a set of integers.

# Construction

Use `mempty` to create an empty set.

singleton :: Prime Int -> PrimeIntSet Source #

Build a singleton set.

fromList :: [Prime Int] -> PrimeIntSet Source #

Build a set from a list of primes.

fromAscList :: [Prime Int] -> PrimeIntSet Source #

Build a set from an ascending list of primes (the precondition is not checked).

fromDistinctAscList :: [Prime Int] -> PrimeIntSet Source #

Build a set from an ascending list of distinct primes (the precondition is not checked).

# Insertion

insert :: Prime Int -> PrimeIntSet -> PrimeIntSet Source #

Insert a prime into the set.

# Deletion

delete :: Int -> PrimeIntSet -> PrimeIntSet Source #

Delete an integer from the set.

# Query

member :: Prime Int -> PrimeIntSet -> Bool Source #

Check whether the given prime is a member of the set.

notMember :: Prime Int -> PrimeIntSet -> Bool Source #

Check whether the given prime is not a member of the set.

lookupEQ :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #

Find a prime in the set, equal to the given integer, if any exists.

lookupLT :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #

Find the largest prime in the set, smaller than the given integer, if any exists.

lookupGT :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #

Find the smallest prime in the set, greater than the given integer, if any exists.

lookupLE :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #

Find the largest prime in the set, smaller or equal to the given integer, if any exists.

lookupGE :: Int -> PrimeIntSet -> Maybe (Prime Int) Source #

Find the smallest prime in the set, greater or equal to the given integer, if any exists.

null :: PrimeIntSet -> Bool Source #

Check whether the set is empty.

size :: PrimeIntSet -> Int Source #

Cardinality of the set.

isSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool Source #

Check whether the first argument is a subset of the second one.

isProperSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool Source #

Check whether the first argument is a proper subset of the second one.

disjoint :: PrimeIntSet -> PrimeIntSet -> Bool Source #

Check whether two sets are disjoint.

# Combine

Use `<>` for unions.

difference :: PrimeIntSet -> IntSet -> PrimeIntSet Source #

Difference between a set of primes and a set of integers.

(\\) :: PrimeIntSet -> IntSet -> PrimeIntSet infixl 9 Source #

An alias to `difference`.

symmetricDifference :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet Source #

Symmetric difference of two sets of primes.

intersection :: PrimeIntSet -> IntSet -> PrimeIntSet Source #

Intersection of a set of primes and a set of integers.

# Filter

filter :: (Prime Int -> Bool) -> PrimeIntSet -> PrimeIntSet Source #

Filter primes satisfying a predicate.

partition :: (Prime Int -> Bool) -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet) Source #

Partition primes according to a predicate.

split :: Int -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet) Source #

Split into primes strictly less and strictly greater than the first argument.

splitMember :: Prime Int -> PrimeIntSet -> (PrimeIntSet, Bool, PrimeIntSet) Source #

Simultaneous `split` and `member`.

splitLookupEQ :: Int -> PrimeIntSet -> (PrimeIntSet, Maybe (Prime Int), PrimeIntSet) Source #

Simultaneous `split` and `lookupEQ`.

splitRoot :: PrimeIntSet -> [PrimeIntSet] Source #

Decompose a set into pieces based on the structure of the underlying tree.

# Folds

foldr :: forall b. (Prime Int -> b -> b) -> b -> PrimeIntSet -> b Source #

Fold a set using the given right-associative operator.

foldl :: forall a. (a -> Prime Int -> a) -> a -> PrimeIntSet -> a Source #

Fold a set using the given left-associative operator.

foldr' :: forall b. (Prime Int -> b -> b) -> b -> PrimeIntSet -> b Source #

A strict version of `foldr`.

foldl' :: forall a. (a -> Prime Int -> a) -> a -> PrimeIntSet -> a Source #

A strict version of `foldl`.

# Min/Max

deleteMin :: PrimeIntSet -> PrimeIntSet Source #

Delete the smallest prime in the set.

deleteMax :: PrimeIntSet -> PrimeIntSet Source #

Delete the largest prime in the set.

minView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet) Source #

Split a set into the smallest prime and the rest, if non-empty.

maxView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet) Source #

Split a set into the largest prime and the rest, if non-empty.

# Conversion

toAscList :: PrimeIntSet -> [Prime Int] Source #

Convert the set to a list of ascending primes.

toDescList :: PrimeIntSet -> [Prime Int] Source #

Convert the set to a list of descending primes.