Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions