Skip to content

Commit

Permalink
Merge pull request #5 from asvarga/main
Browse files Browse the repository at this point in the history
generate_image: add --close and --filter flags
  • Loading branch information
teorth authored Sep 26, 2024
2 parents 4897379 + 2d58a2f commit 84c548e
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions scripts/generate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Example usage:
```sh
$ python scripts/generate_image.py equational_theories/Basic.lean
$ pip install pillow
$ python scripts/generate_image.py equational_theories/Basic.lean --close --filter
$ open equational_theories/Basic.png
```
"""
Expand All @@ -21,6 +22,19 @@ def name_to_ind(name):
KNOWN_IMPLIES_COLOR = (0, 255, 0)
KNOWN_NOT_IMPLIES_COLOR = (255, 0, 0)

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]
Expand All @@ -29,16 +43,19 @@ def name_to_ind(name):
print('Usage: python process_implications.py <file_name.lean>')
exit(1)


universe, known_implies, known_not_implies = parse_proofs_file(file_name)
# all_unknown = get_unknown_implications(universe, known_implies, known_not_implies)

inds = [name_to_ind(e) for e in universe]
min_ind = min(inds)
max_ind = max(inds)
if '--close' in argv:
known_implies = close(known_implies)

inds = {e: name_to_ind(e) for e in universe}
if '--filter' in argv:
inds = {kv[0]: i for i, kv in enumerate(sorted(inds.items(), key=lambda kv: kv[1]))}
min_ind = min(inds.values())
max_ind = max(inds.values())
size = max_ind - min_ind + 1
def ind(name):
return name_to_ind(name) - min_ind
return inds[name] - min_ind

data = [UNKNOWN_COLOR] * (size * size)
for known in known_implies:
Expand Down

0 comments on commit 84c548e

Please sign in to comment.