## Nature and Purpose of Aspen SCM Expert SystemAspen SCM’s Expert System is used as its programming language. Along with macros (which are similar to the macro languages for operating systems) it forms the glue which is used to create complete applications. It is an interpreted language but is semi-compiled at load time and so executes much more efficiently than macros. Unlike conventional procedural programming languages, the Aspen SCM
Expert System is declarative and is modelled on expert system
languages such as Prolog. Thus the basic unit of a program is a
## Example Rule: Adding Two Numbers TogetherHere is a sample rule: `IF ?X = 1` `AND ?Y = 2` `AND ?Z = ?X + ?Y` `THEN SUM_OF ?X ?Y ?Z` Apart from the syntax, this doesn’t appear to be doing anything different to what could be done in a procedural language. It sets local variables ?X to 1 and ?Y to 2, calculates ?Z as the sum of 1 + 2 and then concludes “SUM_OF 1 2 3”. Aspen SCM Expert System rules are connected together by their conclusions, which act as procedure calls. The above rule is unrealistic in setting ?X and ?Y in the first two lines. A procedure to add two numbers together would be written as: `IF ?Z = ?X + ?Y` `THEN SUM_OF ?X ?Y ?Z` where ?X and ?Y are input arguments and ?Z is an output argument. It would be called by a statement such as ` SUM_OF 1 2 ?Z`
When called in this way it would resolve true as SUM_OF 1 2 3. ## Goldbach's ConjectureGoldbach’s conjecture is that every even number
greater than 4 can be expressed as the sum of two odd primes. Now consider this rule: `IF ?X = 3 OR ?X = 5 OR ?X = 7 OR ?X = 11 OR ?X = 13` `AND ?Y = 3 OR ?Y = 5 OR ?Y = 7 OR ?Y = 11 OR ?Y = 13` `AND ?A = ?X + ?Y` `AND ?A EQ ?Z` `THEN SUM_OF ?X ?Y ?Z` This is designed to be called by a statement such as SUM_OF ?X ?Y 12. It finds primes ?X and ?Y such that ?X + ?Y equals the specified value ?Z, in this case 12. The first two statements declare possible values for ?X and ?Y. The statement ?A = ?X + ?Y then calculates their sum. The next statement ?A EQ ?Z tests whether the result equals the target ?Z and, if it does, proves the conclusion with the values of ?X and ?Y which sum to the result. If you assert the statement SUM_OF ?X ?Y 12, Aspen SCM Expert System
resolves it as true with the result SUM_OF 5 7 12. It does this
without your needing to write any code to iterate through the
potential solutions. You have made the declarations of the possible
values of ?X and ?Y and it finds the solution, if one exists.
## Backtracking through a Search TreeAspen SCM Expert System finds the primes which sum to 12 by a process
known as In practice, the search tree is usually so large that in order to exploit the inherent searching capabilities of Aspen SCM Expert System, you would need to ensure that it was searched efficiently. This requires an intimate knowledge of how Aspen SCM backtracks and very careful coding. It is usually easier to think procedurally and use the Aspen SCM Expert System to implement procedural code. Despite its declarative nature, most of the code which is implemented using Aspen SCM Expert System is procedural. In order to do this successfully a particular programming style has to be adopted which guards against backtracking. Backtracking itself is discussed in section 2.7. Ways of writing code to prevent backtracking are set out in section 3.1. |