#!/usr/bin/env python3 def subtraction(Model): prods = [] start_sub = Model.productionstring( name="start_sub", string=""" =g> isa math_goal op sub arg1 =arg1 arg2 =arg2 ?retrieval> state free buffer empty ==> =g> isa math_goal op sub_retrieve +retrieval> isa math_op op add result =arg1 arg2 =arg2 """, ) # Can remember addition fact, addition done # TODO: save all sub-facts as addition facts? sub_retrieve_success = Model.productionstring( name="sub_retrieve_success", string=""" =g> isa math_goal op sub_retrieve arg1 =arg1 arg2 =arg2 =retrieval> isa math_op op add arg1 =result arg2 =arg2 result =arg1 ==> =g> isa math_goal op done result =result +imaginal> isa math_op op add arg1 =result arg2 =arg2 result =arg1 ~retrieval> """, ) sub_retrieve_failure = Model.productionstring( name="sub_retrieve_failure", string=""" =g> isa math_goal op sub_retrieve ones1 =num1 ones2 =num2 ?retrieval> state error ==> =g> isa math_goal op sub_ones ones_carry 0 tens_carry 0 +retrieval> isa math_op op greater arg1 =num1 arg2 =num2 """, ) sub_ones_retry = Model.productionstring( name="sub_ones_retry", string=""" =g> isa math_goal op sub_ones ?retrieval> state error ==> =g> isa math_goal op sub_retrieve ~retrieval> """, ) sub_ones_ok = Model.productionstring( name="sub_ones_ok", string=""" =g> isa math_goal op sub_ones ones1 =num1 ones2 =num2 =retrieval> isa math_op op greater arg1 =num1 arg2 =num2 result =num1 ==> =g> isa math_goal op sub_ones +retrieval> isa math_op op add result =num1 arg1 =num2 """, ) # subtrahent greater than minuent sub_ones_too_large_start = Model.productionstring( name="sub_ones_too_large_start", string=""" =g> isa math_goal op sub_ones ones1 =num1 ones2 =num2 =retrieval> isa math_op op greater arg1 =num1 arg2 =num2 result =num2 ==> =g> isa math_goal op sub_ones_large ones_carry 1 +retrieval> isa math_op op add arg1 =num1 arg2 10 """, ) sub_ones_too_large_done = Model.productionstring( name="sub_ones_too_large_done", string=""" =g> isa math_goal op sub_ones_large ones1 =num1 ones2 =num2 ones_carry 1 =retrieval> isa math_op op add arg1 =num1 arg2 10 result =result ==> =g> isa math_goal op sub_ones +retrieval> isa math_op op add result =result arg1 =num2 """, ) sub_ones_done = Model.productionstring( name="sub_ones_done", string=""" =g> isa math_goal op sub_ones ones2 =num2 =retrieval> isa math_op op add arg1 =num2 arg2 =result ==> =g> isa math_goal op sub_tens ones_ans =result ~retrieval> """, ) sub_tens_with_carry = Model.productionstring( name="sub_tens_with_carry", string=""" =g> isa math_goal op sub_tens tens1 =num1 tens2 =num2 ones_carry 1 ?retrieval> buffer empty state free ==> =g> isa math_goal op sub_tens +retrieval> isa math_op op add arg1 1 arg2 =num2 """, ) sub_tens_with_carry_done = Model.productionstring( name="sub_tens_with_carry_done", string=""" =g> isa math_goal op sub_tens tens1 =num1 tens2 =num2 ones_carry 1 =retrieval> isa math_op op add arg1 1 arg2 =num2 result ~10 result =result ==> =g> isa math_goal op sub_tens ones_carry 0 tens2 =result ~retrieval> """, ) sub_tens_with_carry_done_10 = Model.productionstring( name="sub_tens_with_carry_done_10", string=""" =g> isa math_goal op sub_tens tens1 =num1 tens2 =num2 ones_carry 1 =retrieval> isa math_op op add arg1 1 arg2 =num2 result 10 ==> =g> isa math_goal op sub_tens ones_carry 0 tens_carry 1 tens2 0 ~retrieval> """, ) sub_tens_no_carry = Model.productionstring( name="sub_tens_no_carry", string=""" =g> isa math_goal op sub_tens tens1 =num1 tens2 =num2 ones_carry 0 ?retrieval> buffer empty state free ==> =g> isa math_goal op sub_tens +retrieval> isa math_op op greater arg1 =num1 arg2 =num2 """, ) sub_tens_ok = Model.productionstring( name="sub_tens_ok", string=""" =g> isa math_goal op sub_tens tens1 =num1 tens2 =num2 =retrieval> isa math_op op greater arg1 =num1 arg2 =num2 result =num1 ==> =g> isa math_goal op sub_tens +retrieval> isa math_op op add result =num1 arg1 =num2 """, ) # subtrahent greater than minuent sub_tens_too_large_start = Model.productionstring( name="sub_tens_too_large_start", string=""" =g> isa math_goal op sub_tens tens1 =num1 tens2 =num2 =retrieval> isa math_op op greater arg1 =num1 arg2 =num2 result =num2 ==> =g> isa math_goal op sub_tens tens_carry 1 +retrieval> isa math_op op add arg1 =num1 arg2 10 """, ) sub_tens_too_large_done = Model.productionstring( name="sub_tens_too_large_done", string=""" =g> isa math_goal op sub_tens tens1 =num1 tens2 =num2 tens_carry 1 =retrieval> isa math_op op add arg1 =num1 arg2 10 result =result ==> =g> isa math_goal op sub_tens +retrieval> isa math_op op add result =result arg1 =num2 """, ) sub_tens_done = Model.productionstring( name="sub_tens_done", string=""" =g> isa math_goal op sub_tens tens2 =num2 =retrieval> isa math_op op add arg1 =num2 arg2 =result ==> =g> isa math_goal op sub_hundreds tens_ans =result ~retrieval> """, ) sub_hundreds_with_carry = Model.productionstring( name="sub_hundreds_with_carry", string=""" =g> isa math_goal op sub_hundreds hundreds1 =num1 hundreds2 =num2 tens_carry 1 ?retrieval> buffer empty state free ==> =g> isa math_goal op sub_hundreds +retrieval> isa math_op op add arg1 1 arg2 =num2 """, ) sub_hundreds_with_carry_done = Model.productionstring( name="sub_hundreds_with_carry_done", string=""" =g> isa math_goal op sub_hundreds hundreds1 =num1 hundreds2 =num2 tens_carry 1 =retrieval> isa math_op op add arg1 1 arg2 =num2 result ~10 result =result ==> =g> isa math_goal op sub_hundreds tens_carry 0 hundreds2 =result ~retrieval> """, ) sub_hundreds_with_carry_done_10 = Model.productionstring( name="sub_hundreds_with_carry_done_10", string=""" =g> isa math_goal op sub_hundreds hundreds1 =num1 hundreds2 =num2 tens_carry 1 =retrieval> isa math_op op add arg1 1 arg2 =num2 result 10 ==> =g> isa math_goal op sub_hundreds tens_carry 0 hundreds_carry 1 hundreds2 0 ~retrieval> """, ) sub_hundreds_no_carry = Model.productionstring( name="sub_hundreds_no_carry", string=""" =g> isa math_goal op sub_hundreds hundreds1 =num1 hundreds2 =num2 tens_carry 0 ?retrieval> buffer empty state free ==> =g> isa math_goal op sub_hundreds +retrieval> isa math_op op greater arg1 =num1 arg2 =num2 """, ) sub_hundreds_ok = Model.productionstring( name="sub_hundreds_ok", string=""" =g> isa math_goal op sub_hundreds hundreds1 =num1 hundreds2 =num2 =retrieval> isa math_op op greater arg1 =num1 arg2 =num2 result =num1 ==> =g> isa math_goal op sub_hundreds +retrieval> isa math_op op add result =num1 arg1 =num2 """, ) # subtrahent greater than minuent sub_hundreds_too_large_start = Model.productionstring( name="sub_hundreds_too_large_start", string=""" =g> isa math_goal op sub_hundreds hundreds1 =num1 hundreds2 =num2 =retrieval> isa math_op op greater arg1 =num1 arg2 =num2 result =num2 ==> =g> isa math_goal op sub_hundreds hundreds_carry 1 +retrieval> isa math_op op add arg1 =num1 arg2 10 """, ) sub_hundreds_too_large_done = Model.productionstring( name="sub_hundreds_too_large_done", string=""" =g> isa math_goal op sub_hundreds hundreds1 =num1 hundreds2 =num2 hundreds_carry 1 =retrieval> isa math_op op add arg1 =num1 arg2 10 result =result ==> =g> isa math_goal op sub_hundreds +retrieval> isa math_op op add result =result arg1 =num2 """, ) sub_hundreds_done = Model.productionstring( name="sub_hundreds_done", string=""" =g> isa math_goal op sub_hundreds hundreds1 =num1 hundreds2 =num2 =retrieval> isa math_op op add arg1 =num2 arg2 =result ==> =g> isa math_goal op sub_done hundreds_ans =result ~retrieval> """, ) sub_done = Model.productionstring( name="sub_done", string=""" =g> isa math_goal op sub_done arg1 =arg1 arg2 =arg2 result ~None result =result ==> +imaginal> isa math_op op sub arg1 =arg1 arg2 =arg2 result =result =g> isa math_goal op done ones_carry None tens_carry None ~retrieval> """, ) return prods