?

Average Error: 29.0 → 0.5
Time: 10.5s
Precision: binary64
Cost: 32896

?

\[\left(e^{x} - 2\right) + e^{-x} \]
\[\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(x, x, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.002777777777777778 \cdot {x}^{6}\right)\right) \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
 :precision binary64
 (fma
  0.08333333333333333
  (pow x 4.0)
  (fma
   x
   x
   (+
    (* 4.96031746031746e-5 (pow x 8.0))
    (* 0.002777777777777778 (pow x 6.0))))))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	return fma(0.08333333333333333, pow(x, 4.0), fma(x, x, ((4.96031746031746e-5 * pow(x, 8.0)) + (0.002777777777777778 * pow(x, 6.0)))));
}
function code(x)
	return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
function code(x)
	return fma(0.08333333333333333, (x ^ 4.0), fma(x, x, Float64(Float64(4.96031746031746e-5 * (x ^ 8.0)) + Float64(0.002777777777777778 * (x ^ 6.0)))))
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision] + N[(x * x + N[(N[(4.96031746031746e-5 * N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision] + N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(x, x, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.002777777777777778 \cdot {x}^{6}\right)\right)

Error?

Target

Original29.0
Target0.0
Herbie0.5
\[4 \cdot {\sinh \left(\frac{x}{2}\right)}^{2} \]

Derivation?

  1. Initial program 29.0

    \[\left(e^{x} - 2\right) + e^{-x} \]
  2. Simplified29.0

    \[\leadsto \color{blue}{e^{x} + \left(e^{-x} + -2\right)} \]
    Proof

    [Start]29.0

    \[ \left(e^{x} - 2\right) + e^{-x} \]

    associate-+l- [=>]29.0

    \[ \color{blue}{e^{x} - \left(2 - e^{-x}\right)} \]

    sub-neg [=>]29.0

    \[ \color{blue}{e^{x} + \left(-\left(2 - e^{-x}\right)\right)} \]

    neg-sub0 [=>]29.0

    \[ e^{x} + \color{blue}{\left(0 - \left(2 - e^{-x}\right)\right)} \]

    associate--r- [=>]29.0

    \[ e^{x} + \color{blue}{\left(\left(0 - 2\right) + e^{-x}\right)} \]

    metadata-eval [=>]29.0

    \[ e^{x} + \left(\color{blue}{-2} + e^{-x}\right) \]

    metadata-eval [<=]29.0

    \[ e^{x} + \left(\color{blue}{\left(-2\right)} + e^{-x}\right) \]

    +-commutative [=>]29.0

    \[ e^{x} + \color{blue}{\left(e^{-x} + \left(-2\right)\right)} \]

    metadata-eval [=>]29.0

    \[ e^{x} + \left(e^{-x} + \color{blue}{-2}\right) \]
  3. Taylor expanded in x around 0 0.5

    \[\leadsto \color{blue}{0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)} \]
  4. Simplified0.5

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, \mathsf{fma}\left(0.08333333333333333, {x}^{4}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right)} \]
    Proof

    [Start]0.5

    \[ 0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right) \]

    fma-def [=>]0.5

    \[ \color{blue}{\mathsf{fma}\left(0.002777777777777778, {x}^{6}, {x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)} \]

    unpow2 [=>]0.5

    \[ \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \color{blue}{x \cdot x} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right) \]

    fma-def [=>]0.5

    \[ \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \color{blue}{\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)}\right) \]

    fma-def [=>]0.5

    \[ \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)}\right)\right) \]
  5. Taylor expanded in x around 0 0.5

    \[\leadsto \color{blue}{0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)} \]
  6. Simplified0.5

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(x, x, \mathsf{fma}\left(4.96031746031746 \cdot 10^{-5}, {x}^{8}, 0.002777777777777778 \cdot {x}^{6}\right)\right)\right)} \]
    Proof

    [Start]0.5

    \[ 0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right) \]

    associate-+r+ [=>]0.5

    \[ \color{blue}{\left(0.002777777777777778 \cdot {x}^{6} + {x}^{2}\right) + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)} \]

    unpow2 [=>]0.5

    \[ \left(0.002777777777777778 \cdot {x}^{6} + \color{blue}{x \cdot x}\right) + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right) \]

    +-commutative [<=]0.5

    \[ \color{blue}{\left(x \cdot x + 0.002777777777777778 \cdot {x}^{6}\right)} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right) \]

    +-commutative [=>]0.5

    \[ \left(x \cdot x + 0.002777777777777778 \cdot {x}^{6}\right) + \color{blue}{\left(4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.08333333333333333 \cdot {x}^{4}\right)} \]

    associate-+l+ [<=]0.5

    \[ \color{blue}{\left(\left(x \cdot x + 0.002777777777777778 \cdot {x}^{6}\right) + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right) + 0.08333333333333333 \cdot {x}^{4}} \]

    +-commutative [=>]0.5

    \[ \color{blue}{0.08333333333333333 \cdot {x}^{4} + \left(\left(x \cdot x + 0.002777777777777778 \cdot {x}^{6}\right) + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)} \]

    fma-def [=>]0.5

    \[ \color{blue}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \left(x \cdot x + 0.002777777777777778 \cdot {x}^{6}\right) + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)} \]

    associate-+l+ [=>]0.5

    \[ \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \color{blue}{x \cdot x + \left(0.002777777777777778 \cdot {x}^{6} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)}\right) \]

    +-commutative [=>]0.5

    \[ \mathsf{fma}\left(0.08333333333333333, {x}^{4}, x \cdot x + \color{blue}{\left(4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.002777777777777778 \cdot {x}^{6}\right)}\right) \]

    fma-def [=>]0.5

    \[ \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \color{blue}{\mathsf{fma}\left(x, x, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.002777777777777778 \cdot {x}^{6}\right)}\right) \]

    fma-def [=>]0.5

    \[ \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(4.96031746031746 \cdot 10^{-5}, {x}^{8}, 0.002777777777777778 \cdot {x}^{6}\right)}\right)\right) \]
  7. Applied egg-rr0.5

    \[\leadsto \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(x, x, \color{blue}{4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.002777777777777778 \cdot {x}^{6}}\right)\right) \]
  8. Final simplification0.5

    \[\leadsto \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(x, x, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.002777777777777778 \cdot {x}^{6}\right)\right) \]

Alternatives

Alternative 1
Error0.5
Cost20352
\[4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + \left(\left(0.002777777777777778 \cdot {x}^{6} + x \cdot x\right) + 0.08333333333333333 \cdot {x}^{4}\right) \]
Alternative 2
Error0.6
Cost13632
\[x \cdot x + \left(0.002777777777777778 \cdot {x}^{6} + 0.08333333333333333 \cdot {x}^{4}\right) \]
Alternative 3
Error0.7
Cost13184
\[\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right) \]
Alternative 4
Error0.7
Cost6912
\[x \cdot x + 0.08333333333333333 \cdot {x}^{4} \]
Alternative 5
Error1.1
Cost192
\[x \cdot x \]

Error

Reproduce?

herbie shell --seed 2023060 
(FPCore (x)
  :name "exp2 (problem 3.3.7)"
  :precision binary64

  :herbie-target
  (* 4.0 (pow (sinh (/ x 2.0)) 2.0))

  (+ (- (exp x) 2.0) (exp (- x))))