Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

INTRODUCTION In this THE, we will construct trees representing calculations as defined by a set of functions of a fixed variable ' x '. Function

image text in transcribed
image text in transcribed
INTRODUCTION In this THE, we will construct trees representing calculations as defined by a set of functions of a fixed variable ' x '. Function definitions will conform to the following rules: where a vertical bar (' I ') separates alternatives; and ' +,,,,,,, respectively denote addition, subtraction, multiplication and exponentiation. For exponentiation, you can assume that either the base or the exponent term> is a . A "running" example set of functions conforming to these rules is the following: f(x)=g(x)xg(x)=x+20h(x)=x100 PROBLEM \& SPECIFICATIONS - In this THE, we expect you to write a function named construct_forest with the following parameter and return values: - Parameter: [f unction-def 1, function-def 2, ] * Description: A list of strings where each string defines a function. * Example: ["g g(x)=x+20","h(x)=x100","f(x)=g(x)x] - Return: [Tree1, Tree2, ...] Figure 1: The forest (set of trees) representing the set of function definitions for our running example. - Description: A list of trees for each linbed set of function definitions such that (i) each tree starts with a function node and through the branches the linked function definitions are represented, and (ii) each independent set of function definitions is represented as a separate tree. - Syntax for a treer A function node is represented as: [f unction, operator, term1, term2], where function (str), operator (str), term1 (list) and term2 (list) represent concepts as defined in Introduction. term1 and term2 are lists representing terms, which may be defining another function, a constant or a variable (x). A constant or a variable term is represented as [constant] or [' x '] respectively, as lists. * Example: For ["g(x)=x+20,"h(x)=x100,"f(x)=g(x)x]. the expected return value is as follows: - To simplify the problem, yon can assume that no two trees share functions. - A function definition (str) can contain arbitrary number of spaces between function-names, operators, variables, constants and pareatheses, E-g-, the following are all valid and equal: "f (x)=x20,"f(x)=x20,"f(x)=x20. - The order of trees in the forest is not inportant. However, the order of branches should follow the order of the terms in the definitions. - There may not be recursion or cyclic links between functions. SAMPLE RUN P Defa =["g(x)=x+20,"h(x)=x100,"f(x)=g(x)x] \> Forest = construct_forest (Defs) \$> print(Forest) [[f,,[g,t,[x],[x]]],[xx]],[h,,[x],[x100]]]

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions