
(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 7 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
(let* ((t_0 (+ (- (exp x) 2.0) (exp (- x)))))
(if (<= t_0 1e-5)
(fma
0.002777777777777778
(pow x 6.0)
(+ (* x x) (* 0.08333333333333333 (pow x 4.0))))
t_0)))
double code(double x) {
double t_0 = (exp(x) - 2.0) + exp(-x);
double tmp;
if (t_0 <= 1e-5) {
tmp = fma(0.002777777777777778, pow(x, 6.0), ((x * x) + (0.08333333333333333 * pow(x, 4.0))));
} else {
tmp = t_0;
}
return tmp;
}
function code(x) t_0 = Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) tmp = 0.0 if (t_0 <= 1e-5) tmp = fma(0.002777777777777778, (x ^ 6.0), Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0)))); else tmp = t_0; end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision] + N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(e^{x} - 2\right) + e^{-x}\\
\mathbf{if}\;t_0 \leq 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(0.002777777777777778, {x}^{6}, x \cdot x + 0.08333333333333333 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1.00000000000000008e-5Initial program 51.9%
+-commutative51.9%
associate-+r-51.7%
+-commutative51.7%
associate-+r-52.1%
+-commutative52.1%
associate-+l-51.9%
Simplified51.9%
Taylor expanded in x around 0 100.0%
fma-def100.0%
unpow2100.0%
Simplified100.0%
if 1.00000000000000008e-5 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (- (exp x) 2.0) (exp (- x))))) (if (<= t_0 1e-5) (+ (* x x) (* 0.08333333333333333 (pow x 4.0))) t_0)))
double code(double x) {
double t_0 = (exp(x) - 2.0) + exp(-x);
double tmp;
if (t_0 <= 1e-5) {
tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (exp(x) - 2.0d0) + exp(-x)
if (t_0 <= 1d-5) then
tmp = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (Math.exp(x) - 2.0) + Math.exp(-x);
double tmp;
if (t_0 <= 1e-5) {
tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (math.exp(x) - 2.0) + math.exp(-x) tmp = 0 if t_0 <= 1e-5: tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0)) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) tmp = 0.0 if (t_0 <= 1e-5) tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (exp(x) - 2.0) + exp(-x); tmp = 0.0; if (t_0 <= 1e-5) tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0)); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(e^{x} - 2\right) + e^{-x}\\
\mathbf{if}\;t_0 \leq 10^{-5}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1.00000000000000008e-5Initial program 51.9%
+-commutative51.9%
associate-+r-51.7%
+-commutative51.7%
associate-+r-52.1%
+-commutative52.1%
associate-+l-51.9%
Simplified51.9%
Taylor expanded in x around 0 99.9%
unpow299.9%
Simplified99.9%
if 1.00000000000000008e-5 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 100.0%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 6.4) (+ (* x x) (* 0.08333333333333333 (pow x 4.0))) (sqrt (* (pow x 12.0) 7.71604938271605e-6))))
double code(double x) {
double tmp;
if (x <= 6.4) {
tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
} else {
tmp = sqrt((pow(x, 12.0) * 7.71604938271605e-6));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 6.4d0) then
tmp = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
else
tmp = sqrt(((x ** 12.0d0) * 7.71604938271605d-6))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 6.4) {
tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
} else {
tmp = Math.sqrt((Math.pow(x, 12.0) * 7.71604938271605e-6));
}
return tmp;
}
def code(x): tmp = 0 if x <= 6.4: tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0)) else: tmp = math.sqrt((math.pow(x, 12.0) * 7.71604938271605e-6)) return tmp
function code(x) tmp = 0.0 if (x <= 6.4) tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = sqrt(Float64((x ^ 12.0) * 7.71604938271605e-6)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 6.4) tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0)); else tmp = sqrt(((x ^ 12.0) * 7.71604938271605e-6)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 6.4], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[x, 12.0], $MachinePrecision] * 7.71604938271605e-6), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.4:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{x}^{12} \cdot 7.71604938271605 \cdot 10^{-6}}\\
\end{array}
\end{array}
if x < 6.4000000000000004Initial program 68.0%
+-commutative68.0%
associate-+r-67.9%
+-commutative67.9%
associate-+r-68.2%
+-commutative68.2%
associate-+l-68.0%
Simplified68.0%
Taylor expanded in x around 0 90.8%
unpow290.8%
Simplified90.8%
if 6.4000000000000004 < x Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
+-commutative100.0%
associate-+r-100.0%
+-commutative100.0%
associate-+l-100.0%
Simplified100.0%
Taylor expanded in x around 0 84.7%
fma-def84.7%
unpow284.7%
Simplified84.7%
Taylor expanded in x around inf 84.7%
add-sqr-sqrt84.7%
sqrt-unprod95.4%
*-commutative95.4%
*-commutative95.4%
swap-sqr95.4%
pow-prod-up95.4%
metadata-eval95.4%
metadata-eval95.4%
Applied egg-rr95.4%
Final simplification91.9%
(FPCore (x) :precision binary64 (if (<= x 6.4) (+ (* x x) (* 0.08333333333333333 (pow x 4.0))) (* 0.002777777777777778 (pow x 6.0))))
double code(double x) {
double tmp;
if (x <= 6.4) {
tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
} else {
tmp = 0.002777777777777778 * pow(x, 6.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 6.4d0) then
tmp = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
else
tmp = 0.002777777777777778d0 * (x ** 6.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 6.4) {
tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
} else {
tmp = 0.002777777777777778 * Math.pow(x, 6.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 6.4: tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0)) else: tmp = 0.002777777777777778 * math.pow(x, 6.0) return tmp
function code(x) tmp = 0.0 if (x <= 6.4) tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0))); else tmp = Float64(0.002777777777777778 * (x ^ 6.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 6.4) tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0)); else tmp = 0.002777777777777778 * (x ^ 6.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 6.4], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.4:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6}\\
\end{array}
\end{array}
if x < 6.4000000000000004Initial program 68.0%
+-commutative68.0%
associate-+r-67.9%
+-commutative67.9%
associate-+r-68.2%
+-commutative68.2%
associate-+l-68.0%
Simplified68.0%
Taylor expanded in x around 0 90.8%
unpow290.8%
Simplified90.8%
if 6.4000000000000004 < x Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
+-commutative100.0%
associate-+r-100.0%
+-commutative100.0%
associate-+l-100.0%
Simplified100.0%
Taylor expanded in x around 0 84.7%
fma-def84.7%
unpow284.7%
Simplified84.7%
Taylor expanded in x around inf 84.7%
Final simplification89.3%
(FPCore (x) :precision binary64 (if (<= x 4.2) (* x x) (* 0.002777777777777778 (pow x 6.0))))
double code(double x) {
double tmp;
if (x <= 4.2) {
tmp = x * x;
} else {
tmp = 0.002777777777777778 * pow(x, 6.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 4.2d0) then
tmp = x * x
else
tmp = 0.002777777777777778d0 * (x ** 6.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 4.2) {
tmp = x * x;
} else {
tmp = 0.002777777777777778 * Math.pow(x, 6.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 4.2: tmp = x * x else: tmp = 0.002777777777777778 * math.pow(x, 6.0) return tmp
function code(x) tmp = 0.0 if (x <= 4.2) tmp = Float64(x * x); else tmp = Float64(0.002777777777777778 * (x ^ 6.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 4.2) tmp = x * x; else tmp = 0.002777777777777778 * (x ^ 6.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 4.2], N[(x * x), $MachinePrecision], N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.2:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6}\\
\end{array}
\end{array}
if x < 4.20000000000000018Initial program 68.0%
+-commutative68.0%
associate-+r-67.9%
+-commutative67.9%
associate-+r-68.2%
+-commutative68.2%
associate-+l-68.0%
Simplified68.0%
Taylor expanded in x around 0 84.5%
unpow284.5%
Simplified84.5%
if 4.20000000000000018 < x Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
+-commutative100.0%
associate-+r-100.0%
+-commutative100.0%
associate-+l-100.0%
Simplified100.0%
Taylor expanded in x around 0 84.7%
fma-def84.7%
unpow284.7%
Simplified84.7%
Taylor expanded in x around inf 84.7%
Final simplification84.6%
(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 75.8%
+-commutative75.8%
associate-+r-75.7%
+-commutative75.7%
associate-+r-75.9%
+-commutative75.9%
associate-+l-75.8%
Simplified75.8%
Taylor expanded in x around 0 76.9%
unpow276.9%
Simplified76.9%
Final simplification76.9%
(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 75.8%
+-commutative75.8%
associate-+r-75.7%
+-commutative75.7%
associate-+r-75.9%
+-commutative75.9%
associate-+l-75.8%
Simplified75.8%
Applied egg-rr26.4%
Final simplification26.4%
(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 2023279
(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))))