
(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+154)
(atan -1.0)
(if (<= v 3e+125)
(atan (* v (sqrt (/ 1.0 (fma v v (* H -19.6))))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(-1.0);
} else if (v <= 3e+125) {
tmp = atan((v * sqrt((1.0 / fma(v, v, (H * -19.6))))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 3e+125) tmp = atan(Float64(v * sqrt(Float64(1.0 / fma(v, v, Float64(H * -19.6)))))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -1e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 3e+125], N[ArcTan[N[(v * N[Sqrt[N[(1.0 / N[(v * v + N[(H * -19.6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 3 \cdot 10^{+125}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{1}{\mathsf{fma}\left(v, v, H \cdot -19.6\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.00000000000000004e154Initial program 5.5%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -1.00000000000000004e154 < v < 3.00000000000000015e125Initial program 99.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
div-invN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.8%
if 3.00000000000000015e125 < v Initial program 18.3%
Taylor expanded in v around inf
Applied rewrites100.0%
Final simplification99.8%
(FPCore (v H) :precision binary64 (if (<= v -1.4e+154) (atan -1.0) (if (<= v 3e+125) (atan (/ v (sqrt (fma v v (* H -19.6))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.4e+154) {
tmp = atan(-1.0);
} else if (v <= 3e+125) {
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 <= -1.4e+154) tmp = atan(-1.0); elseif (v <= 3e+125) 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, -1.4e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 3e+125], 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 -1.4 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 3 \cdot 10^{+125}:\\
\;\;\;\;\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 < -1.4e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -1.4e154 < v < 3.00000000000000015e125Initial program 99.7%
lift-*.f64N/A
lift-*.f64N/A
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.7
Applied rewrites99.7%
if 3.00000000000000015e125 < v Initial program 18.3%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(if (<= v -6.6e-76)
(atan -1.0)
(if (<= v 3.5e-82)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (fma H (/ -9.8 v) v))))))
double code(double v, double H) {
double tmp;
if (v <= -6.6e-76) {
tmp = atan(-1.0);
} else if (v <= 3.5e-82) {
tmp = atan((v * sqrt((-0.05102040816326531 / H))));
} else {
tmp = atan((v / fma(H, (-9.8 / v), v)));
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -6.6e-76) tmp = atan(-1.0); elseif (v <= 3.5e-82) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(Float64(v / fma(H, Float64(-9.8 / v), v))); end return tmp end
code[v_, H_] := If[LessEqual[v, -6.6e-76], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 3.5e-82], N[ArcTan[N[(v * N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v / N[(H * N[(-9.8 / v), $MachinePrecision] + v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -6.6 \cdot 10^{-76}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 3.5 \cdot 10^{-82}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\mathsf{fma}\left(H, \frac{-9.8}{v}, v\right)}\right)\\
\end{array}
\end{array}
if v < -6.59999999999999967e-76Initial program 54.9%
Taylor expanded in v around -inf
Applied rewrites92.7%
if -6.59999999999999967e-76 < v < 3.4999999999999999e-82Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
div-invN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.7%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
lower-/.f64N/A
unpow2N/A
rem-square-sqrt97.4
Applied rewrites97.4%
if 3.4999999999999999e-82 < v Initial program 57.4%
Taylor expanded in H around 0
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-*r/N/A
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6488.9
Applied rewrites88.9%
Final simplification92.5%
(FPCore (v H)
:precision binary64
(if (<= v -6.6e-76)
(atan -1.0)
(if (<= v 3.7e-82)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -6.6e-76) {
tmp = atan(-1.0);
} else if (v <= 3.7e-82) {
tmp = atan((v * sqrt((-0.05102040816326531 / 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 <= (-6.6d-76)) then
tmp = atan((-1.0d0))
else if (v <= 3.7d-82) then
tmp = atan((v * sqrt(((-0.05102040816326531d0) / h))))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -6.6e-76) {
tmp = Math.atan(-1.0);
} else if (v <= 3.7e-82) {
tmp = Math.atan((v * Math.sqrt((-0.05102040816326531 / H))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -6.6e-76: tmp = math.atan(-1.0) elif v <= 3.7e-82: tmp = math.atan((v * math.sqrt((-0.05102040816326531 / H)))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -6.6e-76) tmp = atan(-1.0); elseif (v <= 3.7e-82) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -6.6e-76) tmp = atan(-1.0); elseif (v <= 3.7e-82) tmp = atan((v * sqrt((-0.05102040816326531 / H)))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -6.6e-76], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 3.7e-82], 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 -6.6 \cdot 10^{-76}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 3.7 \cdot 10^{-82}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -6.59999999999999967e-76Initial program 54.9%
Taylor expanded in v around -inf
Applied rewrites92.7%
if -6.59999999999999967e-76 < v < 3.7000000000000001e-82Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
div-invN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.7%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
lower-/.f64N/A
unpow2N/A
rem-square-sqrt97.4
Applied rewrites97.4%
if 3.7000000000000001e-82 < v Initial program 57.4%
Taylor expanded in v around inf
Applied rewrites88.8%
Final simplification92.5%
(FPCore (v H)
:precision binary64
(if (<= v -1.5e-185)
(atan -1.0)
(if (<= v 4.1e-102)
(atan (* (* v -0.10204081632653061) (/ v H)))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.5e-185) {
tmp = atan(-1.0);
} else if (v <= 4.1e-102) {
tmp = atan(((v * -0.10204081632653061) * (v / 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 <= (-1.5d-185)) then
tmp = atan((-1.0d0))
else if (v <= 4.1d-102) then
tmp = atan(((v * (-0.10204081632653061d0)) * (v / h)))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1.5e-185) {
tmp = Math.atan(-1.0);
} else if (v <= 4.1e-102) {
tmp = Math.atan(((v * -0.10204081632653061) * (v / H)));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1.5e-185: tmp = math.atan(-1.0) elif v <= 4.1e-102: tmp = math.atan(((v * -0.10204081632653061) * (v / H))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1.5e-185) tmp = atan(-1.0); elseif (v <= 4.1e-102) tmp = atan(Float64(Float64(v * -0.10204081632653061) * Float64(v / H))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1.5e-185) tmp = atan(-1.0); elseif (v <= 4.1e-102) tmp = atan(((v * -0.10204081632653061) * (v / H))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.5e-185], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 4.1e-102], N[ArcTan[N[(N[(v * -0.10204081632653061), $MachinePrecision] * N[(v / H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.5 \cdot 10^{-185}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 4.1 \cdot 10^{-102}:\\
\;\;\;\;\tan^{-1} \left(\left(v \cdot -0.10204081632653061\right) \cdot \frac{v}{H}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.50000000000000015e-185Initial program 61.8%
Taylor expanded in v around -inf
Applied rewrites79.9%
if -1.50000000000000015e-185 < v < 4.1000000000000003e-102Initial program 99.7%
Taylor expanded in H around 0
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-*r/N/A
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6429.9
Applied rewrites29.9%
Taylor expanded in v around 0
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6429.8
Applied rewrites29.8%
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-*.f64N/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-/.f6429.9
Applied rewrites29.9%
if 4.1000000000000003e-102 < v Initial program 58.6%
Taylor expanded in v around inf
Applied rewrites87.3%
(FPCore (v H) :precision binary64 (if (<= v -2e-310) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -2e-310: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -2e-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 <= -2e-310) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -2e-310], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.999999999999994e-310Initial program 69.0%
Taylor expanded in v around -inf
Applied rewrites65.4%
if -1.999999999999994e-310 < v Initial program 67.8%
Taylor expanded in v around inf
Applied rewrites68.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 68.4%
Taylor expanded in v around -inf
Applied rewrites33.1%
herbie shell --seed 2024220
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))