
(FPCore (x y z) :precision binary64 (- (/ (* x y) 2.0) (/ z 8.0)))
double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
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) / 2.0d0) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
def code(x, y, z): return ((x * y) / 2.0) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(x * y) / 2.0) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((x * y) / 2.0) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{2} - \frac{z}{8}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (/ (* x y) 2.0) (/ z 8.0)))
double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
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) / 2.0d0) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((x * y) / 2.0) - (z / 8.0);
}
def code(x, y, z): return ((x * y) / 2.0) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(x * y) / 2.0) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((x * y) / 2.0) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{2} - \frac{z}{8}
\end{array}
(FPCore (x y z) :precision binary64 (fma (/ y 2.0) x (* -0.125 z)))
double code(double x, double y, double z) {
return fma((y / 2.0), x, (-0.125 * z));
}
function code(x, y, z) return fma(Float64(y / 2.0), x, Float64(-0.125 * z)) end
code[x_, y_, z_] := N[(N[(y / 2.0), $MachinePrecision] * x + N[(-0.125 * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{2}, x, -0.125 \cdot z\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l/100.0%
fma-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
associate-/l*99.8%
associate-/r/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -7.2e+87)
(and (not (<= x -2e+37)) (or (<= x -8.8e-5) (not (<= x 4.4e-32)))))
(* y (/ x 2.0))
(* -0.125 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e+87) || (!(x <= -2e+37) && ((x <= -8.8e-5) || !(x <= 4.4e-32)))) {
tmp = y * (x / 2.0);
} else {
tmp = -0.125 * 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 <= (-7.2d+87)) .or. (.not. (x <= (-2d+37))) .and. (x <= (-8.8d-5)) .or. (.not. (x <= 4.4d-32))) then
tmp = y * (x / 2.0d0)
else
tmp = (-0.125d0) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e+87) || (!(x <= -2e+37) && ((x <= -8.8e-5) || !(x <= 4.4e-32)))) {
tmp = y * (x / 2.0);
} else {
tmp = -0.125 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e+87) or (not (x <= -2e+37) and ((x <= -8.8e-5) or not (x <= 4.4e-32))): tmp = y * (x / 2.0) else: tmp = -0.125 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e+87) || (!(x <= -2e+37) && ((x <= -8.8e-5) || !(x <= 4.4e-32)))) tmp = Float64(y * Float64(x / 2.0)); else tmp = Float64(-0.125 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.2e+87) || (~((x <= -2e+37)) && ((x <= -8.8e-5) || ~((x <= 4.4e-32))))) tmp = y * (x / 2.0); else tmp = -0.125 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e+87], And[N[Not[LessEqual[x, -2e+37]], $MachinePrecision], Or[LessEqual[x, -8.8e-5], N[Not[LessEqual[x, 4.4e-32]], $MachinePrecision]]]], N[(y * N[(x / 2.0), $MachinePrecision]), $MachinePrecision], N[(-0.125 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+87} \lor \neg \left(x \leq -2 \cdot 10^{+37}\right) \land \left(x \leq -8.8 \cdot 10^{-5} \lor \neg \left(x \leq 4.4 \cdot 10^{-32}\right)\right):\\
\;\;\;\;y \cdot \frac{x}{2}\\
\mathbf{else}:\\
\;\;\;\;-0.125 \cdot z\\
\end{array}
\end{array}
if x < -7.19999999999999988e87 or -1.99999999999999991e37 < x < -8.7999999999999998e-5 or 4.4e-32 < x Initial program 100.0%
associate-/l*99.8%
frac-sub83.7%
Applied egg-rr83.7%
*-commutative83.7%
associate-*l/83.7%
metadata-eval83.7%
Simplified83.7%
Taylor expanded in x around inf 70.2%
associate-*r*70.2%
metadata-eval70.2%
associate-/r/70.1%
*-commutative70.1%
associate-*r/69.1%
associate-/r/69.4%
*-commutative69.4%
associate-/l*70.2%
metadata-eval70.2%
Simplified70.2%
if -7.19999999999999988e87 < x < -1.99999999999999991e37 or -8.7999999999999998e-5 < x < 4.4e-32Initial program 100.0%
Taylor expanded in x around 0 69.1%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (- (/ (* y x) 2.0) (/ z 8.0)))
double code(double x, double y, double z) {
return ((y * x) / 2.0) - (z / 8.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y * x) / 2.0d0) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((y * x) / 2.0) - (z / 8.0);
}
def code(x, y, z): return ((y * x) / 2.0) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(y * x) / 2.0) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((y * x) / 2.0) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(y * x), $MachinePrecision] / 2.0), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y \cdot x}{2} - \frac{z}{8}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (* -0.125 z))
double code(double x, double y, double z) {
return -0.125 * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (-0.125d0) * z
end function
public static double code(double x, double y, double z) {
return -0.125 * z;
}
def code(x, y, z): return -0.125 * z
function code(x, y, z) return Float64(-0.125 * z) end
function tmp = code(x, y, z) tmp = -0.125 * z; end
code[x_, y_, z_] := N[(-0.125 * z), $MachinePrecision]
\begin{array}{l}
\\
-0.125 \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 51.7%
Final simplification51.7%
herbie shell --seed 2023274
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))