
(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 -0.5) t_0 (if (<= y 0.00095) (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.00095) {
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.00095) 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.00095], 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.00095:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.5 or 9.49999999999999998e-4 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.3
Applied rewrites99.3%
if -0.5 < y < 9.49999999999999998e-4Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.9
Applied rewrites98.9%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ y 0.5) x))) (if (<= y -0.014) t_0 (if (<= y 11800000000.0) (fma x 0.5 z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + 0.5) * x;
double tmp;
if (y <= -0.014) {
tmp = t_0;
} else if (y <= 11800000000.0) {
tmp = fma(x, 0.5, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(y + 0.5) * x) tmp = 0.0 if (y <= -0.014) tmp = t_0; elseif (y <= 11800000000.0) tmp = fma(x, 0.5, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + 0.5), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.014], t$95$0, If[LessEqual[y, 11800000000.0], N[(x * 0.5 + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + 0.5\right) \cdot x\\
\mathbf{if}\;y \leq -0.014:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 11800000000:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0140000000000000003 or 1.18e10 < y Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6477.7
Applied rewrites77.7%
if -0.0140000000000000003 < y < 1.18e10Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.8
Applied rewrites98.8%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (<= y -2300000000000.0) (* y x) (if (<= y 17500000000.0) (fma x 0.5 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2300000000000.0) {
tmp = y * x;
} else if (y <= 17500000000.0) {
tmp = fma(x, 0.5, z);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2300000000000.0) tmp = Float64(y * x); elseif (y <= 17500000000.0) tmp = fma(x, 0.5, z); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2300000000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 17500000000.0], N[(x * 0.5 + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2300000000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 17500000000:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.3e12 or 1.75e10 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6477.8
Applied rewrites77.8%
if -2.3e12 < y < 1.75e10Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.3
Applied rewrites98.3%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= y -0.5) (* y x) (if (<= y 0.00095) (* x 0.5) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = y * x;
} else if (y <= 0.00095) {
tmp = x * 0.5;
} else {
tmp = y * 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 <= (-0.5d0)) then
tmp = y * x
else if (y <= 0.00095d0) then
tmp = x * 0.5d0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = y * x;
} else if (y <= 0.00095) {
tmp = x * 0.5;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.5: tmp = y * x elif y <= 0.00095: tmp = x * 0.5 else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = Float64(y * x); elseif (y <= 0.00095) tmp = Float64(x * 0.5); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.5) tmp = y * x; elseif (y <= 0.00095) tmp = x * 0.5; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.00095], N[(x * 0.5), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.00095:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -0.5 or 9.49999999999999998e-4 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6475.7
Applied rewrites75.7%
if -0.5 < y < 9.49999999999999998e-4Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6445.5
Applied rewrites45.5%
Taylor expanded in y around 0
Applied rewrites44.9%
Final simplification60.7%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6440.2
Applied rewrites40.2%
Final simplification40.2%
herbie shell --seed 2024220
(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))