Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The following definitions: def inc(n: Int) = n + 1 def dec(n: Int) = n 1 def isZero(n: Int) = n == 0 In the
The following definitions:
def inc(n: Int) = n + 1 def dec(n: Int) = n 1 def isZero(n: Int) = n == 0
In the following problems, your solutions may assume that all inputs are non-negative integers (these are sometimes called the natural numbers).
Problem_1
Re-define the function:
add(n: Int, m: Int) = n + m
Your definition should only use classical recursion(not tail recursion), inc, dec, and isZero.
Problem_2
Re-define the function:
mul(n: Int, m: Int) = n * m
Your definition should only use classical recursion, add, inc, dec, and isZero.
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