
(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 5 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 (if (<= y -180000000.0) (fma y x z) (if (<= y 0.0003) (fma x 0.5 z) (fma y x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -180000000.0) {
tmp = fma(y, x, z);
} else if (y <= 0.0003) {
tmp = fma(x, 0.5, z);
} else {
tmp = fma(y, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -180000000.0) tmp = fma(y, x, z); elseif (y <= 0.0003) tmp = fma(x, 0.5, z); else tmp = fma(y, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -180000000.0], N[(y * x + z), $MachinePrecision], If[LessEqual[y, 0.0003], N[(x * 0.5 + z), $MachinePrecision], N[(y * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -180000000:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;y \leq 0.0003:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\end{array}
\end{array}
if y < -1.8e8 or 2.99999999999999974e-4 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.3
Applied rewrites99.3%
*-commutativeN/A
lower-fma.f6499.4
Applied rewrites99.4%
if -1.8e8 < y < 2.99999999999999974e-4Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (if (<= y -3.05e+88) (* y x) (if (<= y 4e+103) (fma x 0.5 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.05e+88) {
tmp = y * x;
} else if (y <= 4e+103) {
tmp = fma(x, 0.5, z);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -3.05e+88) tmp = Float64(y * x); elseif (y <= 4e+103) tmp = fma(x, 0.5, z); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -3.05e+88], N[(y * x), $MachinePrecision], If[LessEqual[y, 4e+103], N[(x * 0.5 + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.05 \cdot 10^{+88}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.0499999999999999e88 or 4e103 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6475.1
Applied rewrites75.1%
if -3.0499999999999999e88 < y < 4e103Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.2
Applied rewrites90.2%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (<= y -9e-9) (* y x) (if (<= y 0.5) (* 0.5 x) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e-9) {
tmp = y * x;
} else if (y <= 0.5) {
tmp = 0.5 * x;
} 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 <= (-9d-9)) then
tmp = y * x
else if (y <= 0.5d0) then
tmp = 0.5d0 * x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9e-9) {
tmp = y * x;
} else if (y <= 0.5) {
tmp = 0.5 * x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9e-9: tmp = y * x elif y <= 0.5: tmp = 0.5 * x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9e-9) tmp = Float64(y * x); elseif (y <= 0.5) tmp = Float64(0.5 * x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9e-9) tmp = y * x; elseif (y <= 0.5) tmp = 0.5 * x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9e-9], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.5], N[(0.5 * x), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-9}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.99999999999999953e-9 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6463.4
Applied rewrites63.4%
if -8.99999999999999953e-9 < y < 0.5Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6449.7
Applied rewrites49.7%
Taylor expanded in y around 0
Applied rewrites49.5%
Final simplification56.5%
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
return 0.5 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
return 0.5 * x;
}
def code(x, y, z): return 0.5 * x
function code(x, y, z) return Float64(0.5 * x) end
function tmp = code(x, y, z) tmp = 0.5 * x; end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6456.9
Applied rewrites56.9%
Taylor expanded in y around 0
Applied rewrites26.1%
Final simplification26.1%
herbie shell --seed 2024214
(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))