ai_utils/knowledge/model_checking.py
def check_all(knowledge, query, symbols, model):
        """Checks if knowledge base entails query, given a particular model."""

        # If model has an assignment for each symbol
        if not symbols:
            # If knowledge base is true in model, then query must also be true
            if knowledge.evaluate(model):
                return query.evaluate(model)
            return True
        else:
            # Choose one of the remaining unused symbols
            remaining = symbols.copy()
            p = remaining.pop()

            # Create a model where the symbol is true
            model_true = model.copy()
            model_true[p] = True

            # Create a model where the symbol is false
            model_false = model.copy()
            model_false[p] = False

            # Ensure entailment holds in both models
            return (check_all(knowledge, query, remaining, model_true) and
                    check_all(knowledge, query, remaining, model_false))
Checks if knowledge base entails query, given a particular model.
Checks if knowledge base entails query, given a particular model.
Checks if knowledge base entails query given a particular model .
def check_all(knowledge, query, symbols, model):
        if not symbols:
            if knowledge.evaluate(model):
                return query.evaluate(model)
            return True
        else:
            remaining = symbols.copy()
            p = remaining.pop()
            model_true = model.copy()
            model_true[p] = True
            model_false = model.copy()
            model_false[p] = False
            return (check_all(knowledge, query, remaining, model_true) and
                    check_all(knowledge, query, remaining, model_false))
def check_all ( knowledge , query , symbols , model ) : if not symbols : if knowledge . evaluate ( model ) : return query . evaluate ( model ) return True else : remaining = symbols . copy ( ) p = remaining . pop ( ) model_true = model . copy ( ) model_true [ p ] = True model_false = model . copy ( ) model_false [ p ] = False return ( check_all ( knowledge , query , remaining , model_true ) and check_all ( knowledge , query , remaining , model_false ) )
Checks if knowledge base entails query, given a particular model.
Checks if knowledge base entails query given a particular model .
"""Checks if knowledge base entails query, given a particular model.""" # If model has an assignment for each symbol # If knowledge base is true in model, then query must also be true # Choose one of the remaining unused symbols # Create a model where the symbol is true # Create a model where the symbol is false # Ensure entailment holds in both models
knowledge
query
symbols
model