def testSetMinus(p, q): premisse = () outputatoms = () input = dlvhex.getInputAtoms() for x in input: tup = x.tuple() if tup[0].value() == p.value(): # keep true monotonic input atoms if dlvhex.isTrue(x): premisse = (x, ) + premisse if x.isTrue() and not dlvhex.isTrue(dlvhex.storeAtom((q, tup[1]))): outputatoms = (dlvhex.storeOutputAtom((tup[1], )), ) + outputatoms dlvhex.output((tup[1], )) if tup[0].value() == q.value(): # keep false antimonotonic input atoms if not dlvhex.isTrue(x): premisse = (x.negate(), ) + premisse # learn one nogood for each output atom for x in outputatoms: dlvhex.learn((x.negate(), ) + premisse)
def testSetMinus(p, q): premisse = () outputatoms = () input = dlvhex.getInputAtoms() for x in input: tup = x.tuple() if tup[0].value() == p.value(): # keep true monotonic input atoms if dlvhex.isTrue(x): premisse = (x, ) + premisse if not dlvhex.isTrue(dlvhex.storeAtom((q, tup[1]))): outputatoms = (dlvhex.storeOutputAtom((tup[1], )), ) + outputatoms dlvhex.output((tup[1], )) if tup[0].value() == q.value(): # keep false antimonotonic input atoms if not dlvhex.isTrue(x): premisse = (x.negate(), ) + premisse # learn one nogood for each output atom for x in outputatoms: dlvhex.learn((x.negate(), ) + premisse)
def testSetMinusPartial(p, q): # compute the set difference of the extension of p minus the one of q input = dlvhex.getInputAtoms() for x in input: tup = x.tuple() # for each possible input atom p(x) (according to the grouding, it is not necessarily true in the current input) if tup[0].value() == p.value(): qAtom = dlvhex.storeAtom((q, tup[1])) # if p(x) is true and the corresponding atom q(x) is not true (i.e., false or undefined) if dlvhex.isTrue(x) and not dlvhex.isTrue(qAtom): # if q(x) is false, then x is definitely in the output if not dlvhex.isInputAtom(qAtom) or dlvhex.isFalse(qAtom): # print "Definitely true: " + tup[1].value() dlvhex.output((tup[1], )) # if q(x) is undefined, then x might be in the output else: # print "Could be true: " + tup[1].value() dlvhex.outputUnknown((tup[1], )) v = 0 # if p(x) is undefined and q(x) is not true (i.e., false or undefined), then x might be in the output if not dlvhex.isTrue(x) and not dlvhex.isFalse( x) and not dlvhex.isTrue(qAtom): # print "Could be true: " + tup[1].value() dlvhex.outputUnknown((tup[1], )) v = 0
def testSetMinusPartial(p, q): # compute the set difference of the extension of p minus the one of q input = dlvhex.getInputAtoms() for x in input: tup = x.tuple() # for each possible input atom p(x) (according to the grouding, it is not necessarily true in the current input) if tup[0].value() == p.value(): qAtom = dlvhex.storeAtom((q, tup[1])) # if p(x) is true and the corresponding atom q(x) is not true (i.e., false or undefined) if dlvhex.isTrue(x) and not dlvhex.isTrue(qAtom): # if q(x) is false, then x is definitely in the output if not dlvhex.isInputAtom(qAtom) or dlvhex.isFalse(qAtom): # print "Definitely true: " + tup[1].value() dlvhex.output((tup[1], )) # if q(x) is undefined, then x might be in the output else: # print "Could be true: " + tup[1].value() dlvhex.outputUnknown((tup[1], )) v=0 # if p(x) is undefined and q(x) is not true (i.e., false or undefined), then x might be in the output if not dlvhex.isTrue(x) and not dlvhex.isFalse(x) and not dlvhex.isTrue(qAtom): # print "Could be true: " + tup[1].value() dlvhex.outputUnknown((tup[1], )) v=0
def aOrNotB(a,b): if dlvhex.learnSupportSets(): dlvhex.learn(( dlvhex.storeAtom((a, )), dlvhex.storeOutputAtom(()).negate() # then () is in the output )); dlvhex.learn(( dlvhex.storeAtom((b, )).negate(), dlvhex.storeOutputAtom(()).negate() # then () is in the output )); else: aIsTrue = dlvhex.isTrue(dlvhex.storeAtom((a, ))) bIsFalse = dlvhex.isFalse(dlvhex.storeAtom((b, ))) if aIsTrue or bIsFalse: dlvhex.output(())