
(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 99.4%
*-commutative99.4%
associate-/l*100.0%
fma-neg100.0%
distribute-neg-frac2100.0%
metadata-eval100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= z -1.16e+33)
(and (not (<= z -1.2e-104))
(or (<= z -1.4e-117)
(and (not (<= z -4.5e-197))
(or (<= z -2.5e-209)
(and (not (<= z -4.3e-232))
(or (<= z -1.52e-235)
(not (<= z 1.08e+38)))))))))
(* z -0.125)
(* x (* y 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.16e+33) || (!(z <= -1.2e-104) && ((z <= -1.4e-117) || (!(z <= -4.5e-197) && ((z <= -2.5e-209) || (!(z <= -4.3e-232) && ((z <= -1.52e-235) || !(z <= 1.08e+38)))))))) {
tmp = z * -0.125;
} 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.16d+33)) .or. (.not. (z <= (-1.2d-104))) .and. (z <= (-1.4d-117)) .or. (.not. (z <= (-4.5d-197))) .and. (z <= (-2.5d-209)) .or. (.not. (z <= (-4.3d-232))) .and. (z <= (-1.52d-235)) .or. (.not. (z <= 1.08d+38))) then
tmp = z * (-0.125d0)
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.16e+33) || (!(z <= -1.2e-104) && ((z <= -1.4e-117) || (!(z <= -4.5e-197) && ((z <= -2.5e-209) || (!(z <= -4.3e-232) && ((z <= -1.52e-235) || !(z <= 1.08e+38)))))))) {
tmp = z * -0.125;
} else {
tmp = x * (y * 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.16e+33) or (not (z <= -1.2e-104) and ((z <= -1.4e-117) or (not (z <= -4.5e-197) and ((z <= -2.5e-209) or (not (z <= -4.3e-232) and ((z <= -1.52e-235) or not (z <= 1.08e+38))))))): tmp = z * -0.125 else: tmp = x * (y * 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.16e+33) || (!(z <= -1.2e-104) && ((z <= -1.4e-117) || (!(z <= -4.5e-197) && ((z <= -2.5e-209) || (!(z <= -4.3e-232) && ((z <= -1.52e-235) || !(z <= 1.08e+38)))))))) tmp = Float64(z * -0.125); 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.16e+33) || (~((z <= -1.2e-104)) && ((z <= -1.4e-117) || (~((z <= -4.5e-197)) && ((z <= -2.5e-209) || (~((z <= -4.3e-232)) && ((z <= -1.52e-235) || ~((z <= 1.08e+38))))))))) tmp = z * -0.125; else tmp = x * (y * 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.16e+33], And[N[Not[LessEqual[z, -1.2e-104]], $MachinePrecision], Or[LessEqual[z, -1.4e-117], And[N[Not[LessEqual[z, -4.5e-197]], $MachinePrecision], Or[LessEqual[z, -2.5e-209], And[N[Not[LessEqual[z, -4.3e-232]], $MachinePrecision], Or[LessEqual[z, -1.52e-235], N[Not[LessEqual[z, 1.08e+38]], $MachinePrecision]]]]]]]], N[(z * -0.125), $MachinePrecision], N[(x * N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.16 \cdot 10^{+33} \lor \neg \left(z \leq -1.2 \cdot 10^{-104}\right) \land \left(z \leq -1.4 \cdot 10^{-117} \lor \neg \left(z \leq -4.5 \cdot 10^{-197}\right) \land \left(z \leq -2.5 \cdot 10^{-209} \lor \neg \left(z \leq -4.3 \cdot 10^{-232}\right) \land \left(z \leq -1.52 \cdot 10^{-235} \lor \neg \left(z \leq 1.08 \cdot 10^{+38}\right)\right)\right)\right):\\
\;\;\;\;z \cdot -0.125\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot 0.5\right)\\
\end{array}
\end{array}
if z < -1.16000000000000001e33 or -1.2e-104 < z < -1.4e-117 or -4.5000000000000001e-197 < z < -2.5000000000000002e-209 or -4.2999999999999997e-232 < z < -1.52e-235 or 1.07999999999999995e38 < z Initial program 100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 75.9%
if -1.16000000000000001e33 < z < -1.2e-104 or -1.4e-117 < z < -4.5000000000000001e-197 or -2.5000000000000002e-209 < z < -4.2999999999999997e-232 or -1.52e-235 < z < 1.07999999999999995e38Initial program 98.7%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around inf 74.7%
*-commutative74.7%
associate-*r*75.9%
*-commutative75.9%
Simplified75.9%
Final simplification75.9%
(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(x * Float64(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[(x * N[(y / 2.0), $MachinePrecision]), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{y}{2} - \frac{z}{8}
\end{array}
Initial program 99.4%
associate-/l*100.0%
Simplified100.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 99.4%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 51.9%
Final simplification51.9%
herbie shell --seed 2024107
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))