species-0.4: Computational combinatorial species

Copyright(c) Brent Yorgey 2010
LicenseBSD-style (see LICENSE)
Maintainerbyorgey@cis.upenn.edu
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Math.Combinatorics.Species.Util.Interval

Contents

Description

A simple implementation of intervals of natural numbers, for use in tracking the possible sizes of structures of a species. For example, the species x + x^2 + x^3 will correspond to the interval [1,3].

Synopsis

The NatO type

data NatO Source #

NatO is an explicit representation of the co-inductive Nat type which admits an infinite value, omega. Our intuition for the semantics of NatO comes from thinking of it as an efficient representation of lazy unary natural numbers, except that we can actually test for omega in finite time.

Instances

Eq NatO Source # 

Methods

(==) :: NatO -> NatO -> Bool #

(/=) :: NatO -> NatO -> Bool #

Ord NatO Source # 

Methods

compare :: NatO -> NatO -> Ordering #

(<) :: NatO -> NatO -> Bool #

(<=) :: NatO -> NatO -> Bool #

(>) :: NatO -> NatO -> Bool #

(>=) :: NatO -> NatO -> Bool #

max :: NatO -> NatO -> NatO #

min :: NatO -> NatO -> NatO #

Show NatO Source # 

Methods

showsPrec :: Int -> NatO -> ShowS #

show :: NatO -> String #

showList :: [NatO] -> ShowS #

C NatO Source #

In fact, NatO forms a semiring, with 1 as the multiplicative unit.

Methods

(*) :: NatO -> NatO -> NatO #

one :: NatO #

fromInteger :: Integer -> NatO #

(^) :: NatO -> Integer -> NatO #

C NatO Source #

NatO forms an additive monoid, with zero as the identity. This doesn't quite fit since Additive.C is supposed to be for groups, so the negate method just throws an error. But we'll never use it and NatO won't be directly exposed to users of the species library anyway.

Methods

zero :: NatO #

(+) :: NatO -> NatO -> NatO #

(-) :: NatO -> NatO -> NatO #

negate :: NatO -> NatO #

omega :: NatO Source #

The infinite NatO value.

natO :: (Integer -> a) -> a -> NatO -> a Source #

Eliminator for NatO values.

The Interval type

data Interval Source #

An Interval is a closed range of consecutive integers. Both endpoints are represented as NatO values. For example, [2,5] represents the values 2,3,4,5; [2,omega] represents all integers greater than 1; intervals where the first endpoint is greater than the second also represent the empty interval.

Instances

Show Interval Source # 
C Interval Source #

Intervals form a semiring, with the multiplication operation being pointwise multiplication of their endpoints.

C Interval Source #

Intervals can be added by adding their endpoints pointwise.

iLow :: Interval -> NatO Source #

Get the lower endpoint of an Interval

iHigh :: Interval -> NatO Source #

Get the upper endpoint of an Interval

Interval operations

decrI :: Interval -> Interval Source #

Decrement both endpoints of an interval.

union :: Interval -> Interval -> Interval Source #

The union of two intervals is the smallest interval containing both.

intersect :: Interval -> Interval -> Interval Source #

The intersection of two intervals is the largest interval contained in both.

elem :: Integer -> Interval -> Bool Source #

Test a given integer for interval membership.

toList :: Interval -> [Integer] Source #

Convert an interval to a list of Integers.

Constructing intervals

natsI :: Interval Source #

The range [0,omega] containing all natural numbers.

fromI :: NatO -> Interval Source #

Construct an open range [n,omega].

emptyI :: Interval Source #

The empty interval.

omegaI :: Interval Source #

The interval which contains only omega.