
(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 6 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 0.5) x z))
double code(double x, double y, double z) {
return fma((y + 0.5), x, z);
}
function code(x, y, z) return fma(Float64(y + 0.5), x, z) end
code[x_, y_, z_] := N[(N[(y + 0.5), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + 0.5, x, z\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ z (* y x)))) (if (<= y -1.2) t_0 (if (<= y 0.14) (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 <= -1.2) {
tmp = t_0;
} else if (y <= 0.14) {
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 <= -1.2) tmp = t_0; elseif (y <= 0.14) 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, -1.2], t$95$0, If[LessEqual[y, 0.14], 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 -1.2:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.14:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.19999999999999996 or 0.14000000000000001 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.1
Applied rewrites99.1%
if -1.19999999999999996 < y < 0.14000000000000001Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.8
Applied rewrites98.8%
Final simplification98.9%
herbie shell --seed 2024227
(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))