
(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 9 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
(+
(pow x 2.0)
(*
(fma
(pow x 2.0)
(fma
(pow x 2.0)
(fma (pow x 2.0) 5.511463844797178e-7 4.96031746031746e-5)
0.002777777777777778)
0.08333333333333333)
(pow x 4.0))))
double code(double x) {
return pow(x, 2.0) + (fma(pow(x, 2.0), fma(pow(x, 2.0), fma(pow(x, 2.0), 5.511463844797178e-7, 4.96031746031746e-5), 0.002777777777777778), 0.08333333333333333) * pow(x, 4.0));
}
function code(x) return Float64((x ^ 2.0) + Float64(fma((x ^ 2.0), fma((x ^ 2.0), fma((x ^ 2.0), 5.511463844797178e-7, 4.96031746031746e-5), 0.002777777777777778), 0.08333333333333333) * (x ^ 4.0))) end
code[x_] := N[(N[Power[x, 2.0], $MachinePrecision] + N[(N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[Power[x, 2.0], $MachinePrecision] * 5.511463844797178e-7 + 4.96031746031746e-5), $MachinePrecision] + 0.002777777777777778), $MachinePrecision] + 0.08333333333333333), $MachinePrecision] * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{x}^{2} + \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, 5.511463844797178 \cdot 10^{-7}, 4.96031746031746 \cdot 10^{-5}\right), 0.002777777777777778\right), 0.08333333333333333\right) \cdot {x}^{4}
\end{array}
Initial program 49.4%
associate-+l-49.4%
sub-neg49.4%
sub-neg49.4%
distribute-neg-in49.4%
remove-double-neg49.4%
+-commutative49.4%
metadata-eval49.4%
Simplified49.4%
Taylor expanded in x around 0 99.2%
distribute-rgt-in99.3%
*-lft-identity99.3%
*-commutative99.3%
associate-*l*99.3%
+-commutative99.3%
fma-define99.3%
+-commutative99.3%
fma-define99.3%
+-commutative99.3%
*-commutative99.3%
fma-define99.3%
pow-sqr99.3%
metadata-eval99.3%
Simplified99.3%
(FPCore (x)
:precision binary64
(*
(pow x 2.0)
(+
1.0
(*
(pow x 2.0)
(+
0.08333333333333333
(*
(pow x 2.0)
(+
0.002777777777777778
(*
(pow x 2.0)
(+ 4.96031746031746e-5 (* (pow x 2.0) 5.511463844797178e-7))))))))))
double code(double x) {
return pow(x, 2.0) * (1.0 + (pow(x, 2.0) * (0.08333333333333333 + (pow(x, 2.0) * (0.002777777777777778 + (pow(x, 2.0) * (4.96031746031746e-5 + (pow(x, 2.0) * 5.511463844797178e-7))))))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** 2.0d0) * (1.0d0 + ((x ** 2.0d0) * (0.08333333333333333d0 + ((x ** 2.0d0) * (0.002777777777777778d0 + ((x ** 2.0d0) * (4.96031746031746d-5 + ((x ** 2.0d0) * 5.511463844797178d-7))))))))
end function
public static double code(double x) {
return Math.pow(x, 2.0) * (1.0 + (Math.pow(x, 2.0) * (0.08333333333333333 + (Math.pow(x, 2.0) * (0.002777777777777778 + (Math.pow(x, 2.0) * (4.96031746031746e-5 + (Math.pow(x, 2.0) * 5.511463844797178e-7))))))));
}
def code(x): return math.pow(x, 2.0) * (1.0 + (math.pow(x, 2.0) * (0.08333333333333333 + (math.pow(x, 2.0) * (0.002777777777777778 + (math.pow(x, 2.0) * (4.96031746031746e-5 + (math.pow(x, 2.0) * 5.511463844797178e-7))))))))
function code(x) return Float64((x ^ 2.0) * Float64(1.0 + Float64((x ^ 2.0) * Float64(0.08333333333333333 + Float64((x ^ 2.0) * Float64(0.002777777777777778 + Float64((x ^ 2.0) * Float64(4.96031746031746e-5 + Float64((x ^ 2.0) * 5.511463844797178e-7))))))))) end
function tmp = code(x) tmp = (x ^ 2.0) * (1.0 + ((x ^ 2.0) * (0.08333333333333333 + ((x ^ 2.0) * (0.002777777777777778 + ((x ^ 2.0) * (4.96031746031746e-5 + ((x ^ 2.0) * 5.511463844797178e-7)))))))); end
code[x_] := N[(N[Power[x, 2.0], $MachinePrecision] * N[(1.0 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.08333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.002777777777777778 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(4.96031746031746e-5 + N[(N[Power[x, 2.0], $MachinePrecision] * 5.511463844797178e-7), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{x}^{2} \cdot \left(1 + {x}^{2} \cdot \left(0.08333333333333333 + {x}^{2} \cdot \left(0.002777777777777778 + {x}^{2} \cdot \left(4.96031746031746 \cdot 10^{-5} + {x}^{2} \cdot 5.511463844797178 \cdot 10^{-7}\right)\right)\right)\right)
\end{array}
Initial program 49.4%
associate-+l-49.4%
sub-neg49.4%
sub-neg49.4%
distribute-neg-in49.4%
remove-double-neg49.4%
+-commutative49.4%
metadata-eval49.4%
Simplified49.4%
Taylor expanded in x around 0 99.2%
*-commutative99.2%
Simplified99.2%
(FPCore (x) :precision binary64 (+ (* x x) (* 0.08333333333333333 (pow x 4.0))))
double code(double x) {
return (x * x) + (0.08333333333333333 * pow(x, 4.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
end function
public static double code(double x) {
return (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
}
def code(x): return (x * x) + (0.08333333333333333 * math.pow(x, 4.0))
function code(x) return Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0))) end
function tmp = code(x) tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0)); end
code[x_] := N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x + 0.08333333333333333 \cdot {x}^{4}
\end{array}
Initial program 49.4%
associate-+l-49.4%
sub-neg49.4%
sub-neg49.4%
distribute-neg-in49.4%
remove-double-neg49.4%
+-commutative49.4%
metadata-eval49.4%
Simplified49.4%
Taylor expanded in x around 0 98.6%
distribute-rgt-in98.7%
*-lft-identity98.7%
associate-*l*98.7%
pow-sqr98.7%
metadata-eval98.7%
Simplified98.7%
unpow298.7%
Applied egg-rr98.7%
(FPCore (x) :precision binary64 (pow x 2.0))
double code(double x) {
return pow(x, 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x ** 2.0d0
end function
public static double code(double x) {
return Math.pow(x, 2.0);
}
def code(x): return math.pow(x, 2.0)
function code(x) return x ^ 2.0 end
function tmp = code(x) tmp = x ^ 2.0; end
code[x_] := N[Power[x, 2.0], $MachinePrecision]
\begin{array}{l}
\\
{x}^{2}
\end{array}
Initial program 49.4%
Taylor expanded in x around 0 47.7%
*-commutative47.7%
Simplified47.7%
Taylor expanded in x around 0 47.9%
Taylor expanded in x around 0 98.0%
(FPCore (x) :precision binary64 (+ (+ (* x (+ 1.0 (* x 0.5))) -1.0) (+ 1.0 (* x (+ (* x 0.5) -1.0)))))
double code(double x) {
return ((x * (1.0 + (x * 0.5))) + -1.0) + (1.0 + (x * ((x * 0.5) + -1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * (1.0d0 + (x * 0.5d0))) + (-1.0d0)) + (1.0d0 + (x * ((x * 0.5d0) + (-1.0d0))))
end function
public static double code(double x) {
return ((x * (1.0 + (x * 0.5))) + -1.0) + (1.0 + (x * ((x * 0.5) + -1.0)));
}
def code(x): return ((x * (1.0 + (x * 0.5))) + -1.0) + (1.0 + (x * ((x * 0.5) + -1.0)))
function code(x) return Float64(Float64(Float64(x * Float64(1.0 + Float64(x * 0.5))) + -1.0) + Float64(1.0 + Float64(x * Float64(Float64(x * 0.5) + -1.0)))) end
function tmp = code(x) tmp = ((x * (1.0 + (x * 0.5))) + -1.0) + (1.0 + (x * ((x * 0.5) + -1.0))); end
code[x_] := N[(N[(N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + N[(1.0 + N[(x * N[(N[(x * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(1 + x \cdot 0.5\right) + -1\right) + \left(1 + x \cdot \left(x \cdot 0.5 + -1\right)\right)
\end{array}
Initial program 49.4%
Taylor expanded in x around 0 47.7%
*-commutative47.7%
Simplified47.7%
Taylor expanded in x around 0 47.9%
Taylor expanded in x around 0 47.9%
Final simplification47.9%
(FPCore (x) :precision binary64 (+ (+ 1.0 (* x (+ 1.0 (* x 0.5)))) (+ (* x (+ (* x 0.5) -1.0)) -1.0)))
double code(double x) {
return (1.0 + (x * (1.0 + (x * 0.5)))) + ((x * ((x * 0.5) + -1.0)) + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 + (x * (1.0d0 + (x * 0.5d0)))) + ((x * ((x * 0.5d0) + (-1.0d0))) + (-1.0d0))
end function
public static double code(double x) {
return (1.0 + (x * (1.0 + (x * 0.5)))) + ((x * ((x * 0.5) + -1.0)) + -1.0);
}
def code(x): return (1.0 + (x * (1.0 + (x * 0.5)))) + ((x * ((x * 0.5) + -1.0)) + -1.0)
function code(x) return Float64(Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * 0.5)))) + Float64(Float64(x * Float64(Float64(x * 0.5) + -1.0)) + -1.0)) end
function tmp = code(x) tmp = (1.0 + (x * (1.0 + (x * 0.5)))) + ((x * ((x * 0.5) + -1.0)) + -1.0); end
code[x_] := N[(N[(1.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(x * N[(N[(x * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + x \cdot \left(1 + x \cdot 0.5\right)\right) + \left(x \cdot \left(x \cdot 0.5 + -1\right) + -1\right)
\end{array}
Initial program 49.4%
associate-+l-49.4%
sub-neg49.4%
sub-neg49.4%
distribute-neg-in49.4%
remove-double-neg49.4%
+-commutative49.4%
metadata-eval49.4%
Simplified49.4%
Taylor expanded in x around 0 47.9%
Taylor expanded in x around 0 47.9%
*-commutative47.7%
Simplified47.9%
Final simplification47.9%
(FPCore (x) :precision binary64 (+ x (* x (+ (* x 0.5) -1.0))))
double code(double x) {
return x + (x * ((x * 0.5) + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + (x * ((x * 0.5d0) + (-1.0d0)))
end function
public static double code(double x) {
return x + (x * ((x * 0.5) + -1.0));
}
def code(x): return x + (x * ((x * 0.5) + -1.0))
function code(x) return Float64(x + Float64(x * Float64(Float64(x * 0.5) + -1.0))) end
function tmp = code(x) tmp = x + (x * ((x * 0.5) + -1.0)); end
code[x_] := N[(x + N[(x * N[(N[(x * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \left(x \cdot 0.5 + -1\right)
\end{array}
Initial program 49.4%
associate-+l-49.4%
sub-neg49.4%
sub-neg49.4%
distribute-neg-in49.4%
remove-double-neg49.4%
+-commutative49.4%
metadata-eval49.4%
Simplified49.4%
Taylor expanded in x around 0 47.9%
Taylor expanded in x around 0 47.2%
+-commutative47.2%
Simplified47.2%
*-un-lft-identity47.2%
associate-+l+6.2%
add-exp-log5.7%
log1p-undefine5.7%
add-exp-log2.5%
expm1-define2.5%
log1p-expm1-u4.0%
add-exp-log47.5%
*-commutative47.5%
fmm-def47.5%
metadata-eval47.5%
Applied egg-rr47.5%
*-lft-identity47.5%
Simplified47.5%
metadata-eval47.5%
fmm-def47.5%
Applied egg-rr47.5%
Final simplification47.5%
(FPCore (x) :precision binary64 (+ -2.0 (+ 2.0 (* x 2.0))))
double code(double x) {
return -2.0 + (2.0 + (x * 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) + (2.0d0 + (x * 2.0d0))
end function
public static double code(double x) {
return -2.0 + (2.0 + (x * 2.0));
}
def code(x): return -2.0 + (2.0 + (x * 2.0))
function code(x) return Float64(-2.0 + Float64(2.0 + Float64(x * 2.0))) end
function tmp = code(x) tmp = -2.0 + (2.0 + (x * 2.0)); end
code[x_] := N[(-2.0 + N[(2.0 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 + \left(2 + x \cdot 2\right)
\end{array}
Initial program 49.4%
associate-+l-49.4%
sub-neg49.4%
sub-neg49.4%
distribute-neg-in49.4%
remove-double-neg49.4%
+-commutative49.4%
metadata-eval49.4%
Simplified49.4%
+-commutative49.4%
associate-+r+49.4%
metadata-eval49.4%
sub-neg49.4%
associate-+l-49.4%
add-sqr-sqrt22.5%
sqrt-unprod48.1%
sqr-neg48.1%
sqrt-unprod25.6%
add-sqr-sqrt47.0%
Applied egg-rr47.0%
associate--r-47.0%
sub-neg47.0%
metadata-eval47.0%
+-commutative47.0%
associate-+l+47.0%
count-247.0%
Simplified47.0%
Taylor expanded in x around 0 47.0%
*-commutative47.0%
Simplified47.0%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 49.4%
associate-+l-49.4%
sub-neg49.4%
sub-neg49.4%
distribute-neg-in49.4%
remove-double-neg49.4%
+-commutative49.4%
metadata-eval49.4%
Simplified49.4%
+-commutative49.4%
associate-+r+49.4%
metadata-eval49.4%
sub-neg49.4%
associate-+l-49.4%
add-sqr-sqrt22.5%
sqrt-unprod48.1%
sqr-neg48.1%
sqrt-unprod25.6%
add-sqr-sqrt47.0%
Applied egg-rr47.0%
associate--r-47.0%
sub-neg47.0%
metadata-eval47.0%
+-commutative47.0%
associate-+l+47.0%
count-247.0%
Simplified47.0%
add-sqr-sqrt25.6%
sqrt-unprod47.2%
sqr-neg47.2%
sqrt-unprod21.6%
add-sqr-sqrt46.8%
exp-neg46.8%
add-sqr-sqrt46.8%
associate-/r*46.8%
metadata-eval46.8%
sqrt-div46.8%
exp-neg46.8%
pow146.8%
pow146.8%
add-sqr-sqrt21.6%
sqrt-unprod46.8%
sqr-neg46.8%
sqrt-unprod25.3%
add-sqr-sqrt46.6%
pow146.6%
pow146.6%
Applied egg-rr46.6%
*-inverses46.6%
Simplified46.6%
metadata-eval46.6%
metadata-eval46.6%
Applied egg-rr46.6%
(FPCore (x) :precision binary64 (let* ((t_0 (sinh (/ x 2.0)))) (* 4.0 (* t_0 t_0))))
double code(double x) {
double t_0 = sinh((x / 2.0));
return 4.0 * (t_0 * t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sinh((x / 2.0d0))
code = 4.0d0 * (t_0 * t_0)
end function
public static double code(double x) {
double t_0 = Math.sinh((x / 2.0));
return 4.0 * (t_0 * t_0);
}
def code(x): t_0 = math.sinh((x / 2.0)) return 4.0 * (t_0 * t_0)
function code(x) t_0 = sinh(Float64(x / 2.0)) return Float64(4.0 * Float64(t_0 * t_0)) end
function tmp = code(x) t_0 = sinh((x / 2.0)); tmp = 4.0 * (t_0 * t_0); end
code[x_] := Block[{t$95$0 = N[Sinh[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sinh \left(\frac{x}{2}\right)\\
4 \cdot \left(t\_0 \cdot t\_0\right)
\end{array}
\end{array}
herbie shell --seed 2024179
(FPCore (x)
:name "exp2 (problem 3.3.7)"
:precision binary64
:pre (<= (fabs x) 710.0)
:alt
(! :herbie-platform default (* 4 (* (sinh (/ x 2)) (sinh (/ x 2)))))
(+ (- (exp x) 2.0) (exp (- x))))