
(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 8 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 -5e+304) (* y x) (if (<= t_0 4e+263) (- y x) (* y x)))))
double code(double x, double y) {
double t_0 = (y * (x + 1.0)) - x;
double tmp;
if (t_0 <= -5e+304) {
tmp = y * x;
} else if (t_0 <= 4e+263) {
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 <= (-5d+304)) then
tmp = y * x
else if (t_0 <= 4d+263) 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 <= -5e+304) {
tmp = y * x;
} else if (t_0 <= 4e+263) {
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 <= -5e+304: tmp = y * x elif t_0 <= 4e+263: 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 <= -5e+304) tmp = Float64(y * x); elseif (t_0 <= 4e+263) 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 <= -5e+304) tmp = y * x; elseif (t_0 <= 4e+263) 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, -5e+304], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 4e+263], 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 -5 \cdot 10^{+304}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+263}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < -4.9999999999999997e304 or 4.00000000000000006e263 < (-.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.f6495.4
Simplified95.4%
Taylor expanded in x around inf
*-lowering-*.f6489.5
Simplified89.5%
if -4.9999999999999997e304 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < 4.00000000000000006e263Initial program 100.0%
Taylor expanded in x around 0
Simplified84.4%
Final simplification85.4%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (fma y x (- x)) (if (<= x 9.6e-15) (- y x) (- (* y x) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = fma(y, x, -x);
} else if (x <= 9.6e-15) {
tmp = y - x;
} else {
tmp = (y * x) - x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = fma(y, x, Float64(-x)); elseif (x <= 9.6e-15) tmp = Float64(y - x); else tmp = Float64(Float64(y * x) - x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.0], N[(y * x + (-x)), $MachinePrecision], If[LessEqual[x, 9.6e-15], N[(y - x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{fma}\left(y, x, -x\right)\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{-15}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x - x\\
\end{array}
\end{array}
if x < -1Initial 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%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6499.1
Simplified99.1%
if -1 < x < 9.5999999999999998e-15Initial program 100.0%
Taylor expanded in x around 0
Simplified99.0%
if 9.5999999999999998e-15 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6499.9
Simplified99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y x) x))) (if (<= x -1.0) t_0 (if (<= x 9.6e-15) (- y x) t_0))))
double code(double x, double y) {
double t_0 = (y * x) - x;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 9.6e-15) {
tmp = y - x;
} else {
tmp = t_0;
}
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) - x
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 9.6d-15) then
tmp = y - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y * x) - x;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 9.6e-15) {
tmp = y - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (y * x) - x tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 9.6e-15: tmp = y - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(y * x) - x) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 9.6e-15) tmp = Float64(y - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (y * x) - x; tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= 9.6e-15) tmp = y - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 9.6e-15], N[(y - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot x - x\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{-15}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 9.5999999999999998e-15 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6499.4
Simplified99.4%
if -1 < x < 9.5999999999999998e-15Initial program 100.0%
Taylor expanded in x around 0
Simplified99.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (fma y x y) (if (<= y 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 = 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(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[(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 1:\\
\;\;\;\;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
accelerator-lowering-fma.f6497.9
Simplified97.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Simplified98.3%
(FPCore (x y) :precision binary64 (if (<= y -2.3e-11) y (if (<= y 2.4e-19) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -2.3e-11) {
tmp = y;
} else if (y <= 2.4e-19) {
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 <= (-2.3d-11)) then
tmp = y
else if (y <= 2.4d-19) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.3e-11) {
tmp = y;
} else if (y <= 2.4e-19) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.3e-11: tmp = y elif y <= 2.4e-19: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.3e-11) tmp = y; elseif (y <= 2.4e-19) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.3e-11) tmp = y; elseif (y <= 2.4e-19) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.3e-11], y, If[LessEqual[y, 2.4e-19], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-11}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-19}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.30000000000000014e-11 or 2.40000000000000023e-19 < y Initial program 100.0%
Taylor expanded in x around 0
Simplified45.1%
if -2.30000000000000014e-11 < y < 2.40000000000000023e-19Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6478.8
Simplified78.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
Simplified70.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
Simplified35.1%
herbie shell --seed 2024199
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))