
(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%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ x y) y)))
(if (<= y -310000.0)
t_0
(if (<= y 1.16e-56)
(/ x (+ y 1.0))
(if (<= y 8200000.0) (/ y (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = (x + y) / y;
double tmp;
if (y <= -310000.0) {
tmp = t_0;
} else if (y <= 1.16e-56) {
tmp = x / (y + 1.0);
} else if (y <= 8200000.0) {
tmp = y / (y + 1.0);
} 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) :: tmp
t_0 = (x + y) / y
if (y <= (-310000.0d0)) then
tmp = t_0
else if (y <= 1.16d-56) then
tmp = x / (y + 1.0d0)
else if (y <= 8200000.0d0) then
tmp = y / (y + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x + y) / y;
double tmp;
if (y <= -310000.0) {
tmp = t_0;
} else if (y <= 1.16e-56) {
tmp = x / (y + 1.0);
} else if (y <= 8200000.0) {
tmp = y / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x + y) / y tmp = 0 if y <= -310000.0: tmp = t_0 elif y <= 1.16e-56: tmp = x / (y + 1.0) elif y <= 8200000.0: tmp = y / (y + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x + y) / y) tmp = 0.0 if (y <= -310000.0) tmp = t_0; elseif (y <= 1.16e-56) tmp = Float64(x / Float64(y + 1.0)); elseif (y <= 8200000.0) tmp = Float64(y / Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x + y) / y; tmp = 0.0; if (y <= -310000.0) tmp = t_0; elseif (y <= 1.16e-56) tmp = x / (y + 1.0); elseif (y <= 8200000.0) tmp = y / (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[y, -310000.0], t$95$0, If[LessEqual[y, 1.16e-56], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8200000.0], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x + y}{y}\\
\mathbf{if}\;y \leq -310000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{-56}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{elif}\;y \leq 8200000:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.1e5 or 8.2e6 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 99.2%
if -3.1e5 < y < 1.1600000000000001e-56Initial program 100.0%
Taylor expanded in x around inf 72.4%
+-commutative72.4%
Simplified72.4%
if 1.1600000000000001e-56 < y < 8.2e6Initial program 99.9%
Taylor expanded in x around 0 80.2%
+-commutative80.2%
Simplified80.2%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 5.5e-10) x (if (<= y 6e+45) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 5.5e-10) {
tmp = x;
} else if (y <= 6e+45) {
tmp = x / y;
} 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 <= 5.5d-10) then
tmp = x
else if (y <= 6d+45) then
tmp = x / y
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 <= 5.5e-10) {
tmp = x;
} else if (y <= 6e+45) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 5.5e-10: tmp = x elif y <= 6e+45: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 5.5e-10) tmp = x; elseif (y <= 6e+45) tmp = Float64(x / y); 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 <= 5.5e-10) tmp = x; elseif (y <= 6e+45) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 5.5e-10], x, If[LessEqual[y, 6e+45], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+45}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 6.00000000000000021e45 < y Initial program 100.0%
Taylor expanded in y around inf 75.8%
if -1 < y < 5.4999999999999996e-10Initial program 100.0%
Taylor expanded in y around 0 67.7%
if 5.4999999999999996e-10 < y < 6.00000000000000021e45Initial program 99.9%
Taylor expanded in x around inf 64.3%
+-commutative64.3%
Simplified64.3%
Taylor expanded in y around inf 61.0%
(FPCore (x y) :precision binary64 (if (or (<= x -180000.0) (not (<= x 17000.0))) (/ x (+ y 1.0)) (/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -180000.0) || !(x <= 17000.0)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (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 ((x <= (-180000.0d0)) .or. (.not. (x <= 17000.0d0))) then
tmp = x / (y + 1.0d0)
else
tmp = y / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -180000.0) || !(x <= 17000.0)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -180000.0) or not (x <= 17000.0): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -180000.0) || !(x <= 17000.0)) tmp = Float64(x / Float64(y + 1.0)); else tmp = Float64(y / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -180000.0) || ~((x <= 17000.0))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -180000.0], N[Not[LessEqual[x, 17000.0]], $MachinePrecision]], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -180000 \lor \neg \left(x \leq 17000\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -1.8e5 or 17000 < x Initial program 100.0%
Taylor expanded in x around inf 76.9%
+-commutative76.9%
Simplified76.9%
if -1.8e5 < x < 17000Initial program 100.0%
Taylor expanded in x around 0 82.9%
+-commutative82.9%
Simplified82.9%
Final simplification80.0%
(FPCore (x y) :precision binary64 (if (<= y -11600000000.0) 1.0 (if (<= y 1.4e+46) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -11600000000.0) {
tmp = 1.0;
} else if (y <= 1.4e+46) {
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 <= (-11600000000.0d0)) then
tmp = 1.0d0
else if (y <= 1.4d+46) 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 <= -11600000000.0) {
tmp = 1.0;
} else if (y <= 1.4e+46) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -11600000000.0: tmp = 1.0 elif y <= 1.4e+46: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -11600000000.0) tmp = 1.0; elseif (y <= 1.4e+46) 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 <= -11600000000.0) tmp = 1.0; elseif (y <= 1.4e+46) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -11600000000.0], 1.0, If[LessEqual[y, 1.4e+46], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -11600000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+46}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.16e10 or 1.40000000000000009e46 < y Initial program 100.0%
Taylor expanded in y around inf 75.8%
if -1.16e10 < y < 1.40000000000000009e46Initial program 100.0%
Taylor expanded in x around inf 67.8%
+-commutative67.8%
Simplified67.8%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 5.5e-10) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 5.5e-10) {
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 <= 5.5d-10) 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 <= 5.5e-10) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 5.5e-10: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 5.5e-10) 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 <= 5.5e-10) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 5.5e-10], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 5.4999999999999996e-10 < y Initial program 100.0%
Taylor expanded in y around inf 69.3%
if -1 < y < 5.4999999999999996e-10Initial program 100.0%
Taylor expanded in y around 0 67.7%
(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 40.7%
herbie shell --seed 2024137
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))