3.3  Mathematical Expressions in the  rule body

F-Logic engines usually support arithmetical operations. Assume that in our meteorological example  we want to add the method which indicates the average daily temperature for Burlington  in Centigrade .  Here is an equation for recalculating the temperature:

centigrade = (fahrenheit - 32) * 5/9

We will add  method temperature_cent( float)   to object burlington and using the information about the temperature from KB1 we can obtain the value of the temperature in Centigrade with the help of the  rule below. Note that in in arithmetic equations in FLORA  (as  in  PROLOG) the operator  "is" is used  as sign of equality/assignement instead of "=" .
 

burlington[ temperature_cent( Time)--> TCentigrade]  :-     burlington[ temperature( Time)--> TFarenheit],    TCentigrade    is    (TFarenheit- 32)*5/9.

Here is the graphic form of this rule:

dot-code

Most often rules with arithmetic expressions require some attention to the order of the statements. All variables appearing in the arithmetic expressions  should be instantiated at the time of evaluation. This means that the values of such variables should be determined before the arithmetic expression is evaluated. For example consider the following:.

?- X>1, X is 1+1.  % this does not have sense, because X is not known in expression X>1.

?-X is 1+1, X>1. % this is evaluated as true. X is 1+1 will instantiate X to 2. Next 2>1 evaluated as true.

To facilitate the  right order of expressions we shall  introduce the  following convention: Green arrows connecting the variables indicate the flow of information , or the order of instantiation of the variables. All the variables that appeared in mathematical expression should have corresponding green arrow, originating from variables with the same name and pointing to the mathematical expression box. This will imply that these variables were instantiated before the evaluation of the mathematical expression.

 

Top     |  Previous   |   Next

 

 

C 2003 S. Krivov  Send your comments to skrivov@zoo.uvm.edu