
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
double code(double x, double y) {
return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - (((1.0d0 - x) * y) / (y + 1.0d0))
end function
public static double code(double x, double y) {
return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
def code(x, y): return 1.0 - (((1.0 - x) * y) / (y + 1.0))
function code(x, y) return Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0))) end
function tmp = code(x, y) tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0)); end
code[x_, y_] := N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
double code(double x, double y) {
return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - (((1.0d0 - x) * y) / (y + 1.0d0))
end function
public static double code(double x, double y) {
return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
def code(x, y): return 1.0 - (((1.0 - x) * y) / (y + 1.0))
function code(x, y) return Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0))) end
function tmp = code(x, y) tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0)); end
code[x_, y_] := N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ y (+ 1.0 y)))
(t_1 (/ (* (- 1.0 x) y) (+ 1.0 y)))
(t_2 (* (- 1.0 x) (+ -1.0 (/ 1.0 y)))))
(if (<= t_1 0.0001)
(fma x (* (+ 1.0 (/ -1.0 x)) t_0) 1.0)
(if (<= t_1 2e+17)
(+
x
(/
(/
(+ (/ (* t_2 t_2) (* y y)) (* (- 1.0 x) (+ x -1.0)))
(fma (/ (+ x -1.0) y) (+ 1.0 (/ -1.0 y)) (+ x -1.0)))
y))
(* x t_0)))))
double code(double x, double y) {
double t_0 = y / (1.0 + y);
double t_1 = ((1.0 - x) * y) / (1.0 + y);
double t_2 = (1.0 - x) * (-1.0 + (1.0 / y));
double tmp;
if (t_1 <= 0.0001) {
tmp = fma(x, ((1.0 + (-1.0 / x)) * t_0), 1.0);
} else if (t_1 <= 2e+17) {
tmp = x + (((((t_2 * t_2) / (y * y)) + ((1.0 - x) * (x + -1.0))) / fma(((x + -1.0) / y), (1.0 + (-1.0 / y)), (x + -1.0))) / y);
} else {
tmp = x * t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(y / Float64(1.0 + y)) t_1 = Float64(Float64(Float64(1.0 - x) * y) / Float64(1.0 + y)) t_2 = Float64(Float64(1.0 - x) * Float64(-1.0 + Float64(1.0 / y))) tmp = 0.0 if (t_1 <= 0.0001) tmp = fma(x, Float64(Float64(1.0 + Float64(-1.0 / x)) * t_0), 1.0); elseif (t_1 <= 2e+17) tmp = Float64(x + Float64(Float64(Float64(Float64(Float64(t_2 * t_2) / Float64(y * y)) + Float64(Float64(1.0 - x) * Float64(x + -1.0))) / fma(Float64(Float64(x + -1.0) / y), Float64(1.0 + Float64(-1.0 / y)), Float64(x + -1.0))) / y)); else tmp = Float64(x * t_0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(1.0 - x), $MachinePrecision] * N[(-1.0 + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0001], N[(x * N[(N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[t$95$1, 2e+17], N[(x + N[(N[(N[(N[(N[(t$95$2 * t$95$2), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision] * N[(1.0 + N[(-1.0 / y), $MachinePrecision]), $MachinePrecision] + N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x * t$95$0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{1 + y}\\
t_1 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
t_2 := \left(1 - x\right) \cdot \left(-1 + \frac{1}{y}\right)\\
\mathbf{if}\;t\_1 \leq 0.0001:\\
\;\;\;\;\mathsf{fma}\left(x, \left(1 + \frac{-1}{x}\right) \cdot t\_0, 1\right)\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+17}:\\
\;\;\;\;x + \frac{\frac{\frac{t\_2 \cdot t\_2}{y \cdot y} + \left(1 - x\right) \cdot \left(x + -1\right)}{\mathsf{fma}\left(\frac{x + -1}{y}, 1 + \frac{-1}{y}, x + -1\right)}}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot t\_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) < 1.00000000000000005e-4Initial program 89.7%
Taylor expanded in y around 0
Applied rewrites68.9%
Taylor expanded in x around inf
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
Applied rewrites100.0%
if 1.00000000000000005e-4 < (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) < 2e17Initial program 18.1%
Taylor expanded in y around 0
Applied rewrites4.7%
Taylor expanded in x around inf
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
Applied rewrites17.9%
Taylor expanded in y around -inf
Applied rewrites99.8%
Applied rewrites99.8%
if 2e17 < (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) Initial program 75.8%
Taylor expanded in x around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ y (+ 1.0 y))) (t_1 (/ (* (- 1.0 x) y) (+ 1.0 y))))
(if (<= t_1 0.0001)
(fma x (* (+ 1.0 (/ -1.0 x)) t_0) 1.0)
(if (<= t_1 2e+17)
(+ x (/ (- 1.0 (fma (/ (+ x -1.0) y) (+ -1.0 (/ 1.0 y)) x)) y))
(* x t_0)))))
double code(double x, double y) {
double t_0 = y / (1.0 + y);
double t_1 = ((1.0 - x) * y) / (1.0 + y);
double tmp;
if (t_1 <= 0.0001) {
tmp = fma(x, ((1.0 + (-1.0 / x)) * t_0), 1.0);
} else if (t_1 <= 2e+17) {
tmp = x + ((1.0 - fma(((x + -1.0) / y), (-1.0 + (1.0 / y)), x)) / y);
} else {
tmp = x * t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(y / Float64(1.0 + y)) t_1 = Float64(Float64(Float64(1.0 - x) * y) / Float64(1.0 + y)) tmp = 0.0 if (t_1 <= 0.0001) tmp = fma(x, Float64(Float64(1.0 + Float64(-1.0 / x)) * t_0), 1.0); elseif (t_1 <= 2e+17) tmp = Float64(x + Float64(Float64(1.0 - fma(Float64(Float64(x + -1.0) / y), Float64(-1.0 + Float64(1.0 / y)), x)) / y)); else tmp = Float64(x * t_0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0001], N[(x * N[(N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[t$95$1, 2e+17], N[(x + N[(N[(1.0 - N[(N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision] * N[(-1.0 + N[(1.0 / y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x * t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{1 + y}\\
t_1 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
\mathbf{if}\;t\_1 \leq 0.0001:\\
\;\;\;\;\mathsf{fma}\left(x, \left(1 + \frac{-1}{x}\right) \cdot t\_0, 1\right)\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+17}:\\
\;\;\;\;x + \frac{1 - \mathsf{fma}\left(\frac{x + -1}{y}, -1 + \frac{1}{y}, x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot t\_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) < 1.00000000000000005e-4Initial program 88.5%
Taylor expanded in y around 0
Applied rewrites65.2%
Taylor expanded in x around inf
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
Applied rewrites100.0%
if 1.00000000000000005e-4 < (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) < 2e17Initial program 15.9%
Taylor expanded in y around -inf
Applied rewrites95.3%
if 2e17 < (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) Initial program 67.7%
Taylor expanded in x around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Final simplification98.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (/ 1.0 y) (- (/ x y) x))))
(if (< y -3693.8482788297247)
t_0
(if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) t_0))))
double code(double x, double y) {
double t_0 = (1.0 / y) - ((x / y) - x);
double tmp;
if (y < -3693.8482788297247) {
tmp = t_0;
} else if (y < 6799310503.41891) {
tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 / y) - ((x / y) - x)
if (y < (-3693.8482788297247d0)) then
tmp = t_0
else if (y < 6799310503.41891d0) then
tmp = 1.0d0 - (((1.0d0 - x) * y) / (y + 1.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (1.0 / y) - ((x / y) - x);
double tmp;
if (y < -3693.8482788297247) {
tmp = t_0;
} else if (y < 6799310503.41891) {
tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (1.0 / y) - ((x / y) - x) tmp = 0 if y < -3693.8482788297247: tmp = t_0 elif y < 6799310503.41891: tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0)) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(1.0 / y) - Float64(Float64(x / y) - x)) tmp = 0.0 if (y < -3693.8482788297247) tmp = t_0; elseif (y < 6799310503.41891) tmp = Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (1.0 / y) - ((x / y) - x); tmp = 0.0; if (y < -3693.8482788297247) tmp = t_0; elseif (y < 6799310503.41891) tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(1.0 / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]}, If[Less[y, -3693.8482788297247], t$95$0, If[Less[y, 6799310503.41891], N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{y} - \left(\frac{x}{y} - x\right)\\
\mathbf{if}\;y < -3693.8482788297247:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y < 6799310503.41891:\\
\;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
herbie shell --seed 2024228
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, D"
:precision binary64
:alt
(! :herbie-platform default (if (< y -36938482788297247/10000000000000) (- (/ 1 y) (- (/ x y) x)) (if (< y 679931050341891/100000) (- 1 (/ (* (- 1 x) y) (+ y 1))) (- (/ 1 y) (- (/ x y) x)))))
(- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))