
(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%
fmm-def100.0%
distribute-neg-frac2100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= (* y x) -1.65e-98)
(not
(or (<= (* y x) 2.6e-90)
(and (not (<= (* y x) 5e-7)) (<= (* y x) 7e+53)))))
(* (* y x) 0.5)
(* z -0.125)))
double code(double x, double y, double z) {
double tmp;
if (((y * x) <= -1.65e-98) || !(((y * x) <= 2.6e-90) || (!((y * x) <= 5e-7) && ((y * x) <= 7e+53)))) {
tmp = (y * x) * 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 * x) <= (-1.65d-98)) .or. (.not. ((y * x) <= 2.6d-90) .or. (.not. ((y * x) <= 5d-7)) .and. ((y * x) <= 7d+53))) then
tmp = (y * x) * 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 * x) <= -1.65e-98) || !(((y * x) <= 2.6e-90) || (!((y * x) <= 5e-7) && ((y * x) <= 7e+53)))) {
tmp = (y * x) * 0.5;
} else {
tmp = z * -0.125;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * x) <= -1.65e-98) or not (((y * x) <= 2.6e-90) or (not ((y * x) <= 5e-7) and ((y * x) <= 7e+53))): tmp = (y * x) * 0.5 else: tmp = z * -0.125 return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * x) <= -1.65e-98) || !((Float64(y * x) <= 2.6e-90) || (!(Float64(y * x) <= 5e-7) && (Float64(y * x) <= 7e+53)))) tmp = Float64(Float64(y * x) * 0.5); else tmp = Float64(z * -0.125); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * x) <= -1.65e-98) || ~((((y * x) <= 2.6e-90) || (~(((y * x) <= 5e-7)) && ((y * x) <= 7e+53))))) tmp = (y * x) * 0.5; else tmp = z * -0.125; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * x), $MachinePrecision], -1.65e-98], N[Not[Or[LessEqual[N[(y * x), $MachinePrecision], 2.6e-90], And[N[Not[LessEqual[N[(y * x), $MachinePrecision], 5e-7]], $MachinePrecision], LessEqual[N[(y * x), $MachinePrecision], 7e+53]]]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * 0.5), $MachinePrecision], N[(z * -0.125), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -1.65 \cdot 10^{-98} \lor \neg \left(y \cdot x \leq 2.6 \cdot 10^{-90} \lor \neg \left(y \cdot x \leq 5 \cdot 10^{-7}\right) \land y \cdot x \leq 7 \cdot 10^{+53}\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z \cdot -0.125\\
\end{array}
\end{array}
if (*.f64 x y) < -1.6500000000000001e-98 or 2.6e-90 < (*.f64 x y) < 4.99999999999999977e-7 or 7.00000000000000038e53 < (*.f64 x y) Initial program 100.0%
Taylor expanded in z around inf 84.8%
Taylor expanded in z around 0 86.0%
if -1.6500000000000001e-98 < (*.f64 x y) < 2.6e-90 or 4.99999999999999977e-7 < (*.f64 x y) < 7.00000000000000038e53Initial program 100.0%
Taylor expanded in x around 0 90.6%
Final simplification88.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 49.3%
Final simplification49.3%
herbie shell --seed 2024115
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))