2 ^ t1 < 1 ^ t2 >= 1" These string..." /> 2 ^ t1 < 1 ^ t2 >= 1" These string..." /> 2 ^ t1 < 1 ^ t2 >= 1" These string..."/>

Is there a way to evaluate a system of disequations?

80 views Asked by At

I have a bunch of strings, that are keys in a dictionary, that contain systems of inequalities:

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

These strings are created based on user input, but sometimes the systems are impossible:

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

there are no possible values of t1 and t3 that solve the system.In case the system is impossible I need to remove the element from the dictionary.

I know for sure that there are no multiple inequalities regarding the same "subject". For instance, there can't be:

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

But

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

If I have to write some code I would do something like this, but it is very messy and I can't get a good picture (or at least a nice one) on how to get the result True or False, whether it's an impossible or possible system ... and I'm pretty sure there are better ways of handling the problem (there can be more than 3 variables, but I think that if I understand how to do it with 3, I can do it with n):

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

any help?

0

There are 0 answers