
(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 6 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(x + Float64(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[(x + N[(y + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x + \left(y + z\right)
\end{array}
Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -1.25e-64) (+ x y) (+ y z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e-64) {
tmp = x + y;
} 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 (x <= (-1.25d-64)) then
tmp = x + y
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 (x <= -1.25e-64) {
tmp = x + y;
} else {
tmp = y + z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -1.25e-64: tmp = x + y else: tmp = y + z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -1.25e-64) tmp = Float64(x + y); 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 (x <= -1.25e-64)
tmp = x + y;
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[x, -1.25e-64], N[(x + y), $MachinePrecision], N[(y + z), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-64}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if x < -1.25000000000000008e-64Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6468.2%
Simplified68.2%
if -1.25000000000000008e-64 < x Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
+-lowering-+.f6481.0%
Simplified81.0%
Final simplification77.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -2.95e-65) (+ x y) z))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -2.95e-65) {
tmp = x + y;
} 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 (x <= (-2.95d-65)) then
tmp = x + y
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 (x <= -2.95e-65) {
tmp = x + y;
} else {
tmp = z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -2.95e-65: tmp = x + y else: tmp = z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -2.95e-65) tmp = Float64(x + y); 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 (x <= -2.95e-65)
tmp = x + y;
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[x, -2.95e-65], N[(x + y), $MachinePrecision], z]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.95 \cdot 10^{-65}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.94999999999999989e-65Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6468.7%
Simplified68.7%
if -2.94999999999999989e-65 < x Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in z around inf
Simplified40.5%
Final simplification48.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x -1.25e-64) x z))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e-64) {
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 (x <= (-1.25d-64)) 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 (x <= -1.25e-64) {
tmp = x;
} else {
tmp = z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -1.25e-64: tmp = x else: tmp = z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -1.25e-64) 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 (x <= -1.25e-64)
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[x, -1.25e-64], x, z]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-64}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.25000000000000008e-64Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
Simplified50.4%
if -1.25000000000000008e-64 < x Initial program 100.0%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in z around inf
Simplified40.3%
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%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-lowering-+.f6465.2%
Simplified65.2%
Final simplification65.2%
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%
associate-+l+N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
Simplified29.1%
herbie shell --seed 2024161
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, I"
:precision binary64
(+ (+ x y) z))