
(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 (let* ((t_0 (/ x (+ x 1.0)))) (+ t_0 (* t_0 (/ x y)))))
double code(double x, double y) {
double t_0 = x / (x + 1.0);
return t_0 + (t_0 * (x / y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = x / (x + 1.0d0)
code = t_0 + (t_0 * (x / y))
end function
public static double code(double x, double y) {
double t_0 = x / (x + 1.0);
return t_0 + (t_0 * (x / y));
}
def code(x, y): t_0 = x / (x + 1.0) return t_0 + (t_0 * (x / y))
function code(x, y) t_0 = Float64(x / Float64(x + 1.0)) return Float64(t_0 + Float64(t_0 * Float64(x / y))) end
function tmp = code(x, y) t_0 = x / (x + 1.0); tmp = t_0 + (t_0 * (x / y)); end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 + N[(t$95$0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t\_0 + t\_0 \cdot \frac{x}{y}
\end{array}
\end{array}
Initial program 87.2%
*-commutative87.2%
associate-/l*99.9%
Applied egg-rr99.9%
*-commutative99.9%
+-commutative99.9%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (+ x 1.0))))
(if (<= x -1950000.0)
(+ 1.0 (/ x y))
(if (<= x 2.6e-83) t_0 (+ t_0 (/ x y))))))
double code(double x, double y) {
double t_0 = x / (x + 1.0);
double tmp;
if (x <= -1950000.0) {
tmp = 1.0 + (x / y);
} else if (x <= 2.6e-83) {
tmp = t_0;
} else {
tmp = t_0 + (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 + 1.0d0)
if (x <= (-1950000.0d0)) then
tmp = 1.0d0 + (x / y)
else if (x <= 2.6d-83) then
tmp = t_0
else
tmp = t_0 + (x / y)
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 <= -1950000.0) {
tmp = 1.0 + (x / y);
} else if (x <= 2.6e-83) {
tmp = t_0;
} else {
tmp = t_0 + (x / y);
}
return tmp;
}
def code(x, y): t_0 = x / (x + 1.0) tmp = 0 if x <= -1950000.0: tmp = 1.0 + (x / y) elif x <= 2.6e-83: tmp = t_0 else: tmp = t_0 + (x / y) return tmp
function code(x, y) t_0 = Float64(x / Float64(x + 1.0)) tmp = 0.0 if (x <= -1950000.0) tmp = Float64(1.0 + Float64(x / y)); elseif (x <= 2.6e-83) tmp = t_0; else tmp = Float64(t_0 + Float64(x / y)); end return tmp end
function tmp_2 = code(x, y) t_0 = x / (x + 1.0); tmp = 0.0; if (x <= -1950000.0) tmp = 1.0 + (x / y); elseif (x <= 2.6e-83) tmp = t_0; else tmp = t_0 + (x / y); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1950000.0], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.6e-83], t$95$0, N[(t$95$0 + N[(x / y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
\mathbf{if}\;x \leq -1950000:\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{-83}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 + \frac{x}{y}\\
\end{array}
\end{array}
if x < -1.95e6Initial program 71.7%
*-commutative71.7%
associate-/l*100.0%
Applied egg-rr100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.9%
Taylor expanded in x around inf 98.7%
distribute-rgt-in98.7%
lft-mult-inverse98.7%
associate-*l/98.9%
*-lft-identity98.9%
Simplified98.9%
if -1.95e6 < x < 2.60000000000000009e-83Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 79.4%
if 2.60000000000000009e-83 < x Initial program 77.6%
*-commutative77.6%
associate-/l*100.0%
Applied egg-rr100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 86.2%
Final simplification85.6%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.0146))) (+ 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.0146)) {
tmp = 1.0 + (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 <= 0.0146d0))) then
tmp = 1.0d0 + (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 <= 0.0146)) {
tmp = 1.0 + (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.0146): tmp = 1.0 + (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.0146)) tmp = Float64(1.0 + Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.0146))) tmp = 1.0 + (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.0146]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.0146\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 0.0146000000000000001 < x Initial program 70.8%
*-commutative70.8%
associate-/l*100.0%
Applied egg-rr100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around inf 97.8%
distribute-rgt-in97.8%
lft-mult-inverse97.8%
associate-*l/98.1%
*-lft-identity98.1%
Simplified98.1%
if -1 < x < 0.0146000000000000001Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.8%
Final simplification85.0%
(FPCore (x y) :precision binary64 (if (or (<= x -170000.0) (not (<= x 196.0))) (+ 1.0 (/ x y)) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -170000.0) || !(x <= 196.0)) {
tmp = 1.0 + (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 <= (-170000.0d0)) .or. (.not. (x <= 196.0d0))) then
tmp = 1.0d0 + (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 <= -170000.0) || !(x <= 196.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -170000.0) or not (x <= 196.0): tmp = 1.0 + (x / y) else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -170000.0) || !(x <= 196.0)) tmp = Float64(1.0 + 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 <= -170000.0) || ~((x <= 196.0))) tmp = 1.0 + (x / y); else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -170000.0], N[Not[LessEqual[x, 196.0]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -170000 \lor \neg \left(x \leq 196\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -1.7e5 or 196 < x Initial program 70.8%
*-commutative70.8%
associate-/l*100.0%
Applied egg-rr100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around inf 97.8%
distribute-rgt-in97.8%
lft-mult-inverse97.8%
associate-*l/98.1%
*-lft-identity98.1%
Simplified98.1%
if -1.7e5 < x < 196Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 75.3%
Final simplification85.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.112))) (/ x y) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.112)) {
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 <= 0.112d0))) 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 <= 0.112)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.112): tmp = x / y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.112)) 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 <= 0.112))) tmp = x / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.112]], $MachinePrecision]], N[(x / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.112\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 0.112000000000000002 < x Initial program 70.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 78.6%
if -1 < x < 0.112000000000000002Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 74.8%
Final simplification76.5%
(FPCore (x y) :precision binary64 (if (<= x -3.1e+14) 1.0 (if (<= x 20000000.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -3.1e+14) {
tmp = 1.0;
} else if (x <= 20000000.0) {
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 <= (-3.1d+14)) then
tmp = 1.0d0
else if (x <= 20000000.0d0) 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 <= -3.1e+14) {
tmp = 1.0;
} else if (x <= 20000000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.1e+14: tmp = 1.0 elif x <= 20000000.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.1e+14) tmp = 1.0; elseif (x <= 20000000.0) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.1e+14) tmp = 1.0; elseif (x <= 20000000.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.1e+14], 1.0, If[LessEqual[x, 20000000.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+14}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 20000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.1e14 or 2e7 < x Initial program 69.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 22.0%
Taylor expanded in x around inf 21.6%
if -3.1e14 < x < 2e7Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 72.5%
Final simplification51.2%
(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.2%
associate-/l*99.9%
Simplified99.9%
Final simplification99.9%
(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(Float64(x / 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[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} \cdot \left(1 + \frac{x}{y}\right)
\end{array}
Initial program 87.2%
*-commutative87.2%
associate-/l*99.9%
Applied egg-rr99.9%
Final simplification99.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 87.2%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 51.6%
Taylor expanded in x around inf 11.2%
Final simplification11.2%
(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 2024066
(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)))