
(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 -0.5)
(* x y)
(if (<= y -2.65e-235)
(* x 0.5)
(if (<= y 1.8e-201)
z
(if (<= y 1.7e-102) (* x 0.5) (if (<= y 2.3e+27) z (* x y)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = x * y;
} else if (y <= -2.65e-235) {
tmp = x * 0.5;
} else if (y <= 1.8e-201) {
tmp = z;
} else if (y <= 1.7e-102) {
tmp = x * 0.5;
} else if (y <= 2.3e+27) {
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 <= (-0.5d0)) then
tmp = x * y
else if (y <= (-2.65d-235)) then
tmp = x * 0.5d0
else if (y <= 1.8d-201) then
tmp = z
else if (y <= 1.7d-102) then
tmp = x * 0.5d0
else if (y <= 2.3d+27) 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 <= -0.5) {
tmp = x * y;
} else if (y <= -2.65e-235) {
tmp = x * 0.5;
} else if (y <= 1.8e-201) {
tmp = z;
} else if (y <= 1.7e-102) {
tmp = x * 0.5;
} else if (y <= 2.3e+27) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.5: tmp = x * y elif y <= -2.65e-235: tmp = x * 0.5 elif y <= 1.8e-201: tmp = z elif y <= 1.7e-102: tmp = x * 0.5 elif y <= 2.3e+27: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = Float64(x * y); elseif (y <= -2.65e-235) tmp = Float64(x * 0.5); elseif (y <= 1.8e-201) tmp = z; elseif (y <= 1.7e-102) tmp = Float64(x * 0.5); elseif (y <= 2.3e+27) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.5) tmp = x * y; elseif (y <= -2.65e-235) tmp = x * 0.5; elseif (y <= 1.8e-201) tmp = z; elseif (y <= 1.7e-102) tmp = x * 0.5; elseif (y <= 2.3e+27) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(x * y), $MachinePrecision], If[LessEqual[y, -2.65e-235], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.8e-201], z, If[LessEqual[y, 1.7e-102], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2.3e+27], z, N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -2.65 \cdot 10^{-235}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-201}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-102}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+27}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -0.5 or 2.3000000000000001e27 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 74.0%
if -0.5 < y < -2.6500000000000001e-235 or 1.80000000000000016e-201 < y < 1.70000000000000006e-102Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 64.9%
Taylor expanded in y around 0 63.5%
if -2.6500000000000001e-235 < y < 1.80000000000000016e-201 or 1.70000000000000006e-102 < y < 2.3000000000000001e27Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 61.9%
Final simplification67.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-99) (not (<= x 2.8e-5))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-99) || !(x <= 2.8e-5)) {
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 ((x <= (-2d-99)) .or. (.not. (x <= 2.8d-5))) 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 ((x <= -2e-99) || !(x <= 2.8e-5)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-99) or not (x <= 2.8e-5): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-99) || !(x <= 2.8e-5)) 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 ((x <= -2e-99) || ~((x <= 2.8e-5))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-99], N[Not[LessEqual[x, 2.8e-5]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-99} \lor \neg \left(x \leq 2.8 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2e-99 or 2.79999999999999996e-5 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 82.3%
if -2e-99 < x < 2.79999999999999996e-5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 71.3%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (if (<= y -260000000.0) (* x y) (if (<= y 0.00013) (+ z (* x 0.5)) (* x (+ y 0.5)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -260000000.0) {
tmp = x * y;
} else if (y <= 0.00013) {
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 <= (-260000000.0d0)) then
tmp = x * y
else if (y <= 0.00013d0) 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 <= -260000000.0) {
tmp = x * y;
} else if (y <= 0.00013) {
tmp = z + (x * 0.5);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -260000000.0: tmp = x * y elif y <= 0.00013: tmp = z + (x * 0.5) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -260000000.0) tmp = Float64(x * y); elseif (y <= 0.00013) 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 <= -260000000.0) tmp = x * y; elseif (y <= 0.00013) tmp = z + (x * 0.5); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -260000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.00013], 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 -260000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.00013:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if y < -2.6e8Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 71.6%
if -2.6e8 < y < 1.29999999999999989e-4Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 98.5%
if 1.29999999999999989e-4 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 75.6%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.8e+14) (* x 0.5) (if (<= x 2.1e+57) z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e+14) {
tmp = x * 0.5;
} else if (x <= 2.1e+57) {
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 <= (-1.8d+14)) then
tmp = x * 0.5d0
else if (x <= 2.1d+57) 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 <= -1.8e+14) {
tmp = x * 0.5;
} else if (x <= 2.1e+57) {
tmp = z;
} else {
tmp = x * 0.5;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.8e+14: tmp = x * 0.5 elif x <= 2.1e+57: tmp = z else: tmp = x * 0.5 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.8e+14) tmp = Float64(x * 0.5); elseif (x <= 2.1e+57) tmp = z; else tmp = Float64(x * 0.5); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.8e+14) tmp = x * 0.5; elseif (x <= 2.1e+57) tmp = z; else tmp = x * 0.5; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.8e+14], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 2.1e+57], z, N[(x * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+14}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+57}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5\\
\end{array}
\end{array}
if x < -1.8e14 or 2.09999999999999991e57 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 87.4%
Taylor expanded in y around 0 43.6%
if -1.8e14 < x < 2.09999999999999991e57Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 62.5%
Final simplification53.1%
(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 38.7%
Final simplification38.7%
herbie shell --seed 2023261
(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))