#!/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> 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 op add arg1 =arg arg2 =result ones1 None tens1 None hundreds1 None ones2 None tens2 None hundreds2 None +retrieval> isa math_op op add arg1 =mul_counter arg2 1 """, ) mul_step_failure_return = Model.productionstring( name="mul_step_failure_return", 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_start) return prods