
(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 (+ z (* (+ 0.5 y) x)))
double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((0.5d0 + y) * x)
end function
public static double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
def code(x, y, z): return z + ((0.5 + y) * x)
function code(x, y, z) return Float64(z + Float64(Float64(0.5 + y) * x)) end
function tmp = code(x, y, z) tmp = z + ((0.5 + y) * x); end
code[x_, y_, z_] := N[(z + N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(0.5 + y\right) \cdot x
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.6e-113) (not (<= x 0.045))) (* (+ 0.5 y) x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.6e-113) || !(x <= 0.045)) {
tmp = (0.5 + y) * x;
} else {
tmp = 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 ((x <= (-4.6d-113)) .or. (.not. (x <= 0.045d0))) then
tmp = (0.5d0 + y) * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.6e-113) || !(x <= 0.045)) {
tmp = (0.5 + y) * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.6e-113) or not (x <= 0.045): tmp = (0.5 + y) * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.6e-113) || !(x <= 0.045)) tmp = Float64(Float64(0.5 + y) * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.6e-113) || ~((x <= 0.045))) tmp = (0.5 + y) * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.6e-113], N[Not[LessEqual[x, 0.045]], $MachinePrecision]], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-113} \lor \neg \left(x \leq 0.045\right):\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -4.60000000000000016e-113 or 0.044999999999999998 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 81.2%
if -4.60000000000000016e-113 < x < 0.044999999999999998Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 77.4%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (<= y -4.5e+97) (* y x) (if (<= y 6e+41) (+ z (* 0.5 x)) (* (+ 0.5 y) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+97) {
tmp = y * x;
} else if (y <= 6e+41) {
tmp = z + (0.5 * x);
} else {
tmp = (0.5 + y) * 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 <= (-4.5d+97)) then
tmp = y * x
else if (y <= 6d+41) then
tmp = z + (0.5d0 * x)
else
tmp = (0.5d0 + y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+97) {
tmp = y * x;
} else if (y <= 6e+41) {
tmp = z + (0.5 * x);
} else {
tmp = (0.5 + y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.5e+97: tmp = y * x elif y <= 6e+41: tmp = z + (0.5 * x) else: tmp = (0.5 + y) * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.5e+97) tmp = Float64(y * x); elseif (y <= 6e+41) tmp = Float64(z + Float64(0.5 * x)); else tmp = Float64(Float64(0.5 + y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.5e+97) tmp = y * x; elseif (y <= 6e+41) tmp = z + (0.5 * x); else tmp = (0.5 + y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.5e+97], N[(y * x), $MachinePrecision], If[LessEqual[y, 6e+41], N[(z + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+97}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+41}:\\
\;\;\;\;z + 0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\end{array}
\end{array}
if y < -4.49999999999999976e97Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 75.9%
if -4.49999999999999976e97 < y < 5.9999999999999997e41Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 94.3%
if 5.9999999999999997e41 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 86.1%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (if (<= y -5e+97) (* y x) (if (<= y 4.3e+41) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5e+97) {
tmp = y * x;
} else if (y <= 4.3e+41) {
tmp = z;
} else {
tmp = y * 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 <= (-5d+97)) then
tmp = y * x
else if (y <= 4.3d+41) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5e+97) {
tmp = y * x;
} else if (y <= 4.3e+41) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5e+97: tmp = y * x elif y <= 4.3e+41: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5e+97) tmp = Float64(y * x); elseif (y <= 4.3e+41) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5e+97) tmp = y * x; elseif (y <= 4.3e+41) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5e+97], N[(y * x), $MachinePrecision], If[LessEqual[y, 4.3e+41], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+97}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{+41}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.99999999999999999e97 or 4.30000000000000024e41 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 81.4%
if -4.99999999999999999e97 < y < 4.30000000000000024e41Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 58.5%
Final simplification66.6%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 45.2%
Final simplification45.2%
herbie shell --seed 2023181
(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))