
(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 6 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 -5e+154) (atan -1.0) (if (<= v 2e+86) (atan (/ v (sqrt (- (* v v) (* 19.6 H))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -5e+154) {
tmp = atan(-1.0);
} else if (v <= 2e+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 <= (-5d+154)) then
tmp = atan((-1.0d0))
else if (v <= 2d+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 <= -5e+154) {
tmp = Math.atan(-1.0);
} else if (v <= 2e+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 <= -5e+154: tmp = math.atan(-1.0) elif v <= 2e+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 <= -5e+154) tmp = atan(-1.0); elseif (v <= 2e+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 <= -5e+154) tmp = atan(-1.0); elseif (v <= 2e+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, -5e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2e+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 -5 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2 \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 < -5.00000000000000004e154Initial program 3.1%
sqr-neg3.1%
sqr-neg3.1%
metadata-eval3.1%
Simplified3.1%
Taylor expanded in v around -inf 100.0%
if -5.00000000000000004e154 < v < 2e86Initial program 99.7%
sqr-neg99.7%
sqr-neg99.7%
metadata-eval99.7%
Simplified99.7%
if 2e86 < v Initial program 32.6%
sqr-neg32.6%
sqr-neg32.6%
metadata-eval32.6%
Simplified32.6%
Taylor expanded in v around inf 100.0%
(FPCore (v H)
:precision binary64
(if (<= v -3.9e-15)
(atan -1.0)
(if (<= v 2.1e-55)
(atan (/ v (sqrt (* H -19.6))))
(atan (* v (/ 1.0 (+ v (* -9.8 (/ H v)))))))))
double code(double v, double H) {
double tmp;
if (v <= -3.9e-15) {
tmp = atan(-1.0);
} else if (v <= 2.1e-55) {
tmp = atan((v / sqrt((H * -19.6))));
} else {
tmp = atan((v * (1.0 / (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.9d-15)) then
tmp = atan((-1.0d0))
else if (v <= 2.1d-55) then
tmp = atan((v / sqrt((h * (-19.6d0)))))
else
tmp = atan((v * (1.0d0 / (v + ((-9.8d0) * (h / v))))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -3.9e-15) {
tmp = Math.atan(-1.0);
} else if (v <= 2.1e-55) {
tmp = Math.atan((v / Math.sqrt((H * -19.6))));
} else {
tmp = Math.atan((v * (1.0 / (v + (-9.8 * (H / v))))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -3.9e-15: tmp = math.atan(-1.0) elif v <= 2.1e-55: tmp = math.atan((v / math.sqrt((H * -19.6)))) else: tmp = math.atan((v * (1.0 / (v + (-9.8 * (H / v)))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -3.9e-15) tmp = atan(-1.0); elseif (v <= 2.1e-55) tmp = atan(Float64(v / sqrt(Float64(H * -19.6)))); else tmp = atan(Float64(v * Float64(1.0 / Float64(v + Float64(-9.8 * Float64(H / v)))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -3.9e-15) tmp = atan(-1.0); elseif (v <= 2.1e-55) tmp = atan((v / sqrt((H * -19.6)))); else tmp = atan((v * (1.0 / (v + (-9.8 * (H / v)))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -3.9e-15], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2.1e-55], N[ArcTan[N[(v / N[Sqrt[N[(H * -19.6), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v * N[(1.0 / N[(v + N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -3.9 \cdot 10^{-15}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2.1 \cdot 10^{-55}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{H \cdot -19.6}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \frac{1}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -3.90000000000000026e-15Initial program 54.6%
sqr-neg54.6%
sqr-neg54.6%
metadata-eval54.6%
Simplified54.6%
Taylor expanded in v around -inf 92.4%
if -3.90000000000000026e-15 < v < 2.1000000000000002e-55Initial program 99.5%
sqr-neg99.5%
sqr-neg99.5%
metadata-eval99.5%
Simplified99.5%
add-cube-cbrt98.8%
pow398.8%
Applied egg-rr98.8%
Taylor expanded in H around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt88.5%
rem-cube-cbrt90.0%
distribute-lft-neg-in90.0%
metadata-eval90.0%
*-lft-identity90.0%
*-commutative90.0%
Simplified90.0%
if 2.1000000000000002e-55 < v Initial program 57.3%
sqr-neg57.3%
sqr-neg57.3%
metadata-eval57.3%
Simplified57.3%
add-cube-cbrt57.2%
pow357.2%
Applied egg-rr57.2%
Taylor expanded in H around 0 89.5%
rem-cube-cbrt89.5%
associate-/l*90.4%
Simplified90.4%
Taylor expanded in H around inf 90.4%
div-inv90.4%
cancel-sign-sub-inv90.4%
metadata-eval90.4%
Applied egg-rr90.4%
Final simplification90.9%
(FPCore (v H) :precision binary64 (if (<= v -1e-178) (atan -1.0) (atan (* v (/ 1.0 (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -1e-178) {
tmp = atan(-1.0);
} else {
tmp = atan((v * (1.0 / (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 <= (-1d-178)) then
tmp = atan((-1.0d0))
else
tmp = atan((v * (1.0d0 / (v + ((-9.8d0) * (h / v))))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1e-178) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan((v * (1.0 / (v + (-9.8 * (H / v))))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1e-178: tmp = math.atan(-1.0) else: tmp = math.atan((v * (1.0 / (v + (-9.8 * (H / v)))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -1e-178) tmp = atan(-1.0); else tmp = atan(Float64(v * Float64(1.0 / Float64(v + Float64(-9.8 * Float64(H / v)))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1e-178) tmp = atan(-1.0); else tmp = atan((v * (1.0 / (v + (-9.8 * (H / v)))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1e-178], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[N[(v * N[(1.0 / N[(v + N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{-178}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \frac{1}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -9.9999999999999995e-179Initial program 66.4%
sqr-neg66.4%
sqr-neg66.4%
metadata-eval66.4%
Simplified66.4%
Taylor expanded in v around -inf 74.4%
if -9.9999999999999995e-179 < v Initial program 68.6%
sqr-neg68.6%
sqr-neg68.6%
metadata-eval68.6%
Simplified68.6%
add-cube-cbrt68.3%
pow368.4%
Applied egg-rr68.4%
Taylor expanded in H around 0 70.6%
rem-cube-cbrt70.6%
associate-/l*71.3%
Simplified71.3%
Taylor expanded in H around inf 71.3%
div-inv71.3%
cancel-sign-sub-inv71.3%
metadata-eval71.3%
Applied egg-rr71.3%
(FPCore (v H) :precision binary64 (if (<= v -1.2e-177) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
double tmp;
if (v <= -1.2e-177) {
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 <= (-1.2d-177)) 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 <= -1.2e-177) {
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 <= -1.2e-177: 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 <= -1.2e-177) 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 <= -1.2e-177) tmp = atan(-1.0); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.2e-177], 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 -1.2 \cdot 10^{-177}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -1.1999999999999999e-177Initial program 66.4%
sqr-neg66.4%
sqr-neg66.4%
metadata-eval66.4%
Simplified66.4%
Taylor expanded in v around -inf 74.4%
if -1.1999999999999999e-177 < v Initial program 68.6%
sqr-neg68.6%
sqr-neg68.6%
metadata-eval68.6%
Simplified68.6%
Taylor expanded in H around 0 71.3%
(FPCore (v H) :precision binary64 (if (<= v -5e-310) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -5e-310) {
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 <= (-5d-310)) 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 <= -5e-310) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -5e-310: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -5e-310) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -5e-310) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -5e-310], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -4.999999999999985e-310Initial program 70.2%
sqr-neg70.2%
sqr-neg70.2%
metadata-eval70.2%
Simplified70.2%
Taylor expanded in v around -inf 66.2%
if -4.999999999999985e-310 < v Initial program 65.4%
sqr-neg65.4%
sqr-neg65.4%
metadata-eval65.4%
Simplified65.4%
Taylor expanded in v around inf 74.4%
(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 67.7%
sqr-neg67.7%
sqr-neg67.7%
metadata-eval67.7%
Simplified67.7%
Taylor expanded in v around -inf 32.2%
herbie shell --seed 2024186
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))