
(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 5 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 -2.05e+14) (fma x y y) (if (<= y 1.1e-15) (- (* 1.0 y) x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -2.05e+14) {
tmp = fma(x, y, y);
} else if (y <= 1.1e-15) {
tmp = (1.0 * y) - x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2.05e+14) tmp = fma(x, y, y); elseif (y <= 1.1e-15) tmp = Float64(Float64(1.0 * y) - x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2.05e+14], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 1.1e-15], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision], N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-15}:\\
\;\;\;\;1 \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -2.05e14 or 1.09999999999999993e-15 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64100.0
Applied rewrites100.0%
if -2.05e14 < y < 1.09999999999999993e-15Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= y -2e-21) (fma x y y) (if (<= y 6.2e-54) (- x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -2e-21) {
tmp = fma(x, y, y);
} else if (y <= 6.2e-54) {
tmp = -x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2e-21) tmp = fma(x, y, y); elseif (y <= 6.2e-54) tmp = Float64(-x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2e-21], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 6.2e-54], (-x), N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-54}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -1.99999999999999982e-21 or 6.20000000000000008e-54 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6498.7
Applied rewrites98.7%
if -1.99999999999999982e-21 < y < 6.20000000000000008e-54Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6480.8
Applied rewrites80.8%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* y x) (if (<= y 1.1e-15) (- x) (* y x))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 1.1e-15) {
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.1d-15) 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.1e-15) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y * x elif y <= 1.1e-15: 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.1e-15) 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.1e-15) 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.1e-15], (-x), N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-15}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1.09999999999999993e-15 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites42.6%
if -1 < y < 1.09999999999999993e-15Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6477.3
Applied rewrites77.3%
(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.1
Applied rewrites38.1%
herbie shell --seed 2024250
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))