Average Error: 58.2 → 1.5
Time: 4.5s
Precision: binary64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
\[\frac{\mathsf{fma}\left(0.016666666666666666, {x}^{5}, \mathsf{fma}\left(0.0003968253968253968, {x}^{7}, \mathsf{fma}\left(2, x, 0.3333333333333333 \cdot {x}^{3}\right)\right)\right)}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 2\right)\right)\right)} \]
(FPCore (x)
 :precision binary64
 (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))
(FPCore (x)
 :precision binary64
 (/
  (fma
   0.016666666666666666
   (pow x 5.0)
   (fma
    0.0003968253968253968
    (pow x 7.0)
    (fma 2.0 x (* 0.3333333333333333 (pow x 3.0)))))
  (fma
   0.08333333333333333
   (pow x 4.0)
   (fma 0.002777777777777778 (pow x 6.0) (fma x x 2.0)))))
double code(double x) {
	return (exp(x) - exp(-x)) / (exp(x) + exp(-x));
}
double code(double x) {
	return fma(0.016666666666666666, pow(x, 5.0), fma(0.0003968253968253968, pow(x, 7.0), fma(2.0, x, (0.3333333333333333 * pow(x, 3.0))))) / fma(0.08333333333333333, pow(x, 4.0), fma(0.002777777777777778, pow(x, 6.0), fma(x, x, 2.0)));
}
function code(x)
	return Float64(Float64(exp(x) - exp(Float64(-x))) / Float64(exp(x) + exp(Float64(-x))))
end
function code(x)
	return Float64(fma(0.016666666666666666, (x ^ 5.0), fma(0.0003968253968253968, (x ^ 7.0), fma(2.0, x, Float64(0.3333333333333333 * (x ^ 3.0))))) / fma(0.08333333333333333, (x ^ 4.0), fma(0.002777777777777778, (x ^ 6.0), fma(x, x, 2.0))))
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(0.016666666666666666 * N[Power[x, 5.0], $MachinePrecision] + N[(0.0003968253968253968 * N[Power[x, 7.0], $MachinePrecision] + N[(2.0 * x + N[(0.3333333333333333 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision] + N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision] + N[(x * x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{\mathsf{fma}\left(0.016666666666666666, {x}^{5}, \mathsf{fma}\left(0.0003968253968253968, {x}^{7}, \mathsf{fma}\left(2, x, 0.3333333333333333 \cdot {x}^{3}\right)\right)\right)}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 2\right)\right)\right)}

Error

Bits error versus x

Derivation

  1. Initial program 58.2

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Taylor expanded in x around 0 1.6

    \[\leadsto \frac{\color{blue}{0.016666666666666666 \cdot {x}^{5} + \left(0.0003968253968253968 \cdot {x}^{7} + \left(0.3333333333333333 \cdot {x}^{3} + 2 \cdot x\right)\right)}}{e^{x} + e^{-x}} \]
  3. Simplified1.6

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(0.016666666666666666, {x}^{5}, \mathsf{fma}\left(0.0003968253968253968, {x}^{7}, \mathsf{fma}\left(2, x, 0.3333333333333333 \cdot {x}^{3}\right)\right)\right)}}{e^{x} + e^{-x}} \]
  4. Taylor expanded in x around 0 1.5

    \[\leadsto \frac{\mathsf{fma}\left(0.016666666666666666, {x}^{5}, \mathsf{fma}\left(0.0003968253968253968, {x}^{7}, \mathsf{fma}\left(2, x, 0.3333333333333333 \cdot {x}^{3}\right)\right)\right)}{\color{blue}{0.08333333333333333 \cdot {x}^{4} + \left(2 + \left(0.002777777777777778 \cdot {x}^{6} + {x}^{2}\right)\right)}} \]
  5. Simplified1.5

    \[\leadsto \frac{\mathsf{fma}\left(0.016666666666666666, {x}^{5}, \mathsf{fma}\left(0.0003968253968253968, {x}^{7}, \mathsf{fma}\left(2, x, 0.3333333333333333 \cdot {x}^{3}\right)\right)\right)}{\color{blue}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 2\right)\right)\right)}} \]
  6. Final simplification1.5

    \[\leadsto \frac{\mathsf{fma}\left(0.016666666666666666, {x}^{5}, \mathsf{fma}\left(0.0003968253968253968, {x}^{7}, \mathsf{fma}\left(2, x, 0.3333333333333333 \cdot {x}^{3}\right)\right)\right)}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 2\right)\right)\right)} \]

Reproduce

herbie shell --seed 2022134 
(FPCore (x)
  :name "Hyperbolic tangent"
  :precision binary64
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))