
(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 8 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 -2.3e+94)
(* x y)
(if (<= y -2.2e-50)
z
(if (<= y 1.95e-286)
(* x 0.5)
(if (<= y 6.5e-170) z (if (<= y 7000.0) (* x 0.5) (* x y)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.3e+94) {
tmp = x * y;
} else if (y <= -2.2e-50) {
tmp = z;
} else if (y <= 1.95e-286) {
tmp = x * 0.5;
} else if (y <= 6.5e-170) {
tmp = z;
} else if (y <= 7000.0) {
tmp = 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 <= (-2.3d+94)) then
tmp = x * y
else if (y <= (-2.2d-50)) then
tmp = z
else if (y <= 1.95d-286) then
tmp = x * 0.5d0
else if (y <= 6.5d-170) then
tmp = z
else if (y <= 7000.0d0) then
tmp = 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 <= -2.3e+94) {
tmp = x * y;
} else if (y <= -2.2e-50) {
tmp = z;
} else if (y <= 1.95e-286) {
tmp = x * 0.5;
} else if (y <= 6.5e-170) {
tmp = z;
} else if (y <= 7000.0) {
tmp = x * 0.5;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.3e+94: tmp = x * y elif y <= -2.2e-50: tmp = z elif y <= 1.95e-286: tmp = x * 0.5 elif y <= 6.5e-170: tmp = z elif y <= 7000.0: tmp = x * 0.5 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.3e+94) tmp = Float64(x * y); elseif (y <= -2.2e-50) tmp = z; elseif (y <= 1.95e-286) tmp = Float64(x * 0.5); elseif (y <= 6.5e-170) tmp = z; elseif (y <= 7000.0) tmp = 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 <= -2.3e+94) tmp = x * y; elseif (y <= -2.2e-50) tmp = z; elseif (y <= 1.95e-286) tmp = x * 0.5; elseif (y <= 6.5e-170) tmp = z; elseif (y <= 7000.0) tmp = x * 0.5; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.3e+94], N[(x * y), $MachinePrecision], If[LessEqual[y, -2.2e-50], z, If[LessEqual[y, 1.95e-286], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 6.5e-170], z, If[LessEqual[y, 7000.0], N[(x * 0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+94}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -2.2 \cdot 10^{-50}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{-286}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-170}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 7000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.3e94 or 7e3 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 88.2%
if -2.3e94 < y < -2.1999999999999999e-50 or 1.94999999999999998e-286 < y < 6.50000000000000035e-170Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 59.6%
if -2.1999999999999999e-50 < y < 1.94999999999999998e-286 or 6.50000000000000035e-170 < y < 7e3Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 65.5%
Taylor expanded in y around 0 64.5%
Final simplification72.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.5e+81) (not (<= x 5.5e+48))) (* x (+ y 0.5)) (+ (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e+81) || !(x <= 5.5e+48)) {
tmp = x * (y + 0.5);
} else {
tmp = (x * y) + 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 ((x <= (-7.5d+81)) .or. (.not. (x <= 5.5d+48))) then
tmp = x * (y + 0.5d0)
else
tmp = (x * y) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e+81) || !(x <= 5.5e+48)) {
tmp = x * (y + 0.5);
} else {
tmp = (x * y) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.5e+81) or not (x <= 5.5e+48): tmp = x * (y + 0.5) else: tmp = (x * y) + z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.5e+81) || !(x <= 5.5e+48)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(Float64(x * y) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.5e+81) || ~((x <= 5.5e+48))) tmp = x * (y + 0.5); else tmp = (x * y) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e+81], N[Not[LessEqual[x, 5.5e+48]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+81} \lor \neg \left(x \leq 5.5 \cdot 10^{+48}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + z\\
\end{array}
\end{array}
if x < -7.49999999999999973e81 or 5.5000000000000002e48 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 91.1%
if -7.49999999999999973e81 < x < 5.5000000000000002e48Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 83.6%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 0.5))) (+ (* x y) z) (+ z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 0.5)) {
tmp = (x * y) + z;
} else {
tmp = z + (x * 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 <= (-0.5d0)) .or. (.not. (y <= 0.5d0))) then
tmp = (x * y) + z
else
tmp = z + (x * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 0.5)) {
tmp = (x * y) + z;
} else {
tmp = z + (x * 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.5) or not (y <= 0.5): tmp = (x * y) + z else: tmp = z + (x * 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.5) || !(y <= 0.5)) tmp = Float64(Float64(x * y) + z); else tmp = Float64(z + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.5) || ~((y <= 0.5))) tmp = (x * y) + z; else tmp = z + (x * 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;x \cdot y + z\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 0.5\\
\end{array}
\end{array}
if y < -0.5 or 0.5 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.5%
if -0.5 < y < 0.5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 97.9%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= z -4e+199) z (if (<= z 1.45e+164) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4e+199) {
tmp = z;
} else if (z <= 1.45e+164) {
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 <= (-4d+199)) then
tmp = z
else if (z <= 1.45d+164) 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 <= -4e+199) {
tmp = z;
} else if (z <= 1.45e+164) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4e+199: tmp = z elif z <= 1.45e+164: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4e+199) tmp = z; elseif (z <= 1.45e+164) 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 <= -4e+199) tmp = z; elseif (z <= 1.45e+164) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4e+199], z, If[LessEqual[z, 1.45e+164], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+199}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{+164}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -4.00000000000000039e199 or 1.4499999999999999e164 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 78.6%
if -4.00000000000000039e199 < z < 1.4499999999999999e164Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 77.1%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (<= x -2.5e+106) (* x 0.5) (if (<= x 5e+53) z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e+106) {
tmp = x * 0.5;
} else if (x <= 5e+53) {
tmp = z;
} else {
tmp = x * 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 (x <= (-2.5d+106)) then
tmp = x * 0.5d0
else if (x <= 5d+53) then
tmp = z
else
tmp = x * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e+106) {
tmp = x * 0.5;
} else if (x <= 5e+53) {
tmp = z;
} else {
tmp = x * 0.5;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.5e+106: tmp = x * 0.5 elif x <= 5e+53: tmp = z else: tmp = x * 0.5 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.5e+106) tmp = Float64(x * 0.5); elseif (x <= 5e+53) tmp = z; else tmp = Float64(x * 0.5); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.5e+106) tmp = x * 0.5; elseif (x <= 5e+53) tmp = z; else tmp = x * 0.5; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.5e+106], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 5e+53], z, N[(x * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+106}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+53}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5\\
\end{array}
\end{array}
if x < -2.4999999999999999e106 or 5.0000000000000004e53 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 91.5%
Taylor expanded in y around 0 47.4%
if -2.4999999999999999e106 < x < 5.0000000000000004e53Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 49.4%
Final simplification48.6%
(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%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.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%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 32.5%
Final simplification32.5%
herbie shell --seed 2023240
(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))