
(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 (- INFINITY)) (* y x) (if (<= t_0 1e+292) (- 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 <= 1e+292) {
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 <= 1e+292) {
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 <= 1e+292: 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 <= 1e+292) 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 <= 1e+292) 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, 1e+292], 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 10^{+292}:\\
\;\;\;\;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 1e292 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) Initial program 100.0%
Taylor expanded in x around inf
Simplified100.0%
sub-negN/A
*-commutativeN/A
neg-mul-1N/A
distribute-rgt-outN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
Taylor expanded in y around inf
Simplified94.1%
if -inf.0 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < 1e292Initial program 100.0%
Taylor expanded in x around 0
Simplified88.1%
Final simplification88.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (+ y -1.0)))) (if (<= x -1.4e+29) t_0 (if (<= x 1.0) (- y x) t_0))))
double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -1.4e+29) {
tmp = t_0;
} else if (x <= 1.0) {
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 = x * (y + (-1.0d0))
if (x <= (-1.4d+29)) then
tmp = t_0
else if (x <= 1.0d0) 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 = x * (y + -1.0);
double tmp;
if (x <= -1.4e+29) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (y + -1.0) tmp = 0 if x <= -1.4e+29: tmp = t_0 elif x <= 1.0: tmp = y - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(y + -1.0)) tmp = 0.0 if (x <= -1.4e+29) tmp = t_0; elseif (x <= 1.0) tmp = Float64(y - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (y + -1.0); tmp = 0.0; if (x <= -1.4e+29) tmp = t_0; elseif (x <= 1.0) tmp = y - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.4e+29], t$95$0, If[LessEqual[x, 1.0], N[(y - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + -1\right)\\
\mathbf{if}\;x \leq -1.4 \cdot 10^{+29}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.4e29 or 1 < x Initial program 100.0%
Taylor expanded in x around inf
Simplified100.0%
sub-negN/A
*-commutativeN/A
neg-mul-1N/A
distribute-rgt-outN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
if -1.4e29 < x < 1Initial program 100.0%
Taylor expanded in x around 0
Simplified98.1%
Final simplification98.9%
(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.f6499.1
Simplified99.1%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Simplified98.5%
(FPCore (x y) :precision binary64 (if (<= x -3.6e-13) (- 0.0 x) (if (<= x 1.8e-6) y (- 0.0 x))))
double code(double x, double y) {
double tmp;
if (x <= -3.6e-13) {
tmp = 0.0 - x;
} else if (x <= 1.8e-6) {
tmp = y;
} else {
tmp = 0.0 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.6d-13)) then
tmp = 0.0d0 - x
else if (x <= 1.8d-6) then
tmp = y
else
tmp = 0.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.6e-13) {
tmp = 0.0 - x;
} else if (x <= 1.8e-6) {
tmp = y;
} else {
tmp = 0.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.6e-13: tmp = 0.0 - x elif x <= 1.8e-6: tmp = y else: tmp = 0.0 - x return tmp
function code(x, y) tmp = 0.0 if (x <= -3.6e-13) tmp = Float64(0.0 - x); elseif (x <= 1.8e-6) tmp = y; else tmp = Float64(0.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.6e-13) tmp = 0.0 - x; elseif (x <= 1.8e-6) tmp = y; else tmp = 0.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.6e-13], N[(0.0 - x), $MachinePrecision], If[LessEqual[x, 1.8e-6], y, N[(0.0 - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-13}:\\
\;\;\;\;0 - x\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-6}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;0 - x\\
\end{array}
\end{array}
if x < -3.5999999999999998e-13 or 1.79999999999999992e-6 < x Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6450.7
Simplified50.7%
sub0-negN/A
neg-lowering-neg.f6450.7
Applied egg-rr50.7%
if -3.5999999999999998e-13 < x < 1.79999999999999992e-6Initial program 100.0%
Taylor expanded in x around 0
Simplified74.5%
Final simplification64.0%
(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
Simplified77.9%
(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
Simplified43.2%
(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 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
neg-sub0N/A
--lowering--.f6436.0
Simplified36.0%
sub0-negN/A
neg-lowering-neg.f6436.0
Applied egg-rr36.0%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
neg-sub0N/A
cube-negN/A
sqr-powN/A
unpow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow13.0
Applied egg-rr3.0%
herbie shell --seed 2024196
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))