Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Peter's Files
Views: 3893
Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu1804
Kernel: Python 3 (system-wide)

tangled trees

Suppose you draw rows of nn evenly spaced dots each, and you take out your favorite set of mm nn-sided dice. For each dot dd in the first row, you roll all mm dice. For each number aa rolled, you draw a line from dd to the dot in the row below that is in the column aa. Continue this process, row by row, until there is some dot in the first row that is connected to every dot in some row---say---row tt.

What is the expected value of t?t ?

import random as rand

The expected value of how many distinct numbers will be rolled when throwing mm nn-sided dice:

def f_experimental(m,n,s): numDict = {} for _ in range(s): num = len(set([rand.randint(1,n) for i in range(m)])) if num not in numDict: numDict[num] = 1 else: numDict[num] += 1 return sum([key * numDict[key] for key in numDict]) / s
f_experimental(5,10,10000)
4.096

Proved: f(m,n)=n(n1n)mf(m,n)=n-\left(\frac{n-1}{n}\right)^{m}

def f(m,n): return n - n * ((n-1)/(n))**m
f(5,10)
4.0950999999999995

The expected value of the minimum number of rows tt so that one of the first dots covers all of the dots on row tt

def g_helper_experimental(m,n): row = [{i} for i in range(1, n + 1)] t = 0 # print(t, row) while set(range(1,1+n)).intersection(*row) == set(): next_row = [set() for _ in range(n)] t += 1 for dot in range(n): for _ in range(m): new_dot = rand.randint(0,n-1) next_row[new_dot] = next_row[new_dot].union(row[dot]) row = next_row # print(t, row) return t def g_experimental(m,n,s): t_dict = {} for _ in range(s): t = g_helper_experimental(m,n) if t not in t_dict: t_dict[t] = 1 else: t_dict[t] += 1 return sum([t * t_dict[t] for t in t_dict]) / s
g_experimental(2,6,10000)
7.1819
from IPython.display import display, Markdown table = "|$n,m$ |" + " | ".join(f"${m}$" for m in range(2,20)) + " | \n" table += "".join("|:--:" for _ in range(22)) + "|\n" for n in range(1,20): table += f"| **${n}$** " for m in range(2,20): table += f" | ${g_experimental(m,n,1000)}$" table += " |\n" display(Markdown(table))

|n,mn,m |22 | 33 | 44 | 55 | 66 | 77 | 88 | 99 | 1010 | 1111 | 1212 | 1313 | 1414 | 1515 | 1616 | 1717 | 1818 | 1919 | |:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐:--😐 | 11 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | 0.00.0 | | 22 | 1.441.44 | 1.081.08 | 1.021.02 | 1.0051.005 | 1.0031.003 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | | 33 | 3.0233.023 | 1.5551.555 | 1.1781.178 | 1.0611.061 | 1.021.02 | 1.0031.003 | 1.01.0 | 1.01.0 | 1.0011.001 | 1.0011.001 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | | 44 | 4.1594.159 | 2.2332.233 | 1.7361.736 | 1.3531.353 | 1.1541.154 | 1.0591.059 | 1.0181.018 | 1.0041.004 | 1.0031.003 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | 1.01.0 | | 55 | 5.7555.755 | 2.4592.459 | 2.0732.073 | 1.8331.833 | 1.551.55 | 1.3011.301 | 1.1441.144 | 1.0511.051 | 1.0271.027 | 1.0091.009 | 1.0011.001 | 1.0011.001 | 1.0011.001 | 1.01.0 | 1.0011.001 | 1.01.0 | 1.01.0 | 1.01.0 | | 66 | 6.8896.889 | 2.822.82 | 2.1292.129 | 2.0322.032 | 1.9371.937 | 1.6941.694 | 1.4761.476 | 1.2981.298 | 1.1511.151 | 1.0691.069 | 1.0361.036 | 1.0141.014 | 1.0021.002 | 1.0021.002 | 1.01.0 | 1.01.0 | 1.01.0 | 1.0011.001 | | 77 | 8.8978.897 | 3.283.28 | 2.2382.238 | 2.0452.045 | 2.0192.019 | 1.9681.968 | 1.8351.835 | 1.691.69 | 1.4771.477 | 1.281.28 | 1.1621.162 | 1.0831.083 | 1.0361.036 | 1.0271.027 | 1.0061.006 | 1.01.0 | 1.0011.001 | 1.01.0 | | 88 | 10.69710.697 | 3.6013.601 | 2.3862.386 | 2.0762.076 | 2.022.02 | 2.0042.004 | 1.9821.982 | 1.921.92 | 1.7921.792 | 1.6471.647 | 1.4541.454 | 1.2721.272 | 1.1771.177 | 1.1051.105 | 1.0491.049 | 1.0241.024 | 1.0111.011 | 1.0061.006 | | 99 | 13.08313.083 | 3.8713.871 | 2.5722.572 | 2.1032.103 | 2.022.02 | 2.012.01 | 2.0062.006 | 1.9961.996 | 1.9641.964 | 1.8911.891 | 1.7731.773 | 1.6411.641 | 1.4661.466 | 1.3371.337 | 1.2041.204 | 1.1071.107 | 1.0871.087 | 1.0331.033 | | 1010 | 17.07217.072 | 4.0464.046 | 2.8532.853 | 2.1322.132 | 2.0272.027 | 2.0092.009 | 2.0012.001 | 2.02.0 | 1.9971.997 | 1.9771.977 | 1.9431.943 | 1.8561.856 | 1.7731.773 | 1.6431.643 | 1.4761.476 | 1.3411.341 | 1.2281.228 | 1.1551.155 | | 1111 | 20.43820.438 | 4.3284.328 | 3.083.08 | 2.2762.276 | 2.0312.031 | 2.0052.005 | 2.0032.003 | 2.0032.003 | 2.02.0 | 1.9991.999 | 1.9931.993 | 1.9781.978 | 1.9251.925 | 1.8531.853 | 1.7351.735 | 1.6181.618 | 1.5141.514 | 1.3891.389 | | 1212 | 26.47626.476 | 4.6124.612 | 3.2053.205 | 2.412.41 | 2.0482.048 | 2.0082.008 | 2.0062.006 | 2.02.0 | 2.02.0 | 2.0012.001 | 1.9981.998 | 1.9941.994 | 1.9841.984 | 1.9731.973 | 1.921.92 | 1.8681.868 | 1.7651.765 | 1.6441.644 | | 1313 | 31.42731.427 | 4.7764.776 | 3.293.29 | 2.5762.576 | 2.082.08 | 2.0152.015 | 2.02.0 | 2.0012.001 | 2.02.0 | 2.02.0 | 2.02.0 | 1.9981.998 | 1.9991.999 | 1.9941.994 | 1.9771.977 | 1.9561.956 | 1.9031.903 | 1.8391.839 | | 1414 | 40.20340.203 | 5.2215.221 | 3.3473.347 | 2.7932.793 | 2.1432.143 | 2.0152.015 | 2.0042.004 | 2.0032.003 | 2.02.0 | 2.02.0 | 2.02.0 | 2.0012.001 | 2.02.0 | 1.9981.998 | 1.9971.997 | 1.991.99 | 1.9751.975 | 1.9521.952 | | 1515 | 52.8552.85 | 5.565.56 | 3.3793.379 | 2.9562.956 | 2.2412.241 | 2.0152.015 | 2.0022.002 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 1.9991.999 | 2.02.0 | 1.9961.996 | 1.9931.993 | | 1616 | 65.82565.825 | 5.7885.788 | 3.4163.416 | 3.0553.055 | 2.3742.374 | 2.0362.036 | 2.0092.009 | 2.0022.002 | 2.0022.002 | 2.0012.001 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 1.9971.997 | | 1717 | 91.18591.185 | 6.0736.073 | 3.4593.459 | 3.0873.087 | 2.5392.539 | 2.0692.069 | 2.0122.012 | 2.0042.004 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | | 1818 | 115.233115.233 | 6.296.29 | 3.5563.556 | 3.0873.087 | 2.6992.699 | 2.112.11 | 2.0162.016 | 2.0042.004 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | | 1919 | 145.382145.382 | 6.4666.466 | 3.6373.637 | 3.1293.129 | 2.832.83 | 2.1782.178 | 2.0152.015 | 2.0012.001 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 | 2.02.0 |