Question: MUST BE WRITTEN IN SCALA Write a function derivativeExpr that calculates the derivative of an expression e w.r.t a given identifier as a string x
MUST BE WRITTEN IN SCALA 
Write a function derivativeExpr that calculates the derivative of an expression e w.r.t a given identifier as a string x def derivativeExpr (e: Expr, x: String): Expr{ YOUR CODE HERE derivativeExpr (e: Expr, x: String)Expr BEGIN TESTS TEST HELPERS evalExpr (e: Expr, env: Map[String, Double]): Double e match case Const (f) >f case Ident (str) if (env.contains (str)) env(str) else throw new IllegalArgumentException(s Environment does not cont for $str" case Plus (e1, e2) > { alExpr(e1, env)) (evalExpr(e2, env)) Minus(e1, (evalExpr (el, env)) e2) -> { case (evalExpr(e2, env)) Mult(e1, (evalExpr (el, e2) { env)) case (evalExpr (e2, env)) * Write a function derivativeExpr that calculates the derivative of an expression e w.r.t a given identifier as a string x def derivativeExpr (e: Expr, x: String): Expr{ YOUR CODE HERE derivativeExpr (e: Expr, x: String)Expr BEGIN TESTS TEST HELPERS evalExpr (e: Expr, env: Map[String, Double]): Double e match case Const (f) >f case Ident (str) if (env.contains (str)) env(str) else throw new IllegalArgumentException(s Environment does not cont for $str" case Plus (e1, e2) > { alExpr(e1, env)) (evalExpr(e2, env)) Minus(e1, (evalExpr (el, env)) e2) -> { case (evalExpr(e2, env)) Mult(e1, (evalExpr (el, e2) { env)) case (evalExpr (e2, env)) *
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
