def testCommute(self): start = logicParse(" (~((p & p) -> q))") start.action = "Beginning Premise" start.cost = 0 goal = logicParse("~q & p", start.propMap) steps = search(start, goal, rules) print "\nDemonstrate that", start, "is logically equivalent to", goal print "\nCost:\tRule:\t\t\t\tStatement:" for s in steps: print s.cost, "\t", s.action, "\t\t", s.state print "\nTherefore, ", start, " = ", goal, "."
def testNotEquivalentSearch(self): # this one will get stuck forever until we figure out how to know when to quit print "impossible" start = logicParse("p -> q") start.action = "Beginning Premise" start.cost = 0 goal = logicParse("q -> p", start.propMap) steps = search(start, goal, rules, True) print "\nCost:\tRule:\t\t\t\tStatement:" assert steps == False
def testSearch2(self): start = logicParse("~(b v c) & (~b & ~c)") start.action = "Beginning Premise" start.cost = 0 goal = logicParse("~(b v c)", start.propMap) steps = search(start, goal, rules) print "\nDemonstrate that", start, "is logically equivalent to", goal print "\nCost:\tRule:\t\t\t\tStatement:" for s in steps: print s.cost, "\t", round( float(s.cost) / (s.cost + distance(str(s.state), str(goal))), 2 ), "\t\t", s.action, "\t\t", s.state print "\nTherefore, ", start, " = ", goal, "."
def testSearchHW1noCache(self): print "\n\n******Hard Problem, no cache******" # (p -> q) & (q -> p) start # (~p v q) & (~q v p) implication # ((~p v q) & ~q)&((~p v q) & p) distribution # ((~p & ~q) v (q & ~q)) v ((p & ~p) v (q&p)) distribution # (~p & ~q) v (q&p) ??? start = logicParse("(p -> q) & (q -> p)") goal = logicParse("(p & q)v(~p & ~q)", start.propMap) steps = search(start, goal, rules) print "\nDemonstrate that", start, "is logically equivalent to", goal print "\nCost:\tEst%Complete\tRule:\t\t\t\tStatement:" for s in steps: print s.cost, "\t", distance(str(s.state), str(goal)), "\t\t", s.action, "\t\t", s.state.mml() print "\nTherefore, ", start, " = ", goal, "."
def testSearch4(self): # this one needs truth constants to work. start = logicParse("~(p v (~p & q))") start.action = "Beginning Premise" start.cost = 0 goal = logicParse("~p & ~q", start.propMap) goal.action = "Goal" steps = search(start, goal, rules) print "\nDemonstrate that", start, "is logically equivalent to", goal print "\nCost:\tRule:\t\t\t\tStatement:" for s in steps: print s.cost, "\t", round( float(s.cost) / (s.cost + distance(str(s.state), str(goal))), 2 ), "\t\t", s.action, "\t\t", s.state print "\nTherefore, ", start, " = ", goal, "."
def searchHW1noCacheNoCommute(self): start = logicParse('(p -> q) & (q -> p)') goal = logicParse('(~p & ~q) v (q &p)',start.propMap) rules = [Negation(),Identity(),Domination(),Idempotence(),Associativity(),Exportation(),Distributivity(),Absorption(),DoubleNegation(),DeMorgans(),ImplicationLaw()] steps = search(start,goal,rules)
def searchHW1noCache(self): start = logicParse('(p -> q) & (q -> p)') goal = logicParse('(p & q)v(~p & ~q)',start.propMap) steps = search(start,goal,rules)