
(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 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.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(if (<= x -1.3e+20)
(/ x y)
(if (<= x -0.065)
(/ x (+ x 1.0))
(if (or (<= x -1.8e-6) (not (<= x 4e-18)))
(* x (/ (/ x y) (+ x 1.0)))
(* x (+ 1.0 (- (/ x y) x)))))))
double code(double x, double y) {
double tmp;
if (x <= -1.3e+20) {
tmp = x / y;
} else if (x <= -0.065) {
tmp = x / (x + 1.0);
} else if ((x <= -1.8e-6) || !(x <= 4e-18)) {
tmp = x * ((x / y) / (x + 1.0));
} 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.3d+20)) then
tmp = x / y
else if (x <= (-0.065d0)) then
tmp = x / (x + 1.0d0)
else if ((x <= (-1.8d-6)) .or. (.not. (x <= 4d-18))) then
tmp = x * ((x / y) / (x + 1.0d0))
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.3e+20) {
tmp = x / y;
} else if (x <= -0.065) {
tmp = x / (x + 1.0);
} else if ((x <= -1.8e-6) || !(x <= 4e-18)) {
tmp = x * ((x / y) / (x + 1.0));
} else {
tmp = x * (1.0 + ((x / y) - x));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.3e+20: tmp = x / y elif x <= -0.065: tmp = x / (x + 1.0) elif (x <= -1.8e-6) or not (x <= 4e-18): tmp = x * ((x / y) / (x + 1.0)) else: tmp = x * (1.0 + ((x / y) - x)) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.3e+20) tmp = Float64(x / y); elseif (x <= -0.065) tmp = Float64(x / Float64(x + 1.0)); elseif ((x <= -1.8e-6) || !(x <= 4e-18)) tmp = Float64(x * Float64(Float64(x / y) / Float64(x + 1.0))); 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.3e+20) tmp = x / y; elseif (x <= -0.065) tmp = x / (x + 1.0); elseif ((x <= -1.8e-6) || ~((x <= 4e-18))) tmp = x * ((x / y) / (x + 1.0)); else tmp = x * (1.0 + ((x / y) - x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.3e+20], N[(x / y), $MachinePrecision], If[LessEqual[x, -0.065], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -1.8e-6], N[Not[LessEqual[x, 4e-18]], $MachinePrecision]], N[(x * N[(N[(x / y), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $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.3 \cdot 10^{+20}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq -0.065:\\
\;\;\;\;\frac{x}{x + 1}\\
\mathbf{elif}\;x \leq -1.8 \cdot 10^{-6} \lor \neg \left(x \leq 4 \cdot 10^{-18}\right):\\
\;\;\;\;x \cdot \frac{\frac{x}{y}}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + \left(\frac{x}{y} - x\right)\right)\\
\end{array}
\end{array}
if x < -1.3e20Initial program 74.4%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around inf 86.3%
if -1.3e20 < x < -0.065000000000000002Initial program 100.0%
associate-/l*99.4%
Simplified99.4%
Taylor expanded in y around inf 100.0%
if -0.065000000000000002 < x < -1.79999999999999992e-6 or 4.0000000000000003e-18 < x Initial program 80.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 67.3%
associate-/r*79.7%
Simplified79.7%
if -1.79999999999999992e-6 < x < 4.0000000000000003e-18Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around inf 99.9%
neg-mul-199.9%
+-commutative99.9%
unsub-neg99.9%
Simplified99.9%
Final simplification91.3%
(FPCore (x y)
:precision binary64
(if (<= x -3.8e+22)
(/ x y)
(if (<= x -0.0025)
(/ x (+ x 1.0))
(if (<= x 1.0) (* x (+ 1.0 (- (/ x y) x))) (/ x y)))))
double code(double x, double y) {
double tmp;
if (x <= -3.8e+22) {
tmp = x / y;
} else if (x <= -0.0025) {
tmp = x / (x + 1.0);
} else if (x <= 1.0) {
tmp = x * (1.0 + ((x / y) - x));
} 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 <= (-3.8d+22)) then
tmp = x / y
else if (x <= (-0.0025d0)) then
tmp = x / (x + 1.0d0)
else if (x <= 1.0d0) then
tmp = x * (1.0d0 + ((x / y) - x))
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.8e+22) {
tmp = x / y;
} else if (x <= -0.0025) {
tmp = x / (x + 1.0);
} else if (x <= 1.0) {
tmp = x * (1.0 + ((x / y) - x));
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.8e+22: tmp = x / y elif x <= -0.0025: tmp = x / (x + 1.0) elif x <= 1.0: tmp = x * (1.0 + ((x / y) - x)) else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (x <= -3.8e+22) tmp = Float64(x / y); elseif (x <= -0.0025) tmp = Float64(x / Float64(x + 1.0)); elseif (x <= 1.0) tmp = Float64(x * Float64(1.0 + Float64(Float64(x / y) - x))); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.8e+22) tmp = x / y; elseif (x <= -0.0025) tmp = x / (x + 1.0); elseif (x <= 1.0) tmp = x * (1.0 + ((x / y) - x)); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.8e+22], N[(x / y), $MachinePrecision], If[LessEqual[x, -0.0025], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(x * N[(1.0 + N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+22}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq -0.0025:\\
\;\;\;\;\frac{x}{x + 1}\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;x \cdot \left(1 + \left(\frac{x}{y} - x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -3.8000000000000004e22 or 1 < x Initial program 76.4%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 82.0%
if -3.8000000000000004e22 < x < -0.00250000000000000005Initial program 100.0%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in y around inf 85.9%
if -0.00250000000000000005 < x < 1Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 98.9%
Taylor expanded in y around inf 99.0%
neg-mul-199.0%
+-commutative99.0%
unsub-neg99.0%
Simplified99.0%
Final simplification90.7%
(FPCore (x y) :precision binary64 (if (or (<= x -4.8e+19) (not (<= x 55000000000.0))) (/ x y) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -4.8e+19) || !(x <= 55000000000.0)) {
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 <= (-4.8d+19)) .or. (.not. (x <= 55000000000.0d0))) 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 <= -4.8e+19) || !(x <= 55000000000.0)) {
tmp = x / y;
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.8e+19) or not (x <= 55000000000.0): tmp = x / y else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.8e+19) || !(x <= 55000000000.0)) 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 <= -4.8e+19) || ~((x <= 55000000000.0))) tmp = x / y; else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.8e+19], N[Not[LessEqual[x, 55000000000.0]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+19} \lor \neg \left(x \leq 55000000000\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -4.8e19 or 5.5e10 < x Initial program 76.2%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 82.7%
if -4.8e19 < x < 5.5e10Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 72.5%
Final simplification77.2%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 4e-18))) (/ x y) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4e-18)) {
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 <= 4d-18))) 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 <= 4e-18)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4e-18): tmp = x / y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4e-18)) 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 <= 4e-18))) tmp = x / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4e-18]], $MachinePrecision]], N[(x / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 4.0000000000000003e-18 < x Initial program 77.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 77.2%
if -1 < x < 4.0000000000000003e-18Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 72.1%
Final simplification74.7%
(FPCore (x y) :precision binary64 (if (<= x -1.0) 1.0 (if (<= x 4e-18) x 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = 1.0;
} else if (x <= 4e-18) {
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 <= 4d-18) 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 <= 4e-18) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = 1.0 elif x <= 4e-18: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = 1.0; elseif (x <= 4e-18) 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 <= 4e-18) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], 1.0, If[LessEqual[x, 4e-18], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 4 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1 or 4.0000000000000003e-18 < x Initial program 77.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 21.4%
Taylor expanded in x around inf 20.4%
Taylor expanded in x around inf 19.9%
if -1 < x < 4.0000000000000003e-18Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 72.1%
Final simplification46.2%
(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.8%
Simplified99.8%
Taylor expanded in y around inf 47.7%
Taylor expanded in x around inf 11.1%
Taylor expanded in x around inf 11.4%
Final simplification11.4%
(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 2024055
(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)))