
(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 -3e+43)
(* x y)
(if (<= y 2.1e-147)
z
(if (<= y 7e-23) (* x 0.5) (if (<= y 9.5e+63) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e+43) {
tmp = x * y;
} else if (y <= 2.1e-147) {
tmp = z;
} else if (y <= 7e-23) {
tmp = x * 0.5;
} else if (y <= 9.5e+63) {
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 <= (-3d+43)) then
tmp = x * y
else if (y <= 2.1d-147) then
tmp = z
else if (y <= 7d-23) then
tmp = x * 0.5d0
else if (y <= 9.5d+63) 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 <= -3e+43) {
tmp = x * y;
} else if (y <= 2.1e-147) {
tmp = z;
} else if (y <= 7e-23) {
tmp = x * 0.5;
} else if (y <= 9.5e+63) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e+43: tmp = x * y elif y <= 2.1e-147: tmp = z elif y <= 7e-23: tmp = x * 0.5 elif y <= 9.5e+63: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e+43) tmp = Float64(x * y); elseif (y <= 2.1e-147) tmp = z; elseif (y <= 7e-23) tmp = Float64(x * 0.5); elseif (y <= 9.5e+63) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e+43) tmp = x * y; elseif (y <= 2.1e-147) tmp = z; elseif (y <= 7e-23) tmp = x * 0.5; elseif (y <= 9.5e+63) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e+43], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.1e-147], z, If[LessEqual[y, 7e-23], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 9.5e+63], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+43}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-147}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-23}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+63}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3.00000000000000017e43 or 9.5000000000000003e63 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6478.0%
Simplified78.0%
if -3.00000000000000017e43 < y < 2.1e-147 or 6.99999999999999987e-23 < y < 9.5000000000000003e63Initial program 100.0%
Taylor expanded in x around 0
Simplified56.9%
if 2.1e-147 < y < 6.99999999999999987e-23Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6467.8%
Simplified67.8%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6467.8%
Simplified67.8%
(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-*.f6499.5%
Simplified99.5%
if -0.5 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6499.8%
Simplified99.8%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (<= y -9.5e+45) (* x y) (if (<= y 1.3e+66) (+ z (* x 0.5)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.5e+45) {
tmp = x * y;
} else if (y <= 1.3e+66) {
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 <= (-9.5d+45)) then
tmp = x * y
else if (y <= 1.3d+66) 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 <= -9.5e+45) {
tmp = x * y;
} else if (y <= 1.3e+66) {
tmp = z + (x * 0.5);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.5e+45: tmp = x * y elif y <= 1.3e+66: tmp = z + (x * 0.5) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.5e+45) tmp = Float64(x * y); elseif (y <= 1.3e+66) 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 <= -9.5e+45) tmp = x * y; elseif (y <= 1.3e+66) tmp = z + (x * 0.5); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.5e+45], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.3e+66], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+45}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{+66}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -9.4999999999999998e45 or 1.30000000000000006e66 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6478.0%
Simplified78.0%
if -9.4999999999999998e45 < y < 1.30000000000000006e66Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6495.6%
Simplified95.6%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.1e+48) z (if (<= z 6.6e+81) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.1e+48) {
tmp = z;
} else if (z <= 6.6e+81) {
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 <= (-1.1d+48)) then
tmp = z
else if (z <= 6.6d+81) 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 <= -1.1e+48) {
tmp = z;
} else if (z <= 6.6e+81) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.1e+48: tmp = z elif z <= 6.6e+81: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.1e+48) tmp = z; elseif (z <= 6.6e+81) 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 <= -1.1e+48) tmp = z; elseif (z <= 6.6e+81) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.1e+48], z, If[LessEqual[z, 6.6e+81], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{+48}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 6.6 \cdot 10^{+81}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.1e48 or 6.6e81 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified71.0%
if -1.1e48 < z < 6.6e81Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6479.8%
Simplified79.8%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= z -7.2e-65) z (if (<= z 8e-56) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.2e-65) {
tmp = z;
} else if (z <= 8e-56) {
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 <= (-7.2d-65)) then
tmp = z
else if (z <= 8d-56) 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 <= -7.2e-65) {
tmp = z;
} else if (z <= 8e-56) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.2e-65: tmp = z elif z <= 8e-56: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.2e-65) tmp = z; elseif (z <= 8e-56) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.2e-65) tmp = z; elseif (z <= 8e-56) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.2e-65], z, If[LessEqual[z, 8e-56], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-65}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 8 \cdot 10^{-56}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -7.1999999999999996e-65 or 8.0000000000000003e-56 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified61.7%
if -7.1999999999999996e-65 < z < 8.0000000000000003e-56Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6490.1%
Simplified90.1%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6446.7%
Simplified46.7%
(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.8%
herbie shell --seed 2024192
(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))