Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need to use Coq functional programming language to solve below question: Problem 5 (22 points). General Trees: (a) Define the polymorphic inductive type tree X

Need to use Coq functional programming language to solve below question:

Problem 5 (22 points). General Trees:

(a) Define the polymorphic inductive type tree X for trees with arbitrary number of subtrees in each

node. (4 points)

(b) Define mytree of type tree nat depicted in Figure 1. (3 points)

image text in transcribed

(c) Define a polymorphic function isleaf that checks whether a general tree is a leaf. (4 points)

(d) As a unit test, show that mytree is not a leaf. (1 points)

(e) Define a polymorphic function height that computes the height of general trees. (4 points) Hint:

You may need to define mutually recursive functions using let expressions.

(f) As a unit test, show that the height of mytree is 3. (1 points)

(g) Define a monomorphic function sum_nodes that returns the summation of values within all nodes

of a general tree of type tree nat. (4 points) Hint: You may need to define mutually recursive

functions using let expressions.

(h) As a unit test, show that sum_nodes of mytree is 30. (1 points)

1 5 8 7 3 2 4 Figure 1: mytree

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

Name and define the six major elements of the accounting equation.

Answered: 1 week ago

Question

6. Discuss the steps involved in conducting a task analysis.

Answered: 1 week ago