LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
moment_stirling2.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012-2026, QORE Lab, Imperial College London
3
* All rights reserved.
4
*/
5
#ifndef LINE_API_MOMENT_MOMENT_STIRLING2_H
6
#define LINE_API_MOMENT_MOMENT_STIRLING2_H
7
8
/**
9
* @file
10
* @ingroup api_moment
11
* Stirling numbers of the second kind.
12
*
13
* Templated port of matlab/src/api/moment/moment_stirling2.m. Every operation is integer or
14
* rational, so the exact instantiation returns the transform with no rounding:
15
* moment conversions are exactly where double arithmetic hurts, since the
16
* alternating binomial sums cancel catastrophically at high order.
17
*/
18
19
#include <vector>
20
21
#include "
line/num/number.h
"
22
#include "
line/util/error.h
"
23
#include "
line/util/matrix.h
"
24
#include "
line/util/population.h
"
25
26
namespace
line
{
27
namespace
moment
{
28
29
/** S(i,j) = j S(i-1,j) + S(i-1,j-1), S(0,0) = 1. */
30
template
<
class
T>
31
Matrix<T>
moment_stirling2
(
int
n) {
32
if
(n < 0)
throw
InputError
(
"moment_stirling2: the maximum order n must be nonnegative"
);
33
Matrix<T>
S(n + 1, n + 1,
num_traits<T>::from_int
(0));
34
S(0, 0) =
num_traits<T>::from_int
(1);
35
for
(
int
i = 1; i <= n; ++i)
36
for
(
int
j = 1; j <= i; ++j)
37
S(i, j) =
num_traits<T>::from_int
(j) * S(i - 1, j) + S(i - 1, j - 1);
38
return
S;
39
}
40
41
}
// namespace moment
42
}
// namespace line
43
44
#endif
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::Matrix
Definition
matrix.h:56
error.h
The exception types the port throws.
matrix.h
Dense matrix and non-owning view.
line::moment
Definition
moment_apply.h:28
line::moment::moment_stirling2
Matrix< T > moment_stirling2(int n)
S(i,j) = j S(i-1,j) + S(i-1,j-1), S(0,0) = 1.
Definition
moment_stirling2.h:31
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
population.h
Population-vector enumeration and combinatorics.
line::num_traits
Definition
number.h:111
include
line
api
moment
moment_stirling2.h
Generated by
1.18.0