
(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 6 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 (/ x (/ (+ x 1.0) (+ 1.0 (/ x y)))))
double code(double x, double y) {
return x / ((x + 1.0) / (1.0 + (x / y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / ((x + 1.0d0) / (1.0d0 + (x / y)))
end function
public static double code(double x, double y) {
return x / ((x + 1.0) / (1.0 + (x / y)));
}
def code(x, y): return x / ((x + 1.0) / (1.0 + (x / y)))
function code(x, y) return Float64(x / Float64(Float64(x + 1.0) / Float64(1.0 + Float64(x / y)))) end
function tmp = code(x, y) tmp = x / ((x + 1.0) / (1.0 + (x / y))); end
code[x_, y_] := N[(x / N[(N[(x + 1.0), $MachinePrecision] / N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{x + 1}{1 + \frac{x}{y}}}
\end{array}
Initial program 87.1%
associate-/l*99.8%
Simplified99.8%
clear-num99.8%
un-div-inv99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= x -36000000.0) (not (<= x 7e+55))) (/ x (+ y (/ y x))) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -36000000.0) || !(x <= 7e+55)) {
tmp = x / (y + (y / x));
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-36000000.0d0)) .or. (.not. (x <= 7d+55))) then
tmp = x / (y + (y / x))
else
tmp = x / (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -36000000.0) || !(x <= 7e+55)) {
tmp = x / (y + (y / x));
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -36000000.0) or not (x <= 7e+55): tmp = x / (y + (y / x)) else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -36000000.0) || !(x <= 7e+55)) tmp = Float64(x / Float64(y + Float64(y / x))); else tmp = Float64(x / Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -36000000.0) || ~((x <= 7e+55))) tmp = x / (y + (y / x)); else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -36000000.0], N[Not[LessEqual[x, 7e+55]], $MachinePrecision]], N[(x / N[(y + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -36000000 \lor \neg \left(x \leq 7 \cdot 10^{+55}\right):\\
\;\;\;\;\frac{x}{y + \frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -3.6e7 or 7.00000000000000021e55 < x Initial program 72.1%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 73.2%
clear-num73.2%
un-div-inv73.3%
+-commutative73.3%
*-commutative73.3%
associate-/l*85.0%
Applied egg-rr85.0%
Taylor expanded in x around 0 73.3%
distribute-rgt1-in73.3%
associate-*r/85.0%
distribute-lft1-in76.6%
*-commutative76.6%
associate-*l/73.3%
associate-/l*85.1%
*-inverses85.1%
*-rgt-identity85.1%
Simplified85.1%
if -3.6e7 < x < 7.00000000000000021e55Initial program 99.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 74.2%
Final simplification79.2%
(FPCore (x y) :precision binary64 (if (or (<= x -23000000000.0) (not (<= x 6e+55))) (/ x y) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -23000000000.0) || !(x <= 6e+55)) {
tmp = x / y;
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-23000000000.0d0)) .or. (.not. (x <= 6d+55))) then
tmp = x / y
else
tmp = x / (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -23000000000.0) || !(x <= 6e+55)) {
tmp = x / y;
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -23000000000.0) or not (x <= 6e+55): tmp = x / y else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -23000000000.0) || !(x <= 6e+55)) tmp = Float64(x / y); else tmp = Float64(x / Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -23000000000.0) || ~((x <= 6e+55))) tmp = x / y; else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -23000000000.0], N[Not[LessEqual[x, 6e+55]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -23000000000 \lor \neg \left(x \leq 6 \cdot 10^{+55}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -2.3e10 or 6.00000000000000033e55 < x Initial program 72.1%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 84.9%
if -2.3e10 < x < 6.00000000000000033e55Initial program 99.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 74.2%
Final simplification79.1%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.16e+29))) (/ x y) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.16e+29)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.16d+29))) then
tmp = x / y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.16e+29)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 1.16e+29): tmp = x / y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.16e+29)) tmp = Float64(x / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.16e+29))) tmp = x / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.16e+29]], $MachinePrecision]], N[(x / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1.16 \cdot 10^{+29}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 1.16e29 < x Initial program 74.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 80.4%
if -1 < x < 1.16e29Initial program 99.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 72.4%
Final simplification76.5%
(FPCore (x y) :precision binary64 (* x (/ (+ 1.0 (/ x y)) (+ x 1.0))))
double code(double x, double y) {
return x * ((1.0 + (x / y)) / (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)) / (x + 1.0d0))
end function
public static double code(double x, double y) {
return x * ((1.0 + (x / y)) / (x + 1.0));
}
def code(x, y): return x * ((1.0 + (x / y)) / (x + 1.0))
function code(x, y) return Float64(x * Float64(Float64(1.0 + Float64(x / y)) / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = x * ((1.0 + (x / y)) / (x + 1.0)); end
code[x_, y_] := N[(x * N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{1 + \frac{x}{y}}{x + 1}
\end{array}
Initial program 87.1%
associate-/l*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 87.1%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 37.8%
Final simplification37.8%
(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 2024054
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:alt
(* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0)))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))