
(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 (<= y -1.35e+82)
(* y 2.0)
(if (<= y 5e-299)
z
(if (<= y 2.2e-199) (* x 3.0) (if (<= y 4.9e+39) z (* y 2.0))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.35e+82) {
tmp = y * 2.0;
} else if (y <= 5e-299) {
tmp = z;
} else if (y <= 2.2e-199) {
tmp = x * 3.0;
} else if (y <= 4.9e+39) {
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.35d+82)) then
tmp = y * 2.0d0
else if (y <= 5d-299) then
tmp = z
else if (y <= 2.2d-199) then
tmp = x * 3.0d0
else if (y <= 4.9d+39) 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.35e+82) {
tmp = y * 2.0;
} else if (y <= 5e-299) {
tmp = z;
} else if (y <= 2.2e-199) {
tmp = x * 3.0;
} else if (y <= 4.9e+39) {
tmp = z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.35e+82: tmp = y * 2.0 elif y <= 5e-299: tmp = z elif y <= 2.2e-199: tmp = x * 3.0 elif y <= 4.9e+39: tmp = z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.35e+82) tmp = Float64(y * 2.0); elseif (y <= 5e-299) tmp = z; elseif (y <= 2.2e-199) tmp = Float64(x * 3.0); elseif (y <= 4.9e+39) 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.35e+82) tmp = y * 2.0; elseif (y <= 5e-299) tmp = z; elseif (y <= 2.2e-199) tmp = x * 3.0; elseif (y <= 4.9e+39) tmp = z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.35e+82], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 5e-299], z, If[LessEqual[y, 2.2e-199], N[(x * 3.0), $MachinePrecision], If[LessEqual[y, 4.9e+39], z, N[(y * 2.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{+82}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-299}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-199}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{+39}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -1.35e82 or 4.89999999999999987e39 < y Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 72.3%
if -1.35e82 < y < 4.99999999999999956e-299 or 2.1999999999999998e-199 < y < 4.89999999999999987e39Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 56.9%
if 4.99999999999999956e-299 < y < 2.1999999999999998e-199Initial program 99.7%
+-commutative99.7%
associate-+l+99.7%
+-commutative99.7%
count-299.7%
Simplified99.7%
Taylor expanded in x around inf 63.9%
Final simplification63.7%
(FPCore (x y z) :precision binary64 (if (<= y -4e-5) (+ z (* y 2.0)) (if (<= y 8.2e+39) (+ z (* x 3.0)) (+ x (* 2.0 (+ x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e-5) {
tmp = z + (y * 2.0);
} else if (y <= 8.2e+39) {
tmp = z + (x * 3.0);
} 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 (y <= (-4d-5)) then
tmp = z + (y * 2.0d0)
else if (y <= 8.2d+39) then
tmp = z + (x * 3.0d0)
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 (y <= -4e-5) {
tmp = z + (y * 2.0);
} else if (y <= 8.2e+39) {
tmp = z + (x * 3.0);
} else {
tmp = x + (2.0 * (x + y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e-5: tmp = z + (y * 2.0) elif y <= 8.2e+39: tmp = z + (x * 3.0) else: tmp = x + (2.0 * (x + y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e-5) tmp = Float64(z + Float64(y * 2.0)); elseif (y <= 8.2e+39) tmp = Float64(z + Float64(x * 3.0)); 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 (y <= -4e-5) tmp = z + (y * 2.0); elseif (y <= 8.2e+39) tmp = z + (x * 3.0); else tmp = x + (2.0 * (x + y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e-5], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.2e+39], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-5}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+39}:\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;x + 2 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -4.00000000000000033e-5Initial program 99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 89.3%
if -4.00000000000000033e-5 < y < 8.20000000000000008e39Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around 0 91.6%
if 8.20000000000000008e39 < y Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around 0 84.5%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.000205) (not (<= y 2.25e+35))) (+ z (* y 2.0)) (+ z (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000205) || !(y <= 2.25e+35)) {
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 <= (-0.000205d0)) .or. (.not. (y <= 2.25d+35))) 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 <= -0.000205) || !(y <= 2.25e+35)) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.000205) or not (y <= 2.25e+35): tmp = z + (y * 2.0) else: tmp = z + (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.000205) || !(y <= 2.25e+35)) 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 <= -0.000205) || ~((y <= 2.25e+35))) tmp = z + (y * 2.0); else tmp = z + (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.000205], N[Not[LessEqual[y, 2.25e+35]], $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 -0.000205 \lor \neg \left(y \leq 2.25 \cdot 10^{+35}\right):\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 3\\
\end{array}
\end{array}
if y < -2.05e-4 or 2.2499999999999998e35 < y Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in x around 0 86.8%
if -2.05e-4 < y < 2.2499999999999998e35Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around 0 91.5%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (<= x -8e+147) (* x 3.0) (if (<= x 7.4e+155) (+ z (* y 2.0)) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8e+147) {
tmp = x * 3.0;
} else if (x <= 7.4e+155) {
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 <= (-8d+147)) then
tmp = x * 3.0d0
else if (x <= 7.4d+155) 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 <= -8e+147) {
tmp = x * 3.0;
} else if (x <= 7.4e+155) {
tmp = z + (y * 2.0);
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8e+147: tmp = x * 3.0 elif x <= 7.4e+155: tmp = z + (y * 2.0) else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8e+147) tmp = Float64(x * 3.0); elseif (x <= 7.4e+155) 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 <= -8e+147) tmp = x * 3.0; elseif (x <= 7.4e+155) tmp = z + (y * 2.0); else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8e+147], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 7.4e+155], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{+147}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 7.4 \cdot 10^{+155}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -7.9999999999999998e147 or 7.3999999999999996e155 < x Initial program 99.7%
+-commutative99.7%
associate-+l+99.7%
+-commutative99.7%
count-299.7%
Simplified99.7%
Taylor expanded in x around inf 72.0%
if -7.9999999999999998e147 < x < 7.3999999999999996e155Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 87.6%
Final simplification84.1%
(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 (<= y -1e+84) (* y 2.0) (if (<= y 2.05e+39) z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1e+84) {
tmp = y * 2.0;
} else if (y <= 2.05e+39) {
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 <= (-1d+84)) then
tmp = y * 2.0d0
else if (y <= 2.05d+39) 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 <= -1e+84) {
tmp = y * 2.0;
} else if (y <= 2.05e+39) {
tmp = z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1e+84: tmp = y * 2.0 elif y <= 2.05e+39: tmp = z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1e+84) tmp = Float64(y * 2.0); elseif (y <= 2.05e+39) tmp = z; else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1e+84) tmp = y * 2.0; elseif (y <= 2.05e+39) tmp = z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1e+84], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 2.05e+39], z, N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+84}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{+39}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -1.00000000000000006e84 or 2.05000000000000002e39 < y Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 72.3%
if -1.00000000000000006e84 < y < 2.05000000000000002e39Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 54.1%
Final simplification61.6%
(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 38.8%
Final simplification38.8%
herbie shell --seed 2023196
(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))