
(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
(if (<= y -410000.0)
(+ 1.0 (/ x y))
(if (<= y -5.5e-124)
(/ y (+ y 1.0))
(if (<= y 15.6) (/ x (+ y 1.0)) (- 1.0 (/ (- 1.0 x) y))))))
double code(double x, double y) {
double tmp;
if (y <= -410000.0) {
tmp = 1.0 + (x / y);
} else if (y <= -5.5e-124) {
tmp = y / (y + 1.0);
} else if (y <= 15.6) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0 - ((1.0 - x) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-410000.0d0)) then
tmp = 1.0d0 + (x / y)
else if (y <= (-5.5d-124)) then
tmp = y / (y + 1.0d0)
else if (y <= 15.6d0) then
tmp = x / (y + 1.0d0)
else
tmp = 1.0d0 - ((1.0d0 - x) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -410000.0) {
tmp = 1.0 + (x / y);
} else if (y <= -5.5e-124) {
tmp = y / (y + 1.0);
} else if (y <= 15.6) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0 - ((1.0 - x) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -410000.0: tmp = 1.0 + (x / y) elif y <= -5.5e-124: tmp = y / (y + 1.0) elif y <= 15.6: tmp = x / (y + 1.0) else: tmp = 1.0 - ((1.0 - x) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -410000.0) tmp = Float64(1.0 + Float64(x / y)); elseif (y <= -5.5e-124) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 15.6) tmp = Float64(x / Float64(y + 1.0)); else tmp = Float64(1.0 - Float64(Float64(1.0 - x) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -410000.0) tmp = 1.0 + (x / y); elseif (y <= -5.5e-124) tmp = y / (y + 1.0); elseif (y <= 15.6) tmp = x / (y + 1.0); else tmp = 1.0 - ((1.0 - x) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -410000.0], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -5.5e-124], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 15.6], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -410000:\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{-124}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 15.6:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{1 - x}{y}\\
\end{array}
\end{array}
if y < -4.1e5Initial program 100.0%
Taylor expanded in y around inf 99.4%
+-commutative99.4%
associate--l+99.4%
+-commutative99.4%
associate--r-99.4%
div-sub99.4%
Simplified99.4%
Taylor expanded in x around inf 99.4%
neg-mul-199.4%
Simplified99.4%
sub-neg99.4%
remove-double-neg99.4%
+-commutative99.4%
Applied egg-rr99.4%
if -4.1e5 < y < -5.50000000000000016e-124Initial program 99.9%
Taylor expanded in x around 0 61.6%
+-commutative61.6%
Simplified61.6%
if -5.50000000000000016e-124 < y < 15.5999999999999996Initial program 100.0%
Taylor expanded in x around inf 87.3%
+-commutative87.3%
Simplified87.3%
if 15.5999999999999996 < y Initial program 100.0%
Taylor expanded in y around inf 99.1%
+-commutative99.1%
associate--l+99.1%
+-commutative99.1%
associate--r-99.1%
div-sub99.1%
Simplified99.1%
Final simplification91.1%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ x y))))
(if (<= y -105000.0)
t_0
(if (<= y -1.7e-121)
(/ y (+ y 1.0))
(if (<= y 21.0) (/ x (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + (x / y);
double tmp;
if (y <= -105000.0) {
tmp = t_0;
} else if (y <= -1.7e-121) {
tmp = y / (y + 1.0);
} else if (y <= 21.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 <= (-105000.0d0)) then
tmp = t_0
else if (y <= (-1.7d-121)) then
tmp = y / (y + 1.0d0)
else if (y <= 21.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 <= -105000.0) {
tmp = t_0;
} else if (y <= -1.7e-121) {
tmp = y / (y + 1.0);
} else if (y <= 21.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 <= -105000.0: tmp = t_0 elif y <= -1.7e-121: tmp = y / (y + 1.0) elif y <= 21.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 <= -105000.0) tmp = t_0; elseif (y <= -1.7e-121) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 21.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 <= -105000.0) tmp = t_0; elseif (y <= -1.7e-121) tmp = y / (y + 1.0); elseif (y <= 21.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, -105000.0], t$95$0, If[LessEqual[y, -1.7e-121], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 21.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 -105000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{-121}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 21:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -105000 or 21 < y Initial program 100.0%
Taylor expanded in y around inf 99.2%
+-commutative99.2%
associate--l+99.2%
+-commutative99.2%
associate--r-99.2%
div-sub99.2%
Simplified99.2%
Taylor expanded in x around inf 99.1%
neg-mul-199.1%
Simplified99.1%
sub-neg99.1%
remove-double-neg99.1%
+-commutative99.1%
Applied egg-rr99.1%
if -105000 < y < -1.70000000000000001e-121Initial program 99.9%
Taylor expanded in x around 0 61.6%
+-commutative61.6%
Simplified61.6%
if -1.70000000000000001e-121 < y < 21Initial program 100.0%
Taylor expanded in x around inf 87.3%
+-commutative87.3%
Simplified87.3%
Final simplification91.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.068))) (+ 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.068)) {
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 <= 0.068d0))) 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 <= 0.068)) {
tmp = 1.0 + (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 0.068): tmp = 1.0 + (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.068)) 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 <= 0.068))) 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, 0.068]], $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 0.068\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 0.068000000000000005 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
+-commutative98.7%
associate--l+98.7%
+-commutative98.7%
associate--r-98.7%
div-sub98.7%
Simplified98.7%
Taylor expanded in x around inf 98.5%
neg-mul-198.5%
Simplified98.5%
sub-neg98.5%
remove-double-neg98.5%
+-commutative98.5%
Applied egg-rr98.5%
if -1 < y < 0.068000000000000005Initial program 100.0%
Taylor expanded in y around 0 77.3%
Final simplification88.6%
(FPCore (x y) :precision binary64 (if (or (<= y -530000000.0) (not (<= y 21.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -530000000.0) || !(y <= 21.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 <= (-530000000.0d0)) .or. (.not. (y <= 21.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 <= -530000000.0) || !(y <= 21.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -530000000.0) or not (y <= 21.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -530000000.0) || !(y <= 21.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 <= -530000000.0) || ~((y <= 21.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -530000000.0], N[Not[LessEqual[y, 21.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 -530000000 \lor \neg \left(y \leq 21\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -5.3e8 or 21 < y Initial program 100.0%
Taylor expanded in y around inf 99.5%
+-commutative99.5%
associate--l+99.5%
+-commutative99.5%
associate--r-99.5%
div-sub99.5%
Simplified99.5%
Taylor expanded in x around inf 99.4%
neg-mul-199.4%
Simplified99.4%
sub-neg99.4%
remove-double-neg99.4%
+-commutative99.4%
Applied egg-rr99.4%
if -5.3e8 < y < 21Initial program 100.0%
Taylor expanded in x around inf 78.1%
+-commutative78.1%
Simplified78.1%
Final simplification89.3%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.88) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.88) {
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 <= 0.88d0) 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 <= 0.88) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.88: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 0.88) 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 <= 0.88) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 0.88], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.88:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.880000000000000004 < y Initial program 100.0%
Taylor expanded in y around inf 79.2%
if -1 < y < 0.880000000000000004Initial program 100.0%
Taylor expanded in y around 0 77.3%
Final simplification78.3%
(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 2024040
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))