
(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 6 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 (/ (+ y x) (+ 1.0 y)))
double code(double x, double y) {
return (y + x) / (1.0 + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + x) / (1.0d0 + y)
end function
public static double code(double x, double y) {
return (y + x) / (1.0 + y);
}
def code(x, y): return (y + x) / (1.0 + y)
function code(x, y) return Float64(Float64(y + x) / Float64(1.0 + y)) end
function tmp = code(x, y) tmp = (y + x) / (1.0 + y); end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y + x}{1 + y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ y x) (+ 1.0 y))) (t_1 (/ x (+ 1.0 y))))
(if (<= t_0 -1e+27)
t_1
(if (<= t_0 1e-6) (fma 1.0 y x) (if (<= t_0 4.0) (/ y (+ 1.0 y)) t_1)))))
double code(double x, double y) {
double t_0 = (y + x) / (1.0 + y);
double t_1 = x / (1.0 + y);
double tmp;
if (t_0 <= -1e+27) {
tmp = t_1;
} else if (t_0 <= 1e-6) {
tmp = fma(1.0, y, x);
} else if (t_0 <= 4.0) {
tmp = y / (1.0 + y);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(y + x) / Float64(1.0 + y)) t_1 = Float64(x / Float64(1.0 + y)) tmp = 0.0 if (t_0 <= -1e+27) tmp = t_1; elseif (t_0 <= 1e-6) tmp = fma(1.0, y, x); elseif (t_0 <= 4.0) tmp = Float64(y / Float64(1.0 + y)); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y + x), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+27], t$95$1, If[LessEqual[t$95$0, 1e-6], N[(1.0 * y + x), $MachinePrecision], If[LessEqual[t$95$0, 4.0], N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y + x}{1 + y}\\
t_1 := \frac{x}{1 + y}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+27}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{elif}\;t\_0 \leq 4:\\
\;\;\;\;\frac{y}{1 + y}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < -1e27 or 4 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
lower-+.f6499.8
Applied rewrites99.8%
if -1e27 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < 9.99999999999999955e-7Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
if 9.99999999999999955e-7 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < 4Initial program 100.0%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f6498.8
Applied rewrites98.8%
Final simplification99.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ y x) (+ 1.0 y))) (t_1 (/ x (+ 1.0 y))))
(if (<= t_0 -1e+27)
t_1
(if (<= t_0 0.9999994970976185) (fma 1.0 y x) t_1))))
double code(double x, double y) {
double t_0 = (y + x) / (1.0 + y);
double t_1 = x / (1.0 + y);
double tmp;
if (t_0 <= -1e+27) {
tmp = t_1;
} else if (t_0 <= 0.9999994970976185) {
tmp = fma(1.0, y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(y + x) / Float64(1.0 + y)) t_1 = Float64(x / Float64(1.0 + y)) tmp = 0.0 if (t_0 <= -1e+27) tmp = t_1; elseif (t_0 <= 0.9999994970976185) tmp = fma(1.0, y, x); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y + x), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+27], t$95$1, If[LessEqual[t$95$0, 0.9999994970976185], N[(1.0 * y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y + x}{1 + y}\\
t_1 := \frac{x}{1 + y}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+27}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.9999994970976185:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < -1e27 or 0.99999949709761848 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
lower-+.f6453.2
Applied rewrites53.2%
if -1e27 < (/.f64 (+.f64 x y) (+.f64 y #s(literal 1 binary64))) < 0.99999949709761848Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6495.3
Applied rewrites95.3%
Taylor expanded in x around 0
Applied rewrites95.3%
Final simplification63.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (/ x y) (if (<= y 7.5) (fma (- 1.0 x) y x) (/ x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x / y;
} else if (y <= 7.5) {
tmp = fma((1.0 - x), y, x);
} else {
tmp = x / y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x / y); elseif (y <= 7.5) tmp = fma(Float64(1.0 - x), y, x); else tmp = Float64(x / y); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x / y), $MachinePrecision], If[LessEqual[y, 7.5], N[(N[(1.0 - x), $MachinePrecision] * y + x), $MachinePrecision], N[(x / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 7.5:\\
\;\;\;\;\mathsf{fma}\left(1 - x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if y < -1 or 7.5 < y Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
lower-+.f6426.5
Applied rewrites26.5%
Taylor expanded in y around inf
Applied rewrites25.3%
if -1 < y < 7.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6497.3
Applied rewrites97.3%
(FPCore (x y) :precision binary64 (fma 1.0 y x))
double code(double x, double y) {
return fma(1.0, y, x);
}
function code(x, y) return fma(1.0, y, x) end
code[x_, y_] := N[(1.0 * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6450.5
Applied rewrites50.5%
Taylor expanded in x around 0
Applied rewrites50.7%
(FPCore (x y) :precision binary64 (* 1.0 y))
double code(double x, double y) {
return 1.0 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 * y
end function
public static double code(double x, double y) {
return 1.0 * y;
}
def code(x, y): return 1.0 * y
function code(x, y) return Float64(1.0 * y) end
function tmp = code(x, y) tmp = 1.0 * y; end
code[x_, y_] := N[(1.0 * y), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f6451.3
Applied rewrites51.3%
Taylor expanded in y around 0
Applied rewrites13.7%
Taylor expanded in y around 0
Applied rewrites14.5%
Taylor expanded in y around 0
Applied rewrites14.5%
herbie shell --seed 2024308
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))