LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
moment_lah.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_LAH_H
6#define LINE_API_MOMENT_MOMENT_LAH_H
7
8/**
9 * @file
10 * @ingroup api_moment
11 * Unsigned Lah numbers.
12 *
13 * Templated port of matlab/src/api/moment/moment_lah.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"
25
26namespace line {
27namespace moment {
28
29/** L(i,j) = L(i-1,j-1) + (i+j-1) L(i-1,j), L(0,0) = 1. */
30template <class T>
32 if (n < 0) throw InputError("moment_lah: the maximum order n must be nonnegative");
33 Matrix<T> L(n + 1, n + 1, num_traits<T>::from_int(0));
34 L(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 L(i, j) = L(i - 1, j - 1) + num_traits<T>::from_int(i + j - 1) * L(i - 1, j);
38 return L;
39}
40
41} // namespace moment
42} // namespace line
43
44#endif
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Dense matrix and non-owning view.
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
Number-type abstraction for the templated API port.
Population-vector enumeration and combinatorics.