A Model of Addition 
The model of categorisation developed earlier is not particular plausible from a psychological perspective. It was developed primarily to demonstrate how to use some of the basic features. In this section we develop a model of multicolumn addition. The model still leaves much to be desired from a psychological perspective, but it does have some psychological virtues. It also illustrates a number of further aspects of the COGENT modelling environment.
The basic situation addressed by the model is subject performance when presented visually with an addition problem. The addition problem is assumed to be presented on paper, and the subject is able to use the paper as an "external buffer" onto which intermediate results may be writen. The model therfore includes a buffer corresponding to the paper.
We are not interested in modelling the processes of reading or comprehending the problem, or of those of writing the answer of intermediate results. We thus include a single input/output process in order to perform these functions.
The input/output process can read and write to the paper. Its rules are triggered by messages from a box simulating the addition process. This box in addition makes use of a shortterm storage facility (working memory) for storing information on current goals/subgoals and partial results. The complete diagram is as below:
Exercise: Create a new research programme and draw the diagram as given above.
We begin fleshing out the model by specifying the initial contents of the paper. In order to do this, we must represent the numbers to be added in a uniform/consistent format. Almost any consistent representation would be adequate, but for readability we will represent each number in the addition problem by a term of the form row(N) where N is the number. Thus, we might start with the following intial contents:
Element: Number to add Element: Number to add Element: Number to add Element: Number to add Element: And one more very big number! 
This represents the following addition problem:
4  5  +  
1  3  9  
1  4  
9  8  
2  0  3  9  1  8 
For the present purposes we are representing only the numbers, not their positions in the sum.
Input/Output mediates between the model of the subject and the paper. As such, it has two distinct functions: 1) it must "copy" relevant bits of the addition problem into the subject's Working Memory; and 2) it must "write" column totals and carry information onto the paper. We'll use separate sets of rules for the two functions. In order to write the rules for either function we must settle on a representation for information in Working Memory.
We'll begin with the process of reading a column of digits into Working Memory, and assume that this task is triggered by a message sent to Input/Output. [This is not the only option. The process could, for example, be triggered by the appearence of an appropriate element in Working Memory.]
Rule (unrefracted): Read a column of digits into working memory
Rule (unrefracted): Note when there are no more columns to read
Rule (unrefracted): Read any digits carried over from addition of previous columns
Condition Definition: get_digit_in_nth_position/3: given a number like 382 and a position like 2, extract the 8
Condition Definition: get_units_digit/2: Get the leftmost digit in a number

Now consider the process of writing the result of adding one column to Paper. There are two separate tasks: 1) writing the new digit; and 2) annoting the next column with any value to be carried. Again, both of these require consideration of representational issues.
The representation of carry information was resolved above, so the write_carry operation is straightfoward. Assuming that the rule is triggered by a message of the form write_carry(C, N), where C is the amount of the carry and N is the current column, we have:
Rule (unrefracted): If we need to carry to the next column, write the carry on the paper TRIGGER: write_carry(C, N)

Note that we only write the carry if it is nonzero, and it can't be negative, so in fact we only write the carry if it is greater than zero. The condition C>0 is obtained by following the pulldown menus along the path Add Condition/term comparison/arithmetic/is greater than. We also have to be sure that we write the carry in the appropriate column, i.e. the column to the left of the current column. The condition Column is (N) + (1) is obtained by following the pulldown menus along the path Add Condition/arithmetic/plus.
We shall represent the answer as an integer embedded with the Prolog functor answer, e.g., answer(243). This is a very readable representation, but it makes the rules a little complex. Basically, when we are part way through the problem we will have an answer such as answer(43) (possible representing the sum of the first two columns). On learning that the sum of the third column comes to 2, this must be changed to answer(243). An appropriate rule is:
Rule (unrefracted): Write an answer for a column onto the paper (incorporating existing partial answer)

This rule is triggered by a message of the form write_sum(S, N) where S is the (units digit of the) sum of the digits in the N column. If N is 3, then S represents 100s. If N is 4, then S represents 1000s. The use of the power function works out the correct multiplier for S. Once multiplied and added to the previous (partial) answer, the new answer can be written in place of the old.
This rule is fine provided we have a partial answer on the paper. We also need the following rule to handle the case were we don't have an existing answer:
Rule (unrefracted): Write an answer for a column onto the paper (no existing partial answer)

These rules are triggered by the same message pattern, but both rules should not fire at the same time because their conditions are mutually exclusive.
Exercise: Enter these rules and condition definitions, and an appropriate description, into Input/Output.
Short term store for goals and partial results
Class: Buffer/Propositional
Properties:
Initialise:  Each Trial  
Decay:  None  
Decay Constant:  20  
Limited Capacity:  No  
Capacity:  7  
On Excess:  Random  
Duplicates:  Yes  
Access:  Random 
Element: We know that our initial goal is to add some numbers 
69: goals([process_column(8), next_column(8)]). 65: last_column.
Rule (refracted): Decompose add goal
Rule (refracted): Decompose process_column goal
Rule (refracted): Stop when there are no more columns
Rule (refracted): Move to the next column
Rule (refracted): Read a column and initialise the sum
Rule (refracted): read_column is complete
Rule (unrefracted): Add the next digit in the current column
Rule (refracted): We've finished adding ...
Rule (refracted): Split the answer into tens and units
Condition Definition: tens_and_units/3: Split an answer into tens and units
Rule (refracted): Write the answer (units and carry) on the paper via Input/Output
