
(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 5 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 6.6e+94) (atan (/ v (sqrt (fma v v (* H -19.6))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -2e+154) {
tmp = atan(-1.0);
} else if (v <= 6.6e+94) {
tmp = atan((v / sqrt(fma(v, v, (H * -19.6)))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -2e+154) tmp = atan(-1.0); elseif (v <= 6.6e+94) tmp = atan(Float64(v / sqrt(fma(v, v, Float64(H * -19.6))))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -2e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 6.6e+94], N[ArcTan[N[(v / N[Sqrt[N[(v * v + N[(H * -19.6), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 6.6 \cdot 10^{+94}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, H \cdot -19.6\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -2.00000000000000007e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -2.00000000000000007e154 < v < 6.6e94Initial program 99.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
if 6.6e94 < v Initial program 26.9%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(if (<= v -2.25e-67)
(atan (fma H (/ -9.8 (* v v)) -1.0))
(if (<= v 3.7e-22)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -2.25e-67) {
tmp = atan(fma(H, (-9.8 / (v * v)), -1.0));
} else if (v <= 3.7e-22) {
tmp = atan((v * sqrt((-0.05102040816326531 / H))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -2.25e-67) tmp = atan(fma(H, Float64(-9.8 / Float64(v * v)), -1.0)); elseif (v <= 3.7e-22) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -2.25e-67], N[ArcTan[N[(H * N[(-9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 3.7e-22], N[ArcTan[N[(v * N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2.25 \cdot 10^{-67}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{-9.8}{v \cdot v}, -1\right)\right)\\
\mathbf{elif}\;v \leq 3.7 \cdot 10^{-22}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -2.25000000000000008e-67Initial program 54.8%
Taylor expanded in v around -inf
sub-negN/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6487.8
Applied rewrites87.8%
if -2.25000000000000008e-67 < v < 3.7e-22Initial program 99.5%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites99.5%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
lower-/.f64N/A
unpow2N/A
rem-square-sqrt86.1
Applied rewrites86.1%
if 3.7e-22 < v Initial program 50.8%
Taylor expanded in v around inf
Applied rewrites92.6%
Final simplification88.9%
herbie shell --seed 2024228
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))