
(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 5 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 (<= (+ z (+ x y)) -4e-180) (+ x y) (+ y z)))
double code(double x, double y, double z) {
double tmp;
if ((z + (x + y)) <= -4e-180) {
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 + (x + y)) <= (-4d-180)) 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 + (x + y)) <= -4e-180) {
tmp = x + y;
} else {
tmp = y + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + (x + y)) <= -4e-180: tmp = x + y else: tmp = y + z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + Float64(x + y)) <= -4e-180) 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 + (x + y)) <= -4e-180) tmp = x + y; else tmp = y + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], -4e-180], N[(x + y), $MachinePrecision], N[(y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + \left(x + y\right) \leq -4 \cdot 10^{-180}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if (+.f64 (+.f64 x y) z) < -4.0000000000000001e-180Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6465.1
Simplified65.1%
if -4.0000000000000001e-180 < (+.f64 (+.f64 x y) z) Initial program 100.0%
Taylor expanded in x around 0
+-lowering-+.f6468.9
Simplified68.9%
Final simplification67.1%
(FPCore (x y z) :precision binary64 (if (<= (+ z (+ x y)) -4e-180) (+ x y) z))
double code(double x, double y, double z) {
double tmp;
if ((z + (x + y)) <= -4e-180) {
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 + (x + y)) <= (-4d-180)) 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 + (x + y)) <= -4e-180) {
tmp = x + y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + (x + y)) <= -4e-180: tmp = x + y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + Float64(x + y)) <= -4e-180) tmp = Float64(x + y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z + (x + y)) <= -4e-180) tmp = x + y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], -4e-180], N[(x + y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + \left(x + y\right) \leq -4 \cdot 10^{-180}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if (+.f64 (+.f64 x y) z) < -4.0000000000000001e-180Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6465.1
Simplified65.1%
if -4.0000000000000001e-180 < (+.f64 (+.f64 x y) z) Initial program 100.0%
Taylor expanded in z around inf
Simplified34.7%
Final simplification49.1%
(FPCore (x y z) :precision binary64 (if (<= (+ z (+ x y)) -4e-180) x z))
double code(double x, double y, double z) {
double tmp;
if ((z + (x + y)) <= -4e-180) {
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 + (x + y)) <= (-4d-180)) 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 + (x + y)) <= -4e-180) {
tmp = x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + (x + y)) <= -4e-180: tmp = x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + Float64(x + y)) <= -4e-180) tmp = x; else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z + (x + y)) <= -4e-180) tmp = x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], -4e-180], x, z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + \left(x + y\right) \leq -4 \cdot 10^{-180}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if (+.f64 (+.f64 x y) z) < -4.0000000000000001e-180Initial program 100.0%
Taylor expanded in x around inf
Simplified32.9%
if -4.0000000000000001e-180 < (+.f64 (+.f64 x y) z) Initial program 100.0%
Taylor expanded in z around inf
Simplified34.7%
Final simplification33.9%
(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
Simplified32.3%
herbie shell --seed 2024205
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, I"
:precision binary64
(+ (+ x y) z))