Commit 1f4b3bfc authored by Vít Novotný's avatar Vít Novotný
Browse files

added example 8.2_20

parent 8a58315b
% nacteni:
/* ['8.2_20.pl']. */
% pomocne funkce - jen "zaslepky"
% symboly P1, P2, P3
proposition_symbols([p1,p2,p3],_).
% priklad: KB = P2 and P3
% alpha = P2
% beta = P1
pl_true(kb, [p3-true, p2-true, p1-true]):-!.
pl_true(kb, [p3-true, p2-true, p1-false]):-!.
pl_true(alpha,[p3-true, p2-true, p1-true]):-!.
pl_true(alpha,[p3-false,p2-true, p1-true]):-!.
pl_true(alpha,[p3-true, p2-true, p1-false]):-!.
pl_true(alpha,[p3-false,p2-true, p1-false]):-!.
pl_true(beta, [p3-true, p2-true, p1-true]):-!.
pl_true(beta, [p3-true, p2-false,p1-true]):-!.
pl_true(beta, [p3-false,p2-true, p1-true]):-!.
pl_true(beta, [p3-false,p2-false,p1-true]):-!.
% tt_entails(+KB,+Alpha)
tt_entails(KB,Alpha):-proposition_symbols(Symbols,[KB,Alpha]),
tt_check_all(KB,Alpha,Symbols,[]).
% tt_check_all(+KB,+Alpha,+Symbols,+Model)
tt_check_all(KB,Alpha,[],Model):-pl_true(KB,Model),!,pl_true(Alpha,Model).
tt_check_all(_KB,_Alpha,[],_Model):-!.
tt_check_all(KB,Alpha,[P|Symbols],Model):-
tt_check_all(KB,Alpha,Symbols,[P-true|Model]),
tt_check_all(KB,Alpha,Symbols,[P-false|Model]).
show_bool(Text,P):-write(Text),call(P),!,write('yes'),nl.
show_bool(_,_):-write('no'),nl.
%:- trace,tt_entails(kb,alpha).
:- show_bool('KB entails Alpha: ', tt_entails(kb,alpha)), % true
show_bool('KB entails Beta: ', tt_entails(kb,beta)). % false
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from linked_lists import LinkedList, Cons, Nil
def preposition_symbols(_):
# zavisi na resenem problemu
return LinkedList(["p1", "p2", "p3"])
def pl_true(formula, model):
# zavisi na resenem problemu
if formula == "kb":
return model == LinkedList([("p3", True), ("p2", True), ("p1", True)]) or \
model == LinkedList([("p3", True), ("p2", True), ("p1", False)])
if formula == "alpha":
return model == LinkedList([("p3", True), ("p2", True), ("p1", True)]) or \
model == LinkedList([("p3", False), ("p2", True), ("p1", True)]) or \
model == LinkedList([("p3", True), ("p2", True), ("p1", False)]) or \
model == LinkedList([("p3", False), ("p2", True), ("p1", False)])
if formula == "beta":
return model == LinkedList([("p3", True), ("p2", True), ("p1", True)]) or \
model == LinkedList([("p3", True), ("p2", False), ("p1", True)]) or \
model == LinkedList([("p3", False), ("p2", True), ("p1", True)]) or \
model == LinkedList([("p3", False), ("p2", False), ("p1", True)])
def tt_entails(kb, alpha):
symbols = preposition_symbols(LinkedList([kb, alpha]))
return tt_check_all(kb, alpha, symbols, Nil)
def tt_check_all(kb, alpha, symbols, model):
if symbols == Nil:
if pl_true(kb, model):
return pl_true(alpha, model)
return True
p = symbols.head
return tt_check_all(kb, alpha, symbols.tail, Cons((p, True), model)) and \
tt_check_all(kb, alpha, symbols.tail, Cons((p, False), model))
# demonstracni vypis
if __name__ == "__main__":
print("KB entails Alpha: %s" % tt_entails("kb", "alpha"))
print("KB entails Beta: %s" % tt_entails("kb", "beta"))
KB entails Alpha: True
KB entails Beta: False
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment