33Reference: [Russell & Norvig, Artificial Intelligence: A Modern Approach, Ch. 7](https://aima.cs.berkeley.edu/)
44Wikipedia: [Entailment](https://en.wikipedia.org/wiki/Entailment)
55
6- This algorithm checks if a knowledge base (KB) entails a query sentence (α )
7- using truth tables. Returns True if KB entails α , False otherwise.
6+ This algorithm checks if a knowledge base (KB) entails a query sentence (a )
7+ using truth tables. Returns True if KB entails a , False otherwise.
88"""
99
1010import itertools
11- from typing import List , Dict
1211
13- def tt_entails (kb : List [str ], query : str , symbols : List [str ]) -> bool :
12+ def tt_entails (kb : list [str ], query : str , symbols : list [str ]) -> bool :
1413 """
1514 Check if the knowledge base entails the query using truth tables.
1615
@@ -27,12 +26,11 @@ def tt_entails(kb: List[str], query: str, symbols: List[str]) -> bool:
2726
2827 """
2928 for values in itertools .product ([True , False ], repeat = len (symbols )):
30- model : Dict [str , bool ] = dict (zip (symbols , values ))
29+ model : dict [str , bool ] = dict (zip (symbols , values ))
3130 # Check if KB is true under this model
32- if all (eval (sentence , {}, model ) for sentence in kb ):
33- # If query is false in this model, KB does not entail query
34- if not eval (query , {}, model ):
35- return False
31+ # # If query is false in this model, KB does not entail query
32+ if all (eval (sentence , {}, model ) for sentence in kb ) and not eval (query , {}, model ):
33+ return False
3634 return True
3735
3836# Example usage
0 commit comments