feat: q1
This commit is contained in:
parent
f2ea658a85
commit
740994568c
53
logicPlan.py
53
logicPlan.py
@ -50,7 +50,15 @@ def sentence1() -> Expr:
|
|||||||
(not A) or (not B) or C
|
(not A) or (not B) or C
|
||||||
"""
|
"""
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
"*** BEGIN YOUR CODE HERE ***"
|
||||||
util.raiseNotDefined()
|
A = Expr('A')
|
||||||
|
B = Expr('B')
|
||||||
|
C = Expr('C')
|
||||||
|
cond1 = A | B
|
||||||
|
cond2 = ~A % (~B | C)
|
||||||
|
cond3 = logic.disjoin(~A, ~B, C)
|
||||||
|
|
||||||
|
return logic.conjoin(cond1, cond2, cond3)
|
||||||
|
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +71,16 @@ def sentence2() -> Expr:
|
|||||||
(not D) implies C
|
(not D) implies C
|
||||||
"""
|
"""
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
"*** BEGIN YOUR CODE HERE ***"
|
||||||
util.raiseNotDefined()
|
A = Expr('A')
|
||||||
|
B = Expr('B')
|
||||||
|
C = Expr('C')
|
||||||
|
D = Expr('D')
|
||||||
|
cond1 = C % (B | D)
|
||||||
|
cond2 = A >> (~B & ~D)
|
||||||
|
cond3 = ~(B & ~C) >> A
|
||||||
|
cond4 = ~D >> C
|
||||||
|
|
||||||
|
return logic.conjoin(cond1, cond2, cond3, cond4)
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +97,16 @@ def sentence3() -> Expr:
|
|||||||
Pacman is born at time 0.
|
Pacman is born at time 0.
|
||||||
"""
|
"""
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
"*** BEGIN YOUR CODE HERE ***"
|
||||||
util.raiseNotDefined()
|
PacmanAlive_0 = PropSymbolExpr('PacmanAlive', time=0)
|
||||||
|
PacmanAlive_1 = PropSymbolExpr('PacmanAlive', time=1)
|
||||||
|
PacmanBorn_0 = PropSymbolExpr('PacmanBorn', time=0)
|
||||||
|
PacmanKilled_0 = PropSymbolExpr('PacmanKilled', time=0)
|
||||||
|
|
||||||
|
cond1 = PacmanAlive_1 % ((PacmanAlive_0 & ~PacmanKilled_0) | (~PacmanAlive_0 & PacmanBorn_0))
|
||||||
|
cond2 = ~(PacmanAlive_0 & PacmanBorn_0)
|
||||||
|
cond3 = PacmanBorn_0
|
||||||
|
|
||||||
|
return logic.conjoin(cond1, cond2, cond3)
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
def findModel(sentence: Expr) -> Dict[Expr, bool]:
|
def findModel(sentence: Expr) -> Dict[Expr, bool]:
|
||||||
@ -96,15 +122,27 @@ def findModelUnderstandingCheck() -> Dict[Expr, bool]:
|
|||||||
"""
|
"""
|
||||||
a = Expr('A')
|
a = Expr('A')
|
||||||
"*** BEGIN YOUR CODE HERE ***"
|
"*** BEGIN YOUR CODE HERE ***"
|
||||||
print("a.__dict__ is:", a.__dict__) # might be helpful for getting ideas
|
|
||||||
util.raiseNotDefined()
|
class dummyClass():
|
||||||
|
def __init__(self, expr: Expr):
|
||||||
|
self.name = expr.__dict__['op'].lower()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
return {dummyClass(a): True}
|
||||||
|
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** 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 ***"
|
"*** BEGIN YOUR CODE HERE ***"
|
||||||
util.raiseNotDefined()
|
# 如果 前提成立,但是(結論不成立) -> 代表 entails 不成立
|
||||||
|
check = premise & ~conclusion
|
||||||
|
|
||||||
|
return False if findModel(check) else True
|
||||||
|
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
def plTrueInverse(assignments: Dict[Expr, bool], inverse_statement: Expr) -> bool:
|
def plTrueInverse(assignments: Dict[Expr, bool], inverse_statement: Expr) -> bool:
|
||||||
@ -112,7 +150,8 @@ def plTrueInverse(assignments: Dict[Expr, bool], inverse_statement: Expr) -> boo
|
|||||||
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 ***"
|
"*** BEGIN YOUR CODE HERE ***"
|
||||||
util.raiseNotDefined()
|
return pl_true(~inverse_statement, assignments)
|
||||||
|
|
||||||
"*** END YOUR CODE HERE ***"
|
"*** END YOUR CODE HERE ***"
|
||||||
|
|
||||||
#______________________________________________________________________________
|
#______________________________________________________________________________
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user