
(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 (or (<= x -1.0) (not (<= x 2.25e-13))) (fma y x (- x)) (- (* 1.0 y) x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 2.25e-13)) {
tmp = fma(y, x, -x);
} else {
tmp = (1.0 * y) - x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 2.25e-13)) tmp = fma(y, x, Float64(-x)); else tmp = Float64(Float64(1.0 * y) - x); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 2.25e-13]], $MachinePrecision]], N[(y * x + (-x)), $MachinePrecision], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 2.25 \cdot 10^{-13}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, -x\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y - x\\
\end{array}
\end{array}
if x < -1 or 2.25e-13 < x Initial program 100.0%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f6499.0
Applied rewrites99.0%
if -1 < x < 2.25e-13Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.6%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= x -4.95e-51) (not (<= x 3.4e-34))) (fma y x (- x)) (fma y x y)))
double code(double x, double y) {
double tmp;
if ((x <= -4.95e-51) || !(x <= 3.4e-34)) {
tmp = fma(y, x, -x);
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -4.95e-51) || !(x <= 3.4e-34)) tmp = fma(y, x, Float64(-x)); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -4.95e-51], N[Not[LessEqual[x, 3.4e-34]], $MachinePrecision]], N[(y * x + (-x)), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.95 \cdot 10^{-51} \lor \neg \left(x \leq 3.4 \cdot 10^{-34}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, -x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if x < -4.94999999999999989e-51 or 3.4000000000000001e-34 < x Initial program 100.0%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f6495.6
Applied rewrites95.6%
if -4.94999999999999989e-51 < x < 3.4000000000000001e-34Initial 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
*-commutativeN/A
sub-negN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f6484.7
Applied rewrites84.7%
Final simplification90.8%
(FPCore (x y) :precision binary64 (if (or (<= y -7.5e-45) (not (<= y 5e-129))) (fma y x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -7.5e-45) || !(y <= 5e-129)) {
tmp = fma(y, x, y);
} else {
tmp = -x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -7.5e-45) || !(y <= 5e-129)) tmp = fma(y, x, y); else tmp = Float64(-x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -7.5e-45], N[Not[LessEqual[y, 5e-129]], $MachinePrecision]], N[(y * x + y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-45} \lor \neg \left(y \leq 5 \cdot 10^{-129}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -7.5000000000000006e-45 or 5.00000000000000027e-129 < 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
*-commutativeN/A
sub-negN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f6491.9
Applied rewrites91.9%
if -7.5000000000000006e-45 < y < 5.00000000000000027e-129Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6482.7
Applied rewrites82.7%
Final simplification88.3%
(FPCore (x y) :precision binary64 (if (or (<= y -7.5e-10) (not (<= y 0.0015))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -7.5e-10) || !(y <= 0.0015)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-7.5d-10)) .or. (.not. (y <= 0.0015d0))) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7.5e-10) || !(y <= 0.0015)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.5e-10) or not (y <= 0.0015): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.5e-10) || !(y <= 0.0015)) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.5e-10) || ~((y <= 0.0015))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.5e-10], N[Not[LessEqual[y, 0.0015]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-10} \lor \neg \left(y \leq 0.0015\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -7.49999999999999995e-10 or 0.0015 < 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
*-commutativeN/A
sub-negN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f6498.3
Applied rewrites98.3%
Taylor expanded in x around inf
Applied rewrites48.8%
if -7.49999999999999995e-10 < y < 0.0015Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6469.8
Applied rewrites69.8%
Final simplification59.6%
(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.f6437.3
Applied rewrites37.3%
Final simplification37.3%
herbie shell --seed 2024313
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))