
(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 5 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 (/ z -8.0)))
double code(double x, double y, double z) {
return fma((y / 2.0), x, (z / -8.0));
}
function code(x, y, z) return fma(Float64(y / 2.0), x, Float64(z / -8.0)) end
code[x_, y_, z_] := N[(N[(y / 2.0), $MachinePrecision] * x + N[(z / -8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{2}, x, \frac{z}{-8}\right)
\end{array}
Initial program 99.7%
associate-/l*N/A
*-commutativeN/A
fmm-defN/A
fma-lowering-fma.f64N/A
/-lowering-/.f64N/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
metadata-eval100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= (* y x) -2e+115) (* (* y x) 0.5) (if (<= (* y x) 5e-8) (* z -0.125) (* (/ y 2.0) x))))
double code(double x, double y, double z) {
double tmp;
if ((y * x) <= -2e+115) {
tmp = (y * x) * 0.5;
} else if ((y * x) <= 5e-8) {
tmp = z * -0.125;
} else {
tmp = (y / 2.0) * x;
}
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) <= (-2d+115)) then
tmp = (y * x) * 0.5d0
else if ((y * x) <= 5d-8) then
tmp = z * (-0.125d0)
else
tmp = (y / 2.0d0) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * x) <= -2e+115) {
tmp = (y * x) * 0.5;
} else if ((y * x) <= 5e-8) {
tmp = z * -0.125;
} else {
tmp = (y / 2.0) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * x) <= -2e+115: tmp = (y * x) * 0.5 elif (y * x) <= 5e-8: tmp = z * -0.125 else: tmp = (y / 2.0) * x return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * x) <= -2e+115) tmp = Float64(Float64(y * x) * 0.5); elseif (Float64(y * x) <= 5e-8) tmp = Float64(z * -0.125); else tmp = Float64(Float64(y / 2.0) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * x) <= -2e+115) tmp = (y * x) * 0.5; elseif ((y * x) <= 5e-8) tmp = z * -0.125; else tmp = (y / 2.0) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * x), $MachinePrecision], -2e+115], N[(N[(y * x), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[N[(y * x), $MachinePrecision], 5e-8], N[(z * -0.125), $MachinePrecision], N[(N[(y / 2.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -2 \cdot 10^{+115}:\\
\;\;\;\;\left(y \cdot x\right) \cdot 0.5\\
\mathbf{elif}\;y \cdot x \leq 5 \cdot 10^{-8}:\\
\;\;\;\;z \cdot -0.125\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{2} \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -2e115Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6493.6%
Simplified93.6%
if -2e115 < (*.f64 x y) < 4.9999999999999998e-8Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6477.6%
Simplified77.6%
if 4.9999999999999998e-8 < (*.f64 x y) Initial program 98.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6475.3%
Simplified75.3%
*-commutativeN/A
metadata-evalN/A
div-invN/A
*-commutativeN/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f6476.0%
Applied egg-rr76.0%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* y x) 0.5))) (if (<= (* y x) -5e+112) t_0 (if (<= (* y x) 5e-8) (* z -0.125) t_0))))
double code(double x, double y, double z) {
double t_0 = (y * x) * 0.5;
double tmp;
if ((y * x) <= -5e+112) {
tmp = t_0;
} else if ((y * x) <= 5e-8) {
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 = (y * x) * 0.5d0
if ((y * x) <= (-5d+112)) then
tmp = t_0
else if ((y * x) <= 5d-8) 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 = (y * x) * 0.5;
double tmp;
if ((y * x) <= -5e+112) {
tmp = t_0;
} else if ((y * x) <= 5e-8) {
tmp = z * -0.125;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y * x) * 0.5 tmp = 0 if (y * x) <= -5e+112: tmp = t_0 elif (y * x) <= 5e-8: tmp = z * -0.125 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y * x) * 0.5) tmp = 0.0 if (Float64(y * x) <= -5e+112) tmp = t_0; elseif (Float64(y * x) <= 5e-8) tmp = Float64(z * -0.125); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * x) * 0.5; tmp = 0.0; if ((y * x) <= -5e+112) tmp = t_0; elseif ((y * x) <= 5e-8) tmp = z * -0.125; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[N[(y * x), $MachinePrecision], -5e+112], t$95$0, If[LessEqual[N[(y * x), $MachinePrecision], 5e-8], N[(z * -0.125), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot x\right) \cdot 0.5\\
\mathbf{if}\;y \cdot x \leq -5 \cdot 10^{+112}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot x \leq 5 \cdot 10^{-8}:\\
\;\;\;\;z \cdot -0.125\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x y) < -5e112 or 4.9999999999999998e-8 < (*.f64 x y) Initial program 99.2%
Taylor expanded in x around inf
*-lowering-*.f64N/A
*-lowering-*.f6480.5%
Simplified80.5%
if -5e112 < (*.f64 x y) < 4.9999999999999998e-8Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6477.6%
Simplified77.6%
Final simplification78.8%
(FPCore (x y z) :precision binary64 (- (* (/ y 2.0) x) (/ z 8.0)))
double code(double x, double y, double z) {
return ((y / 2.0) * x) - (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 / 2.0d0) * x) - (z / 8.0d0)
end function
public static double code(double x, double y, double z) {
return ((y / 2.0) * x) - (z / 8.0);
}
def code(x, y, z): return ((y / 2.0) * x) - (z / 8.0)
function code(x, y, z) return Float64(Float64(Float64(y / 2.0) * x) - Float64(z / 8.0)) end
function tmp = code(x, y, z) tmp = ((y / 2.0) * x) - (z / 8.0); end
code[x_, y_, z_] := N[(N[(N[(y / 2.0), $MachinePrecision] * x), $MachinePrecision] - N[(z / 8.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{2} \cdot x - \frac{z}{8}
\end{array}
Initial program 99.7%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64100.0%
Applied egg-rr100.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.7%
Taylor expanded in x around 0
*-lowering-*.f6453.5%
Simplified53.5%
Final simplification53.5%
herbie shell --seed 2024161
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))