
(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) (* x y)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (x * y)) + 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) + (x * y)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (x * y)) + z;
}
def code(x, y, z): return ((x / 2.0) + (x * y)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(x * y)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (x * y)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + x \cdot y\right) + z
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.1e-5) (not (<= y 1.46e+44))) (* x (+ y 0.5)) (+ (/ x 2.0) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e-5) || !(y <= 1.46e+44)) {
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) :: tmp
if ((y <= (-2.1d-5)) .or. (.not. (y <= 1.46d+44))) 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 tmp;
if ((y <= -2.1e-5) || !(y <= 1.46e+44)) {
tmp = x * (y + 0.5);
} else {
tmp = (x / 2.0) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.1e-5) or not (y <= 1.46e+44): tmp = x * (y + 0.5) else: tmp = (x / 2.0) + z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.1e-5) || !(y <= 1.46e+44)) 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) tmp = 0.0; if ((y <= -2.1e-5) || ~((y <= 1.46e+44))) tmp = x * (y + 0.5); else tmp = (x / 2.0) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.1e-5], N[Not[LessEqual[y, 1.46e+44]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x / 2.0), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{-5} \lor \neg \left(y \leq 1.46 \cdot 10^{+44}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2} + z\\
\end{array}
\end{array}
if y < -2.09999999999999988e-5 or 1.4599999999999999e44 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 76.9%
Taylor expanded in x around 0 76.9%
if -2.09999999999999988e-5 < y < 1.4599999999999999e44Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 98.2%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.3e-7) (* x y) (if (<= y 0.13) (* x 0.5) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.3e-7) {
tmp = x * y;
} else if (y <= 0.13) {
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 <= (-1.3d-7)) then
tmp = x * y
else if (y <= 0.13d0) 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 <= -1.3e-7) {
tmp = x * y;
} else if (y <= 0.13) {
tmp = x * 0.5;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.3e-7: tmp = x * y elif y <= 0.13: tmp = x * 0.5 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.3e-7) tmp = Float64(x * y); elseif (y <= 0.13) 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 <= -1.3e-7) tmp = x * y; elseif (y <= 0.13) tmp = x * 0.5; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.3e-7], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.13], N[(x * 0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-7}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.13:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.29999999999999999e-7 or 0.13 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 74.3%
Taylor expanded in y around inf 73.4%
if -1.29999999999999999e-7 < y < 0.13Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 48.2%
Taylor expanded in y around 0 47.0%
Final simplification60.9%
(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 61.9%
Taylor expanded in x around 0 61.9%
Final simplification61.9%
(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 61.9%
Taylor expanded in y around 0 23.9%
Final simplification23.9%
herbie shell --seed 2023230
(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))