
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 2.0d0) + exp(-x)
end function
public static double code(double x) {
return (Math.exp(x) - 2.0) + Math.exp(-x);
}
def code(x): return (math.exp(x) - 2.0) + math.exp(-x)
function code(x) return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) end
function tmp = code(x) tmp = (exp(x) - 2.0) + exp(-x); end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(e^{x} - 2\right) + e^{-x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 2.0d0) + exp(-x)
end function
public static double code(double x) {
return (Math.exp(x) - 2.0) + Math.exp(-x);
}
def code(x): return (math.exp(x) - 2.0) + math.exp(-x)
function code(x) return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) end
function tmp = code(x) tmp = (exp(x) - 2.0) + exp(-x); end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(e^{x} - 2\right) + e^{-x}
\end{array}
(FPCore (x) :precision binary64 (+ (* 4.96031746031746e-5 (pow x 8.0)) (+ (* 0.002777777777777778 (pow x 6.0)) (fma x x (* 0.08333333333333333 (pow x 4.0))))))
double code(double x) {
return (4.96031746031746e-5 * pow(x, 8.0)) + ((0.002777777777777778 * pow(x, 6.0)) + fma(x, x, (0.08333333333333333 * pow(x, 4.0))));
}
function code(x) return Float64(Float64(4.96031746031746e-5 * (x ^ 8.0)) + Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + fma(x, x, Float64(0.08333333333333333 * (x ^ 4.0))))) end
code[x_] := N[(N[(4.96031746031746e-5 * N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + \left(0.002777777777777778 \cdot {x}^{6} + \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\right)
\end{array}
Initial program 57.6%
associate-+l-57.6%
sub-neg57.6%
sub-neg57.6%
distribute-neg-in57.6%
remove-double-neg57.6%
+-commutative57.6%
metadata-eval57.6%
Simplified57.6%
Taylor expanded in x around 0 99.3%
+-commutative99.3%
unpow299.3%
fma-def99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (+ (* 0.002777777777777778 (pow x 6.0)) (fma x x (* 0.08333333333333333 (pow x 4.0)))))
double code(double x) {
return (0.002777777777777778 * pow(x, 6.0)) + fma(x, x, (0.08333333333333333 * pow(x, 4.0)));
}
function code(x) return Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + fma(x, x, Float64(0.08333333333333333 * (x ^ 4.0)))) end
code[x_] := N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.002777777777777778 \cdot {x}^{6} + \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)
\end{array}
Initial program 57.6%
associate-+l-57.6%
sub-neg57.6%
sub-neg57.6%
distribute-neg-in57.6%
remove-double-neg57.6%
+-commutative57.6%
metadata-eval57.6%
Simplified57.6%
Taylor expanded in x around 0 99.1%
+-commutative99.3%
unpow299.3%
fma-def99.3%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x)
:precision binary64
(*
x
(*
x
(+
1.0
(+
(* (pow x 4.0) 0.003472222222222222)
(* 0.08333333333333333 (pow x 2.0)))))))
double code(double x) {
return x * (x * (1.0 + ((pow(x, 4.0) * 0.003472222222222222) + (0.08333333333333333 * pow(x, 2.0)))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * (1.0d0 + (((x ** 4.0d0) * 0.003472222222222222d0) + (0.08333333333333333d0 * (x ** 2.0d0)))))
end function
public static double code(double x) {
return x * (x * (1.0 + ((Math.pow(x, 4.0) * 0.003472222222222222) + (0.08333333333333333 * Math.pow(x, 2.0)))));
}
def code(x): return x * (x * (1.0 + ((math.pow(x, 4.0) * 0.003472222222222222) + (0.08333333333333333 * math.pow(x, 2.0)))))
function code(x) return Float64(x * Float64(x * Float64(1.0 + Float64(Float64((x ^ 4.0) * 0.003472222222222222) + Float64(0.08333333333333333 * (x ^ 2.0)))))) end
function tmp = code(x) tmp = x * (x * (1.0 + (((x ^ 4.0) * 0.003472222222222222) + (0.08333333333333333 * (x ^ 2.0))))); end
code[x_] := N[(x * N[(x * N[(1.0 + N[(N[(N[Power[x, 4.0], $MachinePrecision] * 0.003472222222222222), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(1 + \left({x}^{4} \cdot 0.003472222222222222 + 0.08333333333333333 \cdot {x}^{2}\right)\right)\right)
\end{array}
Initial program 57.6%
associate-+l-57.6%
sub-neg57.6%
sub-neg57.6%
distribute-neg-in57.6%
remove-double-neg57.6%
+-commutative57.6%
metadata-eval57.6%
Simplified57.6%
+-commutative57.6%
associate-+r+57.6%
metadata-eval57.6%
sub-neg57.6%
add-exp-log57.5%
sub-neg57.5%
metadata-eval57.5%
associate-+r+57.5%
+-commutative57.5%
associate-+r+57.5%
+-commutative57.5%
cosh-undef57.5%
Applied egg-rr57.5%
Taylor expanded in x around 0 49.8%
exp-sum49.8%
*-commutative49.8%
pow-to-exp98.8%
unpow298.8%
associate-*r*98.8%
*-commutative98.8%
exp-prod98.8%
Applied egg-rr98.8%
Taylor expanded in x around 0 98.8%
Final simplification98.8%
(FPCore (x)
:precision binary64
(*
x
(+
x
(+
(* 0.003472222222222222 (pow x 5.0))
(* 0.08333333333333333 (pow x 3.0))))))
double code(double x) {
return x * (x + ((0.003472222222222222 * pow(x, 5.0)) + (0.08333333333333333 * pow(x, 3.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x + ((0.003472222222222222d0 * (x ** 5.0d0)) + (0.08333333333333333d0 * (x ** 3.0d0))))
end function
public static double code(double x) {
return x * (x + ((0.003472222222222222 * Math.pow(x, 5.0)) + (0.08333333333333333 * Math.pow(x, 3.0))));
}
def code(x): return x * (x + ((0.003472222222222222 * math.pow(x, 5.0)) + (0.08333333333333333 * math.pow(x, 3.0))))
function code(x) return Float64(x * Float64(x + Float64(Float64(0.003472222222222222 * (x ^ 5.0)) + Float64(0.08333333333333333 * (x ^ 3.0))))) end
function tmp = code(x) tmp = x * (x + ((0.003472222222222222 * (x ^ 5.0)) + (0.08333333333333333 * (x ^ 3.0)))); end
code[x_] := N[(x * N[(x + N[(N[(0.003472222222222222 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x + \left(0.003472222222222222 \cdot {x}^{5} + 0.08333333333333333 \cdot {x}^{3}\right)\right)
\end{array}
Initial program 57.6%
associate-+l-57.6%
sub-neg57.6%
sub-neg57.6%
distribute-neg-in57.6%
remove-double-neg57.6%
+-commutative57.6%
metadata-eval57.6%
Simplified57.6%
+-commutative57.6%
associate-+r+57.6%
metadata-eval57.6%
sub-neg57.6%
add-exp-log57.5%
sub-neg57.5%
metadata-eval57.5%
associate-+r+57.5%
+-commutative57.5%
associate-+r+57.5%
+-commutative57.5%
cosh-undef57.5%
Applied egg-rr57.5%
Taylor expanded in x around 0 49.8%
exp-sum49.8%
*-commutative49.8%
pow-to-exp98.8%
unpow298.8%
associate-*r*98.8%
*-commutative98.8%
exp-prod98.8%
Applied egg-rr98.8%
Taylor expanded in x around 0 98.8%
Final simplification98.8%
(FPCore (x) :precision binary64 (* x (* x (exp (* 0.08333333333333333 (pow x 2.0))))))
double code(double x) {
return x * (x * exp((0.08333333333333333 * pow(x, 2.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * exp((0.08333333333333333d0 * (x ** 2.0d0))))
end function
public static double code(double x) {
return x * (x * Math.exp((0.08333333333333333 * Math.pow(x, 2.0))));
}
def code(x): return x * (x * math.exp((0.08333333333333333 * math.pow(x, 2.0))))
function code(x) return Float64(x * Float64(x * exp(Float64(0.08333333333333333 * (x ^ 2.0))))) end
function tmp = code(x) tmp = x * (x * exp((0.08333333333333333 * (x ^ 2.0)))); end
code[x_] := N[(x * N[(x * N[Exp[N[(0.08333333333333333 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot e^{0.08333333333333333 \cdot {x}^{2}}\right)
\end{array}
Initial program 57.6%
associate-+l-57.6%
sub-neg57.6%
sub-neg57.6%
distribute-neg-in57.6%
remove-double-neg57.6%
+-commutative57.6%
metadata-eval57.6%
Simplified57.6%
+-commutative57.6%
associate-+r+57.6%
metadata-eval57.6%
sub-neg57.6%
add-exp-log57.5%
sub-neg57.5%
metadata-eval57.5%
associate-+r+57.5%
+-commutative57.5%
associate-+r+57.5%
+-commutative57.5%
cosh-undef57.5%
Applied egg-rr57.5%
Taylor expanded in x around 0 49.8%
exp-sum49.8%
*-commutative49.8%
pow-to-exp98.8%
unpow298.8%
associate-*r*98.8%
*-commutative98.8%
exp-prod98.8%
Applied egg-rr98.8%
Taylor expanded in x around inf 98.8%
Final simplification98.8%
(FPCore (x) :precision binary64 (* x (+ x (* 0.08333333333333333 (pow x 3.0)))))
double code(double x) {
return x * (x + (0.08333333333333333 * pow(x, 3.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x + (0.08333333333333333d0 * (x ** 3.0d0)))
end function
public static double code(double x) {
return x * (x + (0.08333333333333333 * Math.pow(x, 3.0)));
}
def code(x): return x * (x + (0.08333333333333333 * math.pow(x, 3.0)))
function code(x) return Float64(x * Float64(x + Float64(0.08333333333333333 * (x ^ 3.0)))) end
function tmp = code(x) tmp = x * (x + (0.08333333333333333 * (x ^ 3.0))); end
code[x_] := N[(x * N[(x + N[(0.08333333333333333 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x + 0.08333333333333333 \cdot {x}^{3}\right)
\end{array}
Initial program 57.6%
associate-+l-57.6%
sub-neg57.6%
sub-neg57.6%
distribute-neg-in57.6%
remove-double-neg57.6%
+-commutative57.6%
metadata-eval57.6%
Simplified57.6%
+-commutative57.6%
associate-+r+57.6%
metadata-eval57.6%
sub-neg57.6%
add-exp-log57.5%
sub-neg57.5%
metadata-eval57.5%
associate-+r+57.5%
+-commutative57.5%
associate-+r+57.5%
+-commutative57.5%
cosh-undef57.5%
Applied egg-rr57.5%
Taylor expanded in x around 0 49.8%
exp-sum49.8%
*-commutative49.8%
pow-to-exp98.8%
unpow298.8%
associate-*r*98.8%
*-commutative98.8%
exp-prod98.8%
Applied egg-rr98.8%
Taylor expanded in x around 0 98.8%
Final simplification98.8%
(FPCore (x) :precision binary64 (* x x))
double code(double x) {
return x * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * x
end function
public static double code(double x) {
return x * x;
}
def code(x): return x * x
function code(x) return Float64(x * x) end
function tmp = code(x) tmp = x * x; end
code[x_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 57.6%
associate-+l-57.6%
sub-neg57.6%
sub-neg57.6%
distribute-neg-in57.6%
remove-double-neg57.6%
+-commutative57.6%
metadata-eval57.6%
Simplified57.6%
+-commutative57.6%
associate-+r+57.6%
metadata-eval57.6%
sub-neg57.6%
add-exp-log57.5%
sub-neg57.5%
metadata-eval57.5%
associate-+r+57.5%
+-commutative57.5%
associate-+r+57.5%
+-commutative57.5%
cosh-undef57.5%
Applied egg-rr57.5%
Taylor expanded in x around 0 49.8%
exp-sum49.8%
*-commutative49.8%
pow-to-exp98.8%
unpow298.8%
associate-*r*98.8%
*-commutative98.8%
exp-prod98.8%
Applied egg-rr98.8%
Taylor expanded in x around 0 98.0%
Final simplification98.0%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 57.6%
associate-+l-57.6%
sub-neg57.6%
sub-neg57.6%
distribute-neg-in57.6%
remove-double-neg57.6%
+-commutative57.6%
metadata-eval57.6%
Simplified57.6%
Taylor expanded in x around 0 55.3%
Taylor expanded in x around 0 6.1%
Final simplification6.1%
(FPCore (x) :precision binary64 (* 4.0 (pow (sinh (/ x 2.0)) 2.0)))
double code(double x) {
return 4.0 * pow(sinh((x / 2.0)), 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 4.0d0 * (sinh((x / 2.0d0)) ** 2.0d0)
end function
public static double code(double x) {
return 4.0 * Math.pow(Math.sinh((x / 2.0)), 2.0);
}
def code(x): return 4.0 * math.pow(math.sinh((x / 2.0)), 2.0)
function code(x) return Float64(4.0 * (sinh(Float64(x / 2.0)) ^ 2.0)) end
function tmp = code(x) tmp = 4.0 * (sinh((x / 2.0)) ^ 2.0); end
code[x_] := N[(4.0 * N[Power[N[Sinh[N[(x / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot {\sinh \left(\frac{x}{2}\right)}^{2}
\end{array}
herbie shell --seed 2023339
(FPCore (x)
:name "exp2 (problem 3.3.7)"
:precision binary64
:pre (<= (fabs x) 710.0)
:herbie-target
(* 4.0 (pow (sinh (/ x 2.0)) 2.0))
(+ (- (exp x) 2.0) (exp (- x))))