LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
moment_raw_from_upfactorial.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_RAW_FROM_UPFACTORIAL_H
6#define LINE_API_MOMENT_MOMENT_RAW_FROM_UPFACTORIAL_H
7
8/**
9 * @file
10 * @ingroup api_moment
11 * Raw moments from rising-factorial moments.
12 *
13 * Templated port of matlab/src/api/moment/moment_raw_from_upfactorial.m. Every operation is integer
14 * or rational, so the exact instantiation returns the transform with no
15 * rounding at all. That matters more here than almost anywhere else in the API:
16 * the alternating binomial sums of the moment conversions cancel
17 * catastrophically in double arithmetic once the order grows.
18 */
19
20#include <vector>
21
22#include "line/num/number.h"
23#include "line/util/error.h"
24#include "line/util/matrix.h"
28
29namespace line {
30namespace moment {
31
32/** m_i = sum_j (-1)^(i-j) S(i,j) fp_j. */
33template <class T>
34std::vector<T> moment_raw_from_upfactorial(const std::vector<T>& fp) {
35 const int n = static_cast<int>(fp.size()) - 1;
37 Matrix<T> Tm(n + 1, n + 1, num_traits<T>::from_int(0));
38 for (int i = 0; i <= n; ++i)
39 for (int j = 0; j <= i; ++j) Tm(i, j) = ((i - j) % 2 == 0) ? S(i, j) : -S(i, j);
40 return apply_table(Tm, fp);
41}
42
43} // namespace moment
44} // namespace line
45
46#endif
The exception types the port throws.
Dense matrix and non-owning view.
Shared helper applying a triangular moment-transform table.
Stirling numbers of the second kind.
std::vector< T > apply_table(const Matrix< T > &A, const std::vector< T > &v)
Apply a lower-triangular transform table to a moment vector.
Matrix< T > moment_stirling2(int n)
S(i,j) = j S(i-1,j) + S(i-1,j-1), S(0,0) = 1.
std::vector< T > moment_raw_from_upfactorial(const std::vector< T > &fp)
m_i = sum_j (-1)^(i-j) S(i,j) fp_j.
Number-type abstraction for the templated API port.
Population-vector enumeration and combinatorics.