Aspen SCM‎ > ‎Expert System‎ > ‎2. Flow of Control‎ > ‎

2.9 Asserting and Proving Predicates

Recognition of a Predicate

When the Aspen SCM Expert System interpreter is running through a rule and it fails to recognise the meaning of a statement it assumes that a predicate is being asserted. It converts the tokens into canonical form and sees whether there is a predicate which matches it. If there is, it invokes the rule which has that predicate. It gives the predicate arguments in the called rule the values which have been asserted (or leaves them FREE if the corresponding calling argument is FREE). Thus arguments in Aspen SCM Expert System are passed by value, not by reference or by descriptor. For this reason you cannot pass a set or a table into an Aspen SCM Expert System rule, only its name.

The arguments to a predicate can be local or global variables, literal strings (i.e. characters not enclosed in quotes) and quoted strings. Local or global variables and quoted strings can include embedded blanks and keywords such as AND. Arguments which are passed as variables are handled separately from the predicate and can each have up to 79 characters but the entire asserted predicate must be no more than 80 characters long.

Execution of a Rule to Prove a Predicate

The called rule then starts executing at the top, just as it does if you fire it as >MYRULE. But this time if there are instantiated predicate arguments, some of them will now have values. In the ordinary course of events the rule will now run until it reaches the predicate. When it does so, the interpreter checks that each of the arguments is instantiated. If they all are, the predicate is proved in the called rule and the statement resolves TRUE. Usually this means that the rule itself ends TRUE. It is possible that there may be further statements (but no predicates) in the conclusion; if one of these resolves FALSE the rule ends FALSE.

Truth of the Predicate in the Calling Rule

When a rule ends TRUE the predicate is passed back to the calling rule where a check is made that the predicate arguments are consistent with those when the rule was called. This means that any arguments which were instantiated when the rule was called must have the same value now. As the rule can only end TRUE when the predicate has been proved, all the arguments which were FREE when the rule was called will be instantiated now. Any value is accepted as consistent.

If the predicate arguments are consistent, the predicate now resolves TRUE in the calling rule. If any of the input arguments has changed, the predicate resolves FALSE in the calling rule. Thus it is not possible for an argument to be both input and output in a predicate. By convention, output arguments should be listed after input arguments.

Failure to Prove a Predicate

If the interpreter establishes that all possible paths to prove the predicate are blocked, the rule ends FALSE. If an argument in the predicate is FREE when the THEN clause is executed, the rule ends FALSE. It ends UNKNOWN if the interpreter does not reach the predicate but has not exhausted possible paths, e.g. if it BREAKs out of a loop or there is an IN loop over a set which is NULL. Whenever a rule is not proved, the predicate arguments are not passed back to the calling rule and the asserted predicate resolves FALSE (or UNKNOWN) in the calling rule.

Difference between Firing a Rule and Asserting its Predicate

One difference between firing a rule as >MYRULE and asserting a predicate is that if a rule is fired, the interpreter executes it until it can go no further. If a predicate is asserted and the rule contains too many closing brackets, the interpreter works out that it can never prove the predicate and so does not even start. Instead it resolves the predicate as FALSE in the calling rule and continues accordingly.

Another implication of firing a rule as >MYRULE is that, if automatic linking is in use (i.e. RULES(LINK,1) = YES), it causes the case to be relinked. This can cause different behaviour if sets and tables are being created or deleted dynamically.

Back                                Next