
(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 3 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 (+ (* x x) -1.0)))
double code(double x) {
return exp(((x * x) + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(((x * x) + (-1.0d0)))
end function
public static double code(double x) {
return Math.exp(((x * x) + -1.0));
}
def code(x): return math.exp(((x * x) + -1.0))
function code(x) return exp(Float64(Float64(x * x) + -1.0)) end
function tmp = code(x) tmp = exp(((x * x) + -1.0)); end
code[x_] := N[Exp[N[(N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{x \cdot x + -1}
\end{array}
Initial program 100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= (* x x) 0.92) (exp -1.0) (exp (* x x))))
double code(double x) {
double tmp;
if ((x * x) <= 0.92) {
tmp = exp(-1.0);
} else {
tmp = exp((x * x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x * x) <= 0.92d0) then
tmp = exp((-1.0d0))
else
tmp = exp((x * x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x * x) <= 0.92) {
tmp = Math.exp(-1.0);
} else {
tmp = Math.exp((x * x));
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 0.92: tmp = math.exp(-1.0) else: tmp = math.exp((x * x)) return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 0.92) tmp = exp(-1.0); else tmp = exp(Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 0.92) tmp = exp(-1.0); else tmp = exp((x * x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 0.92], N[Exp[-1.0], $MachinePrecision], N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 0.92:\\
\;\;\;\;e^{-1}\\
\mathbf{else}:\\
\;\;\;\;e^{x \cdot x}\\
\end{array}
\end{array}
if (*.f64 x x) < 0.92000000000000004Initial program 100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 98.2%
if 0.92000000000000004 < (*.f64 x x) Initial program 100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 99.4%
unpow299.4%
Simplified99.4%
Final simplification98.9%
(FPCore (x) :precision binary64 (exp -1.0))
double code(double x) {
return exp(-1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp((-1.0d0))
end function
public static double code(double x) {
return Math.exp(-1.0);
}
def code(x): return math.exp(-1.0)
function code(x) return exp(-1.0) end
function tmp = code(x) tmp = exp(-1.0); end
code[x_] := N[Exp[-1.0], $MachinePrecision]
\begin{array}{l}
\\
e^{-1}
\end{array}
Initial program 100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 45.1%
Final simplification45.1%
herbie shell --seed 2023175
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))