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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started