python - Is there a way to evaluate a system of disequations? -


i have bunch of strings, keys in dictionary, contain systems of inequalities:

e.g. "t1+t2 > 2 ^ t1 < 1 ^ t2 >= 1"

these strings created based on user input, systems impossible:

e.g "t1+t3 > 2 ^ t1 <= 1 ^ t3 <= 1".

there no possible values of t1 , t3 solve system.in case system impossible need remove element dictionary.

i know sure there no multiple inequalities regarding same "subject". instance, there can't be:

"... ^ t2 > 0 ^ t2 <= 2 ^ ..."

but

"... ^ 0 < t2 <= 2 ^ ..." possible

if have write code this, messy , can't picture (or @ least nice one) on how result true or false, whether it's impossible or possible system ... , i'm pretty sure there better ways of handling problem (there can more 3 variables, think if understand how 3, can n):

def logical(string):     h = string.split(" ^ ")     count = [0,0,0]     in [1,2,3]:                j in h:             if "t"+str(i) in h:                 count[i-1] += 1     ...     #consider elements of h contain "t"+1 if count of      #that variable bigger 1     #and contain sum of 2 or more     #variables check number of "words" (can 3 or 5).      #check if elements  in position 1 and/or 3 "<=" or "<" or     #">=" or ">" ... , compare element of h      #contains instead ... veeeery long , mechanical     ... 

any help?


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -