
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
(FPCore (v H) :precision binary64 (if (<= v -1e+156) (atan -1.0) (if (<= v 1.65e+86) (atan (/ v (sqrt (- (* v v) (* 19.6 H))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+156) {
tmp = atan(-1.0);
} else if (v <= 1.65e+86) {
tmp = atan((v / sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = atan(1.0);
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-1d+156)) then
tmp = atan((-1.0d0))
else if (v <= 1.65d+86) then
tmp = atan((v / sqrt(((v * v) - (19.6d0 * h)))))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1e+156) {
tmp = Math.atan(-1.0);
} else if (v <= 1.65e+86) {
tmp = Math.atan((v / Math.sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1e+156: tmp = math.atan(-1.0) elif v <= 1.65e+86: tmp = math.atan((v / math.sqrt(((v * v) - (19.6 * H))))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1e+156) tmp = atan(-1.0); elseif (v <= 1.65e+86) tmp = atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(19.6 * H))))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1e+156) tmp = atan(-1.0); elseif (v <= 1.65e+86) tmp = atan((v / sqrt(((v * v) - (19.6 * H))))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1e+156], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.65e+86], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(19.6 * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+156}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.65 \cdot 10^{+86}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -9.9999999999999998e155Initial program 3.1%
sqr-neg3.1%
sqr-neg3.1%
metadata-eval3.1%
Simplified3.1%
Taylor expanded in v around -inf 100.0%
if -9.9999999999999998e155 < v < 1.65e86Initial program 99.7%
sqr-neg99.7%
sqr-neg99.7%
metadata-eval99.7%
Simplified99.7%
if 1.65e86 < v Initial program 28.2%
sqr-neg28.2%
sqr-neg28.2%
metadata-eval28.2%
Simplified28.2%
Taylor expanded in v around inf 100.0%
(FPCore (v H)
:precision binary64
(if (<= v -3.3e-37)
(atan -1.0)
(if (<= v 9.2e-49)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -3.3e-37) {
tmp = atan(-1.0);
} else if (v <= 9.2e-49) {
tmp = atan((v * sqrt((-0.05102040816326531 / H))));
} else {
tmp = atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-3.3d-37)) then
tmp = atan((-1.0d0))
else if (v <= 9.2d-49) then
tmp = atan((v * sqrt(((-0.05102040816326531d0) / h))))
else
tmp = atan((v / (v + ((-9.8d0) * (h / v)))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -3.3e-37) {
tmp = Math.atan(-1.0);
} else if (v <= 9.2e-49) {
tmp = Math.atan((v * Math.sqrt((-0.05102040816326531 / H))));
} else {
tmp = Math.atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -3.3e-37: tmp = math.atan(-1.0) elif v <= 9.2e-49: tmp = math.atan((v * math.sqrt((-0.05102040816326531 / H)))) else: tmp = math.atan((v / (v + (-9.8 * (H / v))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -3.3e-37) tmp = atan(-1.0); elseif (v <= 9.2e-49) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(Float64(v / Float64(v + Float64(-9.8 * Float64(H / v))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -3.3e-37) tmp = atan(-1.0); elseif (v <= 9.2e-49) tmp = atan((v * sqrt((-0.05102040816326531 / H)))); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -3.3e-37], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 9.2e-49], N[ArcTan[N[(v * N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v / N[(v + N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -3.3 \cdot 10^{-37}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 9.2 \cdot 10^{-49}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -3.29999999999999982e-37Initial program 43.1%
sqr-neg43.1%
sqr-neg43.1%
metadata-eval43.1%
Simplified43.1%
Taylor expanded in v around -inf 94.4%
if -3.29999999999999982e-37 < v < 9.1999999999999996e-49Initial program 99.6%
sqr-neg99.6%
sqr-neg99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in v around 0 99.6%
Taylor expanded in v around 0 88.1%
if 9.1999999999999996e-49 < v Initial program 54.4%
sqr-neg54.4%
sqr-neg54.4%
metadata-eval54.4%
Simplified54.4%
Taylor expanded in H around 0 88.0%
(FPCore (v H) :precision binary64 (if (<= v -7e-153) (atan -1.0) (if (<= v 5.2e-116) (atan (/ 1.0 (/ (* -9.8 (/ H v)) v))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -7e-153) {
tmp = atan(-1.0);
} else if (v <= 5.2e-116) {
tmp = atan((1.0 / ((-9.8 * (H / v)) / v)));
} else {
tmp = atan(1.0);
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-7d-153)) then
tmp = atan((-1.0d0))
else if (v <= 5.2d-116) then
tmp = atan((1.0d0 / (((-9.8d0) * (h / v)) / v)))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -7e-153) {
tmp = Math.atan(-1.0);
} else if (v <= 5.2e-116) {
tmp = Math.atan((1.0 / ((-9.8 * (H / v)) / v)));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -7e-153: tmp = math.atan(-1.0) elif v <= 5.2e-116: tmp = math.atan((1.0 / ((-9.8 * (H / v)) / v))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -7e-153) tmp = atan(-1.0); elseif (v <= 5.2e-116) tmp = atan(Float64(1.0 / Float64(Float64(-9.8 * Float64(H / v)) / v))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -7e-153) tmp = atan(-1.0); elseif (v <= 5.2e-116) tmp = atan((1.0 / ((-9.8 * (H / v)) / v))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -7e-153], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5.2e-116], N[ArcTan[N[(1.0 / N[(N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -7 \cdot 10^{-153}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5.2 \cdot 10^{-116}:\\
\;\;\;\;\tan^{-1} \left(\frac{1}{\frac{-9.8 \cdot \frac{H}{v}}{v}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -6.99999999999999961e-153Initial program 53.2%
sqr-neg53.2%
sqr-neg53.2%
metadata-eval53.2%
Simplified53.2%
Taylor expanded in v around -inf 83.1%
if -6.99999999999999961e-153 < v < 5.2000000000000001e-116Initial program 99.5%
sqr-neg99.5%
sqr-neg99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in H around 0 29.6%
Taylor expanded in v around 0 29.6%
clear-num29.6%
inv-pow29.6%
associate-*r/29.6%
metadata-eval29.6%
associate-/r/29.6%
associate-/l/29.6%
metadata-eval29.6%
frac-times29.6%
associate-/r/29.6%
metadata-eval29.6%
associate-*l*29.6%
*-commutative29.6%
associate-*l/29.6%
metadata-eval29.6%
Applied egg-rr29.6%
unpow-129.6%
associate-*r/29.6%
associate-*l/29.6%
*-commutative29.6%
Simplified29.6%
if 5.2000000000000001e-116 < v Initial program 58.7%
sqr-neg58.7%
sqr-neg58.7%
metadata-eval58.7%
Simplified58.7%
Taylor expanded in v around inf 84.3%
(FPCore (v H) :precision binary64 (if (<= v -4.2e-152) (atan -1.0) (if (<= v 5.2e-116) (atan (/ v (* -9.8 (/ H v)))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -4.2e-152) {
tmp = atan(-1.0);
} else if (v <= 5.2e-116) {
tmp = atan((v / (-9.8 * (H / v))));
} else {
tmp = atan(1.0);
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-4.2d-152)) then
tmp = atan((-1.0d0))
else if (v <= 5.2d-116) then
tmp = atan((v / ((-9.8d0) * (h / v))))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -4.2e-152) {
tmp = Math.atan(-1.0);
} else if (v <= 5.2e-116) {
tmp = Math.atan((v / (-9.8 * (H / v))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -4.2e-152: tmp = math.atan(-1.0) elif v <= 5.2e-116: tmp = math.atan((v / (-9.8 * (H / v)))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -4.2e-152) tmp = atan(-1.0); elseif (v <= 5.2e-116) tmp = atan(Float64(v / Float64(-9.8 * Float64(H / v)))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -4.2e-152) tmp = atan(-1.0); elseif (v <= 5.2e-116) tmp = atan((v / (-9.8 * (H / v)))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -4.2e-152], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5.2e-116], N[ArcTan[N[(v / N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -4.2 \cdot 10^{-152}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5.2 \cdot 10^{-116}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{-9.8 \cdot \frac{H}{v}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -4.19999999999999998e-152Initial program 53.2%
sqr-neg53.2%
sqr-neg53.2%
metadata-eval53.2%
Simplified53.2%
Taylor expanded in v around -inf 83.1%
if -4.19999999999999998e-152 < v < 5.2000000000000001e-116Initial program 99.5%
sqr-neg99.5%
sqr-neg99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in H around 0 29.6%
Taylor expanded in v around 0 29.6%
if 5.2000000000000001e-116 < v Initial program 58.7%
sqr-neg58.7%
sqr-neg58.7%
metadata-eval58.7%
Simplified58.7%
Taylor expanded in v around inf 84.3%
(FPCore (v H) :precision binary64 (if (<= v -8.6e-157) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
double tmp;
if (v <= -8.6e-157) {
tmp = atan(-1.0);
} else {
tmp = atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-8.6d-157)) then
tmp = atan((-1.0d0))
else
tmp = atan((v / (v + ((-9.8d0) * (h / v)))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -8.6e-157) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -8.6e-157: tmp = math.atan(-1.0) else: tmp = math.atan((v / (v + (-9.8 * (H / v))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -8.6e-157) tmp = atan(-1.0); else tmp = atan(Float64(v / Float64(v + Float64(-9.8 * Float64(H / v))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -8.6e-157) tmp = atan(-1.0); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -8.6e-157], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[N[(v / N[(v + N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -8.6 \cdot 10^{-157}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -8.5999999999999995e-157Initial program 53.2%
sqr-neg53.2%
sqr-neg53.2%
metadata-eval53.2%
Simplified53.2%
Taylor expanded in v around -inf 83.1%
if -8.5999999999999995e-157 < v Initial program 72.9%
sqr-neg72.9%
sqr-neg72.9%
metadata-eval72.9%
Simplified72.9%
Taylor expanded in H around 0 65.3%
(FPCore (v H) :precision binary64 (if (<= v -2e-304) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -2e-304) {
tmp = atan(-1.0);
} else {
tmp = atan(1.0);
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-2d-304)) then
tmp = atan((-1.0d0))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -2e-304) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -2e-304: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -2e-304) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -2e-304) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -2e-304], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2 \cdot 10^{-304}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.99999999999999994e-304Initial program 60.3%
sqr-neg60.3%
sqr-neg60.3%
metadata-eval60.3%
Simplified60.3%
Taylor expanded in v around -inf 71.1%
if -1.99999999999999994e-304 < v Initial program 68.6%
sqr-neg68.6%
sqr-neg68.6%
metadata-eval68.6%
Simplified68.6%
Taylor expanded in v around inf 64.9%
(FPCore (v H) :precision binary64 (atan -1.0))
double code(double v, double H) {
return atan(-1.0);
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((-1.0d0))
end function
public static double code(double v, double H) {
return Math.atan(-1.0);
}
def code(v, H): return math.atan(-1.0)
function code(v, H) return atan(-1.0) end
function tmp = code(v, H) tmp = atan(-1.0); end
code[v_, H_] := N[ArcTan[-1.0], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} -1
\end{array}
Initial program 64.3%
sqr-neg64.3%
sqr-neg64.3%
metadata-eval64.3%
Simplified64.3%
Taylor expanded in v around -inf 37.6%
herbie shell --seed 2024147
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))