
(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
(if (<= y -5.8e+55)
(* x y)
(if (<= y -1.55e-46)
z
(if (<= y -1.25e-222)
(* x 0.5)
(if (<= y 1.65e-241)
z
(if (<= y 6.8e-103) (* x 0.5) (if (<= y 2.5e+81) z (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e+55) {
tmp = x * y;
} else if (y <= -1.55e-46) {
tmp = z;
} else if (y <= -1.25e-222) {
tmp = x * 0.5;
} else if (y <= 1.65e-241) {
tmp = z;
} else if (y <= 6.8e-103) {
tmp = x * 0.5;
} else if (y <= 2.5e+81) {
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 <= (-5.8d+55)) then
tmp = x * y
else if (y <= (-1.55d-46)) then
tmp = z
else if (y <= (-1.25d-222)) then
tmp = x * 0.5d0
else if (y <= 1.65d-241) then
tmp = z
else if (y <= 6.8d-103) then
tmp = x * 0.5d0
else if (y <= 2.5d+81) 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 <= -5.8e+55) {
tmp = x * y;
} else if (y <= -1.55e-46) {
tmp = z;
} else if (y <= -1.25e-222) {
tmp = x * 0.5;
} else if (y <= 1.65e-241) {
tmp = z;
} else if (y <= 6.8e-103) {
tmp = x * 0.5;
} else if (y <= 2.5e+81) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.8e+55: tmp = x * y elif y <= -1.55e-46: tmp = z elif y <= -1.25e-222: tmp = x * 0.5 elif y <= 1.65e-241: tmp = z elif y <= 6.8e-103: tmp = x * 0.5 elif y <= 2.5e+81: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.8e+55) tmp = Float64(x * y); elseif (y <= -1.55e-46) tmp = z; elseif (y <= -1.25e-222) tmp = Float64(x * 0.5); elseif (y <= 1.65e-241) tmp = z; elseif (y <= 6.8e-103) tmp = Float64(x * 0.5); elseif (y <= 2.5e+81) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.8e+55) tmp = x * y; elseif (y <= -1.55e-46) tmp = z; elseif (y <= -1.25e-222) tmp = x * 0.5; elseif (y <= 1.65e-241) tmp = z; elseif (y <= 6.8e-103) tmp = x * 0.5; elseif (y <= 2.5e+81) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.8e+55], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.55e-46], z, If[LessEqual[y, -1.25e-222], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.65e-241], z, If[LessEqual[y, 6.8e-103], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2.5e+81], z, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+55}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.55 \cdot 10^{-46}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-222}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-241}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-103}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+81}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -5.7999999999999997e55 or 2.4999999999999999e81 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6473.1%
Simplified73.1%
if -5.7999999999999997e55 < y < -1.55e-46 or -1.25000000000000002e-222 < y < 1.6499999999999999e-241 or 6.80000000000000006e-103 < y < 2.4999999999999999e81Initial program 100.0%
Taylor expanded in x around 0
Simplified63.3%
if -1.55e-46 < y < -1.25000000000000002e-222 or 1.6499999999999999e-241 < y < 6.80000000000000006e-103Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6468.8%
Simplified68.8%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6468.8%
Simplified68.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ z (* x y)))) (if (<= y -48.0) 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 <= -48.0) {
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 <= (-48.0d0)) 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 <= -48.0) {
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 <= -48.0: 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 <= -48.0) 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 <= -48.0) 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, -48.0], 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 -48:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -48 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6498.7%
Simplified98.7%
if -48 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6499.0%
Simplified99.0%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (<= y -215.0) (* x (+ y 0.5)) (if (<= y 1.25e+81) (+ z (* x 0.5)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -215.0) {
tmp = x * (y + 0.5);
} else if (y <= 1.25e+81) {
tmp = z + (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 <= (-215.0d0)) then
tmp = x * (y + 0.5d0)
else if (y <= 1.25d+81) then
tmp = z + (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 <= -215.0) {
tmp = x * (y + 0.5);
} else if (y <= 1.25e+81) {
tmp = z + (x * 0.5);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -215.0: tmp = x * (y + 0.5) elif y <= 1.25e+81: tmp = z + (x * 0.5) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -215.0) tmp = Float64(x * Float64(y + 0.5)); elseif (y <= 1.25e+81) tmp = Float64(z + 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 <= -215.0) tmp = x * (y + 0.5); elseif (y <= 1.25e+81) tmp = z + (x * 0.5); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -215.0], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.25e+81], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -215:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{+81}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -215Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6461.2%
Simplified61.2%
if -215 < y < 1.25e81Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6496.6%
Simplified96.6%
if 1.25e81 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6483.4%
Simplified83.4%
Final simplification85.4%
(FPCore (x y z) :precision binary64 (if (<= z -2.4e+70) z (if (<= z 900000.0) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e+70) {
tmp = z;
} else if (z <= 900000.0) {
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 <= (-2.4d+70)) then
tmp = z
else if (z <= 900000.0d0) 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 <= -2.4e+70) {
tmp = z;
} else if (z <= 900000.0) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.4e+70: tmp = z elif z <= 900000.0: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.4e+70) tmp = z; elseif (z <= 900000.0) 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 <= -2.4e+70) tmp = z; elseif (z <= 900000.0) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.4e+70], z, If[LessEqual[z, 900000.0], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+70}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 900000:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.39999999999999987e70 or 9e5 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified70.0%
if -2.39999999999999987e70 < z < 9e5Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6484.2%
Simplified84.2%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (<= z -3.4e-118) z (if (<= z 35000.0) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.4e-118) {
tmp = z;
} else if (z <= 35000.0) {
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 <= (-3.4d-118)) then
tmp = z
else if (z <= 35000.0d0) 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 <= -3.4e-118) {
tmp = z;
} else if (z <= 35000.0) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.4e-118: tmp = z elif z <= 35000.0: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.4e-118) tmp = z; elseif (z <= 35000.0) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.4e-118) tmp = z; elseif (z <= 35000.0) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.4e-118], z, If[LessEqual[z, 35000.0], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{-118}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 35000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -3.39999999999999991e-118 or 35000 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified60.5%
if -3.39999999999999991e-118 < z < 35000Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6490.0%
Simplified90.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6448.1%
Simplified48.1%
(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
Simplified41.4%
herbie shell --seed 2024158
(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))