
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (+ y 1.0))))
(if (<= x -8.6e+27)
t_0
(if (<= x 2.6e+23)
(/ y (+ y 1.0))
(if (or (<= x 3.9e+161) (not (<= x 3.1e+182))) t_0 1.0)))))
double code(double x, double y) {
double t_0 = x / (y + 1.0);
double tmp;
if (x <= -8.6e+27) {
tmp = t_0;
} else if (x <= 2.6e+23) {
tmp = y / (y + 1.0);
} else if ((x <= 3.9e+161) || !(x <= 3.1e+182)) {
tmp = t_0;
} else {
tmp = 1.0;
}
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 / (y + 1.0d0)
if (x <= (-8.6d+27)) then
tmp = t_0
else if (x <= 2.6d+23) then
tmp = y / (y + 1.0d0)
else if ((x <= 3.9d+161) .or. (.not. (x <= 3.1d+182))) then
tmp = t_0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (y + 1.0);
double tmp;
if (x <= -8.6e+27) {
tmp = t_0;
} else if (x <= 2.6e+23) {
tmp = y / (y + 1.0);
} else if ((x <= 3.9e+161) || !(x <= 3.1e+182)) {
tmp = t_0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = x / (y + 1.0) tmp = 0 if x <= -8.6e+27: tmp = t_0 elif x <= 2.6e+23: tmp = y / (y + 1.0) elif (x <= 3.9e+161) or not (x <= 3.1e+182): tmp = t_0 else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(x / Float64(y + 1.0)) tmp = 0.0 if (x <= -8.6e+27) tmp = t_0; elseif (x <= 2.6e+23) tmp = Float64(y / Float64(y + 1.0)); elseif ((x <= 3.9e+161) || !(x <= 3.1e+182)) tmp = t_0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (y + 1.0); tmp = 0.0; if (x <= -8.6e+27) tmp = t_0; elseif (x <= 2.6e+23) tmp = y / (y + 1.0); elseif ((x <= 3.9e+161) || ~((x <= 3.1e+182))) tmp = t_0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.6e+27], t$95$0, If[LessEqual[x, 2.6e+23], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, 3.9e+161], N[Not[LessEqual[x, 3.1e+182]], $MachinePrecision]], t$95$0, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y + 1}\\
\mathbf{if}\;x \leq -8.6 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{+23}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{+161} \lor \neg \left(x \leq 3.1 \cdot 10^{+182}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -8.60000000000000017e27 or 2.59999999999999992e23 < x < 3.9000000000000002e161 or 3.09999999999999996e182 < x Initial program 100.0%
Taylor expanded in x around inf 83.6%
+-commutative83.6%
Simplified83.6%
if -8.60000000000000017e27 < x < 2.59999999999999992e23Initial program 100.0%
Taylor expanded in x around 0 79.2%
+-commutative79.2%
Simplified79.2%
if 3.9000000000000002e161 < x < 3.09999999999999996e182Initial program 100.0%
Taylor expanded in y around inf 100.0%
Final simplification81.7%
(FPCore (x y) :precision binary64 (if (or (<= y -19000.0) (not (<= y 1260000000000.0))) (+ (/ (+ x -1.0) y) 1.0) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -19000.0) || !(y <= 1260000000000.0)) {
tmp = ((x + -1.0) / y) + 1.0;
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-19000.0d0)) .or. (.not. (y <= 1260000000000.0d0))) then
tmp = ((x + (-1.0d0)) / y) + 1.0d0
else
tmp = x / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -19000.0) || !(y <= 1260000000000.0)) {
tmp = ((x + -1.0) / y) + 1.0;
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -19000.0) or not (y <= 1260000000000.0): tmp = ((x + -1.0) / y) + 1.0 else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -19000.0) || !(y <= 1260000000000.0)) tmp = Float64(Float64(Float64(x + -1.0) / y) + 1.0); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -19000.0) || ~((y <= 1260000000000.0))) tmp = ((x + -1.0) / y) + 1.0; else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -19000.0], N[Not[LessEqual[y, 1260000000000.0]], $MachinePrecision]], N[(N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision] + 1.0), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -19000 \lor \neg \left(y \leq 1260000000000\right):\\
\;\;\;\;\frac{x + -1}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -19000 or 1.26e12 < y Initial program 100.0%
Taylor expanded in y around inf 99.8%
associate--l+99.8%
div-sub99.8%
sub-neg99.8%
metadata-eval99.8%
Simplified99.8%
if -19000 < y < 1.26e12Initial program 100.0%
Taylor expanded in x around inf 75.4%
+-commutative75.4%
Simplified75.4%
Final simplification86.9%
(FPCore (x y) :precision binary64 (if (or (<= y -135000.0) (not (<= y 1260000000000.0))) (+ (/ x y) 1.0) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -135000.0) || !(y <= 1260000000000.0)) {
tmp = (x / y) + 1.0;
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-135000.0d0)) .or. (.not. (y <= 1260000000000.0d0))) then
tmp = (x / y) + 1.0d0
else
tmp = x / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -135000.0) || !(y <= 1260000000000.0)) {
tmp = (x / y) + 1.0;
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -135000.0) or not (y <= 1260000000000.0): tmp = (x / y) + 1.0 else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -135000.0) || !(y <= 1260000000000.0)) tmp = Float64(Float64(x / y) + 1.0); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -135000.0) || ~((y <= 1260000000000.0))) tmp = (x / y) + 1.0; else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -135000.0], N[Not[LessEqual[y, 1260000000000.0]], $MachinePrecision]], N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -135000 \lor \neg \left(y \leq 1260000000000\right):\\
\;\;\;\;\frac{x}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -135000 or 1.26e12 < y Initial program 100.0%
Taylor expanded in x around inf 84.9%
Taylor expanded in y around -inf 99.8%
mul-1-neg99.8%
unsub-neg99.8%
sub-neg99.8%
metadata-eval99.8%
distribute-rgt-in99.8%
neg-mul-199.8%
unsub-neg99.8%
lft-mult-inverse99.8%
Simplified99.8%
Taylor expanded in x around inf 99.4%
neg-mul-199.4%
distribute-neg-frac99.4%
Simplified99.4%
if -135000 < y < 1.26e12Initial program 100.0%
Taylor expanded in x around inf 75.4%
+-commutative75.4%
Simplified75.4%
Final simplification86.8%
(FPCore (x y) :precision binary64 (if (<= y -3e+44) 1.0 (if (<= y 16200000000000.0) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3e+44) {
tmp = 1.0;
} else if (y <= 16200000000000.0) {
tmp = x / (y + 1.0);
} 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 (y <= (-3d+44)) then
tmp = 1.0d0
else if (y <= 16200000000000.0d0) then
tmp = x / (y + 1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3e+44) {
tmp = 1.0;
} else if (y <= 16200000000000.0) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3e+44: tmp = 1.0 elif y <= 16200000000000.0: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3e+44) tmp = 1.0; elseif (y <= 16200000000000.0) tmp = Float64(x / Float64(y + 1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3e+44) tmp = 1.0; elseif (y <= 16200000000000.0) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3e+44], 1.0, If[LessEqual[y, 16200000000000.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+44}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 16200000000000:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.99999999999999987e44 or 1.62e13 < y Initial program 100.0%
Taylor expanded in y around inf 79.8%
if -2.99999999999999987e44 < y < 1.62e13Initial program 100.0%
Taylor expanded in x around inf 75.1%
+-commutative75.1%
Simplified75.1%
Final simplification77.2%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1260000000000.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1260000000000.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 (y <= (-1.0d0)) then
tmp = 1.0d0
else if (y <= 1260000000000.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 (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1260000000000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 1260000000000.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 1260000000000.0) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = 1.0; elseif (y <= 1260000000000.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1260000000000.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1260000000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.26e12 < y Initial program 100.0%
Taylor expanded in y around inf 77.4%
if -1 < y < 1.26e12Initial program 100.0%
Taylor expanded in y around 0 72.0%
Final simplification74.5%
(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 100.0%
Taylor expanded in y around inf 38.5%
Final simplification38.5%
herbie shell --seed 2024080
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))