Bonner's Examples

We demonstrate hypothetical and counter factual reasoning as provided by the module "hypo".  We essentially replicate the examples from Bonner [3][4]. A student has to take mandatory German and optionally French or Italian courses before he can grade. We can express this as a set of Prolog rules as follows:

/* must take german and can choose between french and italian */
grade(S) :- take(S, german), take(S, french).
grade(S) :- take(S, german), take(S, italian).

We further assume a database with some facts. These facts express state of affairs for stu-dents. The facts need to be either dynamic or thread local, since static facts cannot be modi-fied by the module "hypo". We need to mark them multi-file, so that we can modify them from the top-level as well:

/* hans has already taken french */
:- multifile take/2.
:- thread_local take/2.
take(hans, french).

Hypothetical reasoning now consists of assuming further facts or rules. The module "hypo" provides the predicates assumea/1 and assumez/1 for this purpose. They are analogous to asserta/1 and assertz/1, except that they only add the given fact or rule temporarily for the du-ration of the continuation:

/* hans would not grade if he takes also italian */
?- assumez(take(hans, italian)), grade(hans).

/* hans would grade if he takes also german */
?- assumez(take(hans, german)), grade(hans).
Yes ;

On the other hand, counter factual reasoning consists of retiring existing facts or rules. The module "hypo" provides the predicates retire/1 and retireall/1 for this purpose. They are analo-gous to retract/1 and retractall/1, except that they only remove a found fact or rule temporarily for the duration of the continuation: The facts we are working with are now:

/* anna has already taken german, french and italian*/
:- multifile take/2.
:- thread_local take/2.
take(anna, german).
take(anna, french).
take(anna, italian).

Whereas in hypothetical reasoning a previously failing query turned into a succeeding one, in counterfactual reasoning the converse can be observed. A previously succeeding query can turn into a succeeding one. This monotonicity holds if the program does not contain negation as failure or other non-monotonic constructs:

/* anna would grade if she would not have taken italian */
?- retire(take(anna, italian)), grade(anna).
Yes ;

/* anna would not grade if she would not have taken german */
?- retire(take2(anna, german)), grade(anna).

It is possible to use the toolbox efficiently for more elaborate applications such as adversarial planning [5]. Also note that in practical applications often the continuation variant [6] of hypo-thetical and counter factual reasoning is used. These variants are also provide by the module "hypo". We refer the interested reader to the module documentation.