#!/usr/bin/env python3 def addition(Model): prods = [] # Try retrieve result from DM add_start = Model.productionstring( name="add_start", string=""" =g> isa math_goal op add arg1 =num1 arg2 =num2 ones_ans None ==> =g> isa math_goal ones_ans busy +retrieval> isa math_op op add arg1 =num1 arg2 =num2 """, ) prods.append(add_start) # Can remember addition fact, addition done add_retrieve_success = Model.productionstring( name="add_retrieve_success", string=""" =g> isa math_goal 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 =retrieval> isa math_op arg1 =num1 arg2 =num2 result =result ==> =g> isa math_goal ones_ans =result carry busy +retrieval> isa math_op op add arg1 10 result =result """, ) prods.append(add_ones) process_carry_ones = Model.productionstring( name="process_carry_ones", string=""" =g> isa math_goal op add tens1 =num1 tens2 =num2 carry busy ones_ans =ones =retrieval> isa math_op op add arg1 10 result =ones arg2 =remainder ==> =g> isa math_goal op add carry 1 tens_ans busy ones_ans =remainder +retrieval> isa math_op op add arg1 =num1 arg2 =num2 """, ) prods.append(process_carry_ones) no_carry_ones = Model.productionstring( name="no_carry_ones", string=""" =g> isa math_goal op add tens1 =num1 tens2 =num2 ones_ans =ones carry busy ?retrieval> state error ==> =g> isa math_goal carry None tens_ans busy ~retrieval> +retrieval> isa math_op arg1 =num1 arg2 =num2 """, ) prods.append(no_carry_ones) add_tens_done = Model.productionstring( name="add_tens_done", string=""" =g> isa math_goal op add tens_ans busy carry None =retrieval> isa math_op op add result =sum ==> =g> isa math_goal tens_ans =sum carry busy +retrieval> isa math_op op add arg1 10 result =sum """, ) prods.append(add_tens_done) add_tens_carry = Model.productionstring( name="add_tens_carry", string=""" =g> isa math_goal op add tens_ans busy tens1 =num1 tens2 =num2 carry 1 =retrieval> isa math_op op add result =sum arg1 =num1 arg2 =num2 ==> =g> isa math_goal carry None ~retrieval> +retrieval> isa math_op op add arg1 1 arg2 =sum """, ) prods.append(add_tens_carry) process_carry_tens = Model.productionstring( name="process_carry_tens", string=""" =g> isa math_goal op add hundreds1 =num1 hundreds2 =num2 carry busy tens_ans =tens =retrieval> isa math_op op add arg1 10 result =tens arg2 =remainder ==> =g> isa math_goal op add carry 1 hundreds_ans busy tens_ans =remainder +retrieval> isa math_op op add arg1 =num1 arg2 =num2 """, ) prods.append(process_carry_tens) no_carry_tens = Model.productionstring( name="no_carry_tens", string=""" =g> isa math_goal op add hundreds1 =num1 hundreds2 =num2 tens_ans =tens carry busy ?retrieval> state error ==> =g> isa math_goal carry None hundreds_ans busy ~retrieval> +retrieval> isa math_op arg1 =num1 arg2 =num2 """, ) prods.append(no_carry_tens) add_hundreds_done = Model.productionstring( name="add_hundreds_done", string=""" =g> isa math_goal op add hundreds_ans busy carry None =retrieval> isa math_op op add result =sum ==> =g> isa math_goal op add_result hundreds_ans =sum """, ) prods.append(add_hundreds_done) add_hundreds_carry = Model.productionstring( name="add_hundreds_carry", string=""" =g> isa math_goal op add hundreds_ans busy hundreds1 =num1 hundreds2 =num2 carry 1 =retrieval> isa math_op op add result =sum arg1 =num1 arg2 =num2 ==> =g> isa math_goal carry None ~retrieval> +retrieval> isa math_op op add arg1 1 arg2 =sum """, ) prods.append(add_hundreds_carry) add_result_contract = Model.productionstring( name="add_result_contract", string=""" =g> isa math_goal op add_result ones_ans =one tens_ans =ten hundreds_ans =hun ==> ~retrieval> +retrieval> 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 result =result """ ) 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