
(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 0.5 x z)))
double code(double x, double y, double z) {
return fma(y, x, fma(0.5, x, z));
}
function code(x, y, z) return fma(y, x, fma(0.5, x, z)) end
code[x_, y_, z_] := N[(y * x + N[(0.5 * x + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(0.5, x, 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
clear-numN/A
associate-/r/N/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (* x y) z))) (if (<= y -0.5) t_0 (if (<= y 8.5e-9) (fma x 0.5 z) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * y) + z;
double tmp;
if (y <= -0.5) {
tmp = t_0;
} else if (y <= 8.5e-9) {
tmp = fma(x, 0.5, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x * y) + z) tmp = 0.0 if (y <= -0.5) tmp = t_0; elseif (y <= 8.5e-9) tmp = fma(x, 0.5, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]}, If[LessEqual[y, -0.5], t$95$0, If[LessEqual[y, 8.5e-9], N[(x * 0.5 + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot y + z\\
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.5 or 8.5e-9 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
if -0.5 < y < 8.5e-9Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.95e+91) (* x y) (if (<= y 0.0048) (fma x 0.5 z) (* (- y -0.5) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+91) {
tmp = x * y;
} else if (y <= 0.0048) {
tmp = fma(x, 0.5, z);
} else {
tmp = (y - -0.5) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+91) tmp = Float64(x * y); elseif (y <= 0.0048) tmp = fma(x, 0.5, z); else tmp = Float64(Float64(y - -0.5) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+91], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.0048], N[(x * 0.5 + z), $MachinePrecision], N[(N[(y - -0.5), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+91}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.0048:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - -0.5\right) \cdot x\\
\end{array}
\end{array}
if y < -1.94999999999999984e91Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6485.1
Applied rewrites85.1%
if -1.94999999999999984e91 < y < 0.00479999999999999958Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6495.5
Applied rewrites95.5%
if 0.00479999999999999958 < y Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6470.6
Applied rewrites70.6%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.95e+91) (* x y) (if (<= y 215.0) (fma x 0.5 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+91) {
tmp = x * y;
} else if (y <= 215.0) {
tmp = fma(x, 0.5, z);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+91) tmp = Float64(x * y); elseif (y <= 215.0) tmp = fma(x, 0.5, z); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+91], N[(x * y), $MachinePrecision], If[LessEqual[y, 215.0], N[(x * 0.5 + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+91}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 215:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.94999999999999984e91 or 215 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6475.0
Applied rewrites75.0%
if -1.94999999999999984e91 < y < 215Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6495.5
Applied rewrites95.5%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (<= y -6.8e-6) (* x y) (if (<= y 1.15e-6) (* 0.5 x) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-6) {
tmp = x * y;
} else if (y <= 1.15e-6) {
tmp = 0.5 * x;
} else {
tmp = x * y;
}
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 <= (-6.8d-6)) then
tmp = x * y
else if (y <= 1.15d-6) then
tmp = 0.5d0 * x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-6) {
tmp = x * y;
} else if (y <= 1.15e-6) {
tmp = 0.5 * x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e-6: tmp = x * y elif y <= 1.15e-6: tmp = 0.5 * x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e-6) tmp = Float64(x * y); elseif (y <= 1.15e-6) tmp = Float64(0.5 * x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.8e-6) tmp = x * y; elseif (y <= 1.15e-6) tmp = 0.5 * x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e-6], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.15e-6], N[(0.5 * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-6}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-6}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -6.80000000000000012e-6 or 1.15e-6 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6467.4
Applied rewrites67.4%
if -6.80000000000000012e-6 < y < 1.15e-6Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6456.2
Applied rewrites56.2%
Taylor expanded in y around 0
Applied rewrites55.6%
Final simplification61.9%
(FPCore (x y z) :precision binary64 (fma (+ 0.5 y) x z))
double code(double x, double y, double z) {
return fma((0.5 + y), x, z);
}
function code(x, y, z) return fma(Float64(0.5 + y), x, z) end
code[x_, y_, z_] := N[(N[(0.5 + y), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 + y, 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
lower-+.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
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
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6437.3
Applied rewrites37.3%
Final simplification37.3%
herbie shell --seed 2024244
(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))