LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
moment_factorial_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_FACTORIAL_FROM_UPFACTORIAL_H
6
#define LINE_API_MOMENT_MOMENT_FACTORIAL_FROM_UPFACTORIAL_H
7
8
/**
9
* @file
10
* @ingroup api_moment
11
* Falling-factorial moments from rising-factorial moments, via the Lah numbers.
12
*
13
* Templated port of matlab/src/api/moment/moment_factorial_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
"
25
#include "
line/util/population.h
"
26
#include "
line/api/moment/moment_lah.h
"
27
28
namespace
line
{
29
namespace
moment
{
30
31
/** f_0 = 1; f_i = sum_k (-1)^(i-k) L(i,k) fp_k for i >= 1. */
32
template
<
class
T>
33
std::vector<T>
moment_factorial_from_upfactorial
(
const
std::vector<T>& fp) {
34
const
int
n =
static_cast<
int
>
(fp.size()) - 1;
35
Matrix<T>
L =
moment_lah<T>
(n);
36
std::vector<T> f(fp.size(),
num_traits<T>::from_int
(0));
37
f[0] =
num_traits<T>::from_int
(1);
38
for
(
int
i = 1; i <= n; ++i)
39
for
(
int
k = 1; k <= i; ++k) {
40
const
T term = L(i, k) * fp[
static_cast<
std::size_t
>
(k)];
41
f[
static_cast<
std::size_t
>
(i)] += ((i - k) % 2 == 0) ? term : -term;
42
}
43
return
f;
44
}
45
46
}
// namespace moment
47
}
// namespace line
48
49
#endif
line::Matrix
Definition
matrix.h:56
error.h
The exception types the port throws.
matrix.h
Dense matrix and non-owning view.
moment_lah.h
Unsigned Lah numbers.
line::moment
Definition
moment_apply.h:28
line::moment::moment_factorial_from_upfactorial
std::vector< T > moment_factorial_from_upfactorial(const std::vector< T > &fp)
f_0 = 1; f_i = sum_k (-1)^(i-k) L(i,k) fp_k for i >= 1.
Definition
moment_factorial_from_upfactorial.h:33
line::moment::moment_lah
Matrix< T > moment_lah(int n)
L(i,j) = L(i-1,j-1) + (i+j-1) L(i-1,j), L(0,0) = 1.
Definition
moment_lah.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_factorial_from_upfactorial.h
Generated by
1.18.0