<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0">


<category>
<pattern>AIMLEQUAL * EQUAL *</pattern>
<template>
<srai>LEARNEQUAL <star/></srai>
<srai><star/> TESTEQUAL <star index="2"/></srai>
</template>
</category>

<category>
<pattern>LEARNEQUAL *</pattern>
<template>
<!-- Learn <star/> = <star/>. -->
<learn>
</learn>
</template>
</category>

<category>
<pattern><eval><star/></eval> TESTEQUAL 
<eval><star/></eval></pattern>
<template>True</template>
<learn>
</learn>
</category>

<category>
<pattern><eval><star/></eval> TESTEQUAL *</pattern>
<template>False</template>
</category>
<learn>
</learn>

<category>
<pattern>* TESTQUAL <eval><star/></eval></pattern>
<template>False</template>
<learn>
</learn>
</category>

<category><pattern>SUCCESSOR
0</pattern><template>1</template></category>
<category><pattern>SUCCESSOR 1</pattern><template>2</template></category>
<category><pattern>SUCCESSOR 2</pattern><template>3</template></category>
<category><pattern>SUCCESSOR 3</pattern><template>4</template></category>
<category><pattern>SUCCESSOR 4</pattern><template>5</template></category>
<category><pattern>SUCCESSOR 5</pattern><template>6</template></category>
<category><pattern>SUCCESSOR 6</pattern><template>7</template></category>
<category><pattern>SUCCESSOR 7</pattern><template>8</template></category>
<category><pattern>SUCCESSOR 8</pattern><template>9</template></category>
<category><pattern>SUCCESSOR 9</pattern><template>1
0</template></category>

<!--
Notice that when we got to 10, we had to write the number as "1 0" rather
than "10", due to the pattern matching style of AIML.

For two digit numbers we need a special case when the last digit is 9. We
can build the SUCCESSOR function for two digits from the one-digit version:
-->

<category><pattern>SUCCESSOR * 9</pattern>
<template><srai>SUCCESSOR <star/></srai> 0</template>
</category>

<category><pattern>SUCCESSOR * *</pattern>
<template><star/> <srai>SUCCESSOR <star index="2"/></srai>
</template>
</category>

<!--
For three digits, we can write:
-->

<category><pattern>SUCCESSOR * 9 9</pattern>
<template><srai>SUCCESSOR <star/></srai> 0 0</template>
</category>

<category><pattern>SUCCESSOR * * *</pattern>
<template><star/> <srai>SUCCESSOR <star index="2"/> <star
index="3"/></srai>
</template>
</category>

<category><pattern>SUCCESSOR * 9 9 9</pattern>
<template><srai>SUCCESSOR <star/></srai> 0 0 0</template>
</category>

<category><pattern>SUCCESSOR * * * *</pattern>
<template><star/> <srai>SUCCESSOR <star index="2"/> <star
index="3"/> <star index="4"/></srai>
</template>
</category>

<!---
Now we have the ability to count from 0 to 9999.

As a boundary condition, add the categories with pattern 
SUCCESSOR * 
SUCCESSOR * * * * *
and SUCCESSOR by itself
to start over at 0:
-->

<category>
<pattern>SUCCESSOR *</pattern>
<template>0</template>
</category>

<category>
<pattern>SUCCESSOR</pattern>
<template>0</template>
</category>

<category>
<pattern>SUCCESSOR * * * * *</pattern>
<template>0</template>
</category>

<!--

Adding 0 to a number is the same as the number itself:
-->


<category>
<pattern>ADD 0 PLUS *</pattern>

<template><star/></template>
</category>

<!-- 
The function ADD(1, X) is the same as the function SUCCESSOR(X):
-->


<category>
<pattern>ADD 1 PLUS *</pattern>

<template><srai>SUCCESSOR <star/></srai></template>
</category>

<!--
The ADD(X,Y) function breaks down the operation of adding into a series of
ADD(X, 1), repeated recursively Y times:
-->

<category>
<pattern>ADD * PLUS *</pattern>
<template><srai>ADD 1 PLUS <srai>ADD <srai>PREDECESSOR <star/></srai> PLUS
<star index="2"/></srai></srai>
</template>
</category>


</aiml>

