
(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 (/ x 2.0) y (* -0.125 z)))
double code(double x, double y, double z) {
return fma((x / 2.0), y, (-0.125 * z));
}
function code(x, y, z) return fma(Float64(x / 2.0), y, Float64(-0.125 * z)) end
code[x_, y_, z_] := N[(N[(x / 2.0), $MachinePrecision] * y + N[(-0.125 * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{x}{2}, y, -0.125 \cdot z\right)
\end{array}
Initial program 99.7%
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 (<= z -1.45e+48)
(not
(or (<= z -3.7e-134) (and (not (<= z -4.2e-158)) (<= z 1.5e+99)))))
(* -0.125 z)
(* x (* y 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e+48) || !((z <= -3.7e-134) || (!(z <= -4.2e-158) && (z <= 1.5e+99)))) {
tmp = -0.125 * z;
} else {
tmp = x * (y * 0.5);
}
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 <= (-1.45d+48)) .or. (.not. (z <= (-3.7d-134)) .or. (.not. (z <= (-4.2d-158))) .and. (z <= 1.5d+99))) then
tmp = (-0.125d0) * z
else
tmp = x * (y * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e+48) || !((z <= -3.7e-134) || (!(z <= -4.2e-158) && (z <= 1.5e+99)))) {
tmp = -0.125 * z;
} else {
tmp = x * (y * 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.45e+48) or not ((z <= -3.7e-134) or (not (z <= -4.2e-158) and (z <= 1.5e+99))): tmp = -0.125 * z else: tmp = x * (y * 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.45e+48) || !((z <= -3.7e-134) || (!(z <= -4.2e-158) && (z <= 1.5e+99)))) tmp = Float64(-0.125 * z); else tmp = Float64(x * Float64(y * 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.45e+48) || ~(((z <= -3.7e-134) || (~((z <= -4.2e-158)) && (z <= 1.5e+99))))) tmp = -0.125 * z; else tmp = x * (y * 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.45e+48], N[Not[Or[LessEqual[z, -3.7e-134], And[N[Not[LessEqual[z, -4.2e-158]], $MachinePrecision], LessEqual[z, 1.5e+99]]]], $MachinePrecision]], N[(-0.125 * z), $MachinePrecision], N[(x * N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{+48} \lor \neg \left(z \leq -3.7 \cdot 10^{-134} \lor \neg \left(z \leq -4.2 \cdot 10^{-158}\right) \land z \leq 1.5 \cdot 10^{+99}\right):\\
\;\;\;\;-0.125 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot 0.5\right)\\
\end{array}
\end{array}
if z < -1.4499999999999999e48 or -3.7e-134 < z < -4.19999999999999983e-158 or 1.50000000000000007e99 < z Initial program 100.0%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 79.2%
if -1.4499999999999999e48 < z < -3.7e-134 or -4.19999999999999983e-158 < z < 1.50000000000000007e99Initial program 99.5%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around inf 75.9%
associate-*r*76.4%
*-commutative76.4%
associate-*r*76.4%
Simplified76.4%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (- (* (/ x 2.0) y) (/ z 8.0)))
double code(double x, double y, double z) {
return ((x / 2.0) * y) - (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 / 2.0d0) * y) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) * y) - (z / 8.0);
}
def code(x, y, z): return ((x / 2.0) * y) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) * y) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((x / 2.0) * y) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] * y), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{2} \cdot y - \frac{z}{8}
\end{array}
Initial program 99.7%
associate-*l/100.0%
Simplified100.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 99.7%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around 0 46.2%
Final simplification46.2%
herbie shell --seed 2023318
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))