
(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 -6e+199)
z
(if (<= z -1e+148)
(* y 2.0)
(if (<= z 3e-144) (* x 3.0) (if (<= z 1.6e+40) (* y 2.0) z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6e+199) {
tmp = z;
} else if (z <= -1e+148) {
tmp = y * 2.0;
} else if (z <= 3e-144) {
tmp = x * 3.0;
} else if (z <= 1.6e+40) {
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 <= (-6d+199)) then
tmp = z
else if (z <= (-1d+148)) then
tmp = y * 2.0d0
else if (z <= 3d-144) then
tmp = x * 3.0d0
else if (z <= 1.6d+40) 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 <= -6e+199) {
tmp = z;
} else if (z <= -1e+148) {
tmp = y * 2.0;
} else if (z <= 3e-144) {
tmp = x * 3.0;
} else if (z <= 1.6e+40) {
tmp = y * 2.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6e+199: tmp = z elif z <= -1e+148: tmp = y * 2.0 elif z <= 3e-144: tmp = x * 3.0 elif z <= 1.6e+40: tmp = y * 2.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6e+199) tmp = z; elseif (z <= -1e+148) tmp = Float64(y * 2.0); elseif (z <= 3e-144) tmp = Float64(x * 3.0); elseif (z <= 1.6e+40) tmp = Float64(y * 2.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6e+199) tmp = z; elseif (z <= -1e+148) tmp = y * 2.0; elseif (z <= 3e-144) tmp = x * 3.0; elseif (z <= 1.6e+40) tmp = y * 2.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6e+199], z, If[LessEqual[z, -1e+148], N[(y * 2.0), $MachinePrecision], If[LessEqual[z, 3e-144], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, 1.6e+40], N[(y * 2.0), $MachinePrecision], z]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+199}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -1 \cdot 10^{+148}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-144}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+40}:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -6.0000000000000002e199 or 1.5999999999999999e40 < z Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 73.2%
if -6.0000000000000002e199 < z < -1e148 or 2.9999999999999999e-144 < z < 1.5999999999999999e40Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 48.4%
if -1e148 < z < 2.9999999999999999e-144Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around inf 60.4%
Final simplification62.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.25e+21) (not (<= y 1.4e+148))) (+ z (* y 2.0)) (+ z (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.25e+21) || !(y <= 1.4e+148)) {
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 <= (-2.25d+21)) .or. (.not. (y <= 1.4d+148))) 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 <= -2.25e+21) || !(y <= 1.4e+148)) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.25e+21) or not (y <= 1.4e+148): tmp = z + (y * 2.0) else: tmp = z + (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.25e+21) || !(y <= 1.4e+148)) 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 <= -2.25e+21) || ~((y <= 1.4e+148))) tmp = z + (y * 2.0); else tmp = z + (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.25e+21], N[Not[LessEqual[y, 1.4e+148]], $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 -2.25 \cdot 10^{+21} \lor \neg \left(y \leq 1.4 \cdot 10^{+148}\right):\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 3\\
\end{array}
\end{array}
if y < -2.25e21 or 1.3999999999999999e148 < y Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 89.1%
if -2.25e21 < y < 1.3999999999999999e148Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around 0 99.9%
Taylor expanded in y around 0 91.5%
Final simplification90.7%
(FPCore (x y z) :precision binary64 (if (<= x -1.55e+175) (* x 3.0) (if (<= x 3e+149) (+ z (* y 2.0)) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.55e+175) {
tmp = x * 3.0;
} else if (x <= 3e+149) {
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 <= (-1.55d+175)) then
tmp = x * 3.0d0
else if (x <= 3d+149) 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 <= -1.55e+175) {
tmp = x * 3.0;
} else if (x <= 3e+149) {
tmp = z + (y * 2.0);
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.55e+175: tmp = x * 3.0 elif x <= 3e+149: tmp = z + (y * 2.0) else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.55e+175) tmp = Float64(x * 3.0); elseif (x <= 3e+149) 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 <= -1.55e+175) tmp = x * 3.0; elseif (x <= 3e+149) tmp = z + (y * 2.0); else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.55e+175], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 3e+149], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{+175}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+149}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.54999999999999992e175 or 3.00000000000000003e149 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around inf 83.5%
if -1.54999999999999992e175 < x < 3.00000000000000003e149Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in x around 0 80.7%
Final simplification81.4%
(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 (+ (* x 3.0) (+ z (* y 2.0))))
double code(double x, double y, double z) {
return (x * 3.0) + (z + (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 = (x * 3.0d0) + (z + (y * 2.0d0))
end function
public static double code(double x, double y, double z) {
return (x * 3.0) + (z + (y * 2.0));
}
def code(x, y, z): return (x * 3.0) + (z + (y * 2.0))
function code(x, y, z) return Float64(Float64(x * 3.0) + Float64(z + Float64(y * 2.0))) end
function tmp = code(x, y, z) tmp = (x * 3.0) + (z + (y * 2.0)); end
code[x_, y_, z_] := N[(N[(x * 3.0), $MachinePrecision] + N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 3 + \left(z + y \cdot 2\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.75e+21) (* y 2.0) (if (<= y 1.15e+149) z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.75e+21) {
tmp = y * 2.0;
} else if (y <= 1.15e+149) {
tmp = z;
} 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 <= (-1.75d+21)) then
tmp = y * 2.0d0
else if (y <= 1.15d+149) then
tmp = z
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 <= -1.75e+21) {
tmp = y * 2.0;
} else if (y <= 1.15e+149) {
tmp = z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.75e+21: tmp = y * 2.0 elif y <= 1.15e+149: tmp = z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.75e+21) tmp = Float64(y * 2.0); elseif (y <= 1.15e+149) tmp = z; else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.75e+21) tmp = y * 2.0; elseif (y <= 1.15e+149) tmp = z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.75e+21], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 1.15e+149], z, N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{+21}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+149}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -1.75e21 or 1.1499999999999999e149 < y Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 72.6%
if -1.75e21 < y < 1.1499999999999999e149Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in z around inf 44.4%
Final simplification53.8%
(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 35.1%
Final simplification35.1%
herbie shell --seed 2023224
(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))