Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* function TT-ENTAILS?(KB, α) returns true or false
* inputs: KB, the knowledge base, a sentence in propositional logic
* α, the query, a sentence in propositional logic
*
* symbols <- a list of proposition symbols in KB and &alpha
* return TT-CHECK-ALL(KB, α symbols, {})
*
* --------------------------------------------------------------------------------
*
* function TT-CHECK-ALL(KB, α symbols, model) returns true or false
* if EMPTY?(symbols) then
* if PL-TRUE?(KB, model) then return PL-TRUE?(α, model)
* else return true // when KB is false, always return true
* else do
* P <- FIRST(symbols)
* rest <- REST(symbols)
* return (TT-CHECK-ALL(KB, α, rest, model ∪ { P = true })
* and
* TT-CHECK-ALL(KB, α, rest, model ∪ { P = false }))
*
*
* Figure 7.10 A truth-table enumeration algorithm for deciding propositional
* entailment. (TT stands for truth table.) PL-TRUE? returns true if a sentence
* holds within a model. The variable model represents a partional model - an
* assignment to some of the symbols. The keyword "and" is used here as a
* logical operation on its two arguments, returning true or false.
*
* @author Ciaran O'Reilly
* @author Ravi Mohan
* @author Mike Stampone
*/
public class TTEntails {
/**
* function TT-ENTAILS?(KB, α) returns true or false.
*
* @param kb
* KB, the knowledge base, a sentence in propositional logic
* @param alpha
* α, the query, a sentence in propositional logic
*
* @return true if KB entails α, false otherwise.
*/
public boolean ttEntails(KnowledgeBase kb, Sentence alpha) {
// symbols <- a list of proposition symbols in KB and &alpha
List symbols = new ArrayList(
SymbolCollector.getSymbolsFrom(kb.asSentence(), alpha));
// return TT-CHECK-ALL(KB, α symbols, {})
return ttCheckAll(kb, alpha, symbols, new Model());
}
//
/**
* function TT-CHECK-ALL(KB, α symbols, model) returns true or false
*
* @param kb
* KB, the knowledge base, a sentence in propositional logic
* @param alpha
* α, the query, a sentence in propositional logic
* @param symbols
* a list of currently unassigned propositional symbols in the
* model.
* @param model
* a partially or fully assigned model for the given KB and
* query.
* @return true if KB entails α, false otherwise.
*/
public boolean ttCheckAll(KnowledgeBase kb, Sentence alpha,
List symbols, Model model) {
// if EMPTY?(symbols) then
if (symbols.isEmpty()) {
// if PL-TRUE?(KB, model) then return PL-TRUE?(α, model)
if (model.isTrue(kb.asSentence())) {
return model.isTrue(alpha);
} else {
// else return true // when KB is false, always return true
return true;
}
}
// else do
// P <- FIRST(symbols)
PropositionSymbol p = Util.first(symbols);
// rest <- REST(symbols)
List rest = Util.rest(symbols);
// return (TT-CHECK-ALL(KB, α, rest, model ∪ { P = true })
// and
// TT-CHECK-ALL(KB, α, rest, model U { P = false }))
return ttCheckAll(kb, alpha, rest, model.union(p, true))
&& ttCheckAll(kb, alpha, rest, model.union(p, false));
}
}