Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Set 5b [20 points] For this assignment you are to take the parse tree that you made in Problem Set 5, as input and

Problem Set 5b [20 points]

For this assignment you are to take the parse tree that you made in Problem Set 5, as input and create and print a derivative tree. The derivative tree should be a binary tree with the nodes that contain the normal data, left, right, and parent fields.

The derivative of an expression that involves the variable x or X can be defined by a few recursive rules:

If A is an expression, let D(A) be the derivative of A.

The derivative of a constant is 0. D(C) = 0.

The derivative of x or X is 1. D(x) = D(X) = 1.

If A and B are expressions, let D(A) be the derivative of A and D(B) be the derivative of B. Then

The D(A + B) is D(A) + D(B).

The D(A - B) is D(A) - D(B).

The D(A * B) is (A * D(B)) + (B * D(A)).

The D(A / B) is ((B * D(A)) - (A * D(B))) / (B * B) [Extra Credit]

this is some of the code but only the node part

def D(node):

if node.op in "0123456789":

return 0

elif node.op in "x":

return 1

elfi node.op in "+":

return D(node.left) + D(node.right)

elif node.op in "-":

return D(node.left) - D(node.right)

elif node.op in "*":

(A*D(B)) + (B*D(A))

elif node.op = "/"

((B*D(A)) - (A*D(B)) / (B*B)

this is what i have so far i need help on the rest

This code has to be written in Python language

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions