
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
(FPCore (x y)
:precision binary64
(if (<= x -4e-62)
(/ (* (/ x (+ x 1.0)) (+ x y)) y)
(if (<= x 5800000000000.0)
(/ (fma (/ x y) x x) (+ x 1.0))
(+ 1.0 (/ (+ x -1.0) y)))))
double code(double x, double y) {
double tmp;
if (x <= -4e-62) {
tmp = ((x / (x + 1.0)) * (x + y)) / y;
} else if (x <= 5800000000000.0) {
tmp = fma((x / y), x, x) / (x + 1.0);
} else {
tmp = 1.0 + ((x + -1.0) / y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -4e-62) tmp = Float64(Float64(Float64(x / Float64(x + 1.0)) * Float64(x + y)) / y); elseif (x <= 5800000000000.0) tmp = Float64(fma(Float64(x / y), x, x) / Float64(x + 1.0)); else tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y)); end return tmp end
code[x_, y_] := If[LessEqual[x, -4e-62], N[(N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[x, 5800000000000.0], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-62}:\\
\;\;\;\;\frac{\frac{x}{x + 1} \cdot \left(x + y\right)}{y}\\
\mathbf{elif}\;x \leq 5800000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\end{array}
\end{array}
if x < -4.0000000000000002e-62Initial program 84.8%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
if -4.0000000000000002e-62 < x < 5.8e12Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6499.9
Applied rewrites99.9%
if 5.8e12 < x Initial program 75.7%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
distribute-rgt-out--N/A
associate-*l/N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6428.1
Applied rewrites28.1%
Taylor expanded in y around inf
Applied rewrites11.5%
Taylor expanded in x around inf
associate--l+N/A
distribute-rgt-inN/A
lft-mult-inverseN/A
*-commutativeN/A
sub-negN/A
distribute-lft-inN/A
associate-*r/N/A
*-rgt-identityN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
sub-negN/A
lower-+.f64N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))) (t_1 (/ (+ x -1.0) y)))
(if (<= t_0 -2e+25)
t_1
(if (<= t_0 2.0)
(/ x (+ x 1.0))
(if (<= t_0 5e+111) (* x (/ x y)) t_1)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double t_1 = (x + -1.0) / y;
double tmp;
if (t_0 <= -2e+25) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x / (x + 1.0);
} else if (t_0 <= 5e+111) {
tmp = x * (x / y);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
t_1 = (x + (-1.0d0)) / y
if (t_0 <= (-2d+25)) then
tmp = t_1
else if (t_0 <= 2.0d0) then
tmp = x / (x + 1.0d0)
else if (t_0 <= 5d+111) then
tmp = x * (x / y)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double t_1 = (x + -1.0) / y;
double tmp;
if (t_0 <= -2e+25) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x / (x + 1.0);
} else if (t_0 <= 5e+111) {
tmp = x * (x / y);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x + 1.0) t_1 = (x + -1.0) / y tmp = 0 if t_0 <= -2e+25: tmp = t_1 elif t_0 <= 2.0: tmp = x / (x + 1.0) elif t_0 <= 5e+111: tmp = x * (x / y) else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) t_1 = Float64(Float64(x + -1.0) / y) tmp = 0.0 if (t_0 <= -2e+25) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(x / Float64(x + 1.0)); elseif (t_0 <= 5e+111) tmp = Float64(x * Float64(x / y)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (x * ((x / y) + 1.0)) / (x + 1.0); t_1 = (x + -1.0) / y; tmp = 0.0; if (t_0 <= -2e+25) tmp = t_1; elseif (t_0 <= 2.0) tmp = x / (x + 1.0); elseif (t_0 <= 5e+111) tmp = x * (x / y); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+25], t$95$1, If[LessEqual[t$95$0, 2.0], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+111], N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
t_1 := \frac{x + -1}{y}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{x + 1}\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+111}:\\
\;\;\;\;x \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -2.00000000000000018e25 or 4.9999999999999997e111 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 67.4%
Taylor expanded in y around 0
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6487.8
Applied rewrites87.8%
Taylor expanded in x around inf
Applied rewrites88.4%
Taylor expanded in x around inf
Applied rewrites88.7%
if -2.00000000000000018e25 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f6486.1
Applied rewrites86.1%
if 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 4.9999999999999997e111Initial program 99.7%
Taylor expanded in y around 0
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6481.6
Applied rewrites81.6%
Taylor expanded in x around 0
Applied rewrites33.3%
(FPCore (x y) :precision binary64 (* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0))))
double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / 1.0d0) * (((x / y) + 1.0d0) / (x + 1.0d0))
end function
public static double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
def code(x, y): return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0))
function code(x, y) return Float64(Float64(x / 1.0) * Float64(Float64(Float64(x / y) + 1.0) / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = (x / 1.0) * (((x / y) + 1.0) / (x + 1.0)); end
code[x_, y_] := N[(N[(x / 1.0), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1} \cdot \frac{\frac{x}{y} + 1}{x + 1}
\end{array}
herbie shell --seed 2024228
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:alt
(! :herbie-platform default (* (/ x 1) (/ (+ (/ x y) 1) (+ x 1))))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))