
(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}
(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 (<= (+ (+ x y) z) -5e-168) (+ x y) (+ y z)))
double code(double x, double y, double z) {
double tmp;
if (((x + y) + z) <= -5e-168) {
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 (((x + y) + z) <= (-5d-168)) 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 (((x + y) + z) <= -5e-168) {
tmp = x + y;
} else {
tmp = y + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x + y) + z) <= -5e-168: tmp = x + y else: tmp = y + z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x + y) + z) <= -5e-168) tmp = Float64(x + y); else tmp = Float64(y + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x + y) + z) <= -5e-168) tmp = x + y; else tmp = y + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision], -5e-168], N[(x + y), $MachinePrecision], N[(y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) + z \leq -5 \cdot 10^{-168}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if (+.f64 (+.f64 x y) z) < -5.00000000000000001e-168Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6467.1
Applied rewrites67.1%
if -5.00000000000000001e-168 < (+.f64 (+.f64 x y) z) Initial program 100.0%
Taylor expanded in x around 0
lower-+.f6468.6
Applied rewrites68.6%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -5e-168) (+ x z) (+ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -5e-168) {
tmp = x + z;
} 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 + y) <= (-5d-168)) then
tmp = x + z
else
tmp = y + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -5e-168) {
tmp = x + z;
} else {
tmp = y + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -5e-168: tmp = x + z else: tmp = y + z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -5e-168) tmp = Float64(x + z); else tmp = Float64(y + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -5e-168) tmp = x + z; else tmp = y + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -5e-168], N[(x + z), $MachinePrecision], N[(y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -5 \cdot 10^{-168}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if (+.f64 x y) < -5.00000000000000001e-168Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6466.0
Applied rewrites66.0%
if -5.00000000000000001e-168 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
lower-+.f6469.9
Applied rewrites69.9%
Final simplification68.2%
(FPCore (x y z) :precision binary64 (+ x y))
double code(double x, double y, double z) {
return 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 = x + y
end function
public static double code(double x, double y, double z) {
return x + y;
}
def code(x, y, z): return x + y
function code(x, y, z) return Float64(x + y) end
function tmp = code(x, y, z) tmp = x + y; end
code[x_, y_, z_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
\\
x + y
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6465.4
Applied rewrites65.4%
Final simplification65.4%
herbie shell --seed 2024219
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, I"
:precision binary64
(+ (+ x y) z))