
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((((x + y) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((((x + y) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
(FPCore (x y z) :precision binary64 (fma x 3.0 (+ z (+ y y))))
double code(double x, double y, double z) {
return fma(x, 3.0, (z + (y + y)));
}
function code(x, y, z) return fma(x, 3.0, Float64(z + Float64(y + y))) end
code[x_, y_, z_] := N[(x * 3.0 + N[(z + N[(y + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 3, z + \left(y + y\right)\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
associate-+l+N/A
metadata-evalN/A
distribute-rgt1-inN/A
associate-+r+N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e+151) (fma x 3.0 z) (if (<= x 1.05e-62) (fma 2.0 y z) (fma x 3.0 (+ y y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+151) {
tmp = fma(x, 3.0, z);
} else if (x <= 1.05e-62) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(x, 3.0, (y + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.1e+151) tmp = fma(x, 3.0, z); elseif (x <= 1.05e-62) tmp = fma(2.0, y, z); else tmp = fma(x, 3.0, Float64(y + y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.1e+151], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 1.05e-62], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0 + N[(y + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;x \leq 1.05 \cdot 10^{-62}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, y + y\right)\\
\end{array}
\end{array}
if x < -1.10000000000000003e151Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6489.6
Applied rewrites89.6%
if -1.10000000000000003e151 < x < 1.05e-62Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.3
Applied rewrites90.3%
if 1.05e-62 < x Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
associate-+l+N/A
metadata-evalN/A
distribute-rgt1-inN/A
associate-+r+N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites89.4%
Applied rewrites89.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e+151) (fma x 3.0 z) (if (<= x 1.05e-62) (fma 2.0 y z) (fma 2.0 (+ x y) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+151) {
tmp = fma(x, 3.0, z);
} else if (x <= 1.05e-62) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(2.0, (x + y), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.1e+151) tmp = fma(x, 3.0, z); elseif (x <= 1.05e-62) tmp = fma(2.0, y, z); else tmp = fma(2.0, Float64(x + y), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.1e+151], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 1.05e-62], N[(2.0 * y + z), $MachinePrecision], N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;x \leq 1.05 \cdot 10^{-62}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\end{array}
\end{array}
if x < -1.10000000000000003e151Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6489.6
Applied rewrites89.6%
if -1.10000000000000003e151 < x < 1.05e-62Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.3
Applied rewrites90.3%
if 1.05e-62 < x Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6489.3
Applied rewrites89.3%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (<= y -8.8e-45) (fma 2.0 y z) (if (<= y 7.8e+83) (fma x 3.0 z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.8e-45) {
tmp = fma(2.0, y, z);
} else if (y <= 7.8e+83) {
tmp = fma(x, 3.0, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -8.8e-45) tmp = fma(2.0, y, z); elseif (y <= 7.8e+83) tmp = fma(x, 3.0, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -8.8e-45], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 7.8e+83], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-45}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -8.79999999999999974e-45 or 7.8000000000000003e83 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6482.6
Applied rewrites82.6%
if -8.79999999999999974e-45 < y < 7.8000000000000003e83Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6488.8
Applied rewrites88.8%
(FPCore (x y z) :precision binary64 (if (<= x -2.1e+151) (* x 3.0) (if (<= x 1.22e+70) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+151) {
tmp = x * 3.0;
} else if (x <= 1.22e+70) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.1e+151) tmp = Float64(x * 3.0); elseif (x <= 1.22e+70) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.1e+151], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 1.22e+70], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+151}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{+70}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -2.1000000000000001e151 or 1.22e70 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6471.6
Applied rewrites71.6%
if -2.1000000000000001e151 < x < 1.22e70Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6487.3
Applied rewrites87.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e+151) (* x 3.0) (if (<= x 5.7e+68) (+ y y) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+151) {
tmp = x * 3.0;
} else if (x <= 5.7e+68) {
tmp = y + y;
} else {
tmp = x * 3.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-1.1d+151)) then
tmp = x * 3.0d0
else if (x <= 5.7d+68) then
tmp = y + y
else
tmp = x * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+151) {
tmp = x * 3.0;
} else if (x <= 5.7e+68) {
tmp = y + y;
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.1e+151: tmp = x * 3.0 elif x <= 5.7e+68: tmp = y + y else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.1e+151) tmp = Float64(x * 3.0); elseif (x <= 5.7e+68) tmp = Float64(y + y); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.1e+151) tmp = x * 3.0; elseif (x <= 5.7e+68) tmp = y + y; else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.1e+151], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 5.7e+68], N[(y + y), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+151}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 5.7 \cdot 10^{+68}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.10000000000000003e151 or 5.6999999999999996e68 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6471.6
Applied rewrites71.6%
if -1.10000000000000003e151 < x < 5.6999999999999996e68Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6446.7
Applied rewrites46.7%
Applied rewrites46.7%
(FPCore (x y z) :precision binary64 (fma 2.0 y (fma x 3.0 z)))
double code(double x, double y, double z) {
return fma(2.0, y, fma(x, 3.0, z));
}
function code(x, y, z) return fma(2.0, y, fma(x, 3.0, z)) end
code[x_, y_, z_] := N[(2.0 * y + N[(x * 3.0 + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, y, \mathsf{fma}\left(x, 3, z\right)\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
associate-+l+N/A
metadata-evalN/A
distribute-rgt1-inN/A
associate-+r+N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (+ y y))
double code(double x, double y, double z) {
return y + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + y
end function
public static double code(double x, double y, double z) {
return y + y;
}
def code(x, y, z): return y + y
function code(x, y, z) return Float64(y + y) end
function tmp = code(x, y, z) tmp = y + y; end
code[x_, y_, z_] := N[(y + y), $MachinePrecision]
\begin{array}{l}
\\
y + y
\end{array}
Initial program 99.9%
Taylor expanded in y around inf
lower-*.f6437.8
Applied rewrites37.8%
Applied rewrites37.8%
herbie shell --seed 2024221
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
:precision binary64
(+ (+ (+ (+ (+ x y) y) x) z) x))