
(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 4 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 (exp (fma x_m (- x_m 1.0) (- x_m 1.0))))
x_m = fabs(x);
double code(double x_m) {
return exp(fma(x_m, (x_m - 1.0), (x_m - 1.0)));
}
x_m = abs(x) function code(x_m) return exp(fma(x_m, Float64(x_m - 1.0), Float64(x_m - 1.0))) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Exp[N[(x$95$m * N[(x$95$m - 1.0), $MachinePrecision] + N[(x$95$m - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
e^{\mathsf{fma}\left(x\_m, x\_m - 1, x\_m - 1\right)}
\end{array}
Initial program 100.0%
Applied rewrites75.4%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lift-pow.f64N/A
metadata-evalN/A
pow-powN/A
pow2N/A
pow2N/A
metadata-evalN/A
lift-fma.f64N/A
metadata-evalN/A
sub-negN/A
flip-+N/A
difference-of-sqr--1N/A
*-commutativeN/A
distribute-rgt-inN/A
Applied rewrites100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= (* x_m x_m) 0.95) (exp -1.0) (exp (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if ((x_m * x_m) <= 0.95) {
tmp = exp(-1.0);
} else {
tmp = exp((x_m * x_m));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if ((x_m * x_m) <= 0.95d0) then
tmp = exp((-1.0d0))
else
tmp = exp((x_m * x_m))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if ((x_m * x_m) <= 0.95) {
tmp = Math.exp(-1.0);
} else {
tmp = Math.exp((x_m * x_m));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if (x_m * x_m) <= 0.95: tmp = math.exp(-1.0) else: tmp = math.exp((x_m * x_m)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (Float64(x_m * x_m) <= 0.95) tmp = exp(-1.0); else tmp = exp(Float64(x_m * x_m)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if ((x_m * x_m) <= 0.95) tmp = exp(-1.0); else tmp = exp((x_m * x_m)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 0.95], N[Exp[-1.0], $MachinePrecision], N[Exp[N[(x$95$m * x$95$m), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m \leq 0.95:\\
\;\;\;\;e^{-1}\\
\mathbf{else}:\\
\;\;\;\;e^{x\_m \cdot x\_m}\\
\end{array}
\end{array}
if (*.f64 x x) < 0.94999999999999996Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.4%
if 0.94999999999999996 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around inf
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (exp (fma x_m x_m -1.0)))
x_m = fabs(x);
double code(double x_m) {
return exp(fma(x_m, x_m, -1.0));
}
x_m = abs(x) function code(x_m) return exp(fma(x_m, x_m, -1.0)) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Exp[N[(x$95$m * x$95$m + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
e^{\mathsf{fma}\left(x\_m, x\_m, -1\right)}
\end{array}
Initial program 100.0%
lift-neg.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (exp -1.0))
x_m = fabs(x);
double code(double x_m) {
return exp(-1.0);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = exp((-1.0d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.exp(-1.0);
}
x_m = math.fabs(x) def code(x_m): return math.exp(-1.0)
x_m = abs(x) function code(x_m) return exp(-1.0) end
x_m = abs(x); function tmp = code(x_m) tmp = exp(-1.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Exp[-1.0], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
e^{-1}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites51.6%
herbie shell --seed 2024327
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))