
(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 (+ z (fma x 3.0 (* 2.0 y))))
double code(double x, double y, double z) {
return z + fma(x, 3.0, (2.0 * y));
}
function code(x, y, z) return Float64(z + fma(x, 3.0, Float64(2.0 * y))) end
code[x_, y_, z_] := N[(z + N[(x * 3.0 + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \mathsf{fma}\left(x, 3, 2 \cdot y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
remove-double-neg99.9%
distribute-neg-in99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+r+99.9%
associate--l+99.9%
count-299.9%
*-commutative99.9%
fma-def99.9%
count-299.9%
neg-mul-199.9%
distribute-rgt-out--99.9%
metadata-eval99.9%
Simplified99.9%
add-log-exp21.0%
*-un-lft-identity21.0%
log-prod21.0%
metadata-eval21.0%
add-log-exp99.9%
fma-udef99.9%
+-commutative99.9%
fma-def100.0%
*-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e+71) (+ z (* x 3.0)) (if (<= x 3.8e+39) (+ z (* 2.0 y)) (+ x (* 2.0 (+ x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+71) {
tmp = z + (x * 3.0);
} else if (x <= 3.8e+39) {
tmp = z + (2.0 * y);
} else {
tmp = x + (2.0 * (x + 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 (x <= (-1.1d+71)) then
tmp = z + (x * 3.0d0)
else if (x <= 3.8d+39) then
tmp = z + (2.0d0 * y)
else
tmp = x + (2.0d0 * (x + y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+71) {
tmp = z + (x * 3.0);
} else if (x <= 3.8e+39) {
tmp = z + (2.0 * y);
} else {
tmp = x + (2.0 * (x + y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.1e+71: tmp = z + (x * 3.0) elif x <= 3.8e+39: tmp = z + (2.0 * y) else: tmp = x + (2.0 * (x + y)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.1e+71) tmp = Float64(z + Float64(x * 3.0)); elseif (x <= 3.8e+39) tmp = Float64(z + Float64(2.0 * y)); else tmp = Float64(x + Float64(2.0 * Float64(x + y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.1e+71) tmp = z + (x * 3.0); elseif (x <= 3.8e+39) tmp = z + (2.0 * y); else tmp = x + (2.0 * (x + y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.1e+71], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.8e+39], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+71}:\\
\;\;\;\;z + x \cdot 3\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{+39}:\\
\;\;\;\;z + 2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + 2 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if x < -1.09999999999999997e71Initial program 99.8%
+-commutative99.8%
associate-+l+99.9%
remove-double-neg99.9%
distribute-neg-in99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+r+99.9%
associate--l+99.8%
count-299.8%
*-commutative99.8%
fma-def99.8%
count-299.8%
neg-mul-199.8%
distribute-rgt-out--99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 87.9%
if -1.09999999999999997e71 < x < 3.7999999999999998e39Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 94.5%
if 3.7999999999999998e39 < x Initial program 99.7%
+-commutative99.7%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in z around 0 85.3%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (<= x -4.2e+36) (* x 3.0) (if (<= x -6e-191) z (if (<= x 2.8e+112) (* 2.0 y) (* x 3.0)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e+36) {
tmp = x * 3.0;
} else if (x <= -6e-191) {
tmp = z;
} else if (x <= 2.8e+112) {
tmp = 2.0 * 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 <= (-4.2d+36)) then
tmp = x * 3.0d0
else if (x <= (-6d-191)) then
tmp = z
else if (x <= 2.8d+112) then
tmp = 2.0d0 * 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 <= -4.2e+36) {
tmp = x * 3.0;
} else if (x <= -6e-191) {
tmp = z;
} else if (x <= 2.8e+112) {
tmp = 2.0 * y;
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.2e+36: tmp = x * 3.0 elif x <= -6e-191: tmp = z elif x <= 2.8e+112: tmp = 2.0 * y else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.2e+36) tmp = Float64(x * 3.0); elseif (x <= -6e-191) tmp = z; elseif (x <= 2.8e+112) tmp = Float64(2.0 * y); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.2e+36) tmp = x * 3.0; elseif (x <= -6e-191) tmp = z; elseif (x <= 2.8e+112) tmp = 2.0 * y; else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.2e+36], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, -6e-191], z, If[LessEqual[x, 2.8e+112], N[(2.0 * y), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+36}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-191}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+112}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -4.20000000000000009e36 or 2.8000000000000001e112 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around inf 66.5%
if -4.20000000000000009e36 < x < -6.0000000000000001e-191Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in z around inf 61.9%
if -6.0000000000000001e-191 < x < 2.8000000000000001e112Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 53.4%
Final simplification60.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e+71) (not (<= x 4.4e+107))) (+ z (* x 3.0)) (+ z (* 2.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+71) || !(x <= 4.4e+107)) {
tmp = z + (x * 3.0);
} else {
tmp = z + (2.0 * 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 ((x <= (-2d+71)) .or. (.not. (x <= 4.4d+107))) then
tmp = z + (x * 3.0d0)
else
tmp = z + (2.0d0 * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+71) || !(x <= 4.4e+107)) {
tmp = z + (x * 3.0);
} else {
tmp = z + (2.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e+71) or not (x <= 4.4e+107): tmp = z + (x * 3.0) else: tmp = z + (2.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e+71) || !(x <= 4.4e+107)) tmp = Float64(z + Float64(x * 3.0)); else tmp = Float64(z + Float64(2.0 * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2e+71) || ~((x <= 4.4e+107))) tmp = z + (x * 3.0); else tmp = z + (2.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e+71], N[Not[LessEqual[x, 4.4e+107]], $MachinePrecision]], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+71} \lor \neg \left(x \leq 4.4 \cdot 10^{+107}\right):\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;z + 2 \cdot y\\
\end{array}
\end{array}
if x < -2.0000000000000001e71 or 4.4e107 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
remove-double-neg99.8%
distribute-neg-in99.8%
distribute-neg-in99.8%
remove-double-neg99.8%
sub-neg99.8%
associate-+l+99.8%
+-commutative99.8%
associate-+r+99.8%
associate--l+99.8%
count-299.8%
*-commutative99.8%
fma-def99.8%
count-299.8%
neg-mul-199.8%
distribute-rgt-out--99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 84.6%
if -2.0000000000000001e71 < x < 4.4e107Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 90.4%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.15e+72) (* x 3.0) (if (<= x 9e+150) (+ z (* 2.0 y)) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e+72) {
tmp = x * 3.0;
} else if (x <= 9e+150) {
tmp = z + (2.0 * 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.15d+72)) then
tmp = x * 3.0d0
else if (x <= 9d+150) then
tmp = z + (2.0d0 * 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.15e+72) {
tmp = x * 3.0;
} else if (x <= 9e+150) {
tmp = z + (2.0 * y);
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.15e+72: tmp = x * 3.0 elif x <= 9e+150: tmp = z + (2.0 * y) else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.15e+72) tmp = Float64(x * 3.0); elseif (x <= 9e+150) tmp = Float64(z + Float64(2.0 * y)); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.15e+72) tmp = x * 3.0; elseif (x <= 9e+150) tmp = z + (2.0 * y); else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.15e+72], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 9e+150], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{+72}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 9 \cdot 10^{+150}:\\
\;\;\;\;z + 2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.15e72 or 9.00000000000000001e150 < x Initial program 99.7%
+-commutative99.7%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around inf 71.9%
if -1.15e72 < x < 9.00000000000000001e150Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 88.6%
Final simplification82.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 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 -1.7e+95) z (if (<= z 1.95e+136) (* 2.0 y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+95) {
tmp = z;
} else if (z <= 1.95e+136) {
tmp = 2.0 * y;
} 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 <= (-1.7d+95)) then
tmp = z
else if (z <= 1.95d+136) then
tmp = 2.0d0 * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+95) {
tmp = z;
} else if (z <= 1.95e+136) {
tmp = 2.0 * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.7e+95: tmp = z elif z <= 1.95e+136: tmp = 2.0 * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.7e+95) tmp = z; elseif (z <= 1.95e+136) tmp = Float64(2.0 * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.7e+95) tmp = z; elseif (z <= 1.95e+136) tmp = 2.0 * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+95], z, If[LessEqual[z, 1.95e+136], N[(2.0 * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+95}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{+136}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.70000000000000011e95 or 1.9500000000000001e136 < z Initial program 99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in z around inf 71.9%
if -1.70000000000000011e95 < z < 1.9500000000000001e136Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 45.5%
Final simplification54.7%
(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 34.0%
Final simplification34.0%
herbie shell --seed 2023297
(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))