
(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 4 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 (+ (+ x y) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x + y) + 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 + y) + z
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x + y) + z;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x + y) + z
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x + y) + z) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x + y) + z;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(x + y\right) + z
\end{array}
Initial program 100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -5.1e-284) x (if (<= y 1.45e-153) z (if (<= y 3.8e-143) x z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5.1e-284) {
tmp = x;
} else if (y <= 1.45e-153) {
tmp = z;
} else if (y <= 3.8e-143) {
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 (y <= (-5.1d-284)) then
tmp = x
else if (y <= 1.45d-153) then
tmp = z
else if (y <= 3.8d-143) 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 (y <= -5.1e-284) {
tmp = x;
} else if (y <= 1.45e-153) {
tmp = z;
} else if (y <= 3.8e-143) {
tmp = x;
} else {
tmp = z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -5.1e-284: tmp = x elif y <= 1.45e-153: tmp = z elif y <= 3.8e-143: tmp = x else: tmp = z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5.1e-284) tmp = x; elseif (y <= 1.45e-153) tmp = z; elseif (y <= 3.8e-143) 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 (y <= -5.1e-284)
tmp = x;
elseif (y <= 1.45e-153)
tmp = z;
elseif (y <= 3.8e-143)
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[y, -5.1e-284], x, If[LessEqual[y, 1.45e-153], z, If[LessEqual[y, 3.8e-143], x, z]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.1 \cdot 10^{-284}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-153}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-143}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -5.1000000000000002e-284 or 1.45000000000000001e-153 < y < 3.79999999999999981e-143Initial program 100.0%
Taylor expanded in x around inf 63.5%
Taylor expanded in x around inf 34.9%
if -5.1000000000000002e-284 < y < 1.45000000000000001e-153 or 3.79999999999999981e-143 < y Initial program 100.0%
Taylor expanded in z around inf 32.6%
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 x around inf 63.4%
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 63.4%
Taylor expanded in x around inf 32.7%
herbie shell --seed 2024111
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, I"
:precision binary64
(+ (+ x y) z))