
(FPCore (x y z) :precision binary64 (+ x (/ y (- (* 1.1283791670955126 (exp z)) (* x y)))))
double code(double x, double y, double z) {
return x + (y / ((1.1283791670955126 * exp(z)) - (x * y)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y / ((1.1283791670955126d0 * exp(z)) - (x * y)))
end function
public static double code(double x, double y, double z) {
return x + (y / ((1.1283791670955126 * Math.exp(z)) - (x * y)));
}
def code(x, y, z): return x + (y / ((1.1283791670955126 * math.exp(z)) - (x * y)))
function code(x, y, z) return Float64(x + Float64(y / Float64(Float64(1.1283791670955126 * exp(z)) - Float64(x * y)))) end
function tmp = code(x, y, z) tmp = x + (y / ((1.1283791670955126 * exp(z)) - (x * y))); end
code[x_, y_, z_] := N[(x + N[(y / N[(N[(1.1283791670955126 * N[Exp[z], $MachinePrecision]), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (/ y (- (* 1.1283791670955126 (exp z)) (* x y)))))
double code(double x, double y, double z) {
return x + (y / ((1.1283791670955126 * exp(z)) - (x * y)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y / ((1.1283791670955126d0 * exp(z)) - (x * y)))
end function
public static double code(double x, double y, double z) {
return x + (y / ((1.1283791670955126 * Math.exp(z)) - (x * y)));
}
def code(x, y, z): return x + (y / ((1.1283791670955126 * math.exp(z)) - (x * y)))
function code(x, y, z) return Float64(x + Float64(y / Float64(Float64(1.1283791670955126 * exp(z)) - Float64(x * y)))) end
function tmp = code(x, y, z) tmp = x + (y / ((1.1283791670955126 * exp(z)) - (x * y))); end
code[x_, y_, z_] := N[(x + N[(y / N[(N[(1.1283791670955126 * N[Exp[z], $MachinePrecision]), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= (exp z) 0.0) (+ (/ -1.0 x) x) (+ (/ y (* (fma (/ (exp z) x) 1.1283791670955126 (- y)) x)) x)))
double code(double x, double y, double z) {
double tmp;
if (exp(z) <= 0.0) {
tmp = (-1.0 / x) + x;
} else {
tmp = (y / (fma((exp(z) / x), 1.1283791670955126, -y) * x)) + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (exp(z) <= 0.0) tmp = Float64(Float64(-1.0 / x) + x); else tmp = Float64(Float64(y / Float64(fma(Float64(exp(z) / x), 1.1283791670955126, Float64(-y)) * x)) + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[Exp[z], $MachinePrecision], 0.0], N[(N[(-1.0 / x), $MachinePrecision] + x), $MachinePrecision], N[(N[(y / N[(N[(N[(N[Exp[z], $MachinePrecision] / x), $MachinePrecision] * 1.1283791670955126 + (-y)), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{z} \leq 0:\\
\;\;\;\;\frac{-1}{x} + x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\mathsf{fma}\left(\frac{e^{z}}{x}, 1.1283791670955126, -y\right) \cdot x} + x\\
\end{array}
\end{array}
if (exp.f64 z) < 0.0Initial program 92.3%
Taylor expanded in y around inf
lower-/.f64100.0
Applied rewrites100.0%
if 0.0 < (exp.f64 z) Initial program 98.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
mul-1-negN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-exp.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= (exp z) 0.0)
(+ (/ -1.0 x) x)
(if (<= (exp z) 2e+163)
(+
(/
y
(fma
(fma
(fma 0.18806319451591877 z 0.5641895835477563)
z
1.1283791670955126)
z
(fma (- x) y 1.1283791670955126)))
x)
(* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (exp(z) <= 0.0) {
tmp = (-1.0 / x) + x;
} else if (exp(z) <= 2e+163) {
tmp = (y / fma(fma(fma(0.18806319451591877, z, 0.5641895835477563), z, 1.1283791670955126), z, fma(-x, y, 1.1283791670955126))) + x;
} else {
tmp = 1.0 * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (exp(z) <= 0.0) tmp = Float64(Float64(-1.0 / x) + x); elseif (exp(z) <= 2e+163) tmp = Float64(Float64(y / fma(fma(fma(0.18806319451591877, z, 0.5641895835477563), z, 1.1283791670955126), z, fma(Float64(-x), y, 1.1283791670955126))) + x); else tmp = Float64(1.0 * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[Exp[z], $MachinePrecision], 0.0], N[(N[(-1.0 / x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[N[Exp[z], $MachinePrecision], 2e+163], N[(N[(y / N[(N[(N[(0.18806319451591877 * z + 0.5641895835477563), $MachinePrecision] * z + 1.1283791670955126), $MachinePrecision] * z + N[((-x) * y + 1.1283791670955126), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{z} \leq 0:\\
\;\;\;\;\frac{-1}{x} + x\\
\mathbf{elif}\;e^{z} \leq 2 \cdot 10^{+163}:\\
\;\;\;\;\frac{y}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.18806319451591877, z, 0.5641895835477563\right), z, 1.1283791670955126\right), z, \mathsf{fma}\left(-x, y, 1.1283791670955126\right)\right)} + x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if (exp.f64 z) < 0.0Initial program 89.2%
Taylor expanded in y around inf
lower-/.f64100.0
Applied rewrites100.0%
if 0.0 < (exp.f64 z) < 1.9999999999999999e163Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
associate--l+N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
+-commutativeN/A
mul-1-negN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6499.5
Applied rewrites99.5%
if 1.9999999999999999e163 < (exp.f64 z) Initial program 93.2%
Taylor expanded in y around 0
+-commutativeN/A
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
rec-expN/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites50.3%
Taylor expanded in x around inf
Applied rewrites50.2%
Taylor expanded in y around 0
Applied rewrites100.0%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (+ x (/ 1.0 (- (* (/ 1.1283791670955126 y) (exp z)) x))))
double code(double x, double y, double z) {
return x + (1.0 / (((1.1283791670955126 / y) * exp(z)) - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (1.0d0 / (((1.1283791670955126d0 / y) * exp(z)) - x))
end function
public static double code(double x, double y, double z) {
return x + (1.0 / (((1.1283791670955126 / y) * Math.exp(z)) - x));
}
def code(x, y, z): return x + (1.0 / (((1.1283791670955126 / y) * math.exp(z)) - x))
function code(x, y, z) return Float64(x + Float64(1.0 / Float64(Float64(Float64(1.1283791670955126 / y) * exp(z)) - x))) end
function tmp = code(x, y, z) tmp = x + (1.0 / (((1.1283791670955126 / y) * exp(z)) - x)); end
code[x_, y_, z_] := N[(x + N[(1.0 / N[(N[(N[(1.1283791670955126 / y), $MachinePrecision] * N[Exp[z], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{1}{\frac{1.1283791670955126}{y} \cdot e^{z} - x}
\end{array}
herbie shell --seed 2024230
(FPCore (x y z)
:name "Numeric.SpecFunctions:invErfc from math-functions-0.1.5.2, A"
:precision binary64
:alt
(! :herbie-platform default (+ x (/ 1 (- (* (/ 5641895835477563/5000000000000000 y) (exp z)) x))))
(+ x (/ y (- (* 1.1283791670955126 (exp z)) (* x y)))))