
(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 7 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 (let* ((t_0 (+ z (* x y)))) (if (<= y -0.5) t_0 (if (<= y 0.5) (+ z (* x 0.5)) t_0))))
double code(double x, double y, double z) {
double t_0 = z + (x * y);
double tmp;
if (y <= -0.5) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = z + (x * 0.5);
} else {
tmp = t_0;
}
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 = z + (x * y)
if (y <= (-0.5d0)) then
tmp = t_0
else if (y <= 0.5d0) then
tmp = z + (x * 0.5d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z + (x * y);
double tmp;
if (y <= -0.5) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = z + (x * 0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z + (x * y) tmp = 0 if y <= -0.5: tmp = t_0 elif y <= 0.5: tmp = z + (x * 0.5) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z + Float64(x * y)) tmp = 0.0 if (y <= -0.5) tmp = t_0; elseif (y <= 0.5) tmp = Float64(z + Float64(x * 0.5)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z + (x * y); tmp = 0.0; if (y <= -0.5) tmp = t_0; elseif (y <= 0.5) tmp = z + (x * 0.5); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.5], t$95$0, If[LessEqual[y, 0.5], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z + x \cdot y\\
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.5 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6498.3%
Simplified98.3%
if -0.5 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6497.6%
Simplified97.6%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.45e+43) (* x y) (if (<= y 8.8e-10) (+ z (* x 0.5)) (* x (+ y 0.5)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.45e+43) {
tmp = x * y;
} else if (y <= 8.8e-10) {
tmp = z + (x * 0.5);
} else {
tmp = x * (y + 0.5);
}
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.45d+43)) then
tmp = x * y
else if (y <= 8.8d-10) then
tmp = z + (x * 0.5d0)
else
tmp = x * (y + 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.45e+43) {
tmp = x * y;
} else if (y <= 8.8e-10) {
tmp = z + (x * 0.5);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.45e+43: tmp = x * y elif y <= 8.8e-10: tmp = z + (x * 0.5) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.45e+43) tmp = Float64(x * y); elseif (y <= 8.8e-10) tmp = Float64(z + Float64(x * 0.5)); else tmp = Float64(x * Float64(y + 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.45e+43) tmp = x * y; elseif (y <= 8.8e-10) tmp = z + (x * 0.5); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.45e+43], N[(x * y), $MachinePrecision], If[LessEqual[y, 8.8e-10], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+43}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{-10}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if y < -1.4500000000000001e43Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6478.2%
Simplified78.2%
if -1.4500000000000001e43 < y < 8.7999999999999996e-10Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6496.2%
Simplified96.2%
if 8.7999999999999996e-10 < y Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6475.4%
Simplified75.4%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (<= z -7e+60) z (if (<= z 5.2e+115) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7e+60) {
tmp = z;
} else if (z <= 5.2e+115) {
tmp = x * (y + 0.5);
} 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 (z <= (-7d+60)) then
tmp = z
else if (z <= 5.2d+115) then
tmp = x * (y + 0.5d0)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7e+60) {
tmp = z;
} else if (z <= 5.2e+115) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7e+60: tmp = z elif z <= 5.2e+115: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7e+60) tmp = z; elseif (z <= 5.2e+115) tmp = Float64(x * Float64(y + 0.5)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7e+60) tmp = z; elseif (z <= 5.2e+115) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7e+60], z, If[LessEqual[z, 5.2e+115], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{+60}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+115}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -7.0000000000000004e60 or 5.2000000000000001e115 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified77.8%
if -7.0000000000000004e60 < z < 5.2000000000000001e115Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6479.3%
Simplified79.3%
Final simplification78.8%
(FPCore (x y z) :precision binary64 (if (<= y -6.8e+43) (* x y) (if (<= y 9e+61) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e+43) {
tmp = x * y;
} else if (y <= 9e+61) {
tmp = 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 <= (-6.8d+43)) then
tmp = x * y
else if (y <= 9d+61) then
tmp = 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 <= -6.8e+43) {
tmp = x * y;
} else if (y <= 9e+61) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e+43: tmp = x * y elif y <= 9e+61: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e+43) tmp = Float64(x * y); elseif (y <= 9e+61) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.8e+43) tmp = x * y; elseif (y <= 9e+61) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e+43], N[(x * y), $MachinePrecision], If[LessEqual[y, 9e+61], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+43}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+61}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -6.80000000000000024e43 or 9e61 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6479.1%
Simplified79.1%
if -6.80000000000000024e43 < y < 9e61Initial program 100.0%
Taylor expanded in x around 0
Simplified56.5%
(FPCore (x y z) :precision binary64 (if (<= z -0.54) z (if (<= z 5.3e-40) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.54) {
tmp = z;
} else if (z <= 5.3e-40) {
tmp = x * 0.5;
} 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 (z <= (-0.54d0)) then
tmp = z
else if (z <= 5.3d-40) then
tmp = x * 0.5d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -0.54) {
tmp = z;
} else if (z <= 5.3e-40) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.54: tmp = z elif z <= 5.3e-40: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.54) tmp = z; elseif (z <= 5.3e-40) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.54) tmp = z; elseif (z <= 5.3e-40) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.54], z, If[LessEqual[z, 5.3e-40], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.54:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 5.3 \cdot 10^{-40}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -0.54000000000000004 or 5.3000000000000002e-40 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified66.6%
if -0.54000000000000004 < z < 5.3000000000000002e-40Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6490.5%
Simplified90.5%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6442.0%
Simplified42.0%
(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%
Taylor expanded in x around 0
Simplified43.3%
herbie shell --seed 2024150
(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))