
(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+240)
(and (not (<= t_0 -9.5e+201))
(or (<= t_0 -2e+140) (not (<= t_0 1e+77)))))
(* 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+240) || (!(t_0 <= -9.5e+201) && ((t_0 <= -2e+140) || !(t_0 <= 1e+77)))) {
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+240)) .or. (.not. (t_0 <= (-9.5d+201))) .and. (t_0 <= (-2d+140)) .or. (.not. (t_0 <= 1d+77))) 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+240) || (!(t_0 <= -9.5e+201) && ((t_0 <= -2e+140) || !(t_0 <= 1e+77)))) {
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+240) or (not (t_0 <= -9.5e+201) and ((t_0 <= -2e+140) or not (t_0 <= 1e+77))): 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+240) || (!(t_0 <= -9.5e+201) && ((t_0 <= -2e+140) || !(t_0 <= 1e+77)))) 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+240) || (~((t_0 <= -9.5e+201)) && ((t_0 <= -2e+140) || ~((t_0 <= 1e+77))))) 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+240], And[N[Not[LessEqual[t$95$0, -9.5e+201]], $MachinePrecision], Or[LessEqual[t$95$0, -2e+140], N[Not[LessEqual[t$95$0, 1e+77]], $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^{+240} \lor \neg \left(t_0 \leq -9.5 \cdot 10^{+201}\right) \land \left(t_0 \leq -2 \cdot 10^{+140} \lor \neg \left(t_0 \leq 10^{+77}\right)\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.00000000000000001e240 or -9.5000000000000002e201 < (+.f64 (/.f64 x 2) (*.f64 y x)) < -2.00000000000000012e140 or 9.99999999999999983e76 < (+.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 90.3%
Taylor expanded in x around 0 90.3%
if -1.00000000000000001e240 < (+.f64 (/.f64 x 2) (*.f64 y x)) < -9.5000000000000002e201 or -2.00000000000000012e140 < (+.f64 (/.f64 x 2) (*.f64 y x)) < 9.99999999999999983e76Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 88.2%
Final simplification89.3%
(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 -0.5) (* x y) (if (<= y 0.5) (* x 0.5) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
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 <= (-0.5d0)) 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 <= -0.5) {
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 <= -0.5: 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 <= -0.5) 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 <= -0.5) 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, -0.5], 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 -0.5:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -0.5 or 0.5 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 69.5%
Taylor expanded in y around inf 68.5%
if -0.5 < y < 0.5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 54.7%
Taylor expanded in y around 0 54.0%
Final simplification61.6%
(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 62.5%
Taylor expanded in x around 0 62.5%
Final simplification62.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 62.5%
Taylor expanded in y around 0 27.5%
Final simplification27.5%
herbie shell --seed 2023242
(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))