
(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 (<= y -1.0) (not (<= y 3.2e-23))) (fma y x y) (- (* 1.0 y) x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 3.2e-23)) {
tmp = fma(y, x, y);
} else {
tmp = (1.0 * y) - x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 3.2e-23)) tmp = fma(y, x, y); else tmp = Float64(Float64(1.0 * y) - x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 3.2e-23]], $MachinePrecision]], N[(y * x + y), $MachinePrecision], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 3.2 \cdot 10^{-23}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y - x\\
\end{array}
\end{array}
if y < -1 or 3.19999999999999976e-23 < 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
associate-*r*N/A
distribute-rgt-out--N/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f6498.9
Applied rewrites98.9%
if -1 < y < 3.19999999999999976e-23Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.3%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (or (<= y -9e-44) (not (<= y 1.05e-31))) (fma y x y) (* (- y 1.0) x)))
double code(double x, double y) {
double tmp;
if ((y <= -9e-44) || !(y <= 1.05e-31)) {
tmp = fma(y, x, y);
} else {
tmp = (y - 1.0) * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -9e-44) || !(y <= 1.05e-31)) tmp = fma(y, x, y); else tmp = Float64(Float64(y - 1.0) * x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -9e-44], N[Not[LessEqual[y, 1.05e-31]], $MachinePrecision]], N[(y * x + y), $MachinePrecision], N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-44} \lor \neg \left(y \leq 1.05 \cdot 10^{-31}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - 1\right) \cdot x\\
\end{array}
\end{array}
if y < -8.9999999999999997e-44 or 1.04999999999999996e-31 < 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
associate-*r*N/A
distribute-rgt-out--N/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f6497.2
Applied rewrites97.2%
if -8.9999999999999997e-44 < y < 1.04999999999999996e-31Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6481.2
Applied rewrites81.2%
Final simplification90.2%
(FPCore (x y) :precision binary64 (if (or (<= y -9e-44) (not (<= y 1.05e-31))) (fma y x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -9e-44) || !(y <= 1.05e-31)) {
tmp = fma(y, x, y);
} else {
tmp = -x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -9e-44) || !(y <= 1.05e-31)) tmp = fma(y, x, y); else tmp = Float64(-x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -9e-44], N[Not[LessEqual[y, 1.05e-31]], $MachinePrecision]], N[(y * x + y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-44} \lor \neg \left(y \leq 1.05 \cdot 10^{-31}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -8.9999999999999997e-44 or 1.04999999999999996e-31 < 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
associate-*r*N/A
distribute-rgt-out--N/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f6497.2
Applied rewrites97.2%
if -8.9999999999999997e-44 < y < 1.04999999999999996e-31Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6481.2
Applied rewrites81.2%
Final simplification90.2%
(FPCore (x y) :precision binary64 (if (or (<= y -0.006) (not (<= y 5.2e-23))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -0.006) || !(y <= 5.2e-23)) {
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 <= (-0.006d0)) .or. (.not. (y <= 5.2d-23))) 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 <= -0.006) || !(y <= 5.2e-23)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.006) or not (y <= 5.2e-23): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.006) || !(y <= 5.2e-23)) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -0.006) || ~((y <= 5.2e-23))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.006], N[Not[LessEqual[y, 5.2e-23]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.006 \lor \neg \left(y \leq 5.2 \cdot 10^{-23}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -0.0060000000000000001 or 5.2e-23 < 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
associate-*r*N/A
distribute-rgt-out--N/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f6498.9
Applied rewrites98.9%
Taylor expanded in x around inf
Applied rewrites45.3%
if -0.0060000000000000001 < y < 5.2e-23Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6474.3
Applied rewrites74.3%
Final simplification59.5%
(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.f6438.0
Applied rewrites38.0%
herbie shell --seed 2024326
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))