cifl-math-library-1.1.1.0: Math libraries
Copyright(c) Esa Pulkkinen 2018
LicenseLGPL
Maintaineresa.pulkkinen@iki.fi
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Math.Number.Stream

Description

This module implements lazy infinite streams, stream generating functions and lots of operations on the lazy streams. some examples for use of this module:

fib = 1 `div` (1 - s_z - s_z*s_z)
pascal_triangle = Matrix $ 1 `div` (1 - s_z - s_z2*s_z)
take 4 fib == [1,1,2,3]
alternating_bits = cycle [0,1]
Synopsis

Documentation

(!) :: Stream a -> Integer -> a infixl 4 Source #

matrix_exponential_stream :: (Fractional (Scalar ((g :*: g) a)), Diagonalizable g a, LinearTransform g g a, SupportsMatrixMultiplication g g g a, InnerProductSpace (g a), VectorSpace ((g :*: g) a), Num ((g :*: g) a), Scalar (g (g a)) ~ Scalar (g a), Scalar (g a) ~ a, Scalar a ~ a) => (g :*: g) a -> Stream ((g :*: g) a) Source #

cmap :: (Limiting s a, Limiting s b) => (a -> b) -> Closure s a -> Closure s b Source #

mapping operation for closures. Note we cannot make this a Functor instance due to constraint in the type.

cliftA2 :: (Limiting s a, Limiting s b, Limiting s c) => (a -> b -> c) -> Closure s a -> Closure s b -> Closure s c Source #

close :: Limiting Stream a => a -> Closure Stream a Source #

operation for producing a closure out of single element.

(.>>=.) :: (Limiting s a, Limiting s b) => Closure s a -> (a -> Closure s b) -> Closure s b Source #

Monadic bind operation for closures, again cannot be made instance of Monad.

stream_identity_matrix :: Integral a => (Stream :*: Stream) a Source #

This implementation of infinite identity matrix requires Integral constraint. it is not as efficient as identity, but is implemented using generating functions.

stream_diagonal :: (Closed a, ConjugateSymmetric a, Num a) => (Stream a :-> Stream a) -> Stream a Source #

stream_diagonal is the "depth-first" traversal over two-dimensional streams, where the choice always goes to diagonal elements.

stream_diagonal (matrix f x y) == liftA2 f x y

ssum :: (Closed a, Num a) => Stream a -> a Source #

sum of a stream elements.

svsum :: (Closed a, VectorSpace a) => Stream a -> a Source #

sub_member :: Ord a => Stream a -> a -> Bool Source #

bind_matrix :: (ConjugateSymmetric a, Num a, Closed a) => (Stream a :-> Stream a) -> (a -> Stream a -> Stream a -> Stream b) -> Stream b Source #

bind diagonal element and horizontal and vertical strip

stream_as_diagonal :: (ConjugateSymmetric a, Num a, Closed a) => Stream a -> Stream a :-> Stream a Source #

stream matrix with a specified diagonal, other elements are zero.

add_row :: f a -> (Stream :*: f) a -> (Stream :*: f) a Source #

adding a row to a matrix.

first_row :: (Stream :*: g) a -> g a Source #

first_column :: Functor f => (f :*: Stream) a -> f a Source #

remove_row :: (Stream :*: f) a -> (Stream :*: f) a Source #

add_column :: Applicative f => f a -> (f :*: Stream) a -> (f :*: Stream) a Source #

adding a column to a matrix.

remove_column :: Functor f => (f :*: Stream) a -> (f :*: Stream) a Source #

join3 :: (ConjugateSymmetric a, Num a, Closed a) => (Stream a :-> Stream a) -> Stream (a, a, a) Source #

convolution_product_matrix :: (Functor m, Functor n, Num a) => (m :*: Stream) a -> (n :*: Stream) a -> (m :*: n) (Stream a) Source #

sum_seq :: Num a => Seq a -> a Source #

compose :: (ConjugateSymmetric a, Num a, Eq a) => Stream a -> Stream a -> Stream a Source #

For streams \(b = (b_i)_{i\in{\mathbf{N}}}\) and \(a = (a_i)_{i\in{\mathbf{N}}}\) representing generating functions \(g(z) = \sum_{i=0}^{\infty}{b_iz^i}\) and \(f(z) = \sum_{i=1}^{\infty}{a_iz^i}\) where \(a_0 = 0\), this computes: \[(g \circ f)(z) = g(f(z)) = \sum_{i=0}^{\infty}{b_i(f(z))^i} = \sum_{i=0}^{\infty}(b_i(\sum_{j=1}^{\infty}{a_jz^j})^i)\]

Note that identity of composition on the right is s_z. That is, \(s \circ s_z = s\). https://en.wikipedia.org/wiki/Formal_power_series

matrix_convolution :: (SupportsMatrixMultiplication f g h a, VectorSpace ((f :*: h) a)) => Stream ((f :*: g) a) -> Stream ((g :*: h) a) -> Stream ((f :*: h) a) Source #

matrix_convolution_product :: (ConjugateSymmetric a, Fractional a) => (Stream :*: Stream) a -> (Stream :*: Stream) a -> (Stream :*: Stream) a Source #

computes average to normalize the matrix

distance_product :: (Floating a, ConjugateSymmetric a) => Stream a -> Stream a -> Stream a Source #

distance_product a b computes \[l_k = \sqrt{\sum_{i+j=k}a_ib_j^{*}}\].

lu_decomposition_stream_matrix :: (Floating a, Eq a) => (Stream :*: Stream) a -> ((Stream :*: Stream) a, (Stream :*: Stream) a, Stream Integer) Source #

https://en.wikipedia.org/wiki/LU_decomposition This has some bug still, l_matrix computation gets stuck.

min_convolution :: (Num a, Ord a) => Stream a -> Stream a -> Stream a Source #

fromNum :: Num a => a -> Stream a Source #

cycleQueueBy :: (a -> b -> b) -> Queue a -> b Source #

convolve_with :: Num a => ([a] -> b) -> (c -> d -> a) -> Stream c -> Stream d -> Stream b Source #

convolve_with_seq :: Num a => (Seq a -> b) -> (c -> d -> a) -> Stream c -> Stream d -> Stream b Source #

data StreamIndex a Source #

Constructors

StreamIndex 

Instances

Instances details
Functor StreamIndex Source # 
Instance details

Defined in Math.Number.Stream

Methods

fmap :: (a -> b) -> StreamIndex a -> StreamIndex b #

(<$) :: a -> StreamIndex b -> StreamIndex a #

Comonad StreamIndex Source # 
Instance details

Defined in Math.Number.Stream

Adjunction StreamIndex Stream Source # 
Instance details

Defined in Math.Number.Stream

Methods

leftAdjunct :: (StreamIndex a -> b) -> a -> Stream b Source #

unit :: a -> Stream (StreamIndex a) Source #

rightAdjunct :: (a -> Stream b) -> StreamIndex a -> b Source #

counit :: StreamIndex (Stream b) -> b Source #

Show a => Show (StreamIndex a) Source # 
Instance details

Defined in Math.Number.Stream

streamfold :: (a -> b -> b) -> Fold (Stream a) b Source #

fold over streams

fold_codiagonals :: Num a => ([a] -> b -> b) -> (Stream :*: Stream) a -> b Source #

streamfold2 :: (a -> c -> b) -> (a -> b -> c) -> Fold (Stream a) b Source #

streamfold_lst :: [a -> b -> b] -> Fold (Stream a) b Source #

streamfold_stream :: Stream (a -> b -> b) -> Fold (Stream a) b Source #

threeNplusOne :: Integer -> Integer Source #

the function studied in the Collatz conjecture.

toNatSeq :: Stream a -> Rec Maybe -> a Source #

sumSeq :: (Num b, Num a, Ord a) => (a -> b) -> a -> Stream b Source #

\[[sumSeq(f)(n)]_j = \sum_{i=n}^{n+j+1}f(i)\]

boolValue :: Num a => Bool -> a Source #

limit_fold :: (a -> a -> a) -> Fold (Stream a) (Integer -> a) Source #

limit_fold_gen :: (a -> b -> b) -> (a -> b) -> Fold (Stream a) (Integer -> b) Source #

fixpoint :: Limiting str a => (a -> a) -> a -> Closure str a Source #

matrix_inverse :: (ConjugateSymmetric (g2 a), LinearTransform (f2 :*: g1) (f2 :*: g1) (g2 a), FunctorArrow (f2 :*: g1) LinearMap LinearMap, InnerProductSpace (f2 (g2 a)), InnerProductSpace (g1 (g2 a)), Transposable f2 g1 (g2 a), Transposable g1 f2 (g2 a), Linearizable LinearMap (:*:) g1 f2 (g2 a), Linearizable LinearMap (:*:) f2 g1 (g2 a), Linearizable LinearMap (:*:) f2 g1 (g2 a), VectorSpace ((:*:) f2 g1 (g2 a)), Scalar (f2 (g2 a)) ~ g2 a, Scalar (g1 (g2 a)) ~ g2 a, Linearizable LinearMap (:*:) g2 g2 a, VectorSpace ((:*:) g2 g2 a), Diagonalizable g2 a) => (g1 (g2 a) :-> f2 (g2 a)) -> (f2 (g2 a) :-> g1 (g2 a)) -> Stream (f2 (g2 a) :-> g1 (g2 a)) Source #

stream_min :: Ord a => Fold (Stream a) (Integer -> a) Source #

stream_max :: Ord a => Fold (Stream a) (Integer -> a) Source #

liftStream2 :: (a -> a -> a) -> Stream a -> Stream a Source #

stream_sum :: Num a => Fold (Stream a) (Integer -> a) Source #

product_stream :: Num a => Stream a -> Stream a Source #

product_stream produce from a stream \([a_0,a_1,a_2,...]\) a stream \([a_0,a_0a_1,a_0a_1a_2,a_0a_1a_2a_3,...]\)

sum_stream :: Num a => Stream a -> Stream a Source #

sum_stream will produce from a stream \([a_0,a_1,a_2,...]\) a stream \([a_0,a_0+a_1,a_0+a_1+a_2,...]\).

cobind :: (ConjugateSymmetric a, Num a, Closed a) => (a -> b) -> (Stream a :-> Stream a) -> Stream b Source #

if f in cobind is a fixed-point free function, then this will find a stream that is not an element of any of the streams.

stream_codiagonal :: (ConjugateSymmetric a, Num a, Closed a) => (Stream a :-> Stream a) -> Stream (Stream a, Stream a) Source #

Everything but a diagonal

stream_matrix :: (ConjugateSymmetric a, Num a, Closed a) => Stream a -> Stream (Stream a, Stream a) -> Stream a :-> Stream a Source #

stream_matrix creates matrix from a diagonal and a codiagonal

from_triangular_matrices :: Num a => Stream a -> (Stream :*: Stream) a -> (Stream :*: Stream) a -> (Stream :*: Stream) a Source #

this surprising function builds a two-dimensional infinite matrix from a diagonal, an upper triangular matrix and a lower triangular matrix. Notice the input matrices have no zero entries, rather indices for the triangular matrices are bijectively mapped to indices of the result matrix. This is only possible for infinite matrices. It's even more surprising once it's realised that two-dimensional infinite matrices can be bijectively described as an infinite binary tree of one-dimensional streams.

triangular_matrix_iso :: Num a => (Stream :*: Stream) a :==: ((Stream :*: Stream) a, Stream a, (Stream :*: Stream) a) Source #

isomorphism of infinite matrices that splits along diagonal.

triangular_order_matrix :: Num a => (Stream :*: Stream) a Source #

this matrix contains 0 on diagonal, 1 on diagonal of upper and lower triangular matrices and so on. Every element of the two-dimensional matrix gets an index.

map_matrix :: (Num a, Num b) => (a -> b) -> ((Stream a, Stream a) -> (Stream b, Stream b)) -> (Stream :*: Stream) a -> (Stream :*: Stream) b Source #

map_diagonal :: Num a => (a -> a) -> (Stream :*: Stream) a -> (Stream :*: Stream) a Source #

joinWith :: (a -> b -> c) -> Stream a -> Stream b -> Stream c Source #

stail_index :: Num a => (Stream a :==: I a) -> Stream a :==: I a Source #

zipList :: ([a] -> b) -> [Stream a] -> Stream b Source #

sequence :: [Stream a] -> Stream [a] Source #

zipStream :: Functor f => (f b -> a) -> f (Stream b) -> Stream a Source #

sequenceStream :: Functor f => f (Stream a) -> Stream (f a) Source #

apply3 :: Stream (a -> b -> c) -> Stream a -> Stream b -> Stream c Source #

applyA :: Arrow arr => Stream (arr a b) -> arr (Stream a) (Stream b) Source #

codiagonals_list :: Num a => (Stream :*: Stream) a -> Stream [a] Source #

codiagonals operation implemented natively on lists. This is not efficient due to use of list append (++) operation, which is linear-time operation. Use codiagonals function instead.

codiagonals_seq :: (Stream :*: Stream) a -> Stream (Seq a) Source #

This is faster than the version for lists, because the suffix computation on Seq is constant time rather than linear. However, strictness seems to behave differently.

codiagonals :: (Stream :*: Stream) a -> Stream [a] Source #

The codiagonals function will divide a two-dimensional stream of streams (where elements are \(e_{(i,j)}\) into a stream of lists

\(l_k\) where \(l_k = [e_{(i,j)} | i \leftarrow naturals, j \leftarrow naturals, i+j = k]\)

The indices in the streams are closely related to "Cantor pairing function" (which is a bijection)

f :: (N,N) -> N
f(x,y) = (x+y)(x+y+1)/2 + x

Note that the list at each element of the resulting stream is of finite (but increasing) size. The order in each list is such that the diagonal elements are at the center of (the every second) list.

It is possible to think of this as "breadth-first" traversal over two-dimensional streams.

 d   x xr0 xr1  xr2 ..
 y   d' x' xr0' xr1' ..
 yr0 y'
 yr1 yr0'
 yr2 yr1'
 ..

There is symmetry between primed and unprimed (e.g. d and d') towards the diagonal.

The resulting lists would be: [d], [x,y], [xr0,d',yr0], [xr1,x',y',yr1],...

uncodiagonals :: (ConjugateSymmetric a, Closed a, Num a) => Stream [a] -> Stream a :-> Stream a Source #

for uncodiagonals, the i'th list element of the input stream must have length i.

uncodiagonals ([a] `Pre` [b,c] `Pre` [d,e,f] ...) == Pre (a `Pre` c `Pre` f ...) $ Pre (b `Pre` e `Pre` ...) $ Pre (d `Pre` ... ) $ ...

https://en.wikipedia.org/wiki/Formal_power_series

lower_triangle :: (ConjugateSymmetric a, Num a, Closed a) => (Stream a :-> Stream a) -> Stream a :-> Stream a Source #

lower_triangle takes lower half of a two-dimensional stream split at diagonal.

upper_triangle :: (ConjugateSymmetric a, Num a, Closed a) => (Stream a :-> Stream a) -> Stream a :-> Stream a Source #

upper_triangle takes upper half of a two-dimensional stream split at diagonal.

concatenate :: Stream [a] -> Stream a Source #

concatenate a stream of lists to a stream of elements

nice_tail :: [a] -> [a] Source #

find_equal :: Eq a => Stream a -> Stream a -> a Source #

fixedpoint :: (ConjugateSymmetric a, Num a, Closed a, Eq a) => (a -> a) -> (Stream a :-> Stream a) -> a Source #

sum_bind :: Num b => Stream a -> (a -> Stream b) -> Stream b Source #

cojoin :: (Stream :*: Stream) a -> Stream a Source #

cojoin is "better" version of join for streams. cojoin does not satisfy monad laws (Right identity and associativity do not hold.). It eventually produces every element of the original two-dimensional stream. It first produces all elements \(e_{(i,j)}\) where \(i+j=k\) and \(k\) increasing.

(|*|) :: Closed a => Stream a -> Stream a -> Stream (Vector2 a) Source #

naturals |*| naturals == (0,0),   [note sum=0]
                         (0,1),(1,0),  [note sum=1]
                         (0,2),(2,0),(1,1),  [note sum=2]
                         (0,3),(3,0),(1,2),(2,1),  [note sum=3]
                         (0,4),(4,0),(1,3),(3,1),(2,2),  [note sum=4]
                          ...  

(>>!=) :: Num b => Stream a -> (a -> Stream b) -> Stream b Source #

For a better "bind" operation, there exists (>>!=), which produces the following result (note duplicates):

naturals >>!= \x -> naturals >>!= \y -> return (x,y)
== (0,0),
  (0,0),(1,0),
     (0,1),(1,0),(2,0),
  (0,0),(1,1),(2,0),(3,0),
    (0,1),(1,0),(2,1),(3,0),(4,0),
      (0,2),(1,1),(2,0),(3,1),(4,0),(5,0),
  (0,0),(1,2),(2,1),(3,0),(4,1),(5,0),(6,0),
    (0,1),(1,0),(2,2),(3,1),(4,0),(5,1),(6,0),(7,0),
      (0,2),(1,1),(2,0),(3,2),(4,1),(5,0),(6,1),(7,0),(8,0),
       (0,3),(1,2),(2,1),(3,0),(4,2),(5,1),(6,0),(7,1),(8,0),(9,0),
  ...

(>!=) :: Num b => Stream a -> (a -> Stream b) -> Stream [b] Source #

The (>!=) is like binding, but the results are packaged to a finite list. Again note duplicates.

naturals >!= \x -> naturals >!= \y -> return (x,y)
== [[(0,0)]
  ],
  [[(0,0),(0,1)],
   [(1,0)]
  ],
  [[(0,0),(0,1),(0,2)],
   [(1,0),(1,1)],
   [(2,0)],
  ],
  [[(0,0),(0,1),(0,2),(0,3)],
 [(1,0),(1,1),(1,2)],
 [(2,0),(2,1)],
 [(3,0)]
],
...

integers_stream :: Stream Integer Source #

A stream of integers. This is specialized version of naturals for integers

naturals :: Num a => Stream a Source #

A stream of increasing numbers starting from 0

naturals_starting_from :: (Num a, Ord a) => a -> Stream a Source #

A stream of increasing numbers starting from a given number.

nonzero_naturals :: Num a => Stream a Source #

A stream of increasing numbers starting from 1

s_z :: Num a => Stream a Source #

This is the variable used in generating functions. Note that in multidimensional streams, this is the variable associated with the largest dimension.

s_z2 :: Num a => Stream (Stream a) Source #

The variable associated with second largest dimension:

s_z3 :: Num a => Stream (Stream (Stream a)) Source #

variable associated with third largest dimension

approximate_sums :: Fractional a => Stream a -> Stream a -> Stream a Source #

For a stream of terms \(a=[a_0,a_1,a_2,...]\), and \(x=[x_0,x_1,x_2,...]\), 'approximate_sums a x' computes \[\sum_{i=0}^n{a_ix_i^i}\], where n is the index to the result stream.

exponential_stream :: Fractional a => Stream a Source #

exponential_stream computes \(s_{i} = {{1}\over{i!}}\). notice that euler's constant \(e = \sum_{i=0}^{\infty}{1\over{i!}}\). therefore "sum_stream exponential_stream" produces approximations to e.

reciprocal :: Fractional a => Stream a -> Stream a Source #

both reciprocal and inversion are the inverse of a Cauchy product. see http://en.wikipedia.org/wiki/Formal_power_series

reciprocal s * s == unit_product

inversion :: Integral a => Stream a -> Stream a Source #

see http://en.wikipedia.org/wiki/Formal_power_series

inversion s * s == unit_product.

unit_product :: Num a => Stream a Source #

unit_product is the unit element of (*) for streams.

zero :: Num a => Stream a Source #

zero is the unit element of (+) for streams

either :: (a -> c) -> (b -> c) -> Stream (Either a b) -> Stream c Source #

subtract :: Num a => Stream a -> Stream a -> Stream a Source #

prefix :: [a] -> Stream a -> Stream a Source #

add a list as a prefix to a stream

fromList :: Num a => [a] -> Stream a Source #

The cycle operation is better than fromList, if the list is infinite, because it will ensure the result is infinite (and no Num constraint is needed).

toList :: Stream a -> [a] Source #

filter :: (a -> Bool) -> Stream a -> Stream a Source #

filter f s for streams does not terminate, if the input stream never contains any elements e for which f e == True.

remove :: Eq a => [a] -> Stream a -> Stream a Source #

interleave_count :: Integer -> Stream a -> Stream a -> Stream a Source #

interleave_count is like interleave except that i elements of each stream are taken from each stream at each stream.

interleave_stream :: Stream a -> Stream a -> Stream a Source #

interleave two streams such that even indexed elements of result are from first input stream and odd indexed elements of result are from second stream.

interleave_either :: Stream a -> Stream b -> Stream (Either a b) Source #

version of interleave that produces either instances

uninterleave :: Stream a -> (Stream a, Stream a) Source #

split a stream, elements with even index go to first result stream, rest to second.

interleave3 :: Stream a -> Stream a -> Stream a -> Stream a Source #

three stream interleave

uninterleave3 :: Stream a -> (Stream a, Stream a, Stream a) Source #

three stream uninterleave

interleave_lst :: [Stream a] -> Stream a Source #

interleave a non-empty list of streams.

uninterleave_lst :: Integer -> Stream a -> [Stream a] Source #

uninterleave to an indicated number of streams.

interleave_queue :: (Queue :*: Stream) a -> Stream a Source #

interleave a queue of streams.

uninterleave_queue :: Integer -> Stream a -> (Queue :*: Stream) a Source #

uninterleave to a queue of streams

square :: Num a => [[a]] -> (Stream :*: Stream) a Source #

drop :: Integer -> Stream a -> Stream a Source #

drop a specified number of elements from beginning of a stream.

take :: Integer -> Stream a -> [a] Source #

take a specified number of elements from the beginning of the stream.

splitAt :: Integer -> Stream a -> ([a], Stream a) Source #

split a stream from index.

countWhile :: (a -> Bool) -> Stream a -> Integer Source #

count how many elements from a beginning of a stream satisfy a predicate.

takeWhile :: (a -> Bool) -> Stream a -> [a] Source #

take elements from a stream while predicate is true.

dropWhile :: (a -> Bool) -> Stream a -> Stream a Source #

drop elements from a stream while predicate is true.

span :: (a -> Bool) -> Stream a -> ([a], Stream a) Source #

cycle :: [a] -> Stream a Source #

The cycle operation is better than fromList for converting a list to stream, if the list is infinite, because it will ensure the result is infinite.

cycle_queue :: Queue a -> Stream a Source #

use elements of a queue to produce an infinite stream.

stirling_numbers :: Num a => (Stream :*: Stream) a Source #

stirling numbers are the numbers obtained from \(z (z+1) ... (z+n)\)

toSquare :: (Stream :*: Stream) a -> [[a]] Source #

power :: Fractional a => Integer -> Stream a Source #

stream of powers of a given integer for fractional items

power_integral :: Integral a => Integer -> Stream a Source #

stream of powers of a given integer for integral items.

substitute :: Num a => Stream a -> Stream a -> Stream a Source #

exponential_generating_function :: Fractional a => Stream a -> Stream a Source #

https://en.wikipedia.org/wiki/Generating_function. \[EGF(z \mapsto \sum_{k=0}^{\infty}{s_kz^k}) = z \mapsto \sum_{k=0}^{\infty}{{1\over{k!}}{s_kz^k}}\].

pre_subst :: Num a => Stream a -> Stream a -> Stream [a] Source #

subst :: (Closed a, Num a) => Stream a -> Stream a -> Stream a Source #

multiply :: Num a => a -> Stream a -> Stream a Source #

powers :: Num a => Stream a -> (Stream :*: Stream) a Source #

input stream elements are raised to n'th power.

cauchy_powers :: Num a => a -> Stream a Source #

input element is raised to successive increasing powers (first element of the stream is \(n^1\))

binomial_coefficient :: Integral a => Integer -> Integer -> a Source #

The elements of pascal triangle are binomial coefficients.

http://en.wikipedia.org/wiki/Binomial_coefficient

pascal_triangle :: Integral a => (Stream :*: Stream) a Source #

pascal triangle, elements are binomial coefficients. https://en.wikipedia.org/wiki/Pascal%27s_triangle this expands "down" (leaving zero elements)

pascal_triangle_diag :: Integral a => (Stream :*: Stream) a Source #

pascal triangle which expands towards the diagonal

polynomial_powers :: Integral a => a -> a -> Stream a Source #

computes \((a + b)^n\) for all n, using binomial coefficients. Hint: use z in one of the argument. pascal_triangle == Matrix $ polynomial_powers 1 z Note: stream_powers can sometimes be a more efficient alternative.

fib :: Integral a => Stream a Source #

a stream of fibonacci numbers, each element is a sum of two previous elements. 1,1,2,3,5,8,13,21,34,55,...

triangular_numbers :: Integral a => Stream a Source #

Triangular numbers. https://en.wikipedia.org/wiki/Generating_function 1,3,6,10,15,21,28,36,...

alternating_signs :: Fractional a => Stream a Source #

1.0,-1.0,1.0,-1.0,...

alternating_bits :: Fractional a => Stream a Source #

1.0,0.0,1.0,0.0,1.0,0.0,...

odd_integers :: Integral a => Stream a Source #

stream of odd integers

integers_divisible_by :: Integer -> Stream Integer Source #

This is an ideal of the set of positive integers, usually denoted \(nZ^+\), e.g. set of positive integers divisible by n.

residue_class_modulo :: Integer -> Integer -> Stream Integer Source #

This function produces the equivalence class of m mod n. The numbers produced by the stream are considered as equivalent by the equivalence class.

peirces_triangle_func :: (Num a, Ord a) => a -> a -> a Source #

peirces_triangle is the number of set partitions. From Knuth: The art of Computer Programming, Volume 4 "Generating all combinations and partitions", page 64.

peirces_triangle :: (Num a, Ord a) => (Stream :*: Stream) a Source #

peirces_triangle is the number of set partitions. From Knuth: The art of Computer Programming, Volume 4 "Generating all combinations and partitions", page 64.

falling_factorial_powers_diag :: (ConjugateSymmetric a, Integral a, Closed a) => Stream a :-> Stream a Source #

https://en.wikipedia.org/wiki/Injective_function?wprof=sfla1 falling factorial powers specify number of injective functions from domain with specified number of elements to codomain with specified number of elements. https://en.wikipedia.org/wiki/Falling_and_rising_factorials?wprof=sfla1

Be careful about indices here, could cause off-by-one error!

bell_numbers :: (Num a, Ord a) => Stream a Source #

bell numbers https://en.wikipedia.org/wiki/Bell_number. also see Knuth: The Art of Computer Programming, Volume 4.

square_root :: Integral a => a -> Stream a Source #

newton's method of computing square root approximations:

detect_cycle :: Eq a => Stream a -> [a] Source #

This is an implementation of Floyd's cycle-finding algorithm http://en.wikipedia.org/wiki/Cycle_detection.

primes :: Integral t => Stream t Source #

Stream of prime numbers generated using a sieve.

https://wiki.haskell.org/Prime_numbers

derivative :: Num a => Stream a -> Stream a Source #

derivative calculates the derivative of the generating function. https://en.wikipedia.org/wiki/Generating_function \[{\rm{derivative}}({\bf{a}})_i = {\bf{b}}_i = (i+1){\bf{a}}_{i+1}\] \[f(z) = \sum_{i=0}^{\infty}{\bf{a}}_iz^i\] \[f'(z) = \sum_{i=0}^{\infty}{\bf{b}}_iz^i = {d\over{dz}} \sum_{i=0}^{\infty}{\bf{a}}_iz^i = \sum_{i=0}^{\infty}(i+1){\bf{a}}_{i+1}z^i\]

monotonic_membership :: Ord a => Stream a -> Stream a -> Stream Bool Source #

for two monotone streams, compares whether all elements of the first stream are also in the second stream. produces True for every element of the first stream, if that element is part of the second stream. produces error if the streams are not monotone.

sqrt_stream :: (Floating a, Closed a) => Stream a -> Stream a Source #

Square root algorithm is from Simpson: Power Series, http://caps.gsfc.nasa.gov/simpson/ref/series.pdf

stream_derivate :: (Fractional a, Closed a, Infinitesimal str (Stream a)) => (Stream a -> Stream a) -> Stream a -> Closure str (Stream a) Source #

derivate a stream function at a particular point.

stream_integral :: (Closed b, Infinitesimal str (Stream b), Fractional b, Enum b) => (Stream b -> Stream b) -> (Stream b, Stream b) -> Closure str (Stream b) Source #

evaluate_polynomial :: Fractional a => [a] -> a -> a Source #

Orphan instances

MonadFail Stream Source # 
Instance details

Methods

fail :: String -> Stream a #

Foldable Stream Source # 
Instance details

Methods

fold :: Monoid m => Stream m -> m #

foldMap :: Monoid m => (a -> m) -> Stream a -> m #

foldMap' :: Monoid m => (a -> m) -> Stream a -> m #

foldr :: (a -> b -> b) -> b -> Stream a -> b #

foldr' :: (a -> b -> b) -> b -> Stream a -> b #

foldl :: (b -> a -> b) -> b -> Stream a -> b #

foldl' :: (b -> a -> b) -> b -> Stream a -> b #

foldr1 :: (a -> a -> a) -> Stream a -> a #

foldl1 :: (a -> a -> a) -> Stream a -> a #

toList :: Stream a -> [a] #

null :: Stream a -> Bool #

length :: Stream a -> Int #

elem :: Eq a => a -> Stream a -> Bool #

maximum :: Ord a => Stream a -> a #

minimum :: Ord a => Stream a -> a #

sum :: Num a => Stream a -> a #

product :: Num a => Stream a -> a #

Traversable Stream Source # 
Instance details

Methods

traverse :: Applicative f => (a -> f b) -> Stream a -> f (Stream b) #

sequenceA :: Applicative f => Stream (f a) -> f (Stream a) #

mapM :: Monad m => (a -> m b) -> Stream a -> m (Stream b) #

sequence :: Monad m => Stream (m a) -> m (Stream a) #

Monad Stream Source #

According to http://patternsinfp.wordpress.com/2010/12/31/stream-monad/, the diagonal is the join of the stream monad.

Instance details

Methods

(>>=) :: Stream a -> (a -> Stream b) -> Stream b #

(>>) :: Stream a -> Stream b -> Stream b #

return :: a -> Stream a #

Closed Double Source # 
Instance details

Closed Float Source # 
Instance details

StreamBuilder Stream Source # 
Instance details

Methods

pre :: a -> Stream a -> Stream a Source #

CircularComonad Stream Source # 
Instance details

Methods

rotate :: Stream a -> Stream a Source #

Comonad Stream Source # 
Instance details

Methods

extract :: Stream a -> a Source #

duplicate :: Stream a -> Stream (Stream a) Source #

extend :: (Stream a -> b) -> Stream a -> Stream b Source #

(=>>) :: Stream a -> (Stream a -> b) -> Stream b Source #

(.>>) :: Stream a -> b -> Stream b Source #

InfiniteComonad Stream Source # 
Instance details

Methods

comonad_pre :: a -> Stream a -> Stream a Source #

InterleaveFunctor Stream Source # 
Instance details

Methods

interleave :: Stream a -> Stream a -> Stream a Source #

Nondeterministic Stream Source # 
Instance details

Methods

guess :: [a] -> Stream a Source #

PpShowF Stream Source # 
Instance details

Methods

ppf :: PpShow a => Stream a -> Doc Source #

PpShowVerticalF Stream Source # 
Instance details

Methods

ppf_vertical :: PpShow a => Stream a -> Doc Source #

AppendableVector Vector3 Stream Source # 
Instance details

Associated Types

type Vector3 :+: Stream :: Type -> Type Source #

Methods

(||>>) :: Vector3 a -> Stream a -> (Vector3 :+: Stream) a Source #

Num a => Diagonalizable Stream a Source #

square matrix implementation for streams.

Instance details

Num a => Indexable Stream a Source # 
Instance details

Approximations Stream Double Source # 
Instance details

Approximations Stream Float Source # 
Instance details

Infinitesimal Stream Double Source #

Notice that after double precision is not sufficient, the infinitesimals are zero.

Instance details

Infinitesimal Stream Float Source #

Notice that after float precision is not sufficient, the infinitesimals are zero.

Instance details

Limiting Stream Rational Source #

https://en.wikipedia.org/wiki/Matrix_exponential

Instance details

Associated Types

data Closure Stream Rational Source #

Limiting Stream Integer Source # 
Instance details

Associated Types

data Closure Stream Integer Source #

Limiting Stream Double Source # 
Instance details

Associated Types

data Closure Stream Double Source #

Limiting Stream Float Source # 
Instance details

Associated Types

data Closure Stream Float Source #

Adjunction StreamIndex Stream Source # 
Instance details

Methods

leftAdjunct :: (StreamIndex a -> b) -> a -> Stream b Source #

unit :: a -> Stream (StreamIndex a) Source #

rightAdjunct :: (a -> Stream b) -> StreamIndex a -> b Source #

counit :: StreamIndex (Stream b) -> b Source #

(Closed a, ConjugateSymmetric a, Num a) => LinearTransform Stream Stream a Source # 
Instance details

Methods

(<*>>) :: Stream a -> (Stream :*: Stream) a -> Stream a Source #

(<<*>) :: (Stream :*: Stream) a -> Stream a -> Stream a Source #

(Infinitesimal Stream a, Num a) => Infinitesimal Stream (Stream a) Source # 
Instance details

(RealFloat a, Infinitesimal str a) => Infinitesimal str (Complex a) Source # 
Instance details

(Num a, Limiting Stream a) => Limiting Stream (Stream a) Source # 
Instance details

Associated Types

data Closure Stream (Stream a) Source #

Limiting Stream (IO ()) Source # 
Instance details

Associated Types

data Closure Stream (IO ()) Source #

Methods

limit :: Stream (IO ()) -> Closure Stream (IO ()) Source #

approximations :: Closure Stream (IO ()) -> Stream (IO ()) Source #

Limiting str a => Limiting str (Complex a) Source # 
Instance details

Associated Types

data Closure str (Complex a) Source #

Methods

limit :: str (Complex a) -> Closure str (Complex a) Source #

approximations :: Closure str (Complex a) -> str (Complex a) Source #

Limiting Stream (a :==: a) Source # 
Instance details

Associated Types

data Closure Stream (a :==: a) Source #

(Limiting str a, Limiting str b) => Limiting str (a, b) Source # 
Instance details

Associated Types

data Closure str (a, b) Source #

Methods

limit :: str (a, b) -> Closure str (a, b) Source #

approximations :: Closure str (a, b) -> str (a, b) Source #

Monad m => Limiting Stream (Kleisli m a a) Source # 
Instance details

Associated Types

data Closure Stream (Kleisli m a a) Source #

(Limiting str a, Limiting str b, Limiting str c) => Limiting str (a, b, c) Source # 
Instance details

Associated Types

data Closure str (a, b, c) Source #

Methods

limit :: str (a, b, c) -> Closure str (a, b, c) Source #

approximations :: Closure str (a, b, c) -> str (a, b, c) Source #

(Applicative f, Traversable f, Traversable str, Applicative g, Traversable g, Limiting str a) => Limiting str ((f :*: g) a) Source # 
Instance details

Associated Types

data Closure str ((f :*: g) a) Source #

Methods

limit :: str ((f :*: g) a) -> Closure str ((f :*: g) a) Source #

approximations :: Closure str ((f :*: g) a) -> str ((f :*: g) a) Source #

Data a => Data (Stream a) Source # 
Instance details

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Stream a -> c (Stream a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Stream a) #

toConstr :: Stream a -> Constr #

dataTypeOf :: Stream a -> DataType #

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

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

gmapT :: (forall b. Data b => b -> b) -> Stream a -> Stream a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Stream a -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Stream a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Stream a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Stream a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Stream a -> m (Stream a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Stream a -> m (Stream a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Stream a -> m (Stream a) #

Monoid a => Monoid (Stream a) Source #

monoid instance for streams generated by monoid instance of the elements.

Instance details

Methods

mempty :: Stream a #

mappend :: Stream a -> Stream a -> Stream a #

mconcat :: [Stream a] -> Stream a #

Semigroup a => Semigroup (Stream a) Source # 
Instance details

Methods

(<>) :: Stream a -> Stream a -> Stream a #

sconcat :: NonEmpty (Stream a) -> Stream a #

stimes :: Integral b => b -> Stream a -> Stream a #

(Enum a, Num a) => Enum (Stream a) Source # 
Instance details

Methods

succ :: Stream a -> Stream a #

pred :: Stream a -> Stream a #

toEnum :: Int -> Stream a #

fromEnum :: Stream a -> Int #

enumFrom :: Stream a -> [Stream a] #

enumFromThen :: Stream a -> Stream a -> [Stream a] #

enumFromTo :: Stream a -> Stream a -> [Stream a] #

enumFromThenTo :: Stream a -> Stream a -> Stream a -> [Stream a] #

(ConjugateSymmetric a, Closed a, Eq a, Floating a) => Floating (Stream a) Source #

inverse trigonometric functions hyperbolic function

Instance details

Methods

pi :: Stream a #

exp :: Stream a -> Stream a #

log :: Stream a -> Stream a #

sqrt :: Stream a -> Stream a #

(**) :: Stream a -> Stream a -> Stream a #

logBase :: Stream a -> Stream a -> Stream a #

sin :: Stream a -> Stream a #

cos :: Stream a -> Stream a #

tan :: Stream a -> Stream a #

asin :: Stream a -> Stream a #

acos :: Stream a -> Stream a #

atan :: Stream a -> Stream a #

sinh :: Stream a -> Stream a #

cosh :: Stream a -> Stream a #

tanh :: Stream a -> Stream a #

asinh :: Stream a -> Stream a #

acosh :: Stream a -> Stream a #

atanh :: Stream a -> Stream a #

log1p :: Stream a -> Stream a #

expm1 :: Stream a -> Stream a #

log1pexp :: Stream a -> Stream a #

log1mexp :: Stream a -> Stream a #

Generic (Stream a) Source # 
Instance details

Associated Types

type Rep (Stream a) :: Type -> Type #

Methods

from :: Stream a -> Rep (Stream a) x #

to :: Rep (Stream a) x -> Stream a #

Num a => Num (Stream a) Source #

Interpretation of a stream as a polynomial (its ordinary generating function) \[OGF_{s}(z) = \sum_{i=0}^{\infty}s_iz^i\] Good exposition exists in http://en.wikipedia.org/wiki/Formal_power_series

the (*) operation is specific to ordinary generating function interpretation, i.e. discrete convolution/Cauchy product

\[(xy)_k = \sum_{i+j=k}x_iy_j\] \[OGF_{xy}(z) = \sum_{k=0}^{\infty}\sum_{i+j=k}x_iy_jz^k\]

Instance details

Methods

(+) :: Stream a -> Stream a -> Stream a #

(-) :: Stream a -> Stream a -> Stream a #

(*) :: Stream a -> Stream a -> Stream a #

negate :: Stream a -> Stream a #

abs :: Stream a -> Stream a #

signum :: Stream a -> Stream a #

fromInteger :: Integer -> Stream a #

Fractional a => Fractional (Stream a) Source #

Fractional instance is based on interpretation of a stream as generating function.

Instance details

Methods

(/) :: Stream a -> Stream a -> Stream a #

recip :: Stream a -> Stream a #

fromRational :: Rational -> Stream a #

Integral a => Integral (Stream a) Source #

Integral instance is based on interpretation of a stream as generating function.

Instance details

Methods

quot :: Stream a -> Stream a -> Stream a #

rem :: Stream a -> Stream a -> Stream a #

div :: Stream a -> Stream a -> Stream a #

mod :: Stream a -> Stream a -> Stream a #

quotRem :: Stream a -> Stream a -> (Stream a, Stream a) #

divMod :: Stream a -> Stream a -> (Stream a, Stream a) #

toInteger :: Stream a -> Integer #

(Num a, Ord a, Real a) => Real (Stream a) Source # 
Instance details

Methods

toRational :: Stream a -> Rational #

Show x => Show (Stream x) Source #

Show instance displays 15 elements from beginning of stream To display more elements, use drop operation.

Instance details

Methods

showsPrec :: Int -> Stream x -> ShowS #

show :: Stream x -> String #

showList :: [Stream x] -> ShowS #

ConjugateSymmetric a => ConjugateSymmetric (Stream a) Source # 
Instance details

Methods

conj :: Stream a -> Stream a Source #

(ConjugateSymmetric a, Num a, Closed a) => InnerProductSpace (Stream a) Source # 
Instance details

Methods

(%.) :: Stream a -> Stream a -> Scalar (Stream a) Source #

(Closed a, ConjugateSymmetric a, Floating a) => NormedSpace (Stream a) Source # 
Instance details

(RealFloat a, Infinitesimal Stream a) => Closed (Complex a) Source # 
Instance details

(Closed a, Num a) => Closed (Stream a) Source # 
Instance details

PpShow x => PpShow (Stream x) Source #

pretty printing displays 15 element prefix of the stream.

Instance details

Methods

pp :: Stream x -> Doc Source #

Builder a => Builder (Stream a) Source #

unfold for streams

Instance details

Associated Types

data Unfold (Stream a) :: Type -> Type Source #

Methods

build :: Unfold (Stream a) a0 -> a0 -> Stream a Source #

Visitor (Stream a) Source #

folds over streams

Instance details

Associated Types

data Fold (Stream a) :: Type -> Type Source #

Methods

visit :: Fold (Stream a) a0 -> Stream a -> a0 Source #

Eq a => Eq (Stream a) Source #

The instance of Eq is kind of bogus, because equality for streams is only semidecidable. It's still possible to use this if you know that the operation on your specific streams terminate. worst case occurs if the streams contain exactly equal elements.

Instance details

Methods

(==) :: Stream a -> Stream a -> Bool #

(/=) :: Stream a -> Stream a -> Bool #

Ord a => Ord (Stream a) Source #

this instance of Ord goes to infinite loop if the compared streams are equal.

Instance details

Methods

compare :: Stream a -> Stream a -> Ordering #

(<) :: Stream a -> Stream a -> Bool #

(<=) :: Stream a -> Stream a -> Bool #

(>) :: Stream a -> Stream a -> Bool #

(>=) :: Stream a -> Stream a -> Bool #

max :: Stream a -> Stream a -> Stream a #

min :: Stream a -> Stream a -> Stream a #

(Closed a, Fractional a, ConjugateSymmetric a) => Num (Stream a :-> Stream a) Source # 
Instance details

Methods

(+) :: (Stream a :-> Stream a) -> (Stream a :-> Stream a) -> Stream a :-> Stream a #

(-) :: (Stream a :-> Stream a) -> (Stream a :-> Stream a) -> Stream a :-> Stream a #

(*) :: (Stream a :-> Stream a) -> (Stream a :-> Stream a) -> Stream a :-> Stream a #

negate :: (Stream a :-> Stream a) -> Stream a :-> Stream a #

abs :: (Stream a :-> Stream a) -> Stream a :-> Stream a #

signum :: (Stream a :-> Stream a) -> Stream a :-> Stream a #

fromInteger :: Integer -> Stream a :-> Stream a #

(Limiting Stream a, RealFloat a) => Num (Closure Stream (Complex a)) Source # 
Instance details

Num (Closure Stream Rational) Source # 
Instance details

Num (Closure Stream Integer) Source # 
Instance details

Fractional (Closure Stream Rational) Source # 
Instance details

Show (Closure Stream Rational) Source # 
Instance details

Show (Closure Stream a) => Show (Closure Stream (Stream a)) Source # 
Instance details

Show (Closure Stream Integer) Source # 
Instance details

Show (Closure Stream Double) Source # 
Instance details

Show (Closure Stream Float) Source # 
Instance details

Show (Closure str a) => Show (Closure str (Complex a)) Source # 
Instance details

Methods

showsPrec :: Int -> Closure str (Complex a) -> ShowS #

show :: Closure str (Complex a) -> String #

showList :: [Closure str (Complex a)] -> ShowS #

(Show (Closure str a), Show (Closure str b), Show (Closure str c)) => Show (Closure str (a, b, c)) Source # 
Instance details

Methods

showsPrec :: Int -> Closure str (a, b, c) -> ShowS #

show :: Closure str (a, b, c) -> String #

showList :: [Closure str (a, b, c)] -> ShowS #

(Closed a, Num a, ConjugateSymmetric a) => ConjugateSymmetric (Stream a :-> Stream a) Source # 
Instance details

Methods

conj :: (Stream a :-> Stream a) -> Stream a :-> Stream a Source #

Infinitary (Closure Stream Rational) Source # 
Instance details

Infinitary (Closure Stream Integer) Source # 
Instance details

PpShow a => Show ((Stream :*: Stream) a) Source # 
Instance details

ConjugateSymmetric a => ConjugateSymmetric ((Stream :*: Stream) a) Source # 
Instance details

Methods

conj :: (Stream :*: Stream) a -> (Stream :*: Stream) a Source #