
(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%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/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) x))) (if (<= x -59.0) t_0 (if (<= x 0.00028) (- (* y 1.0) 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 * 1.0) - 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 * 1.0d0) - 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 * 1.0) - 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 * 1.0) - 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(Float64(y * 1.0) - 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 * 1.0) - 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[(N[(y * 1.0), $MachinePrecision] - 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 \cdot 1 - 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%
Final simplification98.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y x) x))) (if (<= x -0.00043) t_0 (if (<= x 6.6e-65) (fma y x y) t_0))))
double code(double x, double y) {
double t_0 = (y * x) - x;
double tmp;
if (x <= -0.00043) {
tmp = t_0;
} else if (x <= 6.6e-65) {
tmp = fma(y, x, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(y * x) - x) tmp = 0.0 if (x <= -0.00043) tmp = t_0; elseif (x <= 6.6e-65) tmp = fma(y, x, y); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[x, -0.00043], t$95$0, If[LessEqual[x, 6.6e-65], N[(y * x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot x - x\\
\mathbf{if}\;x \leq -0.00043:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6.6 \cdot 10^{-65}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.29999999999999989e-4 or 6.6000000000000002e-65 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6497.1
Applied rewrites97.1%
if -4.29999999999999989e-4 < x < 6.6000000000000002e-65Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6479.1
Applied rewrites79.1%
(FPCore (x y) :precision binary64 (if (<= y -1.5e-54) (fma y x y) (if (<= y 5.4e-105) (- x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.5e-54) {
tmp = fma(y, x, y);
} else if (y <= 5.4e-105) {
tmp = -x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.5e-54) tmp = fma(y, x, y); elseif (y <= 5.4e-105) tmp = Float64(-x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.5e-54], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 5.4e-105], (-x), N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-54}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{-105}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -1.50000000000000005e-54 or 5.39999999999999985e-105 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6489.3
Applied rewrites89.3%
if -1.50000000000000005e-54 < y < 5.39999999999999985e-105Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6485.6
Applied rewrites85.6%
(FPCore (x y) :precision binary64 (if (<= y -2e-6) (* y x) (if (<= y 5000.0) (- x) (* y x))))
double code(double x, double y) {
double tmp;
if (y <= -2e-6) {
tmp = y * x;
} else if (y <= 5000.0) {
tmp = -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) :: tmp
if (y <= (-2d-6)) then
tmp = y * x
else if (y <= 5000.0d0) then
tmp = -x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2e-6) {
tmp = y * x;
} else if (y <= 5000.0) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e-6: tmp = y * x elif y <= 5000.0: tmp = -x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -2e-6) tmp = Float64(y * x); elseif (y <= 5000.0) tmp = Float64(-x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e-6) tmp = y * x; elseif (y <= 5000.0) tmp = -x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e-6], N[(y * x), $MachinePrecision], If[LessEqual[y, 5000.0], (-x), N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-6}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.99999999999999991e-6 or 5e3 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.8
Applied rewrites98.8%
Taylor expanded in x around inf
Applied rewrites52.5%
if -1.99999999999999991e-6 < y < 5e3Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6469.8
Applied rewrites69.8%
Final simplification62.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))