
(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 7 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 (fma y x (- y x)))
double code(double x, double y) {
return fma(y, x, (y - x));
}
function code(x, y) return fma(y, x, Float64(y - x)) end
code[x_, y_] := N[(y * x + N[(y - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, y - x\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= y -2.6e+28) (fma x y y) (if (<= y 0.042) (fma x -1.0 y) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -2.6e+28) {
tmp = fma(x, y, y);
} else if (y <= 0.042) {
tmp = fma(x, -1.0, y);
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2.6e+28) tmp = fma(x, y, y); elseif (y <= 0.042) tmp = fma(x, -1.0, y); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2.6e+28], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 0.042], N[(x * -1.0 + y), $MachinePrecision], N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+28}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 0.042:\\
\;\;\;\;\mathsf{fma}\left(x, -1, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -2.6000000000000002e28 or 0.0420000000000000026 < y Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
remove-double-negN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
if -2.6000000000000002e28 < y < 0.0420000000000000026Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-fma.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-neg.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lift-neg.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.3%
(FPCore (x y) :precision binary64 (if (<= y -1.65e-68) (fma x y y) (if (<= y 3.5e-14) (- x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -1.65e-68) {
tmp = fma(x, y, y);
} else if (y <= 3.5e-14) {
tmp = -x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.65e-68) tmp = fma(x, y, y); elseif (y <= 3.5e-14) tmp = Float64(-x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.65e-68], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 3.5e-14], (-x), N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-68}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-14}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -1.6499999999999999e-68 or 3.5000000000000002e-14 < y Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
remove-double-negN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6496.0
Applied rewrites96.0%
if -1.6499999999999999e-68 < y < 3.5000000000000002e-14Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6482.5
Applied rewrites82.5%
(FPCore (x y) :precision binary64 (if (<= y -0.185) (* x y) (if (<= y 0.042) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -0.185) {
tmp = x * y;
} else if (y <= 0.042) {
tmp = -x;
} else {
tmp = 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 <= (-0.185d0)) then
tmp = x * y
else if (y <= 0.042d0) then
tmp = -x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -0.185) {
tmp = x * y;
} else if (y <= 0.042) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.185: tmp = x * y elif y <= 0.042: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -0.185) tmp = Float64(x * y); elseif (y <= 0.042) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -0.185) tmp = x * y; elseif (y <= 0.042) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.185], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.042], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.185:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.042:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -0.185 or 0.0420000000000000026 < y Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
remove-double-negN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites49.0%
if -0.185 < y < 0.0420000000000000026Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6479.0
Applied rewrites79.0%
(FPCore (x y) :precision binary64 (fma x (+ -1.0 y) y))
double code(double x, double y) {
return fma(x, (-1.0 + y), y);
}
function code(x, y) return fma(x, Float64(-1.0 + y), y) end
code[x_, y_] := N[(x * N[(-1.0 + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, -1 + y, y\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-fma.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-neg.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lift-neg.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6441.0
Applied rewrites41.0%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6441.0
Applied rewrites41.0%
Applied rewrites2.7%
herbie shell --seed 2024294
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))