
(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 -2e+154)
(atan -1.0)
(if (<= v 5.8e+94)
(atan (* v (pow (+ (pow v 2.0) (* H -19.6)) -0.5)))
(atan (/ v (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -2e+154) {
tmp = atan(-1.0);
} else if (v <= 5.8e+94) {
tmp = atan((v * pow((pow(v, 2.0) + (H * -19.6)), -0.5)));
} 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 <= (-2d+154)) then
tmp = atan((-1.0d0))
else if (v <= 5.8d+94) then
tmp = atan((v * (((v ** 2.0d0) + (h * (-19.6d0))) ** (-0.5d0))))
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 <= -2e+154) {
tmp = Math.atan(-1.0);
} else if (v <= 5.8e+94) {
tmp = Math.atan((v * Math.pow((Math.pow(v, 2.0) + (H * -19.6)), -0.5)));
} else {
tmp = Math.atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -2e+154: tmp = math.atan(-1.0) elif v <= 5.8e+94: tmp = math.atan((v * math.pow((math.pow(v, 2.0) + (H * -19.6)), -0.5))) else: tmp = math.atan((v / (v + (-9.8 * (H / v))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -2e+154) tmp = atan(-1.0); elseif (v <= 5.8e+94) tmp = atan(Float64(v * (Float64((v ^ 2.0) + Float64(H * -19.6)) ^ -0.5))); 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 <= -2e+154) tmp = atan(-1.0); elseif (v <= 5.8e+94) tmp = atan((v * (((v ^ 2.0) + (H * -19.6)) ^ -0.5))); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -2e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5.8e+94], N[ArcTan[N[(v * N[Power[N[(N[Power[v, 2.0], $MachinePrecision] + N[(H * -19.6), $MachinePrecision]), $MachinePrecision], -0.5], $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 -2 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5.8 \cdot 10^{+94}:\\
\;\;\;\;\tan^{-1} \left(v \cdot {\left({v}^{2} + H \cdot -19.6\right)}^{-0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -2.00000000000000007e154Initial program 3.0%
sqr-neg3.0%
sqr-neg3.0%
metadata-eval3.0%
Simplified3.0%
Taylor expanded in v around -inf 100.0%
if -2.00000000000000007e154 < v < 5.7999999999999997e94Initial program 99.7%
sqr-neg99.7%
sqr-neg99.7%
metadata-eval99.7%
Simplified99.7%
clear-num99.7%
associate-/r/99.7%
pow1/299.7%
pow-flip99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-define99.8%
metadata-eval99.8%
pow299.8%
metadata-eval99.8%
Applied egg-rr99.8%
fma-undefine99.8%
+-commutative99.8%
Applied egg-rr99.8%
if 5.7999999999999997e94 < v Initial program 22.8%
sqr-neg22.8%
sqr-neg22.8%
metadata-eval22.8%
Simplified22.8%
Taylor expanded in H around 0 100.0%
Final simplification99.8%
(FPCore (v H)
:precision binary64
(if (<= v -2e+154)
(atan -1.0)
(if (<= v 5.8e+94)
(atan (/ v (sqrt (- (* v v) (* H 19.6)))))
(atan (/ v (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -2e+154) {
tmp = atan(-1.0);
} else if (v <= 5.8e+94) {
tmp = atan((v / sqrt(((v * v) - (H * 19.6)))));
} 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 <= (-2d+154)) then
tmp = atan((-1.0d0))
else if (v <= 5.8d+94) then
tmp = atan((v / sqrt(((v * v) - (h * 19.6d0)))))
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 <= -2e+154) {
tmp = Math.atan(-1.0);
} else if (v <= 5.8e+94) {
tmp = Math.atan((v / Math.sqrt(((v * v) - (H * 19.6)))));
} else {
tmp = Math.atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -2e+154: tmp = math.atan(-1.0) elif v <= 5.8e+94: tmp = math.atan((v / math.sqrt(((v * v) - (H * 19.6))))) else: tmp = math.atan((v / (v + (-9.8 * (H / v))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -2e+154) tmp = atan(-1.0); elseif (v <= 5.8e+94) tmp = atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(H * 19.6))))); 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 <= -2e+154) tmp = atan(-1.0); elseif (v <= 5.8e+94) tmp = atan((v / sqrt(((v * v) - (H * 19.6))))); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -2e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5.8e+94], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(H * 19.6), $MachinePrecision]), $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 -2 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5.8 \cdot 10^{+94}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - H \cdot 19.6}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -2.00000000000000007e154Initial program 3.0%
sqr-neg3.0%
sqr-neg3.0%
metadata-eval3.0%
Simplified3.0%
Taylor expanded in v around -inf 100.0%
if -2.00000000000000007e154 < v < 5.7999999999999997e94Initial program 99.7%
sqr-neg99.7%
sqr-neg99.7%
metadata-eval99.7%
Simplified99.7%
if 5.7999999999999997e94 < v Initial program 22.8%
sqr-neg22.8%
sqr-neg22.8%
metadata-eval22.8%
Simplified22.8%
Taylor expanded in H around 0 100.0%
Final simplification99.8%
(FPCore (v H)
:precision binary64
(if (<= v -1e-33)
(atan -1.0)
(if (<= v 1.9e-12)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -1e-33) {
tmp = atan(-1.0);
} else if (v <= 1.9e-12) {
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 <= (-1d-33)) then
tmp = atan((-1.0d0))
else if (v <= 1.9d-12) 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 <= -1e-33) {
tmp = Math.atan(-1.0);
} else if (v <= 1.9e-12) {
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 <= -1e-33: tmp = math.atan(-1.0) elif v <= 1.9e-12: 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 <= -1e-33) tmp = atan(-1.0); elseif (v <= 1.9e-12) 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 <= -1e-33) tmp = atan(-1.0); elseif (v <= 1.9e-12) 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, -1e-33], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.9e-12], 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 -1 \cdot 10^{-33}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.9 \cdot 10^{-12}:\\
\;\;\;\;\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 < -1.0000000000000001e-33Initial program 55.4%
sqr-neg55.4%
sqr-neg55.4%
metadata-eval55.4%
Simplified55.4%
Taylor expanded in v around -inf 90.7%
if -1.0000000000000001e-33 < v < 1.89999999999999998e-12Initial program 99.5%
sqr-neg99.5%
sqr-neg99.5%
metadata-eval99.5%
Simplified99.5%
clear-num99.5%
associate-/r/99.5%
pow1/299.5%
pow-flip99.6%
sub-neg99.6%
+-commutative99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
fma-define99.6%
metadata-eval99.6%
pow299.6%
metadata-eval99.6%
Applied egg-rr99.6%
Taylor expanded in H around inf 88.4%
*-commutative88.4%
Simplified88.4%
add-sqr-sqrt88.1%
sqrt-unprod88.4%
pow-prod-up88.4%
metadata-eval88.4%
Applied egg-rr88.4%
unpow-188.4%
*-commutative88.4%
associate-/r*88.4%
metadata-eval88.5%
Simplified88.5%
if 1.89999999999999998e-12 < v Initial program 45.1%
sqr-neg45.1%
sqr-neg45.1%
metadata-eval45.1%
Simplified45.1%
Taylor expanded in H around 0 92.7%
Final simplification90.6%
(FPCore (v H) :precision binary64 (if (<= v -2.3e-173) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
double tmp;
if (v <= -2.3e-173) {
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 <= (-2.3d-173)) 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 <= -2.3e-173) {
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 <= -2.3e-173: 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 <= -2.3e-173) 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 <= -2.3e-173) tmp = atan(-1.0); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -2.3e-173], 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 -2.3 \cdot 10^{-173}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -2.29999999999999988e-173Initial program 66.7%
sqr-neg66.7%
sqr-neg66.7%
metadata-eval66.7%
Simplified66.7%
Taylor expanded in v around -inf 74.2%
if -2.29999999999999988e-173 < v Initial program 67.0%
sqr-neg67.0%
sqr-neg67.0%
metadata-eval67.0%
Simplified67.0%
Taylor expanded in H around 0 66.0%
(FPCore (v H) :precision binary64 (if (<= v -5.2e-296) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -5.2e-296) {
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 <= (-5.2d-296)) 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 <= -5.2e-296) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -5.2e-296: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -5.2e-296) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -5.2e-296) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -5.2e-296], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -5.2 \cdot 10^{-296}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -5.2000000000000001e-296Initial program 70.0%
sqr-neg70.0%
sqr-neg70.0%
metadata-eval70.0%
Simplified70.0%
Taylor expanded in v around -inf 67.2%
if -5.2000000000000001e-296 < v Initial program 63.7%
sqr-neg63.7%
sqr-neg63.7%
metadata-eval63.7%
Simplified63.7%
Taylor expanded in v around inf 64.1%
(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 66.9%
sqr-neg66.9%
sqr-neg66.9%
metadata-eval66.9%
Simplified66.9%
Taylor expanded in v around -inf 35.0%
herbie shell --seed 2024103
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))