-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold_comments.txt
38 lines (28 loc) · 1.57 KB
/
old_comments.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
The idiom `product(*tuple(ranges))` found below is a bit tricky to understand but it is extremely useful.
Recall that the function `product` is a Python standard library function. It takes the Cartesian
product of an arbitrary number of iterables. You can find the docs for `product` here:
https://docs.python.org/3/library/itertools.html#itertools.product
A naive inventory is an element of
`product(ranges[0], ranges[1], ranges[2], ..., ranges[N-1])`
However, we cannot use the `...` syntax in this way in Python. Instead, we must use the unary
"unpacking" operator, denoted by `*`. This operator takes a tuple and turns each element of the
tuple into an argument of a function.
So for example, you could do
`comb(*(5,3))`
which gives you the same number as `comb(5,3)` does. The operator `*` is useless in this context.
However, `*` is very useful when the function can take a variable number of arguments, like
`product` does.
So `product(*tuple(ranges))` takes the list `ranges`, converts it to a tuple, then "unpacks" it
for the variable-parameter function `product`.
"""
"""
An inventory is a list of non-negative integers of length `N`.
If `inv` is an inventory and `1 <= k <= N`, then `inv[k]` is the number of open sets in
a minimal basis of size `k`.
The Python standard library function `comb` calculates binomial coefficients. Follow this
link for a description:
https://docs.python.org/3/library/math.html#math.comb
Naively, `inv[k]` can take on any value between 0 and `comb(N,k)`, inclusive.
The following code creates a list `inventories` of all possible naive inventories.
"""