Optimal throwing angle

Percentage Accurate: 68.1% → 99.3%
Time: 7.0s
Alternatives: 5
Speedup: 1.0×

Specification

?
\[\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
 (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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 68.1% accurate, 1.0× speedup?

\[\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
 (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}

Alternative 1: 99.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(H, 19.6, v \cdot v\right)\\ \mathbf{if}\;v \leq -1.4 \cdot 10^{+154}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{elif}\;v \leq 1.05 \cdot 10^{+98}:\\ \;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{t\_0}, \frac{-H}{t\_0} \cdot \left(384.16 \cdot H\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \]
(FPCore (v H)
 :precision binary64
 (let* ((t_0 (fma H 19.6 (* v v))))
   (if (<= v -1.4e+154)
     (atan -1.0)
     (if (<= v 1.05e+98)
       (atan
        (/
         v
         (sqrt (fma (* v v) (/ (* v v) t_0) (* (/ (- H) t_0) (* 384.16 H))))))
       (atan 1.0)))))
double code(double v, double H) {
	double t_0 = fma(H, 19.6, (v * v));
	double tmp;
	if (v <= -1.4e+154) {
		tmp = atan(-1.0);
	} else if (v <= 1.05e+98) {
		tmp = atan((v / sqrt(fma((v * v), ((v * v) / t_0), ((-H / t_0) * (384.16 * H))))));
	} else {
		tmp = atan(1.0);
	}
	return tmp;
}
function code(v, H)
	t_0 = fma(H, 19.6, Float64(v * v))
	tmp = 0.0
	if (v <= -1.4e+154)
		tmp = atan(-1.0);
	elseif (v <= 1.05e+98)
		tmp = atan(Float64(v / sqrt(fma(Float64(v * v), Float64(Float64(v * v) / t_0), Float64(Float64(Float64(-H) / t_0) * Float64(384.16 * H))))));
	else
		tmp = atan(1.0);
	end
	return tmp
end
code[v_, H_] := Block[{t$95$0 = N[(H * 19.6 + N[(v * v), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[v, -1.4e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.05e+98], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] * N[(N[(v * v), $MachinePrecision] / t$95$0), $MachinePrecision] + N[(N[((-H) / t$95$0), $MachinePrecision] * N[(384.16 * H), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(H, 19.6, v \cdot v\right)\\
\mathbf{if}\;v \leq -1.4 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\

\mathbf{elif}\;v \leq 1.05 \cdot 10^{+98}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{t\_0}, \frac{-H}{t\_0} \cdot \left(384.16 \cdot H\right)\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if v < -1.4e154

    1. Initial program 3.1%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in v around -inf

      \[\leadsto \tan^{-1} \color{blue}{-1} \]
    4. Step-by-step derivation
      1. Applied rewrites100.0%

        \[\leadsto \tan^{-1} \color{blue}{-1} \]

      if -1.4e154 < v < 1.05000000000000002e98

      1. Initial program 99.7%

        \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v - \left(2 \cdot \frac{49}{5}\right) \cdot H}}}\right) \]
        2. flip--N/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\frac{\left(v \cdot v\right) \cdot \left(v \cdot v\right) - \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}}}}\right) \]
        3. div-subN/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\frac{\left(v \cdot v\right) \cdot \left(v \cdot v\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H} - \frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}}}}\right) \]
        4. sub-negN/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\frac{\left(v \cdot v\right) \cdot \left(v \cdot v\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H} + \left(\mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}}\right) \]
        5. associate-/l*N/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(v \cdot v\right) \cdot \frac{v \cdot v}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}} + \left(\mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
        6. lower-fma.f64N/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}, \mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}}\right) \]
        7. lower-/.f64N/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \color{blue}{\frac{v \cdot v}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}}, \mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
        8. +-commutativeN/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{\color{blue}{\left(2 \cdot \frac{49}{5}\right) \cdot H + v \cdot v}}, \mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
        9. lift-*.f64N/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{\color{blue}{\left(2 \cdot \frac{49}{5}\right) \cdot H} + v \cdot v}, \mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
        10. *-commutativeN/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{\color{blue}{H \cdot \left(2 \cdot \frac{49}{5}\right)} + v \cdot v}, \mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
        11. lower-fma.f64N/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{\color{blue}{\mathsf{fma}\left(H, 2 \cdot \frac{49}{5}, v \cdot v\right)}}, \mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
        12. lift-*.f64N/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{\mathsf{fma}\left(H, \color{blue}{2 \cdot \frac{49}{5}}, v \cdot v\right)}, \mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
        13. metadata-evalN/A

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{\mathsf{fma}\left(H, \color{blue}{\frac{98}{5}}, v \cdot v\right)}, \mathsf{neg}\left(\frac{\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right) \cdot \left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)}{v \cdot v + \left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
      4. Applied rewrites99.8%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{\mathsf{fma}\left(H, 19.6, v \cdot v\right)}, -\left(384.16 \cdot H\right) \cdot \frac{H}{\mathsf{fma}\left(H, 19.6, v \cdot v\right)}\right)}}}\right) \]

      if 1.05000000000000002e98 < v

      1. Initial program 30.8%

        \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. Add Preprocessing
      3. Taylor expanded in v around inf

        \[\leadsto \tan^{-1} \color{blue}{1} \]
      4. Step-by-step derivation
        1. Applied rewrites100.0%

          \[\leadsto \tan^{-1} \color{blue}{1} \]
      5. Recombined 3 regimes into one program.
      6. Final simplification99.9%

        \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq -1.4 \cdot 10^{+154}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{elif}\;v \leq 1.05 \cdot 10^{+98}:\\ \;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v \cdot v, \frac{v \cdot v}{\mathsf{fma}\left(H, 19.6, v \cdot v\right)}, \frac{-H}{\mathsf{fma}\left(H, 19.6, v \cdot v\right)} \cdot \left(384.16 \cdot H\right)\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \]
      7. Add Preprocessing

      Alternative 2: 99.5% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq -1.4 \cdot 10^{+154}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{elif}\;v \leq 1.05 \cdot 10^{+98}:\\ \;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, -19.6 \cdot H\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \]
      (FPCore (v H)
       :precision binary64
       (if (<= v -1.4e+154)
         (atan -1.0)
         (if (<= v 1.05e+98) (atan (/ v (sqrt (fma v v (* -19.6 H))))) (atan 1.0))))
      double code(double v, double H) {
      	double tmp;
      	if (v <= -1.4e+154) {
      		tmp = atan(-1.0);
      	} else if (v <= 1.05e+98) {
      		tmp = atan((v / sqrt(fma(v, v, (-19.6 * H)))));
      	} 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 <= 1.05e+98)
      		tmp = atan(Float64(v / sqrt(fma(v, v, Float64(-19.6 * H)))));
      	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, 1.05e+98], N[ArcTan[N[(v / N[Sqrt[N[(v * v + 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.4 \cdot 10^{+154}:\\
      \;\;\;\;\tan^{-1} -1\\
      
      \mathbf{elif}\;v \leq 1.05 \cdot 10^{+98}:\\
      \;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, -19.6 \cdot H\right)}}\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\tan^{-1} 1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if v < -1.4e154

        1. Initial program 3.1%

          \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
        2. Add Preprocessing
        3. Taylor expanded in v around -inf

          \[\leadsto \tan^{-1} \color{blue}{-1} \]
        4. Step-by-step derivation
          1. Applied rewrites100.0%

            \[\leadsto \tan^{-1} \color{blue}{-1} \]

          if -1.4e154 < v < 1.05000000000000002e98

          1. Initial program 99.7%

            \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift--.f64N/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v - \left(2 \cdot \frac{49}{5}\right) \cdot H}}}\right) \]
            2. sub-negN/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v + \left(\mathsf{neg}\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)\right)}}}\right) \]
            3. lift-*.f64N/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} + \left(\mathsf{neg}\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)\right)}}\right) \]
            4. lower-fma.f64N/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\mathsf{fma}\left(v, v, \mathsf{neg}\left(\left(2 \cdot \frac{49}{5}\right) \cdot H\right)\right)}}}\right) \]
            5. lift-*.f64N/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, \mathsf{neg}\left(\color{blue}{\left(2 \cdot \frac{49}{5}\right) \cdot H}\right)\right)}}\right) \]
            6. distribute-lft-neg-inN/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, \color{blue}{\left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) \cdot H}\right)}}\right) \]
            7. lower-*.f64N/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, \color{blue}{\left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) \cdot H}\right)}}\right) \]
            8. lift-*.f64N/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, \left(\mathsf{neg}\left(\color{blue}{2 \cdot \frac{49}{5}}\right)\right) \cdot H\right)}}\right) \]
            9. metadata-evalN/A

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, \left(\mathsf{neg}\left(\color{blue}{\frac{98}{5}}\right)\right) \cdot H\right)}}\right) \]
            10. metadata-eval99.8

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, \color{blue}{-19.6} \cdot H\right)}}\right) \]
          4. Applied rewrites99.8%

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\mathsf{fma}\left(v, v, -19.6 \cdot H\right)}}}\right) \]

          if 1.05000000000000002e98 < v

          1. Initial program 30.8%

            \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
          2. Add Preprocessing
          3. Taylor expanded in v around inf

            \[\leadsto \tan^{-1} \color{blue}{1} \]
          4. Step-by-step derivation
            1. Applied rewrites100.0%

              \[\leadsto \tan^{-1} \color{blue}{1} \]
          5. Recombined 3 regimes into one program.
          6. Add Preprocessing

          Alternative 3: 88.3% accurate, 1.0× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq -1.36 \cdot 10^{-30}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{elif}\;v \leq 9 \cdot 10^{+21}:\\ \;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \]
          (FPCore (v H)
           :precision binary64
           (if (<= v -1.36e-30)
             (atan -1.0)
             (if (<= v 9e+21)
               (atan (* (sqrt (/ -0.05102040816326531 H)) v))
               (atan 1.0))))
          double code(double v, double H) {
          	double tmp;
          	if (v <= -1.36e-30) {
          		tmp = atan(-1.0);
          	} else if (v <= 9e+21) {
          		tmp = atan((sqrt((-0.05102040816326531 / 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 <= (-1.36d-30)) then
                  tmp = atan((-1.0d0))
              else if (v <= 9d+21) then
                  tmp = atan((sqrt(((-0.05102040816326531d0) / 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 <= -1.36e-30) {
          		tmp = Math.atan(-1.0);
          	} else if (v <= 9e+21) {
          		tmp = Math.atan((Math.sqrt((-0.05102040816326531 / H)) * v));
          	} else {
          		tmp = Math.atan(1.0);
          	}
          	return tmp;
          }
          
          def code(v, H):
          	tmp = 0
          	if v <= -1.36e-30:
          		tmp = math.atan(-1.0)
          	elif v <= 9e+21:
          		tmp = math.atan((math.sqrt((-0.05102040816326531 / H)) * v))
          	else:
          		tmp = math.atan(1.0)
          	return tmp
          
          function code(v, H)
          	tmp = 0.0
          	if (v <= -1.36e-30)
          		tmp = atan(-1.0);
          	elseif (v <= 9e+21)
          		tmp = atan(Float64(sqrt(Float64(-0.05102040816326531 / H)) * v));
          	else
          		tmp = atan(1.0);
          	end
          	return tmp
          end
          
          function tmp_2 = code(v, H)
          	tmp = 0.0;
          	if (v <= -1.36e-30)
          		tmp = atan(-1.0);
          	elseif (v <= 9e+21)
          		tmp = atan((sqrt((-0.05102040816326531 / H)) * v));
          	else
          		tmp = atan(1.0);
          	end
          	tmp_2 = tmp;
          end
          
          code[v_, H_] := If[LessEqual[v, -1.36e-30], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 9e+21], N[ArcTan[N[(N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision] * v), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;v \leq -1.36 \cdot 10^{-30}:\\
          \;\;\;\;\tan^{-1} -1\\
          
          \mathbf{elif}\;v \leq 9 \cdot 10^{+21}:\\
          \;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\tan^{-1} 1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if v < -1.36e-30

            1. Initial program 52.7%

              \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
            2. Add Preprocessing
            3. Taylor expanded in v around -inf

              \[\leadsto \tan^{-1} \color{blue}{-1} \]
            4. Step-by-step derivation
              1. Applied rewrites96.8%

                \[\leadsto \tan^{-1} \color{blue}{-1} \]

              if -1.36e-30 < v < 9e21

              1. Initial program 99.6%

                \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
              2. Add Preprocessing
              3. Taylor expanded in v around 0

                \[\leadsto \color{blue}{\tan^{-1} \left(v \cdot \sqrt{\frac{1}{{v}^{2} - \frac{98}{5} \cdot H}}\right)} \]
              4. Step-by-step derivation
                1. cancel-sign-sub-invN/A

                  \[\leadsto \tan^{-1} \left(v \cdot \sqrt{\frac{1}{\color{blue}{{v}^{2} + \left(\mathsf{neg}\left(\frac{98}{5}\right)\right) \cdot H}}}\right) \]
                2. metadata-evalN/A

                  \[\leadsto \tan^{-1} \left(v \cdot \sqrt{\frac{1}{{v}^{2} + \color{blue}{\frac{-98}{5}} \cdot H}}\right) \]
                3. +-commutativeN/A

                  \[\leadsto \tan^{-1} \left(v \cdot \sqrt{\frac{1}{\color{blue}{\frac{-98}{5} \cdot H + {v}^{2}}}}\right) \]
                4. lower-atan.f64N/A

                  \[\leadsto \color{blue}{\tan^{-1} \left(v \cdot \sqrt{\frac{1}{\frac{-98}{5} \cdot H + {v}^{2}}}\right)} \]
                5. *-commutativeN/A

                  \[\leadsto \tan^{-1} \color{blue}{\left(\sqrt{\frac{1}{\frac{-98}{5} \cdot H + {v}^{2}}} \cdot v\right)} \]
                6. lower-*.f64N/A

                  \[\leadsto \tan^{-1} \color{blue}{\left(\sqrt{\frac{1}{\frac{-98}{5} \cdot H + {v}^{2}}} \cdot v\right)} \]
                7. lower-sqrt.f64N/A

                  \[\leadsto \tan^{-1} \left(\color{blue}{\sqrt{\frac{1}{\frac{-98}{5} \cdot H + {v}^{2}}}} \cdot v\right) \]
                8. lower-/.f64N/A

                  \[\leadsto \tan^{-1} \left(\sqrt{\color{blue}{\frac{1}{\frac{-98}{5} \cdot H + {v}^{2}}}} \cdot v\right) \]
                9. +-commutativeN/A

                  \[\leadsto \tan^{-1} \left(\sqrt{\frac{1}{\color{blue}{{v}^{2} + \frac{-98}{5} \cdot H}}} \cdot v\right) \]
                10. unpow2N/A

                  \[\leadsto \tan^{-1} \left(\sqrt{\frac{1}{\color{blue}{v \cdot v} + \frac{-98}{5} \cdot H}} \cdot v\right) \]
                11. lower-fma.f64N/A

                  \[\leadsto \tan^{-1} \left(\sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(v, v, \frac{-98}{5} \cdot H\right)}}} \cdot v\right) \]
                12. *-commutativeN/A

                  \[\leadsto \tan^{-1} \left(\sqrt{\frac{1}{\mathsf{fma}\left(v, v, \color{blue}{H \cdot \frac{-98}{5}}\right)}} \cdot v\right) \]
                13. lower-*.f6499.6

                  \[\leadsto \tan^{-1} \left(\sqrt{\frac{1}{\mathsf{fma}\left(v, v, \color{blue}{H \cdot -19.6}\right)}} \cdot v\right) \]
              5. Applied rewrites99.6%

                \[\leadsto \color{blue}{\tan^{-1} \left(\sqrt{\frac{1}{\mathsf{fma}\left(v, v, H \cdot -19.6\right)}} \cdot v\right)} \]
              6. Taylor expanded in v around 0

                \[\leadsto \tan^{-1} \left(\sqrt{\frac{\frac{-5}{98}}{H}} \cdot v\right) \]
              7. Step-by-step derivation
                1. Applied rewrites87.1%

                  \[\leadsto \tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\right) \]

                if 9e21 < v

                1. Initial program 41.1%

                  \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
                2. Add Preprocessing
                3. Taylor expanded in v around inf

                  \[\leadsto \tan^{-1} \color{blue}{1} \]
                4. Step-by-step derivation
                  1. Applied rewrites97.5%

                    \[\leadsto \tan^{-1} \color{blue}{1} \]
                5. Recombined 3 regimes into one program.
                6. Add Preprocessing

                Alternative 4: 66.2% accurate, 1.3× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq -4.6 \cdot 10^{-302}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \]
                (FPCore (v H) :precision binary64 (if (<= v -4.6e-302) (atan -1.0) (atan 1.0)))
                double code(double v, double H) {
                	double tmp;
                	if (v <= -4.6e-302) {
                		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 <= (-4.6d-302)) 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 <= -4.6e-302) {
                		tmp = Math.atan(-1.0);
                	} else {
                		tmp = Math.atan(1.0);
                	}
                	return tmp;
                }
                
                def code(v, H):
                	tmp = 0
                	if v <= -4.6e-302:
                		tmp = math.atan(-1.0)
                	else:
                		tmp = math.atan(1.0)
                	return tmp
                
                function code(v, H)
                	tmp = 0.0
                	if (v <= -4.6e-302)
                		tmp = atan(-1.0);
                	else
                		tmp = atan(1.0);
                	end
                	return tmp
                end
                
                function tmp_2 = code(v, H)
                	tmp = 0.0;
                	if (v <= -4.6e-302)
                		tmp = atan(-1.0);
                	else
                		tmp = atan(1.0);
                	end
                	tmp_2 = tmp;
                end
                
                code[v_, H_] := If[LessEqual[v, -4.6e-302], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;v \leq -4.6 \cdot 10^{-302}:\\
                \;\;\;\;\tan^{-1} -1\\
                
                \mathbf{else}:\\
                \;\;\;\;\tan^{-1} 1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if v < -4.60000000000000004e-302

                  1. Initial program 68.0%

                    \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
                  2. Add Preprocessing
                  3. Taylor expanded in v around -inf

                    \[\leadsto \tan^{-1} \color{blue}{-1} \]
                  4. Step-by-step derivation
                    1. Applied rewrites69.1%

                      \[\leadsto \tan^{-1} \color{blue}{-1} \]

                    if -4.60000000000000004e-302 < v

                    1. Initial program 65.8%

                      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
                    2. Add Preprocessing
                    3. Taylor expanded in v around inf

                      \[\leadsto \tan^{-1} \color{blue}{1} \]
                    4. Step-by-step derivation
                      1. Applied rewrites65.6%

                        \[\leadsto \tan^{-1} \color{blue}{1} \]
                    5. Recombined 2 regimes into one program.
                    6. Add Preprocessing

                    Alternative 5: 34.9% accurate, 1.4× speedup?

                    \[\begin{array}{l} \\ \tan^{-1} -1 \end{array} \]
                    (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}
                    
                    Derivation
                    1. Initial program 66.9%

                      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
                    2. Add Preprocessing
                    3. Taylor expanded in v around -inf

                      \[\leadsto \tan^{-1} \color{blue}{-1} \]
                    4. Step-by-step derivation
                      1. Applied rewrites35.5%

                        \[\leadsto \tan^{-1} \color{blue}{-1} \]
                      2. Add Preprocessing

                      Reproduce

                      ?
                      herbie shell --seed 2024277 
                      (FPCore (v H)
                        :name "Optimal throwing angle"
                        :precision binary64
                        (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))