-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·76 lines (53 loc) · 1.91 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3
# attempt to put out information on logical formulas
# Copyright (C) 2015 Matthias Krüger
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
import sys
from sympy import *
import sympy.abc
from sympy.logic.inference import satisfiable
__author__ = 'Matthias "matthiaskrgr" Krüger'
OPERATORS=['&', '|', '~']
_input=[]
# split args
for arg in sys.argv:
for i in arg.split():
_input.append(i)
_input.pop(0) # remove the first element which is the script name
print("Input :" + str(_input))
tokenized_input = []
for i in _input:
# and
if ((i == "AND") or (i == "&&" ) or (i == "and") or (i == "∧")):
tokenized_input.append("&")
continue
# or
if ((i == "OR") or (i == "||" ) or (i == "or") or (i == "∨")):
tokenized_input.append("|")
continue
# not
if ((i == "NOT") or (i == "not") or (i == "!" ) or (i == "¬")):
tokenized_input.append("~")
continue
# XOR
if ((i == "XOR") or (i == "xor") or (i == "^")):
tokenized_input.append("^")
continue
tokenized_input.append(i)
print("Tokenized: "+ str(tokenized_input))
string =' '.join(tokenized_input)
print("string: " + string)
sym = sympify(str(string), convert_xor=False)
sat = satisfiable(sym, all_models=True)
for x in sat: # print all possibilities
print(x)