














				s m a l l   -   X

		      A Language for Building Expert Systems


				Randy M. Kaplan

				 December 1985
                                 Version 1.02


           Copyright (C) 1984, 1985 R. M. Kaplan  All rights reserved

									i



  	  No part of this manual may be reproduced by any means in
	  any form without the explicit written permission of the
	  author.

	  This manual has been prepared carefully and reviewed for
	  accuracy to insure that it properly represents the program
	  described. However the author makes no warranties whatever
	  concerning this manual or the small-X interpreter described
	  and assumes no liability of any kind for errors or the
	  consequences of these errors.

									ii

			      Table Of Contents

	1. Introduction	...................................   1
	2. A Brief Note About small-X .....................   2
	2.1 Using the Built-In Line Editor ................   3
	3. Running small-X ................................   4
	4. A small-X Tutorial .............................   8
	5. Expert Systems and small-X .....................  16
	6. The small-X Language ...........................  18
	7. small-X Commands ...............................  19
	7.1 STORAGE .......................................  20
	7.2 CLEAR .........................................  21
	7.3 RULES .........................................  22
	7.4 STM ...........................................  23
	7.5 SAVE ..........................................  24
	7.6 READ ..........................................  25
	7.7 REMEMBER ......................................  26
	7.8 MEMORIZE ......................................  27
	7.9 EXIT ..........................................  28
	7.10 ENGINE .......................................  29
	7.11 LIST .........................................  30
	7.12 DELETE .......................................  32
	7.13 TRACE/NOTRACE ................................  33
	7.14 STEP/NOSTEP ..................................  34
	7.15 TERMINAL .....................................  35
	7.16 SHOW .........................................  36
	7.17 HELP .........................................  37
	7.18 DOS ..........................................  39
	7.19 CSAVE ........................................  40
	7.20 CLOAD ........................................  42
	7.21 QUIET/NOQUIET ................................  43
	7.22 LOWER/UPPER ..................................  44
	7.23 FORWARD/BACKWARD .............................  45
	7.24 GOAL .........................................  46
	7.25 STATUS .......................................  47
	8. small-X Data Objects ...........................  48
	9. small-X Actions ................................  51
	9.1 ADD ...........................................  52
	9.2 REMOVE ........................................  53
	9.3 READ ..........................................  54
	9.4 WRITE .........................................  56
	9.5 COMPUTE .......................................  58
	9.6 BIND ..........................................  63
	9.7 UNBIND ........................................  64
	9.8 HALT ..........................................  65
	9.9 FIRE ..........................................  66
	9.10 RESET ........................................  67
	9.11 RUN ..........................................  68
	9.12 OPEN .........................................  69
	9.13 CLOSE ........................................  70
	9.14 MODIFY .......................................  71
	9.15 RESTRICT .....................................  72
	10 small-X Rules ..................................  73
	Appendix A ........................................  81
	Appendix B ........................................  83
	Appendix C ........................................  85
	Appendix D ........................................  97
	Appendix E ........................................  106
	Appendix F ........................................  113

	
									1

	1 Introduction


	This manual describes a programming language called small-X
	and its interpreter. small-X differs from other programming 
	languages because it is a language designed explicitly for building 
	expert systems on small personal computers. small-X is not another 
	LISP or PROLOG although it borrows some of the underlying concepts
	and ideas of these languages.

	small-X is a data driven language. This means that the 
	instructions specified in small-X statements(called rules)
	are only carried out if the data contained in memory
	maintained by small-X meets some criteria or passes some test
	stated in a rule. Rules may be created for almost any condition
	in memory that may arise. The small-X interpreter carries out
	all of the mechanics of testing memory and doing instructions.
	This allows the programmer using small-X to write very complex
	programs using only one kind of programming statement - the 
	rule.

	The small-X interpreter has other duties in addition to 
	doing what rule programs specify. The interpreter manages
	a special kind of memory called short term memory(STM).
	STM is an area of memory that can contain any data object 
	that small-X knows about. The interpreter allows you to manipulate 
	STM with a small number of commands. These are also used as part 
	of small-X rules.

	Following this introduction is a brief tutorial that describes
	how small-X is used to create a simple rule program. You will
	be able to see what some of the interpreter commands are, and
	how they are used. You will also see what a small-X rule looks
	like. As you read the tutorial you may enter the commands
	as shown in the text so that you can actually see how small-X
	works. 

	In order to run small-X you will need an IBM PC or any 100%
	compatible IBM PC. The computer you are using should have
	at least 128K of memory. Since rules and STM are kept in memory, 
	the number of rules you can have at any one time is limited
	by the memory the computer has available.

	After the tutorial will follow a brief description of expert
	systems and their relationship to small-X. In order to write 
	small-X programs it is important to understand the "building 
	blocks" that make up small-X. This description will provide the 
	necessary information about the small-X "building blocks".

	Next, the small-X language will be described in detail. This
	description will include a complete discussion of the syntax of
	small-X commands and rules and their meaning. 

	Welcome to a new realm of programming ... Data bases and
	spreadsheets revolutionized PC use, and now small-X ...

									2


	2 A Brief Note About small-X and its Operation


	small-X is a command driven program. This means that you
	enter a command by typing it on a keyboard and then press
	the "enter key" on the keyboard. If small-X understands
	what you have entered it will respond by doing what the
	command says to do. If it does not understand what you
	have entered it will display an error message and display
	a marker for another command. In this way small-X is very
	similar to DOS in the way it operates. Remember, you must
	press the "enter key" after any command or statement that
	you enter in order for small-X to process it.

	Another point to keep in mind while using small-X is that
	small-X will try to do as much of a command as it can without
	displaying an error message. This means that if you should enter
	some extra characters at the end of a line, but small-X can 
	interpret the line up until the place where these characters are, 
	small-X will do what the command says ignoring the extra 
	characters.


									3

	2.1 Using the Built-In Line Editor


	Sometimes, when you are entering a small-X command or a small-X
	rule you might find that you have made an error. One way to
	correct the error is to enter the command or rule from the very
	start making sure that you do not repeat the error. Other times,
	you might notice the error before you press enter, but you would
	have to delete most of the line in order to correct the mistake.
	The small-X interpreter has a feature that makes correcting errors
	easier. The feature is a built-in line editor that is always at
	your disposal.

	Whenever you enter a command or rule into small-X you can modify
	that command(before you press enter) with the use of several keys
	on the keyboard. These keys are,

				<-   (backspace)
				Del  (Delete)
				Ins  (Insert)
				<-   (Left Arrow)
				->   (Right Arrow)
				+    (Plus)
				-    (Minus)

	All of these keys, except the backspace key, are located on the
	numeric keypad on the right hand side of the keyboard. The backspace
	key is located on the top row of the keyboard, in the alphanumeric
	section(middle section), the rightmost key in the top row(right above 
	the enter key).

	You can move the cursor anywhere on a line using the left and
	right arrow keys. When you move to a spot on a line with these keys
	you can type over whatever is there. 

	The delete key deletes the character directly above the cursor. The
	backspace key deletes the character to the left of the cursor and moves
	the cursor to the left.

	New characters can be inserted by pressing the insert key. This 
	"turns on" insert mode. Characters entered when insert mode is
	"turned on" will cause the line to expand and the characters to
	be inserted.

	The minus key erases the line from the cursor through the end of
	the line.

	The plus key recalls the last line entered. This allows you to
	quickly repeat commands or make small modifications to the same
	command.

	By using these special keys you can correct or change commands
	or rules without having to retype the entire line. Use these keys
	whenever you need to.

									4

	3 Running small-X


	The diskette included with this manual contains a copy
	of the small-X interpreter, a copy of this manual and its
	appendices, a demonstration/tutorial program(written in the
	small-X language), and several sample expert systems. The
	names of the files and there contents are listed below.

	File Name		Contents

	sx.exe			small-X interpreter, 64K version

	nsx.hlp			small-X help file
	sx.err			small-X error file

	sx.txt			text of this manual
	sxapdx.txt		text of the appendices of this manual

	demo.sx			the demonstration script
	demo1.rul		rule base 1 of 5 for the demonstration
	demo2.rul		rule base 2 of 5 for the demonstration
	demo3.rul		rule base 3 of 5 for the demonstration
	demo4.rul		rule base 4 of 5 for the demonstration
	demo5.rul		rule base 5 of 5 for the demonstration

	demo1.crl		encoded rule base 1 of 5 for the demonstration
	demo2.crl		encoded rule base 2 of 5 for the demonstration
	demo3.crl		encoded rule base 3 of 5 for the demonstration
	demo4.crl		encoded rule base 4 of 5 for the demonstration
	demo5.crl		encoded rule base 5 of 5 for the demonstration

	exp1.rul		sample expert system 1 - animal classification
	exp2.rul		sample expert system 2 - simple car diagnosis
	exp2.crl		encoded sample expert system 2 - simple car 
				 diagnosis
	exp3.rul		sample expert system 3 - simple plant
				 classification
	exp4.rul		sample expert system 4 - mock tax advisor
	eliza.rul		sample expert system 5 - a simple version
				 of the ELIZA program
	fact.rul		sample expert system 6 - a program to compute
				 factorials

	When you are ready to use small-X, it is important that you
	protect the disk included with this manual. The best way to
	do this is to make a copy of the diskette and use the copy
	whenever you want to use the small-X program. To make a copy
	of the diskette, follow the instructions on the next page.



									5


	Making a Copy of the small-X Distribution Diskette

	1. Insert the small-X distribution diskette(the diskette with
	   this manual) in one of the diskette drives of your system.

	2. If your system has a hard disk, you may want to make a
	   new subdirectory for the small-X program. You can do this
	   by entering the command,

			MKDIR directory name

	   Once you have made the directory you need to make it the
	   default directory. Do this by entering the command below.

			CD directory name

	3. If you are making a copy of the small-X disk on another 
	   floppy diskette, insert the other floppy diskette into
	   the other available drive(i.e., if you've inserted the
	   distribution diskette into the A: drive, insert the
	   blank diskette into the B: drive).

	4. If you are using a floppy diskette to copy to and the diskette
	   is not formatted, enter the command below to format this
	   diskette,

			FORMAT drive name

	   MAKE SURE THE drive name YOU SPECIFY IS THE DRIVE WITH THE
	   BLANK DISKETTE.

	5. Copy all of the files to the copy target(disktte or hard disk)
	   by entering the command,

			COPY distrbution drive:*.*  target drive:

	   For example,

			COPY A:*.* B:

	Having made a copy of the distribution diskette you are now
	ready to use the small-X program.


									6


	Using the small-X Program


	In order to use the small-X program, you need to insert the
	copy of the small-X distribution diskette into a disk drive
	or make the small-X directory of your hard disk the current
	directory.

	If your copy of small-X is on a floppy disk, the drive into
	which you insert the floppy must be the current drive. For
	instance, if you insert the small-X floppy into drive B, enter
	the command,

			B:

	to make B the current drive.

	Once you have done this you can use the small-X interpreter.

	A good way to begin is to run the demonstration/tutorial. To
	do this, enter the command,

			sx demo.sx

	This will run the small-X demonstration script.

	You may want to run the sample expert systems also. To do
	this, follow the steps below.

	1. Enter the command,

			sx

	   This will start the small-X interpreter.

	2. Enter the small-X command, 

			REMEMBER sample name

	   where sample name is,

			EXP1 or,
			EXP2 or,
			EXP3 or,
			EXP4 or,
			ELIZA

	   This will load the sample you want to run.

	3. To run the sample, enter

			ENGINE

	   This will run the sample.



									7


	4. After running the sample, you may wish to select another
	   sample. To do this, its a good idea to clear memory. The
	   commands

			CLEAR RULES

	   and

			CLEAR STM

	   erase the contents of memory.

	5. To run another sample, go to step 2.

	6. To exit the small-X interpreter, enter the command,
	
			EXIT
	

									8

	4 A small-X Tutorial


	This section contains a brief small-X tutorial. The tutorial
	shows some of the features of small-X and how the small-X
	interpreter operates. If you wish, you can follow this tutorial 
	using the small-X interpreter by entering the commands and rules 
	shown in the following discussion.

	Suppose you wanted to create a program that helps classify
	animals. To do this you need 2 things. First you need a 
	list of criteria you will use to classify the animals and
	second you will need the rules which use the criteria to
	do the actual classification.

	Suppose we ask the following questions about an animal in
	order to classify it.

		does the animal have hair ?
		does the animal give milk ?
		does the animal have feathers ?
		does the animal lay eggs ?
		does the animal fly ?

	Each of these questions is answered yes or no depending upon
	the characteristics of the animal.

	Let us make a rule in small-X that will ask these questions
	so that an animal may be classified.

	First, we start the small-X program by entering sx and pressing
	RETURN.

	Then we enter the small-X command RULES and press RETURN.

	Next we enter the following rule(be careful to enter this exactly
	as shown):

	if NOT IN-MEMORY(dummy) then
	{
		write 'Answer each of the following questions with a yes or no'
		write new-line
		read 'Does animal have hair ?' #hair
		read 'Does animal give milk ?' #milk
		read 'Does animal have feathers ?' #feathers
		read 'Does animal lay eggs ?' #eggs
		read 'Does animal fly ?' #flies
	}

									9


	Here's what it looks like so far:
	
	---------------------------------------------------------------------
	A> sx

	Welcome to Small-X  -  Version 1.02
	Copyright (C) 1984,1985. All rights reserved
	R. Kaplan, West Chester, PA

	SmallX> RULES
	Rules> if NOT IN-MEMORY(dummy) then
	More> {
	More>	write 'Answer each of the following questions with a yes or no'
	More>	write new-line
	More>	read 'Does animal have hair ?' #hair
	More>	read 'Does animal give milk ?' #milk
	More>	read 'Does animal have feathers ?' #feathers
	More>	read 'Does animal lay eggs ?' #eggs
	More>	read 'Does animal fly ?' #flies
	More> }
	Rules>
	---------------------------------------------------------------------
	
	At this point you can see what the rule looks like to make
	sure you entered it correctly. You do this by entering the
	LIST RULES command. 

	First press RETURN to get the SmallX> marker and then enter 
	LIST RULES and press RETURN. The rule you entered is listed
	on the screen.


	---------------------------------------------------------------------
	Rules>
	Smallx> LIST RULES

	[r01] IF #start =  'true'  C[1.000000]  THEN 
	{
	WRITE  'Answer each of the following questions with a yes or no'  
	WRITE NEW-LINE
	READ 'Does animal have hair ?' #hair  
	READ 'Does animal give milk ?' #milk  
	READ 'Does animal have feathers ?' #feathers  
	READ 'Does animal lay eggs ?' #eggs  
	READ 'Does animal fly ?' #flies  
	}
	---------------------------------------------------------------------

	Notice that small-X makes some changes to the rule. First it
	adds a name to the rule, [r01]. This is so you can identify the
	rule if you need to. It also adds a rule value, designated by
	the C[1.000000]. This value represents the quality of the
	rule and determines when it is used. small-X also capitalizes
	some words to make the rule more readable.

									10

	When you enter a rule, memory is used. Every rule makes use of
	computer memory. Sometimes it's useful to see how much memory
	you have avilable for rules. You can do this by entering the 
	STORAGE command.

	Enter this command and small-X will display the amount of memory 
	available for rules.

	---------------------------------------------------------------------
	SmallX> STORAGE

	** 3 rules **
	** total memory available  58332 bytes **
	** can hold 265 rules **
	---------------------------------------------------------------------

	Using this command you can tell how much space is left for rules
	and STM objects.

	Back to our expert system. Now that you entered the rule 
	that gets your criteria, you can enter the classification rules.

	First, we know that if an animal has hair it is a mammal. This
	is our first classification rule.

	We also know that if an animal gives milk, it is also a mammal.

	Next, we can say that an animal having feathers is a bird or
	if the animal flies and lays eggs it is also a bird.

	These classification rules can be translated into small-X rules.

		IF #hair = yes OR
		   #milk = yes THEN
		{
			write 'animal is a mammal'
			halt
		}

		
		if #feathers = yes then 
		{
			write 'animal is a bird'
			halt
		}

		if #flies = yes and #eggs = yes then 
		{
			write 'animal is a bird'
			halt
		}

	Now that we have these rules, they can be entered into small-X.
	Enter the command RULES to get into rule memory then these rules
	can be entered also.

									11


	---------------------------------------------------------------------
	SMALLX> RULES
	Rules>	IF #hair = yes OR
	More>	   #milk = yes THEN
	More>	{
	More>		write 'animal is a mammal'
	More>		halt
	More>	}
	Rules>	if #feathers = yes then 
	More>	{
	More>		write 'animal is a bird'
	More>		halt
	More>	}
	Rules>	if #flies = yes and #eggs = yes then 
	More>	{
	More>		write 'animal is a bird'
	More>		halt
	More>	}
	Rules>
	---------------------------------------------------------------------

	Having entered these rules, you may want to save them so that you
	can change them or restore them for the next time you want to
	classify animals.

	To do this you enter the MEMORIZE command with a name. A file
	will be created on disk that contains the rules in rule memory.

	---------------------------------------------------------------------
	Rules>
	SmallX> MEMORIZE ANIMALS
	** saving rules **

	SmallX>
	---------------------------------------------------------------------

	Restoring these rules is just as simple. Instead of MEMORIZE the
	REMEMBER command is used. Entering this command causes the rules
	that were previously saved to be restored to rule memory. This
	is shown below.

	---------------------------------------------------------------------
	SmallX> REMEMBER ANIMALS
	** restoring rules **

	SmallX>
	---------------------------------------------------------------------

									12

	Now that you have a few of the rules entered, you might want to
	check to see these rules work. To do this you start the inference 
	engine with the ENGINE command. If the rules work the way you expect 
	them to, you would continue entering more classification rules.

	Right now, let's test what we have.

	Enter the ENGINE command and press RETURN.
 
	Here's what happens then:

	The inference engine starts examining STM and rule memory
	for a condition in a rule that matches STM. The first rule
	will match because symbol dummy is not in STM. Rule r01 is 
	the first rule to fire.

	This rule asks the question to get all of the criteria.

	The way it looks up to now is shown below:

	
	---------------------------------------------------------------------
	SmallX> ENGINE
	** Inference Engine Running **

	Answer each of the following questions with a yes or a no
	Does the animal have hair ? no
	Does the animal give milk ? no
	Does the animal have feathers ? yes
	Does the animal lay eggs ? yes
	Does the animal fly ? yes
	---------------------------------------------------------------------

	Notice we have answered each of the questions.

	Once the last question is answered, the inference engine scans
	all of the rules again to see if any rule condition matches STM.
	The inference engine finds that rule r04 matches and displays
	the message "animal is a bird" and the inference engine
	halts.

	
	---------------------------------------------------------------------
	animal is a bird 
	SmallX>
	---------------------------------------------------------------------

									13

	You might want to see what rules are being fired as the inference
	engine operates. small-X has a feature that allows you to see
	the names of the rules being fired. This feature is called trace.

	Trace can be turned on by entering the small-X command TRACE.
	The same inference engine example is shown below with trace turned
	on.

	---------------------------------------------------------------------
	SmallX> TRACE
	** trace is now on **

	SmallX> ENGINE
	** Inference Engine Running **

	** firing rule [r01] **
	<rule r01 is displayed>

	Answer each of the following questions with a yes or a no
	Does the animal have hair ? no
	Does the animal give milk ? no
	Does the animal have feathers ? yes
	Does the animal lay eggs ? yes
	Does the animal fly ? yes

	** firing rule [r04] **
	<rule r04 is displayed>

	animal is a bird SmallX> NOTRACE
	** trace is now off **

	SmallX>
	---------------------------------------------------------------------

	Trace mode can be turned off with the command NOTRACE as shown
	above.

	Just as you were able to examine the rules that you entered you
	can also examine the contents of short term memory. This is
	done with the LIST command again, but instead of LIST RULES you
	enter LIST STM. The result is shown below.

	---------------------------------------------------------------------
	SmallX> LIST STM
	BIND #hair 'no'
	BIND #milk 'no'
	BIND #feathers 'yes'
	BIND #eggs 'yes'
	BIND #flies 'yes'

	SmallX>
	---------------------------------------------------------------------

									14

	The words in STM that are preceeded by a # are called variables.
	Variables represent objects in STM and can assume the value of
	any data object that small-X can manipulate.

	You can manipulate STM with STM commands. For instance, if you
	want to change the value of one of the animal classification
	variables you can use the BIND action to do this.

	Supposing the animal did not fly. To change the flies variable
	you could enter BIND #flies no. When you listed STM again
	you would see that the #flies variable value was changed.

	---------------------------------------------------------------------
	SmallX> STM
	STM> BIND #flies no
	STM>
	SmallX> LIST STM
	BIND #hair 'no'
	BIND #milk 'no'
	BIND #feathers 'yes'
	BIND #eggs 'yes'
	BIND #flies 'no'

	SmallX>
	---------------------------------------------------------------------

	Other kinds of manipulations are also possible in STM. One of
	these allows you to do simple aritmetic computations.

	The COMPUTE command allows you to assign a variable to the
	value of a simple expression, such as 4*5 or 7.2-6.5, etc.
	This command can also be used to change a variables value.
	You can see the result of a COMPUTE command by using the WRITE
	command immediately after entering the COMPUTE command. The
	following shows several examples of the COMPUTE command.

	---------------------------------------------------------------------
	SmallX> STM
	STM> COMPUTE #x <- 7 + 2
	STM> WRITE #x
	9 
	STM> COMPUTE #x <- #x * 2
	STM> WRITE #x
	18 
	STM> COMPUTE #y <- #x / 3
	STM> WRITE #y
	6 
	STM> COMPUTE #z <- #x + #y
	STM> WRITE #z
	24 
	STM>
	SmallX>
	---------------------------------------------------------------------

									15

	Once you are finished using a particular set of rules in rule
	memory and its corresponding short term memory you can erase
	the contents of these memories for another set of rules and
	objects. This is done with the CLEAR command. To clear short term
	memory, enter the command CLEAR STM. To clear rule memory enter
	the command CLEAR RULES. If you do this and then enter the storage
	command you will see that you now have the same amount of memory that
	you started with.

	---------------------------------------------------------------------
	SmallX> CLEAR STM
	SmallX> CLEAR RULES
	SmallX> STORAGE
	** 0 rules **
	** total memory available 58880 bytes **
	** can hold 267 rules **

	SmallX>
	---------------------------------------------------------------------

	After entering rules and running rule programs you may want to
	return to DOS. To end small-X and return to DOS, use the EXIT 
	command.

	---------------------------------------------------------------------
	SmallX> EXIT

        A>
	---------------------------------------------------------------------

	This finishes the brief small-X tutorial. In this tutorial you
	saw some the commands, how rules were constructed, how the inference
	engine runs, and how to manipulate short term memory. In the
	next section we will discuss some basic concepts about expert
	systems. This will help you in better understanding this 
	tutorial and subsequent explanations of small-X commands and 
	rules.

									16

	5 Expert Systems and small-X


	As you saw in the tutorial small-X is a computer program that
	understands a certain kind of language. The language consists
	of commands that the small-X interpreter processes and rules 
	that make up small-X programs which are also processed by the 
	small-X  program.

	small-X is a program to build small expert systems. As we have
	said an expert system is a computer program that behaves like
	a human expert by using the same rules a human expert does to
	make decisions.

	A rule is a kind of knowledge and a set of rules make a kind
	of data base called a knowledge base.

	The rules specify tests against an area of memory we have
	called short term memory or STM. The tests that can be done
	are basically arithmetic comparisons in the case of numbers
	stored in STM and pattern comparisons in the case of other
	kinds of data objects stored in STM. Expert systems rely
	heavily on this ability to "pattern match" rules against
	STM. This is a very important characteristic of expert systems.

	Another important characteristic of expert systems is their
	control mechanism. small-X has a relatively simple and powerful
	control mechanism built into the inference engine. This control
	mechanism is the way small-X selects rules and fires or activates
	them.

	In any expert system the inference engine continues to run
	until it is explicitly halted or until it cannot find any
	rules that match the conditions in STM. Each time the inference 
	engine searches for, matches, and fires a rule constitutes
	a cycle of the inference engine. In any cycle only a single rule
	is activated. Once a rule is activated it will never again be
	selected, unless it is "reset" by a rule so that it can be
	use again.

	If during a cycle, more than one rule can be fired, small-X
	selects a single rule by either taking the first rule it
	encountered in the matching process or taking the rule with
	the highest rule value. The rule value is a value you can assign
	to a rule that represents the "goodness" of the rule.
	
	The small-X inference engine allows you to choose how it 
	operates. Currently you can choose between forward and 
	backward chaining modes.

	In forward chaining, small-X looks at short term memory
	for data that matches the conditions of a rule. All rules
	whose conditions match short term memory are collected and
	one of the rules is selected. The selected rule is activated 
	and the process repeats itself.

									17


	The backward chaining control mechansim uses a goal to determine
	what has to be done. The goal specifies a problem to be solved. 
	The inference engine in backward chaining mode looks for rules
	that accomplish the specified goal. Finding these rules the
	engine checks to see if any of the rules conditions are
	completely satisfied so that a rule can be activated. If a
	rule can be activated, it is, and the engine stops. If no rule
	can be activated because its conditions are not completely
	satisfied, a rule is selected and its conditions become the
	new goal(s). The engine attempts to accomplish each of these
	new goal(s) in the same way it attempted to accomplish the
	original goal. The inference engine, working in backward chaining
	mode solves a problem by decomposing the problem into smaller
	and smaller subproblems.
	
	In summary, expert systems have data bases called knowledge
	bases that consist of rules. A pattern matching mechanism is
	built into the expert system that match rules against STM. The
	inference engine does the searching/matching/firing process
	continually until it is explicitly halted or until no more
	rules can be found to match STM. 
	
									18

	6 The small-X Language


	Now that you have seen a bit about how small-X operates and
	also understand more about expert systems and their structure 
	it's time to get into the nitty-gritty of small-X - the details 
	of the language.

	The tutorial showed most of the features of the small-X language,
	and how they work. This section extends the information presented
	in the tutorial by describing in detail everything about small-X
	commands and programming statements.

	small-X is more than just a language. It is a language in the
	sense that there are a set of rules which define how sentences
	in small-X can be written. These rules for putting together sentences
	in small-X will be described in this section. Besides being a 
	language, small-X is also a computer program that takes these 
	sentences and does what they say. This part of small-X, called an
	interpreter, not only understands sentences but also understands
	commands.

	small-X commands are instructions to the interpreter to do
	certain actions. For instance, in order for small-X to translate
	rules so that it can carry out their purpose you must first
	tell the interpreter that this is what you want to do. Having
	told this to the interpreter, it becomes ready to accept
	rules. This section will begin by describing all of the
	small-X interpreter commands and how they are used.


									19

	7 small-X Commands


	When you first start small-X from DOS, small-X clears the
	screen of your PC, and displays 3 lines that look like
	the lines shown below.


	---------------------------------------------------------------------
	Welcome to Small-X  -  Version 1.02
	Copyright (C) 1984,1985. All rights reserved
	R. Kaplan, West Chester, PA

	SmallX> 
	---------------------------------------------------------------------


	The first line indentifies that small-X is running and the second
	next line is called a marker. The marker tells you that the
	small-X interpreter is waiting for input(denoted by a >) and also
	what kind of input(denoted by Small-X). When you first start small-X,
	the marker indicates that it is waiting for a small-X command. As
	you will see, there are other markers that indicate that small-X
	is waiting for other sorts of commands.

	The following commands may be entered at the small-X marker.
	

			STOrage		CLEar
			CSAve 		CLOad
			RUles		STM
			SAve		REAd
			REMember	MEMorize
			EXit		ENgine
			LIst		LOwer
			Upper		Forward
			Backward	Goal
			STAtus		DElete
			DOs		TRace/NOTrace
			STEp/NOStep	TErminal
			Help		SHow
			Quiet/NOQuiet

	The capital letters of the list above indicate which letters
	of a command need to be entered in order for small-X to recognize
	the command. Therefore, in order for small-X to recognize that
	the command is storage, all that has to be entered are the 
	letters S, T, and O.

									20

	7.1 STORAGE

	The STORAGE command makes small-X show you the amount of free
	storage available for rules and STM. Anytime you enter this
	command, small-X will show you the number of free bytes in
	memory that are available and also estimate the number of
	rules that can be stored in this available area. An example
	is shown below. Also, the number of rules currently in rule
	memory will be shown.


	---------------------------------------------------------------------
	SmallX> storage
	** 10 rules **
	** total memory available 58880 bytes **
	** can hold 267 rules **

	SmallX>
	---------------------------------------------------------------------

									21

	7.2 CLEAR


	The clear command is used to erase STM or rule memory completly.
	Once you use this command to erase STM or rule memory, it is
	deleted and cannot be recovered so you must be careful when using
	the CLEAR command.

	To erase all of STM you enter the command CLEAR STM.

	To erase all of rule memory you enter the command CLEAR RULES.

	If you forget to specify what you want to clear the small-X
	interpreter will display another marker(as shown below). At
	this marker you are to enter either RULES or STM.
	

	---------------------------------------------------------------------
	SmallX> clear
	Option STM/Rules> STM

	SmallX>
	---------------------------------------------------------------------


	After you enter the clear command with the appropriate option,
	small-X displays the small-X marker to let you know it carried
	out the CLEAR command successfully.

									22

	7.3 RULES


	This command tells the interpreter to recognize rules. When
	you enter this command, two things happen.

	First, small-X displays a different marker. This marker, called
	the rules marker, indicates that small-X is waiting to accept
	rules. The rules marker is shown below.

	---------------------------------------------------------------------
	SmallX> Rules
	Rules>

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

	The second thing that happens is that now small-X will not
	recognize any small-X commands - it will only recognize small-X
	rules. Therefore if you now try to enter a command that works
	at the small-X marker, it will not work at the rules marker.
	small-X will display an error message letting you know that it
	did not get a rule as it was expecting.

	If you enter a rule properly and small-X recognizes the rule,
	it will be stored in rule memory. How a rule is written will be
	discussed in detail in a later section of this manual.
	

									23

	7.4 STM


	STM is a command that is used when you want to manipulate
	STM. Like the RULES command, when you enter this command, the marker
	changes. In this case the marker changes to the STM marker
	(shown below). Also like the RULES command, when you are in
	STM, small-X will no longer understand Small-X marker commands -
	only STM commands. Thus if you enter a Small-X marker command
	while the STM marker is displayed, small-X will display a
	message letting you know it does not recognize the command
	you entered.

	---------------------------------------------------------------------
	SmallX> STM
	STM>

	---------------------------------------------------------------------

									24

	7.5 SAVE


	The SAVE command lets you create a file of the object currently
	in STM. When you enter a SAVE command, the interpreter will 
	create a file of commands that will restore STM to the state
	at the time it was saved.

	To save STM enter the command, SAVE or SAVE filename.

	If you enter just SAVE, small-X will prompt you for a file
	name by displaying the marker Filename>.

	The file name can be up to 8 characters long and will be used
	to create the file that contains the STM commands to restore
	STM. The actual file name created by small-X will have the 
	file name suffix .STM. Once this file is created you can
	examine it with the DOS type command or edit it with EDLIN
	or any other editor.


	Examples


	In the following examples a file called PROJECT.STM is created
	that contains STM commands to restore STM.


	---------------------------------------------------------------------
	SmallX> SAVE project
	** saving STM **
	** writing project.stm **

	SmallX>
	---------------------------------------------------------------------


	---------------------------------------------------------------------
	SmallX> SAVE
	** saving STM **

	Filename> project
	** writing project.stm **
	SmallX>
	---------------------------------------------------------------------

									25

	7.6 READ


	READ is a companion to SAVE. READ allows you to restore STM
	to a previous state from a file that was previously created
	by SAVE or one that you created yourself(with an editor for
	instance).

	To READ an STM file enter the command READ or READ filename.

	If you enter just READ, small-X will prompt you for a file name
	by displaying the marker Filename>. Here you enter the name of
	the file you want to use to restore STM.

	Small-X appends a .STM to the file name you specify. Therefore,
	if a file name is specified and there is no file on disk
	with the name and an .STM suffix, small-X will display a message 
	letting you know it cannot find the specified file.
	

	Examples


	In the following examples a file called PROJECT.STM is restored
	to STM.


	---------------------------------------------------------------------
	SmallX> READ project
	** restoring STM **
	** reading project.stm **

	SmallX>
	---------------------------------------------------------------------


	---------------------------------------------------------------------
	SmallX> READ
	** restoring STM **

	Filename> project
	** reading project.stm **
	SmallX>
	---------------------------------------------------------------------


									26
	
	7.7 REMEMBER



	Just as you can save and resotore short term memory you may also
	save and restore any rules that have been created during a small-X
	session. The commands MEMORIZE and REMEMBER are used for this
	purpose.

	Since rules tend to be somewhat more complex than STM, these
	commands are particularly useful when a small-X program is created
	using an external editor. The file created by this editor can
	then be moved into small-X rule memory with the REMEMBER command.

	Likewise, a set of rules can be saved using the MEMORIZE command.
	This command creates a file of rules that can be edited.

	To restore a rule file enter the command REMEMBER or REMEMBER
	filename.

	If you enter only REMEMBER you will be prompted for the file
	name.

	All rule files must have the file suffix .RUL. small-X takes
	the file name you specify and appends a .RUL to it before
	trying to find it. If small-X cannot find a file named 
	filename.RUL, small-X will display a message to let you 
	know this.


	Examples


	The examples below show a file called PROJECT.RUL being used
	to restore rule memory.


	---------------------------------------------------------------------
	SmallX> REMEMBER project
	** restoring Rules **
	** reading project.rul **

	SmallX>
	---------------------------------------------------------------------

	---------------------------------------------------------------------
	SmallX> REMEMBER
	** restoring Rules **

	Filename> project
	** reading project.rul **
	SmallX>
	---------------------------------------------------------------------

									27

	7.8 MEMORIZE


	The memorize command saves the contents of rule memory to
	a disk file. The file created will have a .RUL appended to
	its file name.

	To save rule memory, enter the command MEMORIZE or MEMORIZE
	filename.

	If you enter only the command MEMORIZE you will be prompted
	for the file name with the marker Filename>.

	
	Examples


	Below, the examples show a file called PROJECT.RUL being
	created which will contain the contents of rule memory.


	---------------------------------------------------------------------
	SmallX> MEMORIZE project
	** saving Rules **
	** writing project.rul **

	SmallX>
	---------------------------------------------------------------------

	---------------------------------------------------------------------
	SmallX> MEMORIZE
	** saving Rules **

	Filename> project
	** writing project.rul **
	SmallX>
	---------------------------------------------------------------------

									28

	7.9 EXIT


	The EXIT command ends a small-X session. Entering the EXIT command
	causes small-X to return to DOS.


	---------------------------------------------------------------------
	SmallX> EXIT
	A>
	---------------------------------------------------------------------

									29

	7.10 ENGINE


	The ENGINE command starts the small-X inference engine.
	Entering this command causes the rules currently in rule
	memory to be processed. The ENGINE command "runs" small-X
	programs.


	---------------------------------------------------------------------
	SmallX> ENGINE

	** Inference Engine Running **
	---------------------------------------------------------------------

									30

	7.11 LIST


	LIST is used to display the contents of rule memory or
	STM. Rules or STM contents are displayed on the PC screen.

	To display the contents of STM enter the command LIST STM.
	If you forget to specify STM, small-X will prompt for what
	you want to list by displaying the marker Option STM/Rules>.
	To list STM, STM is entered when this prompt is displayed.

	Likewise, to list the rules in rule memory enter the command
	LIST RULES or just LIST. If all you enter is LIST the
	Option STM/Rules> marker will be displayed and you can then
	enter RULES.

	The examples below show sample listings of STM and rule memory.


	Examples


	---------------------------------------------------------------------
	SmallX> LIST STM
	BIND #cranks  'yes'  
	BIND #charged  'yes'  
	BIND #empty  'yes'  
	---------------------------------------------------------------------

	---------------------------------------------------------------------
	Smallx> LIST
	Option STM/Rules> STM

				STM listing
				    .
				    .
				    .
	---------------------------------------------------------------------

									31

	When a rule program is displayed on the screen, one rule at a time
	will be displayed. In order to see the next rule you press return
	as indicated by the message displayed at the bottom of the screen.
	If your rule program is long you may not want to see all of the rules
	so you can press escape to return to the SmallX> marker. You can
	also display a single rule by using the SHOW command.

	LIST Examples (continued)

	---------------------------------------------------------------------
	SmallX> LIST RULES
	[r01] IF  NOT IN-MEMORY(  'dummy'  ) C[1.000000]  THEN 
	{
	WRITE  CLEAR  
	WRITE  NEW-LINE  
	WRITE  NEW-LINE  
	WRITE  'Car Problem Expert System'  
	WRITE  NEW-LINE  
	WRITE  NEW-LINE  
	WRITE  'Please answer each of the questions yes or no.'  
	WRITE  NEW-LINE  
	}

	... press return for more ... press escape for SmallX> ...
	---------------------------------------------------------------------

	---------------------------------------------------------------------
	SmallX> LIST
	Option STM/Rules> RULES

				Rule listing
				    .
				    .
				    .
	---------------------------------------------------------------------

									32

	7.12 DELETE


	DELETE is used to remove a single rule from rule memory. Each
	rule has a name in rule memory. This is a name that you assign
	to a rule or that small-X automatically assigns when you do not
	name a rule. The names of rules can be determined by using the
	LIST RULES command. The name preceeds the IF of every rule
	and is enclosed in brackets.


          rule name
          v
	[r08] IF #charged =  'no'  AND 
	 NOT IN-MEMORY( #lit  ) C[1.000000]  THEN 
	{
	READ  STRING 'Is battery indicator lit ? ' #lit  
	}

	To delete a rule, enter the command DELETE followed by
	a rule name, as in DELETE r08. This will cause the specified
	rule to be removed from memory. All other rules will remain in
	tact. If the rule was successfully deleted, small-X will display
	the small-X marker. This is shown in the example.


	Example


	---------------------------------------------------------------------
	SmallX> DELETE r08
	SmallX>
	---------------------------------------------------------------------

	If you enter only the DELETE command without a rule name, small-X
	will prompt you for a rule name by displaying a rule name marker.
	This is shown in the example below.

	---------------------------------------------------------------------
	SmallX> DELETE
	Rule Name> r08
	SmallX>
	---------------------------------------------------------------------

									33

	7.13 TRACE/NOTRACE


	TRACE and NOTRACE are used to debug small-X programs. When you
	activate the trace feature by entering the command TRACE, small-X
	will display the name of each rule it activates and also the rule
	while a rule program is being processed. This is useful for seeing 
	the sequence of rules being activated for a specific state of STM.

	When TRACE is entered, small-X lets you know the trace feature
	is turned on by displaying a message.

	NOTRACE deactivates the TRACE feature. When you enter the NOTRACE
	command, no rule names are displayed as small-X is processing the
	rule program. NOTRACE is the normal mode of small-X operation.


	Examples

	
	---------------------------------------------------------------------
	SmallX> TRACE

	** trace is on **
	SmallX> ENGINE

	** firing rule [r01] **
	<rule r01 is displayed>

	** firing rule [r04] **
	<rule r04 is displayed>

		.
		.
		.
	---------------------------------------------------------------------


	---------------------------------------------------------------------
	SmallX> NOTRACE

	** trace is off **
	SmallX>
	---------------------------------------------------------------------

									34

	7.14 STEP/NOSTEP


	Another command that is very useful for debugging is STEP
	command.

	The purpose of the STEP command is to stop the inference engine
	after each cycle and allow you to examine the contents of STM.

	When you enter the STEP command, small-X displays a message to
	let you know that single step mode is activated. Once activated,
	the STEP command, after a rule is fired, causes small-X to activate 
	STM. You will know this because the STM marker will be displayed.
	When the STM marker is displayed you can enter any STM action
	to examine or manipulate STM. STEP may be useful when you are
	running a rule program and need to make a change to STM in the 
	middle of the rule program run. By activating single step mode
	you can do this.

	The NOSTEP command deactivates single step mode. This is the
	way small-X normally operates.


	Examples


	---------------------------------------------------------------------
	SmallX> STEP

	** single step on **
	SmallX> TRACE

	** trace is on **
	SmallX> ENGINE

	** firing rule [r01] **
	<rule r01 is displayed>

	STM>
	---------------------------------------------------------------------
	

	---------------------------------------------------------------------
	SmallX> NOSTEP
	** single step off **

	SmallX>
	---------------------------------------------------------------------

									35

	7.15 TERMINAL


	When small-X commands are coming from a file you may want
	to "re-direct" the source of small-X commands to the keyboard.
	The TERMINAL command is used for this purpose.

	When small-X encounters a TERMINAL command in a small-X 
	command file, small-X stops getting its commands from the
	file and returns to getting commands and rules from the
	terminal.

	Examples

	---------------------------------------------------------------------
	SmallX> TERMINAL

	** keyboard input **
	SmallX>
	---------------------------------------------------------------------
	

									36
	7.16 SHOW

	The SHOW command allows you to display a single rule. This command
	would be useful when you want to know about a paricular rule in
	rule memory or when you are looking for a particular rule to delete.

	To display an individual rule enter the command SHOW followed
	by the name of the rule you want to display.

	When you enter this command and a rule name, the rule will be
	displayed if it can be found in rule memory. This is shown in
	the following example.

	Example

	---------------------------------------------------------------------
	SmallX> SHOW r01
	[r01] IF #charged =  'no'  AND 
	NOT IN-MEMORY( #lit  ) C[1.000000]  THEN 
	READ STRING 'Is battery indicator lit ? ' #lit
	SmallX>
	---------------------------------------------------------------------

	If you enter only the SHOW command without a rule name, small-X
	will prompt you for a rule name by displaying a rule name marker.
	This is shown in the example below.

	---------------------------------------------------------------------
	SmallX> SHOW
	Rule Name> r01
	[r01] IF #charged =  'no'  AND 
	NOT IN-MEMORY( #lit  ) C[1.000000]  THEN 
	READ STRING 'Is battery indicator lit ? ' #lit
	SmallX>
	---------------------------------------------------------------------

									37

	7.17 HELP


	The HELP command displays information about small-X commands,
	data objects, actions, and rules. Its purpose is to provide
	assistance while small-X is being used to develop and run
	rule programs. Most of the information contained in this manual
	is available through the HELP command.

	To use the HELP command, enter HELP.

	When you do this, the screen will clear and the display will
	look like the figure below.

	The top box of this display will show what help you are seeing.

	You enter a phrase that says what you want help for at the
	marker at the bottom(Help for>).

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

	
	  -------------Small-X Interprter Help - Version 1.02------------
	 |                                                               |
	  ---------------------------------------------------------------











	   Help for>


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

									38

	Any of the following topics can be entered and help will be
	displayed for it.


	COMMANDS	STORAGE		CLEAR		RULES
	STM		SAVE		READ 		REMEMBER
	MEMORIZE 	EXIT		ENGINE 		LIST
	DELETE 		TRACE		STEP 		TERMINAL
	SHOW		HELP		DOS		CLOAD
	CSAVE		STATUS		GOAL		FORWARD
	BACKWARD	UPPER		LOWER		ADD ACTION
	REMOVE ACTION	READ ACTION	WRITE ACTION	COMPUTE ACTION
	BIND ACTION	UNBIND ACTION	HALT ACTION	FIRE ACTION
	RESET ACTION	RUN ACTION	OPEN ACTION	CLOSE ACTION
	RESTRICT ACTION	RULES		ERRORS		MODIFY ACTION
	DATA		SYNTAX

	When you enter a particular topic, help will be displayed for
	that topic. If the help available requires more than 1 screen
	for display, you will be prompted at the bottom to press RETURN 
	for more. If you do not wish to see the rest of the help for a 
	topic you can press ESCAPE(esc) and this will return you to the 
	Smallx> marker.

	To return to the SmallX> marker after you have finshed using
	help you can simply press RETURN.


									39

	7.18 DOS


	The DOS command allows you to enter commands that are processed
	by the operating system without leaving the small-X interpreter.
	This command allows you to run an editor or do a directory from
	within small-X.

	When you enter the DOS command the DOS marker(DOS>) is displayed.
	At this marker you can enter any valid DOS command. 

	Example

	---------------------------------------------------------------------
	SmallX> DOS
	DOS> DIR SX.EXE
	SX       EXE    44504   6-29-85   5:29p

	DOS>
	---------------------------------------------------------------------

	To return to small-X command mode when in DOS, press the return
	key at the DOS marker. The small-X marker will be displayed
	indicating you have returned to small-X.

	DOS mode can be used to edit rule files as you are writing or
	debugging them. Suppose you are working on a rule base called
	example. You have loaded this and have run it and want to make
	some changes to it. The command sequence shown below depicts how
	this can be accomplished.

	---------------------------------------------------------------------
	SmallX> rem example
	.
	.
	SmallX> engine
	.
	.
	SmallX> dos
	DOS> edit example.rul
	.
	edit commands
	.
	DOS> (return)
	SmallX> clear rules
	SmallX> rem example
	.
	.
	---------------------------------------------------------------------

									40

	7.19 CSAVE

	The CSAVE command is used to produce a partially compiled form
	of the rule program on a disk file. The file produced by CSAVE
	can then be reloaded with the CLOAD command.

	CSAVE is provided for 2 reasons. First, CSAVEd files cannot
	be displayed - that is the contents of a CSAVEd file cannot be 
	deciphered when listing the file or editing the file. This allows
	a rule program to be developed and distributed using the small-X
	language while keeping the actual rule content "private".

	The second reason for using the CSAVE command is that rule programs
	load faster when they are CSAVEd. If a rule program consists of
	several rule program files, CSAVEing and then CLOADing can reduce
	the total amount of time required to run the complete rule program.

	To CSAVE a rule program, enter the command,

		CSAVE filename option

	where filename is a 1 to 8 character name which will be used
	to name the file used to hold the CSAVEed rule program. The
	characters ".CRL" will be appended to the name you specify
	to make up the full file name. If a file already exists with the
	same name its contents will be lost so select a name carefully.

	You must specify LOCK or NOLOCK as part of the CSAVE command.
	If you do not you will be prompted for the option. LOCK causes
	a CSAVED file to be compiled so that it cannot be viewed.

	When a CSAVEd file is saved with the lock option and then
	reloaded with the CLOAD command, certain small-X commands will
	be disabled. The commands that will be disabled are LIST, TRACE,
	MEMORIZE, STEP, DELETE, and SHOW. A user will not be able to
	examine the rule program because these commands will be
	inoperative. If the rules contained in a rule program are
	proprietary then the lock option will protect their 
	proprietary nature. The lock will not be released until a 
	CLEAR RULES command has been entered or until a file is CLOADed
	without a lock.

									41


	An example of the CSAVE command is shown below.

	With NOLOCK Option
	---------------------------------------------------------------------
	SmallX> CSAVE myrules NOLOCK
	** compiling myrules **
	** writing myrules.crl **

	SmallX>
	---------------------------------------------------------------------

	With lock Option
	---------------------------------------------------------------------
	SmallX> CSAVE special LOCK
	** compiling special **
	** writing special.crl **

	SmallX>
	---------------------------------------------------------------------


									42

	7.20 CLOAD


	The CLOAD command is used to load a previously CSAVEd file.
	This command can only be used with files created by the CSAVE
	command. MEMORIZE type files cannot be loaded with this command.

	In order to load a CSAVEd file, enter the command

			CLOAD filename

	where filename is a 1 to 8 character file name. The characters
	".CRL" will be appended to the name you specify to make the
	full file name. Only files whose name ends in ".CRL" can be 
	CLOADed. An example of the use of the CLOAD command follows:


	---------------------------------------------------------------------
	SmallX> CLOAD myrules
	** loading rules **
	** reading myrules.crl **

	SmallX>
	---------------------------------------------------------------------

	If a rule program was created with the CSAVE LOCK command, you will
	not be able to list or modify any of the rules in the rule program.

									43


	7.21 QUIET/NOQUIET


	QUIET and NOQUIET are used to control whether or not small-X displays
	commands, rules, actions, and data coming from a file. For
	instance, if you use the command REMEMBER to read a rule program into
	rule memory, the rules that are being read will be displayed by
	small-X as they are being read. Sometimes it is desireable to not
	display the rules. The QUIET command "shuts off" the display of
	rules, STM commands, and script file commands(Appendix F).


	The NOQUIET command does the opposite of the QUIET command. If
	you have "shut off" the display of rules or commands as they are
	being read from a file, you can "turn on" this display with the
	NOQUIET command.

	When you enter QUIET or NOQUIET, small-X responds with a 
	message letting you know that it will not be displaying rules
	and commands(running quietly) or that it will be displaying
	rules and commands(input echoed). These commands only have
	an effect on rules and commands coming from a file and have no 
	effect on rules and commands coming from the keyboard. Examples
	of their use are shown below.


	---------------------------------------------------------------------
	SmallX> QUIET
	** running quietly **
	SmallX>
	---------------------------------------------------------------------

	---------------------------------------------------------------------
	SmallX> NOQUIET
	** input echoed **
	SmallX>
	---------------------------------------------------------------------

									44

	7.22 UPPER and LOWER


	small-X accepts both upper and lower case keyboard input. This means
	for instance that the word cat is not the same as the word CAT to 
	small-X. Sometimes it is undesireable to have upper and lower case
	distinguished. For this reason the UPPER and LOWER commands are part
	of the small-X interpreter.

	The UPPER command places small-X in upper case only mode. This means
	that anything that is entered from the keyboard will be converted
	to upper case.

	LOWER makes small-X distinguish between upper and lower case.

	When you first start small-X from DOS, LOWER is in effect. It 
	remains this way until you change it with the UPPER command.

	Examples

	---------------------------------------------------------------------
	SmallX> LOWER
	SmallX>
	---------------------------------------------------------------------

	---------------------------------------------------------------------
	SmallX> UPPER
	SmallX>
	---------------------------------------------------------------------

									45

	7.23 FORWARD and BACKWARD


	FORWARD and BACKWARD let you set the mode of operation of the
	inference engine. The modes that you can select from are either
	forward chaining mode or backward chaining mode.

	To set forward chaining mode enter the command FORWARD(or F).
	To set backward chaining mode enter the command BACKWARD(or B).

	The setting remains in effect until you change it with another
	FORWARD or BACKWARD command.

	When you first enter small-X from DOS forward chaining is
	in effect.

	Examples

	---------------------------------------------------------------------
	SmallX> FORWARD
	** forward chaining **
	SmallX>
	---------------------------------------------------------------------

	---------------------------------------------------------------------
	SmallX> BACKWARD
	** backward chaining **
	SmallX>
	---------------------------------------------------------------------


									46

	7.24 GOAL


	When small-X is in backward chaining mode(see section 7.23 and 
	5), a goal must be set. The goal represents the problem to be
	solved. In small-X a goal name is the name of a variable that
	will be given a value as a result of the rule program running.

	For instance, if background chaining rules make diagnosis about
	car problems then the diagnosis could be contained in a variable
	called car_diagnosis. In this case the goal would be #car_diagnosis.

	To specify a goal you enter the command GOAL(or G) followed by the
	name of the variable representing the goal. When entering the goal
	name you omit the # from the variable name.

	Example

	---------------------------------------------------------------------
	SmallX> GOAL car_diagnosis
	SmallX>
	---------------------------------------------------------------------

									47

	7.25 STATUS


	The STATUS command lets you examine the present state of small-X.
	The state consists of how much storage is available, the number
	of rules in memory, the names of any open files, and any states
	or settings that you have set while using small-X. Settings 
	include running quietly vs. echoing input, forward vs. backward
	chaining, the current GOAL, the current OBJECT, single step on
	or off, trace on or off, and lower vs. upper case. By using
	STATUS you will be able to see all of this data. An example
	of the STATUS command and its output is shown below.

	Example


	---------------------------------------------------------------------
	SmallX> STATUS

	Small-X Status
	
	single step off
	trace off
	input echoed
	upper case only
	forward chaining
	no current object
	no goal defined
	10 rules
	total memory available 53566 bytes
	can hold 243 rules

	File Mode Index File Symbol

	no open files

	SmallX>
	---------------------------------------------------------------------

									48

	8 small-X Data Objects


	All computer languages manipulate data. In order to manipulate
	data in small-X you must know the kinds of data that can be
	manipulated. This part of the manual describes the kinds of
	data objects that can be manipulated in small-X.

	Integers

	small-X integers consist of an optional sign(+ or -) followed by a
	sequence of digits. An integer represents a whole number. An integer 
	constant must be less than 32768 and greater than -32768.

	Examples

	12
	-143
	32767


	Reals

	Real numbers in small-X consist of an integer part, followed
	by a decimal point, followed by a fractional part, followed
	by an optional exponention part.  The exponential part consists
	of an e or E followed by a sign(+ or -) followed by a 1 or 2
	digit exponent. The fractional part of a real number is a
	sequence of digits.

	Examples

	0.23
	25.765
	-44.6e+3


	Strings


	A string is a sequence of any characters. In rules and STM commands
	strings must start and end with a '. The null string represented by
	'' is also a valid string.

	Examples

	'this is a string'
	''

									49

	Symbols

	A symbol in small-X is a kind of string. It cannot have any blanks.
	It does not begin and end with a '.

	Examples

	symbol


	Lists

	small-X lists begin with a [ and end with a ]. A list can contain
	strings, integers, or reals, or any combination of these. The null
	list, represented by [] is also a valid list.

	Examples

	[1 2 3]
	[a b c d]
	[3.2 4.5 6.7e3]
	[1 able 2 baker 3 omega]
	['one string' 'two string']
	[]


	Variables

	A variable in small-X is a data object which has a name. A variable
	can represent any kind of data object. Variable names consist of
	a # followed by a letter followed by any sequence of letters or
	digits and the underscore. Special small-X actions manipulate 
	variables. These will be described in the section about small-X 
	actions.


	Examples

	#v
	#var1
	#cat102

	When choosing a variable name it is important to remember two things.
	First, choose variable names that are descriptive so that you will
	know what they represent. This will make your rule programs easier
	to read. Second, it is important to remember that small-X distinguishes 
	between upper and lower case. The variables #a and #A are considered 
	two different variables in small-X unless you use the UPPER command. 
	Use upper or lower case consistently so that you will not mistakenly 
	refer to a variable by an incorrect name.

									50

	Current Object


	A special object, signified by an exclamation point(!) called
	the current object, can be used in certain actions.

	STM memory holds data objects of the kinds described above. As
	rules are processed STM is continually searched for specific data
	objects(those specified in a rule's condition). When a data object
	is found in STM that satisfies the conditions in a rule it is called
	the current object. It can be retrieved or accessed by using the
	current object symbol !.

	The current object is especially useful when matching against
	special lists called wild card lists. These lists contain wild
	card markers(?) as place holders. The list [? 2 3] will match the
	list [1 2 3] or the list [david 2 3]. When a list in STM matches
	a wildcard list, the list in STM which matches becomes the current
	object. If [david 2 3] matched [? 2 3] the [david 2 3] list is
	assigned to !. ! can be assigned to a variable and used in other
	rules and actions.


									51
	9 small-X Actions


	When a rule is activated the rule carries out actions specified
	by the small-X programmer. There are 5 kinds of actions that
	can be specified in a rule. These are,


			[1] change STM
			[2] get data
			[3] display data
			[4] stop the inference engine
			[5] miscellaneous

	Actions are not only specified in rules but may also be
	carried out independently of small-X rules. When you enter
	the STM command, and the STM marker is displayed OR when
	you activate single step mode, any small-X action can be
	entered. The small-X interpreter will carry out this action
	immediately when entered at an STM marker.  This section
	reviews all of the STM actions in detail. STM actions are 
	summarized in the table below.

	Action		Purpose				Type

	ADD		adds an object to STM		change STM
	REMOVE		removes an object from STM	change STM
	READ		reads data into STM		get data
	WRITE		writes data from STM		display data
	COMPUTE		perform STM calculations	change STM
	BIND		give a variable a value		change STM
	UNBIND		remove a variable value		change STM
	HALT		halt the inference engine	stop engine
	RUN		runs an external DOS program	miscellaneous
	RESET		resets a rule so it can be	miscellaneous
			used again                  
	OPEN		opens an external file          miscellaneous
	CLOSE		closes an external file         miscellaneous
	FIRE		forces a rule's actions to	miscellaneous
			run
	RESTRICT	restrict the values that	miscellaneous
			variables can be assigned
	MODIFY		modify a rule's goodness value	miscellaneous

									52


	9.1 ADD


	The ADD action is used to place data objects in STM. Any
	kind of data object(integers, real numbers, strings, lists,
	symbols, and variables) can be placed in STM with this
	action. If you ADD a data object which is not a variable
	and which is already in STM, it will not be added again.
	If you ADD a variable to STM and a variable of the same
	name already exists in STM, the new variable will replace the
	old variable. The new variable has no value since ADD cannot
	give values to variables.

	Syntax:  ADD <operand>

	<operand> can be an: 	integer
				real
				string
				symbol
				list
				variable

	Examples

	ADD 12
	ADD 3.141e+3
	ADD 'this is a string'
	ADD asymbol
	ADD [1 2 3 4]
	ADD #var1

									53

	9.2 REMOVE


	The REMOVE action does the opposite of the ADD action. This
	action removes an object from STM. Any kind of data object can
	be removed from STM providing it is present in STM.


	Syntax: REMOVE <operand>

	<operand> can be an: 	integer
				real
				string
				symbol
				list
				variable

	Examples

	REMOVE 32
	REMOVE -.9011
	REMOVE 'the cat likes the dog'
	REMOVE symbol
	REMOVE [a b c]
	REMOVE #var1

									54

	9.3 READ

	READ is used to get data from the keyboard or from an external 
	file. The READ action can display an optional prompt and request 
	a specific data object. Once a data object is read it is assigned 
	to a variable and added to STM.


	To read data from the keyboard the following syntax is used:

	Syntax: READ <type> <prompt string> <variable>

	<type> can be: INT
		       FLOAT
		       STRING
		       LIST

	<type> is optional

	<prompt string> is a string that will be displayed when
	small-X requests the data. <prompt string> is optional.

	<variable> is the variable name where the read data object
	will be stored.

	Examples

	READ INT 'Please enter disease type' #dtype
	READ #var1


	To read data from an external file the following syntax is used:

	Syntax: READ FILE <file name> <variable>

	<file name> is the name of a previously opened file. The file
	must be opened for INPUT.

	<variable> is the variable name where the read data object
	will be stored.

	Example

	READ FILE infile #avar

									55

	Reading Files Not Created By small-X Programs

	If a small-X program is to read an external file created by a 
	program other than small-X you must keep in mind the following:

	1) The READ action will only recognize integers, reals, symbols,
	   lists and strings according to the descriptions in this manual
	   (Page 48-49).

	2) Each data object must be separated by at least 1 blank character.

	3) Lines can be terminated by a new line character(return).

									56

	9.4 WRITE


	WRITE is used to display data objects on the PC screen or
	write data objects to an external file. WRITE also can be used 
	to clear the PC screen, advance a line, move the cursor to a 
	particular spot on the screen, or draw a box on the screen.

	If write is given a data object as its operand then write
	will display that data object.

	If write is given a variable as its operand then write will
	display the variables data value.

	If write is given a special keyword then write will carry
	out the keyword function display.

	Each of the following forms of the WRITE action are used to display
	data objects or perform special functions on the PC screen.

	Syntax: WRITE <operand>
	
	<operand> can be an: 	integer
				real
				string
				symbol
				list
				variable
				! (current object)


	Syntax: WRITE NEW-LINE
	(skips a line on the PC screen)

	Syntax: WRITE CLEAR
	(clears the PC screen)

	Syntax: WRITE MOVE <row> <column>
	(move the cursor to the specified row and column)

	<row> is an integer between 1 and 24
	<column> is an integer between 1 and 80

	Syntax: WRITE BOX <row> <column> <width> <height>
	(draws a box with its left hand corner positioned at
	 row and column of the specified width and height)

	<row> is an integer between 1 and 24
	<column> is an integer between 1 and 80
	<width> is an integer such that column+width < 80
	<height> is an integer such that row+height < 24

									57


	Examples

	WRITE 7
	WRITE 3.4
	WRITE 'a string'
	WRITE symbol
	WRITE [1 2 3]
	WRITE #var1
	WRITE CLEAR
	WRITE NEW-LINE
	WRITE MOVE 10 15
	WRITE BOX 1 1 80 24
	WRITE !


	The other form of the WRITE action is to allow data objects to
	be written to an external file. The syntax for this kind of WRITE
	action follows:

	Syntax: WRITE FILE <file name> <operand>

	<file name> is the name of a file previously opened for OUTPUT.

	<operand> can be an: 	integer
				real
				string
				symbol
				list
				variable
				! (current object)
				NEW-LINE

	NEW-LINE will cause the WRITE action to output a new line character
	to the external file.

	Examples

	WRITE FILE outfile #x
	WRITE FILE newf NEW-LINE

									58

	9.5 COMPUTE


	The COMPUTE action is used to do simple calculations and
	manipulations of data objects. There are 5 kinds of operations
	that a COMPUTE action can do.

			[1] numeric scalar/scalar
			[2] string scalar/scalar
			[3] scalar/list
			[4] list
			[5] list/list

	Numeric Scalar/Scalar

	This type of operation involves operands that are single-valued
	(integer, real, or string) and numeric(integer and real). The
	action cannot mix integer with real and vice versa.


	Syntax:  COMPUTE <variable> <- <operand-1> <operator> <operand-2>

	<variable> is the name of the variable that will receive the result
	of the computation.

	<operand-1> and <operand-2> are both integer or both real valued
	constants or variables.

	<operator> can be +, -, *, or /.

	Examples

	COMPUTE #var <- 4 + 9
	COMPUTE #newval <- #var * 1
	COMPUTE #avalue <- #a - #b
	COMPUTE #sum <- 4.5 / 7.32

									59


	String Scalar/Scalar

	String scalar/scalar computations involved string constants
	and single-valued string variables. String compute actions
	are restricted to string operands. The only operation valid
	for strings is string concatenation.

	Syntax: COMPUTE <variable> <- <string operand 1> + <string operand 2>

	<variable> is the name of the variable that will receive the result
	of the computation.

	<string operand 1> and <string operand 2> are string constants or
	variables.

	The result of this computation will be to take <string operand 1>
	and append <string operand 2> to the end of <string operand 1>. The
	resulting string will be the combination of both string operands.


	Examples


	COMPUTE #con <- 'abc' + 'def'		Result: #con <- 'abcdef'
	COMPUTE #a <- #b + 'xxx'

									60

	Scalar/List

	Scalar/List computations involve the concatenation of single
	values operands to lists. Two operations are provided for the
	purpose.

	The + operation appends scalar operands to the beginning or end
	of a list.

	The - operation deletes scalar operands from the list.

	Syntax: COMPUTE <variable> <- <operand 1> <operator> <operand 2>

	<variable> is the name of the variable that will receive the result
	of the scalar/list computation.

	<operand 1> is a scalar or a list.

	if <operand 1> is a scalar then <operand 2> is a list otherwise
	<operand 2> is a scalar.

	<operator> is a + or a -.


	Examples


	COMPUTE #v <- 1 + [2 3]			Result #v <- [1 2 3]
	COMPUTE #a <- [a b c] - b		Result #a <- [a c]
	COMPUTE #x <- #a + #b

									61

	List


	List computations allow lists to be decomposed into scalars.
	The 2 list operations are . and ...

	The . operation removes the first element from a list and returns
	the first element as its result.

	The ... operation removes the first element from a list and
	returns the remainder of the list as its result.

	Syntax: COMPUTE <variable> <- <operator> <list operand>

	<variable> is the name of the variable that will receive the
	result of the computation

	<operator> is . or ...

	<list operand> is a list or a list valued variable

	Examples:

	COMPUTE #v <- .[1 3 4]			Result: #v <- 1
	COMPUTE #v <- ...[1 3 4]			#v <- [3 4]
	COMPUTE #v <- ...#v

									62

	List/List

	List/List computations include list concatenation and list
	element deletion. The operators are + and - respectively.

	Syntax: COMPUTE <variable><-<list operand 1> <operator> <list operand 2>

	<variable> is the name of the variable that will receive the
	list result of the computation

	<list operand 1> and <list operand 2> are list constants or list
	valued variables.

	<operator> is either a + or -

	Examples

	COMPUTE #v <- [1 2 3] + [4 5 6]		Result: #v <- [1 2 3 4 5 6]
	COMPUTE #l <- [a b c d e f] - [e]	Result: #v <- [a b c d f]
	COMPUTE #m <- #a - #b


									63

	9.6 BIND

	The BIND action is another way to give a variable a value.
	With BIND you can assign any data object to a variable or
	assign a variable to a variable.

	Syntax:  BIND <variable> <operand>

	<variable> is the name of the variable that will be bound
	to the data object.

	<operand> is the data object used for binding to the variable.

	<operand> can be an: 	integer
				real
				string
				symbol
				list
				variable
				! (current object)

	Examples

	BIND #var1 -10
	BIND #var1 2.7e26
	BIND #xyz001 'abmqrs'
	BIND #cat true
	BIND #alist [2 3 4]
	BIND #var1 #var2
	BIND #x !

									64

	9.7 UNBIND


	The UNBIND action removes the value bound to a variable. This
	leaves the variable in STM but gives it an unknown value. If a
	variable is already unbound, this action does not affect the
	variable in STM - it remains unbound.

	Syntax: UNBIND <variable>

	<variable> is the name of the variable whose value is to be
	unbound from it.


	Examples

	UNBIND #var1

									65

	9.8 HALT


	In STM the halt action ends the STM session. As a rule action,
	halt stops the inference engine. HALT has no operands.


	Examples


	HALT

									66

	9.9 FIRE


	The FIRE action allows you to activate the actions in a rule
	outside of the inference engine. The rule whose actions will
	be affected by the FIRE action will not be marked as FIRED so
	that the inference engine may activate the actions as it normally
	would.

	Syntax: FIRE <rule name>

	<rule name> is the name of the rule whose actions are to be
	activated.

	Examples

	FIRE r01
	FIRE diagnosisRule

									67

	9.10 RESET


	Once a rule has been fired it is marked as FIRED. In subsequent
	cycles of the inference engine a FIRED rule will be ingnored. The
	RESET action allows you to remove the mark indicating the rule
	has fired. This makes the rule, once again, a candidate for firing.

	Syntax: RESET <rule name>

	<rule name> is the name of the rule whose FIRED mark is to be
	removed.

	Examples

	RESET r07
	RESET xxyy	

									68
	9.11 RUN


	The RUN action is used to execute programs external to small-X.
	When a RUN action is performed by the inference engine control
	is relinquished by small-X to the external program. The external
	program carries out its processing and when it terminates the 
	small-X inference engine regains control and continues scanning
	and activating rules.

	This action can be used to execute a program which performs complex
	or specialized calculations out of the scope of small-X.

	Syntax: RUN <path name>

	<path name> is a standard DOS file name enclosed in single quotes
	(').

	Example

	RUN 'special'

									69

	9.12 OPEN


	OPEN allows you to open or ready an external file. An external
	file can be used to store rule program results, obtain rule
	parameters, and also serve as a general means of inter-program
	communication(small-X to other DOS programs and vice versa).

	An external file can be open for INPUT or OUTPUT.

	If an external program is opened for INPUT then the data in that
	file can be read into small-X variables.

	If an external file is opened for OUTPUT, data in small-X 
	variables or any small-X data object can be written to the file.

	Up to 10 external files can be opened simultaneously.

	Syntax: OPEN <path name> AS <file name> FOR <file mode>

	<path name> is the full DOS file name of the external file to be
	opened enclosed in single quotes(').

	<file name> is a small-X symbol(up to 40 characters) that will be
	used in small-X programs to refer to the external file. This is
	the <file name> used in READ FILE and WRITE FILE actions.

	<file mode> can be INPUT or OUTPUT.

	If an external file is opened for input, the file must exist on
	the specified disk, in the specified directory.

	If an external file is opened for output, a new file is created.
	If a file with the same name exists, it is overwritten(its contents
	will be lost).

	Examples

	OPEN 'C:\rules\data\xfile.dat' AS infile for INPUT
	OPEN 'X' AS X FOR OUTPUT

									70
	9.13 CLOSE

	CLOSE is the action used to release an external file used
	in a small-X rule program.

	When an external file is closed it can no longer be accessed by
	rule program.

	Syntax: CLOSE <file name>

	<file name> is the name of the file to be closed. The file
	must be one known to the rule program(opened by the program) and
	currently in an open state.

	Examples

	CLOSE fileone
	CLOSE x

									71


	9.14 MODIFY
 

	The MODIFY action allows you to alter the value assigned to
	each rule called the rule value. This value plays a part in
	which rule will be selected during each iteration of the 
	inference engine. Remember, if more than one rule is eligible
	in an iteration, one rule will be selected to be fired if,

		a) it has the highest rule value of 
		   all eligible rules,

		or

		b) it is the first rules of all those 
	           that are eligible.


	Through the MODIFY action you can make one rule more or less
	eligible than another rule by changing its rule value while
	the inference engine is running. You might want to do so if,
	for instance, as data or evidence is accumulated for a particular
	situation, certain rules are more appropriate for the situation
	and others are less appropriate. The MODIFY action allows you to
	have additional control over which rules will fire as the inference
	engine executes rules.

	Syntax:	MODIFY <rule name> <modify operator > <rule value>

	<rule name> is the name of a rule currently contained in rule
	memory.

	<modify operator> is optional and can be either a + or -.

	If the modify operator is a + then the value that follows it
	is added to the current rule value and this new value becomes
	the rule value.

	If the modify operator is a - then the value that follows it
	is subtracted from the current rule value and this new value
	becomes the rule value.

	If there is no modify operator then the rule value in the action
	becomes the new rule value.

	<rule value> is a real number that will be assigned to the specified
	rule as its rule value.


	Examples


	MODIFY r01 5.0
	MODIFY gasrule 1.0
	MODIFY diagnosis + 2.0
	MODIFY findanswer - 1.0

									72

	9.15 RESTRICT


	Sometimes you might find it desireable to restrict the values
	that variables can take on. Usually there are no restrictions
	in Small-X so a variable having an integer value can be 
	reassigned a string value, and reassigned again in the same
	rules program to a list value. The RESTRICT action is used
	to limit the values that a variable can have when its value is
	assigned with a READ action.

	For instance suppose you wanted to restrict the variable whose 
	name is #choice to the values 1,2, and 3. To do this you would
	use the action shown below.

			RESTRICT #choice TO [1 2 3]

	This action would limit the values that #choice can have to 1,2,
	or 3.

	Restrictions can also be changed at any time by simply entering
	another RESTRICT action.

	Restrictions can be eliminated for a variable by entering a 
	RESTRICT action with an empty list.

	Syntax:	RESTRICT <variable name> TO <restriction list>

	<variable name> is the name of the variable whose values will be
	restricted.

	<restriction list> is a small-X list containing the allowed values
	for the specified variable.

	Examples

	RESTRICT #choice TO [1 2 3]
	RESTRICT #choice TO []

	


									73

	10 small-X Rules


	Programs written for small-X are written in the form of small-X
	rules. A small-X rule has 2 main parts. The first part contains
	the conditions of the rule and the second part contains the
	actions of the rule. The kinds of actions that small-X provides
	have been described in the section about small-X actions. Here
	we concentrate on the details of rules and rule conditions. 


	Rule Structure

	A small-X rule has the following structure:

	<rule name> IF <condition> <rule value> THEN <actions>

	Rule Names

	Whether or not you specify a name every rule is assigned a name. One 
	of the reasons for naming rules in small-X is so that you can delete 
	a rule from rule memory. By giving all of the rules in rule memory 
	names you can refer to a specific rule by its name.

	Another reason for giving names to rules is so that rules can
	be identified when they are activated by the inference engine.
	Remember that the name of the rule is displayed in trace mode of
	the inference engine. The name that is displayed is that name
	assigned or given to the rule.

	<rule name> is optional - you don't have to give a rule a name.
	If you leave the rule name out, the interpreter will assign a 
	name to the rule. This name will begin with an r and have a unique
	number following the r. The numbers are assigned in order from 1
	as new rules are entered into the small-X interpreter.

	If you do want to give a rule a name it must be enclosed in
	brackets []. The name of a rule must also begin with a letter
	of the alphabet. Any letter or digit may follow the first letter
	of the name. Some rule name examples are shown below.

	Examples

	[rule1]
	[outOfGas]
	[classifyAnimal]

									74

	The rule name always comes before the word IF in the rule.


	IF


	The word IF follows the optional rule name or starts the rule.
	IF must be present in all small-X rules. It marks the beginning
	of the small-X condition.


	Condition
	
	The condition of a rule contains the test that is carried out on 
	STM. The condition can be simple or very complex. Conditions can be
	made up of a single test or many tests.


	Kinds of Tests


	There are 2 kinds of tests that you can carry out in a small-X 
	condition. You can check to see if a data object is in STM or
	you can test a variable in STM. A variable test could be an
	arithmetic test(=, <=, >, etc.), a matching test, [1 2 3] = [1 2 4],
	or a membership test, 3 in [2 3 5 7].


	IN-MEMORY Tests

	With an IN-MEMORY test you can check to see if a data object is
	present in STM. The IN-MEMORY test will be true if the object is
	present and false otherwise. 

	The syntax of an IN-MEMORY test is,

	IN-MEMORY(<operand>)

	where <operand> can be an integer,
				  real,
				  string,
				  symbol,
				  variable,
				  list, or
				  choice.

									75


	Examples

	IN-MEMORY(1)
	IN-MEMORY(12.3)
	IN-MEMORY('a string')
	IN-MEMORY(cat)
	IN-MEMORY(#sum)
	IN-MEMORY([2 4 6])

	A rule containing an IN-MEMORY test might be,

	IF IN-MEMORY(cat) THEN BIND #eats mice


	This rule tests to see if the symbol 'cat' is in STM. If it
	is then the variable eats(all variables begin with a #) is given
	the value mice when this rule fires.

	It is also possible to see if an object is not in STM. This is
	done with the special word NOT. This word can preceed any test.
	When this word is present the test must not be true in order for
	the rule to fire. Look at the following example,

	IF NOT IN-MEMORY(CLOUDS) THEN WRITE 'Its not going to rain'

	This rule says that if the symbol CLOUDS is not found in STM then
	display the message "Its not going to rain".

	A special kind of operand can also be used in an IN-MEMORY test.
	This kind of operand is called a choice. A choice is always 
	enclosed in braces. The braces can enclose any list of data
	objects. You can use choices to check STM for a number of data
	objects. For instance, the following rule,

	IF IN-MEMORY({ dog cat frog }) THEN BIND #pet small

	binds the variable pet to small if dog or cat or frog is found
	in STM. 


									76

	Variable Tests

	A variable test checks the value of a variable. The syntax of
	a variable test is,

	<variable> <operator> <operand>

	<variable> is the name of the variable to be tested.

	<operator> is one of the following operators:

			=
			<
			<=
			>
			>=
			<>
			IN

	<operand> is one of the following:

			integer
			real
			string
			symbol
			list
			choice
			variable

	Examples

		#v < 7
		#cat = #dog
		#m in [1 2 3]
		#q in {[symbol1 symbol2] x y z}
		#empty = true

	A rule with a variable test would look like,

	IF #v < 7 THEN WRITE 'Blood pressure too low'

									77


	You can use NOT for a variable test also. If you want to test
	whether a condition is not true, simply preceed the test with
	the word NOT.

	Example

	IF NOT #v < 7 THEN WRITE 'Blood pressure okay'


	Matching Lists


	One of the operand types you can use in a test is a list.
	Suppose a variable #v has the list value [1 2 3]. You could
	construct a test such as #v = [1 2 3]. This test would be
	true and if the condition consisted of only this test
	the rule could be fired.

	Suppose though, you were only interested in testing whether
	the first element of the list was a 1. If the first element
	of the list valued variable is a 1 then the test should succeed.
	This kind of test can be constructed in small-X by using a 
	special list member - the question mark(?).

	A question mark in a list is a place holder - a wild card.
	When used in a test, the question mark will match any list
	element in that position. To check whether the first element
	of a list is a 1, the list [1 ? ?] would be used in the
	test, i.e. #v = [1 ? ?]. This test would succeed for any 
	list whose first element is a 1.


	Matching Strings


	Another kind of data you can use in a test are strings. You
	can compare strings, testing to see if two strings are equal,
	not equal, or if one string is smaller or larger than another.
	In addition you can test strings to see if they match other
	special strings called patterns.

	A pattern is a special string that contains one or more asterisks(*)
	and/or question marks(?). The * and ? have a special meaning when
	used in strings for testing.

	If a ? appears in a pattern string, the ? will match any character
	that appears in the same position in the comparison string. An *
	will match zero or more characters in the comparison string. Some
	examples are shown below.


	Comparison String	Pattern String		Match

	abc			a*c			yes
	abbbbc			a*c			yes
	abbbbc			a?c			no
	the large dog		the * dog		yes

									78


	Pattern strings containing * and ? can only be used on the
	right of the comparison operator in a test and should only
	be used with = or <>.



	Complex Tests


	So far we have only shown conditions made up of a single 
	test. It is possible to combine tests into more complex tests
	with the connectives AND and OR.

	Any test can be connnected to another test with an AND or an
	OR.

	For instance suppose you wanted to check if a variable was
	present in STM and then you wanted to check the value of that
	variable. You could use the AND connective for this.

	Example

	IF IN-MEMORY(#empty) AND #empty = yes THEN WRITE 'Tank is empty'

	OR can be used in a similar way to combine tests.

	You can combine an unlimited number of tests to create a complex
	condition using AND or OR.

									79

	Rule Value


	The rule value of a rule is another optional part of the rule. If
	you leave this value out it will be automatically assigned to the
	rule.

	The rule value of a rule is used to control the rule that is
	fired when 2 or more rules can be fired in a cycle of the
	inference engine.

	The rule with the higher rule value will always be selected to be
	fired by the engine.

	The syntax for a rule value is:
	C[<real number>]

	Examples

	C[.1]
	C[1.000000]
	C[1.5]

									80

	THEN

	THEN marks the beginning of the actions in a rule. Every rule
	must have a THEN and it must be followed by one or more actions.


	Actions

	The actions that can appear in a rule are the same as the commands
	that can be used in STM. Any of these can be used as part of the
	actions part of a rule.

	The actions part of a rule can consist of 1 or more actions. If
	more than 1 action is specified for a rule the actions must be
	enclosed in braces {}.

	Here is a rule from the car diagnosis expert that is contained in
	appendix B that contains multiple actions.

	IF #charged = no THEN
	{
		WRITE 'You need to charge battery -- $5.'
		WRITE NEW-LINE
	}

                                                                                                            