
(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 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 (if (<= y -1.4e+48) (* y x) (if (<= y 1e+15) (fma 0.5 x z) (* (- y -0.5) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e+48) {
tmp = y * x;
} else if (y <= 1e+15) {
tmp = fma(0.5, x, z);
} else {
tmp = (y - -0.5) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.4e+48) tmp = Float64(y * x); elseif (y <= 1e+15) tmp = fma(0.5, x, z); else tmp = Float64(Float64(y - -0.5) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.4e+48], N[(y * x), $MachinePrecision], If[LessEqual[y, 1e+15], N[(0.5 * x + z), $MachinePrecision], N[(N[(y - -0.5), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+48}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - -0.5\right) \cdot x\\
\end{array}
\end{array}
if y < -1.40000000000000006e48Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6420.0
Applied rewrites20.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6479.6
Applied rewrites79.6%
if -1.40000000000000006e48 < y < 1e15Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6495.9
Applied rewrites95.9%
if 1e15 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6435.0
Applied rewrites35.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6469.6
Applied rewrites69.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.4e+48) (not (<= y 1e+15))) (* y x) (fma 0.5 x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e+48) || !(y <= 1e+15)) {
tmp = y * x;
} else {
tmp = fma(0.5, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1.4e+48) || !(y <= 1e+15)) tmp = Float64(y * x); else tmp = fma(0.5, x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.4e+48], N[Not[LessEqual[y, 1e+15]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+48} \lor \neg \left(y \leq 10^{+15}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\end{array}
\end{array}
if y < -1.40000000000000006e48 or 1e15 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6428.5
Applied rewrites28.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6474.0
Applied rewrites74.0%
if -1.40000000000000006e48 < y < 1e15Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6495.9
Applied rewrites95.9%
Final simplification86.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -380.0) (not (<= y 1.1e-7))) (* y x) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -380.0) || !(y <= 1.1e-7)) {
tmp = y * x;
} else {
tmp = 0.5 * 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 <= (-380.0d0)) .or. (.not. (y <= 1.1d-7))) then
tmp = y * x
else
tmp = 0.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -380.0) || !(y <= 1.1e-7)) {
tmp = y * x;
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -380.0) or not (y <= 1.1e-7): tmp = y * x else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -380.0) || !(y <= 1.1e-7)) tmp = Float64(y * x); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -380.0) || ~((y <= 1.1e-7))) tmp = y * x; else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -380.0], N[Not[LessEqual[y, 1.1e-7]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -380 \lor \neg \left(y \leq 1.1 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -380 or 1.1000000000000001e-7 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6433.0
Applied rewrites33.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6468.4
Applied rewrites68.4%
if -380 < y < 1.1000000000000001e-7Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites44.1%
Final simplification56.4%
(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 (* 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 y around 0
+-commutativeN/A
lower-fma.f6466.1
Applied rewrites66.1%
Taylor expanded in x around inf
Applied rewrites23.6%
herbie shell --seed 2024324
(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))