
(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 6 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 2.0 (+ x y) x) z))
double code(double x, double y, double z) {
return fma(2.0, (x + y), x) + z;
}
function code(x, y, z) return Float64(fma(2.0, Float64(x + y), x) + z) end
code[x_, y_, z_] := N[(N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, x + y, x\right) + z
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lower-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
count-2N/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= z -8.6e+177)
(fma 3.0 x z)
(if (<= z -1.75e+83)
(fma y 2.0 z)
(if (<= z 1.25e+92) (fma 3.0 x (+ y y)) (fma 3.0 x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.6e+177) {
tmp = fma(3.0, x, z);
} else if (z <= -1.75e+83) {
tmp = fma(y, 2.0, z);
} else if (z <= 1.25e+92) {
tmp = fma(3.0, x, (y + y));
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -8.6e+177) tmp = fma(3.0, x, z); elseif (z <= -1.75e+83) tmp = fma(y, 2.0, z); elseif (z <= 1.25e+92) tmp = fma(3.0, x, Float64(y + y)); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -8.6e+177], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[z, -1.75e+83], N[(y * 2.0 + z), $MachinePrecision], If[LessEqual[z, 1.25e+92], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.6 \cdot 10^{+177}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;z \leq -1.75 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{+92}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if z < -8.60000000000000074e177 or 1.25000000000000005e92 < z Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6490.8
Applied rewrites90.8%
if -8.60000000000000074e177 < z < -1.74999999999999989e83Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.6
Applied rewrites90.6%
if -1.74999999999999989e83 < z < 1.25000000000000005e92Initial program 99.9%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.7
Applied rewrites89.7%
Applied rewrites89.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.1e+73) (fma y 2.0 z) (if (<= y 1e+117) (fma 3.0 x z) (fma y 2.0 z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+73) {
tmp = fma(y, 2.0, z);
} else if (y <= 1e+117) {
tmp = fma(3.0, x, z);
} else {
tmp = fma(y, 2.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.1e+73) tmp = fma(y, 2.0, z); elseif (y <= 1e+117) tmp = fma(3.0, x, z); else tmp = fma(y, 2.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.1e+73], N[(y * 2.0 + z), $MachinePrecision], If[LessEqual[y, 1e+117], N[(3.0 * x + z), $MachinePrecision], N[(y * 2.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+73}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{elif}\;y \leq 10^{+117}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\end{array}
\end{array}
if y < -1.1e73 or 1.00000000000000005e117 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.0
Applied rewrites88.0%
if -1.1e73 < y < 1.00000000000000005e117Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6487.0
Applied rewrites87.0%
(FPCore (x y z) :precision binary64 (if (<= y -6e+94) (+ y y) (if (<= y 4.8e+162) (fma 3.0 x z) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6e+94) {
tmp = y + y;
} else if (y <= 4.8e+162) {
tmp = fma(3.0, x, z);
} else {
tmp = y + y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -6e+94) tmp = Float64(y + y); elseif (y <= 4.8e+162) tmp = fma(3.0, x, z); else tmp = Float64(y + y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -6e+94], N[(y + y), $MachinePrecision], If[LessEqual[y, 4.8e+162], N[(3.0 * x + z), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+94}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+162}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -6.0000000000000001e94 or 4.80000000000000018e162 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6478.7
Applied rewrites78.7%
Applied rewrites78.7%
if -6.0000000000000001e94 < y < 4.80000000000000018e162Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6483.2
Applied rewrites83.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.1e+73) (+ y y) (if (<= y 1.18e+117) (* 3.0 x) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+73) {
tmp = y + y;
} else if (y <= 1.18e+117) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
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 (y <= (-1.1d+73)) then
tmp = y + y
else if (y <= 1.18d+117) then
tmp = 3.0d0 * x
else
tmp = y + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+73) {
tmp = y + y;
} else if (y <= 1.18e+117) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.1e+73: tmp = y + y elif y <= 1.18e+117: tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.1e+73) tmp = Float64(y + y); elseif (y <= 1.18e+117) tmp = Float64(3.0 * x); else tmp = Float64(y + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.1e+73) tmp = y + y; elseif (y <= 1.18e+117) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.1e+73], N[(y + y), $MachinePrecision], If[LessEqual[y, 1.18e+117], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+73}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 1.18 \cdot 10^{+117}:\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -1.1e73 or 1.18e117 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6469.0
Applied rewrites69.0%
Applied rewrites69.0%
if -1.1e73 < y < 1.18e117Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6447.8
Applied rewrites47.8%
(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
*-commutativeN/A
lower-*.f6434.8
Applied rewrites34.8%
Applied rewrites34.8%
herbie shell --seed 2024277
(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))