
(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 7 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%
lift-+.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y (+ x 1.0)) x))) (if (<= t_0 -5e+307) (* y x) (if (<= t_0 1e+273) (- y x) (* y x)))))
double code(double x, double y) {
double t_0 = (y * (x + 1.0)) - x;
double tmp;
if (t_0 <= -5e+307) {
tmp = y * x;
} else if (t_0 <= 1e+273) {
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+307)) then
tmp = y * x
else if (t_0 <= 1d+273) 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+307) {
tmp = y * x;
} else if (t_0 <= 1e+273) {
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+307: tmp = y * x elif t_0 <= 1e+273: 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+307) tmp = Float64(y * x); elseif (t_0 <= 1e+273) 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+307) tmp = y * x; elseif (t_0 <= 1e+273) 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+307], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 1e+273], 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^{+307}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;t\_0 \leq 10^{+273}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < -5e307 or 9.99999999999999945e272 < (-.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
lower-fma.f6497.5
Applied rewrites97.5%
Taylor expanded in x around inf
lower-*.f6495.1
Applied rewrites95.1%
if -5e307 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < 9.99999999999999945e272Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites87.6%
*-lft-identity87.6
Applied rewrites87.6%
Final simplification88.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y x) x))) (if (<= x -59.0) t_0 (if (<= x 0.00028) (- y x) t_0))))
double code(double x, double y) {
double t_0 = (y * x) - x;
double tmp;
if (x <= -59.0) {
tmp = t_0;
} else if (x <= 0.00028) {
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 <= (-59.0d0)) then
tmp = t_0
else if (x <= 0.00028d0) 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 <= -59.0) {
tmp = t_0;
} else if (x <= 0.00028) {
tmp = y - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (y * x) - x tmp = 0 if x <= -59.0: tmp = t_0 elif x <= 0.00028: 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 <= -59.0) tmp = t_0; elseif (x <= 0.00028) 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 <= -59.0) tmp = t_0; elseif (x <= 0.00028) 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, -59.0], t$95$0, If[LessEqual[x, 0.00028], N[(y - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot x - x\\
\mathbf{if}\;x \leq -59:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.00028:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -59 or 2.7999999999999998e-4 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
if -59 < x < 2.7999999999999998e-4Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.2%
*-lft-identity98.2
Applied rewrites98.2%
(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
lower-fma.f6499.1
Applied rewrites99.1%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.7%
*-lft-identity98.7
Applied rewrites98.7%
(FPCore (x y) :precision binary64 (if (<= x -9e-33) (- x) (if (<= x 2.8e-64) (+ y x) (- x))))
double code(double x, double y) {
double tmp;
if (x <= -9e-33) {
tmp = -x;
} else if (x <= 2.8e-64) {
tmp = y + x;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-9d-33)) then
tmp = -x
else if (x <= 2.8d-64) then
tmp = y + x
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -9e-33) {
tmp = -x;
} else if (x <= 2.8e-64) {
tmp = y + x;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9e-33: tmp = -x elif x <= 2.8e-64: tmp = y + x else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -9e-33) tmp = Float64(-x); elseif (x <= 2.8e-64) tmp = Float64(y + x); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -9e-33) tmp = -x; elseif (x <= 2.8e-64) tmp = y + x; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9e-33], (-x), If[LessEqual[x, 2.8e-64], N[(y + x), $MachinePrecision], (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-33}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-64}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -8.99999999999999982e-33 or 2.80000000000000004e-64 < x Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6453.3
Applied rewrites53.3%
if -8.99999999999999982e-33 < x < 2.80000000000000004e-64Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
*-lft-identity100.0
Applied rewrites100.0%
sub-negN/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
neg-sub0N/A
distribute-frac-negN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
unpow-prod-downN/A
sqr-powN/A
cube-negN/A
neg-sub0N/A
metadata-evalN/A
flip3--N/A
neg-sub0N/A
remove-double-negN/A
lower-+.f6481.6
Applied rewrites81.6%
(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
Applied rewrites76.0%
*-lft-identity76.0
Applied rewrites76.0%
(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.f6439.7
Applied rewrites39.7%
herbie shell --seed 2024219
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))