#!/usr/bin/env python3 def multiplication(Model): prods = [] # TODO: switch operands so less steps are needed # switch_mul = Model.productionstring( # name="switch_mul", # string=""" # =g> # =imaginal> # ==> # =imaginal> # """, # ) # prods.append(switch_mul) mul_arg1_1 = Model.productionstring( name="mul_arg1_1", string=""" =g> isa math_goal op mul arg1 1 arg1 =arg1 arg2 =arg2 ==> =g> isa math_goal op done result =arg2 +imaginal> isa math_op op mul arg1 =arg1 arg2 =arg2 result =arg2 ~retrieval> """ ) mul_arg2_1 = Model.productionstring( name="mul_arg2_1", string=""" =g> isa math_goal op mul arg2 1 arg1 =arg1 arg2 =arg2 ==> =g> isa math_goal op done result =arg1 +imaginal> isa math_op op mul arg1 =arg1 arg2 =arg2 result =arg1 ~retrieval> """ ) mul_arg1_0 = Model.productionstring( name="mul_arg1_0", string=""" =g> isa math_goal op mul arg1 0 arg1 =arg1 arg2 =arg2 ==> =g> isa math_goal op done result 0 +imaginal> isa math_op op mul arg1 =arg1 arg2 =arg2 result 0 ~retrieval> """ ) mul_arg2_0 = Model.productionstring( name="mul_arg2_0", string=""" =g> isa math_goal op mul arg2 0 arg1 =arg1 arg2 =arg2 ==> =g> isa math_goal op done result 0 +imaginal> isa math_op op mul arg1 =arg1 arg2 =arg2 result 0 ~retrieval> """ ) # TODO: why mul_start->mul_step_success?? mul_start = Model.productionstring( name="mul_start", string=""" =g> isa math_goal op mul arg1 ~0 arg1 ~1 arg2 ~0 arg1 ~1 arg1 =arg1 arg2 =arg2 ?retrieval> state free ==> =g> isa math_goal op mul_try_retrieve +retrieval> isa math_op op mul arg1 =arg1 arg2 =arg2 """, ) prods.append(mul_start) # mul_start_failure = Model.productionstring( # name="mul_start_failure", # string=""" # =g> # isa math_goal # op mul_try_retrieve # arg1 =arg1 # arg2 =arg2 # ?retrieval> # state error # ==> # isa math_goal # op mul_step # """ mul_start_success = Model.productionstring( name="mul_start_success", string=""" =g> isa math_goal op mul_try_retrieve arg1 =arg1 arg2 =arg2 =retrieval> isa math_op op mul arg1 =arg1 arg2 =arg2 result =result ==> =g> isa math_goal op done +imaginal> isa math_op op mul arg1 =arg1 arg2 =arg2 result =result ~retrieval> """, ) mul_step = Model.productionstring( name="mul_step", string=""" =g> isa math_goal op mul_try_retrieve arg1 ~0 arg1 ~1 arg2 ~0 arg1 ~1 arg1 =mul arg2 =arg ones2 =ones tens2 =tens hundreds2 =huns mul_counter None ?retrieval> state error ==> =g> isa math_goal op mul mul_counter 1 result =arg +retrieval> isa math_op op add arg1 =arg arg2 =arg """, ) prods.append(mul_step) mul_step_success = Model.productionstring( name="mul_step_success", string=""" =g> isa math_goal op mul arg1 =mul arg2 =arg ones2 =ones tens2 =tens hundreds2 =huns mul_counter =mul_counter result =result =retrieval> isa math_op op add arg1 =arg arg2 =result result =sum ==> =g> isa math_goal result =sum +retrieval> isa math_op op add arg1 =mul_counter arg2 1 """, ) prods.append(mul_step_success) mul_done = Model.productionstring( name="mul_done", string=""" =g> isa math_goal op mul arg1 =arg1 arg2 =arg2 result =result mul_counter =mul_counter =retrieval> isa math_op op add arg1 =mul_counter arg2 1 result =arg1 ==> =g> isa math_goal op done +imaginal> isa math_op op mul arg1 =arg1 arg2 =arg2 result =result ~retrieval> """, ) mul_continue = Model.productionstring( name="mul_continue", string=""" =g> isa math_goal op mul arg1 =arg1 arg2 =arg2 mul_counter =mul_counter result =result =retrieval> isa math_op op add arg1 =mul_counter arg2 1 result ~=arg1 result =counted ==> =g> isa math_goal mul_counter =counted ~retrieval> +retrieval> isa math_op op add arg1 =arg2 arg2 =result """, ) mul_step_failure = Model.productionstring( name="mul_step_failure", string=""" =g> isa math_goal op mul arg1 =mul arg2 =arg ones2 =ones tens2 =tens hundreds2 =huns mul_counter =mul_counter result =result ?retrieval> state error ==> =g> isa math_goal nextnextop mul_fail nextop add op expand arg1 =arg arg2 =result mem_arg1 =mul mem_arg2 =arg ones1 None tens1 None hundreds1 None ones2 None tens2 None hundreds2 None ones_ans None tens_ans None hundreds_ans None result None ~retrieval> """, ) # instead of remembering original mult args, maybe should # start from the beginning, with the addition results now # retrievable mul_step_addition_return = Model.productionstring( name="mul_step_addition_return", string=""" =g> isa math_goal op mul_fail mul_counter =mul_counter result =result mem_arg1 =mem_arg1 mem_arg2 =mem_arg2 ==> =g> isa math_goal op mul arg1 =mem_arg1 arg2 =mem_arg2 +retrieval> isa math_op op add arg1 =mul_counter arg2 1 """, ) prods.append(mul_start) return prods