
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
(FPCore (x y) :precision binary64 (- (* y (+ 1.0 x)) x))
double code(double x, double y) {
return (y * (1.0 + x)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (1.0d0 + x)) - x
end function
public static double code(double x, double y) {
return (y * (1.0 + x)) - x;
}
def code(x, y): return (y * (1.0 + x)) - x
function code(x, y) return Float64(Float64(y * Float64(1.0 + x)) - x) end
function tmp = code(x, y) tmp = (y * (1.0 + x)) - x; end
code[x_, y_] := N[(N[(y * N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(1 + x\right) - x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -770000000000.0) (fma x y y) (if (<= y 1.0) (- (* 1.0 y) x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -770000000000.0) {
tmp = fma(x, y, y);
} else if (y <= 1.0) {
tmp = (1.0 * y) - x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -770000000000.0) tmp = fma(x, y, y); elseif (y <= 1.0) tmp = Float64(Float64(1.0 * y) - x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -770000000000.0], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 1.0], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision], N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -770000000000:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1 \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -7.7e11 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6499.6
Applied rewrites99.6%
if -7.7e11 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.3%
herbie shell --seed 2024230
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))