summaryrefslogtreecommitdiff
path: root/modeling/addition.py
blob: 5e83acc5eb9eecf4c829fc4c255481bbf7c80e81 (plain)
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
#!/usr/bin/env python3

import pyactr as actr


Model = actr.ACTRModel()
actr.chunktype("countOrder", ("first", "second"))
actr.chunktype("add", ("arg1", "arg2", "sum", "count"))

dm = Model.decmem

for i in range(0, 11):
    dm.add(actr.makechunk("chunk" + str(i), "countOrder", first=i, second=i + 1))

Model.goal.add(actr.makechunk("", "add", arg1=5, arg2=2))

Model.productionstring(
    name="init_addition",
    string="""
    =g>
    isa     add
    arg1    =num1
    arg2    =num2
    sum     None
    ==>
    =g>
    isa     add
    sum     =num1
    count   0
    +retrieval>
    isa     countOrder
    first   =num1
""",
)

Model.productionstring(
    name="terminate_addition",
    string="""
        =g>
        isa     add
        count   =num
        arg2    =num
        sum     =answer
        ==>
        ~g>""",
)

Model.productionstring(
    name="increment_count",
    string="""
        =g>
        isa     add
        count   =count
        sum     =sum
        =retrieval>
        isa     countOrder
        first   =count
        second  =newcount
        ==>
        =g>
        isa     add
        count   =newcount
        +retrieval>
        isa     countOrder
        first   =sum""",
)

Model.productionstring(
    name="increment_sum",
    string="""
        =g>
        isa     add
        count   =count
        arg2    ~=count
        sum     =sum
        =retrieval>
        isa     countOrder
        first   =sum
        second  =newsum
        ==>
        =g>
        isa     add
        sum     =newsum
        +retrieval>
        isa     countOrder
        first   =count""",
)

if __name__ == "__main__":
    x = Model.simulation()
    x.run()