
(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 (+ z (* x (- y -0.5))))
double code(double x, double y, double z) {
return z + (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 = z + (x * (y - (-0.5d0)))
end function
public static double code(double x, double y, double z) {
return z + (x * (y - -0.5));
}
def code(x, y, z): return z + (x * (y - -0.5))
function code(x, y, z) return Float64(z + Float64(x * Float64(y - -0.5))) end
function tmp = code(x, y, z) tmp = z + (x * (y - -0.5)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y - -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y - -0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-inN/A
*-commutativeN/A
+-commutativeN/A
associate-+r+N/A
metadata-evalN/A
distribute-lft-neg-inN/A
unsub-negN/A
associate-+r-N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
distribute-lft-inN/A
remove-double-negN/A
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
neg-sub0N/A
distribute-rgt-neg-inN/A
neg-sub0N/A
associate-+r-N/A
+-rgt-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
sub-negN/A
Simplified100.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.5%
Simplified98.5%
if -0.5 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6498.2%
Simplified98.2%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y 0.5)))) (if (<= y -0.116) t_0 (if (<= y 2050.0) (+ z (* x 0.5)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + 0.5);
double tmp;
if (y <= -0.116) {
tmp = t_0;
} else if (y <= 2050.0) {
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 = x * (y + 0.5d0)
if (y <= (-0.116d0)) then
tmp = t_0
else if (y <= 2050.0d0) 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 = x * (y + 0.5);
double tmp;
if (y <= -0.116) {
tmp = t_0;
} else if (y <= 2050.0) {
tmp = z + (x * 0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + 0.5) tmp = 0 if y <= -0.116: tmp = t_0 elif y <= 2050.0: tmp = z + (x * 0.5) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + 0.5)) tmp = 0.0 if (y <= -0.116) tmp = t_0; elseif (y <= 2050.0) tmp = Float64(z + Float64(x * 0.5)); 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 (y <= -0.116) tmp = t_0; elseif (y <= 2050.0) tmp = z + (x * 0.5); 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[y, -0.116], t$95$0, If[LessEqual[y, 2050.0], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + 0.5\right)\\
\mathbf{if}\;y \leq -0.116:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2050:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.116000000000000006 or 2050 < y Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6477.4%
Simplified77.4%
if -0.116000000000000006 < y < 2050Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6498.2%
Simplified98.2%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= z -3.2e+57) z (if (<= z 3.6e+50) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.2e+57) {
tmp = z;
} else if (z <= 3.6e+50) {
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 <= (-3.2d+57)) then
tmp = z
else if (z <= 3.6d+50) 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 <= -3.2e+57) {
tmp = z;
} else if (z <= 3.6e+50) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.2e+57: tmp = z elif z <= 3.6e+50: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.2e+57) tmp = z; elseif (z <= 3.6e+50) 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 <= -3.2e+57) tmp = z; elseif (z <= 3.6e+50) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.2e+57], z, If[LessEqual[z, 3.6e+50], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{+57}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+50}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -3.20000000000000029e57 or 3.59999999999999986e50 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified69.3%
if -3.20000000000000029e57 < z < 3.59999999999999986e50Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6482.3%
Simplified82.3%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (<= y -1050.0) (* x y) (if (<= y 4.4e+49) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1050.0) {
tmp = x * y;
} else if (y <= 4.4e+49) {
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 <= (-1050.0d0)) then
tmp = x * y
else if (y <= 4.4d+49) 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 <= -1050.0) {
tmp = x * y;
} else if (y <= 4.4e+49) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1050.0: tmp = x * y elif y <= 4.4e+49: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1050.0) tmp = Float64(x * y); elseif (y <= 4.4e+49) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1050.0) tmp = x * y; elseif (y <= 4.4e+49) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1050.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.4e+49], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1050:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{+49}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1050 or 4.4000000000000001e49 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6479.4%
Simplified79.4%
if -1050 < y < 4.4000000000000001e49Initial program 100.0%
Taylor expanded in x around 0
Simplified56.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.05e-52) z (if (<= z 4.5e-54) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e-52) {
tmp = z;
} else if (z <= 4.5e-54) {
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.05d-52)) then
tmp = z
else if (z <= 4.5d-54) 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.05e-52) {
tmp = z;
} else if (z <= 4.5e-54) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.05e-52: tmp = z elif z <= 4.5e-54: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.05e-52) tmp = z; elseif (z <= 4.5e-54) 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.05e-52) tmp = z; elseif (z <= 4.5e-54) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.05e-52], z, If[LessEqual[z, 4.5e-54], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{-52}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-54}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.0499999999999999e-52 or 4.4999999999999998e-54 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified60.7%
if -1.0499999999999999e-52 < z < 4.4999999999999998e-54Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6491.2%
Simplified91.2%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6437.6%
Simplified37.6%
(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
Simplified40.8%
herbie shell --seed 2024145
(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))