
(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 (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 (<= x -4.8e+118)
(* x 3.0)
(if (<= x -2.05e-46)
z
(if (<= x 1.65e-24) (* y 2.0) (if (<= x 2.7e+67) z (* x 3.0))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e+118) {
tmp = x * 3.0;
} else if (x <= -2.05e-46) {
tmp = z;
} else if (x <= 1.65e-24) {
tmp = y * 2.0;
} else if (x <= 2.7e+67) {
tmp = z;
} 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.8d+118)) then
tmp = x * 3.0d0
else if (x <= (-2.05d-46)) then
tmp = z
else if (x <= 1.65d-24) then
tmp = y * 2.0d0
else if (x <= 2.7d+67) then
tmp = z
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.8e+118) {
tmp = x * 3.0;
} else if (x <= -2.05e-46) {
tmp = z;
} else if (x <= 1.65e-24) {
tmp = y * 2.0;
} else if (x <= 2.7e+67) {
tmp = z;
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.8e+118: tmp = x * 3.0 elif x <= -2.05e-46: tmp = z elif x <= 1.65e-24: tmp = y * 2.0 elif x <= 2.7e+67: tmp = z else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.8e+118) tmp = Float64(x * 3.0); elseif (x <= -2.05e-46) tmp = z; elseif (x <= 1.65e-24) tmp = Float64(y * 2.0); elseif (x <= 2.7e+67) tmp = z; else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.8e+118) tmp = x * 3.0; elseif (x <= -2.05e-46) tmp = z; elseif (x <= 1.65e-24) tmp = y * 2.0; elseif (x <= 2.7e+67) tmp = z; else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.8e+118], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, -2.05e-46], z, If[LessEqual[x, 1.65e-24], N[(y * 2.0), $MachinePrecision], If[LessEqual[x, 2.7e+67], z, N[(x * 3.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+118}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq -2.05 \cdot 10^{-46}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{-24}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+67}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -4.8e118 or 2.6999999999999999e67 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in x around inf 71.3%
if -4.8e118 < x < -2.05e-46 or 1.64999999999999992e-24 < x < 2.6999999999999999e67Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 54.5%
if -2.05e-46 < x < 1.64999999999999992e-24Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 58.6%
Final simplification62.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.75e+38) (not (<= x 5.2e+106))) (+ z (* x 3.0)) (+ z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e+38) || !(x <= 5.2e+106)) {
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 <= (-2.75d+38)) .or. (.not. (x <= 5.2d+106))) 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 <= -2.75e+38) || !(x <= 5.2e+106)) {
tmp = z + (x * 3.0);
} else {
tmp = z + (y * 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.75e+38) or not (x <= 5.2e+106): tmp = z + (x * 3.0) else: tmp = z + (y * 2.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.75e+38) || !(x <= 5.2e+106)) 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 <= -2.75e+38) || ~((x <= 5.2e+106))) tmp = z + (x * 3.0); else tmp = z + (y * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.75e+38], N[Not[LessEqual[x, 5.2e+106]], $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 -2.75 \cdot 10^{+38} \lor \neg \left(x \leq 5.2 \cdot 10^{+106}\right):\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot 2\\
\end{array}
\end{array}
if x < -2.7500000000000002e38 or 5.20000000000000039e106 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in y around 0 88.7%
+-commutative88.7%
associate-+l+88.7%
distribute-rgt1-in88.7%
metadata-eval88.7%
Simplified88.7%
if -2.7500000000000002e38 < x < 5.20000000000000039e106Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 91.3%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (<= y -8.4e+108) (* y 2.0) (if (<= y 9.8e+67) (+ z (* x 3.0)) (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e+108) {
tmp = y * 2.0;
} else if (y <= 9.8e+67) {
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 <= (-8.4d+108)) then
tmp = y * 2.0d0
else if (y <= 9.8d+67) 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 <= -8.4e+108) {
tmp = y * 2.0;
} else if (y <= 9.8e+67) {
tmp = z + (x * 3.0);
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.4e+108: tmp = y * 2.0 elif y <= 9.8e+67: tmp = z + (x * 3.0) else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.4e+108) tmp = Float64(y * 2.0); elseif (y <= 9.8e+67) 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 <= -8.4e+108) tmp = y * 2.0; elseif (y <= 9.8e+67) tmp = z + (x * 3.0); else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.4e+108], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 9.8e+67], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{+108}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{+67}:\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -8.40000000000000039e108 or 9.7999999999999998e67 < y Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in y around inf 71.4%
if -8.40000000000000039e108 < y < 9.7999999999999998e67Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around 0 84.3%
+-commutative84.3%
associate-+l+84.3%
distribute-rgt1-in84.3%
metadata-eval84.3%
Simplified84.3%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (<= x -2.2e+38) (+ x (+ z (* x 2.0))) (if (<= x 2e+107) (+ z (* y 2.0)) (+ z (* x 3.0)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.2e+38) {
tmp = x + (z + (x * 2.0));
} else if (x <= 2e+107) {
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 (x <= (-2.2d+38)) then
tmp = x + (z + (x * 2.0d0))
else if (x <= 2d+107) 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 (x <= -2.2e+38) {
tmp = x + (z + (x * 2.0));
} else if (x <= 2e+107) {
tmp = z + (y * 2.0);
} else {
tmp = z + (x * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.2e+38: tmp = x + (z + (x * 2.0)) elif x <= 2e+107: tmp = z + (y * 2.0) else: tmp = z + (x * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.2e+38) tmp = Float64(x + Float64(z + Float64(x * 2.0))); elseif (x <= 2e+107) 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 (x <= -2.2e+38) tmp = x + (z + (x * 2.0)); elseif (x <= 2e+107) tmp = z + (y * 2.0); else tmp = z + (x * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.2e+38], N[(x + N[(z + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e+107], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+38}:\\
\;\;\;\;x + \left(z + x \cdot 2\right)\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+107}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 3\\
\end{array}
\end{array}
if x < -2.20000000000000006e38Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in y around 0 86.3%
if -2.20000000000000006e38 < x < 1.9999999999999999e107Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 91.3%
if 1.9999999999999999e107 < x Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
Simplified99.8%
Taylor expanded in y around 0 91.0%
+-commutative91.0%
associate-+l+91.1%
distribute-rgt1-in91.1%
metadata-eval91.1%
Simplified91.1%
Final simplification90.3%
(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 -3.8e+78) (* y 2.0) (if (<= y 7.5e+65) z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+78) {
tmp = y * 2.0;
} else if (y <= 7.5e+65) {
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 <= (-3.8d+78)) then
tmp = y * 2.0d0
else if (y <= 7.5d+65) 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 <= -3.8e+78) {
tmp = y * 2.0;
} else if (y <= 7.5e+65) {
tmp = z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e+78: tmp = y * 2.0 elif y <= 7.5e+65: tmp = z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e+78) tmp = Float64(y * 2.0); elseif (y <= 7.5e+65) tmp = z; else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e+78) tmp = y * 2.0; elseif (y <= 7.5e+65) tmp = z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e+78], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 7.5e+65], z, N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+78}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+65}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -3.7999999999999999e78 or 7.50000000000000006e65 < y Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in y around inf 67.9%
if -3.7999999999999999e78 < y < 7.50000000000000006e65Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
Simplified99.9%
Taylor expanded in z around inf 45.3%
Final simplification54.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 31.7%
Final simplification31.7%
herbie shell --seed 2023192
(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))