
(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 (+ 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
(let* ((t_0 (+ (/ x 2.0) (* y x))))
(if (or (<= t_0 -4e+137) (not (<= t_0 2e+179)))
(* (- y -0.5) x)
(fma 0.5 x z))))
double code(double x, double y, double z) {
double t_0 = (x / 2.0) + (y * x);
double tmp;
if ((t_0 <= -4e+137) || !(t_0 <= 2e+179)) {
tmp = (y - -0.5) * x;
} else {
tmp = fma(0.5, x, z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x / 2.0) + Float64(y * x)) tmp = 0.0 if ((t_0 <= -4e+137) || !(t_0 <= 2e+179)) tmp = Float64(Float64(y - -0.5) * x); else tmp = fma(0.5, x, z); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -4e+137], N[Not[LessEqual[t$95$0, 2e+179]], $MachinePrecision]], N[(N[(y - -0.5), $MachinePrecision] * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{2} + y \cdot x\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{+137} \lor \neg \left(t\_0 \leq 2 \cdot 10^{+179}\right):\\
\;\;\;\;\left(y - -0.5\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -4.0000000000000001e137 or 1.99999999999999996e179 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6435.1
Applied rewrites35.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6494.3
Applied rewrites94.3%
if -4.0000000000000001e137 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 1.99999999999999996e179Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6487.3
Applied rewrites87.3%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e+39) (not (<= y 2.5e+61))) (* y x) (fma 0.5 x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e+39) || !(y <= 2.5e+61)) {
tmp = y * x;
} else {
tmp = fma(0.5, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e+39) || !(y <= 2.5e+61)) tmp = Float64(y * x); else tmp = fma(0.5, x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e+39], N[Not[LessEqual[y, 2.5e+61]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+39} \lor \neg \left(y \leq 2.5 \cdot 10^{+61}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\end{array}
\end{array}
if y < -7.5000000000000005e39 or 2.50000000000000009e61 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6425.6
Applied rewrites25.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6476.3
Applied rewrites76.3%
if -7.5000000000000005e39 < y < 2.50000000000000009e61Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6498.1
Applied rewrites98.1%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.2e-22) (not (<= y 0.5))) (* y x) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-22) || !(y <= 0.5)) {
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 <= (-9.2d-22)) .or. (.not. (y <= 0.5d0))) 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 <= -9.2e-22) || !(y <= 0.5)) {
tmp = y * x;
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.2e-22) or not (y <= 0.5): tmp = y * x else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.2e-22) || !(y <= 0.5)) 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 <= -9.2e-22) || ~((y <= 0.5))) tmp = y * x; else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e-22], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{-22} \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -9.1999999999999992e-22 or 0.5 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6434.8
Applied rewrites34.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6466.8
Applied rewrites66.8%
if -9.1999999999999992e-22 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites44.0%
Final simplification55.1%
(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.f6468.4
Applied rewrites68.4%
Taylor expanded in x around inf
Applied rewrites24.1%
herbie shell --seed 2024307
(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))