
(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 (* (+ 0.5 y) x)))
double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((0.5d0 + y) * x)
end function
public static double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
def code(x, y, z): return z + ((0.5 + y) * x)
function code(x, y, z) return Float64(z + Float64(Float64(0.5 + y) * x)) end
function tmp = code(x, y, z) tmp = z + ((0.5 + y) * x); end
code[x_, y_, z_] := N[(z + N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(0.5 + y\right) \cdot x
\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
(if (<= z -0.0023)
z
(if (or (<= z -1.3e-46) (and (not (<= z -5.9e-93)) (<= z 7.8e+88)))
(* (+ 0.5 y) x)
z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.0023) {
tmp = z;
} else if ((z <= -1.3e-46) || (!(z <= -5.9e-93) && (z <= 7.8e+88))) {
tmp = (0.5 + y) * x;
} 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 <= (-0.0023d0)) then
tmp = z
else if ((z <= (-1.3d-46)) .or. (.not. (z <= (-5.9d-93))) .and. (z <= 7.8d+88)) then
tmp = (0.5d0 + y) * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -0.0023) {
tmp = z;
} else if ((z <= -1.3e-46) || (!(z <= -5.9e-93) && (z <= 7.8e+88))) {
tmp = (0.5 + y) * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.0023: tmp = z elif (z <= -1.3e-46) or (not (z <= -5.9e-93) and (z <= 7.8e+88)): tmp = (0.5 + y) * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.0023) tmp = z; elseif ((z <= -1.3e-46) || (!(z <= -5.9e-93) && (z <= 7.8e+88))) tmp = Float64(Float64(0.5 + y) * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.0023) tmp = z; elseif ((z <= -1.3e-46) || (~((z <= -5.9e-93)) && (z <= 7.8e+88))) tmp = (0.5 + y) * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.0023], z, If[Or[LessEqual[z, -1.3e-46], And[N[Not[LessEqual[z, -5.9e-93]], $MachinePrecision], LessEqual[z, 7.8e+88]]], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.0023:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -1.3 \cdot 10^{-46} \lor \neg \left(z \leq -5.9 \cdot 10^{-93}\right) \land z \leq 7.8 \cdot 10^{+88}:\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -0.0023 or -1.3000000000000001e-46 < z < -5.9e-93 or 7.8000000000000002e88 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 73.0%
if -0.0023 < z < -1.3000000000000001e-46 or -5.9e-93 < z < 7.8000000000000002e88Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.9%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (<= y -0.5) (* y x) (if (<= y -1.2e-233) (* 0.5 x) (if (<= y 1.4e+21) z (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = y * x;
} else if (y <= -1.2e-233) {
tmp = 0.5 * x;
} else if (y <= 1.4e+21) {
tmp = z;
} else {
tmp = y * x;
}
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 = y * x
else if (y <= (-1.2d-233)) then
tmp = 0.5d0 * x
else if (y <= 1.4d+21) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = y * x;
} else if (y <= -1.2e-233) {
tmp = 0.5 * x;
} else if (y <= 1.4e+21) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.5: tmp = y * x elif y <= -1.2e-233: tmp = 0.5 * x elif y <= 1.4e+21: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = Float64(y * x); elseif (y <= -1.2e-233) tmp = Float64(0.5 * x); elseif (y <= 1.4e+21) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.5) tmp = y * x; elseif (y <= -1.2e-233) tmp = 0.5 * x; elseif (y <= 1.4e+21) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.2e-233], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 1.4e+21], z, N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.2 \cdot 10^{-233}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+21}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -0.5 or 1.4e21 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 69.0%
if -0.5 < y < -1.19999999999999995e-233Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 58.6%
Taylor expanded in y around 0 58.4%
if -1.19999999999999995e-233 < y < 1.4e21Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 57.2%
Final simplification62.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e+163) (not (<= x 9.6e+31))) (* (+ 0.5 y) x) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e+163) || !(x <= 9.6e+31)) {
tmp = (0.5 + y) * x;
} else {
tmp = z + (y * x);
}
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 <= (-9d+163)) .or. (.not. (x <= 9.6d+31))) then
tmp = (0.5d0 + y) * x
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9e+163) || !(x <= 9.6e+31)) {
tmp = (0.5 + y) * x;
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e+163) or not (x <= 9.6e+31): tmp = (0.5 + y) * x else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e+163) || !(x <= 9.6e+31)) tmp = Float64(Float64(0.5 + y) * x); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9e+163) || ~((x <= 9.6e+31))) tmp = (0.5 + y) * x; else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e+163], N[Not[LessEqual[x, 9.6e+31]], $MachinePrecision]], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+163} \lor \neg \left(x \leq 9.6 \cdot 10^{+31}\right):\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if x < -8.99999999999999976e163 or 9.59999999999999929e31 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.6%
if -8.99999999999999976e163 < x < 9.59999999999999929e31Initial 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 87.9%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -25500000000.0) (not (<= y 0.5))) (+ z (* y x)) (+ z (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -25500000000.0) || !(y <= 0.5)) {
tmp = z + (y * x);
} else {
tmp = z + (0.5 * x);
}
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 <= (-25500000000.0d0)) .or. (.not. (y <= 0.5d0))) then
tmp = z + (y * x)
else
tmp = z + (0.5d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -25500000000.0) || !(y <= 0.5)) {
tmp = z + (y * x);
} else {
tmp = z + (0.5 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -25500000000.0) or not (y <= 0.5): tmp = z + (y * x) else: tmp = z + (0.5 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -25500000000.0) || !(y <= 0.5)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(z + Float64(0.5 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -25500000000.0) || ~((y <= 0.5))) tmp = z + (y * x); else tmp = z + (0.5 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -25500000000.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -25500000000 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + 0.5 \cdot x\\
\end{array}
\end{array}
if y < -2.55e10 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 98.9%
if -2.55e10 < y < 0.5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 98.7%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.3e+149) (* 0.5 x) (if (<= x 9.6e+31) z (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+149) {
tmp = 0.5 * x;
} else if (x <= 9.6e+31) {
tmp = z;
} else {
tmp = 0.5 * x;
}
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.3d+149)) then
tmp = 0.5d0 * x
else if (x <= 9.6d+31) then
tmp = z
else
tmp = 0.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+149) {
tmp = 0.5 * x;
} else if (x <= 9.6e+31) {
tmp = z;
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e+149: tmp = 0.5 * x elif x <= 9.6e+31: tmp = z else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+149) tmp = Float64(0.5 * x); elseif (x <= 9.6e+31) tmp = z; else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.3e+149) tmp = 0.5 * x; elseif (x <= 9.6e+31) tmp = z; else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+149], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, 9.6e+31], z, N[(0.5 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+149}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{+31}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if x < -1.29999999999999989e149 or 9.59999999999999929e31 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.8%
Taylor expanded in y around 0 48.4%
if -1.29999999999999989e149 < x < 9.59999999999999929e31Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 63.2%
Final simplification57.5%
(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 43.5%
Final simplification43.5%
herbie shell --seed 2023252
(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))