
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / 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 * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / 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 * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* x (/ y z))))
double code(double x, double y, double z) {
return x + (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 + (x * (y / z))
end function
public static double code(double x, double y, double z) {
return x + (x * (y / z));
}
def code(x, y, z): return x + (x * (y / z))
function code(x, y, z) return Float64(x + Float64(x * Float64(y / z))) end
function tmp = code(x, y, z) tmp = x + (x * (y / z)); end
code[x_, y_, z_] := N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \frac{y}{z}
\end{array}
Initial program 87.2%
associate-*l/84.2%
distribute-rgt-in80.2%
*-commutative80.2%
associate-/r/93.7%
*-inverses93.7%
/-rgt-identity93.7%
associate-*r/94.3%
*-commutative94.3%
associate-*r/97.7%
fma-def97.7%
Simplified97.7%
fma-udef97.7%
Applied egg-rr97.7%
Final simplification97.7%
(FPCore (x y z)
:precision binary64
(if (<= z -1.65e-77)
x
(if (or (<= z 3.8e-156) (and (not (<= z 6.3e-93)) (<= z 2.5e+73)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.65e-77) {
tmp = x;
} else if ((z <= 3.8e-156) || (!(z <= 6.3e-93) && (z <= 2.5e+73))) {
tmp = x * (y / z);
} else {
tmp = 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 (z <= (-1.65d-77)) then
tmp = x
else if ((z <= 3.8d-156) .or. (.not. (z <= 6.3d-93)) .and. (z <= 2.5d+73)) then
tmp = x * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.65e-77) {
tmp = x;
} else if ((z <= 3.8e-156) || (!(z <= 6.3e-93) && (z <= 2.5e+73))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.65e-77: tmp = x elif (z <= 3.8e-156) or (not (z <= 6.3e-93) and (z <= 2.5e+73)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.65e-77) tmp = x; elseif ((z <= 3.8e-156) || (!(z <= 6.3e-93) && (z <= 2.5e+73))) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.65e-77) tmp = x; elseif ((z <= 3.8e-156) || (~((z <= 6.3e-93)) && (z <= 2.5e+73))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.65e-77], x, If[Or[LessEqual[z, 3.8e-156], And[N[Not[LessEqual[z, 6.3e-93]], $MachinePrecision], LessEqual[z, 2.5e+73]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{-77}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-156} \lor \neg \left(z \leq 6.3 \cdot 10^{-93}\right) \land z \leq 2.5 \cdot 10^{+73}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.64999999999999996e-77 or 3.80000000000000008e-156 < z < 6.30000000000000028e-93 or 2.49999999999999988e73 < z Initial program 80.5%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in z around inf 79.1%
if -1.64999999999999996e-77 < z < 3.80000000000000008e-156 or 6.30000000000000028e-93 < z < 2.49999999999999988e73Initial program 95.1%
associate-*l/89.3%
Simplified89.3%
Taylor expanded in z around 0 78.3%
*-commutative78.3%
associate-*r/77.0%
Simplified77.0%
Final simplification78.2%
(FPCore (x y z)
:precision binary64
(if (<= z -4.8e-76)
x
(if (<= z 3.8e-156)
(* x (/ y z))
(if (<= z 2.9e-91) x (if (<= z 5.5e+72) (* y (/ x z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e-76) {
tmp = x;
} else if (z <= 3.8e-156) {
tmp = x * (y / z);
} else if (z <= 2.9e-91) {
tmp = x;
} else if (z <= 5.5e+72) {
tmp = y * (x / z);
} else {
tmp = 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 (z <= (-4.8d-76)) then
tmp = x
else if (z <= 3.8d-156) then
tmp = x * (y / z)
else if (z <= 2.9d-91) then
tmp = x
else if (z <= 5.5d+72) then
tmp = y * (x / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e-76) {
tmp = x;
} else if (z <= 3.8e-156) {
tmp = x * (y / z);
} else if (z <= 2.9e-91) {
tmp = x;
} else if (z <= 5.5e+72) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.8e-76: tmp = x elif z <= 3.8e-156: tmp = x * (y / z) elif z <= 2.9e-91: tmp = x elif z <= 5.5e+72: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.8e-76) tmp = x; elseif (z <= 3.8e-156) tmp = Float64(x * Float64(y / z)); elseif (z <= 2.9e-91) tmp = x; elseif (z <= 5.5e+72) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.8e-76) tmp = x; elseif (z <= 3.8e-156) tmp = x * (y / z); elseif (z <= 2.9e-91) tmp = x; elseif (z <= 5.5e+72) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.8e-76], x, If[LessEqual[z, 3.8e-156], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.9e-91], x, If[LessEqual[z, 5.5e+72], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-76}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-156}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{-91}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+72}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.80000000000000026e-76 or 3.80000000000000008e-156 < z < 2.9000000000000001e-91 or 5.5e72 < z Initial program 80.5%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in z around inf 79.1%
if -4.80000000000000026e-76 < z < 3.80000000000000008e-156Initial program 95.5%
associate-*l/89.1%
Simplified89.1%
Taylor expanded in z around 0 86.0%
*-commutative86.0%
associate-*r/82.3%
Simplified82.3%
if 2.9000000000000001e-91 < z < 5.5e72Initial program 93.8%
associate-*l/89.6%
Simplified89.6%
Taylor expanded in z around 0 55.9%
associate-*r/61.9%
Simplified61.9%
Final simplification78.2%
(FPCore (x y z)
:precision binary64
(if (<= z -3.8e-83)
x
(if (<= z 3.8e-156)
(/ x (/ z y))
(if (<= z 2.9e-92) x (if (<= z 5.5e+72) (* y (/ x z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.8e-83) {
tmp = x;
} else if (z <= 3.8e-156) {
tmp = x / (z / y);
} else if (z <= 2.9e-92) {
tmp = x;
} else if (z <= 5.5e+72) {
tmp = y * (x / z);
} else {
tmp = 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 (z <= (-3.8d-83)) then
tmp = x
else if (z <= 3.8d-156) then
tmp = x / (z / y)
else if (z <= 2.9d-92) then
tmp = x
else if (z <= 5.5d+72) then
tmp = y * (x / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.8e-83) {
tmp = x;
} else if (z <= 3.8e-156) {
tmp = x / (z / y);
} else if (z <= 2.9e-92) {
tmp = x;
} else if (z <= 5.5e+72) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.8e-83: tmp = x elif z <= 3.8e-156: tmp = x / (z / y) elif z <= 2.9e-92: tmp = x elif z <= 5.5e+72: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.8e-83) tmp = x; elseif (z <= 3.8e-156) tmp = Float64(x / Float64(z / y)); elseif (z <= 2.9e-92) tmp = x; elseif (z <= 5.5e+72) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.8e-83) tmp = x; elseif (z <= 3.8e-156) tmp = x / (z / y); elseif (z <= 2.9e-92) tmp = x; elseif (z <= 5.5e+72) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.8e-83], x, If[LessEqual[z, 3.8e-156], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.9e-92], x, If[LessEqual[z, 5.5e+72], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-83}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-156}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{-92}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+72}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.79999999999999977e-83 or 3.80000000000000008e-156 < z < 2.89999999999999985e-92 or 5.5e72 < z Initial program 80.5%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in z around inf 79.1%
if -3.79999999999999977e-83 < z < 3.80000000000000008e-156Initial program 95.5%
associate-*l/89.1%
Simplified89.1%
Taylor expanded in z around 0 86.0%
*-commutative86.0%
associate-*r/82.3%
Simplified82.3%
clear-num82.2%
un-div-inv82.5%
Applied egg-rr82.5%
if 2.89999999999999985e-92 < z < 5.5e72Initial program 93.8%
associate-*l/89.6%
Simplified89.6%
Taylor expanded in z around 0 55.9%
associate-*r/61.9%
Simplified61.9%
Final simplification78.3%
(FPCore (x y z)
:precision binary64
(if (<= z -2.65e-86)
x
(if (<= z 3.8e-156)
(/ (* x y) z)
(if (<= z 5.2e-93) x (if (<= z 5.5e+72) (* y (/ x z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.65e-86) {
tmp = x;
} else if (z <= 3.8e-156) {
tmp = (x * y) / z;
} else if (z <= 5.2e-93) {
tmp = x;
} else if (z <= 5.5e+72) {
tmp = y * (x / z);
} else {
tmp = 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 (z <= (-2.65d-86)) then
tmp = x
else if (z <= 3.8d-156) then
tmp = (x * y) / z
else if (z <= 5.2d-93) then
tmp = x
else if (z <= 5.5d+72) then
tmp = y * (x / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.65e-86) {
tmp = x;
} else if (z <= 3.8e-156) {
tmp = (x * y) / z;
} else if (z <= 5.2e-93) {
tmp = x;
} else if (z <= 5.5e+72) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.65e-86: tmp = x elif z <= 3.8e-156: tmp = (x * y) / z elif z <= 5.2e-93: tmp = x elif z <= 5.5e+72: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.65e-86) tmp = x; elseif (z <= 3.8e-156) tmp = Float64(Float64(x * y) / z); elseif (z <= 5.2e-93) tmp = x; elseif (z <= 5.5e+72) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.65e-86) tmp = x; elseif (z <= 3.8e-156) tmp = (x * y) / z; elseif (z <= 5.2e-93) tmp = x; elseif (z <= 5.5e+72) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.65e-86], x, If[LessEqual[z, 3.8e-156], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[z, 5.2e-93], x, If[LessEqual[z, 5.5e+72], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.65 \cdot 10^{-86}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-156}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{-93}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+72}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.6499999999999998e-86 or 3.80000000000000008e-156 < z < 5.1999999999999997e-93 or 5.5e72 < z Initial program 80.5%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in z around inf 79.1%
if -2.6499999999999998e-86 < z < 3.80000000000000008e-156Initial program 95.5%
associate-*l/89.1%
Simplified89.1%
Taylor expanded in z around 0 86.0%
if 5.1999999999999997e-93 < z < 5.5e72Initial program 93.8%
associate-*l/89.6%
Simplified89.6%
Taylor expanded in z around 0 55.9%
associate-*r/61.9%
Simplified61.9%
Final simplification79.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (/ x z) (+ y z))))
(if (<= z -1.45e-251)
t_0
(if (<= z 1e-218) (/ (* x y) z) (if (<= z 7e+93) t_0 x)))))
double code(double x, double y, double z) {
double t_0 = (x / z) * (y + z);
double tmp;
if (z <= -1.45e-251) {
tmp = t_0;
} else if (z <= 1e-218) {
tmp = (x * y) / z;
} else if (z <= 7e+93) {
tmp = t_0;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = (x / z) * (y + z)
if (z <= (-1.45d-251)) then
tmp = t_0
else if (z <= 1d-218) then
tmp = (x * y) / z
else if (z <= 7d+93) then
tmp = t_0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x / z) * (y + z);
double tmp;
if (z <= -1.45e-251) {
tmp = t_0;
} else if (z <= 1e-218) {
tmp = (x * y) / z;
} else if (z <= 7e+93) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = (x / z) * (y + z) tmp = 0 if z <= -1.45e-251: tmp = t_0 elif z <= 1e-218: tmp = (x * y) / z elif z <= 7e+93: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(x / z) * Float64(y + z)) tmp = 0.0 if (z <= -1.45e-251) tmp = t_0; elseif (z <= 1e-218) tmp = Float64(Float64(x * y) / z); elseif (z <= 7e+93) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x / z) * (y + z); tmp = 0.0; if (z <= -1.45e-251) tmp = t_0; elseif (z <= 1e-218) tmp = (x * y) / z; elseif (z <= 7e+93) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / z), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.45e-251], t$95$0, If[LessEqual[z, 1e-218], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[z, 7e+93], t$95$0, x]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{z} \cdot \left(y + z\right)\\
\mathbf{if}\;z \leq -1.45 \cdot 10^{-251}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 10^{-218}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+93}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.45e-251 or 1e-218 < z < 6.99999999999999996e93Initial program 87.3%
associate-*l/89.9%
Simplified89.9%
if -1.45e-251 < z < 1e-218Initial program 99.9%
associate-*l/71.9%
Simplified71.9%
Taylor expanded in z around 0 97.2%
if 6.99999999999999996e93 < z Initial program 77.1%
associate-*l/67.6%
Simplified67.6%
Taylor expanded in z around inf 97.7%
Final simplification92.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 87.2%
associate-*l/84.2%
Simplified84.2%
Taylor expanded in z around inf 51.9%
Final simplification51.9%
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
return x / (z / (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 / (z / (y + z))
end function
public static double code(double x, double y, double z) {
return x / (z / (y + z));
}
def code(x, y, z): return x / (z / (y + z))
function code(x, y, z) return Float64(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2023240
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))