
(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 (* y 0.5) x (* z -0.125)))
double code(double x, double y, double z) {
return fma((y * 0.5), x, (z * -0.125));
}
function code(x, y, z) return fma(Float64(y * 0.5), x, Float64(z * -0.125)) end
code[x_, y_, z_] := N[(N[(y * 0.5), $MachinePrecision] * x + N[(z * -0.125), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y \cdot 0.5, x, z \cdot -0.125\right)
\end{array}
Initial program 100.0%
sub-negN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
div-invN/A
*-lowering-*.f64N/A
metadata-evalN/A
distribute-neg-frac2N/A
div-invN/A
*-lowering-*.f64N/A
metadata-evalN/A
metadata-eval100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (* y 0.5)))) (if (<= y -1.15e-32) t_0 (if (<= y 4.9e+51) (* z -0.125) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y * 0.5);
double tmp;
if (y <= -1.15e-32) {
tmp = t_0;
} else if (y <= 4.9e+51) {
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 = x * (y * 0.5d0)
if (y <= (-1.15d-32)) then
tmp = t_0
else if (y <= 4.9d+51) 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 = x * (y * 0.5);
double tmp;
if (y <= -1.15e-32) {
tmp = t_0;
} else if (y <= 4.9e+51) {
tmp = z * -0.125;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y * 0.5) tmp = 0 if y <= -1.15e-32: tmp = t_0 elif y <= 4.9e+51: tmp = z * -0.125 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y * 0.5)) tmp = 0.0 if (y <= -1.15e-32) tmp = t_0; elseif (y <= 4.9e+51) tmp = Float64(z * -0.125); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y * 0.5); tmp = 0.0; if (y <= -1.15e-32) tmp = t_0; elseif (y <= 4.9e+51) tmp = z * -0.125; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.15e-32], t$95$0, If[LessEqual[y, 4.9e+51], N[(z * -0.125), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y \cdot 0.5\right)\\
\mathbf{if}\;y \leq -1.15 \cdot 10^{-32}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{+51}:\\
\;\;\;\;z \cdot -0.125\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.15e-32 or 4.89999999999999983e51 < y Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
remove-double-negN/A
+-rgt-identityN/A
distribute-neg-inN/A
remove-double-negN/A
metadata-evalN/A
accelerator-lowering-fma.f6468.6%
Simplified68.6%
+-rgt-identityN/A
+-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6468.6%
Applied egg-rr68.6%
if -1.15e-32 < y < 4.89999999999999983e51Initial program 100.0%
Taylor expanded in x around 0
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6471.7%
Simplified71.7%
+-rgt-identityN/A
*-lowering-*.f6471.7%
Applied egg-rr71.7%
Final simplification70.1%
(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
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6450.9%
Simplified50.9%
+-rgt-identityN/A
*-lowering-*.f6450.9%
Applied egg-rr50.9%
herbie shell --seed 2024193
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, D"
:precision binary64
(- (/ (* x y) 2.0) (/ z 8.0)))