
(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 -2e+299) (* y x) (if (<= t_0 2e+294) (- y x) (* y x)))))
double code(double x, double y) {
double t_0 = (y * (x + 1.0)) - x;
double tmp;
if (t_0 <= -2e+299) {
tmp = y * x;
} else if (t_0 <= 2e+294) {
tmp = y - 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) :: t_0
real(8) :: tmp
t_0 = (y * (x + 1.0d0)) - x
if (t_0 <= (-2d+299)) then
tmp = y * x
else if (t_0 <= 2d+294) then
tmp = y - x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y * (x + 1.0)) - x;
double tmp;
if (t_0 <= -2e+299) {
tmp = y * x;
} else if (t_0 <= 2e+294) {
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 <= -2e+299: tmp = y * x elif t_0 <= 2e+294: 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 <= -2e+299) tmp = Float64(y * x); elseif (t_0 <= 2e+294) 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 <= -2e+299) tmp = y * x; elseif (t_0 <= 2e+294) 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, -2e+299], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 2e+294], 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 -2 \cdot 10^{+299}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+294}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < -2.0000000000000001e299 or 2.00000000000000013e294 < (-.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-*.f6493.4
Simplified93.4%
if -2.0000000000000001e299 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < 2.00000000000000013e294Initial program 99.9%
Taylor expanded in x around 0
Simplified88.8%
Final simplification89.5%
(FPCore (x y) :precision binary64 (if (<= y -3.65) (fma y x y) (if (<= y 1.7e-7) (- y x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -3.65) {
tmp = fma(y, x, y);
} else if (y <= 1.7e-7) {
tmp = y - x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -3.65) tmp = fma(y, x, y); elseif (y <= 1.7e-7) tmp = Float64(y - x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -3.65], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 1.7e-7], N[(y - x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.65:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-7}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -3.64999999999999991 or 1.69999999999999987e-7 < y Initial program 99.9%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f6499.2
Simplified99.2%
if -3.64999999999999991 < y < 1.69999999999999987e-7Initial program 100.0%
Taylor expanded in x around 0
Simplified98.8%
(FPCore (x y) :precision binary64 (if (<= y -0.00032) y (if (<= y 1.4e-25) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -0.00032) {
tmp = y;
} else if (y <= 1.4e-25) {
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 <= (-0.00032d0)) then
tmp = y
else if (y <= 1.4d-25) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -0.00032) {
tmp = y;
} else if (y <= 1.4e-25) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.00032: tmp = y elif y <= 1.4e-25: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -0.00032) tmp = y; elseif (y <= 1.4e-25) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -0.00032) tmp = y; elseif (y <= 1.4e-25) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.00032], y, If[LessEqual[y, 1.4e-25], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00032:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-25}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -3.20000000000000026e-4 or 1.39999999999999994e-25 < y Initial program 99.9%
Taylor expanded in x around 0
Simplified52.2%
if -3.20000000000000026e-4 < y < 1.39999999999999994e-25Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6482.9
Simplified82.9%
(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
Simplified76.0%
(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
Simplified35.4%
herbie shell --seed 2024198
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))