
(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 (+ (/ 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 (if (or (<= y -1.48e+57) (not (<= y 1.55e+100))) (+ (/ x 2.0) (* x y)) (+ (/ x 2.0) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.48e+57) || !(y <= 1.55e+100)) {
tmp = (x / 2.0) + (x * y);
} 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) :: tmp
if ((y <= (-1.48d+57)) .or. (.not. (y <= 1.55d+100))) then
tmp = (x / 2.0d0) + (x * y)
else
tmp = (x / 2.0d0) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.48e+57) || !(y <= 1.55e+100)) {
tmp = (x / 2.0) + (x * y);
} else {
tmp = (x / 2.0) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.48e+57) or not (y <= 1.55e+100): tmp = (x / 2.0) + (x * y) else: tmp = (x / 2.0) + z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.48e+57) || !(y <= 1.55e+100)) tmp = Float64(Float64(x / 2.0) + Float64(x * y)); else tmp = Float64(Float64(x / 2.0) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.48e+57) || ~((y <= 1.55e+100))) tmp = (x / 2.0) + (x * y); else tmp = (x / 2.0) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.48e+57], N[Not[LessEqual[y, 1.55e+100]], $MachinePrecision]], N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(x / 2.0), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.48 \cdot 10^{+57} \lor \neg \left(y \leq 1.55 \cdot 10^{+100}\right):\\
\;\;\;\;\frac{x}{2} + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2} + z\\
\end{array}
\end{array}
if y < -1.47999999999999999e57 or 1.55000000000000003e100 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 84.9%
if -1.47999999999999999e57 < y < 1.55000000000000003e100Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 95.1%
Final simplification91.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 (+ (/ x 2.0) (+ z (* x y))))
double code(double x, double y, double z) {
return (x / 2.0) + (z + (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 / 2.0d0) + (z + (x * y))
end function
public static double code(double x, double y, double z) {
return (x / 2.0) + (z + (x * y));
}
def code(x, y, z): return (x / 2.0) + (z + (x * y))
function code(x, y, z) return Float64(Float64(x / 2.0) + Float64(z + Float64(x * y))) end
function tmp = code(x, y, z) tmp = (x / 2.0) + (z + (x * y)); end
code[x_, y_, z_] := N[(N[(x / 2.0), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{2} + \left(z + x \cdot y\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (+ (/ x 2.0) z))
double code(double x, double y, double z) {
return (x / 2.0) + 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) + z
end function
public static double code(double x, double y, double z) {
return (x / 2.0) + z;
}
def code(x, y, z): return (x / 2.0) + z
function code(x, y, z) return Float64(Float64(x / 2.0) + z) end
function tmp = code(x, y, z) tmp = (x / 2.0) + z; end
code[x_, y_, z_] := N[(N[(x / 2.0), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{2} + z
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 66.1%
Final simplification66.1%
herbie shell --seed 2023182
(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))