
(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 x y y) (if (<= y 0.7) (- (* 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 <= 0.7) {
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 <= 0.7) 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, 0.7], 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 0.7:\\
\;\;\;\;1 \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -1 or 0.69999999999999996 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6499.2
Applied rewrites99.2%
if -1 < y < 0.69999999999999996Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.7%
(FPCore (x y) :precision binary64 (if (<= y -1200000000.0) (fma x y y) (if (<= y 2.7e-6) (- (* y x) x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -1200000000.0) {
tmp = fma(x, y, y);
} else if (y <= 2.7e-6) {
tmp = (y * x) - x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1200000000.0) tmp = fma(x, y, y); elseif (y <= 2.7e-6) tmp = Float64(Float64(y * x) - x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -1200000000.0], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 2.7e-6], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1200000000:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-6}:\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -1.2e9 or 2.69999999999999998e-6 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6499.5
Applied rewrites99.5%
if -1.2e9 < y < 2.69999999999999998e-6Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6481.8
Applied rewrites81.8%
Final simplification90.9%
(FPCore (x y) :precision binary64 (if (<= y -1.26e-70) (fma x y y) (if (<= y 1.45e-12) (- x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -1.26e-70) {
tmp = fma(x, y, y);
} else if (y <= 1.45e-12) {
tmp = -x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.26e-70) tmp = fma(x, y, y); elseif (y <= 1.45e-12) tmp = Float64(-x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.26e-70], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 1.45e-12], (-x), N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.26 \cdot 10^{-70}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-12}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -1.2600000000000001e-70 or 1.4500000000000001e-12 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6493.3
Applied rewrites93.3%
if -1.2600000000000001e-70 < y < 1.4500000000000001e-12Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* y x) (if (<= y 1.0) (- x) (* y x))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 1.0) {
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 <= 1.0d0) 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 <= 1.0) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y * x elif y <= 1.0: 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 <= 1.0) 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 <= 1.0) 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, 1.0], (-x), N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\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.2
Applied rewrites99.2%
Taylor expanded in x around inf
Applied rewrites48.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6479.8
Applied rewrites79.8%
(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.3
Applied rewrites40.3%
herbie shell --seed 2024235
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))