-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathgenerate_most_wanted_list.py
More file actions
executable file
·66 lines (54 loc) · 1.95 KB
/
generate_most_wanted_list.py
File metadata and controls
executable file
·66 lines (54 loc) · 1.95 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""
Example usage:
```sh
$ python scripts/generate_most_wanted_list.py equational_theories/Subgraph.lean
$ less most_wanted.md
```
"""
from process_implications import *
from itertools import product
from datetime import datetime
def close(known_implies):
# copilot wrote this
new_pairs = closure = set(known_implies)
while new_pairs:
new_pairs = {
(a, d) for a, b in new_pairs for c, d in known_implies if b == c
} - closure
closure |= new_pairs
return closure
if __name__ == "__main__":
try:
file_name = argv[1]
assert os.path.exists(file_name)
except:
print("Usage: python generate_most_wanted_list.py <file_name.lean>")
exit(1)
universe, known_implies, known_not_implies = parse_proofs_file(file_name)
known_implies = close(known_implies)
ascendants = defaultdict(int) # equation -> equations it's implied by
descendants = defaultdict(int) # equation -> equations it implies
for a, b in known_implies:
if a != b:
descendants[a] += 1
ascendants[b] += 1
edge_value = {} # (a, b) -> value of the a->b implication
for a, b in product(universe, universe):
if (a, b) in known_implies or (a, b) in known_not_implies:
continue
# This doesn't work with cycles
v = ascendants[a] + descendants[b]
# speed things up by not recording explicitly zero-value edges
if v > 0:
edge_value[(a, b)] = v
with open("most_wanted.md", "w+") as fh:
fh.write(
f"# Most Wanted list of implications as of ({datetime.now().strftime('%Y-%m-%d %H:%M:%S')})"
+ "\n\n"
)
for a, b in sorted(edge_value, key=lambda ab: edge_value[ab], reverse=True):
fh.write(
f"* `{a}` -> `{b}` (implied by {ascendants[a]} -> implies {descendants[b]} = {edge_value[(a,b)]})"
+ "\n"
)