
(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 9 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 y) 1.0) (/ x (+ x 1.0))))
double code(double x, double y) {
return ((x / y) + 1.0) * (x / (x + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x / y) + 1.0d0) * (x / (x + 1.0d0))
end function
public static double code(double x, double y) {
return ((x / y) + 1.0) * (x / (x + 1.0));
}
def code(x, y): return ((x / y) + 1.0) * (x / (x + 1.0))
function code(x, y) return Float64(Float64(Float64(x / y) + 1.0) * Float64(x / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = ((x / y) + 1.0) * (x / (x + 1.0)); end
code[x_, y_] := N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{y} + 1\right) \cdot \frac{x}{x + 1}
\end{array}
Initial program 89.0%
*-commutative89.0%
associate-/l*99.9%
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.82))) (/ (+ x y) y) (* x (+ 1.0 (- (/ x y) x)))))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.82)) {
tmp = (x + y) / y;
} else {
tmp = x * (1.0 + ((x / y) - 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 <= 0.82d0))) then
tmp = (x + y) / y
else
tmp = x * (1.0d0 + ((x / y) - x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.82)) {
tmp = (x + y) / y;
} else {
tmp = x * (1.0 + ((x / y) - x));
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.82): tmp = (x + y) / y else: tmp = x * (1.0 + ((x / y) - x)) return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.82)) tmp = Float64(Float64(x + y) / y); else tmp = Float64(x * Float64(1.0 + Float64(Float64(x / y) - x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.82))) tmp = (x + y) / y; else tmp = x * (1.0 + ((x / y) - x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.82]], $MachinePrecision]], N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision], N[(x * N[(1.0 + N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.82\right):\\
\;\;\;\;\frac{x + y}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + \left(\frac{x}{y} - x\right)\right)\\
\end{array}
\end{array}
if x < -1 or 0.819999999999999951 < x Initial program 77.8%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 97.3%
Taylor expanded in y around 0 97.4%
if -1 < x < 0.819999999999999951Initial program 99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 98.1%
Taylor expanded in y around inf 98.1%
neg-mul-198.1%
+-commutative98.1%
unsub-neg98.1%
Simplified98.1%
Final simplification97.8%
(FPCore (x y) :precision binary64 (if (or (<= x -3350.0) (not (<= x 3e+14))) (/ (+ x y) y) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -3350.0) || !(x <= 3e+14)) {
tmp = (x + y) / 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 <= (-3350.0d0)) .or. (.not. (x <= 3d+14))) then
tmp = (x + y) / 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 <= -3350.0) || !(x <= 3e+14)) {
tmp = (x + y) / y;
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3350.0) or not (x <= 3e+14): tmp = (x + y) / y else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -3350.0) || !(x <= 3e+14)) tmp = Float64(Float64(x + y) / y); else tmp = Float64(x / Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3350.0) || ~((x <= 3e+14))) tmp = (x + y) / y; else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3350.0], N[Not[LessEqual[x, 3e+14]], $MachinePrecision]], N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3350 \lor \neg \left(x \leq 3 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{x + y}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -3350 or 3e14 < x Initial program 77.5%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 97.8%
Taylor expanded in y around 0 97.9%
if -3350 < x < 3e14Initial program 99.8%
Taylor expanded in y around inf 77.4%
Final simplification87.3%
(FPCore (x y) :precision binary64 (if (or (<= x -6.5e+16) (not (<= x 2.8e+16))) (/ x y) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -6.5e+16) || !(x <= 2.8e+16)) {
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 <= (-6.5d+16)) .or. (.not. (x <= 2.8d+16))) 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 <= -6.5e+16) || !(x <= 2.8e+16)) {
tmp = x / y;
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -6.5e+16) or not (x <= 2.8e+16): tmp = x / y else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -6.5e+16) || !(x <= 2.8e+16)) 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 <= -6.5e+16) || ~((x <= 2.8e+16))) tmp = x / y; else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -6.5e+16], N[Not[LessEqual[x, 2.8e+16]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+16} \lor \neg \left(x \leq 2.8 \cdot 10^{+16}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -6.5e16 or 2.8e16 < x Initial program 76.4%
*-commutative76.4%
associate-/l*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 80.7%
if -6.5e16 < x < 2.8e16Initial program 99.8%
Taylor expanded in y around inf 75.6%
Final simplification77.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.024))) (/ x y) (* x (- 1.0 x))))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.024)) {
tmp = x / y;
} else {
tmp = x * (1.0 - 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 <= 0.024d0))) then
tmp = x / y
else
tmp = x * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.024)) {
tmp = x / y;
} else {
tmp = x * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.024): tmp = x / y else: tmp = x * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.024)) tmp = Float64(x / y); else tmp = Float64(x * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.024))) tmp = x / y; else tmp = x * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.024]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.024\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -1 or 0.024 < x Initial program 78.0%
*-commutative78.0%
associate-/l*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 76.6%
if -1 < x < 0.024Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 98.7%
Taylor expanded in y around inf 77.3%
neg-mul-177.3%
sub-neg77.3%
Simplified77.3%
Final simplification77.0%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 3e+14))) (/ x y) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 3e+14)) {
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 <= 3d+14))) 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 <= 3e+14)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 3e+14): tmp = x / y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 3e+14)) 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 <= 3e+14))) tmp = x / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 3e+14]], $MachinePrecision]], N[(x / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 3 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 3e14 < x Initial program 77.5%
*-commutative77.5%
associate-/l*100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 78.3%
if -1 < x < 3e14Initial program 99.8%
*-commutative99.8%
associate-/l*99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 75.0%
Final simplification76.6%
(FPCore (x y) :precision binary64 (if (<= x -27000000.0) 1.0 (if (<= x 0.025) x 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -27000000.0) {
tmp = 1.0;
} else if (x <= 0.025) {
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 <= (-27000000.0d0)) then
tmp = 1.0d0
else if (x <= 0.025d0) 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 <= -27000000.0) {
tmp = 1.0;
} else if (x <= 0.025) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -27000000.0: tmp = 1.0 elif x <= 0.025: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -27000000.0) tmp = 1.0; elseif (x <= 0.025) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -27000000.0) tmp = 1.0; elseif (x <= 0.025) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -27000000.0], 1.0, If[LessEqual[x, 0.025], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -27000000:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 0.025:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.7e7 or 0.025000000000000001 < x Initial program 77.3%
associate-/l*99.9%
Simplified99.9%
associate-*r/77.3%
clear-num77.2%
distribute-lft-in77.2%
fma-define77.2%
*-rgt-identity77.2%
Applied egg-rr77.2%
Taylor expanded in y around inf 23.8%
+-commutative23.8%
Simplified23.8%
Taylor expanded in x around inf 23.5%
Taylor expanded in x around inf 23.0%
if -2.7e7 < x < 0.025000000000000001Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 74.4%
(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(x * Float64(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[(x * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\frac{x}{y} + 1}{x + 1}
\end{array}
Initial program 89.0%
associate-/l*99.9%
Simplified99.9%
(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 89.0%
associate-/l*99.9%
Simplified99.9%
associate-*r/89.0%
clear-num88.8%
distribute-lft-in88.8%
fma-define88.8%
*-rgt-identity88.8%
Applied egg-rr88.8%
Taylor expanded in y around inf 50.5%
+-commutative50.5%
Simplified50.5%
Taylor expanded in x around inf 12.3%
Taylor expanded in x around inf 13.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 2024180
(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)))