#!/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_start = Model.productionstring( name="mul_start", string=""" =g> isa math_goal op mul arg1 ~0 arg1 ~1 arg2 ~0 arg1 ~1 arg1 =mul arg2 =arg ones2 =ones tens2 =tens hundreds2 =huns mul_counter None ?retrieval> state free ==> =g> isa math_goal mul_counter 1 result =arg +retrieval> isa math_op op add arg1 =arg arg2 =arg """, ) prods.append(mul_start) 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 mul_counter =mul_counter =retrieval> isa math_op op add arg1 =mul_counter arg2 1 result =arg1 ==> =g> isa math_goal op done """, ) 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 nextop mul_fail op add 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