
(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 -1.0) (fma x y y) (if (<= y 1.0) (- (* 1.0 y) x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = fma(x, y, y);
} else if (y <= 1.0) {
tmp = (1.0 * y) - x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = fma(x, y, y); elseif (y <= 1.0) tmp = Float64(Float64(1.0 * y) - x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 1.0], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision], N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1 \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6499.0
Applied rewrites99.0%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.1%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma x y (- x)))) (if (<= x -2.2e-12) t_0 (if (<= x 7.4e-19) (fma x y y) t_0))))
double code(double x, double y) {
double t_0 = fma(x, y, -x);
double tmp;
if (x <= -2.2e-12) {
tmp = t_0;
} else if (x <= 7.4e-19) {
tmp = fma(x, y, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(x, y, Float64(-x)) tmp = 0.0 if (x <= -2.2e-12) tmp = t_0; elseif (x <= 7.4e-19) tmp = fma(x, y, y); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(x * y + (-x)), $MachinePrecision]}, If[LessEqual[x, -2.2e-12], t$95$0, If[LessEqual[x, 7.4e-19], N[(x * y + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x, y, -x\right)\\
\mathbf{if}\;x \leq -2.2 \cdot 10^{-12}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.4 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.19999999999999992e-12 or 7.40000000000000011e-19 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
sub-negN/A
lower-fma.f64N/A
lower-neg.f6497.0
Applied rewrites97.0%
if -2.19999999999999992e-12 < x < 7.40000000000000011e-19Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6481.7
Applied rewrites81.7%
(FPCore (x y) :precision binary64 (if (<= y -4.6e-29) (fma x y y) (if (<= y 6.5e-75) (- x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -4.6e-29) {
tmp = fma(x, y, y);
} else if (y <= 6.5e-75) {
tmp = -x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -4.6e-29) tmp = fma(x, y, y); elseif (y <= 6.5e-75) tmp = Float64(-x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -4.6e-29], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 6.5e-75], (-x), N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{-29}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-75}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -4.59999999999999982e-29 or 6.5000000000000002e-75 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6492.6
Applied rewrites92.6%
if -4.59999999999999982e-29 < y < 6.5000000000000002e-75Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6482.9
Applied rewrites82.9%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 2600000.0) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 2600000.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 <= 2600000.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 <= 2600000.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 2600000.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 <= 2600000.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 <= 2600000.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, 2600000.0], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2600000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 2.6e6 < y Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
sub-negN/A
lower-fma.f64N/A
lower-neg.f6450.0
Applied rewrites50.0%
Taylor expanded in y around inf
Applied rewrites49.0%
if -1 < y < 2.6e6Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6473.6
Applied rewrites73.6%
Final simplification61.9%
(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.f6440.4
Applied rewrites40.4%
(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.f6440.4
Applied rewrites40.4%
Applied rewrites2.2%
herbie shell --seed 2024244
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))