
(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 (* 0.5 x) y (* -0.125 z)))
double code(double x, double y, double z) {
return fma((0.5 * x), y, (-0.125 * z));
}
function code(x, y, z) return fma(Float64(0.5 * x), y, Float64(-0.125 * z)) end
code[x_, y_, z_] := N[(N[(0.5 * x), $MachinePrecision] * y + N[(-0.125 * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 \cdot x, y, -0.125 \cdot z\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
fp-cancel-sub-sign-invN/A
associate-*r*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x y) 2.0)))
(if (or (<= t_0 -1e-20) (not (<= t_0 4e+17)))
(* 0.5 (* y x))
(* -0.125 z))))
double code(double x, double y, double z) {
double t_0 = (x * y) / 2.0;
double tmp;
if ((t_0 <= -1e-20) || !(t_0 <= 4e+17)) {
tmp = 0.5 * (y * x);
} 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) :: t_0
real(8) :: tmp
t_0 = (x * y) / 2.0d0
if ((t_0 <= (-1d-20)) .or. (.not. (t_0 <= 4d+17))) then
tmp = 0.5d0 * (y * x)
else
tmp = (-0.125d0) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * y) / 2.0;
double tmp;
if ((t_0 <= -1e-20) || !(t_0 <= 4e+17)) {
tmp = 0.5 * (y * x);
} else {
tmp = -0.125 * z;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) / 2.0 tmp = 0 if (t_0 <= -1e-20) or not (t_0 <= 4e+17): tmp = 0.5 * (y * x) else: tmp = -0.125 * z return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) / 2.0) tmp = 0.0 if ((t_0 <= -1e-20) || !(t_0 <= 4e+17)) tmp = Float64(0.5 * Float64(y * x)); else tmp = Float64(-0.125 * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) / 2.0; tmp = 0.0; if ((t_0 <= -1e-20) || ~((t_0 <= 4e+17))) tmp = 0.5 * (y * x); else tmp = -0.125 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e-20], N[Not[LessEqual[t$95$0, 4e+17]], $MachinePrecision]], N[(0.5 * N[(y * x), $MachinePrecision]), $MachinePrecision], N[(-0.125 * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot y}{2}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-20} \lor \neg \left(t\_0 \leq 4 \cdot 10^{+17}\right):\\
\;\;\;\;0.5 \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-0.125 \cdot z\\
\end{array}
\end{array}
if (/.f64 (*.f64 x y) #s(literal 2 binary64)) < -9.99999999999999945e-21 or 4e17 < (/.f64 (*.f64 x y) #s(literal 2 binary64)) Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6417.9
Applied rewrites17.9%
Taylor expanded in x around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6484.7
Applied rewrites84.7%
if -9.99999999999999945e-21 < (/.f64 (*.f64 x y) #s(literal 2 binary64)) < 4e17Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6483.0
Applied rewrites83.0%
Final simplification83.9%
(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
lower-*.f6449.4
Applied rewrites49.4%
herbie shell --seed 2024337
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))