
(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 (- (* y (+ 1.0 x)) x))
double code(double x, double y) {
return (y * (1.0 + x)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (1.0d0 + x)) - x
end function
public static double code(double x, double y) {
return (y * (1.0 + x)) - x;
}
def code(x, y): return (y * (1.0 + x)) - x
function code(x, y) return Float64(Float64(y * Float64(1.0 + x)) - x) end
function tmp = code(x, y) tmp = (y * (1.0 + x)) - x; end
code[x_, y_] := N[(N[(y * N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(1 + x\right) - x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (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 <= -1.0) {
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 <= -1.0) 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, -1.0], 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 -1:\\
\;\;\;\;\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 < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.8
Applied rewrites98.8%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y x) x))) (if (<= x -2.5e-6) t_0 (if (<= x 420000.0) (fma y x y) t_0))))
double code(double x, double y) {
double t_0 = (y * x) - x;
double tmp;
if (x <= -2.5e-6) {
tmp = t_0;
} else if (x <= 420000.0) {
tmp = fma(y, x, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(y * x) - x) tmp = 0.0 if (x <= -2.5e-6) tmp = t_0; elseif (x <= 420000.0) tmp = fma(y, x, y); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[x, -2.5e-6], t$95$0, If[LessEqual[x, 420000.0], N[(y * x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot x - x\\
\mathbf{if}\;x \leq -2.5 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 420000:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.5000000000000002e-6 or 4.2e5 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
if -2.5000000000000002e-6 < x < 4.2e5Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6476.3
Applied rewrites76.3%
(FPCore (x y) :precision binary64 (if (<= y -2.8e-72) (fma y x y) (if (<= y 1.5e-16) (- x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -2.8e-72) {
tmp = fma(y, x, y);
} else if (y <= 1.5e-16) {
tmp = -x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2.8e-72) tmp = fma(y, x, y); elseif (y <= 1.5e-16) tmp = Float64(-x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2.8e-72], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 1.5e-16], (-x), N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-72}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{-16}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -2.7999999999999998e-72 or 1.49999999999999997e-16 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6494.6
Applied rewrites94.6%
if -2.7999999999999998e-72 < y < 1.49999999999999997e-16Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6477.4
Applied rewrites77.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* y x) (if (<= y 19.5) (- x) (* y x))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 19.5) {
tmp = -x;
} else {
tmp = y * x;
}
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 = y * x
else if (y <= 19.5d0) then
tmp = -x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 19.5) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y * x elif y <= 19.5: tmp = -x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * x); elseif (y <= 19.5) tmp = Float64(-x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = y * x; elseif (y <= 19.5) tmp = -x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 19.5], (-x), N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 19.5:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 19.5 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.8
Applied rewrites98.8%
Taylor expanded in x around inf
Applied rewrites46.4%
if -1 < y < 19.5Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6472.7
Applied rewrites72.7%
(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.3
Applied rewrites38.3%
herbie shell --seed 2024276
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))