diff --git a/logic/logicPlan.py b/logic/logicPlan.py index 3d10afd..069be55 100644 --- a/logic/logicPlan.py +++ b/logic/logicPlan.py @@ -49,9 +49,10 @@ def sentence1() -> Expr: (not A) if and only if ((not B) or C) (not A) or (not B) or C """ - "*** BEGIN YOUR CODE HERE ***" - util.raiseNotDefined() - "*** END YOUR CODE HERE ***" + A=Expr('A') + B=Expr('B') + C=Expr('C') + return conjoin([A | B, (~A % ( ~B | C)), disjoin([~A , ~B , C])]) def sentence2() -> Expr: @@ -62,9 +63,8 @@ def sentence2() -> Expr: (not (B and (not C))) implies A (not D) implies C """ - "*** BEGIN YOUR CODE HERE ***" - util.raiseNotDefined() - "*** END YOUR CODE HERE ***" + A,B,C,D=Expr('A'),Expr('B'),Expr('C'),Expr('D') + return conjoin([(C % (B | D)), (A >> (~B & ~D)), (~(B & ~C) >> A), (~D >> C)]) def sentence3() -> Expr: @@ -79,9 +79,12 @@ def sentence3() -> Expr: Pacman is born at time 0. """ - "*** BEGIN YOUR CODE HERE ***" - util.raiseNotDefined() - "*** END YOUR CODE HERE ***" + PacmanAlive_0=PropSymbolExpr('PacmanAlive_0') + PacmanAlive_1=PropSymbolExpr('PacmanAlive_1') + PacmanBorn_0=PropSymbolExpr('PacmanBorn_0') + PacmanKilled_0=PropSymbolExpr('PacmanKilled_0') + # the answer should be "((PacmanAlive_1 <=> ((PacmanAlive_0 & ~PacmanKilled_0) | (~PacmanAlive_0 & PacmanBorn_0))) & ~(PacmanAlive_0 & PacmanBorn_0) & PacmanBorn_0)" + return conjoin([(PacmanAlive_1 % ((PacmanAlive_0 & ~PacmanKilled_0) | (~PacmanAlive_0 & PacmanBorn_0))), (~(PacmanAlive_0 & PacmanBorn_0)), PacmanBorn_0]) def findModel(sentence: Expr) -> Dict[Expr, bool]: """Given a propositional logic sentence (i.e. a Expr instance), returns a satisfying @@ -95,25 +98,20 @@ def findModelUnderstandingCheck() -> Dict[Expr, bool]: You should not use findModel or Expr in this method. """ a = Expr('A') - "*** BEGIN YOUR CODE HERE ***" - print("a.__dict__ is:", a.__dict__) # might be helpful for getting ideas - util.raiseNotDefined() - "*** END YOUR CODE HERE ***" + a.__dict__['op']='a' + return {a:True} def entails(premise: Expr, conclusion: Expr) -> bool: """Returns True if the premise entails the conclusion and False otherwise. """ - "*** BEGIN YOUR CODE HERE ***" - util.raiseNotDefined() - "*** END YOUR CODE HERE ***" + expr=conjoin([premise,~conclusion]) + return not pycoSAT(to_cnf(expr)) def plTrueInverse(assignments: Dict[Expr, bool], inverse_statement: Expr) -> bool: """Returns True if the (not inverse_statement) is True given assignments and False otherwise. pl_true may be useful here; see logic.py for its description. """ - "*** BEGIN YOUR CODE HERE ***" - util.raiseNotDefined() - "*** END YOUR CODE HERE ***" + return pl_true(~inverse_statement,assignments) #______________________________________________________________________________ # QUESTION 2