Originally Posted by

**Plato** Suppose that $\displaystyle Z=1,~2,\text{ or }3$ then you need two functions such that $\displaystyle (1,Z)\in g\text{ and }(Z,3)\in f$.

That would mean that $\displaystyle (1,3)\in f\circ g$.

How many pairs $\displaystyle (g,f)$ have those properties?

Thank you once more. If I understand correctly, if $\displaystyle Z=1,~2,\text{ or }3$, then there are three possibilities for the ordered pairs $\displaystyle (1,Z)\in g\text{ and }(Z,3)\in f$. As each of the two unmapped inputs in f and g must then be mapped to one of three possible outputs, there are 3(3^2)(3^2) = 3^5 = 243 pairs $\displaystyle (g,f)$ that have the desired properties. A small Python program I wrote agrees:

Code:

def test_functions(functions):
for f in functions:
for g in functions:
if f[g[1]] == 3:
print f, g, f[g[1]]
def make_functions():
functions = []
for i in range(1, 4):
for j in range(1, 4):
for k in range(1, 4):
functions.append({1: i, 2: j, 3: k})
return functions
test_functions(make_functions())