#!/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 ?retrieval> state free ==> =g> isa math_goal +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 result =result +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 ones1 =num1 ones2 =num2 ones_carry ~busy tens_carry ~busy tens_ans ~busy hundreds_ans ~busy ?retrieval> state error ==> =g> isa math_goal ones_ans busy +retrieval> isa math_op op add arg1 =num1 arg2 =num2 """, ) prods.append(add_retrieve_failure) 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 op add arg1 =num1 arg2 =num2 result =result ==> =g> isa math_goal ones_ans =result ones_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 ones_carry busy ones_ans =ones =retrieval> isa math_op op add arg1 10 result =ones arg2 =remainder ==> =g> isa math_goal op add ones_carry 1 tens_ans busy ones_ans =remainder ~retrieval> +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 ones_carry busy tens_ans None ?retrieval> state error ==> =g> isa math_goal ones_carry None tens_ans busy ~retrieval> +retrieval> isa math_op arg1 =num1 arg2 =num2 """, ) prods.append(no_carry_ones) add_tens = Model.productionstring( name="add_tens", string=""" =g> isa math_goal op add tens_ans busy tens1 =num1 tens2 =num2 =retrieval> isa math_op op add arg1 =num1 arg2 =num2 result =sum ==> =g> isa math_goal tens_ans =sum tens_carry busy +retrieval> isa math_op op add arg1 10 result =sum """,) prods.append(add_tens) add_tens_carry = Model.productionstring( name="add_tens_carry", string=""" =g> isa math_goal op add tens_ans =ten_ans tens1 =num1 tens2 =num2 ones_carry 1 ?retrieval> state free ==> =g> isa math_goal +retrieval> isa math_op op add arg1 1 arg2 =ten_ans """, ) prods.append(add_tens_carry) add_tens_carry_done = Model.productionstring( name="add_tens_carry_done", string=""" =g> isa math_goal op add tens_ans =ten_ans tens1 =num1 tens2 =num2 ones_carry 1 =retrieval> isa math_op op add arg1 1 arg2 =ten_ans result =result ==> =g> isa math_goal tens_ans =result ones_carry None """, ) prods.append(add_tens_carry_done) process_carry_tens = Model.productionstring( name="process_carry_tens", string=""" =g> isa math_goal op add tens_carry busy tens_ans =tens =retrieval> isa math_op op add arg1 10 result =tens arg2 =remainder ==> =g> isa math_goal op add tens_carry 1 tens_ans =remainder ~retrieval> """, ) prods.append(process_carry_tens) no_carry_tens = Model.productionstring( name="no_carry_tens", string=""" =g> isa math_goal op add tens_ans =tens tens_carry busy ?retrieval> state error ==> =g> isa math_goal tens_carry None ~retrieval> """, ) prods.append(no_carry_tens) add_hundreds_start = Model.productionstring( name="add_hundreds_start", string=""" =g> isa math_goal op add ones_carry None tens_ans ~None hundreds1 =hun1 hundreds2 =hun2 ?retrieval> state free ==> =g> isa math_goal hundreds_ans busy +retrieval> isa math_op op add arg1 =hun1 arg2 =hun2 """, ) prods.append(add_hundreds_start) add_hundreds = Model.productionstring( name="add_hundreds", string=""" =g> isa math_goal op add hundreds_ans busy tens_carry None ones_carry None =retrieval> isa math_op op add result =sum ==> =g> isa math_goal op add_done hundreds_ans =sum ~retrieval> """, ) prods.append(add_hundreds) add_hundreds_carry = Model.productionstring( name="add_hundreds_carry", string=""" =g> isa math_goal op add hundreds_ans busy hundreds1 =num1 hundreds2 =num2 tens_carry 1 ones_carry None =retrieval> isa math_op op add result =sum arg1 =num1 arg2 =num2 ==> =g> isa math_goal tens_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_done 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 ~retrieval> """, ) prods.append(add_done) return prods