-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
70 lines (53 loc) · 1.85 KB
/
util.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import logging
def flatten(l):
return [item for sublist in l for item in sublist]
# utility lambda functions
def nxt(k): return (k+1) % n
def conjoin(u, v): return u & v
def disjoin(u, v): return u | v
def mergecur(x, y):
curstate = list(set(x['current_states'] + y['current_states']))
nextstate = list(set(x['next_states'] + y['next_states']))
curstate.sort()
nextstate.sort()
return { 'current_states': curstate, 'next_states': nextstate }
def red(msg):
return "\033[1;31m" + msg + "\033[0m"
def green(msg):
return "\033[1;32m" + msg + "\033[0m"
def yellow(msg):
return "\033[1;33m" + msg + "\033[0m"
def blue(msg):
return "\033[1;34m" + msg + "\033[0m"
def magenta(msg):
return "\033[1;35m" + msg + "\033[0m"
def cyan(msg):
return "\033[1;36m" + msg + "\033[0m"
def white(msg):
return "\033[1;37m" + msg + "\033[0m"
def bold(msg):
return "\033[1m" + msg + "\033[0m"
def underline(msg):
return "\033[4m" + msg + "\033[0m"
class Result:
def __init__(self, status):
self.status = status
def __str__(self):
return red("K does not ⊨ φ\n") if self.status == False else green("K ⊨ φ\n")
# Logger configuration
debug = False
if debug:
logging.basicConfig(level=logging.DEBUG,
format='%(levelname)s: %(message)s')
else:
logging.basicConfig(level=logging.INFO,
format='%(levelname)s: %(message)s')
# set error and warning colors
logging.addLevelName(
logging.ERROR, "\033[1;31m%s\033[1;0m" % logging.getLevelName(logging.ERROR))
logging.addLevelName(
logging.WARNING, "\033[1;33m%s\033[1;0m" % logging.getLevelName(logging.WARNING))
logging.addLevelName(
logging.DEBUG, "\033[1;34m%s\033[1;0m" % logging.getLevelName(logging.DEBUG))
logging.addLevelName(
logging.INFO, "\033[1;32m%s\033[1;0m" % logging.getLevelName(logging.INFO))