This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (40 loc) · 1.56 KB
/
main.py
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
from typing import Callable
import utils
from detect_relation_types import *
def main(M: tuple, tau: Callable[[int, int], bool]) -> None:
utils.new_section("M", need_first_nl=False)
print(M)
utils.new_section("M * M")
for i in range(len(M)):
for j in range(len(M)):
print(f"({M[i]},{M[j]})", end="\t")
print()
utils.new_section("M * M (with tau)")
taus = set()
for i in range(len(M)):
for j in range(len(M)):
if tau(M[i], M[j]):
taus.add(Pair(x=M[i], y=M[j]))
print(f"({M[i]},{M[j]})", end="\t")
else:
print("-", end="\t")
print()
utils.new_section("properties of binary relations")
which_relation = WhichRelation(
reflexive_relation=is_reflexive_relation(M, taus),
symmetric_relation=is_symmetric_relation(M, taus),
antisymmetric_relation=is_antisymmetric_relation(M, taus),
transitive_relation=is_transitive_relation(M, taus),
)
for relation in which_relation._fields:
if getattr(which_relation, relation).is_belong_to_type:
print(f"{relation}\t+")
else:
print(f"{relation}\t-\t{getattr(which_relation, relation).message}")
utils.new_section("types of binary relations")
print(f"equivalence relation\t{'+' if is_equivalence_relation(which_relation) else '-'}")
print(f"order relation\t\t{'+' if is_order_relation(which_relation) else '-'}")
if __name__ == "__main__":
M = (-1, 2, 3, 4)
tau = lambda x, y: x*y >= x-y
main(M, tau)