Did you know ... | Search Documentation: |
Janus and Prolog truth |
In traditional Prolog, queries succeed or fail. Systems that implement tabling with Well Founded Semantics such as XSB and SWI-Prolog define a third truth value typically called undefined. Undefined results may have two reasons; (1) the program is logically inconsistent or (2) restraints have been applied in the derivation.
Because classical Prolog truth is dominant, we represent the success
of a query using the Python booleans True
and False
.
For undefined answers we define a class janus.Undefined()
that may represent different levels of detail on why the result is
undefined. The notion of generic undefined is represented by a
unique instance of this class. The three truth values are accessible as
properties of the janus
module.
True
False
The class janus.Undefined() represents an undefined result under the Well Founded Semantics.
The class has a single property class term
that
represents either the delay list or the residual program.
See
janus.TruthVal() for
details.
True
. This is quite
pointless in the current design and this may go.janus.undefined
, a unique
instance of the class janus.Undefined().
The instances of this enumeration are available as attributed of the janus
module.
For example, given Russel's paradox defined in Prolog as below.
:- module(russel, [shaves/2]). :- table shaves/2. shaves(barber,P) :- person(P), tnot(shaves(P,P)). person(barber). person(mayor).
From Python, we may ask who shaves the barber in four ways as
illustrated below. Note that the Prolog representations for
janus.DELAY_LISTS
and janus.RESIDUAL_PROGRAM
use the write_canonical/1
notation. They may later be changed to use a more human friendly
notation.
# Using NO_TRUTHVALS >>> janus.query_once("russel:shaves(barber, X)", truth_vals=janus.NO_TRUTHVALS) {'truth': True, 'X': 'barber'} # Using default PLAIN_TRUTHVALS (default) >>> janus.query_once("russel:shaves(barber, X)") {'truth': Undefined, 'X': 'barber'} # Using default DELAY_LISTS >>> janus.query_once("russel:shaves(barber, X)", truth_vals=janus.DELAY_LISTS) {'truth': :(russel,shaves(barber,barber)), 'X': 'barber'} # Using default RESIDUAL_PROGRAM >>> janus.query_once("russel:shaves(barber, X)", truth_vals=janus.RESIDUAL_PROGRAM) {'truth': [:-(:(russel,shaves(barber,barber)),tnot(:(russel,shaves(barber,barber))))], 'X': 'barber'}