logic q1
This commit is contained in:
@ -49,9 +49,10 @@ def sentence1() -> Expr:
|
|||||||
(not A) if and only if ((not B) or C)
|
(not A) if and only if ((not B) or C)
|
||||||
(not A) or (not B) or C
|
(not A) or (not B) or C
|
||||||
"""
|
"""
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
A=Expr('A')
|
||||||
util.raiseNotDefined()
|
B=Expr('B')
|
||||||
"*** END YOUR CODE HERE ***"
|
C=Expr('C')
|
||||||
|
return conjoin([A | B, (~A % ( ~B | C)), disjoin([~A , ~B , C])])
|
||||||
|
|
||||||
|
|
||||||
def sentence2() -> Expr:
|
def sentence2() -> Expr:
|
||||||
@ -62,9 +63,8 @@ def sentence2() -> Expr:
|
|||||||
(not (B and (not C))) implies A
|
(not (B and (not C))) implies A
|
||||||
(not D) implies C
|
(not D) implies C
|
||||||
"""
|
"""
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
A,B,C,D=Expr('A'),Expr('B'),Expr('C'),Expr('D')
|
||||||
util.raiseNotDefined()
|
return conjoin([(C % (B | D)), (A >> (~B & ~D)), (~(B & ~C) >> A), (~D >> C)])
|
||||||
"*** END YOUR CODE HERE ***"
|
|
||||||
|
|
||||||
|
|
||||||
def sentence3() -> Expr:
|
def sentence3() -> Expr:
|
||||||
@ -79,9 +79,12 @@ def sentence3() -> Expr:
|
|||||||
|
|
||||||
Pacman is born at time 0.
|
Pacman is born at time 0.
|
||||||
"""
|
"""
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
PacmanAlive_0=PropSymbolExpr('PacmanAlive_0')
|
||||||
util.raiseNotDefined()
|
PacmanAlive_1=PropSymbolExpr('PacmanAlive_1')
|
||||||
"*** END YOUR CODE HERE ***"
|
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]:
|
def findModel(sentence: Expr) -> Dict[Expr, bool]:
|
||||||
"""Given a propositional logic sentence (i.e. a Expr instance), returns a satisfying
|
"""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.
|
You should not use findModel or Expr in this method.
|
||||||
"""
|
"""
|
||||||
a = Expr('A')
|
a = Expr('A')
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
a.__dict__['op']='a'
|
||||||
print("a.__dict__ is:", a.__dict__) # might be helpful for getting ideas
|
return {a:True}
|
||||||
util.raiseNotDefined()
|
|
||||||
"*** END YOUR CODE HERE ***"
|
|
||||||
|
|
||||||
def entails(premise: Expr, conclusion: Expr) -> bool:
|
def entails(premise: Expr, conclusion: Expr) -> bool:
|
||||||
"""Returns True if the premise entails the conclusion and False otherwise.
|
"""Returns True if the premise entails the conclusion and False otherwise.
|
||||||
"""
|
"""
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
expr=conjoin([premise,~conclusion])
|
||||||
util.raiseNotDefined()
|
return not pycoSAT(to_cnf(expr))
|
||||||
"*** END YOUR CODE HERE ***"
|
|
||||||
|
|
||||||
def plTrueInverse(assignments: Dict[Expr, bool], inverse_statement: Expr) -> bool:
|
def plTrueInverse(assignments: Dict[Expr, bool], inverse_statement: Expr) -> bool:
|
||||||
"""Returns True if the (not inverse_statement) is True given assignments and False otherwise.
|
"""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.
|
pl_true may be useful here; see logic.py for its description.
|
||||||
"""
|
"""
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
return pl_true(~inverse_statement,assignments)
|
||||||
util.raiseNotDefined()
|
|
||||||
"*** END YOUR CODE HERE ***"
|
|
||||||
|
|
||||||
#______________________________________________________________________________
|
#______________________________________________________________________________
|
||||||
# QUESTION 2
|
# QUESTION 2
|
||||||
|
Reference in New Issue
Block a user