
(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%
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
accelerator-lowering-fma.f64N/A
--lowering--.f64100.0
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y (+ x 1.0)) x))) (if (<= t_0 (- INFINITY)) (* y x) (if (<= t_0 5e+306) (- y x) (* y x)))))
double code(double x, double y) {
double t_0 = (y * (x + 1.0)) - x;
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = y * x;
} else if (t_0 <= 5e+306) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = (y * (x + 1.0)) - x;
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = y * x;
} else if (t_0 <= 5e+306) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): t_0 = (y * (x + 1.0)) - x tmp = 0 if t_0 <= -math.inf: tmp = y * x elif t_0 <= 5e+306: tmp = y - x else: tmp = y * x return tmp
function code(x, y) t_0 = Float64(Float64(y * Float64(x + 1.0)) - x) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(y * x); elseif (t_0 <= 5e+306) tmp = Float64(y - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) t_0 = (y * (x + 1.0)) - x; tmp = 0.0; if (t_0 <= -Inf) tmp = y * x; elseif (t_0 <= 5e+306) tmp = y - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 5e+306], N[(y - x), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + 1\right) - x\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+306}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < -inf.0 or 4.99999999999999993e306 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f64100.0
Simplified100.0%
if -inf.0 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < 4.99999999999999993e306Initial program 100.0%
Taylor expanded in x around 0
Simplified85.2%
Final simplification87.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (fma y x y) (if (<= y 6.5e-18) (- 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 <= 6.5e-18) {
tmp = 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 <= 6.5e-18) tmp = Float64(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, 6.5e-18], N[(y - 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 6.5 \cdot 10^{-18}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -1 or 6.50000000000000008e-18 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f6498.9
Simplified98.9%
if -1 < y < 6.50000000000000008e-18Initial program 100.0%
Taylor expanded in x around 0
Simplified98.9%
(FPCore (x y) :precision binary64 (if (<= y -92000000.0) y (if (<= y 5e-18) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -92000000.0) {
tmp = y;
} else if (y <= 5e-18) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-92000000.0d0)) then
tmp = y
else if (y <= 5d-18) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -92000000.0) {
tmp = y;
} else if (y <= 5e-18) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -92000000.0: tmp = y elif y <= 5e-18: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -92000000.0) tmp = y; elseif (y <= 5e-18) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -92000000.0) tmp = y; elseif (y <= 5e-18) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -92000000.0], y, If[LessEqual[y, 5e-18], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -92000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-18}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -9.2e7 or 5.00000000000000036e-18 < y Initial program 100.0%
Taylor expanded in x around 0
Simplified55.6%
if -9.2e7 < y < 5.00000000000000036e-18Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6481.8
Simplified81.8%
(FPCore (x y) :precision binary64 (- y x))
double code(double x, double y) {
return y - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y - x
end function
public static double code(double x, double y) {
return y - x;
}
def code(x, y): return y - x
function code(x, y) return Float64(y - x) end
function tmp = code(x, y) tmp = y - x; end
code[x_, y_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Simplified74.8%
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Simplified38.2%
herbie shell --seed 2024204
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))