
(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 -8.5e+24)
(* x y)
(if (<= y 1.2e-111)
z
(if (<= y 8.5e-44) (* x 0.5) (if (<= y 1.4e+18) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.5e+24) {
tmp = x * y;
} else if (y <= 1.2e-111) {
tmp = z;
} else if (y <= 8.5e-44) {
tmp = x * 0.5;
} else if (y <= 1.4e+18) {
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 <= (-8.5d+24)) then
tmp = x * y
else if (y <= 1.2d-111) then
tmp = z
else if (y <= 8.5d-44) then
tmp = x * 0.5d0
else if (y <= 1.4d+18) 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 <= -8.5e+24) {
tmp = x * y;
} else if (y <= 1.2e-111) {
tmp = z;
} else if (y <= 8.5e-44) {
tmp = x * 0.5;
} else if (y <= 1.4e+18) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.5e+24: tmp = x * y elif y <= 1.2e-111: tmp = z elif y <= 8.5e-44: tmp = x * 0.5 elif y <= 1.4e+18: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.5e+24) tmp = Float64(x * y); elseif (y <= 1.2e-111) tmp = z; elseif (y <= 8.5e-44) tmp = Float64(x * 0.5); elseif (y <= 1.4e+18) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.5e+24) tmp = x * y; elseif (y <= 1.2e-111) tmp = z; elseif (y <= 8.5e-44) tmp = x * 0.5; elseif (y <= 1.4e+18) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.5e+24], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.2e-111], z, If[LessEqual[y, 8.5e-44], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.4e+18], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{+24}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-111}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-44}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+18}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -8.49999999999999959e24 or 1.4e18 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6473.5%
Simplified73.5%
if -8.49999999999999959e24 < y < 1.2e-111 or 8.5000000000000002e-44 < y < 1.4e18Initial program 100.0%
Taylor expanded in x around 0
Simplified65.5%
if 1.2e-111 < y < 8.5000000000000002e-44Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6470.3%
Simplified70.3%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6470.3%
Simplified70.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ z (* x y)))) (if (<= y -3.55e+21) t_0 (if (<= y 1.16e-18) (+ z (* x 0.5)) t_0))))
double code(double x, double y, double z) {
double t_0 = z + (x * y);
double tmp;
if (y <= -3.55e+21) {
tmp = t_0;
} else if (y <= 1.16e-18) {
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 <= (-3.55d+21)) then
tmp = t_0
else if (y <= 1.16d-18) 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 <= -3.55e+21) {
tmp = t_0;
} else if (y <= 1.16e-18) {
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 <= -3.55e+21: tmp = t_0 elif y <= 1.16e-18: 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 <= -3.55e+21) tmp = t_0; elseif (y <= 1.16e-18) 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 <= -3.55e+21) tmp = t_0; elseif (y <= 1.16e-18) 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, -3.55e+21], t$95$0, If[LessEqual[y, 1.16e-18], 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 -3.55 \cdot 10^{+21}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{-18}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.55e21 or 1.16e-18 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64100.0%
Simplified100.0%
if -3.55e21 < y < 1.16e-18Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6499.6%
Simplified99.6%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.55e+22) (* x y) (if (<= y 4.2e+17) (+ z (* x 0.5)) (* x (+ y 0.5)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.55e+22) {
tmp = x * y;
} else if (y <= 4.2e+17) {
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.55d+22)) then
tmp = x * y
else if (y <= 4.2d+17) 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.55e+22) {
tmp = x * y;
} else if (y <= 4.2e+17) {
tmp = z + (x * 0.5);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.55e+22: tmp = x * y elif y <= 4.2e+17: tmp = z + (x * 0.5) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.55e+22) tmp = Float64(x * y); elseif (y <= 4.2e+17) 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.55e+22) tmp = x * y; elseif (y <= 4.2e+17) tmp = z + (x * 0.5); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.55e+22], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.2e+17], 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.55 \cdot 10^{+22}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+17}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if y < -1.5500000000000001e22Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6474.7%
Simplified74.7%
if -1.5500000000000001e22 < y < 4.2e17Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6499.6%
Simplified99.6%
if 4.2e17 < y Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6472.4%
Simplified72.4%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y 0.5)))) (if (<= x -3.2e-39) t_0 (if (<= x 1.55e+19) z t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + 0.5);
double tmp;
if (x <= -3.2e-39) {
tmp = t_0;
} else if (x <= 1.55e+19) {
tmp = z;
} 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 = x * (y + 0.5d0)
if (x <= (-3.2d-39)) then
tmp = t_0
else if (x <= 1.55d+19) then
tmp = z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y + 0.5);
double tmp;
if (x <= -3.2e-39) {
tmp = t_0;
} else if (x <= 1.55e+19) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + 0.5) tmp = 0 if x <= -3.2e-39: tmp = t_0 elif x <= 1.55e+19: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + 0.5)) tmp = 0.0 if (x <= -3.2e-39) tmp = t_0; elseif (x <= 1.55e+19) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + 0.5); tmp = 0.0; if (x <= -3.2e-39) tmp = t_0; elseif (x <= 1.55e+19) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.2e-39], t$95$0, If[LessEqual[x, 1.55e+19], z, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + 0.5\right)\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{-39}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{+19}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.1999999999999998e-39 or 1.55e19 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6478.6%
Simplified78.6%
if -3.1999999999999998e-39 < x < 1.55e19Initial program 100.0%
Taylor expanded in x around 0
Simplified68.3%
Final simplification73.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.36e-11) z (if (<= z 6e-60) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.36e-11) {
tmp = z;
} else if (z <= 6e-60) {
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 <= (-1.36d-11)) then
tmp = z
else if (z <= 6d-60) 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 <= -1.36e-11) {
tmp = z;
} else if (z <= 6e-60) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.36e-11: tmp = z elif z <= 6e-60: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.36e-11) tmp = z; elseif (z <= 6e-60) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.36e-11) tmp = z; elseif (z <= 6e-60) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.36e-11], z, If[LessEqual[z, 6e-60], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.36 \cdot 10^{-11}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-60}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.36e-11 or 6.00000000000000038e-60 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified61.3%
if -1.36e-11 < z < 6.00000000000000038e-60Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6481.9%
Simplified81.9%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6440.1%
Simplified40.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
Simplified44.6%
herbie shell --seed 2024160
(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))