
(FPCore (x y z) :precision binary64 (- (+ (+ x y) z) (+ x (+ y z))))
double code(double x, double y, double z) {
return ((x + y) + z) - (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) - (x + (y + z))
end function
public static double code(double x, double y, double z) {
return ((x + y) + z) - (x + (y + z));
}
def code(x, y, z): return ((x + y) + z) - (x + (y + z))
function code(x, y, z) return Float64(Float64(Float64(x + y) + z) - Float64(x + Float64(y + z))) end
function tmp = code(x, y, z) tmp = ((x + y) + z) - (x + (y + z)); end
code[x_, y_, z_] := N[(N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision] - N[(x + N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x + y\right) + z\right) - \left(x + \left(y + z\right)\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 1 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (+ (+ x y) z) (+ x (+ y z))))
double code(double x, double y, double z) {
return ((x + y) + z) - (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) - (x + (y + z))
end function
public static double code(double x, double y, double z) {
return ((x + y) + z) - (x + (y + z));
}
def code(x, y, z): return ((x + y) + z) - (x + (y + z))
function code(x, y, z) return Float64(Float64(Float64(x + y) + z) - Float64(x + Float64(y + z))) end
function tmp = code(x, y, z) tmp = ((x + y) + z) - (x + (y + z)); end
code[x_, y_, z_] := N[(N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision] - N[(x + N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x + y\right) + z\right) - \left(x + \left(y + z\right)\right)
\end{array}
y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) (FPCore (y_s x y_m z) :precision binary64 (* y_s (- (+ (+ x y_m) z) (+ x (+ y_m z)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
return y_s * (((x + y_m) + z) - (x + (y_m + z)));
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
code = y_s * (((x + y_m) + z) - (x + (y_m + z)))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
return y_s * (((x + y_m) + z) - (x + (y_m + z)));
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z): return y_s * (((x + y_m) + z) - (x + (y_m + z)))
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) return Float64(y_s * Float64(Float64(Float64(x + y_m) + z) - Float64(x + Float64(y_m + z)))) end
y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp = code(y_s, x, y_m, z) tmp = y_s * (((x + y_m) + z) - (x + (y_m + z))); end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * N[(N[(N[(x + y$95$m), $MachinePrecision] + z), $MachinePrecision] - N[(x + N[(y$95$m + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \left(\left(\left(x + y\_m\right) + z\right) - \left(x + \left(y\_m + z\right)\right)\right)
\end{array}
Initial program 99.6%
herbie shell --seed 2024155 -o setup:simplify
(FPCore (x y z)
:name "Commute and associate"
:precision binary64
(- (+ (+ x y) z) (+ x (+ y z))))