Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To define the functions (whatever is on the right-hand side of the '='), only use: - The initial primitive recursive functions (above) - The primitive

To define the functions (whatever is on the right-hand side of the '='), only use:

- The initial primitive recursive functions (above)

- The primitive recursive operators (above)

- Previously defined primitive recursive functions

Here is the HASKELL code:

type PN = [Char] type Vec = [PN]

-- 1) Zero function z :: Vec -> PN z x = "0"

-- 2) Successor function s :: Vec -> PN s x = ('S':(head x))

-- 3) Projection function pr :: Int -> (Vec -> PN) pr n = \x -> x !! (n-1)

-- 4) Composition circ :: (Vec -> PN) -> [(Vec -> PN)] -> (Vec -> PN) circ f gs = \x -> f $ sequence gs x

-- 5) Primitive recursion operator rho :: (Vec -> PN) -> (Vec -> PN) -> (Vec -> PN) rho f g = h where h ("0":xs) = f xs h (('S':n):xs) = g $ n:((h (n:xs)):xs)

-- 6) Addition function : add(n, x) = n + x add = rho f_add g_add f_add = g_add =

-- 7) Subtraction function : sub(n, x) = n - x

-- 8) Predecessor function : pred(n) = n - 1

-- 9) Truncated Subtraction function : tsub(n, x) = x - n if x > n, 0 otherwise

-- 10) Multipication function : mult(n, x) = n * x

-- 11) Exponent function : expo(n, x) = n^x

-- 12) Boolean Signature function : sig(n) = 0 is n = 0, 1 otherwise

-- 13) Equality function : eq(n, x) = 0 if n = x, 1 otherwise

Please complete the code!

Here is an example output:

image text in transcribed

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

More Books

Students also viewed these Databases questions