
(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 x (+ y -1.0) y))
double code(double x, double y) {
return fma(x, (y + -1.0), y);
}
function code(x, y) return fma(x, Float64(y + -1.0), y) end
code[x_, y_] := N[(x * N[(y + -1.0), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + -1, 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-+r+N/A
lift-neg.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
*-rgt-identityN/A
distribute-lft-out--N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -6e+24) (fma y x y) (if (<= y 2.2e-5) (fma x -1.0 y) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -6e+24) {
tmp = fma(y, x, y);
} else if (y <= 2.2e-5) {
tmp = fma(x, -1.0, y);
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -6e+24) tmp = fma(y, x, y); elseif (y <= 2.2e-5) tmp = fma(x, -1.0, y); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -6e+24], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 2.2e-5], N[(x * -1.0 + y), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(x, -1, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -5.9999999999999999e24 or 2.1999999999999999e-5 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6499.8
Applied rewrites99.8%
if -5.9999999999999999e24 < y < 2.1999999999999999e-5Initial 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-+r+N/A
lift-neg.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
*-rgt-identityN/A
distribute-lft-out--N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites98.2%
(FPCore (x y) :precision binary64 (if (<= y -4.5e-13) (fma y x y) (if (<= y 1.7e-28) (- x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -4.5e-13) {
tmp = fma(y, x, y);
} else if (y <= 1.7e-28) {
tmp = -x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -4.5e-13) tmp = fma(y, x, y); elseif (y <= 1.7e-28) tmp = Float64(-x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -4.5e-13], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 1.7e-28], (-x), N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-28}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -4.5e-13 or 1.7e-28 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6497.3
Applied rewrites97.3%
if -4.5e-13 < y < 1.7e-28Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6477.7
Applied rewrites77.7%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 1150000000.0) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1150000000.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 <= (-1.0d0)) then
tmp = x * y
else if (y <= 1150000000.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 <= -1.0) {
tmp = x * y;
} else if (y <= 1150000000.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1150000000.0: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 1150000000.0) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 1150000000.0) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1150000000.0], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1150000000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1.15e9 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites53.5%
if -1 < y < 1.15e9Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6472.4
Applied rewrites72.4%
(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 Float64(fma(y, x, y) - x) end
code[x_, y_] := N[(N[(y * x + y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, y\right) - x
\end{array}
Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.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.f6435.6
Applied rewrites35.6%
herbie shell --seed 2024220
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))