
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
(FPCore (x y z) :precision binary64 (fma y x (fma x 0.5 z)))
double code(double x, double y, double z) {
return fma(y, x, fma(x, 0.5, z));
}
function code(x, y, z) return fma(y, x, fma(x, 0.5, z)) end
code[x_, y_, z_] := N[(y * x + N[(x * 0.5 + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(x, 0.5, z\right)\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ z (* y x)))) (if (<= y -0.5) t_0 (if (<= y 0.112) (fma x 0.5 z) t_0))))
double code(double x, double y, double z) {
double t_0 = z + (y * x);
double tmp;
if (y <= -0.5) {
tmp = t_0;
} else if (y <= 0.112) {
tmp = fma(x, 0.5, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z + Float64(y * x)) tmp = 0.0 if (y <= -0.5) tmp = t_0; elseif (y <= 0.112) tmp = fma(x, 0.5, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.5], t$95$0, If[LessEqual[y, 0.112], N[(x * 0.5 + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z + y \cdot x\\
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.112:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.5 or 0.112000000000000002 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.0
Applied rewrites99.0%
if -0.5 < y < 0.112000000000000002Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.1
Applied rewrites99.1%
Final simplification99.0%
herbie shell --seed 2024223
(FPCore (x y z)
:name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
:precision binary64
(+ (+ (/ x 2.0) (* y x)) z))