
(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 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 92.3%
associate-/l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(if (<= x -9.8e+67)
(/ x y)
(if (<= x -2.0)
(/ x (+ x 1.0))
(if (<= x -8e-5)
(* x (/ x (* y (+ x 1.0))))
(if (<= x 1.0) (* x (+ 1.0 (* x (+ (/ 1.0 y) -1.0)))) (/ x y))))))
double code(double x, double y) {
double tmp;
if (x <= -9.8e+67) {
tmp = x / y;
} else if (x <= -2.0) {
tmp = x / (x + 1.0);
} else if (x <= -8e-5) {
tmp = x * (x / (y * (x + 1.0)));
} else if (x <= 1.0) {
tmp = x * (1.0 + (x * ((1.0 / y) + -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 <= (-9.8d+67)) then
tmp = x / y
else if (x <= (-2.0d0)) then
tmp = x / (x + 1.0d0)
else if (x <= (-8d-5)) then
tmp = x * (x / (y * (x + 1.0d0)))
else if (x <= 1.0d0) then
tmp = x * (1.0d0 + (x * ((1.0d0 / y) + (-1.0d0))))
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -9.8e+67) {
tmp = x / y;
} else if (x <= -2.0) {
tmp = x / (x + 1.0);
} else if (x <= -8e-5) {
tmp = x * (x / (y * (x + 1.0)));
} else if (x <= 1.0) {
tmp = x * (1.0 + (x * ((1.0 / y) + -1.0)));
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9.8e+67: tmp = x / y elif x <= -2.0: tmp = x / (x + 1.0) elif x <= -8e-5: tmp = x * (x / (y * (x + 1.0))) elif x <= 1.0: tmp = x * (1.0 + (x * ((1.0 / y) + -1.0))) else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (x <= -9.8e+67) tmp = Float64(x / y); elseif (x <= -2.0) tmp = Float64(x / Float64(x + 1.0)); elseif (x <= -8e-5) tmp = Float64(x * Float64(x / Float64(y * Float64(x + 1.0)))); elseif (x <= 1.0) tmp = Float64(x * Float64(1.0 + Float64(x * Float64(Float64(1.0 / y) + -1.0)))); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -9.8e+67) tmp = x / y; elseif (x <= -2.0) tmp = x / (x + 1.0); elseif (x <= -8e-5) tmp = x * (x / (y * (x + 1.0))); elseif (x <= 1.0) tmp = x * (1.0 + (x * ((1.0 / y) + -1.0))); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9.8e+67], N[(x / y), $MachinePrecision], If[LessEqual[x, -2.0], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -8e-5], N[(x * N[(x / N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(x * N[(1.0 + N[(x * N[(N[(1.0 / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{+67}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq -2:\\
\;\;\;\;\frac{x}{x + 1}\\
\mathbf{elif}\;x \leq -8 \cdot 10^{-5}:\\
\;\;\;\;x \cdot \frac{x}{y \cdot \left(x + 1\right)}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;x \cdot \left(1 + x \cdot \left(\frac{1}{y} + -1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -9.7999999999999998e67 or 1 < x Initial program 80.1%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 77.6%
if -9.7999999999999998e67 < x < -2Initial program 90.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 78.6%
if -2 < x < -8.00000000000000065e-5Initial program 98.4%
associate-/l*99.2%
Simplified99.2%
Taylor expanded in y around 0 100.0%
if -8.00000000000000065e-5 < x < 1Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 98.8%
Final simplification90.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ x (+ x 1.0)))) (if (<= x -3.2e+67) (/ x y) (if (<= x 1.8e-33) t_0 (/ t_0 (/ y x))))))
double code(double x, double y) {
double t_0 = x / (x + 1.0);
double tmp;
if (x <= -3.2e+67) {
tmp = x / y;
} else if (x <= 1.8e-33) {
tmp = t_0;
} else {
tmp = t_0 / (y / x);
}
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 + 1.0d0)
if (x <= (-3.2d+67)) then
tmp = x / y
else if (x <= 1.8d-33) then
tmp = t_0
else
tmp = t_0 / (y / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (x + 1.0);
double tmp;
if (x <= -3.2e+67) {
tmp = x / y;
} else if (x <= 1.8e-33) {
tmp = t_0;
} else {
tmp = t_0 / (y / x);
}
return tmp;
}
def code(x, y): t_0 = x / (x + 1.0) tmp = 0 if x <= -3.2e+67: tmp = x / y elif x <= 1.8e-33: tmp = t_0 else: tmp = t_0 / (y / x) return tmp
function code(x, y) t_0 = Float64(x / Float64(x + 1.0)) tmp = 0.0 if (x <= -3.2e+67) tmp = Float64(x / y); elseif (x <= 1.8e-33) tmp = t_0; else tmp = Float64(t_0 / Float64(y / x)); end return tmp end
function tmp_2 = code(x, y) t_0 = x / (x + 1.0); tmp = 0.0; if (x <= -3.2e+67) tmp = x / y; elseif (x <= 1.8e-33) tmp = t_0; else tmp = t_0 / (y / x); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.2e+67], N[(x / y), $MachinePrecision], If[LessEqual[x, 1.8e-33], t$95$0, N[(t$95$0 / N[(y / x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{+67}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-33}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\frac{y}{x}}\\
\end{array}
\end{array}
if x < -3.19999999999999983e67Initial program 78.8%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 80.4%
if -3.19999999999999983e67 < x < 1.80000000000000017e-33Initial program 99.4%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 78.3%
if 1.80000000000000017e-33 < x Initial program 83.2%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in y around 0 70.5%
*-commutative70.5%
+-commutative70.5%
associate-/l*79.4%
*-lft-identity79.4%
associate-*l/79.3%
unpow279.3%
+-commutative79.3%
associate-/l*99.8%
*-lft-identity99.8%
associate-*l/99.7%
distribute-rgt-out99.7%
associate-*l/99.9%
*-lft-identity99.9%
+-commutative99.9%
Simplified99.9%
clear-num99.7%
inv-pow99.7%
*-un-lft-identity99.7%
times-frac99.7%
clear-num99.7%
+-commutative99.7%
+-commutative99.7%
Applied egg-rr99.7%
unpow-199.7%
associate-/r*99.6%
associate-/r/99.5%
*-commutative99.5%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Taylor expanded in y around 0 74.5%
Final simplification77.8%
(FPCore (x y) :precision binary64 (if (or (<= x -2.35e+67) (not (<= x 1.7e+36))) (/ x y) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -2.35e+67) || !(x <= 1.7e+36)) {
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 <= (-2.35d+67)) .or. (.not. (x <= 1.7d+36))) 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 <= -2.35e+67) || !(x <= 1.7e+36)) {
tmp = x / y;
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.35e+67) or not (x <= 1.7e+36): tmp = x / y else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.35e+67) || !(x <= 1.7e+36)) 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 <= -2.35e+67) || ~((x <= 1.7e+36))) tmp = x / y; else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.35e+67], N[Not[LessEqual[x, 1.7e+36]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.35 \cdot 10^{+67} \lor \neg \left(x \leq 1.7 \cdot 10^{+36}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -2.35000000000000009e67 or 1.6999999999999999e36 < x Initial program 79.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 79.8%
if -2.35000000000000009e67 < x < 1.6999999999999999e36Initial program 99.4%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 76.0%
Final simplification77.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 106000000000.0))) (/ x y) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 106000000000.0)) {
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 <= 106000000000.0d0))) 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 <= 106000000000.0)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 106000000000.0): tmp = x / y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 106000000000.0)) 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 <= 106000000000.0))) tmp = x / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 106000000000.0]], $MachinePrecision]], N[(x / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 106000000000\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 1.06e11 < x Initial program 80.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 73.2%
if -1 < x < 1.06e11Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 75.4%
Final simplification74.5%
(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 92.3%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 46.5%
Final simplification46.5%
(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 2024078
(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)))