
(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 (<= y -2800000000000.0) (* x (+ y 0.5)) (if (<= y 7.4e+81) (+ (/ x 2.0) z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2800000000000.0) {
tmp = x * (y + 0.5);
} else if (y <= 7.4e+81) {
tmp = (x / 2.0) + z;
} 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 <= (-2800000000000.0d0)) then
tmp = x * (y + 0.5d0)
else if (y <= 7.4d+81) then
tmp = (x / 2.0d0) + z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2800000000000.0) {
tmp = x * (y + 0.5);
} else if (y <= 7.4e+81) {
tmp = (x / 2.0) + z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2800000000000.0: tmp = x * (y + 0.5) elif y <= 7.4e+81: tmp = (x / 2.0) + z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2800000000000.0) tmp = Float64(x * Float64(y + 0.5)); elseif (y <= 7.4e+81) tmp = Float64(Float64(x / 2.0) + z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2800000000000.0) tmp = x * (y + 0.5); elseif (y <= 7.4e+81) tmp = (x / 2.0) + z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2800000000000.0], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.4e+81], N[(N[(x / 2.0), $MachinePrecision] + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2800000000000:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{+81}:\\
\;\;\;\;\frac{x}{2} + z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.8e12Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 72.1%
Taylor expanded in x around 0 72.1%
if -2.8e12 < y < 7.4000000000000001e81Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 97.4%
if 7.4000000000000001e81 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 78.7%
Taylor expanded in y around inf 78.7%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (<= y -48000000000.0) (* x y) (if (<= y 135000000000.0) (* x 0.5) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -48000000000.0) {
tmp = x * y;
} else if (y <= 135000000000.0) {
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 <= (-48000000000.0d0)) then
tmp = x * y
else if (y <= 135000000000.0d0) 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 <= -48000000000.0) {
tmp = x * y;
} else if (y <= 135000000000.0) {
tmp = x * 0.5;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -48000000000.0: tmp = x * y elif y <= 135000000000.0: tmp = x * 0.5 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -48000000000.0) tmp = Float64(x * y); elseif (y <= 135000000000.0) 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 <= -48000000000.0) tmp = x * y; elseif (y <= 135000000000.0) tmp = x * 0.5; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -48000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 135000000000.0], N[(x * 0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -48000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 135000000000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -4.8e10 or 1.35e11 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 69.9%
Taylor expanded in y around inf 69.9%
if -4.8e10 < y < 1.35e11Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 48.5%
Taylor expanded in y around 0 48.6%
Final simplification59.2%
(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.1%
Taylor expanded in x around 0 59.1%
Final simplification59.1%
(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.1%
Taylor expanded in y around 0 26.2%
Final simplification26.2%
herbie shell --seed 2023173
(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))