
(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 9 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
(if (<= y -2.7e+69)
1.0
(if (<= y -1.0)
(/ x y)
(if (<= y 1.0) (fma (- 1.0 x) y x) (+ (/ -1.0 y) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.7e+69) {
tmp = 1.0;
} else if (y <= -1.0) {
tmp = x / y;
} else if (y <= 1.0) {
tmp = fma((1.0 - x), y, x);
} else {
tmp = (-1.0 / y) + 1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2.7e+69) tmp = 1.0; elseif (y <= -1.0) tmp = Float64(x / y); elseif (y <= 1.0) tmp = fma(Float64(1.0 - x), y, x); else tmp = Float64(Float64(-1.0 / y) + 1.0); end return tmp end
code[x_, y_] := If[LessEqual[y, -2.7e+69], 1.0, If[LessEqual[y, -1.0], N[(x / y), $MachinePrecision], If[LessEqual[y, 1.0], N[(N[(1.0 - x), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(-1.0 / y), $MachinePrecision] + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+69}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(1 - x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{y} + 1\\
\end{array}
\end{array}
if y < -2.6999999999999998e69Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites79.6%
if -2.6999999999999998e69 < y < -1Initial program 100.0%
Taylor expanded in x around inf
lower-/.f64N/A
lower-+.f6444.7
Applied rewrites44.7%
Taylor expanded in y around inf
Applied rewrites40.4%
if -1 < y < 1Initial 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.6
Applied rewrites98.6%
if 1 < y Initial program 100.0%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f6475.2
Applied rewrites75.2%
Taylor expanded in y around inf
Applied rewrites74.6%
herbie shell --seed 2024230
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))