
(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 11 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}
(FPCore (x) :precision binary64 (exp (fma x x -1.0)))
double code(double x) {
return exp(fma(x, x, -1.0));
}
function code(x) return exp(fma(x, x, -1.0)) end
code[x_] := N[Exp[N[(x * x + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\mathsf{fma}\left(x, x, -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%
(FPCore (x) :precision binary64 (if (<= (exp (- (* x x) 1.0)) 0.5) (/ (fma (* x x) E E) (* E E)) (* (* (/ 0.5 E) x) (* (* x x) x))))
double code(double x) {
double tmp;
if (exp(((x * x) - 1.0)) <= 0.5) {
tmp = fma((x * x), ((double) M_E), ((double) M_E)) / (((double) M_E) * ((double) M_E));
} else {
tmp = ((0.5 / ((double) M_E)) * x) * ((x * x) * x);
}
return tmp;
}
function code(x) tmp = 0.0 if (exp(Float64(Float64(x * x) - 1.0)) <= 0.5) tmp = Float64(fma(Float64(x * x), exp(1), exp(1)) / Float64(exp(1) * exp(1))); else tmp = Float64(Float64(Float64(0.5 / exp(1)) * x) * Float64(Float64(x * x) * x)); end return tmp end
code[x_] := If[LessEqual[N[Exp[N[(N[(x * x), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision], 0.5], N[(N[(N[(x * x), $MachinePrecision] * E + E), $MachinePrecision] / N[(E * E), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 / E), $MachinePrecision] * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{x \cdot x - 1} \leq 0.5:\\
\;\;\;\;\frac{\mathsf{fma}\left(x \cdot x, e, e\right)}{e \cdot e}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{0.5}{e} \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\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
distribute-rgt1-inN/A
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f64100.0
Applied rewrites100.0%
Applied rewrites98.5%
Applied rewrites100.0%
if 0.5 < (exp.f64 (neg.f64 (-.f64 #s(literal 1 binary64) (*.f64 x x)))) Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites75.3%
Taylor expanded in x around inf
Applied rewrites75.3%
Final simplification87.5%
(FPCore (x) :precision binary64 (if (<= (* x x) 1e-8) (/ (fma (* x x) E E) (* E E)) (exp (* x x))))
double code(double x) {
double tmp;
if ((x * x) <= 1e-8) {
tmp = fma((x * x), ((double) M_E), ((double) M_E)) / (((double) M_E) * ((double) M_E));
} else {
tmp = exp((x * x));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x * x) <= 1e-8) tmp = Float64(fma(Float64(x * x), exp(1), exp(1)) / Float64(exp(1) * exp(1))); else tmp = exp(Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e-8], N[(N[(N[(x * x), $MachinePrecision] * E + E), $MachinePrecision] / N[(E * E), $MachinePrecision]), $MachinePrecision], N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-8}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x \cdot x, e, e\right)}{e \cdot e}\\
\mathbf{else}:\\
\;\;\;\;e^{x \cdot x}\\
\end{array}
\end{array}
if (*.f64 x x) < 1e-8Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt1-inN/A
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f64100.0
Applied rewrites100.0%
Applied rewrites98.5%
Applied rewrites100.0%
if 1e-8 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (fma (* x x) 0.5 1.0)))
(if (<= (* x x) 2e+149)
(/
(fma (* (* t_0 t_0) (* x x)) (* x x) -1.0)
(* (fma t_0 (* x x) -1.0) E))
(* (* (/ 0.5 E) x) (* (* x x) x)))))
double code(double x) {
double t_0 = fma((x * x), 0.5, 1.0);
double tmp;
if ((x * x) <= 2e+149) {
tmp = fma(((t_0 * t_0) * (x * x)), (x * x), -1.0) / (fma(t_0, (x * x), -1.0) * ((double) M_E));
} else {
tmp = ((0.5 / ((double) M_E)) * x) * ((x * x) * x);
}
return tmp;
}
function code(x) t_0 = fma(Float64(x * x), 0.5, 1.0) tmp = 0.0 if (Float64(x * x) <= 2e+149) tmp = Float64(fma(Float64(Float64(t_0 * t_0) * Float64(x * x)), Float64(x * x), -1.0) / Float64(fma(t_0, Float64(x * x), -1.0) * exp(1))); else tmp = Float64(Float64(Float64(0.5 / exp(1)) * x) * Float64(Float64(x * x) * x)); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e+149], N[(N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision] / N[(N[(t$95$0 * N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision] * E), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 / E), $MachinePrecision] * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x \cdot x, 0.5, 1\right)\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+149}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\left(t\_0 \cdot t\_0\right) \cdot \left(x \cdot x\right), x \cdot x, -1\right)}{\mathsf{fma}\left(t\_0, x \cdot x, -1\right) \cdot e}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{0.5}{e} \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 2.0000000000000001e149Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites79.9%
Applied rewrites91.6%
if 2.0000000000000001e149 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites100.0%
Final simplification94.7%
(FPCore (x) :precision binary64 (if (<= (* x x) 1e-8) (/ (fma (* x x) E E) (* E E)) (* (* (* (* (/ (* x x) E) x) x) (* x x)) 0.16666666666666666)))
double code(double x) {
double tmp;
if ((x * x) <= 1e-8) {
tmp = fma((x * x), ((double) M_E), ((double) M_E)) / (((double) M_E) * ((double) M_E));
} else {
tmp = (((((x * x) / ((double) M_E)) * x) * x) * (x * x)) * 0.16666666666666666;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x * x) <= 1e-8) tmp = Float64(fma(Float64(x * x), exp(1), exp(1)) / Float64(exp(1) * exp(1))); else tmp = Float64(Float64(Float64(Float64(Float64(Float64(x * x) / exp(1)) * x) * x) * Float64(x * x)) * 0.16666666666666666); end return tmp end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e-8], N[(N[(N[(x * x), $MachinePrecision] * E + E), $MachinePrecision] / N[(E * E), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(N[(x * x), $MachinePrecision] / E), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-8}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x \cdot x, e, e\right)}{e \cdot e}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\frac{x \cdot x}{e} \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot 0.16666666666666666\\
\end{array}
\end{array}
if (*.f64 x x) < 1e-8Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt1-inN/A
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f64100.0
Applied rewrites100.0%
Applied rewrites98.5%
Applied rewrites100.0%
if 1e-8 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites86.2%
Taylor expanded in x around inf
Applied rewrites86.2%
Applied rewrites86.2%
Final simplification93.0%
(FPCore (x) :precision binary64 (* (/ 1.0 E) (fma (fma (fma 0.16666666666666666 (* x x) 0.5) (* x x) 1.0) (* x x) 1.0)))
double code(double x) {
return (1.0 / ((double) M_E)) * fma(fma(fma(0.16666666666666666, (x * x), 0.5), (x * x), 1.0), (x * x), 1.0);
}
function code(x) return Float64(Float64(1.0 / exp(1)) * fma(fma(fma(0.16666666666666666, Float64(x * x), 0.5), Float64(x * x), 1.0), Float64(x * x), 1.0)) end
code[x_] := N[(N[(1.0 / E), $MachinePrecision] * N[(N[(N[(0.16666666666666666 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x \cdot x, 0.5\right), x \cdot x, 1\right), x \cdot x, 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites93.0%
Final simplification93.0%
(FPCore (x) :precision binary64 (/ (fma (fma (* x x) 0.5 1.0) (* x x) 1.0) E))
double code(double x) {
return fma(fma((x * x), 0.5, 1.0), (x * x), 1.0) / ((double) M_E);
}
function code(x) return Float64(fma(fma(Float64(x * x), 0.5, 1.0), Float64(x * x), 1.0) / exp(1)) end
code[x_] := N[(N[(N[(N[(x * x), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.5, 1\right), x \cdot x, 1\right)}{e}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites87.4%
Applied rewrites87.4%
(FPCore (x) :precision binary64 (if (<= (* x x) 1e-8) (/ 1.0 E) (* (/ x E) x)))
double code(double x) {
double tmp;
if ((x * x) <= 1e-8) {
tmp = 1.0 / ((double) M_E);
} else {
tmp = (x / ((double) M_E)) * x;
}
return tmp;
}
public static double code(double x) {
double tmp;
if ((x * x) <= 1e-8) {
tmp = 1.0 / Math.E;
} else {
tmp = (x / Math.E) * x;
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 1e-8: tmp = 1.0 / math.e else: tmp = (x / math.e) * x return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 1e-8) tmp = Float64(1.0 / exp(1)); else tmp = Float64(Float64(x / exp(1)) * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 1e-8) tmp = 1.0 / 2.71828182845904523536; else tmp = (x / 2.71828182845904523536) * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e-8], N[(1.0 / E), $MachinePrecision], N[(N[(x / E), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-8}:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{e} \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1e-8Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f6499.7
Applied rewrites99.7%
if 1e-8 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt1-inN/A
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f6451.2
Applied rewrites51.2%
Taylor expanded in x around inf
Applied rewrites51.2%
Applied rewrites51.2%
(FPCore (x) :precision binary64 (/ (fma (* x x) E E) (* E E)))
double code(double x) {
return fma((x * x), ((double) M_E), ((double) M_E)) / (((double) M_E) * ((double) M_E));
}
function code(x) return Float64(fma(Float64(x * x), exp(1), exp(1)) / Float64(exp(1) * exp(1))) end
code[x_] := N[(N[(N[(x * x), $MachinePrecision] * E + E), $MachinePrecision] / N[(E * E), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x \cdot x, e, e\right)}{e \cdot e}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt1-inN/A
lower-*.f64N/A
unpow2N/A
lower-fma.f64N/A
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f6475.2
Applied rewrites75.2%
Applied rewrites74.4%
Applied rewrites75.2%
(FPCore (x) :precision binary64 (/ (fma x x 1.0) E))
double code(double x) {
return fma(x, x, 1.0) / ((double) M_E);
}
function code(x) return Float64(fma(x, x, 1.0) / exp(1)) end
code[x_] := N[(N[(x * x + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, x, 1\right)}{e}
\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%
Taylor expanded in x around 0
distribute-rgt1-inN/A
metadata-evalN/A
rec-expN/A
e-exp-1N/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
lower-E.f6475.2
Applied rewrites75.2%
(FPCore (x) :precision binary64 (/ 1.0 E))
double code(double x) {
return 1.0 / ((double) M_E);
}
public static double code(double x) {
return 1.0 / Math.E;
}
def code(x): return 1.0 / math.e
function code(x) return Float64(1.0 / exp(1)) end
function tmp = code(x) tmp = 1.0 / 2.71828182845904523536; end
code[x_] := N[(1.0 / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f6450.6
Applied rewrites50.6%
herbie shell --seed 2024235
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))