
(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 (fma y 2.0 z)))
double code(double x, double y, double z) {
return fma(x, 3.0, fma(y, 2.0, z));
}
function code(x, y, z) return fma(x, 3.0, fma(y, 2.0, z)) end
code[x_, y_, z_] := N[(x * 3.0 + N[(y * 2.0 + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 3, \mathsf{fma}\left(y, 2, z\right)\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
+-commutative99.9%
associate-+l+99.9%
associate-+r+99.9%
count-299.9%
associate-+l+99.9%
associate-+r+99.9%
distribute-rgt1-in99.9%
*-commutative99.9%
fma-def100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -2.7e+51)
z
(if (<= z -0.00355)
(* x 3.0)
(if (<= z -8.6e-12)
z
(if (<= z -7.6e-160)
(* y 2.0)
(if (<= z -1.05e-250) (* x 3.0) (if (<= z 1.05e+57) (* y 2.0) z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+51) {
tmp = z;
} else if (z <= -0.00355) {
tmp = x * 3.0;
} else if (z <= -8.6e-12) {
tmp = z;
} else if (z <= -7.6e-160) {
tmp = y * 2.0;
} else if (z <= -1.05e-250) {
tmp = x * 3.0;
} else if (z <= 1.05e+57) {
tmp = y * 2.0;
} else {
tmp = z;
}
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 (z <= (-2.7d+51)) then
tmp = z
else if (z <= (-0.00355d0)) then
tmp = x * 3.0d0
else if (z <= (-8.6d-12)) then
tmp = z
else if (z <= (-7.6d-160)) then
tmp = y * 2.0d0
else if (z <= (-1.05d-250)) then
tmp = x * 3.0d0
else if (z <= 1.05d+57) then
tmp = y * 2.0d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+51) {
tmp = z;
} else if (z <= -0.00355) {
tmp = x * 3.0;
} else if (z <= -8.6e-12) {
tmp = z;
} else if (z <= -7.6e-160) {
tmp = y * 2.0;
} else if (z <= -1.05e-250) {
tmp = x * 3.0;
} else if (z <= 1.05e+57) {
tmp = y * 2.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.7e+51: tmp = z elif z <= -0.00355: tmp = x * 3.0 elif z <= -8.6e-12: tmp = z elif z <= -7.6e-160: tmp = y * 2.0 elif z <= -1.05e-250: tmp = x * 3.0 elif z <= 1.05e+57: tmp = y * 2.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.7e+51) tmp = z; elseif (z <= -0.00355) tmp = Float64(x * 3.0); elseif (z <= -8.6e-12) tmp = z; elseif (z <= -7.6e-160) tmp = Float64(y * 2.0); elseif (z <= -1.05e-250) tmp = Float64(x * 3.0); elseif (z <= 1.05e+57) tmp = Float64(y * 2.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.7e+51) tmp = z; elseif (z <= -0.00355) tmp = x * 3.0; elseif (z <= -8.6e-12) tmp = z; elseif (z <= -7.6e-160) tmp = y * 2.0; elseif (z <= -1.05e-250) tmp = x * 3.0; elseif (z <= 1.05e+57) tmp = y * 2.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.7e+51], z, If[LessEqual[z, -0.00355], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, -8.6e-12], z, If[LessEqual[z, -7.6e-160], N[(y * 2.0), $MachinePrecision], If[LessEqual[z, -1.05e-250], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, 1.05e+57], N[(y * 2.0), $MachinePrecision], z]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+51}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -0.00355:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;z \leq -8.6 \cdot 10^{-12}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -7.6 \cdot 10^{-160}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;z \leq -1.05 \cdot 10^{-250}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+57}:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.69999999999999992e51 or -0.0035500000000000002 < z < -8.59999999999999971e-12 or 1.04999999999999995e57 < z Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in z around inf 71.9%
if -2.69999999999999992e51 < z < -0.0035500000000000002 or -7.5999999999999997e-160 < z < -1.05e-250Initial program 99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around inf 66.1%
if -8.59999999999999971e-12 < z < -7.5999999999999997e-160 or -1.05e-250 < z < 1.04999999999999995e57Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 53.2%
Final simplification62.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e+44) (not (<= x 5e+57))) (+ z (* x 3.0)) (+ z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e+44) || !(x <= 5e+57)) {
tmp = z + (x * 3.0);
} else {
tmp = z + (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 ((x <= (-6d+44)) .or. (.not. (x <= 5d+57))) then
tmp = z + (x * 3.0d0)
else
tmp = z + (y * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6e+44) || !(x <= 5e+57)) {
tmp = z + (x * 3.0);
} else {
tmp = z + (y * 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e+44) or not (x <= 5e+57): tmp = z + (x * 3.0) else: tmp = z + (y * 2.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e+44) || !(x <= 5e+57)) tmp = Float64(z + Float64(x * 3.0)); else tmp = Float64(z + Float64(y * 2.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e+44) || ~((x <= 5e+57))) tmp = z + (x * 3.0); else tmp = z + (y * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e+44], N[Not[LessEqual[x, 5e+57]], $MachinePrecision]], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{+44} \lor \neg \left(x \leq 5 \cdot 10^{+57}\right):\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot 2\\
\end{array}
\end{array}
if x < -5.99999999999999974e44 or 4.99999999999999972e57 < x Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around 0 85.1%
Taylor expanded in x around 0 85.1%
if -5.99999999999999974e44 < x < 4.99999999999999972e57Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 92.6%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (<= x -9.5e+118) (* x 3.0) (if (<= x 1.65e+143) (+ z (* y 2.0)) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e+118) {
tmp = x * 3.0;
} else if (x <= 1.65e+143) {
tmp = z + (y * 2.0);
} 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 <= (-9.5d+118)) then
tmp = x * 3.0d0
else if (x <= 1.65d+143) then
tmp = z + (y * 2.0d0)
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 <= -9.5e+118) {
tmp = x * 3.0;
} else if (x <= 1.65e+143) {
tmp = z + (y * 2.0);
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.5e+118: tmp = x * 3.0 elif x <= 1.65e+143: tmp = z + (y * 2.0) else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.5e+118) tmp = Float64(x * 3.0); elseif (x <= 1.65e+143) tmp = Float64(z + Float64(y * 2.0)); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.5e+118) tmp = x * 3.0; elseif (x <= 1.65e+143) tmp = z + (y * 2.0); else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.5e+118], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 1.65e+143], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+118}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{+143}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -9.49999999999999974e118 or 1.65e143 < x Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in x around inf 81.4%
if -9.49999999999999974e118 < x < 1.65e143Initial program 99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 85.5%
Final simplification84.5%
(FPCore (x y z) :precision binary64 (if (<= x -1.85e+112) (+ x (* 2.0 (+ x y))) (if (<= x 2e+56) (+ z (* y 2.0)) (+ z (* x 3.0)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.85e+112) {
tmp = x + (2.0 * (x + y));
} else if (x <= 2e+56) {
tmp = z + (y * 2.0);
} else {
tmp = z + (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.85d+112)) then
tmp = x + (2.0d0 * (x + y))
else if (x <= 2d+56) then
tmp = z + (y * 2.0d0)
else
tmp = z + (x * 3.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.85e+112) {
tmp = x + (2.0 * (x + y));
} else if (x <= 2e+56) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.85e+112: tmp = x + (2.0 * (x + y)) elif x <= 2e+56: tmp = z + (y * 2.0) else: tmp = z + (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.85e+112) tmp = Float64(x + Float64(2.0 * Float64(x + y))); elseif (x <= 2e+56) tmp = Float64(z + Float64(y * 2.0)); else tmp = Float64(z + Float64(x * 3.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.85e+112) tmp = x + (2.0 * (x + y)); elseif (x <= 2e+56) tmp = z + (y * 2.0); else tmp = z + (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.85e+112], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e+56], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{+112}:\\
\;\;\;\;x + 2 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+56}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 3\\
\end{array}
\end{array}
if x < -1.85000000000000002e112Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around 0 98.4%
if -1.85000000000000002e112 < x < 2.00000000000000018e56Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 89.4%
if 2.00000000000000018e56 < x Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around 0 86.1%
Taylor expanded in x around 0 86.1%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (+ x (+ z (* 2.0 (+ x y)))))
double code(double x, double y, double z) {
return x + (z + (2.0 * (x + y)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (z + (2.0d0 * (x + y)))
end function
public static double code(double x, double y, double z) {
return x + (z + (2.0 * (x + y)));
}
def code(x, y, z): return x + (z + (2.0 * (x + y)))
function code(x, y, z) return Float64(x + Float64(z + Float64(2.0 * Float64(x + y)))) end
function tmp = code(x, y, z) tmp = x + (z + (2.0 * (x + y))); end
code[x_, y_, z_] := N[(x + N[(z + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(z + 2 \cdot \left(x + y\right)\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z -7.4e-13) z (if (<= z 5.2e+58) (* y 2.0) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.4e-13) {
tmp = z;
} else if (z <= 5.2e+58) {
tmp = y * 2.0;
} else {
tmp = z;
}
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 (z <= (-7.4d-13)) then
tmp = z
else if (z <= 5.2d+58) then
tmp = y * 2.0d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7.4e-13) {
tmp = z;
} else if (z <= 5.2e+58) {
tmp = y * 2.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.4e-13: tmp = z elif z <= 5.2e+58: tmp = y * 2.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.4e-13) tmp = z; elseif (z <= 5.2e+58) tmp = Float64(y * 2.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.4e-13) tmp = z; elseif (z <= 5.2e+58) tmp = y * 2.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.4e-13], z, If[LessEqual[z, 5.2e+58], N[(y * 2.0), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.4 \cdot 10^{-13}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+58}:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -7.39999999999999977e-13 or 5.19999999999999976e58 < z Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in z around inf 67.1%
if -7.39999999999999977e-13 < z < 5.19999999999999976e58Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 48.9%
Final simplification57.4%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 37.7%
Final simplification37.7%
herbie shell --seed 2023176
(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))