
(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.9%
associate-/r/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= (* y x) -4.7e+33)
(and (not (<= (* y x) 1.6e-107))
(or (<= (* y x) 1.65e-101) (not (<= (* y x) 7.2e+23)))))
(* (* y x) 0.5)
(* -0.125 z)))
double code(double x, double y, double z) {
double tmp;
if (((y * x) <= -4.7e+33) || (!((y * x) <= 1.6e-107) && (((y * x) <= 1.65e-101) || !((y * x) <= 7.2e+23)))) {
tmp = (y * x) * 0.5;
} 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 (((y * x) <= (-4.7d+33)) .or. (.not. ((y * x) <= 1.6d-107)) .and. ((y * x) <= 1.65d-101) .or. (.not. ((y * x) <= 7.2d+23))) then
tmp = (y * x) * 0.5d0
else
tmp = (-0.125d0) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * x) <= -4.7e+33) || (!((y * x) <= 1.6e-107) && (((y * x) <= 1.65e-101) || !((y * x) <= 7.2e+23)))) {
tmp = (y * x) * 0.5;
} else {
tmp = -0.125 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * x) <= -4.7e+33) or (not ((y * x) <= 1.6e-107) and (((y * x) <= 1.65e-101) or not ((y * x) <= 7.2e+23))): tmp = (y * x) * 0.5 else: tmp = -0.125 * z return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * x) <= -4.7e+33) || (!(Float64(y * x) <= 1.6e-107) && ((Float64(y * x) <= 1.65e-101) || !(Float64(y * x) <= 7.2e+23)))) tmp = Float64(Float64(y * x) * 0.5); else tmp = Float64(-0.125 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * x) <= -4.7e+33) || (~(((y * x) <= 1.6e-107)) && (((y * x) <= 1.65e-101) || ~(((y * x) <= 7.2e+23))))) tmp = (y * x) * 0.5; else tmp = -0.125 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * x), $MachinePrecision], -4.7e+33], And[N[Not[LessEqual[N[(y * x), $MachinePrecision], 1.6e-107]], $MachinePrecision], Or[LessEqual[N[(y * x), $MachinePrecision], 1.65e-101], N[Not[LessEqual[N[(y * x), $MachinePrecision], 7.2e+23]], $MachinePrecision]]]], N[(N[(y * x), $MachinePrecision] * 0.5), $MachinePrecision], N[(-0.125 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -4.7 \cdot 10^{+33} \lor \neg \left(y \cdot x \leq 1.6 \cdot 10^{-107}\right) \land \left(y \cdot x \leq 1.65 \cdot 10^{-101} \lor \neg \left(y \cdot x \leq 7.2 \cdot 10^{+23}\right)\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;-0.125 \cdot z\\
\end{array}
\end{array}
if (*.f64 x y) < -4.6999999999999998e33 or 1.60000000000000006e-107 < (*.f64 x y) < 1.64999999999999992e-101 or 7.1999999999999997e23 < (*.f64 x y) Initial program 100.0%
Taylor expanded in x around inf 83.2%
if -4.6999999999999998e33 < (*.f64 x y) < 1.60000000000000006e-107 or 1.64999999999999992e-101 < (*.f64 x y) < 7.1999999999999997e23Initial program 100.0%
Taylor expanded in x around 0 82.0%
Final simplification82.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 53.4%
Final simplification53.4%
herbie shell --seed 2023290
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))