
(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 5 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 (+ x (+ (+ x (+ y (+ x y))) z)))
double code(double x, double y, double z) {
return x + ((x + (y + (x + y))) + z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((x + (y + (x + y))) + z)
end function
public static double code(double x, double y, double z) {
return x + ((x + (y + (x + y))) + z);
}
def code(x, y, z): return x + ((x + (y + (x + y))) + z)
function code(x, y, z) return Float64(x + Float64(Float64(x + Float64(y + Float64(x + y))) + z)) end
function tmp = code(x, y, z) tmp = x + ((x + (y + (x + y))) + z); end
code[x_, y_, z_] := N[(x + N[(N[(x + N[(y + N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(x + \left(y + \left(x + y\right)\right)\right) + z\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= y -4e+133) (fma 2.0 y z) (if (<= y 3.2e+97) (fma x 3.0 z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e+133) {
tmp = fma(2.0, y, z);
} else if (y <= 3.2e+97) {
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 <= -4e+133) tmp = fma(2.0, y, z); elseif (y <= 3.2e+97) tmp = fma(x, 3.0, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -4e+133], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 3.2e+97], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+133}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{+97}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -4.0000000000000001e133 or 3.20000000000000016e97 < y Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6494.8
Applied rewrites94.8%
if -4.0000000000000001e133 < y < 3.20000000000000016e97Initial 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.f6491.1
Applied rewrites91.1%
(FPCore (x y z) :precision binary64 (if (<= x -2.5e+68) (* x 3.0) (if (<= x 1.5e+181) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e+68) {
tmp = x * 3.0;
} else if (x <= 1.5e+181) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.5e+68) tmp = Float64(x * 3.0); elseif (x <= 1.5e+181) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.5e+68], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 1.5e+181], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+68}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+181}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -2.5000000000000002e68 or 1.50000000000000006e181 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6476.6
Applied rewrites76.6%
if -2.5000000000000002e68 < x < 1.50000000000000006e181Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6489.0
Applied rewrites89.0%
(FPCore (x y z) :precision binary64 (if (<= y -4e+133) (* y 2.0) (if (<= y 1.5e+101) (* x 3.0) (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e+133) {
tmp = y * 2.0;
} else if (y <= 1.5e+101) {
tmp = x * 3.0;
} else {
tmp = y * 2.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 (y <= (-4d+133)) then
tmp = y * 2.0d0
else if (y <= 1.5d+101) then
tmp = x * 3.0d0
else
tmp = y * 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4e+133) {
tmp = y * 2.0;
} else if (y <= 1.5e+101) {
tmp = x * 3.0;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e+133: tmp = y * 2.0 elif y <= 1.5e+101: tmp = x * 3.0 else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e+133) tmp = Float64(y * 2.0); elseif (y <= 1.5e+101) tmp = Float64(x * 3.0); else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4e+133) tmp = y * 2.0; elseif (y <= 1.5e+101) tmp = x * 3.0; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e+133], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 1.5e+101], N[(x * 3.0), $MachinePrecision], N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+133}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+101}:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -4.0000000000000001e133 or 1.49999999999999997e101 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6478.9
Applied rewrites78.9%
if -4.0000000000000001e133 < y < 1.49999999999999997e101Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6447.5
Applied rewrites47.5%
Final simplification57.8%
(FPCore (x y z) :precision binary64 (* y 2.0))
double code(double x, double y, double z) {
return y * 2.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * 2.0d0
end function
public static double code(double x, double y, double z) {
return y * 2.0;
}
def code(x, y, z): return y * 2.0
function code(x, y, z) return Float64(y * 2.0) end
function tmp = code(x, y, z) tmp = y * 2.0; end
code[x_, y_, z_] := N[(y * 2.0), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 2
\end{array}
Initial program 99.9%
Taylor expanded in y around inf
lower-*.f6433.1
Applied rewrites33.1%
Final simplification33.1%
herbie shell --seed 2024219
(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))