-
Notifications
You must be signed in to change notification settings - Fork 0
/
primitive-math.aiml
155 lines (122 loc) · 3.57 KB
/
primitive-math.aiml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?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>
<category>
<pattern><eval><star/></eval> TESTEQUAL <eval><star/></eval></pattern>
<template>True</template>
</category>
</learn>
<learn>
<category>
<pattern><eval><star/></eval> TESTEQUAL *</pattern>
<template>False</template>
</category>
</learn>
<learn>
<category>
<pattern>* TESTQUAL <eval><star/></eval></pattern>
<template>False</template>
</category>
</learn>
</template>
</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>