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
Post a Comment