
(FPCore (x y z) :precision binary64 (+ (+ x y) z))
double code(double x, double y, double z) {
return (x + y) + z;
}
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) + z
end function
public static double code(double x, double y, double z) {
return (x + y) + z;
}
def code(x, y, z): return (x + y) + z
function code(x, y, z) return Float64(Float64(x + y) + z) end
function tmp = code(x, y, z) tmp = (x + y) + z; end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) + z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x y) z))
double code(double x, double y, double z) {
return (x + y) + z;
}
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) + z
end function
public static double code(double x, double y, double z) {
return (x + y) + z;
}
def code(x, y, z): return (x + y) + z
function code(x, y, z) return Float64(Float64(x + y) + z) end
function tmp = code(x, y, z) tmp = (x + y) + z; end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) + z
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma (pow (cbrt y) 2.0) (cbrt y) (+ x z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(pow(cbrt(y), 2.0), cbrt(y), (x + z));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma((cbrt(y) ^ 2.0), cbrt(y), Float64(x + z)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[Power[N[Power[y, 1/3], $MachinePrecision], 2.0], $MachinePrecision] * N[Power[y, 1/3], $MachinePrecision] + N[(x + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left({\left(\sqrt[3]{y}\right)}^{2}, \sqrt[3]{y}, x + z\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
add-cube-cbrt99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Final simplification99.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 300000.0) (+ y x) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 300000.0) {
tmp = y + x;
} else {
tmp = z;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= 300000.0d0) then
tmp = y + x
else
tmp = z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (z <= 300000.0) {
tmp = y + x;
} else {
tmp = z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= 300000.0: tmp = y + x else: tmp = z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 300000.0) tmp = Float64(y + x); else tmp = z; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= 300000.0)
tmp = y + x;
else
tmp = z;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, 300000.0], N[(y + x), $MachinePrecision], z]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 300000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < 3e5Initial program 100.0%
Taylor expanded in z around 0 80.1%
+-commutative80.1%
Simplified80.1%
if 3e5 < z Initial program 100.0%
Taylor expanded in z around inf 54.5%
Final simplification72.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 13500000.0) (+ y x) (+ y z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 13500000.0) {
tmp = y + x;
} else {
tmp = y + z;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= 13500000.0d0) then
tmp = y + x
else
tmp = y + z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (z <= 13500000.0) {
tmp = y + x;
} else {
tmp = y + z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= 13500000.0: tmp = y + x else: tmp = y + z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 13500000.0) tmp = Float64(y + x); else tmp = Float64(y + z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= 13500000.0)
tmp = y + x;
else
tmp = y + z;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, 13500000.0], N[(y + x), $MachinePrecision], N[(y + z), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 13500000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if z < 1.35e7Initial program 100.0%
Taylor expanded in z around 0 80.1%
+-commutative80.1%
Simplified80.1%
if 1.35e7 < z Initial program 100.0%
Taylor expanded in x around 0 77.4%
Final simplification79.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 13500000.0) x z))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 13500000.0) {
tmp = x;
} else {
tmp = z;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= 13500000.0d0) then
tmp = x
else
tmp = z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (z <= 13500000.0) {
tmp = x;
} else {
tmp = z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= 13500000.0: tmp = x else: tmp = z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 13500000.0) tmp = x; else tmp = z; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= 13500000.0)
tmp = x;
else
tmp = z;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, 13500000.0], x, z]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 13500000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < 1.35e7Initial program 100.0%
Taylor expanded in x around inf 45.7%
if 1.35e7 < z Initial program 100.0%
Taylor expanded in z around inf 54.5%
Final simplification48.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (+ z (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return z + (y + x);
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 + x)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return z + (y + x);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return z + (y + x)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(z + Float64(y + x)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = z + (y + x);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z + N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
z + \left(y + x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (+ x z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x + z;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x + z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x + z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x + z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x + z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x + z
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 68.0%
+-commutative68.0%
Simplified68.0%
Final simplification68.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x
x, y, z = sort([x, y, z]) function code(x, y, z) return x end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 39.5%
Final simplification39.5%
herbie shell --seed 2024018
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, I"
:precision binary64
(+ (+ x y) z))