
(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 (/ x 2.0) (/ z -8.0)))
double code(double x, double y, double z) {
return fma(y, (x / 2.0), (z / -8.0));
}
function code(x, y, z) return fma(y, Float64(x / 2.0), Float64(z / -8.0)) end
code[x_, y_, z_] := N[(y * N[(x / 2.0), $MachinePrecision] + N[(z / -8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \frac{x}{2}, \frac{z}{-8}\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-/l*100.0%
fma-neg100.0%
distribute-neg-frac2100.0%
metadata-eval100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.9e-134)
(not (or (<= y 2.5e-34) (and (not (<= y 1.2e+26)) (<= y 3.3e+79)))))
(* x (* y 0.5))
(* z -0.125)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e-134) || !((y <= 2.5e-34) || (!(y <= 1.2e+26) && (y <= 3.3e+79)))) {
tmp = x * (y * 0.5);
} else {
tmp = z * -0.125;
}
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 ((y <= (-1.9d-134)) .or. (.not. (y <= 2.5d-34) .or. (.not. (y <= 1.2d+26)) .and. (y <= 3.3d+79))) then
tmp = x * (y * 0.5d0)
else
tmp = z * (-0.125d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e-134) || !((y <= 2.5e-34) || (!(y <= 1.2e+26) && (y <= 3.3e+79)))) {
tmp = x * (y * 0.5);
} else {
tmp = z * -0.125;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.9e-134) or not ((y <= 2.5e-34) or (not (y <= 1.2e+26) and (y <= 3.3e+79))): tmp = x * (y * 0.5) else: tmp = z * -0.125 return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.9e-134) || !((y <= 2.5e-34) || (!(y <= 1.2e+26) && (y <= 3.3e+79)))) tmp = Float64(x * Float64(y * 0.5)); else tmp = Float64(z * -0.125); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.9e-134) || ~(((y <= 2.5e-34) || (~((y <= 1.2e+26)) && (y <= 3.3e+79))))) tmp = x * (y * 0.5); else tmp = z * -0.125; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.9e-134], N[Not[Or[LessEqual[y, 2.5e-34], And[N[Not[LessEqual[y, 1.2e+26]], $MachinePrecision], LessEqual[y, 3.3e+79]]]], $MachinePrecision]], N[(x * N[(y * 0.5), $MachinePrecision]), $MachinePrecision], N[(z * -0.125), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-134} \lor \neg \left(y \leq 2.5 \cdot 10^{-34} \lor \neg \left(y \leq 1.2 \cdot 10^{+26}\right) \land y \leq 3.3 \cdot 10^{+79}\right):\\
\;\;\;\;x \cdot \left(y \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot -0.125\\
\end{array}
\end{array}
if y < -1.90000000000000001e-134 or 2.5000000000000001e-34 < y < 1.20000000000000002e26 or 3.3000000000000002e79 < y Initial program 100.0%
Taylor expanded in x around inf 66.1%
*-commutative66.1%
associate-*r*66.1%
*-commutative66.1%
Simplified66.1%
if -1.90000000000000001e-134 < y < 2.5000000000000001e-34 or 1.20000000000000002e26 < y < 3.3000000000000002e79Initial program 100.0%
Taylor expanded in x around 0 70.7%
Final simplification68.0%
(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 (* z -0.125))
double code(double x, double y, double z) {
return z * -0.125;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * (-0.125d0)
end function
public static double code(double x, double y, double z) {
return z * -0.125;
}
def code(x, y, z): return z * -0.125
function code(x, y, z) return Float64(z * -0.125) end
function tmp = code(x, y, z) tmp = z * -0.125; end
code[x_, y_, z_] := N[(z * -0.125), $MachinePrecision]
\begin{array}{l}
\\
z \cdot -0.125
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 50.2%
Final simplification50.2%
herbie shell --seed 2024091
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))