diff options
author | Niclas Dobbertin <niclas.dobbertin@mailbox.org> | 2024-07-05 15:18:04 +0200 |
---|---|---|
committer | Niclas Dobbertin <niclas.dobbertin@mailbox.org> | 2024-07-05 15:18:04 +0200 |
commit | 4721cd226e693c1933c22d643d982d29e9b59121 (patch) | |
tree | 85eb48a9fc0e0bfba7f91e7f82d91c6e5e7aeee9 /modeling/prod_subtraction.py | |
parent | 751895424dc1b5ff41d67648df263f08680c5d4f (diff) |
added subtraction
Diffstat (limited to 'modeling/prod_subtraction.py')
-rw-r--r-- | modeling/prod_subtraction.py | 600 |
1 files changed, 600 insertions, 0 deletions
diff --git a/modeling/prod_subtraction.py b/modeling/prod_subtraction.py new file mode 100644 index 0000000..a0ac8b7 --- /dev/null +++ b/modeling/prod_subtraction.py @@ -0,0 +1,600 @@ +#!/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 + ==> + =g> + isa math_goal + +retrieval> + isa math_op + op sub + arg1 =arg1 + arg2 =arg2 + """, + ) + + # Can remember addition fact, addition done + sub_retrieve_success = Model.productionstring( + name="sub_retrieve_success", + string=""" + =g> + isa math_goal + op sub + arg1 =arg1 + arg2 =arg1 + =retrieval> + isa math_op + op add + arg1 =arg1 + arg2 =arg2 + result =result + ==> + =g> + isa math_goal + op done + result =result + +imaginal> + isa math_op + op sub + arg1 =arg1 + arg2 =arg2 + result =result + ~retrieval> + """, + ) + sub_retrieve_failure = Model.productionstring( + name="sub_retrieve_failure", + string=""" + =g> + isa math_goal + op sub + 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_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> + 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> + 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> + 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> + 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 |