
(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}
(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}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (if (<= z 1.06e+38) (+ x y) (+ y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.06e+38) {
tmp = x + y;
} else {
tmp = y + z;
}
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 <= 1.06d+38) then
tmp = x + y
else
tmp = y + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.06e+38) {
tmp = x + y;
} else {
tmp = y + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.06e+38: tmp = x + y else: tmp = y + z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.06e+38) tmp = Float64(x + y); else tmp = Float64(y + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.06e+38) tmp = x + y; else tmp = y + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.06e+38], N[(x + y), $MachinePrecision], N[(y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.06 \cdot 10^{+38}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if z < 1.06e38Initial program 100.0%
Taylor expanded in z around 0 73.6%
+-commutative73.6%
Simplified73.6%
if 1.06e38 < z Initial program 100.0%
Taylor expanded in x around 0 74.7%
Final simplification73.8%
(FPCore (x y z) :precision binary64 (if (<= z 1.15e+38) (+ x y) z))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.15e+38) {
tmp = x + y;
} else {
tmp = z;
}
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 <= 1.15d+38) then
tmp = x + y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.15e+38) {
tmp = x + y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.15e+38: tmp = x + y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.15e+38) tmp = Float64(x + y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.15e+38) tmp = x + y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.15e+38], N[(x + y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.15 \cdot 10^{+38}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < 1.1500000000000001e38Initial program 100.0%
Taylor expanded in z around 0 73.6%
+-commutative73.6%
Simplified73.6%
if 1.1500000000000001e38 < z Initial program 100.0%
Taylor expanded in z around inf 55.4%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (if (<= z 1.36e+35) x z))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.36e+35) {
tmp = x;
} else {
tmp = z;
}
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 <= 1.36d+35) then
tmp = x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.36e+35) {
tmp = x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.36e+35: tmp = x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.36e+35) tmp = x; else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.36e+35) tmp = x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.36e+35], x, z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.36 \cdot 10^{+35}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < 1.36e35Initial program 100.0%
Taylor expanded in x around inf 36.6%
if 1.36e35 < z Initial program 100.0%
Taylor expanded in z around inf 54.5%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 66.2%
+-commutative66.2%
Simplified66.2%
Final simplification66.2%
(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 100.0%
Taylor expanded in x around inf 34.2%
herbie shell --seed 2024106
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, I"
:precision binary64
(+ (+ x y) z))