
(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 (+ z (+ x y)))
double code(double x, double y, double z) {
return z + (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 = z + (x + y)
end function
public static double code(double x, double y, double z) {
return z + (x + y);
}
def code(x, y, z): return z + (x + y)
function code(x, y, z) return Float64(z + Float64(x + y)) end
function tmp = code(x, y, z) tmp = z + (x + y); end
code[x_, y_, z_] := N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.7e+137) (+ x y) (if (<= x -3.6e+62) (+ y z) (if (<= x -2.6e+20) x (+ y z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e+137) {
tmp = x + y;
} else if (x <= -3.6e+62) {
tmp = y + z;
} else if (x <= -2.6e+20) {
tmp = x;
} 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 (x <= (-1.7d+137)) then
tmp = x + y
else if (x <= (-3.6d+62)) then
tmp = y + z
else if (x <= (-2.6d+20)) then
tmp = x
else
tmp = y + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e+137) {
tmp = x + y;
} else if (x <= -3.6e+62) {
tmp = y + z;
} else if (x <= -2.6e+20) {
tmp = x;
} else {
tmp = y + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.7e+137: tmp = x + y elif x <= -3.6e+62: tmp = y + z elif x <= -2.6e+20: tmp = x else: tmp = y + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.7e+137) tmp = Float64(x + y); elseif (x <= -3.6e+62) tmp = Float64(y + z); elseif (x <= -2.6e+20) tmp = x; else tmp = Float64(y + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.7e+137) tmp = x + y; elseif (x <= -3.6e+62) tmp = y + z; elseif (x <= -2.6e+20) tmp = x; else tmp = y + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.7e+137], N[(x + y), $MachinePrecision], If[LessEqual[x, -3.6e+62], N[(y + z), $MachinePrecision], If[LessEqual[x, -2.6e+20], x, N[(y + z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{+137}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;x \leq -3.6 \cdot 10^{+62}:\\
\;\;\;\;y + z\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{+20}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if x < -1.69999999999999993e137Initial program 100.0%
Taylor expanded in z around 0 77.5%
if -1.69999999999999993e137 < x < -3.6e62 or -2.6e20 < x Initial program 100.0%
Taylor expanded in x around 0 72.2%
if -3.6e62 < x < -2.6e20Initial program 100.0%
Taylor expanded in x around inf 51.6%
Final simplification72.2%
(FPCore (x y z) :precision binary64 (if (<= x -8.2e+136) x (if (<= x -2.2e+61) z (if (<= x -2.6e+20) x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.2e+136) {
tmp = x;
} else if (x <= -2.2e+61) {
tmp = z;
} else if (x <= -2.6e+20) {
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 (x <= (-8.2d+136)) then
tmp = x
else if (x <= (-2.2d+61)) then
tmp = z
else if (x <= (-2.6d+20)) 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 (x <= -8.2e+136) {
tmp = x;
} else if (x <= -2.2e+61) {
tmp = z;
} else if (x <= -2.6e+20) {
tmp = x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.2e+136: tmp = x elif x <= -2.2e+61: tmp = z elif x <= -2.6e+20: tmp = x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.2e+136) tmp = x; elseif (x <= -2.2e+61) tmp = z; elseif (x <= -2.6e+20) tmp = x; else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -8.2e+136) tmp = x; elseif (x <= -2.2e+61) tmp = z; elseif (x <= -2.6e+20) tmp = x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.2e+136], x, If[LessEqual[x, -2.2e+61], z, If[LessEqual[x, -2.6e+20], x, z]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{+136}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{+61}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{+20}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -8.1999999999999995e136 or -2.2e61 < x < -2.6e20Initial program 100.0%
Taylor expanded in x around inf 65.5%
if -8.1999999999999995e136 < x < -2.2e61 or -2.6e20 < x Initial program 100.0%
Taylor expanded in z around inf 38.1%
Final simplification43.6%
(FPCore (x y z) :precision binary64 (if (<= x -1.55e+19) (+ x y) z))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.55e+19) {
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 (x <= (-1.55d+19)) 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 (x <= -1.55e+19) {
tmp = x + y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.55e+19: tmp = x + y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.55e+19) tmp = Float64(x + y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.55e+19) tmp = x + y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.55e+19], N[(x + y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{+19}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.55e19Initial program 100.0%
Taylor expanded in z around 0 74.3%
if -1.55e19 < x Initial program 100.0%
Taylor expanded in z around inf 37.9%
Final simplification47.3%
(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 70.0%
Final simplification70.0%
(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 36.7%
Final simplification36.7%
herbie shell --seed 2023224
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, I"
:precision binary64
(+ (+ x y) z))