diff options
Diffstat (limited to 'modeling')
-rw-r--r-- | modeling/prod_addition.py | 316 | ||||
-rw-r--r-- | modeling/prod_multi.py | 53 | ||||
-rw-r--r-- | modeling/prod_numbers.py | 134 | ||||
-rw-r--r-- | modeling/productions_math.py | 113 | ||||
-rw-r--r-- | modeling/todo.org | 8 |
5 files changed, 452 insertions, 172 deletions
diff --git a/modeling/prod_addition.py b/modeling/prod_addition.py index 3c7e888..b96820c 100644 --- a/modeling/prod_addition.py +++ b/modeling/prod_addition.py @@ -4,22 +4,19 @@ def addition(Model): prods = [] - start_add = Model.productionstring( - name="start_add", + # Try retrieve result from DM + add_start = Model.productionstring( + name="add_start", string=""" =g> isa math_goal op add - task calc - =imaginal> - isa math_op - op add - ones1 =num1 - ones2 =num2 - ones_ans None + arg1 =num1 + arg2 =num2 + ones_ans None ==> - =imaginal> - isa math_op + =g> + isa math_goal ones_ans busy +retrieval> isa math_op @@ -28,17 +25,112 @@ def addition(Model): arg2 =num2 """, ) - prods.append(start_add) + prods.append(add_start) - add_ones = Model.productionstring( - name="add_ones", + # Can remember addition fact, addition done + add_retrieve_success = Model.productionstring( + name="add_retrieve_success", string=""" =g> isa math_goal - task calc - =imaginal> + op add + arg1 =num1 + arg2 =num2 + =retrieval> + isa math_op + op add + arg1 =num1 + arg2 =num2 + result =result + ==> + =g> + isa math_goal + op done + +imaginal> isa math_op op add + arg1 =num1 + arg2 =num2 + result =result + ~retrieval> + """ + ) + prods.append(add_retrieve_success) + + # Cannot remember addition fact, split arguments into digits for column add + add_retrieve_failure = Model.productionstring( + name="add_retrieve_failure", + string=""" + =g> + isa math_goal + op add + arg1 =num1 + arg2 =num2 + ?retrieval> + state error + ==> + ~retrieval> + +retrieval> + isa number + number =num1 + ~retrieval> + +retrieval> + isa number + number =num2 + """ + ) + prods.append(add_retrieve_failure) + + add_expand_arg1 = Model.productionstring( + name="number_expand_arg1", + string=""" + =g> + isa math_goal + op add + arg1 =num + =retrieval> + isa number + number =num + ones =one + tens =ten + hundreds =hun + ==> + =g> + ones1 =one + tens1 =ten + hundreds1 =hun + """ + ) + prods.append(add_expand_arg1) + + add_expand_arg2 = Model.productionstring( + name="number_expand_arg2", + string=""" + =g> + isa math_goal + op add + arg2 =num + =retrieval> + isa number + number =num + ones =one + tens =ten + hundreds =hun + ==> + =g> + ones2 =one + tens2 =ten + hundreds2 =hun + """ + ) + prods.append(add_expand_arg2) + + add_ones = Model.productionstring( + name="add_ones", + string=""" + =g> + isa math_goal + op add ones_ans busy ones1 =num1 ones2 =num2 @@ -48,10 +140,10 @@ def addition(Model): arg2 =num2 result =result ==> - =imaginal> - isa math_op + =g> + isa math_goal ones_ans =result - carry_ones busy + carry busy +retrieval> isa math_op op add @@ -66,13 +158,10 @@ def addition(Model): string=""" =g> isa math_goal - task calc - =imaginal> - isa math_op - op add + op add tens1 =num1 tens2 =num2 - carry_ones busy + carry busy ones_ans =ones =retrieval> isa math_op @@ -81,10 +170,10 @@ def addition(Model): result =ones arg2 =remainder ==> - =imaginal> - isa math_op + =g> + isa math_goal op add - carry_ones 1 + carry 1 tens_ans busy ones_ans =remainder +retrieval> @@ -101,20 +190,17 @@ def addition(Model): string=""" =g> isa math_goal - task calc - =imaginal> - isa math_op - op add + op add tens1 =num1 tens2 =num2 ones_ans =ones - carry_ones busy + carry busy ?retrieval> state error ==> - =imaginal> - isa math_op - carry_ones None + =g> + isa math_goal + carry None tens_ans busy ~retrieval> +retrieval> @@ -130,21 +216,18 @@ def addition(Model): string=""" =g> isa math_goal - task calc - =imaginal> - isa math_op - op add + op add tens_ans busy - carry_ones None + carry None =retrieval> isa math_op op add result =sum ==> - =imaginal> - isa math_op + =g> + isa math_goal tens_ans =sum - carry_tens busy + carry busy +retrieval> isa math_op op add @@ -159,14 +242,11 @@ def addition(Model): string=""" =g> isa math_goal - task calc - =imaginal> - isa math_op - op add + op add tens_ans busy tens1 =num1 tens2 =num2 - carry_ones 1 + carry 1 =retrieval> isa math_op op add @@ -174,9 +254,9 @@ def addition(Model): arg1 =num1 arg2 =num2 ==> - =imaginal> - isa math_op - carry_ones None + =g> + isa math_goal + carry None ~retrieval> +retrieval> isa math_op @@ -193,13 +273,10 @@ def addition(Model): string=""" =g> isa math_goal - task calc - =imaginal> - isa math_op - op add + op add hundreds1 =num1 hundreds2 =num2 - carry_tens busy + carry busy tens_ans =tens =retrieval> isa math_op @@ -208,10 +285,10 @@ def addition(Model): result =tens arg2 =remainder ==> - =imaginal> - isa math_op + =g> + isa math_goal op add - carry_tens 1 + carry 1 hundreds_ans busy tens_ans =remainder +retrieval> @@ -228,20 +305,17 @@ def addition(Model): string=""" =g> isa math_goal - task calc - =imaginal> - isa math_op - op add + op add hundreds1 =num1 hundreds2 =num2 tens_ans =tens - carry_tens busy + carry busy ?retrieval> state error ==> - =imaginal> - isa math_op - carry_tens None + =g> + isa math_goal + carry None hundreds_ans busy ~retrieval> +retrieval> @@ -257,12 +331,9 @@ def addition(Model): string=""" =g> isa math_goal - task calc - =imaginal> - isa math_op - op add + op add hundreds_ans busy - carry_tens None + carry None =retrieval> isa math_op op add @@ -270,9 +341,7 @@ def addition(Model): ==> =g> isa math_goal - task done - =imaginal> - isa math_op + op add_result hundreds_ans =sum """, ) @@ -283,14 +352,11 @@ def addition(Model): string=""" =g> isa math_goal - task calc - =imaginal> - isa math_op - op add + op add hundreds_ans busy hundreds1 =num1 hundreds2 =num2 - carry_tens 1 + carry 1 =retrieval> isa math_op op add @@ -298,9 +364,9 @@ def addition(Model): arg1 =num1 arg2 =num2 ==> - =imaginal> - isa math_op - carry_tens None + =g> + isa math_goal + carry None ~retrieval> +retrieval> isa math_op @@ -311,37 +377,73 @@ def addition(Model): ) prods.append(add_hundreds_carry) - addition_done = Model.productionstring( - name="addition_done", + add_result_contract = Model.productionstring( + name="add_result_contract", string=""" =g> isa math_goal - task done - =imaginal> - isa math_op - op add - arg1 =arg1 - ones1 =ones1 - tens1 =tens1 - hundreds1 =huns1 - arg2 =arg2 - ones2 =ones2 - tens2 =tens2 - hundreds2 =huns2 + op add_result + ones_ans =one + tens_ans =ten + hundreds_ans =hun ==> + ~retrieval> +retrieval> - isa math_op + isa number + ones =one + tens =ten + hundreds =hun + """ + ) + prods.append(add_result_contract) + + add_contract_done = Model.productionstring( + name="add_contract_done", + string=""" + =g> + isa math_goal + op add_result + arg1 =arg1 + arg2 =arg2 + ones_ans =one + tens_ans =ten + hundreds_ans =hun + =retrieval> + isa number + number =result + ones =one + tens =ten + hundreds =hun + ==> + =g> + isa math_goal op add - arg1 =arg1 - ones1 =ones1 - tens1 =tens1 - hundreds1 =huns1 - arg2 =arg2 - ones2 =ones2 - tens2 =tens2 - hundreds2 =huns2 + result =result """ ) - prods.append(addition_done) + prods.append(add_contract_done) + add_done = Model.productionstring( + name="add_done", + string=""" + =g> + isa math_goal + op add + arg1 =arg1 + arg2 =arg2 + result ~None + result =result + ==> + +imaginal> + isa math_op + op add + arg1 =arg1 + arg2 =arg2 + result =result + =g> + isa math_goal + op done + """ + ) + prods.append(add_done) return prods diff --git a/modeling/prod_multi.py b/modeling/prod_multi.py index 667241e..4b4e7c5 100644 --- a/modeling/prod_multi.py +++ b/modeling/prod_multi.py @@ -22,7 +22,6 @@ def multiplication(Model): =g> isa math_goal op mul - task calc =imaginal> isa math_op op mul @@ -41,7 +40,7 @@ def multiplication(Model): +g> isa math_goal op add - task calc + task mul +imaginal> isa math_op op add @@ -53,6 +52,7 @@ def multiplication(Model): ones2 =ones tens2 =tens hundreds2 =huns + mul_counter =mul +retrieval> isa math_op op add @@ -62,29 +62,62 @@ def multiplication(Model): ) prods.append(start_mul) + count_mul = Model.productionstring( + name="count_mul", + string=""" + =g> + isa math_goal + op add_done + task mul + =imaginal> + isa math_op + op add + mul_counter =counter + ==> + =g> + isa math_goal + op count_done + +retrieval> + isa math_op + op add + arg1 1 + result =counter + """ + ) step_mul = Model.productionstring( name="step_mul", string=""" =g> isa math_goal - op mul - task calc + op count_done + task mul =imaginal> isa math_op - op mul - arg2 =arg + op add + hundreds_ans =hun_ans + tens_ans =ten_ans + ones_ans =one_ans + mul_counter =mul_counter =retrieval> isa math_op op add - arg1 =arg - arg2 =arg - result =sum + result =mul_counter + arg2 =new_counter ==> =g> isa math_goal op mul - one_ans =sum + task mul + +imaginal> + isa math_op + op mul + arg1 =new_counter + ones1 =new_counter + hundreds2 =hun_ans + tens2 =ten_ans + ones2 =one_ans + mul_counter =new_counter """, ) prods.append(step_mul) diff --git a/modeling/prod_numbers.py b/modeling/prod_numbers.py new file mode 100644 index 0000000..8bf1ebb --- /dev/null +++ b/modeling/prod_numbers.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 + +def number(Model): + prods = [] + + number_expand_arg1 = Model.productionstring( + name="number_expand_arg1", + string=""" + =g> + isa math_goal + op expand + expand_slot arg1 + arg1 =num + ==> + +retrieval> + isa number + number =num + """ + ) + prods.append(number_expand_arg1) + + number_expand_arg1_done = Model.productionstring( + name="number_expand_arg1_done", + string=""" + =g> + isa math_goal + op expand + expand_slot arg1 + arg1 =num + =retrieval> + isa number + number =num + ones =one + tens =ten + hundreds =hun + ==> + =g> + isa math_goal + op done + ones1 =one + tens1 =ten + hundreds1 =hun + """ + ) + prods.append(number_expand_arg1_done) + + + number_expand_arg2 = Model.productionstring( + name="number_expand_arg2", + string=""" + =g> + isa math_goal + op expand + expand_slot 2arg + arg2 =num + ==> + +retrieval> + isa number + number =num + """ + ) + prods.append(number_expand_arg2) + + number_expand_arg2_done = Model.productionstring( + name="number_expand_arg2_done", + string=""" + =g> + isa math_goal + op expand + expand_slot arg2 + arg2 =num + =retrieval> + isa number + number =num + ones =one + tens =ten + hundreds =hun + ==> + =g> + isa math_goal + op done + ones2 =one + tens2 =ten + hundreds2 =hun + """ + ) + prods.append(number_expand_arg2_done) + + number_contract_result = Model.productionstring( + name="number_contract_result", + string=""" + =g> + isa math_goal + op contract + expand_slot result + ones_ans =ones + tens_ans =tens + hundreds_ans =huns + ==> + +retrieval> + isa number + ones =ones + tens =tens + hundreds =huns + """ + ) + prods.append(number_contract_result) + + number_contract_result_done = Model.productionstring( + name="number_contract_result_done", + string=""" + =g> + isa math_goal + op contract + expand_slot result + ones_ans =ones + tens_ans =tens + hundreds_ans =huns + =retrieval> + isa number + number =num + ones =ones + tens =tens + hundreds =huns + ==> + =g> + isa math_goal + op done + result =num + """ + ) + prods.append(number_contract_result_done) + + return prods diff --git a/modeling/productions_math.py b/modeling/productions_math.py index 182a208..635efff 100644 --- a/modeling/productions_math.py +++ b/modeling/productions_math.py @@ -16,17 +16,21 @@ def init(): DM = Model.decmem goal = Model.goal - imaginal = Model.set_goal(name="imaginal", delay=0) + 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("procedure", ("proc", "op1", "arg1_1", "arg1_2")) actr.chunktype( - "math_op", + "math_goal", ( + "task", "op", + "nextop", "arg1", "arg2", "result", + "expand_slot", + "contract_slot", "hundreds1", "tens1", "ones1", @@ -36,11 +40,19 @@ def init(): "hundreds_ans", "tens_ans", "ones_ans", - "carry_ones", - "carry_tens", + "mul_counter", + "carry", + ), + ) + actr.chunktype( + "math_op", + ( + "op", + "arg1", + "arg2", + "result", ), ) - # Add numbers 0-999 to decmem for i in range(0, 1000): @@ -86,55 +98,42 @@ def init(): ) return Model, DM, goal, imaginal -def add_goal(goal, imaginal, op, arg1, arg2): - - goal.add(actr.makechunk("", "math_goal", op=op, task="calc")) - imaginal.add( - actr.makechunk( - "", - "math_op", - op=op, - arg1=arg1, - arg2=arg2, - ones1=get_digit(arg1, 0), - tens1=get_digit(arg1, 1), - hundreds1=get_digit(arg1, 2), - ones2=get_digit(arg2, 0), - tens2=get_digit(arg2, 1), - hundreds2=get_digit(arg2, 2), - ) - ) +def add_goal(goal, op, arg1, arg2): -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 - # """, - # ) + goal.add(actr.makechunk("", "math_goal", op=op, task=op, arg1=arg1, arg2=arg2)) + # imaginal.add( + # actr.makechunk( + # "", + # "math_op", + # op=op, + # arg1=arg1, + # arg2=arg2, + # ones1=get_digit(arg1, 0), + # tens1=get_digit(arg1, 1), + # hundreds1=get_digit(arg1, 2), + # ones2=get_digit(arg2, 0), + # tens2=get_digit(arg2, 1), + # hundreds2=get_digit(arg2, 2), + # ) + #) + + +def general_prod(Model): Model.productionstring( - name="terminate_op", + name="continue_with_next_op", string=""" =g> isa math_goal - task finished_op - =imaginal> - isa math_op - result =answer + op done + nextop ~None + nextop =nextop ==> - ~g>""", + =g> + isa math_goal + op =nextop + """, ) @@ -146,20 +145,20 @@ def wait_input(): def start(): - while(True): + while True: op, arg1, arg2 = wait_input() Model, DM, goal, imaginal = init() - add_goal(goal, imaginal, op, arg1, arg2) + add_goal(goal, op, arg1, arg2) - # unwind_prod() + general_prod(Model) add_prods = prod_addition.addition(Model) greater_prods = prod_comp.greater_than(Model) less_prods = prod_comp.less_than(Model) multi_prods = prod_multi.multiplication(Model) - for prod in add_prods: - print(prod) - print("\n") + # for prod in multi_prods: + # print(prod) + # print("\n") print("goal: ", goal) print("imaginal: ", imaginal) @@ -177,8 +176,12 @@ def start(): result_num = result_huns + result_tens + result_ones print(result_num) # print(list(DM)) - numbers = [x for x in list(DM) if x.typename != "number" and x.typename != "math_op"] - numbers = [x for x in list(DM) if x.typename != "number" and x.typename == "math_op"] + numbers = [ + x for x in list(DM) if x.typename != "number" and x.typename != "math_op" + ] + numbers = [ + x for x in list(DM) if x.typename != "number" and x.typename == "math_op" + ] # print(numbers) diff --git a/modeling/todo.org b/modeling/todo.org new file mode 100644 index 0000000..c3cfa70 --- /dev/null +++ b/modeling/todo.org @@ -0,0 +1,8 @@ +#+title: Todo + +* Operations +** Subtraction +** Multiplication +** Max of 4 numbers +** Min of 4 numbers +** subgoals, i.e. do addition manually if addition fact not in decmem |