This commit is contained in:
snsd0805 2024-04-23 00:48:19 +08:00
parent f2ea658a85
commit 740994568c
Signed by: snsd0805
GPG Key ID: 569349933C77A854

View File

@ -50,7 +50,15 @@ def sentence1() -> Expr:
(not A) or (not B) or C
"""
"*** 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 ***"
@ -63,7 +71,16 @@ def sentence2() -> Expr:
(not D) implies C
"""
"*** 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 ***"
@ -80,7 +97,16 @@ def sentence3() -> Expr:
Pacman is born at time 0.
"""
"*** 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 ***"
def findModel(sentence: Expr) -> Dict[Expr, bool]:
@ -96,15 +122,27 @@ def findModelUnderstandingCheck() -> Dict[Expr, bool]:
"""
a = Expr('A')
"*** 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 ***"
def entails(premise: Expr, conclusion: Expr) -> bool:
"""Returns True if the premise entails the conclusion and False otherwise.
"""
"*** BEGIN YOUR CODE HERE ***"
util.raiseNotDefined()
# 如果 前提成立,但是(結論不成立) -> 代表 entails 不成立
check = premise & ~conclusion
return False if findModel(check) else True
"*** END YOUR CODE HERE ***"
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.
"""
"*** BEGIN YOUR CODE HERE ***"
util.raiseNotDefined()
return pl_true(~inverse_statement, assignments)
"*** END YOUR CODE HERE ***"
#______________________________________________________________________________