TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
Study Plan
Differentiate Exponentials and Powers
Calculus
Medium

Evaluate the exponential and constant-power functions at x, and compute each input-gradient contribution for the supplied upstream_gradient.

yexp=exy_{\mathrm{exp}}=e^xyexp​=ex gexp=uexg_{\mathrm{exp}}=u e^xgexp​=uex ypower=xny_{\mathrm{power}}=x^nypower​=xn gpower=unxn−1g_{\mathrm{power}}=u n x^{n-1}gpower​=unxn−1

Here x is the scalar input, n is exponent, u is the upstream gradient, y denotes a function's output, and g denotes its input-gradient contribution. For a zero exponent, define the power output as 1.0 and its gradient as 0.0, including when x is zero.

Return a tuple of four 64-bit floating-point numbers in this order: exponential output, exponential gradient, power output, power gradient.

Loading visualization...

Examples

Input: x = 2, exponent = 0, upstream_gradient = 3

Output: (7.389056, 22.167168, 1.0, 0.0)

Explanation: The zero power is constant, so its gradient contribution is zero.

Input: x = 2, exponent = -2, upstream_gradient = -0.5

Output: (7.389056, -3.694528, 0.25, 0.125)

Input: x = -2, exponent = 3, upstream_gradient = 2

Output: (0.135335, 0.270671, -8.0, 24.0)

Hint 1

np.exp evaluates the exponential for a scalar.

Hint 2

np.power supports fractional exponents for positive bases.

Hint 3

Handle exponent zero before evaluating a negative power of the base.

Requirements

  • Use 64-bit floating-point arithmetic; NumPy is available.
  • Compute both gradient contributions manually for the supplied upstream gradient.

Constraints

  • x, exponent, and upstream_gradient are finite real numbers.
  • A negative x has an integer-valued exponent.
  • When x is zero, exponent is zero or at least one.
  • Inputs keep all four results finite and real in 64-bit floating point.
Try Similar Problems
Accumulate Shared-Path GradientsMediumBackpropagate Through a Scalar NeuronMediumTopologically Sort a Computation DAGMediumTrace a Reachable Expression GraphMediumGradient-Check a Scalar NeuronMediumBuild a Scalar Expression GraphMediumCheck a Product-Chain GradientMediumApply Local Vector-Jacobian RulesEasyFinite Difference Gradient CheckingMediumHessian Tensor of a Vector-Valued FunctionMediumHigher-Order Derivatives & Loss CurvatureMediumContinuity of Activation FunctionsMedium

Accepts: number

Accepts: number

Accepts: number

You must run your code first.

Differentiate Exponentials and Powers

Calculus
Medium

Evaluate the exponential and constant-power functions at x, and compute each input-gradient contribution for the supplied upstream_gradient.

yexp=exy_{\mathrm{exp}}=e^xyexp​=ex gexp=uexg_{\mathrm{exp}}=u e^xgexp​=uex ypower=xny_{\mathrm{power}}=x^nypower​=xn gpower=unxn−1g_{\mathrm{power}}=u n x^{n-1}gpower​=unxn−1

Here x is the scalar input, n is exponent, u is the upstream gradient, y denotes a function's output, and g denotes its input-gradient contribution. For a zero exponent, define the power output as 1.0 and its gradient as 0.0, including when x is zero.

Return a tuple of four 64-bit floating-point numbers in this order: exponential output, exponential gradient, power output, power gradient.

Loading visualization...

Examples

Input: x = 2, exponent = 0, upstream_gradient = 3

Output: (7.389056, 22.167168, 1.0, 0.0)

Explanation: The zero power is constant, so its gradient contribution is zero.

Input: x = 2, exponent = -2, upstream_gradient = -0.5

Output: (7.389056, -3.694528, 0.25, 0.125)

Input: x = -2, exponent = 3, upstream_gradient = 2

Output: (0.135335, 0.270671, -8.0, 24.0)

Hint 1

np.exp evaluates the exponential for a scalar.

Hint 2

np.power supports fractional exponents for positive bases.

Hint 3

Handle exponent zero before evaluating a negative power of the base.

Requirements

  • Use 64-bit floating-point arithmetic; NumPy is available.
  • Compute both gradient contributions manually for the supplied upstream gradient.

Constraints

  • x, exponent, and upstream_gradient are finite real numbers.
  • A negative x has an integer-valued exponent.
  • When x is zero, exponent is zero or at least one.
  • Inputs keep all four results finite and real in 64-bit floating point.
Try Similar Problems
Accumulate Shared-Path GradientsMediumBackpropagate Through a Scalar NeuronMediumTopologically Sort a Computation DAGMediumTrace a Reachable Expression GraphMediumGradient-Check a Scalar NeuronMediumBuild a Scalar Expression GraphMediumCheck a Product-Chain GradientMediumApply Local Vector-Jacobian RulesEasyFinite Difference Gradient CheckingMediumHessian Tensor of a Vector-Valued FunctionMediumHigher-Order Derivatives & Loss CurvatureMediumContinuity of Activation FunctionsMedium

Accepts: number

Accepts: number

Accepts: number

You must run your code first.