Example #1
0
def test_valid():
    A, B, C = symbols('A,B,C')
    assert valid(A >> (B >> A)) is True
    assert valid((A >> (B >> C)) >> ((A >> B) >> (A >> C))) is True
    assert valid((~B >> ~A) >> (A >> B)) is True
    assert valid(A | B | C) is False
    assert valid(A >> B) is False
Example #2
0
def test_valid():
    A, B, C = symbols('A,B,C')
    assert valid(A >> (B >> A)) is True
    assert valid((A >> (B >> C)) >> ((A >> B) >> (A >> C))) is True
    assert valid((~B >> ~A) >> (A >> B)) is True
    assert valid(A | B | C) is False
    assert valid(A >> B) is False
Example #3
0
def domination_relations(rules):
    #print("Calculating Domination Relations______________________________________________________________________________\n")
    dominations = set()
    for k1, r1 in rules.items(
    ):  #and compare each rule with each of the others
        for k2, r2 in rules.items():
            #The following simply applies the definition of rule domination to the extensions of the rules in each world
            #First check for "improper" domination
            if not r1.body and not r2.body:
                #(str(r1.body).isspace() or str(r2.body).isspace() ):
                continue
            #if str(r1.body).isspace():
            if not r1.body:  #To process rules without conditions
                continue
            elif not r2.body:  # If r2 does not have a body will generally be dominated by r1 when the two heads collide
                #str(r2.body).isspace():
                #print("r1head: %s" %(r1.head))
                #print("r2head: %s" % (r2.head))
                r1h_cnf = to_cnf(r1.head)
                r2h_cnf = to_cnf(r2.head)
                temp3 = And(r1h_cnf, r2h_cnf)
                notbothheads = Not(temp3)
                if valid(notbothheads) == True:
                    r2.dominatedBy.add(r1)
            else:
                r1b_cnf = to_cnf(
                    r1.body)  #convert formulats to CNF for SAT solving
                #	print(r2.body)
                r2b_cnf = to_cnf(r2.body)
                r1h_cnf = to_cnf(r1.head)
                r2h_cnf = to_cnf(r2.head)
                temp1 = Not(
                    r1.body
                )  #putting together formulas for testing the domination condition
                temp2 = Not(r2.body)
                r1b_r2b = Or(temp1, r2b_cnf)
                r2b_r1b = Or(temp2, r1b_cnf)
                temp3 = And(r1h_cnf, r2h_cnf)
                notbothheads = Not(temp3)
                #print("First: %s, %s \n" % (r1b_r2b, notbothheads) )
                if ((valid(r1b_r2b) == True) and valid(notbothheads) == True):
                    if (valid(r2b_r1b) == False
                            or valid(notbothheads) == False):
                        new = (r1.name, r2.name)
                        dominations.add(new)
                        if (r2.item != r1.item):
                            r2.dominatedBy.add(r1)
Example #4
0
 def eval(variable, expr):
     if valid(expr) == True:
         return true
     return Forall(variable, expr, evaluate=False)