Chapter 1
Backgrounds
In this introductory section we review theoretical concepts about the Riordan group that will be useful in subsequent chapters; additionally, we provide a very short introduction to symbolic computation using the sympy module implemented using the Python programming language, giving a taste of our programming style.
1.1Riordan Arrays, formally#
A Riordan array is an infinite lower triangular array , defined by a pair of formal power series such that , and ; furthermore, each element
is the coefficient of monomial in the series expansion of and the bivariate generating function
(1.1)enumerates the sequence .
These arrays were introduced inL. W. Shapiro, S. G., W.-J. Woan, and L. C. Woodson. The Riordan group. Discrete Applied Mathematics, 34(1):229–239, 1991. ISSN 0166-218X. doi: 10.1016/0166-218X(91)90088-E. URL http://www.sciencedirect.com/science/article/pii/0166218X9190088E with the aim of defining a class of infinite, lower triangular arrays and since then they have attracted, and continue to attract, a lot of attention in the literature and recent applications can be found inA. Luzon, D. Merlini, M. A. Moron, and R. Sprugnoli. Complementary Riordan arrays. Discrete Applied Mathematics, 172:75–87, 2014. ISSN 0166-218X. doi: 10.1016/j.dam.2014.03.005. URL http://www.sciencedirect.com/science/article/pii/S0166218X14001280.
Example 1.1. The most simple Riordan matrix could be the Pascal triangle
moreover, another remarkable matrix is the Catalan triangle
where .
An important property of Riordan arrays concerns the computation of combinatorial sums; precisely, it is encoded by the identity
(1.2)and it is extensively commented inA. Luzon, D. Merlini, M. A. Moron, and R. Sprugnoli. Identities induced by Riordan arrays. Linear Algebra and its Applications, 436(3):631–647, 2012. ISSN 0024-3795. doi: 10.1016/j.laa.2011.08.007. URL http://www.sciencedirect.com/science/article/pii/S0024379511005805; D. Merlini, R. Sprugnoli, and M. C. Verri. Combinatorial Sums and Implicit Riordan Arrays. Discrete Math., 309(2):475–486, Elsevier Science Publishers B. V., Amsterdam, The Netherlands, The Netherlands, January 2009. ISSN 0012-365X. doi: 10.1016/j.disc.2007.12.039. URL http://dx.doi.org/10.1016/j.disc.2007.12.039; and R. Sprugnoli. Riordan arrays and combinatorial sums. Discrete Mathematics, 132(1):267–290, 1994. ISSN 0012-365X. doi: 10.1016/0012-365X(92)00570-H. URL http://www.sciencedirect.com/science/article/pii/0012365X9200570H It states that every combinatorial sum involving a Riordan array can be computed by extracting the coefficient of from the series expansion of , where denotes the generating function of the sequence and the symbol denotes the generating function operator. Due to its importance, relation (1.2) is commonly known as the fundamental rule of Riordan arrays. For short and when no confusion arises, the notation will be used as an abbreviation of .
As it is well-known (see, e.g.,A. Luzon, D. Merlini, M. A. Moron, and R. Sprugnoli. Complementary Riordan arrays. Discrete Applied Mathematics, 172:75–87, 2014. ISSN 0166-218X. doi: 10.1016/j.dam.2014.03.005. URL http://www.sciencedirect.com/science/article/pii/S0166218X14001280; D. Merlini, D. G. Rogers, R. Sprugnoli, and M. C. Verri. On Some Alternative Characterizations of Riordan Arrays. Canadian Journal of Mathematics, 49:301–320, August 1997; and L. W. Shapiro, S. G., W.-J. Woan, and L. C. Woodson. The Riordan group. Discrete Applied Mathematics, 34(1):229–239, 1991. ISSN 0166-218X. doi: 10.1016/0166-218X(91)90088-E. URL http://www.sciencedirect.com/science/article/pii/0166218X9190088E), Riordan arrays constitute an algebraic group with respect to the usual row-by-column product between matrices; formally, the group operation applied to two Riordan arrays and is carried out as
(1.3)Moreover, the Riordan array acts as the identity element and the inverse of is the Riordan array
(1.4)where denotes the compositional inverse of .
An equivalent characterization of a each matrix in the Riordan group is given by two sequences of coefficients and called -sequence and -sequence, respectively. The former one can be used to define every coefficient with ,
where the sum is finite because exists such that ; on the other hand, the latter one can be used to define every coefficient lying on the first column,
where the sum is finite because for .
Moreover, let and be the generating functions of the -sequence and -sequence respectively, then relations
connect them with functions and , where is the very first element of ; for the sake of completeness,D. Merlini, D. G. Rogers, R. Sprugnoli, and M. C. Verri. On Some Alternative Characterizations of Riordan Arrays. Canadian Journal of Mathematics, 49:301–320, August 1997 collects more alternative characterizations.
1.2Symbolic computation#
The main part of the symbolic computations supporting the topics discussed in this dissertation has been coded using the Python language, relying on the module sympy for what concerns mathematical stuff. Quoting from http://www.sympy.org/:
“SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible.”
The paperA. Meurer, C. P. Smith, M. Paprocki, O. Čertík, S. B. Kirpichev, M. Rocklin, A. Kumar, S. Ivanov, J. K. Moore, S. Singh, T. Rathnayake, S. Vig, B. E. Granger, R. P. Muller, F. Bonazzi, H. Gupta, S. Vats, F. Johansson, F. Pedregosa, M. J. Curry, A. R. Terrel, Š. Roučka, A. Saboo, I. Fernando, S.h Kulal, R. Cimrman, and A. Scopatz. SymPy: symbolic computing in Python. PeerJ Computer Science, 3:e103, January 2017. ISSN 2376-5992. doi: 10.7717/peerj-cs.103. URL https://doi.org/10.7717/peerj-cs.103 explains it and many other resources can be found online; for example, a comprehensive documentation isSymPy. SymPy’s documentation. URL http://docs.sympy.org/latest/index.html and a well written, understandable tutorialSymPy. SymPy’s tutorial. URL http://docs.sympy.org/latest/tutorial/index.html is provided by the original development team.
Here we avoid to duplicate the tutorial with similar examples, instead we state the methodology used while coding our definitions. Python is a very expressive language allowing programmers to use both the object-oriented and functional paradigms. It can tackle different application domains by means of modules and sympy is an example that targets the manipulation of symbolic terms. Contrary to other proprietary software like Maple and Mathematica which ship their own languages, sympy is implemented entirely in Python, allowing a transparent and easy integration in other Python programs, as we will see in later chapters.
The main point to grasp in our opinion is the difference between the meta language, which is Python, and the object language, which is the mathematical expressions denoted by sympy objects.
Example 1.2. Symbol is a fundamental class of objects that introduces arbitrary mathematical symbols.
>>> from sympy import Symbol
>>> a_sym = Symbol('a')
>>> a_sym
aThe previous snippet allows us to clarify the duality among meta and object languages; precisely, the mathematical expression is denoted by the Python object a_sym.
The above example is the first one found by the reader and it shows a common pattern used through this document to illustrate computations; in particular, when a line starts with (i) >>> then it is an input line holding code to be executed, (ii) ... then it is a continuation line holding an unfinished code expression, otherwise (iii) it is an output line reporting the result of the evaluation.
A second fundamental methodology that we embrace in our symbolic manipulations is equational reasoning, namely we use equations denoted by Eq objects to express identities to reason about, used both to define things and to be solved with respect to a desired symbol.
Example 1.3. Introduction of Eq, solve and symbols functions:
>>> from sympy import Eq, solve, symbols
>>> a, t = symbols('a t')
>>> a_def = Eq(a, 3)
>>> at_eq = Eq(a+5*t, 1/(1-t))
>>> a_def, at_eq>>> sols = [Eq(t, s) for s in solve(at_eq, t)]
>>> solsDue to the importance of equations in our code, we introduce two helper functions. First, define builds a definition:
def define(let, be, ctor=Eq, **kwds,):
if 'evaluate' not in kwds: # If `evaluate` is already given, use it # as it is,
kwds['evaluate'] = False # otherwise set to `False` to preevent evaluation
# by `Eq`, which implicitly do simplifications;Example 1.4. Introduction of Function objects:
>>> from sympy import Function, sqrt
>>> f = Function('f')
>>> f(3)
f(3)
>>> t = symbols('t')
>>> define(let=f(t), be=(1-sqrt(1-4*t))/(2*t), ctor=FEq)The keyword argument ctor=FEq asks define to promote the equation we are defining as a callable object by means of the FEq class,
first, *rest = lst # Destructure `lst` into car and cdr.
accumulated = key(first) # Init the accumulator with the first element.
while rest: # While there is element in the cdr,
current, *rest = rest # take the next element to combine
accumulated = f(accumulated, key(current)) # with the accumulated value via the function `f`.
return accumulated # Finally, return the accumulated value.
class FEq(Eq):
def __call__(self, *args, **kwds):
with lift_to_Lambda(self, **kwds) as feq:
applied = feq(*args)
if isinstance(applied, Eq):
subs = Subs(applied, self.lhs, self.rhs)
setattr(subs, 'substitution', partial(
lambda inner_self, *args, **kwds: self, subs))
return subs
else:
return applied
def swap(self):
return self.__class__(self.rhs, self.lhs)
def __iter__(self):
yield self.lhs, self.rhs
def as_substitution(self):
return dict(self)
def __mod__(self, arg):which provides methods that allows it to be used as a substitution too; in turn, it depends on
@contextmanager
def lift_to_Lambda(eq, return_eq=False, lhs_handler=lambda args: []):
lhs = eq.lhs
args = (lhs.args[1:] if isinstance(lhs, Indexed) else # get arguments wrt the type of `lhs` object;
lhs.args if isinstance(lhs, Function) else # here we handle both function and subscript
lhs_handler(lhs)) # notations. Finally, `Lambda` is theExample 1.5. Introduction of IndexedBase objects:
>>> from commons import lift_to_Lambda
>>> from sympy import IndexedBase
>>> a = IndexedBase('a')
>>> aeq = Eq(a[n], n+a[n-1])
>>> aeq(n+1)>>> b = Function('b')
>>> beq = Eq(b(n), n+b(n-1))
>>> beq(n+1)1.3Riordan Arrays, computationally#
In this section we describe a little framework that implements parts of the concepts seen in the previous section; in particular, we provide some strategies to build Riordan arrays, to find corresponding production matrices and their group inverse elements, respectively.
First of all we introduce (i) function symbols d_fn and h_fn to denote arbitrary symbolic functions and , (ii) indexed symbols d and h to denote arbitrary symbolic and indexed coefficients
>>> d_fn, h_fn = Function('d'), Function('h')
>>> d, h = IndexedBase('d'), IndexedBase('h')respectively. To build Riordan matrices we use Matrix objects; in particular, the expression Matrix(r, c, ctor) denotes a matrix with r rows and c columns where each coefficient in the matrix is defined according to ctor which is a callableFrom the official doc at https://docs.python.org/3/library/functions.html#callable: callable(object) return True if the object argument appears callable, False if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); instances are callable if their class has a __call__ method. object consuming two arguments and , its row and column coordinates. We call it ctor as abbreviation for constructor, because it allows us to code the definition of each coefficient with a Python callable object.
Here we show how to build a pure symbolic matrix:
>>> from sympy import Matrix
>>> rows, cols = 5, 5
>>> ctor = lambda i,j: d[i,j]
>>> Matrix(rows, cols, ctor)In the following sections we show a collection of such ctors, each one of them implements one theoretical characterization used to denote Riordan arrays and corresponding examples are given.
1.3.1Convolution ctor#
The following definition implements a ctor that allows us to build Riordan arrays by convolution of their and functions; here it is,
def riordan_matrix_by_convolution(dim, d, h):
t = symbols('t') # Local symbol to denote a formal variable `t`.
with lift_to_Lambda(d, return_eq=True) as D: # Lift equations `d` and `h` to become callables
with lift_to_Lambda(h, return_eq=True) as H: # objects, returning equations as well, in order
d_eq, h_eq = D(t), H(t) # to let both of them depend on variable `t`.
@lru_cache(maxsize=None)
def column(j): # Columns are memoized for the sake of efficiency.
if not j: return d_eq # Base case.
lhs = column(j-1).lhs * h_eq.lhs # Otherwise, use already computed column to build
rhs = column(j-1).rhs * h_eq.rhs # the current `lhs` and `rhs`.
return Eq(lhs, rhs)
@lru_cache(maxsize=None)
def C(j): # Local function that performs Taylor expansion
return column(j).rhs.series(t, n=dim).removeO() # of columns, which are symbolic terms up to now.
return lambda i, j: C(j).coeff(t, i).expand() # Return a lambda to be plugged in a `Matrix` ctor.Example 1.6. Symbolic Riordan array built by two polynomials with symbolic coefficients:
>>> d_series = Eq(d_fn(t), 1+sum(d[i]*t**i for i in range(1,m)))
>>> h_series = Eq(h_fn(t), t*(1+sum(h[i]*t**i for i in range(1,m-1)))).expand()
>>> d_series, h_series>>> R = Matrix(m, m, riordan_matrix_by_convolution(m, d_series, h_series))
>>> RExample 1.7. The Pascal triangle built using closed generating functions:
>>> d_series = Eq(d_fn(t), 1/(1-t))
>>> h_series = Eq(h_fn(t), t*d_series.rhs)
>>> d_series, h_series>>> R = Matrix(10, 10, riordan_matrix_by_convolution(10, d_series, h_series))
>>> R1.3.2Recurrence ctor#
The following definition implements a ctor that allows us to build Riordan arrays by a recurrence relation over coefficients ; here it is,
def riordan_matrix_by_recurrence(dim, rec, init={(0,0):1},
ctor=zeros, post=expand,
lattice=None):
if not lattice:
lattice = [(n, k) for n in range(1, dim) # `lattice` denotes the order in which coeffs in
for k in range(n+1)] # the array will be computed; it can be plugged in.
R = ctor(dim) # Initial array as base for recursive construction.
for cell, i in init.items(): R[cell] = i # Set boundary values for the recurrence `rec`.
for cell in lattice: # Visit cells as they appear in the order `lattice`;
for comb_cell, v in rec(*cell).items(): # then, get dependencies with respect the each cell.
try:
comb = (1 if cell == comb_cell
else R[comb_cell]) # If it is possible to access the dependee cell,
combined = v * comb # then perform the combination using the given `v`.
except IndexError:
combined = 0 # Otherwise, take `0` because combination fails.
R[cell] += combined # Finally, accumulate the current combination.
if callable(post): R = R.applyfunc(post) # If some post processing is desired, do it.
return lambda n, k: R[n, k] # Return a lambda that uses the computed `R`.Example 1.8. Symbolic Riordan Array built according to the recurrence:
>>> dim = 5
>>> a, b, b_bar, c = symbols(r'a b \bar{b} c')
>>> M = Matrix(dim, dim,
... riordan_matrix_by_recurrence(
... dim, lambda n, k: {(n-1, k-1):a,
... (n-1, k): b if k else b_bar,
... (n-1, k+1):c}))
>>> M>>> production_matrix(M)Forcing and yield the easier matrix Msubs
>>> Msubs = M.subs({a:1, b_bar:b})
>>> Msubs, production_matrix(Msubs)and the correspoding production matrix checks the substitution.
Previous examples uses the function production_matrix to compute the production matrixE. Deutsch, L. Ferrari, and S. Rinaldi. Production matrices. Advances in Applied Mathematics, 34(1):101–122, 2005. ISSN 0196-8858. doi: 10.1016/j.aam.2004.05.002. URL http://www.sciencedirect.com/science/article/pii/S0196885804000673; and E. Deutsch, L. Ferrari, and S. Rinaldi. Production Matrices and Riordan Arrays. Annals of Combinatorics, 13(1):65–85, July 2009. ISSN 0219-3094. doi: 10.1007/s00026-009-0013-1. URL https://doi.org/10.1007/s00026-009-0013-1 of a Riordan array, here is its definition with two helper ctors:
def columns_symmetry(M):
return lambda i, j: M[i, i-j]
def rows_shift_matrix(by):
return lambda i, j: 1 if i + by == j else 0
def diagonal_func_matrix(f):
return lambda i, j: f(i) if i == j else 0
def production_matrix(M, exp=False):
f = factorial if exp else one
U = Matrix(M.rows, M.cols, rows_shift_matrix(by=1))
F = Matrix(M.rows, M.cols, diagonal_func_matrix(f))
F_inv = F**(-1)
V = F_inv * U * F
O = F_inv * M * F
O_inv = O**(-1)
PM = F * O_inv * V * O * F_inv
PM = F_inv * PM * F if exp else PM
PM = PM[:-1, :-1]
return PM.applyfunc(simplify)implemented according toP. Barry. Riordan Arrays: A Primer. Lulu.com, 2017. ISBN 9781326855239. URL https://books.google.it/books?id=7fGBDgAAQBAJ, p. 215.
1.3.3 and sequences ctor#
The following definition implements a ctor that allows us to build Riordan arrays by their and sequences; here it is,
def riordan_matrix_by_AZ_sequences(dim, seqs, init={(0,0):1},
ctor=zeros, post=expand,
lattice=None):
if not lattice: lattice = [(n, k) for n in range(1, dim)
for k in range(n+1)]
Zseq, Aseq = seqs
t = symbols('t')
with lift_to_Lambda(Zseq) as Z, lift_to_Lambda(Aseq) as A:
Z_series = Z(t).series(t, n=dim).removeO()
A_series = A(t).series(t, n=dim).removeO()
R = ctor(dim)
for cell, i in init.items(): R[cell] = i
for n, k in lattice:
if k:
v = sum(R[n-1, j] * A_series.coeff(t, n=i)
for i, j in enumerate(range(k-1, dim)))
else:
v = sum(R[n-1, j] * Z_series.coeff(t, n=j)
for j in range(dim))
R[n, k] = v
if callable(post): R = R.applyfunc(post)
return lambda n, k: R[n, k]in words, (i) it deconstructs seqs into objs denoting Z and A seqs, promoting both of them as callables, (ii) it introduces the formal variable t, (iii) it performs two Taylor expansions with respect to t. In order to build the resulting matrix, it visits each cell according to the order given by lattice then if the cell lies not on the first column, it combines using A_series coefficients up to the cell in position (k-1, dim-1); otherwise, it combine using Z_series coefficients up to the cell in position (k-1, dim-1). Finally, it stores the combination and if some post processing is desired, it does so; at last, it returns a lambda that uses the computed matrix R.
Example 1.9. Again the Pascal triangle built using and sequences
>>> A, Z = Function('A'), Function('Z')
>>> A_eq = Eq(A(t), 1 + t)
>>> Z_eq = Eq(Z(t),1)
>>> A_eq, Z_eq>>> R = Matrix(10, 10, riordan_matrix_by_AZ_sequences(10, (Z_eq, A_eq)))
>>> R, production_matrix(R)Example 1.10. Catalan triangle built using and sequences,
>>> A_ones = Eq(A(t), 1/(1-t)) # A is defined as in the previous example
>>> R = Matrix(10, 10, riordan_matrix_by_AZ_sequences(10, (A_ones, A_ones)))
>>> R, production_matrix(R)Example 1.11. Symbolic Riordan arrays built using and sequences,
>>> dim = 5
>>> a = IndexedBase('a')
>>> A_gen = Eq(A(t), sum((a[j] if j else 1)*t**j for j in range(dim)))
>>> R = Matrix(dim, dim, riordan_matrix_by_AZ_sequences(dim, (A_gen, A_gen)))
>>> R>>> z = IndexedBase('z')
>>> A_gen = Eq(A(t), sum((a[j] if j else 1)*t**j for j in range(dim)))
>>> Z_gen = Eq(Z(t), sum((z[j] if j else 1)*t**j for j in range(dim)))
>>> Raz = Matrix(dim, dim, riordan_matrix_by_AZ_sequences(dim, (Z_gen, A_gen)))
>>> Raz>>> production_matrix(R), production_matrix(Raz)1.3.4Exponential ctor#
The following definition implements a ctor that allows us to build an exponential Riordan array; here it is,
def riordan_matrix_exponential(RA):
return lambda i,j: factorial(i)*RA(i,j)/factorial(j)Example 1.12. Build the triangle of Stirling numbers of the II kind:
>>> d_series = Eq(d_fn(t), 1)
>>> h_series = Eq(h_fn(t), exp(t)-1)
>>> d_series, h_series>>> R = matrix(10, 10, riordan_matrix_exponential(
... riordan_matrix_by_convolution(
... 10, d_series, h_series)))
>>> R>>> production_matrix(R), production_matrix(R, exp=True)>>> inspect(R)
nature(is_ordinary=False, is_exponential=True)In the above example we introduced another function inspect that studies the type of array it consumes. Before reporting its definition we remark that the matrix on the left is an usual production matrix (which tells us that , for example); on the other hand, the matrix on right helps to decide if the array is an exponential one by proving that each diagonal is an arithmetic progression, for more on this seeP. Barry. Riordan Arrays: A Primer. Lulu.com, 2017. ISBN 9781326855239. URL https://books.google.it/books?id=7fGBDgAAQBAJ.
def inspect(M):
P = production_matrix(M, exp=False) # Ordinary production matrix.
C = production_matrix(M, exp=True) # "Exponential" production matrix.
is_ord = all(P[:1-i, 1] == P[i-1:, i] # A RA is ordinary if columns of its PM
for i in range(2, P.cols)) # are shifted but equals.
diagonals = {d: [C[j+d,j] for j in range(1,C.rows-d)] # Fetch matrix diagonals for the
for d in range(C.rows-3) } # exponential case.
is_exp = all(map(is_arithmetic_progression, # A Riordan array is exponential if `diagonals`
diagonals.values())) # are arithmetic progressions, all of them.
return nature(is_ord, is_exp)
def is_arithmetic_progression(prog):
steps = len(prog)-1
for _ in range(steps):
prog = [(b-a).simplify() # Reduce the list by consecutive differences,
for a, b in zip(prog, prog[1:])] # till a single object survives.
assert len(prog) == 1 # Consistency check of the last comment.
return prog.pop() == 0 # Finally, the reduced object has to vanish.Example 1.13. In this example we explore an exponential Riordan array starting from the generating functions of the Pascal triangle. Surprisingly the array we get back is known in the OEIS (https://oeis.org/A021009) and looking for some comments we quote the observation
“the generalized Riordan array with respect to the sequence is Pascal’s triangle A007318”
>>> d_series, h_series = Eq(d_fn(t), 1/(1-t)), Eq(h_fn(t), t/(1-t))
>>> d_series, h_series>>> R = matrix(10, 10, riordan_matrix_exponential(
... riordan_matrix_by_convolution(
... 10, d_series, h_series)))
>>> R>>> production_matrix(R), production_matrix(R, exp=True)>>> inspect(R)
nature(is_ordinary=False, is_exponential=True)1.3.5Group inverse elements#
In this final section we show how to compute the compositional inverse of a function and then apply this procedure to find the inverse of a given Riordan array. By small steps, your task is to find the compositional inverse of Pascal array’s function
namely you want to find a function such that . Starting from this very last identity we use the substitution notation
that allows us to reduce the original problem to solve with respect to ; formally, using the definition of we rewrite
The latter identity can be used back in as substitution for yielding as required; this procedure is promptly implemented as
def compositional_inverse(h_eq, y=symbols('y'), check=True):
spec, body = h_eq.lhs, h_eq.rhs # Destructuring function $h$ denoted by `h_eq`,
t, = spec.args # let `t` be the formal var of function $h$.
# $\bar{h}(h(t)) = t \leftrightarrow \left[ \bar{h}(y) = t\, | \, y = h(t) \right]$ allows us
sols = solve(Eq(y, body), t) # to solve $y = h(t)$ with respect to $t$ because
for sol in sols: # $h(t)$ is known, denoted by `body`. For each
L = Lambda(y, sol) # solution `sol`, which depends on $y$, we build
if L(0) == 0: # a callable object `L`. If it vanishes in $0$ and
# $\bar{h}(h(t))=t$, then it is a compositional
if check: assert L(body).simplify() == t # inverse of $h$.
h_bar = Function(r'\bar{{ {} }}'.format( # Prepare the name for function $\bar{h}$ and
str(spec.func)))
eq = Eq(h_bar(y), sol.factor()) # build the corresponding equation that defines
return eq # $\bar{h}(y)$, compositional inverse of $h(t)$.
raise ValueError # If the above code fails to return, raise an error.def group_inverse(d_eq, h_eq, post=identity, check=True):
t, y = symbols('t y') # Formal symbols for symbolic functions $f$ and $g$.
g_fn, f_fn = Function('g'), Function('f')
with lift_to_Lambda(d_eq, return_eq=False) as D: # Promote equations `d` and `h` to become
with lift_to_Lambda(h_eq, return_eq=True) as H: # callables objects, returning equations as well.
f_eq = compositional_inverse(H(t), y, check) # Let function $f$ be the compositional inverse of
with lift_to_Lambda(f_eq, return_eq=False) as F: # function $h$, then promote it as callable and
F_t = F(t) # (i) evaluate it at $t$;
g = post(1/D(F_t)) # (ii) build and refine $g$, the first function of
f = post(F_t) # the new Ra; (iii) refine $f$, the snd function.
g_eq = Eq(g_fn(t), g.simplify()) # Build corresponding equation objects with
f_eq = Eq(f_fn(t), f.simplify()) # simplified expressions.
if check: # If it is required to certify the computation,
with lift_to_Lambda(g_eq, return_eq=False) as G: # then promote the just built equations `g` and
with lift_to_Lambda(f_eq, return_eq=False) as F: # `f` to perform group operation in order to
H_rhs = H(t).rhs # check that, it yields the identity element,
assert (D(t)*G(H_rhs)).simplify() == 1 # which has (i) $1$ as first component and
assert F(H_rhs).simplify() == t # (ii) $t$ as second component.
return g_eq, f_eqExample 1.14. Compositional inverse of Catalan tringle’s generating function:
>>> catalan_term = (1-sqrt(1-4*t))/(2*t)
>>> d_series = Eq(d_fn(t), catalan_term)
>>> h_series = Eq(h_fn(t), t*catalan_term)
>>> h_series, compositional_inverse(h_series)>>> C_inverse = group_inverse(d_series, h_series, post=radsimp)
>>> C_inverse>>> R = Matrix(10, 10, riordan_matrix_by_convolution(
... 10, C_inverse[0], C_inverse[1]))
>>> RConclusions#
This chapter offers to the reader a concise review of the theory of Riordan Arrays by recalling definitions, characterizations and their fundamental properties; moreover, we pair these formal arguments with a set of software abstractions that allow us to mimic the theory with objects living in a computer. Coding our definitions using the Python programming language and taking advantage of the symbolic module Sympy, we provide a coherent and unified environment to experiment in.