
(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 3 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 y) 0.5 (* z -0.125)))
double code(double x, double y, double z) {
return fma((x * y), 0.5, (z * -0.125));
}
function code(x, y, z) return fma(Float64(x * y), 0.5, Float64(z * -0.125)) end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] * 0.5 + N[(z * -0.125), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y, 0.5, z \cdot -0.125\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* 0.5 (* x y)))) (if (<= (* x y) -1.5e-41) t_0 (if (<= (* x y) 5e-115) (* z -0.125) t_0))))
double code(double x, double y, double z) {
double t_0 = 0.5 * (x * y);
double tmp;
if ((x * y) <= -1.5e-41) {
tmp = t_0;
} else if ((x * y) <= 5e-115) {
tmp = z * -0.125;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * (x * y)
if ((x * y) <= (-1.5d-41)) then
tmp = t_0
else if ((x * y) <= 5d-115) then
tmp = z * (-0.125d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 0.5 * (x * y);
double tmp;
if ((x * y) <= -1.5e-41) {
tmp = t_0;
} else if ((x * y) <= 5e-115) {
tmp = z * -0.125;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 0.5 * (x * y) tmp = 0 if (x * y) <= -1.5e-41: tmp = t_0 elif (x * y) <= 5e-115: tmp = z * -0.125 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(0.5 * Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -1.5e-41) tmp = t_0; elseif (Float64(x * y) <= 5e-115) tmp = Float64(z * -0.125); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 0.5 * (x * y); tmp = 0.0; if ((x * y) <= -1.5e-41) tmp = t_0; elseif ((x * y) <= 5e-115) tmp = z * -0.125; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(0.5 * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1.5e-41], t$95$0, If[LessEqual[N[(x * y), $MachinePrecision], 5e-115], N[(z * -0.125), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -1.5 \cdot 10^{-41}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-115}:\\
\;\;\;\;z \cdot -0.125\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x y) < -1.49999999999999994e-41 or 5.0000000000000003e-115 < (*.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6426.1
Applied rewrites26.1%
Taylor expanded in x around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6476.2
Applied rewrites76.2%
if -1.49999999999999994e-41 < (*.f64 x y) < 5.0000000000000003e-115Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6485.7
Applied rewrites85.7%
Final simplification80.2%
(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
lower-*.f6451.2
Applied rewrites51.2%
Final simplification51.2%
herbie shell --seed 2024298
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))