Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I am very confused by this question in OCAML, so if anyone could shed some light on it, it would be great! Thanks! We

Hi, I am very confused by this question in OCAML, so if anyone could shed some light on it, it would be great! Thanks!

We can represent binary numbers as a list of increasing integers where each element is a power of two:

type nat = int list For example: 5 = [1; 4] or 15 = [1; 2; 4; 8] or 17 = [1; 16].

We can represent 0 with the empty list. The sparse representation can be a more useful way of representing numbers than using a dense representation (i.e. one using ones and zeroes), especially for human-readable arithmetic.

1) Implement a function inc : nat -> nat which increments a given sparse binary number in OCAML.

let inc (ws : nat ) : nat =

2) Implement a function dec : nat -> nat which decrements (i.e., subtracts one from) a given sparse binary number. If given 0 as input, you should raise the exception Domain IN OCAML.

let dec (ws : nat) : nat =

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

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

Students also viewed these Databases questions

Question

What is Ohm's law and also tell about Snell's law?

Answered: 1 week ago