Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75617fa

Browse files
committed
replace TRUE, FALSE with True, False
1 parent 685a8f8 commit 75617fa

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

logic.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ def is_var_symbol(s):
144144

145145

146146
def is_prop_symbol(s):
147-
"""A proposition logic symbol is an initial-uppercase string other than
148-
TRUE or FALSE."""
149-
return is_symbol(s) and s[0].isupper() and s != 'TRUE' and s != 'FALSE'
147+
"""A proposition logic symbol is an initial-uppercase string."""
148+
return is_symbol(s) and s[0].isupper()
150149

151150

152151
def variables(s):
@@ -184,7 +183,6 @@ def parse_definite_clause(s):
184183
return conjuncts(antecedent), consequent
185184

186185
# Useful constant Exprs used in examples and code:
187-
TRUE, FALSE = Symbol('TRUE'), Symbol('FALSE')
188186
A, B, C, D, E, F, G, P, Q, x, y, z = map(Expr, 'ABCDEFGPQxyz')
189187

190188

@@ -233,20 +231,18 @@ def tt_true(s):
233231
True
234232
"""
235233
s = expr(s)
236-
return tt_entails(TRUE, s)
234+
return tt_entails(True, s)
237235

238236

239237
def pl_true(exp, model={}):
240238
"""Return True if the propositional logic expression is true in the model,
241239
and False if it is false. If the model does not specify the value for
242240
every proposition, this may return None to indicate 'not obvious';
243241
this may happen even when the expression is tautological."""
242+
if exp == True or exp == False:
243+
return exp
244244
op, args = exp.op, exp.args
245-
if exp == TRUE:
246-
return True
247-
elif exp == FALSE:
248-
return False
249-
elif is_prop_symbol(op):
245+
if is_prop_symbol(op):
250246
return model.get(exp)
251247
elif op == '~':
252248
p = pl_true(args[0], model)
@@ -364,7 +360,7 @@ def distribute_and_over_or(s):
364360
if s.op != '|':
365361
return distribute_and_over_or(s)
366362
if len(s.args) == 0:
367-
return FALSE
363+
return False
368364
if len(s.args) == 1:
369365
return distribute_and_over_or(s.args[0])
370366
conj = first(arg for arg in s.args if arg.op == '&')
@@ -397,7 +393,7 @@ def associate(op, args):
397393
else:
398394
return Expr(op, *args)
399395

400-
_op_identity = {'&': TRUE, '|': FALSE, '+': 0, '*': 1}
396+
_op_identity = {'&': True, '|': False, '+': 0, '*': 1}
401397

402398

403399
def dissociate(op, args):
@@ -447,7 +443,7 @@ def pl_resolution(KB, alpha):
447443
for i in range(n) for j in range(i+1, n)]
448444
for (ci, cj) in pairs:
449445
resolvents = pl_resolve(ci, cj)
450-
if FALSE in resolvents:
446+
if False in resolvents:
451447
return True
452448
new = new.union(set(resolvents))
453449
if new.issubset(set(clauses)):

0 commit comments

Comments
 (0)