
(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))) (t_1 (/ y (+ y 1.0))))
(if (<= x -1.3e+89)
t_0
(if (<= x -7.8e+18)
t_1
(if (<= x -6.6e-12) x (if (<= x 9.8e-42) t_1 t_0))))))
double code(double x, double y) {
double t_0 = x / (y + 1.0);
double t_1 = y / (y + 1.0);
double tmp;
if (x <= -1.3e+89) {
tmp = t_0;
} else if (x <= -7.8e+18) {
tmp = t_1;
} else if (x <= -6.6e-12) {
tmp = x;
} else if (x <= 9.8e-42) {
tmp = t_1;
} else {
tmp = t_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) :: t_1
real(8) :: tmp
t_0 = x / (y + 1.0d0)
t_1 = y / (y + 1.0d0)
if (x <= (-1.3d+89)) then
tmp = t_0
else if (x <= (-7.8d+18)) then
tmp = t_1
else if (x <= (-6.6d-12)) then
tmp = x
else if (x <= 9.8d-42) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (y + 1.0);
double t_1 = y / (y + 1.0);
double tmp;
if (x <= -1.3e+89) {
tmp = t_0;
} else if (x <= -7.8e+18) {
tmp = t_1;
} else if (x <= -6.6e-12) {
tmp = x;
} else if (x <= 9.8e-42) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (y + 1.0) t_1 = y / (y + 1.0) tmp = 0 if x <= -1.3e+89: tmp = t_0 elif x <= -7.8e+18: tmp = t_1 elif x <= -6.6e-12: tmp = x elif x <= 9.8e-42: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(y + 1.0)) t_1 = Float64(y / Float64(y + 1.0)) tmp = 0.0 if (x <= -1.3e+89) tmp = t_0; elseif (x <= -7.8e+18) tmp = t_1; elseif (x <= -6.6e-12) tmp = x; elseif (x <= 9.8e-42) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (y + 1.0); t_1 = y / (y + 1.0); tmp = 0.0; if (x <= -1.3e+89) tmp = t_0; elseif (x <= -7.8e+18) tmp = t_1; elseif (x <= -6.6e-12) tmp = x; elseif (x <= 9.8e-42) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.3e+89], t$95$0, If[LessEqual[x, -7.8e+18], t$95$1, If[LessEqual[x, -6.6e-12], x, If[LessEqual[x, 9.8e-42], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y + 1}\\
t_1 := \frac{y}{y + 1}\\
\mathbf{if}\;x \leq -1.3 \cdot 10^{+89}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -7.8 \cdot 10^{+18}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -6.6 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 9.8 \cdot 10^{-42}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.3e89 or 9.8000000000000001e-42 < x Initial program 100.0%
Taylor expanded in x around inf 80.9%
+-commutative80.9%
Simplified80.9%
if -1.3e89 < x < -7.8e18 or -6.6000000000000001e-12 < x < 9.8000000000000001e-42Initial program 100.0%
Taylor expanded in x around 0 81.7%
+-commutative81.7%
Simplified81.7%
if -7.8e18 < x < -6.6000000000000001e-12Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification81.7%
(FPCore (x y) :precision binary64 (if (or (<= y -8000000.0) (not (<= y 820000.0))) (/ (+ x y) y) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -8000000.0) || !(y <= 820000.0)) {
tmp = (x + y) / y;
} 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 <= (-8000000.0d0)) .or. (.not. (y <= 820000.0d0))) then
tmp = (x + y) / y
else
tmp = x / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -8000000.0) || !(y <= 820000.0)) {
tmp = (x + y) / y;
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -8000000.0) or not (y <= 820000.0): tmp = (x + y) / y else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -8000000.0) || !(y <= 820000.0)) tmp = Float64(Float64(x + y) / y); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -8000000.0) || ~((y <= 820000.0))) tmp = (x + y) / y; else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -8000000.0], N[Not[LessEqual[y, 820000.0]], $MachinePrecision]], N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8000000 \lor \neg \left(y \leq 820000\right):\\
\;\;\;\;\frac{x + y}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -8e6 or 8.2e5 < y Initial program 100.0%
clear-num99.8%
associate-/r/99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 99.0%
*-commutative99.0%
div-inv99.3%
+-commutative99.3%
Applied egg-rr99.3%
if -8e6 < y < 8.2e5Initial program 100.0%
Taylor expanded in x around inf 73.0%
+-commutative73.0%
Simplified73.0%
Final simplification86.3%
(FPCore (x y) :precision binary64 (if (<= y -1.45e+102) 1.0 (if (<= y 3e+96) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.45e+102) {
tmp = 1.0;
} else if (y <= 3e+96) {
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 <= (-1.45d+102)) then
tmp = 1.0d0
else if (y <= 3d+96) 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 <= -1.45e+102) {
tmp = 1.0;
} else if (y <= 3e+96) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.45e+102: tmp = 1.0 elif y <= 3e+96: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.45e+102) tmp = 1.0; elseif (y <= 3e+96) 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 <= -1.45e+102) tmp = 1.0; elseif (y <= 3e+96) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.45e+102], 1.0, If[LessEqual[y, 3e+96], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+102}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+96}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.4500000000000001e102 or 3e96 < y Initial program 100.0%
Taylor expanded in y around inf 77.2%
if -1.4500000000000001e102 < y < 3e96Initial program 100.0%
Taylor expanded in x around inf 70.6%
+-commutative70.6%
Simplified70.6%
Final simplification73.1%
(FPCore (x y) :precision binary64 (if (<= y -3.5e+102) 1.0 (if (<= y -920000000000.0) (/ x y) (if (<= y 1.4e-29) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -3.5e+102) {
tmp = 1.0;
} else if (y <= -920000000000.0) {
tmp = x / y;
} else if (y <= 1.4e-29) {
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 <= (-3.5d+102)) then
tmp = 1.0d0
else if (y <= (-920000000000.0d0)) then
tmp = x / y
else if (y <= 1.4d-29) 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 <= -3.5e+102) {
tmp = 1.0;
} else if (y <= -920000000000.0) {
tmp = x / y;
} else if (y <= 1.4e-29) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.5e+102: tmp = 1.0 elif y <= -920000000000.0: tmp = x / y elif y <= 1.4e-29: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.5e+102) tmp = 1.0; elseif (y <= -920000000000.0) tmp = Float64(x / y); elseif (y <= 1.4e-29) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.5e+102) tmp = 1.0; elseif (y <= -920000000000.0) tmp = x / y; elseif (y <= 1.4e-29) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.5e+102], 1.0, If[LessEqual[y, -920000000000.0], N[(x / y), $MachinePrecision], If[LessEqual[y, 1.4e-29], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+102}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -920000000000:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-29}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.50000000000000011e102 or 1.4000000000000001e-29 < y Initial program 100.0%
Taylor expanded in y around inf 70.4%
if -3.50000000000000011e102 < y < -9.2e11Initial program 99.9%
Taylor expanded in x around inf 67.1%
+-commutative67.1%
Simplified67.1%
Taylor expanded in y around inf 67.1%
if -9.2e11 < y < 1.4000000000000001e-29Initial program 100.0%
Taylor expanded in y around 0 73.9%
Final simplification71.8%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1.4e-29) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.4e-29) {
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 <= 1.4d-29) 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 <= 1.4e-29) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 1.4e-29: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 1.4e-29) 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 <= 1.4e-29) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.4e-29], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-29}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.4000000000000001e-29 < y Initial program 100.0%
Taylor expanded in y around inf 65.6%
if -1 < y < 1.4000000000000001e-29Initial program 100.0%
Taylor expanded in y around 0 74.4%
Final simplification69.8%
(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 36.2%
Final simplification36.2%
herbie shell --seed 2023257
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))