Question: Write all functions in SCALA using a strict functional paradigm. In this question, you are required to implement addition, subtraction, multiplication and division of two

Write all functions in SCALA using a strict functional paradigm.

In this question, you are required to implement addition, subtraction, multiplication and division of two natural numbers. However, you are not allowed to use the standard mathematical operators in your implementation! You will only have access to two functions: Successor(x) and Predecessor(x), which will return x + 1 and x 1 respectively. Moreover, you are not allowed to use constants other than the number 0 inside your functions. For example, to write an expression such as (n > 1), you would write (n > Successor(0)). You need to implement 4 functions: add(x, y), minus(x, y), multiply(x, y) and divide(x, y).

Note: Division here is defined as integer division, so that 7/ 2 = 3. You are not required to handle division by 0.

Using the above functions (and possibly more), implement a boolean-valued function that takes a number n and returns true iff n is a prime number.

Write all functions in SCALA using a strict functional paradigm.

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!