
(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 7 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 100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+99.9%
associate-+r+100.0%
count-2100.0%
associate-+l+100.0%
associate-+r+100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
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 -1000000.0) z (if (<= z 1.08e-44) (* y 2.0) (if (<= z 7e+53) (* x 3.0) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1000000.0) {
tmp = z;
} else if (z <= 1.08e-44) {
tmp = y * 2.0;
} else if (z <= 7e+53) {
tmp = x * 3.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 <= (-1000000.0d0)) then
tmp = z
else if (z <= 1.08d-44) then
tmp = y * 2.0d0
else if (z <= 7d+53) then
tmp = x * 3.0d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1000000.0) {
tmp = z;
} else if (z <= 1.08e-44) {
tmp = y * 2.0;
} else if (z <= 7e+53) {
tmp = x * 3.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1000000.0: tmp = z elif z <= 1.08e-44: tmp = y * 2.0 elif z <= 7e+53: tmp = x * 3.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1000000.0) tmp = z; elseif (z <= 1.08e-44) tmp = Float64(y * 2.0); elseif (z <= 7e+53) tmp = Float64(x * 3.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1000000.0) tmp = z; elseif (z <= 1.08e-44) tmp = y * 2.0; elseif (z <= 7e+53) tmp = x * 3.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1000000.0], z, If[LessEqual[z, 1.08e-44], N[(y * 2.0), $MachinePrecision], If[LessEqual[z, 7e+53], N[(x * 3.0), $MachinePrecision], z]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1000000:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.08 \cdot 10^{-44}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+53}:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1e6 or 7.00000000000000038e53 < z Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in z around inf 61.1%
if -1e6 < z < 1.07999999999999994e-44Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 55.0%
if 1.07999999999999994e-44 < z < 7.00000000000000038e53Initial program 99.7%
+-commutative99.7%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in x around inf 66.0%
Final simplification58.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1100000000.0) (not (<= y 155000.0))) (+ z (* y 2.0)) (+ z (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1100000000.0) || !(y <= 155000.0)) {
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 ((y <= (-1100000000.0d0)) .or. (.not. (y <= 155000.0d0))) 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 ((y <= -1100000000.0) || !(y <= 155000.0)) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1100000000.0) or not (y <= 155000.0): tmp = z + (y * 2.0) else: tmp = z + (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1100000000.0) || !(y <= 155000.0)) 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 ((y <= -1100000000.0) || ~((y <= 155000.0))) tmp = z + (y * 2.0); else tmp = z + (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1100000000.0], N[Not[LessEqual[y, 155000.0]], $MachinePrecision]], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1100000000 \lor \neg \left(y \leq 155000\right):\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 3\\
\end{array}
\end{array}
if y < -1.1e9 or 155000 < y Initial program 99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 83.8%
if -1.1e9 < y < 155000Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around 0 90.7%
count-290.7%
+-commutative90.7%
+-commutative90.7%
+-commutative90.7%
associate-+l+90.7%
+-commutative90.7%
count-290.7%
distribute-lft1-in90.7%
metadata-eval90.7%
Simplified90.7%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (<= y -5.5e+139) (* y 2.0) (if (<= y 1.05e+56) (+ z (* x 3.0)) (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e+139) {
tmp = y * 2.0;
} else if (y <= 1.05e+56) {
tmp = z + (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 <= (-5.5d+139)) then
tmp = y * 2.0d0
else if (y <= 1.05d+56) then
tmp = z + (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 <= -5.5e+139) {
tmp = y * 2.0;
} else if (y <= 1.05e+56) {
tmp = z + (x * 3.0);
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.5e+139: tmp = y * 2.0 elif y <= 1.05e+56: tmp = z + (x * 3.0) else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.5e+139) tmp = Float64(y * 2.0); elseif (y <= 1.05e+56) tmp = Float64(z + 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 <= -5.5e+139) tmp = y * 2.0; elseif (y <= 1.05e+56) tmp = z + (x * 3.0); else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.5e+139], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 1.05e+56], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+139}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+56}:\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -5.4999999999999996e139 or 1.05000000000000009e56 < y Initial program 99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 70.9%
if -5.4999999999999996e139 < y < 1.05000000000000009e56Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around 0 85.0%
count-285.0%
+-commutative85.0%
+-commutative85.0%
+-commutative85.0%
associate-+l+85.0%
+-commutative85.0%
count-285.0%
distribute-lft1-in85.0%
metadata-eval85.0%
Simplified85.0%
Final simplification80.6%
(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 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= z -850000000.0) z (if (<= z 1.95e+31) (* y 2.0) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -850000000.0) {
tmp = z;
} else if (z <= 1.95e+31) {
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 <= (-850000000.0d0)) then
tmp = z
else if (z <= 1.95d+31) 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 <= -850000000.0) {
tmp = z;
} else if (z <= 1.95e+31) {
tmp = y * 2.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -850000000.0: tmp = z elif z <= 1.95e+31: tmp = y * 2.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -850000000.0) tmp = z; elseif (z <= 1.95e+31) tmp = Float64(y * 2.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -850000000.0) tmp = z; elseif (z <= 1.95e+31) tmp = y * 2.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -850000000.0], z, If[LessEqual[z, 1.95e+31], N[(y * 2.0), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -850000000:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{+31}:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -8.5e8 or 1.95e31 < z Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in z around inf 59.7%
if -8.5e8 < z < 1.95e31Initial program 99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 52.9%
Final simplification56.5%
(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 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in z around inf 35.7%
Final simplification35.7%
herbie shell --seed 2023199
(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))