
(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 (+ (/ x 2.0) (fma x y z)))
double code(double x, double y, double z) {
return (x / 2.0) + fma(x, y, z);
}
function code(x, y, z) return Float64(Float64(x / 2.0) + fma(x, y, z)) end
code[x_, y_, z_] := N[(N[(x / 2.0), $MachinePrecision] + N[(x * y + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{2} + \mathsf{fma}\left(x, y, z\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (/ x 2.0) (* x y))))
(if (or (<= t_0 -1e+248) (not (<= t_0 2e+174)))
(* x (+ y 0.5))
(+ (/ x 2.0) z))))
double code(double x, double y, double z) {
double t_0 = (x / 2.0) + (x * y);
double tmp;
if ((t_0 <= -1e+248) || !(t_0 <= 2e+174)) {
tmp = x * (y + 0.5);
} else {
tmp = (x / 2.0) + z;
}
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) :: t_0
real(8) :: tmp
t_0 = (x / 2.0d0) + (x * y)
if ((t_0 <= (-1d+248)) .or. (.not. (t_0 <= 2d+174))) then
tmp = x * (y + 0.5d0)
else
tmp = (x / 2.0d0) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x / 2.0) + (x * y);
double tmp;
if ((t_0 <= -1e+248) || !(t_0 <= 2e+174)) {
tmp = x * (y + 0.5);
} else {
tmp = (x / 2.0) + z;
}
return tmp;
}
def code(x, y, z): t_0 = (x / 2.0) + (x * y) tmp = 0 if (t_0 <= -1e+248) or not (t_0 <= 2e+174): tmp = x * (y + 0.5) else: tmp = (x / 2.0) + z return tmp
function code(x, y, z) t_0 = Float64(Float64(x / 2.0) + Float64(x * y)) tmp = 0.0 if ((t_0 <= -1e+248) || !(t_0 <= 2e+174)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(Float64(x / 2.0) + z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x / 2.0) + (x * y); tmp = 0.0; if ((t_0 <= -1e+248) || ~((t_0 <= 2e+174))) tmp = x * (y + 0.5); else tmp = (x / 2.0) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e+248], N[Not[LessEqual[t$95$0, 2e+174]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x / 2.0), $MachinePrecision] + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{2} + x \cdot y\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+248} \lor \neg \left(t_0 \leq 2 \cdot 10^{+174}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2} + z\\
\end{array}
\end{array}
if (+.f64 (/.f64 x 2) (*.f64 y x)) < -1.00000000000000005e248 or 2.00000000000000014e174 < (+.f64 (/.f64 x 2) (*.f64 y x)) Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 94.8%
Taylor expanded in x around 0 94.8%
if -1.00000000000000005e248 < (+.f64 (/.f64 x 2) (*.f64 y x)) < 2.00000000000000014e174Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 83.8%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (+ z (+ (/ x 2.0) (* x y))))
double code(double x, double y, double z) {
return z + ((x / 2.0) + (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 = z + ((x / 2.0d0) + (x * y))
end function
public static double code(double x, double y, double z) {
return z + ((x / 2.0) + (x * y));
}
def code(x, y, z): return z + ((x / 2.0) + (x * y))
function code(x, y, z) return Float64(z + Float64(Float64(x / 2.0) + Float64(x * y))) end
function tmp = code(x, y, z) tmp = z + ((x / 2.0) + (x * y)); end
code[x_, y_, z_] := N[(z + N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(\frac{x}{2} + x \cdot y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.4e-29) (* x y) (if (<= y 0.5) (* x 0.5) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e-29) {
tmp = x * y;
} else if (y <= 0.5) {
tmp = x * 0.5;
} 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 <= (-2.4d-29)) then
tmp = x * y
else if (y <= 0.5d0) then
tmp = x * 0.5d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e-29) {
tmp = x * y;
} else if (y <= 0.5) {
tmp = x * 0.5;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.4e-29: tmp = x * y elif y <= 0.5: tmp = x * 0.5 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.4e-29) tmp = Float64(x * y); elseif (y <= 0.5) tmp = Float64(x * 0.5); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.4e-29) tmp = x * y; elseif (y <= 0.5) tmp = x * 0.5; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.4e-29], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.5], N[(x * 0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-29}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.39999999999999992e-29 or 0.5 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 64.5%
Taylor expanded in y around inf 64.0%
if -2.39999999999999992e-29 < y < 0.5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 55.0%
Taylor expanded in y around 0 54.1%
Final simplification58.8%
(FPCore (x y z) :precision binary64 (* x (+ y 0.5)))
double code(double x, double y, double z) {
return x * (y + 0.5);
}
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 + 0.5d0)
end function
public static double code(double x, double y, double z) {
return x * (y + 0.5);
}
def code(x, y, z): return x * (y + 0.5)
function code(x, y, z) return Float64(x * Float64(y + 0.5)) end
function tmp = code(x, y, z) tmp = x * (y + 0.5); end
code[x_, y_, z_] := N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + 0.5\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 59.5%
Taylor expanded in x around 0 59.5%
Final simplification59.5%
(FPCore (x y z) :precision binary64 (* x 0.5))
double code(double x, double y, double z) {
return x * 0.5;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 0.5d0
end function
public static double code(double x, double y, double z) {
return x * 0.5;
}
def code(x, y, z): return x * 0.5
function code(x, y, z) return Float64(x * 0.5) end
function tmp = code(x, y, z) tmp = x * 0.5; end
code[x_, y_, z_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 59.5%
Taylor expanded in y around 0 29.6%
Final simplification29.6%
herbie shell --seed 2023221
(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))