Average Error: 58.3 → 0.0
Time: 1.1m
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\tanh x\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\tanh x
double f(double x) {
        double r42034 = x;
        double r42035 = exp(r42034);
        double r42036 = -r42034;
        double r42037 = exp(r42036);
        double r42038 = r42035 - r42037;
        double r42039 = r42035 + r42037;
        double r42040 = r42038 / r42039;
        return r42040;
}

double f(double x) {
        double r42041 = x;
        double r42042 = tanh(r42041);
        return r42042;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 58.3

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
  2. Using strategy rm
  3. Applied tanh-undef0.0

    \[\leadsto \color{blue}{\tanh x}\]
  4. Final simplification0.0

    \[\leadsto \tanh x\]

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic tangent"
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))