Optimal throwing angle

Percentage Accurate: 66.7% → 99.6%
Time: 8.4s
Alternatives: 6
Speedup: 2.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 6 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: 66.7% 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.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{elif}\;v \leq 1.35 \cdot 10^{+109}:\\ \;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \]
(FPCore (v H)
 :precision binary64
 (if (<= v -1.35e+154)
   (atan -1.0)
   (if (<= v 1.35e+109)
     (atan (/ v (sqrt (- (* v v) (* 19.6 H)))))
     (atan 1.0))))
double code(double v, double H) {
	double tmp;
	if (v <= -1.35e+154) {
		tmp = atan(-1.0);
	} else if (v <= 1.35e+109) {
		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 <= (-1.35d+154)) then
        tmp = atan((-1.0d0))
    else if (v <= 1.35d+109) 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 <= -1.35e+154) {
		tmp = Math.atan(-1.0);
	} else if (v <= 1.35e+109) {
		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 <= -1.35e+154:
		tmp = math.atan(-1.0)
	elif v <= 1.35e+109:
		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 <= -1.35e+154)
		tmp = atan(-1.0);
	elseif (v <= 1.35e+109)
		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 <= -1.35e+154)
		tmp = atan(-1.0);
	elseif (v <= 1.35e+109)
		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, -1.35e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.35e+109], 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 -1.35 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\

\mathbf{elif}\;v \leq 1.35 \cdot 10^{+109}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)\\

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


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

    1. Initial program 3.1%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg3.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg3.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval3.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified3.1%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in v around -inf 100.0%

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

    if -1.35000000000000003e154 < v < 1.35000000000000001e109

    1. Initial program 99.8%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg99.8%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg99.8%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval99.8%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing

    if 1.35000000000000001e109 < v

    1. Initial program 24.9%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg24.9%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg24.9%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval24.9%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified24.9%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in v around inf 100.0%

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

Alternative 2: 89.0% accurate, 1.0× speedup?

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

\mathbf{elif}\;v \leq 1.18 \cdot 10^{-40}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{H \cdot -19.6}}\right)\\

\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if v < -4.7e-35

    1. Initial program 48.9%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg48.9%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg48.9%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval48.9%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified48.9%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in v around -inf 93.1%

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

    if -4.7e-35 < v < 1.1799999999999999e-40

    1. Initial program 99.6%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg99.6%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg99.6%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval99.6%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-cube-cbrt98.9%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{\left(\sqrt[3]{19.6 \cdot H} \cdot \sqrt[3]{19.6 \cdot H}\right) \cdot \sqrt[3]{19.6 \cdot H}}}}\right) \]
      2. pow398.8%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{{\left(\sqrt[3]{19.6 \cdot H}\right)}^{3}}}}\right) \]
    6. Applied egg-rr98.8%

      \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{{\left(\sqrt[3]{19.6 \cdot H}\right)}^{3}}}}\right) \]
    7. Taylor expanded in H around -inf 0.0%

      \[\leadsto \tan^{-1} \left(\frac{v}{\color{blue}{-1 \cdot \left(\sqrt{H \cdot {\left(\sqrt[3]{-19.6}\right)}^{3}} \cdot {\left(\sqrt{-1}\right)}^{2}\right)}}\right) \]
    8. Step-by-step derivation
      1. mul-1-neg0.0%

        \[\leadsto \tan^{-1} \left(\frac{v}{\color{blue}{-\sqrt{H \cdot {\left(\sqrt[3]{-19.6}\right)}^{3}} \cdot {\left(\sqrt{-1}\right)}^{2}}}\right) \]
      2. *-commutative0.0%

        \[\leadsto \tan^{-1} \left(\frac{v}{-\color{blue}{{\left(\sqrt{-1}\right)}^{2} \cdot \sqrt{H \cdot {\left(\sqrt[3]{-19.6}\right)}^{3}}}}\right) \]
      3. unpow20.0%

        \[\leadsto \tan^{-1} \left(\frac{v}{-\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{H \cdot {\left(\sqrt[3]{-19.6}\right)}^{3}}}\right) \]
      4. rem-square-sqrt89.9%

        \[\leadsto \tan^{-1} \left(\frac{v}{-\color{blue}{-1} \cdot \sqrt{H \cdot {\left(\sqrt[3]{-19.6}\right)}^{3}}}\right) \]
      5. rem-cube-cbrt91.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{--1 \cdot \sqrt{H \cdot \color{blue}{-19.6}}}\right) \]
      6. distribute-lft-neg-in91.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\color{blue}{\left(--1\right) \cdot \sqrt{H \cdot -19.6}}}\right) \]
      7. metadata-eval91.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\color{blue}{1} \cdot \sqrt{H \cdot -19.6}}\right) \]
      8. *-lft-identity91.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\color{blue}{\sqrt{H \cdot -19.6}}}\right) \]
    9. Simplified91.3%

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

    if 1.1799999999999999e-40 < v

    1. Initial program 58.1%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg58.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg58.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval58.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified58.1%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in H around 0 89.8%

      \[\leadsto \tan^{-1} \left(\frac{v}{\color{blue}{v + -9.8 \cdot \frac{H}{v}}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 72.4% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq -1.25 \cdot 10^{-181}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{elif}\;v \leq 2.1 \cdot 10^{-144}:\\ \;\;\;\;\tan^{-1} \left(v \cdot \left(-0.10204081632653061 \cdot \frac{v}{H}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \]
(FPCore (v H)
 :precision binary64
 (if (<= v -1.25e-181)
   (atan -1.0)
   (if (<= v 2.1e-144)
     (atan (* v (* -0.10204081632653061 (/ v H))))
     (atan 1.0))))
double code(double v, double H) {
	double tmp;
	if (v <= -1.25e-181) {
		tmp = atan(-1.0);
	} else if (v <= 2.1e-144) {
		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.25d-181)) then
        tmp = atan((-1.0d0))
    else if (v <= 2.1d-144) 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.25e-181) {
		tmp = Math.atan(-1.0);
	} else if (v <= 2.1e-144) {
		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.25e-181:
		tmp = math.atan(-1.0)
	elif v <= 2.1e-144:
		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.25e-181)
		tmp = atan(-1.0);
	elseif (v <= 2.1e-144)
		tmp = atan(Float64(v * Float64(-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.25e-181)
		tmp = atan(-1.0);
	elseif (v <= 2.1e-144)
		tmp = atan((v * (-0.10204081632653061 * (v / H))));
	else
		tmp = atan(1.0);
	end
	tmp_2 = tmp;
end
code[v_, H_] := If[LessEqual[v, -1.25e-181], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2.1e-144], N[ArcTan[N[(v * N[(-0.10204081632653061 * N[(v / H), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.25 \cdot 10^{-181}:\\
\;\;\;\;\tan^{-1} -1\\

\mathbf{elif}\;v \leq 2.1 \cdot 10^{-144}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \left(-0.10204081632653061 \cdot \frac{v}{H}\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if v < -1.25e-181

    1. Initial program 56.1%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg56.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg56.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval56.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified56.1%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in v around -inf 81.7%

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

    if -1.25e-181 < v < 2.1000000000000001e-144

    1. Initial program 99.6%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg99.6%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg99.6%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval99.6%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.5%

        \[\leadsto \tan^{-1} \color{blue}{\left(\frac{1}{\frac{\sqrt{v \cdot v - 19.6 \cdot H}}{v}}\right)} \]
      2. inv-pow99.5%

        \[\leadsto \tan^{-1} \color{blue}{\left({\left(\frac{\sqrt{v \cdot v - 19.6 \cdot H}}{v}\right)}^{-1}\right)} \]
      3. sub-neg99.5%

        \[\leadsto \tan^{-1} \left({\left(\frac{\sqrt{\color{blue}{v \cdot v + \left(-19.6 \cdot H\right)}}}{v}\right)}^{-1}\right) \]
      4. add-sqr-sqrt99.5%

        \[\leadsto \tan^{-1} \left({\left(\frac{\sqrt{v \cdot v + \color{blue}{\sqrt{-19.6 \cdot H} \cdot \sqrt{-19.6 \cdot H}}}}{v}\right)}^{-1}\right) \]
      5. hypot-define99.5%

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

        \[\leadsto \tan^{-1} \left({\left(\frac{\mathsf{hypot}\left(v, \sqrt{-\color{blue}{H \cdot 19.6}}\right)}{v}\right)}^{-1}\right) \]
      7. distribute-rgt-neg-in99.5%

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

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

      \[\leadsto \tan^{-1} \color{blue}{\left({\left(\frac{\mathsf{hypot}\left(v, \sqrt{H \cdot -19.6}\right)}{v}\right)}^{-1}\right)} \]
    7. Step-by-step derivation
      1. unpow-199.5%

        \[\leadsto \tan^{-1} \color{blue}{\left(\frac{1}{\frac{\mathsf{hypot}\left(v, \sqrt{H \cdot -19.6}\right)}{v}}\right)} \]
      2. associate-/r/99.5%

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

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

      \[\leadsto \tan^{-1} \left(\frac{1}{\color{blue}{v + 0.5 \cdot \frac{H \cdot {\left(\sqrt{-19.6}\right)}^{2}}{v}}} \cdot v\right) \]
    10. Step-by-step derivation
      1. associate-/l*0.0%

        \[\leadsto \tan^{-1} \left(\frac{1}{v + 0.5 \cdot \color{blue}{\left(H \cdot \frac{{\left(\sqrt{-19.6}\right)}^{2}}{v}\right)}} \cdot v\right) \]
      2. unpow20.0%

        \[\leadsto \tan^{-1} \left(\frac{1}{v + 0.5 \cdot \left(H \cdot \frac{\color{blue}{\sqrt{-19.6} \cdot \sqrt{-19.6}}}{v}\right)} \cdot v\right) \]
      3. rem-square-sqrt28.8%

        \[\leadsto \tan^{-1} \left(\frac{1}{v + 0.5 \cdot \left(H \cdot \frac{\color{blue}{-19.6}}{v}\right)} \cdot v\right) \]
    11. Simplified28.8%

      \[\leadsto \tan^{-1} \left(\frac{1}{\color{blue}{v + 0.5 \cdot \left(H \cdot \frac{-19.6}{v}\right)}} \cdot v\right) \]
    12. Taylor expanded in v around 0 28.8%

      \[\leadsto \tan^{-1} \left(\color{blue}{\left(-0.10204081632653061 \cdot \frac{v}{H}\right)} \cdot v\right) \]

    if 2.1000000000000001e-144 < v

    1. Initial program 65.5%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg65.5%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg65.5%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval65.5%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified65.5%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in v around inf 78.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq -1.25 \cdot 10^{-181}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{elif}\;v \leq 2.1 \cdot 10^{-144}:\\ \;\;\;\;\tan^{-1} \left(v \cdot \left(-0.10204081632653061 \cdot \frac{v}{H}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 72.7% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;v \leq -1.25 \cdot 10^{-181}:\\ \;\;\;\;\tan^{-1} -1\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\ \end{array} \end{array} \]
(FPCore (v H)
 :precision binary64
 (if (<= v -1.25e-181) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
	double tmp;
	if (v <= -1.25e-181) {
		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.25d-181)) 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.25e-181) {
		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.25e-181:
		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.25e-181)
		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.25e-181)
		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.25e-181], 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.25 \cdot 10^{-181}:\\
\;\;\;\;\tan^{-1} -1\\

\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if v < -1.25e-181

    1. Initial program 56.1%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg56.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg56.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval56.1%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified56.1%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in v around -inf 81.7%

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

    if -1.25e-181 < v

    1. Initial program 75.3%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg75.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg75.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval75.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified75.3%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in H around 0 64.7%

      \[\leadsto \tan^{-1} \left(\frac{v}{\color{blue}{v + -9.8 \cdot \frac{H}{v}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 68.5% accurate, 2.0× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 2 regimes
  2. if v < -4.999999999999985e-310

    1. Initial program 61.8%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg61.8%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg61.8%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval61.8%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified61.8%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in v around -inf 71.4%

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

    if -4.999999999999985e-310 < v

    1. Initial program 72.3%

      \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. Step-by-step derivation
      1. sqr-neg72.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      2. sqr-neg72.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
      3. metadata-eval72.3%

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
    3. Simplified72.3%

      \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in v around inf 63.7%

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

Alternative 6: 35.6% accurate, 2.1× 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 67.3%

    \[\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
  2. Step-by-step derivation
    1. sqr-neg67.3%

      \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(-v\right) \cdot \left(-v\right)} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    2. sqr-neg67.3%

      \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{v \cdot v} - \left(2 \cdot 9.8\right) \cdot H}}\right) \]
    3. metadata-eval67.3%

      \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \color{blue}{19.6} \cdot H}}\right) \]
  3. Simplified67.3%

    \[\leadsto \color{blue}{\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in v around -inf 35.0%

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

Reproduce

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