
(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 8 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 (let* ((t_0 (+ (/ x y) 1.0))) (if (<= x -6.2e+37) t_0 (if (<= x 5e+14) (/ (* x t_0) (+ x 1.0)) t_0))))
double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double tmp;
if (x <= -6.2e+37) {
tmp = t_0;
} else if (x <= 5e+14) {
tmp = (x * t_0) / (x + 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 = (x / y) + 1.0d0
if (x <= (-6.2d+37)) then
tmp = t_0
else if (x <= 5d+14) then
tmp = (x * t_0) / (x + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double tmp;
if (x <= -6.2e+37) {
tmp = t_0;
} else if (x <= 5e+14) {
tmp = (x * t_0) / (x + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x / y) + 1.0 tmp = 0 if x <= -6.2e+37: tmp = t_0 elif x <= 5e+14: tmp = (x * t_0) / (x + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x / y) + 1.0) tmp = 0.0 if (x <= -6.2e+37) tmp = t_0; elseif (x <= 5e+14) tmp = Float64(Float64(x * t_0) / Float64(x + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x / y) + 1.0; tmp = 0.0; if (x <= -6.2e+37) tmp = t_0; elseif (x <= 5e+14) tmp = (x * t_0) / (x + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -6.2e+37], t$95$0, If[LessEqual[x, 5e+14], N[(N[(x * t$95$0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y} + 1\\
\mathbf{if}\;x \leq -6.2 \cdot 10^{+37}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+14}:\\
\;\;\;\;\frac{x \cdot t\_0}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.2000000000000004e37 or 5e14 < x Initial program 69.3%
Taylor expanded in x around 0
Applied rewrites100.0%
if -6.2000000000000004e37 < x < 5e14Initial program 99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (/ x y) 1.0)) (t_1 (/ (* x t_0) (+ x 1.0))))
(if (<= t_1 -5000000000000.0)
t_0
(if (<= t_1 5e-5) (* x (+ (+ x 1.0) 1.0)) t_0))))
double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double t_1 = (x * t_0) / (x + 1.0);
double tmp;
if (t_1 <= -5000000000000.0) {
tmp = t_0;
} else if (t_1 <= 5e-5) {
tmp = x * ((x + 1.0) + 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) :: t_1
real(8) :: tmp
t_0 = (x / y) + 1.0d0
t_1 = (x * t_0) / (x + 1.0d0)
if (t_1 <= (-5000000000000.0d0)) then
tmp = t_0
else if (t_1 <= 5d-5) then
tmp = x * ((x + 1.0d0) + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double t_1 = (x * t_0) / (x + 1.0);
double tmp;
if (t_1 <= -5000000000000.0) {
tmp = t_0;
} else if (t_1 <= 5e-5) {
tmp = x * ((x + 1.0) + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x / y) + 1.0 t_1 = (x * t_0) / (x + 1.0) tmp = 0 if t_1 <= -5000000000000.0: tmp = t_0 elif t_1 <= 5e-5: tmp = x * ((x + 1.0) + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x / y) + 1.0) t_1 = Float64(Float64(x * t_0) / Float64(x + 1.0)) tmp = 0.0 if (t_1 <= -5000000000000.0) tmp = t_0; elseif (t_1 <= 5e-5) tmp = Float64(x * Float64(Float64(x + 1.0) + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x / y) + 1.0; t_1 = (x * t_0) / (x + 1.0); tmp = 0.0; if (t_1 <= -5000000000000.0) tmp = t_0; elseif (t_1 <= 5e-5) tmp = x * ((x + 1.0) + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * t$95$0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5000000000000.0], t$95$0, If[LessEqual[t$95$1, 5e-5], N[(x * N[(N[(x + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y} + 1\\
t_1 := \frac{x \cdot t\_0}{x + 1}\\
\mathbf{if}\;t\_1 \leq -5000000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;x \cdot \left(\left(x + 1\right) + 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -5e12 or 5.00000000000000024e-5 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 75.6%
Taylor expanded in x around 0
Applied rewrites86.7%
if -5e12 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 5.00000000000000024e-5Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites97.9%
Taylor expanded in x around 0
Applied rewrites17.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (<= t_0 -5000000000000.0)
(/ x y)
(if (<= t_0 1.0000005) (* x (+ (+ x 1.0) 1.0)) (/ x y)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if (t_0 <= -5000000000000.0) {
tmp = x / y;
} else if (t_0 <= 1.0000005) {
tmp = x * ((x + 1.0) + 1.0);
} else {
tmp = x / y;
}
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 = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
if (t_0 <= (-5000000000000.0d0)) then
tmp = x / y
else if (t_0 <= 1.0000005d0) then
tmp = x * ((x + 1.0d0) + 1.0d0)
else
tmp = x / y
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 tmp;
if (t_0 <= -5000000000000.0) {
tmp = x / y;
} else if (t_0 <= 1.0000005) {
tmp = x * ((x + 1.0) + 1.0);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x + 1.0) tmp = 0 if t_0 <= -5000000000000.0: tmp = x / y elif t_0 <= 1.0000005: tmp = x * ((x + 1.0) + 1.0) else: tmp = x / y return tmp
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if (t_0 <= -5000000000000.0) tmp = Float64(x / y); elseif (t_0 <= 1.0000005) tmp = Float64(x * Float64(Float64(x + 1.0) + 1.0)); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) t_0 = (x * ((x / y) + 1.0)) / (x + 1.0); tmp = 0.0; if (t_0 <= -5000000000000.0) tmp = x / y; elseif (t_0 <= 1.0000005) tmp = x * ((x + 1.0) + 1.0); else tmp = x / y; 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]}, If[LessEqual[t$95$0, -5000000000000.0], N[(x / y), $MachinePrecision], If[LessEqual[t$95$0, 1.0000005], N[(x * N[(N[(x + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq -5000000000000:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;t\_0 \leq 1.0000005:\\
\;\;\;\;x \cdot \left(\left(x + 1\right) + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -5e12 or 1.0000005000000001 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 68.7%
Taylor expanded in x around 0
Applied rewrites83.2%
if -5e12 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 1.0000005000000001Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites76.9%
Taylor expanded in x around 0
Applied rewrites14.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ (/ x y) 1.0))) (if (<= x -1.0) t_0 (if (<= x 1.0) (* x t_0) t_0))))
double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = x * t_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 = (x / y) + 1.0d0
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = x * t_0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = x * t_0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x / y) + 1.0 tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 1.0: tmp = x * t_0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x / y) + 1.0) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = Float64(x * t_0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x / y) + 1.0; tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = x * t_0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], N[(x * t$95$0), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y} + 1\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;x \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 72.4%
Taylor expanded in x around 0
Applied rewrites97.7%
if -1 < x < 1Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites96.6%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ (/ x y) 1.0))) (if (<= x -1.0) t_0 (if (<= x 4.6e-5) (* x (/ x y)) t_0))))
double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 4.6e-5) {
tmp = x * (x / y);
} 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 = (x / y) + 1.0d0
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 4.6d-5) then
tmp = x * (x / y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 4.6e-5) {
tmp = x * (x / y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x / y) + 1.0 tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 4.6e-5: tmp = x * (x / y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x / y) + 1.0) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 4.6e-5) tmp = Float64(x * Float64(x / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x / y) + 1.0; tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= 4.6e-5) tmp = x * (x / y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 4.6e-5], N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y} + 1\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{-5}:\\
\;\;\;\;x \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 4.6e-5 < x Initial program 72.6%
Taylor expanded in x around 0
Applied rewrites97.0%
if -1 < x < 4.6e-5Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites97.0%
Taylor expanded in x around 0
Applied rewrites26.3%
(FPCore (x y) :precision binary64 (* x (+ (+ x 1.0) 1.0)))
double code(double x, double y) {
return x * ((x + 1.0) + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * ((x + 1.0d0) + 1.0d0)
end function
public static double code(double x, double y) {
return x * ((x + 1.0) + 1.0);
}
def code(x, y): return x * ((x + 1.0) + 1.0)
function code(x, y) return Float64(x * Float64(Float64(x + 1.0) + 1.0)) end
function tmp = code(x, y) tmp = x * ((x + 1.0) + 1.0); end
code[x_, y_] := N[(x * N[(N[(x + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\left(x + 1\right) + 1\right)
\end{array}
Initial program 86.1%
Taylor expanded in x around 0
Applied rewrites54.7%
Taylor expanded in x around 0
Applied rewrites13.2%
(FPCore (x y) :precision binary64 (+ (+ x 1.0) 1.0))
double code(double x, double y) {
return (x + 1.0) + 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + 1.0d0) + 1.0d0
end function
public static double code(double x, double y) {
return (x + 1.0) + 1.0;
}
def code(x, y): return (x + 1.0) + 1.0
function code(x, y) return Float64(Float64(x + 1.0) + 1.0) end
function tmp = code(x, y) tmp = (x + 1.0) + 1.0; end
code[x_, y_] := N[(N[(x + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) + 1
\end{array}
Initial program 86.1%
Taylor expanded in x around 0
Applied rewrites50.9%
Taylor expanded in x around 0
Applied rewrites4.1%
(FPCore (x y) :precision binary64 (+ x 1.0))
double code(double x, double y) {
return x + 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + 1.0d0
end function
public static double code(double x, double y) {
return x + 1.0;
}
def code(x, y): return x + 1.0
function code(x, y) return Float64(x + 1.0) end
function tmp = code(x, y) tmp = x + 1.0; end
code[x_, y_] := N[(x + 1.0), $MachinePrecision]
\begin{array}{l}
\\
x + 1
\end{array}
Initial program 86.1%
Taylor expanded in x around 0
Applied rewrites39.3%
Taylor expanded in x around 0
Applied rewrites4.1%
(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 2024321
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (* (/ x 1) (/ (+ (/ x y) 1) (+ x 1))))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))