A demo example of decision trees that contain logical conditions in their nodes

Example of structure (= program)

-----------------------------------------------
-- log-test-11

[: type observed-structure]
[: has-structure
   [block
       [:= a b]
       [loop v 1 100 [loop a 1 v [routine-2]]]
       [:= c v]
       :pred2 t :pred3 {foo fie}
              ]]
---------------------------------

Annotation of this tree (assigning labels to subexpressions)
Generated using the command 'pula':

ses.275) pula
[block
   [:= a b
      :label L-02 ]
   [loop v 1 100
      [loop a 1 v
         [routine-2
            :label L-05 ]
         :label L-04 ]
      :label L-03 ]
   [:= c v
      :label L-06 ]
   :label L-01 :pred2 t :pred3 {foo fie} ]



Predicates for use in the decision tree apply to labels in the observed tree 
but the meaning is for the corresponding substructures. The meanings of the 
predicates are:

[is-loop .x]           .x is a loop expression
[has-subexpr .x .y]    .y is an immediate subexpression of .x
[has-loop .x .y]       .y is a loop inside the expression .x
                         (the latter may or may not be a loop expression)

Examples of decision trees:

----------------------------------------------
-- log-tree-1

[: type decision-tree]
[: has-tree [? [is-loop .t]
               green
               [?? .x [has-subexpr .t .x]
                   [? [is-loop .x] yellow red]
                   violet ] 
                ]]

A node expression marked by ? contains a logic expression that is
evaluated for true or false, followed by one branch to be followed for
each case. This is a deterministic (non-looping) construct.

A node expression marked by ?? contains a variable, a logic expression,
and two branches. The executive looks for all bindings of the variable
whereby the expression is true, and if one or more are found then the first
of the branches is pursued for each of the cases. If none is found then the
second branch is pursued.

ses.293) lode
Several solutions found:
  red for .x = L-06
  yellow for .x = L-03
  red for .x = L-02

Notice that here .x will vary over L-02, L-03 and L-06. All give an
answer.

----------------------------------------------
-- log-tree-2

[: type decision-tree]
[: has-tree [? [is-loop .t]
               green
               [?? .x [has-subexpr .t .x]
                   [? [is-loop .x] yellow nil]
                   nil ] 
                ]]

The value nil indicates failure in the present branch of the search.

ses.298) lode
One solution found: 
  yellow for .x = L-03

The difference here is that we have nil instead of red, and nil is
interpreted as not providing a solution.

----------------------------------------------
-- log-tree-3

[: type decision-tree]
[: has-tree [? [is-loop .t]
               green
               [?? .x [has-loop .t .x]
                   [?? .y [has-loop .x .y] .y nil]
                   nil ] 
                ]]

ses.273) lode
One solution found: 
  L-04 for .x = L-03, .y = L-04

Here we have nested ?? nodes. Notice that the variable may be used for
providing the outcome.

-----------------------------------------------


Operating Instructions
======================

When the session has started, do
   loadk dtc-lib-kb
   loadfil dt-logcond
(If you add dt-logcond to the mustload attribute of dtc-lib-kb,
as follows:
   [: mustload <dtc-onto dt-nonprob dt-logcond dt-prob caunet-defs>]
then it is loaded automatically by the loadk command so you don't have
to type it separately).

When dt-logcond is loaded it sets the current decision tree to
log-tree-1 and the current program tree to log-test-11. These settings
can be changed using e.g.
   curtree log-tree-2
and
   curtest log-test-12

In order to apply the current decision tree to the current program,
one must first execute the command
   pula
(for 'put labels'). This puts the labels and shows the result. Then
to apply the current decision tree, execute
   lode
(A nonobvious acronym but it started as an acronym for logical decision
tree).

These commands can be repeated of course. To change either of the trees,
edit the entityfile containing your definitions and reload it.

No special measures need to be taken if you start using other files besides
dt-logcond for your examples.

After loading a definitions file one must redo the pula command before
doing the lode command, since the reloading destroys the labelling.
The same applies if you use the curtest command for changing to another
program tree, since the labelling (map from label to corresponding
substructure) is global and not attached to a particular program tree.
(This should probably be fixed). On the other hand it is not necessary
to redo 'pula' after the curtree command that changes the decision tree, 
since the labelling is not affected by it.

Error messages e.g. if you forget to do pula before lode are considered
an unnecessary luxury at this point, sorry.


