| Applying science to business management |
  
Logical Look-Ahead
The operators, Logical And
(&&) and Logical Or
(||) are sometimes used to create Boolean rule sets as part of an
expert system application. In this type of application, you
combine rules with nodes that prompt the user for input
information. For example, the following set of node definitions
create part of an expert system that determines if a patient has
a cold.
Cold:= Runny Nose&&Slight
Fever
Runny Nose:=askyesno("Does the
patient have a runny nose?")
Slight
Fever:=Temperature>=99&&Temperature<=102
Temperature:=asknumber("What is
the patient's temperature?")
The first definition contains a rule that is true if
the patient both has a runny nose AND has a slight fever. The
next definition is a rule that defines slight fever. The
remaining two definitions present questions to the user to ask
for a numeric input (asknumber)
or ask for the response to a Yes/No question (askyesno).
Now suppose these definitions are part of a larger medical
diagnostic system. Also, assume the user had previously answered
the Temperature question and indicated that the patient's
temperature is 104. Then, when evaluating the node Cold,
you would like the application simply to recognize that Cold
can never be true and don't even bother asking if the
patient has a runny nose. This effect can be accomplished using Logical
Look-Ahead.
Logical Look-Ahead is a feature of DScript that controls how
the Logical And and Logical Or operators behave.
Specifically, this feature prevents applications from prompting
the user for information that, ultimately, will not be needed.
In evaluating a Boolean expression, DScript scans the entire
logic tree to determine if there is any way to calculate a result
without asking the user for input. If it is not possible to
calculate a solution, DScript will ask one question and then
repeat the scan.
Logical Look-Ahead allows you to build rule-based applications
without worrying about the order in which questions are posed to
the user. In addition, you don't have to worry about redundant
logic. DScript will only ask questions that are absolutely
necessary.
You can choose whether to use Logical Look-Ahead in your
rule-based applications by clicking System Options in the Tools
menu and choosing the appropriate option in the Calculation
page.
Gate Primitive
The gate primitive is
designed to force a branch in a Logical Look-Ahead to fail while
not interfering with calculations at other times. If one of the
primitives And/Or is active and the system is attempting
to evaluate a Boolean expression without prompting the user, gate causes the current branch
being explored to fail. In all other cases, gate is benign.
All input primitives have the functionality of the gate primitive built in. The
purpose of the gate primitive
is to tell DScript which calculations are expensive.
Asking the user to respond to a question is expensive in terms of
user effort and time. If you are getting information from a
source other than the user and the source is slow, you might want
to gate access to the source.
For example, if you build an application that uses stock
prices pulled from the Internet as an input, you may want your
application to retrieve the price only if absolutely necessary.
This is accomplished by changing a node from
Price:=StockPrice("IBM")
to
Price:=gate(StockPrice("IBM"))
With the latter expression, DScript will avoid pulling data
from the Internet if there is any other way to draw a complete
conclusion.
|