#!/usr/bin/env python3 import pyactr as actr Model = actr.ACTRModel() DM = Model.decmem goal = Model.goal imaginal = Model.set_goal(name="imaginal", delay=0.2) actr.chunktype("number", ("number", "next", "ones", "tens", "hundreds")) actr.chunktype("math_goal", ("op", "task")) actr.chunktype( "math_op", ( "op", "arg1", "arg2", "result", "hundreds1", "tens1", "ones1", "hundreds2", "tens2", "ones2", "hundreds_ans", "tens_ans", "ones_ans", "carry", ), ) goal.add(actr.makechunk("", "math_goal", op="add", task="calc")) imaginal.add( actr.makechunk( "", "math_op", op="add", arg1=5, arg2=2, ones1=5, tens1=0, hundreds1=0, ones2=2, tens2=0, hundreds2=0, ) ) # https://stackoverflow.com/a/39644726 def get_digit(number, n): return number // 10**n % 10 # Add numbers 0-999 to decmem for i in range(0, 1000): DM.add( actr.makechunk( f"number{str(i)}", "number", number=i, next=i + 1, ones=get_digit(i, 0), tens=get_digit(i, 1), hundreds=get_digit(i, 2), ) ) # Add comparison relations to single digit numbers for i in range(0, 10): for j in range(0, 10): DM.add( actr.makechunk( f"greater{i}{j}", "math_op", op="greater", arg1=i, arg2=j, result=max(i, j), ) ) DM.add( actr.makechunk( f"lesser{i}{j}", "math_op", op="lesser", arg1=i, arg2=j, result=min(i, j), ) ) DM.add( actr.makechunk( f"plus{i}{j}", "math_op", op="add", arg1=i, arg2=j, result=i + j ) ) def unwind_prod(): # Model.productionstring( # name="init_math_op", # string=""" # =g> # isa math_op # task None # arg1 =num1 # arg2 =num2 # ==> # +retrieval> # isa number # number =num1 # =g> # task unwind_left # """, # ) Model.productionstring( name="terminate_op", string=""" =g> isa math_goal task finished_op =imaginal> isa math_op result =answer ==> ~g>""", ) def greater_than_prod(): # TODO: if two numbers are equal, extra effort to determine greater one? prod_start = Model.productionstring( name="greater_start", string=""" =g> isa math_goal task calc =imaginal> isa math_op op greater hundreds1 =hun1 hundreds2 =hun1 tens1 =tens1 tens2 =tens1 ones1 =ones1 ones2 ~=ones1 ones2 =ones2 ==> +retrieval> isa math_op op greater arg1 =ones1 arg2 =ones2 """, ) print(prod_start) Model.productionstring( name="greater_end", string=""" =g> isa math_goal =imaginal> op greater =retrieval> isa math_op op greater result =ans ==> =imaginal> isa math_op result =ans ~g> """, ) def addition(): start_add = Model.productionstring( name="start_add", string=""" =goal> isa math_goal task calc =imaginal> isa math_op op add ones1 =num1 ones2 =num2 ones_ans None ==> =imaginal> isa math_op ones_ans busy +retrieval> isa math_op op add arg1 =num1 arg2 =num2 """, ) print("start_add: ", start_add) add_ones = Model.productionstring( name="add_ones", string=""" =goal> isa math_goal task calc =imaginal> isa math_op op add ones_ans busy ones1 =num1 ones2 =num2 =retrieval> isa math_op arg1 =num1 arg2 =num2 result =result ==> =imaginal> isa math_op ones_ans =result carry busy +retrieval> isa math_op op add arg1 10 result =result """, ) print(add_ones) Model.productionstring( name="process_carry", string=""" =goal> isa math_goal task calc =imaginal> isa math_op op add tens1 =num1 tens2 =num2 carry busy ones_ans =ones =retrieval> isa math_op op add arg1 10 result =ones arg2 =remainder ==> =imaginal> isa math_op op add carry 1 tens_ans busy ones_ans =remainder +retrieval> isa math_op op add arg1 =num1 arg2 =num2 """, ) Model.productionstring( name="no_carry", string=""" =goal> isa math_goal task calc =imaginal> isa math_op op add tens1 =num1 tens2 =num2 ones_ans =ones carry busy ?retrieval> buffer failure ==> =imaginal> isa math_op carry None tens_ans busy +retrieval> isa math_op arg1 =num1 arg2 =num2 """, ) Model.productionstring( name="add_tens_done", string=""" =goal> isa math_goal task calc =imaginal> isa math_op op add tens_ans busy carry None =retrieval> isa math_op op add result =sum ==> =imaginal> isa math_op tens_ans =sum """, ) add_tens_carry = Model.productionstring( name="add_tens_carry", string=""" =goal> isa math_goal task calc =imaginal> isa math_op op add tens_ans busy carry 1 =retrieval> isa math_op op add result =sum ==> =imaginal> isa math_op carry None +retrieval> isa math_op op add arg1 1 arg2 =sum """, ) print("add_tens_carry: ", add_tens_carry) # print(DM) # unwind_prod() addition() greater_than_prod() # Model.goal.add(actr.makechunk("goal", "math_op", op="greater", arg1=5, arg2=9)) print("goal: ", goal) print("imaginal: ", imaginal) x = Model.simulation() x.run() # print(list(DM)) numbers = [x for x in list(DM) if x.typename != "number" and x.typename != "math_op"] # print(numbers)