
(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 (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 -3.8e+21) (fma y x y) (if (<= y 1.0) (- (* 1.0 y) x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -3.8e+21) {
tmp = fma(y, x, y);
} else if (y <= 1.0) {
tmp = (1.0 * y) - x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -3.8e+21) tmp = fma(y, x, y); elseif (y <= 1.0) tmp = Float64(Float64(1.0 * y) - x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -3.8e+21], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 1.0], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+21}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1 \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -3.8e21 or 1 < 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-lft-inN/A
*-rgt-identityN/A
lower-fma.f6499.4
Applied rewrites99.4%
if -3.8e21 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.7%
(FPCore (x y) :precision binary64 (if (<= y -2.45e-23) (fma y x y) (if (<= y 25.0) (- (* x y) x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -2.45e-23) {
tmp = fma(y, x, y);
} else if (y <= 25.0) {
tmp = (x * y) - x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2.45e-23) tmp = fma(y, x, y); elseif (y <= 25.0) tmp = Float64(Float64(x * y) - x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2.45e-23], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 25.0], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.45 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 25:\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -2.4499999999999999e-23 or 25 < 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-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.2
Applied rewrites98.2%
if -2.4499999999999999e-23 < y < 25Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6480.3
Applied rewrites80.3%
Final simplification90.5%
(FPCore (x y) :precision binary64 (if (<= y -2.45e-23) (fma y x y) (if (<= y 7.1e-12) (- x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -2.45e-23) {
tmp = fma(y, x, y);
} else if (y <= 7.1e-12) {
tmp = -x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2.45e-23) tmp = fma(y, x, y); elseif (y <= 7.1e-12) tmp = Float64(-x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2.45e-23], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 7.1e-12], (-x), N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.45 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 7.1 \cdot 10^{-12}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -2.4499999999999999e-23 or 7.1e-12 < 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-lft-inN/A
*-rgt-identityN/A
lower-fma.f6497.7
Applied rewrites97.7%
if -2.4499999999999999e-23 < y < 7.1e-12Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6480.0
Applied rewrites80.0%
(FPCore (x y) :precision binary64 (if (<= y -5800000000.0) (* x y) (if (<= y 1.0) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -5800000000.0) {
tmp = x * y;
} else if (y <= 1.0) {
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 <= (-5800000000.0d0)) then
tmp = x * y
else if (y <= 1.0d0) 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 <= -5800000000.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5800000000.0: tmp = x * y elif y <= 1.0: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -5800000000.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5800000000.0) tmp = x * y; elseif (y <= 1.0) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5800000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5800000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -5.8e9 or 1 < 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-lft-inN/A
*-rgt-identityN/A
lower-fma.f6499.4
Applied rewrites99.4%
Taylor expanded in x around inf
Applied rewrites52.6%
if -5.8e9 < y < 1Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6474.0
Applied rewrites74.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.f6436.9
Applied rewrites36.9%
herbie shell --seed 2024295
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))