
(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 (- 1.0 (/ (- 1.0 x) y))))
(if (<= y -600000.0)
t_0
(if (<= y -1.5e-34)
(/ y (+ y 1.0))
(if (<= y 28000.0) (/ x (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 - ((1.0 - x) / y);
double tmp;
if (y <= -600000.0) {
tmp = t_0;
} else if (y <= -1.5e-34) {
tmp = y / (y + 1.0);
} else if (y <= 28000.0) {
tmp = x / (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 = 1.0d0 - ((1.0d0 - x) / y)
if (y <= (-600000.0d0)) then
tmp = t_0
else if (y <= (-1.5d-34)) then
tmp = y / (y + 1.0d0)
else if (y <= 28000.0d0) then
tmp = x / (y + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 - ((1.0 - x) / y);
double tmp;
if (y <= -600000.0) {
tmp = t_0;
} else if (y <= -1.5e-34) {
tmp = y / (y + 1.0);
} else if (y <= 28000.0) {
tmp = x / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - ((1.0 - x) / y) tmp = 0 if y <= -600000.0: tmp = t_0 elif y <= -1.5e-34: tmp = y / (y + 1.0) elif y <= 28000.0: tmp = x / (y + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(Float64(1.0 - x) / y)) tmp = 0.0 if (y <= -600000.0) tmp = t_0; elseif (y <= -1.5e-34) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 28000.0) tmp = Float64(x / Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - ((1.0 - x) / y); tmp = 0.0; if (y <= -600000.0) tmp = t_0; elseif (y <= -1.5e-34) tmp = y / (y + 1.0); elseif (y <= 28000.0) tmp = x / (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -600000.0], t$95$0, If[LessEqual[y, -1.5e-34], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 28000.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{1 - x}{y}\\
\mathbf{if}\;y \leq -600000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.5 \cdot 10^{-34}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 28000:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -6e5 or 28000 < y Initial program 100.0%
Taylor expanded in y around -inf 99.4%
mul-1-neg99.4%
unsub-neg99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
if -6e5 < y < -1.5e-34Initial program 99.8%
Taylor expanded in x around 0 86.1%
+-commutative86.1%
Simplified86.1%
if -1.5e-34 < y < 28000Initial program 100.0%
Taylor expanded in x around inf 74.9%
+-commutative74.9%
Simplified74.9%
Final simplification89.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ x y))))
(if (<= y -740000.0)
t_0
(if (<= y -2.1e-33)
(/ y (+ y 1.0))
(if (<= y 6200.0) (/ x (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + (x / y);
double tmp;
if (y <= -740000.0) {
tmp = t_0;
} else if (y <= -2.1e-33) {
tmp = y / (y + 1.0);
} else if (y <= 6200.0) {
tmp = x / (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 = 1.0d0 + (x / y)
if (y <= (-740000.0d0)) then
tmp = t_0
else if (y <= (-2.1d-33)) then
tmp = y / (y + 1.0d0)
else if (y <= 6200.0d0) then
tmp = x / (y + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (x / y);
double tmp;
if (y <= -740000.0) {
tmp = t_0;
} else if (y <= -2.1e-33) {
tmp = y / (y + 1.0);
} else if (y <= 6200.0) {
tmp = x / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (x / y) tmp = 0 if y <= -740000.0: tmp = t_0 elif y <= -2.1e-33: tmp = y / (y + 1.0) elif y <= 6200.0: tmp = x / (y + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(x / y)) tmp = 0.0 if (y <= -740000.0) tmp = t_0; elseif (y <= -2.1e-33) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 6200.0) tmp = Float64(x / Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (x / y); tmp = 0.0; if (y <= -740000.0) tmp = t_0; elseif (y <= -2.1e-33) tmp = y / (y + 1.0); elseif (y <= 6200.0) tmp = x / (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -740000.0], t$95$0, If[LessEqual[y, -2.1e-33], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6200.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x}{y}\\
\mathbf{if}\;y \leq -740000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.1 \cdot 10^{-33}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 6200:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -7.4e5 or 6200 < y Initial program 100.0%
Taylor expanded in y around -inf 99.4%
mul-1-neg99.4%
unsub-neg99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
Taylor expanded in x around inf 98.7%
neg-mul-198.7%
distribute-neg-frac98.7%
Simplified98.7%
sub-neg98.7%
distribute-frac-neg98.7%
remove-double-neg98.7%
+-commutative98.7%
Applied egg-rr98.7%
if -7.4e5 < y < -2.1e-33Initial program 99.8%
Taylor expanded in x around 0 86.1%
+-commutative86.1%
Simplified86.1%
if -2.1e-33 < y < 6200Initial program 100.0%
Taylor expanded in x around inf 74.9%
+-commutative74.9%
Simplified74.9%
Final simplification88.6%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 2.1e-13))) (+ 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 2.1e-13)) {
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 ((y <= (-1.0d0)) .or. (.not. (y <= 2.1d-13))) 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 ((y <= -1.0) || !(y <= 2.1e-13)) {
tmp = 1.0 + (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 2.1e-13): tmp = 1.0 + (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 2.1e-13)) tmp = Float64(1.0 + Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 2.1e-13))) tmp = 1.0 + (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 2.1e-13]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 2.1 \cdot 10^{-13}\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 2.09999999999999989e-13 < y Initial program 100.0%
Taylor expanded in y around -inf 98.0%
mul-1-neg98.0%
unsub-neg98.0%
mul-1-neg98.0%
sub-neg98.0%
Simplified98.0%
Taylor expanded in x around inf 97.2%
neg-mul-197.2%
distribute-neg-frac97.2%
Simplified97.2%
sub-neg97.2%
distribute-frac-neg97.2%
remove-double-neg97.2%
+-commutative97.2%
Applied egg-rr97.2%
if -1 < y < 2.09999999999999989e-13Initial program 100.0%
Taylor expanded in y around 0 71.6%
Final simplification86.3%
(FPCore (x y) :precision binary64 (if (or (<= y -7800.0) (not (<= y 14000.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -7800.0) || !(y <= 14000.0)) {
tmp = 1.0 + (x / 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 <= (-7800.0d0)) .or. (.not. (y <= 14000.0d0))) then
tmp = 1.0d0 + (x / 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 <= -7800.0) || !(y <= 14000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7800.0) or not (y <= 14000.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7800.0) || !(y <= 14000.0)) tmp = Float64(1.0 + Float64(x / y)); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7800.0) || ~((y <= 14000.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7800.0], N[Not[LessEqual[y, 14000.0]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7800 \lor \neg \left(y \leq 14000\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -7800 or 14000 < y Initial program 100.0%
Taylor expanded in y around -inf 99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
Simplified99.2%
Taylor expanded in x around inf 98.3%
neg-mul-198.3%
distribute-neg-frac98.3%
Simplified98.3%
sub-neg98.3%
distribute-frac-neg98.3%
remove-double-neg98.3%
+-commutative98.3%
Applied egg-rr98.3%
if -7800 < y < 14000Initial program 100.0%
Taylor expanded in x around inf 71.9%
+-commutative71.9%
Simplified71.9%
Final simplification86.9%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 8.5) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 8.5) {
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 <= 8.5d0) 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 <= 8.5) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 8.5: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 8.5) 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 <= 8.5) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 8.5], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 8.5 < y Initial program 100.0%
Taylor expanded in y around inf 74.4%
if -1 < y < 8.5Initial program 100.0%
Taylor expanded in y around 0 70.5%
Final simplification72.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 43.7%
Final simplification43.7%
herbie shell --seed 2023283
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))