
(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 7 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 88.6%
associate-/l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(if (<= x -1.0)
(/ x y)
(if (<= x 2.1e-13)
x
(if (or (<= x 3.9e+30) (not (<= x 5.8e+91))) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x / y;
} else if (x <= 2.1e-13) {
tmp = x;
} else if ((x <= 3.9e+30) || !(x <= 5.8e+91)) {
tmp = x / y;
} else {
tmp = 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 <= (-1.0d0)) then
tmp = x / y
else if (x <= 2.1d-13) then
tmp = x
else if ((x <= 3.9d+30) .or. (.not. (x <= 5.8d+91))) then
tmp = x / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x / y;
} else if (x <= 2.1e-13) {
tmp = x;
} else if ((x <= 3.9e+30) || !(x <= 5.8e+91)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x / y elif x <= 2.1e-13: tmp = x elif (x <= 3.9e+30) or not (x <= 5.8e+91): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x / y); elseif (x <= 2.1e-13) tmp = x; elseif ((x <= 3.9e+30) || !(x <= 5.8e+91)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = x / y; elseif (x <= 2.1e-13) tmp = x; elseif ((x <= 3.9e+30) || ~((x <= 5.8e+91))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x / y), $MachinePrecision], If[LessEqual[x, 2.1e-13], x, If[Or[LessEqual[x, 3.9e+30], N[Not[LessEqual[x, 5.8e+91]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-13}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{+30} \lor \neg \left(x \leq 5.8 \cdot 10^{+91}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1 or 2.09999999999999989e-13 < x < 3.90000000000000011e30 or 5.80000000000000028e91 < x Initial program 77.7%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around inf 84.1%
if -1 < x < 2.09999999999999989e-13Initial program 99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 68.6%
if 3.90000000000000011e30 < x < 5.80000000000000028e91Initial program 84.5%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around inf 69.3%
Taylor expanded in x around inf 69.3%
Final simplification76.0%
(FPCore (x y)
:precision binary64
(if (<= x -1.32e+22)
(/ x y)
(if (<= x 550000.0)
(/ x (+ x 1.0))
(if (or (<= x 8.8e+30) (not (<= x 1.1e+92))) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (x <= -1.32e+22) {
tmp = x / y;
} else if (x <= 550000.0) {
tmp = x / (x + 1.0);
} else if ((x <= 8.8e+30) || !(x <= 1.1e+92)) {
tmp = x / y;
} else {
tmp = 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 <= (-1.32d+22)) then
tmp = x / y
else if (x <= 550000.0d0) then
tmp = x / (x + 1.0d0)
else if ((x <= 8.8d+30) .or. (.not. (x <= 1.1d+92))) then
tmp = x / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.32e+22) {
tmp = x / y;
} else if (x <= 550000.0) {
tmp = x / (x + 1.0);
} else if ((x <= 8.8e+30) || !(x <= 1.1e+92)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.32e+22: tmp = x / y elif x <= 550000.0: tmp = x / (x + 1.0) elif (x <= 8.8e+30) or not (x <= 1.1e+92): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.32e+22) tmp = Float64(x / y); elseif (x <= 550000.0) tmp = Float64(x / Float64(x + 1.0)); elseif ((x <= 8.8e+30) || !(x <= 1.1e+92)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.32e+22) tmp = x / y; elseif (x <= 550000.0) tmp = x / (x + 1.0); elseif ((x <= 8.8e+30) || ~((x <= 1.1e+92))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.32e+22], N[(x / y), $MachinePrecision], If[LessEqual[x, 550000.0], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, 8.8e+30], N[Not[LessEqual[x, 1.1e+92]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.32 \cdot 10^{+22}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 550000:\\
\;\;\;\;\frac{x}{x + 1}\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{+30} \lor \neg \left(x \leq 1.1 \cdot 10^{+92}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.32e22 or 5.5e5 < x < 8.7999999999999999e30 or 1.09999999999999996e92 < x Initial program 76.4%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around inf 88.6%
if -1.32e22 < x < 5.5e5Initial program 99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 68.8%
if 8.7999999999999999e30 < x < 1.09999999999999996e92Initial program 84.5%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around inf 69.3%
Taylor expanded in x around inf 69.3%
Final simplification77.7%
(FPCore (x y)
:precision binary64
(if (<= x -1.15e+21)
(/ x y)
(if (<= x 155000.0)
(/ x (+ x 1.0))
(if (<= x 8.8e+30) (/ (+ x -1.0) y) (if (<= x 6.2e+91) 1.0 (/ x y))))))
double code(double x, double y) {
double tmp;
if (x <= -1.15e+21) {
tmp = x / y;
} else if (x <= 155000.0) {
tmp = x / (x + 1.0);
} else if (x <= 8.8e+30) {
tmp = (x + -1.0) / y;
} else if (x <= 6.2e+91) {
tmp = 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) :: tmp
if (x <= (-1.15d+21)) then
tmp = x / y
else if (x <= 155000.0d0) then
tmp = x / (x + 1.0d0)
else if (x <= 8.8d+30) then
tmp = (x + (-1.0d0)) / y
else if (x <= 6.2d+91) then
tmp = 1.0d0
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.15e+21) {
tmp = x / y;
} else if (x <= 155000.0) {
tmp = x / (x + 1.0);
} else if (x <= 8.8e+30) {
tmp = (x + -1.0) / y;
} else if (x <= 6.2e+91) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.15e+21: tmp = x / y elif x <= 155000.0: tmp = x / (x + 1.0) elif x <= 8.8e+30: tmp = (x + -1.0) / y elif x <= 6.2e+91: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.15e+21) tmp = Float64(x / y); elseif (x <= 155000.0) tmp = Float64(x / Float64(x + 1.0)); elseif (x <= 8.8e+30) tmp = Float64(Float64(x + -1.0) / y); elseif (x <= 6.2e+91) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.15e+21) tmp = x / y; elseif (x <= 155000.0) tmp = x / (x + 1.0); elseif (x <= 8.8e+30) tmp = (x + -1.0) / y; elseif (x <= 6.2e+91) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.15e+21], N[(x / y), $MachinePrecision], If[LessEqual[x, 155000.0], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8.8e+30], N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[x, 6.2e+91], 1.0, N[(x / y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{+21}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 155000:\\
\;\;\;\;\frac{x}{x + 1}\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{+30}:\\
\;\;\;\;\frac{x + -1}{y}\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{+91}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -1.15e21 or 6.19999999999999995e91 < x Initial program 73.6%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around inf 89.5%
if -1.15e21 < x < 155000Initial program 99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 68.8%
if 155000 < x < 8.7999999999999999e30Initial program 99.7%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around inf 99.6%
Taylor expanded in y around 0 83.6%
if 8.7999999999999999e30 < x < 6.19999999999999995e91Initial program 84.5%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around inf 69.3%
Taylor expanded in x around inf 69.3%
Final simplification77.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1e+21) (not (<= x 112000.0))) (+ 1.0 (/ (+ x -1.0) y)) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -1e+21) || !(x <= 112000.0)) {
tmp = 1.0 + ((x + -1.0) / 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 <= (-1d+21)) .or. (.not. (x <= 112000.0d0))) then
tmp = 1.0d0 + ((x + (-1.0d0)) / 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 <= -1e+21) || !(x <= 112000.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1e+21) or not (x <= 112000.0): tmp = 1.0 + ((x + -1.0) / y) else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -1e+21) || !(x <= 112000.0)) tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y)); else tmp = Float64(x / Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1e+21) || ~((x <= 112000.0))) tmp = 1.0 + ((x + -1.0) / y); else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1e+21], N[Not[LessEqual[x, 112000.0]], $MachinePrecision]], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+21} \lor \neg \left(x \leq 112000\right):\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -1e21 or 112000 < x Initial program 77.1%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate--l+100.0%
+-commutative100.0%
sub-div100.0%
Applied egg-rr100.0%
if -1e21 < x < 112000Initial program 99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 68.8%
Final simplification84.2%
(FPCore (x y) :precision binary64 (if (<= x -1.0) 1.0 (if (<= x 2.1e-13) x 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = 1.0;
} else if (x <= 2.1e-13) {
tmp = x;
} else {
tmp = 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 <= (-1.0d0)) then
tmp = 1.0d0
else if (x <= 2.1d-13) then
tmp = x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = 1.0;
} else if (x <= 2.1e-13) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = 1.0 elif x <= 2.1e-13: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = 1.0; elseif (x <= 2.1e-13) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = 1.0; elseif (x <= 2.1e-13) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], 1.0, If[LessEqual[x, 2.1e-13], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-13}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1 or 2.09999999999999989e-13 < x Initial program 78.3%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around inf 20.4%
Taylor expanded in x around inf 19.3%
if -1 < x < 2.09999999999999989e-13Initial program 99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 68.6%
Final simplification43.0%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 88.6%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 43.9%
Taylor expanded in x around inf 11.7%
Final simplification11.7%
(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 2024024
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:herbie-target
(* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0)))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))