Question: Use Scheme to solve this Consider that the + and - builtin functions of scheme are broken and that you cannot use them. The only

Use Scheme to solve this

Use Scheme to solve this Consider that the + and - builtin

Consider that the + and - builtin functions of scheme are broken and that you cannot use them. The only math- ematical operations that work normally are the usual comparisons and boolean operators (i.e., and, or, not as well as ,2,= all work fine). Your task is to rebuild addition (the same as the builtin +. Thankfully, this broken version of SCHEME has two working functions to increment an integer by 1 and decrement an integer by 1. Both could be implemented with (define (inc x) (+ x 1)) (define (dec x) (- x 1)) Your task is to implement the function add such that, for instance, (add 3 10) produces the answer 13. Your add function is expected to work on non-negative integers (namely, the naturals). Your function starts like (define (add n m) ...) And can only make use of inc and dec to do any kind of arithmetic. Observe that the following simple identities an n> 0 (add :- 1) + (m +1) n m) on=0 { m are true. Namely, if you adopt a set-based interpretation of natural numbers (a natural number is a bag of pebbles), then to combine two bags of pebbles, one simply needs to move pebbles from one bag to the other, one by one... Consider that the + and - builtin functions of scheme are broken and that you cannot use them. The only math- ematical operations that work normally are the usual comparisons and boolean operators (i.e., and, or, not as well as ,2,= all work fine). Your task is to rebuild addition (the same as the builtin +. Thankfully, this broken version of SCHEME has two working functions to increment an integer by 1 and decrement an integer by 1. Both could be implemented with (define (inc x) (+ x 1)) (define (dec x) (- x 1)) Your task is to implement the function add such that, for instance, (add 3 10) produces the answer 13. Your add function is expected to work on non-negative integers (namely, the naturals). Your function starts like (define (add n m) ...) And can only make use of inc and dec to do any kind of arithmetic. Observe that the following simple identities an n> 0 (add :- 1) + (m +1) n m) on=0 { m are true. Namely, if you adopt a set-based interpretation of natural numbers (a natural number is a bag of pebbles), then to combine two bags of pebbles, one simply needs to move pebbles from one bag to the other, one by one

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!