
(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 9 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 (* y 2.0))))
double code(double x, double y, double z) {
return z + fma(x, 3.0, (y * 2.0));
}
function code(x, y, z) return Float64(z + fma(x, 3.0, Float64(y * 2.0))) end
code[x_, y_, z_] := N[(z + N[(x * 3.0 + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \mathsf{fma}\left(x, 3, y \cdot 2\right)
\end{array}
Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
+-commutative99.8%
associate-+l+99.8%
associate-+r+99.8%
associate-+r+99.8%
*-lft-identity99.8%
metadata-eval99.8%
count-299.8%
distribute-rgt-out99.8%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.2e+49) (not (<= x 4.2e+26))) (+ z (* x 3.0)) (+ (* y 2.0) (+ z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.2e+49) || !(x <= 4.2e+26)) {
tmp = z + (x * 3.0);
} else {
tmp = (y * 2.0) + (z + x);
}
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 <= (-2.2d+49)) .or. (.not. (x <= 4.2d+26))) then
tmp = z + (x * 3.0d0)
else
tmp = (y * 2.0d0) + (z + x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.2e+49) || !(x <= 4.2e+26)) {
tmp = z + (x * 3.0);
} else {
tmp = (y * 2.0) + (z + x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.2e+49) or not (x <= 4.2e+26): tmp = z + (x * 3.0) else: tmp = (y * 2.0) + (z + x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.2e+49) || !(x <= 4.2e+26)) tmp = Float64(z + Float64(x * 3.0)); else tmp = Float64(Float64(y * 2.0) + Float64(z + x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.2e+49) || ~((x <= 4.2e+26))) tmp = z + (x * 3.0); else tmp = (y * 2.0) + (z + x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.2e+49], N[Not[LessEqual[x, 4.2e+26]], $MachinePrecision]], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(y * 2.0), $MachinePrecision] + N[(z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+49} \lor \neg \left(x \leq 4.2 \cdot 10^{+26}\right):\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2 + \left(z + x\right)\\
\end{array}
\end{array}
if x < -2.2000000000000001e49 or 4.2000000000000002e26 < x Initial program 99.6%
+-commutative99.6%
associate-+l+99.6%
+-commutative99.6%
+-commutative99.6%
associate-+l+99.6%
associate-+r+99.6%
associate-+r+99.7%
*-lft-identity99.7%
metadata-eval99.7%
count-299.7%
distribute-rgt-out99.7%
fma-define99.9%
metadata-eval99.9%
metadata-eval99.9%
count-299.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in x around inf 89.5%
if -2.2000000000000001e49 < x < 4.2000000000000002e26Initial program 100.0%
associate-+l+100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 92.4%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.1e+46) (not (<= x 1.4e+28))) (+ z (* x 3.0)) (+ z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e+46) || !(x <= 1.4e+28)) {
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 <= (-1.1d+46)) .or. (.not. (x <= 1.4d+28))) 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 <= -1.1e+46) || !(x <= 1.4e+28)) {
tmp = z + (x * 3.0);
} else {
tmp = z + (y * 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e+46) or not (x <= 1.4e+28): tmp = z + (x * 3.0) else: tmp = z + (y * 2.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e+46) || !(x <= 1.4e+28)) 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 <= -1.1e+46) || ~((x <= 1.4e+28))) tmp = z + (x * 3.0); else tmp = z + (y * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e+46], N[Not[LessEqual[x, 1.4e+28]], $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 -1.1 \cdot 10^{+46} \lor \neg \left(x \leq 1.4 \cdot 10^{+28}\right):\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot 2\\
\end{array}
\end{array}
if x < -1.1e46 or 1.4000000000000001e28 < x Initial program 99.6%
+-commutative99.6%
associate-+l+99.6%
+-commutative99.6%
+-commutative99.6%
associate-+l+99.6%
associate-+r+99.6%
associate-+r+99.7%
*-lft-identity99.7%
metadata-eval99.7%
count-299.7%
distribute-rgt-out99.7%
fma-define99.9%
metadata-eval99.9%
metadata-eval99.9%
count-299.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in x around inf 89.5%
if -1.1e46 < x < 1.4000000000000001e28Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
associate-+r+100.0%
associate-+r+100.0%
*-lft-identity100.0%
metadata-eval100.0%
count-2100.0%
distribute-rgt-out100.0%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 91.2%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.2e+68) (not (<= z 1.4e-47))) (+ z x) (+ x (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+68) || !(z <= 1.4e-47)) {
tmp = z + x;
} else {
tmp = x + (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 ((z <= (-2.2d+68)) .or. (.not. (z <= 1.4d-47))) then
tmp = z + x
else
tmp = x + (y * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+68) || !(z <= 1.4e-47)) {
tmp = z + x;
} else {
tmp = x + (y * 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.2e+68) or not (z <= 1.4e-47): tmp = z + x else: tmp = x + (y * 2.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.2e+68) || !(z <= 1.4e-47)) tmp = Float64(z + x); else tmp = Float64(x + Float64(y * 2.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.2e+68) || ~((z <= 1.4e-47))) tmp = z + x; else tmp = x + (y * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e+68], N[Not[LessEqual[z, 1.4e-47]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(x + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+68} \lor \neg \left(z \leq 1.4 \cdot 10^{-47}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot 2\\
\end{array}
\end{array}
if z < -2.19999999999999987e68 or 1.39999999999999996e-47 < z Initial program 99.9%
associate-+l+99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 81.0%
Taylor expanded in y around 0 68.0%
if -2.19999999999999987e68 < z < 1.39999999999999996e-47Initial program 99.8%
associate-+l+99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
+-commutative99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in x around 0 63.9%
Taylor expanded in z around 0 57.4%
Final simplification63.2%
(FPCore (x y z) :precision binary64 (+ z (+ (* x 3.0) (* y 2.0))))
double code(double x, double y, double z) {
return z + ((x * 3.0) + (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 = z + ((x * 3.0d0) + (y * 2.0d0))
end function
public static double code(double x, double y, double z) {
return z + ((x * 3.0) + (y * 2.0));
}
def code(x, y, z): return z + ((x * 3.0) + (y * 2.0))
function code(x, y, z) return Float64(z + Float64(Float64(x * 3.0) + Float64(y * 2.0))) end
function tmp = code(x, y, z) tmp = z + ((x * 3.0) + (y * 2.0)); end
code[x_, y_, z_] := N[(z + N[(N[(x * 3.0), $MachinePrecision] + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(x \cdot 3 + y \cdot 2\right)
\end{array}
Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
+-commutative99.8%
associate-+l+99.8%
associate-+r+99.8%
associate-+r+99.8%
*-lft-identity99.8%
metadata-eval99.8%
count-299.8%
distribute-rgt-out99.8%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
fma-undefine99.8%
+-commutative99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ z (* y 2.0)))
double code(double x, double y, double z) {
return 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 = z + (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return z + (y * 2.0);
}
def code(x, y, z): return z + (y * 2.0)
function code(x, y, z) return Float64(z + Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = z + (y * 2.0); end
code[x_, y_, z_] := N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot 2
\end{array}
Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
+-commutative99.8%
associate-+l+99.8%
associate-+r+99.8%
associate-+r+99.8%
*-lft-identity99.8%
metadata-eval99.8%
count-299.8%
distribute-rgt-out99.8%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 68.8%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return 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 = z + x
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 99.8%
associate-+l+99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
+-commutative99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in x around 0 73.3%
Taylor expanded in y around 0 44.4%
Final simplification44.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.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
+-commutative99.8%
associate-+l+99.8%
associate-+r+99.8%
associate-+r+99.8%
*-lft-identity99.8%
metadata-eval99.8%
count-299.8%
distribute-rgt-out99.8%
fma-define100.0%
metadata-eval100.0%
metadata-eval100.0%
count-2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 39.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
associate-+l+99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
+-commutative99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in x around 0 73.3%
Taylor expanded in x around inf 7.6%
herbie shell --seed 2024163
(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))