Massimo Nocentini


Abstract
In this document we collect a naive type system based on sets.

In [1]:
from itertools import repeat
from sympy import *
#from type_system import *

In [2]:
%run ../../src/commons.py

In [3]:
%run ./type-system.py


In [4]:
init_printing()

In [5]:
x,y,m,n,t,z = symbols('x y m n t z', commutative=True)
alpha, beta, gamma, eta = symbols(r'\alpha \beta \gamma \eta', commutative=True)
f,g = Function('f'), Function('g')


In [7]:
bin_tree_gfs = bin_tree(tyvar(alpha)[z]).gf()
bin_tree_gfs


Out[7]:
$$\left [ \mathcal{B}{\left (\alpha,z \right )} = \frac{- \sqrt{- 4 \alpha z + 1} + 1}{2 \alpha z}, \quad \mathcal{B}{\left (\alpha,z \right )} = \frac{\sqrt{- 4 \alpha z + 1} + 1}{2 \alpha z}\right ]$$

In [8]:
bin_tree_gf = bin_tree_gfs[0]

In [10]:
bin_tree_gf.series(z, n=10, kernel='ordinary')


Out[10]:
$$\mathcal{B}{\left (\alpha,z \right )} = \frac{- \sqrt{- 4 \alpha z + 1} + 1}{2 \alpha z} = 1 + \alpha z + 2 \alpha^{2} z^{2} + 5 \alpha^{3} z^{3} + 14 \alpha^{4} z^{4} + 42 \alpha^{5} z^{5} + 132 \alpha^{6} z^{6} + 429 \alpha^{7} z^{7} + 1430 \alpha^{8} z^{8} + 4862 \alpha^{9} z^{9} + O\left(z^{10}\right)$$

In [9]:
bin_tree_gf.series(z, n=10, kernel='catalan')


Out[9]:
$$\mathcal{B}{\left (\alpha,z \right )} = \frac{- \sqrt{- 4 \alpha z + 1} + 1}{2 \alpha z} = 1 + \alpha z + \alpha^{2} z^{2} + \alpha^{3} z^{3} + \alpha^{4} z^{4} + \alpha^{5} z^{5} + \alpha^{6} z^{6} + \alpha^{7} z^{7} + \alpha^{8} z^{8} + \alpha^{9} z^{9} + O\left(z^{10}\right)$$

In [11]:
occupancy(bin_tree_gf, syms=[alpha], objects='unlike', boxes='unlike').series(z)


Out[11]:
$$\operatorname{gf}{\left (\alpha,z \right )} = \frac{\alpha^{-1} \left(1 - \sqrt{- 4 z \alpha + 1}\right)}{2 z} = 1 + z \alpha + 2 z^{2} \alpha^{2} + 5 z^{3} \alpha^{3} + 14 z^{4} \alpha^{4} + 42 z^{5} \alpha^{5} + O\left(z^{6}\right)$$


In [13]:
bin_tree_of_boolean_gfs = bin_tree(maybe(tyvar(alpha))[z]).gf()
bin_tree_of_boolean_gfs


Out[13]:
$$\left [ \mathcal{B}{\left (\alpha,z \right )} = \frac{- \sqrt{- 4 \alpha z - 4 z ␣ + 1} + 1}{2 z \left(\alpha + ␣\right)}, \quad \mathcal{B}{\left (\alpha,z \right )} = \frac{\sqrt{- 4 \alpha z - 4 z ␣ + 1} + 1}{2 z \left(\alpha + ␣\right)}\right ]$$

In [21]:
bin_tree_of_boolean_gf = bin_tree_of_boolean_gfs[0]

In [23]:
occupancy(bin_tree_of_boolean_gf, syms=[alpha], objects='unlike', boxes='unlike').series(z,n=6, kernel='ordinary')


Out[23]:
$$\operatorname{gf}{\left (␣,\alpha,z \right )} = \frac{\left(\alpha + ␣\right)^{-1} \left(1 - \sqrt{- 4 z \alpha - 4 z ␣ + 1}\right)}{2 z} = \left(\alpha + ␣\right)^{-1} ␣ + \left(\alpha + ␣\right)^{-1} \alpha + z \left(\left(\alpha + ␣\right)^{-1} \alpha ␣ + \left(\alpha + ␣\right)^{-1} \alpha^{2} + \left(\alpha + ␣\right)^{-1} ␣ \alpha + \left(\alpha + ␣\right)^{-1} ␣^{2}\right) + z^{2} \left(2 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha + 2 \left(\alpha + ␣\right)^{-1} \alpha ␣^{2} + 2 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣ + 2 \left(\alpha + ␣\right)^{-1} \alpha^{3} + 2 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣ + 2 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{2} + 2 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha + 2 \left(\alpha + ␣\right)^{-1} ␣^{3}\right) + z^{3} \left(5 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha ␣ + 5 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha^{2} + 5 \left(\alpha + ␣\right)^{-1} \alpha ␣^{2} \alpha + 5 \left(\alpha + ␣\right)^{-1} \alpha ␣^{3} + 5 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣ \alpha + 5 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣^{2} + 5 \left(\alpha + ␣\right)^{-1} \alpha^{3} ␣ + 5 \left(\alpha + ␣\right)^{-1} \alpha^{4} + 5 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣ \alpha + 5 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣^{2} + 5 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{2} ␣ + 5 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{3} + 5 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha ␣ + 5 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha^{2} + 5 \left(\alpha + ␣\right)^{-1} ␣^{3} \alpha + 5 \left(\alpha + ␣\right)^{-1} ␣^{4}\right) + z^{4} \left(14 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha ␣ \alpha + 14 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha ␣^{2} + 14 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha^{2} ␣ + 14 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha^{3} + 14 \left(\alpha + ␣\right)^{-1} \alpha ␣^{2} \alpha ␣ + 14 \left(\alpha + ␣\right)^{-1} \alpha ␣^{2} \alpha^{2} + 14 \left(\alpha + ␣\right)^{-1} \alpha ␣^{3} \alpha + 14 \left(\alpha + ␣\right)^{-1} \alpha ␣^{4} + 14 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣ \alpha ␣ + 14 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣ \alpha^{2} + 14 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣^{2} \alpha + 14 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣^{3} + 14 \left(\alpha + ␣\right)^{-1} \alpha^{3} ␣ \alpha + 14 \left(\alpha + ␣\right)^{-1} \alpha^{3} ␣^{2} + 14 \left(\alpha + ␣\right)^{-1} \alpha^{4} ␣ + 14 \left(\alpha + ␣\right)^{-1} \alpha^{5} + 14 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣ \alpha ␣ + 14 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣ \alpha^{2} + 14 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣^{2} \alpha + 14 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣^{3} + 14 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{2} ␣ \alpha + 14 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{2} ␣^{2} + 14 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{3} ␣ + 14 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{4} + 14 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha ␣ \alpha + 14 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha ␣^{2} + 14 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha^{2} ␣ + 14 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha^{3} + 14 \left(\alpha + ␣\right)^{-1} ␣^{3} \alpha ␣ + 14 \left(\alpha + ␣\right)^{-1} ␣^{3} \alpha^{2} + 14 \left(\alpha + ␣\right)^{-1} ␣^{4} \alpha + 14 \left(\alpha + ␣\right)^{-1} ␣^{5}\right) + z^{5} \left(42 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha ␣ \alpha ␣ + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha ␣ \alpha^{2} + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha ␣^{2} \alpha + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha ␣^{3} + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha^{2} ␣ \alpha + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha^{2} ␣^{2} + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha^{3} ␣ + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣ \alpha^{4} + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣^{2} \alpha ␣ \alpha + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣^{2} \alpha ␣^{2} + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣^{2} \alpha^{2} ␣ + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣^{2} \alpha^{3} + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣^{3} \alpha ␣ + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣^{3} \alpha^{2} + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣^{4} \alpha + 42 \left(\alpha + ␣\right)^{-1} \alpha ␣^{5} + 42 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣ \alpha ␣ \alpha + 42 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣ \alpha ␣^{2} + 42 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣ \alpha^{2} ␣ + 42 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣ \alpha^{3} + 42 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣^{2} \alpha ␣ + 42 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣^{2} \alpha^{2} + 42 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣^{3} \alpha + 42 \left(\alpha + ␣\right)^{-1} \alpha^{2} ␣^{4} + 42 \left(\alpha + ␣\right)^{-1} \alpha^{3} ␣ \alpha ␣ + 42 \left(\alpha + ␣\right)^{-1} \alpha^{3} ␣ \alpha^{2} + 42 \left(\alpha + ␣\right)^{-1} \alpha^{3} ␣^{2} \alpha + 42 \left(\alpha + ␣\right)^{-1} \alpha^{3} ␣^{3} + 42 \left(\alpha + ␣\right)^{-1} \alpha^{4} ␣ \alpha + 42 \left(\alpha + ␣\right)^{-1} \alpha^{4} ␣^{2} + 42 \left(\alpha + ␣\right)^{-1} \alpha^{5} ␣ + 42 \left(\alpha + ␣\right)^{-1} \alpha^{6} + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣ \alpha ␣ \alpha + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣ \alpha ␣^{2} + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣ \alpha^{2} ␣ + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣ \alpha^{3} + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣^{2} \alpha ␣ + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣^{2} \alpha^{2} + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣^{3} \alpha + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha ␣^{4} + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{2} ␣ \alpha ␣ + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{2} ␣ \alpha^{2} + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{2} ␣^{2} \alpha + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{2} ␣^{3} + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{3} ␣ \alpha + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{3} ␣^{2} + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{4} ␣ + 42 \left(\alpha + ␣\right)^{-1} ␣ \alpha^{5} + 42 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha ␣ \alpha ␣ + 42 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha ␣ \alpha^{2} + 42 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha ␣^{2} \alpha + 42 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha ␣^{3} + 42 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha^{2} ␣ \alpha + 42 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha^{2} ␣^{2} + 42 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha^{3} ␣ + 42 \left(\alpha + ␣\right)^{-1} ␣^{2} \alpha^{4} + 42 \left(\alpha + ␣\right)^{-1} ␣^{3} \alpha ␣ \alpha + 42 \left(\alpha + ␣\right)^{-1} ␣^{3} \alpha ␣^{2} + 42 \left(\alpha + ␣\right)^{-1} ␣^{3} \alpha^{2} ␣ + 42 \left(\alpha + ␣\right)^{-1} ␣^{3} \alpha^{3} + 42 \left(\alpha + ␣\right)^{-1} ␣^{4} \alpha ␣ + 42 \left(\alpha + ␣\right)^{-1} ␣^{4} \alpha^{2} + 42 \left(\alpha + ␣\right)^{-1} ␣^{5} \alpha + 42 \left(\alpha + ␣\right)^{-1} ␣^{6}\right) + O\left(z^{6}\right)$$

In [ ]: