
(FPCore (x) :precision binary64 (exp (- (- 1.0 (* x x)))))
double code(double x) {
return exp(-(1.0 - (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(-(1.0d0 - (x * x)))
end function
public static double code(double x) {
return Math.exp(-(1.0 - (x * x)));
}
def code(x): return math.exp(-(1.0 - (x * x)))
function code(x) return exp(Float64(-Float64(1.0 - Float64(x * x)))) end
function tmp = code(x) tmp = exp(-(1.0 - (x * x))); end
code[x_] := N[Exp[(-N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\left(1 - x \cdot x\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (exp (- (- 1.0 (* x x)))))
double code(double x) {
return exp(-(1.0 - (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(-(1.0d0 - (x * x)))
end function
public static double code(double x) {
return Math.exp(-(1.0 - (x * x)));
}
def code(x): return math.exp(-(1.0 - (x * x)))
function code(x) return exp(Float64(-Float64(1.0 - Float64(x * x)))) end
function tmp = code(x) tmp = exp(-(1.0 - (x * x))); end
code[x_] := N[Exp[(-N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\left(1 - x \cdot x\right)}
\end{array}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (pow (exp (+ x_m 1.0)) (+ x_m -1.0)))
x_m = fabs(x);
double code(double x_m) {
return pow(exp((x_m + 1.0)), (x_m + -1.0));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = exp((x_m + 1.0d0)) ** (x_m + (-1.0d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(Math.exp((x_m + 1.0)), (x_m + -1.0));
}
x_m = math.fabs(x) def code(x_m): return math.pow(math.exp((x_m + 1.0)), (x_m + -1.0))
x_m = abs(x) function code(x_m) return exp(Float64(x_m + 1.0)) ^ Float64(x_m + -1.0) end
x_m = abs(x); function tmp = code(x_m) tmp = exp((x_m + 1.0)) ^ (x_m + -1.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Power[N[Exp[N[(x$95$m + 1.0), $MachinePrecision]], $MachinePrecision], N[(x$95$m + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{\left(e^{x\_m + 1}\right)}^{\left(x\_m + -1\right)}
\end{array}
Initial program 99.9%
lift-neg.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.9
Applied rewrites99.9%
lift-exp.f64N/A
lift-fma.f64N/A
difference-of-sqr--1N/A
exp-prodN/A
lower-pow.f64N/A
lower-exp.f64N/A
lower-+.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f64100.0
Applied rewrites100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= (exp (+ -1.0 (* x_m x_m))) 0.5) (/ 1.0 (/ E (fma x_m (fma x_m (* (* x_m x_m) 0.5) x_m) 1.0))) (* 0.16666666666666666 (* x_m (/ (* x_m (* x_m (* x_m (* x_m x_m)))) E)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (exp((-1.0 + (x_m * x_m))) <= 0.5) {
tmp = 1.0 / (((double) M_E) / fma(x_m, fma(x_m, ((x_m * x_m) * 0.5), x_m), 1.0));
} else {
tmp = 0.16666666666666666 * (x_m * ((x_m * (x_m * (x_m * (x_m * x_m)))) / ((double) M_E)));
}
return tmp;
}
x_m = abs(x) function code(x_m) tmp = 0.0 if (exp(Float64(-1.0 + Float64(x_m * x_m))) <= 0.5) tmp = Float64(1.0 / Float64(exp(1) / fma(x_m, fma(x_m, Float64(Float64(x_m * x_m) * 0.5), x_m), 1.0))); else tmp = Float64(0.16666666666666666 * Float64(x_m * Float64(Float64(x_m * Float64(x_m * Float64(x_m * Float64(x_m * x_m)))) / exp(1)))); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[N[Exp[N[(-1.0 + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.5], N[(1.0 / N[(E / N[(x$95$m * N[(x$95$m * N[(N[(x$95$m * x$95$m), $MachinePrecision] * 0.5), $MachinePrecision] + x$95$m), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.16666666666666666 * N[(x$95$m * N[(N[(x$95$m * N[(x$95$m * N[(x$95$m * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / E), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;e^{-1 + x\_m \cdot x\_m} \leq 0.5:\\
\;\;\;\;\frac{1}{\frac{e}{\mathsf{fma}\left(x\_m, \mathsf{fma}\left(x\_m, \left(x\_m \cdot x\_m\right) \cdot 0.5, x\_m\right), 1\right)}}\\
\mathbf{else}:\\
\;\;\;\;0.16666666666666666 \cdot \left(x\_m \cdot \frac{x\_m \cdot \left(x\_m \cdot \left(x\_m \cdot \left(x\_m \cdot x\_m\right)\right)\right)}{e}\right)\\
\end{array}
\end{array}
if (exp.f64 (neg.f64 (-.f64 #s(literal 1 binary64) (*.f64 x x)))) < 0.5Initial program 100.0%
Taylor expanded in x around 0
*-lft-identityN/A
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+l+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites99.7%
Applied rewrites99.7%
if 0.5 < (exp.f64 (neg.f64 (-.f64 #s(literal 1 binary64) (*.f64 x x)))) Initial program 100.0%
Applied rewrites49.9%
Taylor expanded in x around 0
Applied rewrites83.6%
Applied rewrites33.6%
Taylor expanded in x around inf
Applied rewrites83.6%
Final simplification91.5%
herbie shell --seed 2024223
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))