@@ -144,9 +144,8 @@ def is_var_symbol(s):
144
144
145
145
146
146
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 ()
150
149
151
150
152
151
def variables (s ):
@@ -184,7 +183,6 @@ def parse_definite_clause(s):
184
183
return conjuncts (antecedent ), consequent
185
184
186
185
# Useful constant Exprs used in examples and code:
187
- TRUE , FALSE = Symbol ('TRUE' ), Symbol ('FALSE' )
188
186
A , B , C , D , E , F , G , P , Q , x , y , z = map (Expr , 'ABCDEFGPQxyz' )
189
187
190
188
@@ -233,20 +231,18 @@ def tt_true(s):
233
231
True
234
232
"""
235
233
s = expr (s )
236
- return tt_entails (TRUE , s )
234
+ return tt_entails (True , s )
237
235
238
236
239
237
def pl_true (exp , model = {}):
240
238
"""Return True if the propositional logic expression is true in the model,
241
239
and False if it is false. If the model does not specify the value for
242
240
every proposition, this may return None to indicate 'not obvious';
243
241
this may happen even when the expression is tautological."""
242
+ if exp == True or exp == False :
243
+ return exp
244
244
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 ):
250
246
return model .get (exp )
251
247
elif op == '~' :
252
248
p = pl_true (args [0 ], model )
@@ -364,7 +360,7 @@ def distribute_and_over_or(s):
364
360
if s .op != '|' :
365
361
return distribute_and_over_or (s )
366
362
if len (s .args ) == 0 :
367
- return FALSE
363
+ return False
368
364
if len (s .args ) == 1 :
369
365
return distribute_and_over_or (s .args [0 ])
370
366
conj = first (arg for arg in s .args if arg .op == '&' )
@@ -397,7 +393,7 @@ def associate(op, args):
397
393
else :
398
394
return Expr (op , * args )
399
395
400
- _op_identity = {'&' : TRUE , '|' : FALSE , '+' : 0 , '*' : 1 }
396
+ _op_identity = {'&' : True , '|' : False , '+' : 0 , '*' : 1 }
401
397
402
398
403
399
def dissociate (op , args ):
@@ -447,7 +443,7 @@ def pl_resolution(KB, alpha):
447
443
for i in range (n ) for j in range (i + 1 , n )]
448
444
for (ci , cj ) in pairs :
449
445
resolvents = pl_resolve (ci , cj )
450
- if FALSE in resolvents :
446
+ if False in resolvents :
451
447
return True
452
448
new = new .union (set (resolvents ))
453
449
if new .issubset (set (clauses )):
0 commit comments