LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
moment_stirling1.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_STIRLING1_H
6#define LINE_API_MOMENT_MOMENT_STIRLING1_H
7
8/**
9 * @file
10 * @ingroup api_moment
11 * Signed Stirling numbers of the first kind.
12 *
13 * Templated port of matlab/src/api/moment/moment_stirling1.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"
26
27namespace line {
28namespace moment {
29
30
31/** s(i,j) = (-1)^(i-j) sigma(i,j). */
32template <class T>
35 Matrix<T> s(n + 1, n + 1, num_traits<T>::from_int(0));
36 for (int i = 0; i <= n; ++i)
37 for (int j = 0; j <= i; ++j)
38 s(i, j) = ((i - j) % 2 == 0) ? sigma(i, j) : -sigma(i, j);
39 return s;
40}
41
42} // namespace moment
43} // namespace line
44
45#endif
The exception types the port throws.
Dense matrix and non-owning view.
Unsigned Stirling numbers of the first kind (cycle numbers), orders 0..n.
Matrix< T > moment_stirling1(int n)
s(i,j) = (-1)^(i-j) sigma(i,j).
Matrix< T > moment_stirlingcycle(int n)
sigma(i,j), (n+1) x (n+1) lower triangular, sigma(0,0) = 1.
Number-type abstraction for the templated API port.
Population-vector enumeration and combinatorics.