Optimal throwing angle

Percentage Accurate: 67.6% → 99.6%
Time: 3.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)))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(v, h)
use fmin_fmax_functions
    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}

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: 67.6% 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)))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(v, h)
use fmin_fmax_functions
    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} v\_m = \left|v\right| \\ v\_s = \mathsf{copysign}\left(1, v\right) \\ v\_s \cdot \begin{array}{l} \mathbf{if}\;v\_m \leq 10^{+133}:\\ \;\;\;\;\tan^{-1} \left(\frac{v\_m}{\sqrt{\mathsf{fma}\left(H, -19.6, v\_m \cdot v\_m\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \]
v\_m = (fabs.f64 v)
v\_s = (copysign.f64 #s(literal 1 binary64) v)
(FPCore (v_s v_m H)
 :precision binary64
 (*
  v_s
  (if (<= v_m 1e+133)
    (atan (/ v_m (sqrt (fma H -19.6 (* v_m v_m)))))
    (atan 1.0))))
v\_m = fabs(v);
v\_s = copysign(1.0, v);
double code(double v_s, double v_m, double H) {
	double tmp;
	if (v_m <= 1e+133) {
		tmp = atan((v_m / sqrt(fma(H, -19.6, (v_m * v_m)))));
	} else {
		tmp = atan(1.0);
	}
	return v_s * tmp;
}
v\_m = abs(v)
v\_s = copysign(1.0, v)
function code(v_s, v_m, H)
	tmp = 0.0
	if (v_m <= 1e+133)
		tmp = atan(Float64(v_m / sqrt(fma(H, -19.6, Float64(v_m * v_m)))));
	else
		tmp = atan(1.0);
	end
	return Float64(v_s * tmp)
end
v\_m = N[Abs[v], $MachinePrecision]
v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[v$95$s_, v$95$m_, H_] := N[(v$95$s * If[LessEqual[v$95$m, 1e+133], N[ArcTan[N[(v$95$m / N[Sqrt[N[(H * -19.6 + N[(v$95$m * v$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
v\_m = \left|v\right|
\\
v\_s = \mathsf{copysign}\left(1, v\right)

\\
v\_s \cdot \begin{array}{l}
\mathbf{if}\;v\_m \leq 10^{+133}:\\
\;\;\;\;\tan^{-1} \left(\frac{v\_m}{\sqrt{\mathsf{fma}\left(H, -19.6, v\_m \cdot v\_m\right)}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if v < 1e133

    1. Initial program 67.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. 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. lift-*.f64N/A

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

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

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

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

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) \cdot H + \color{blue}{\left|v\right| \cdot \left|v\right|}}}\right) \]
      7. fp-cancel-sign-sub-invN/A

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) \cdot H - \left(\mathsf{neg}\left(\left|v\right|\right)\right) \cdot \left|v\right|}}}\right) \]
      8. fp-cancel-sub-sign-invN/A

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

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{H \cdot \left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right)} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|v\right|\right)\right)\right)\right) \cdot \left|v\right|}}\right) \]
      10. distribute-lft-neg-outN/A

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{H \cdot \left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|v\right|\right)\right) \cdot \left|v\right|\right)\right)}}}\right) \]
      11. distribute-rgt-neg-outN/A

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{H \cdot \left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\left|v\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|v\right|\right)\right)}}}\right) \]
      12. sqr-neg-revN/A

        \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{H \cdot \left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) + \color{blue}{\left|v\right| \cdot \left|v\right|}}}\right) \]
      13. sqr-abs-revN/A

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

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

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

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

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

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

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

    if 1e133 < v

    1. Initial program 67.6%

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

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

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

    Alternative 2: 95.0% accurate, 0.3× speedup?

    \[\begin{array}{l} v\_m = \left|v\right| \\ v\_s = \mathsf{copysign}\left(1, v\right) \\ \begin{array}{l} t_0 := \tan^{-1} \left(\frac{v\_m}{\sqrt{v\_m \cdot v\_m - \left(2 \cdot 9.8\right) \cdot H}}\right)\\ v\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\tan^{-1} 1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\tan^{-1} \left(\frac{\frac{v\_m}{\sqrt{19.6}}}{\sqrt{-H}}\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \end{array} \]
    v\_m = (fabs.f64 v)
    v\_s = (copysign.f64 #s(literal 1 binary64) v)
    (FPCore (v_s v_m H)
     :precision binary64
     (let* ((t_0 (atan (/ v_m (sqrt (- (* v_m v_m) (* (* 2.0 9.8) H)))))))
       (*
        v_s
        (if (<= t_0 0.0)
          (atan 1.0)
          (if (<= t_0 2e-5)
            (atan (/ (/ v_m (sqrt 19.6)) (sqrt (- H))))
            (atan 1.0))))))
    v\_m = fabs(v);
    v\_s = copysign(1.0, v);
    double code(double v_s, double v_m, double H) {
    	double t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
    	double tmp;
    	if (t_0 <= 0.0) {
    		tmp = atan(1.0);
    	} else if (t_0 <= 2e-5) {
    		tmp = atan(((v_m / sqrt(19.6)) / sqrt(-H)));
    	} else {
    		tmp = atan(1.0);
    	}
    	return v_s * tmp;
    }
    
    v\_m =     private
    v\_s =     private
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(v_s, v_m, h)
    use fmin_fmax_functions
        real(8), intent (in) :: v_s
        real(8), intent (in) :: v_m
        real(8), intent (in) :: h
        real(8) :: t_0
        real(8) :: tmp
        t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0d0 * 9.8d0) * h)))))
        if (t_0 <= 0.0d0) then
            tmp = atan(1.0d0)
        else if (t_0 <= 2d-5) then
            tmp = atan(((v_m / sqrt(19.6d0)) / sqrt(-h)))
        else
            tmp = atan(1.0d0)
        end if
        code = v_s * tmp
    end function
    
    v\_m = Math.abs(v);
    v\_s = Math.copySign(1.0, v);
    public static double code(double v_s, double v_m, double H) {
    	double t_0 = Math.atan((v_m / Math.sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
    	double tmp;
    	if (t_0 <= 0.0) {
    		tmp = Math.atan(1.0);
    	} else if (t_0 <= 2e-5) {
    		tmp = Math.atan(((v_m / Math.sqrt(19.6)) / Math.sqrt(-H)));
    	} else {
    		tmp = Math.atan(1.0);
    	}
    	return v_s * tmp;
    }
    
    v\_m = math.fabs(v)
    v\_s = math.copysign(1.0, v)
    def code(v_s, v_m, H):
    	t_0 = math.atan((v_m / math.sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))))
    	tmp = 0
    	if t_0 <= 0.0:
    		tmp = math.atan(1.0)
    	elif t_0 <= 2e-5:
    		tmp = math.atan(((v_m / math.sqrt(19.6)) / math.sqrt(-H)))
    	else:
    		tmp = math.atan(1.0)
    	return v_s * tmp
    
    v\_m = abs(v)
    v\_s = copysign(1.0, v)
    function code(v_s, v_m, H)
    	t_0 = atan(Float64(v_m / sqrt(Float64(Float64(v_m * v_m) - Float64(Float64(2.0 * 9.8) * H)))))
    	tmp = 0.0
    	if (t_0 <= 0.0)
    		tmp = atan(1.0);
    	elseif (t_0 <= 2e-5)
    		tmp = atan(Float64(Float64(v_m / sqrt(19.6)) / sqrt(Float64(-H))));
    	else
    		tmp = atan(1.0);
    	end
    	return Float64(v_s * tmp)
    end
    
    v\_m = abs(v);
    v\_s = sign(v) * abs(1.0);
    function tmp_2 = code(v_s, v_m, H)
    	t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
    	tmp = 0.0;
    	if (t_0 <= 0.0)
    		tmp = atan(1.0);
    	elseif (t_0 <= 2e-5)
    		tmp = atan(((v_m / sqrt(19.6)) / sqrt(-H)));
    	else
    		tmp = atan(1.0);
    	end
    	tmp_2 = v_s * tmp;
    end
    
    v\_m = N[Abs[v], $MachinePrecision]
    v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
    code[v$95$s_, v$95$m_, H_] := Block[{t$95$0 = N[ArcTan[N[(v$95$m / N[Sqrt[N[(N[(v$95$m * v$95$m), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(v$95$s * If[LessEqual[t$95$0, 0.0], N[ArcTan[1.0], $MachinePrecision], If[LessEqual[t$95$0, 2e-5], N[ArcTan[N[(N[(v$95$m / N[Sqrt[19.6], $MachinePrecision]), $MachinePrecision] / N[Sqrt[(-H)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]), $MachinePrecision]]
    
    \begin{array}{l}
    v\_m = \left|v\right|
    \\
    v\_s = \mathsf{copysign}\left(1, v\right)
    
    \\
    \begin{array}{l}
    t_0 := \tan^{-1} \left(\frac{v\_m}{\sqrt{v\_m \cdot v\_m - \left(2 \cdot 9.8\right) \cdot H}}\right)\\
    v\_s \cdot \begin{array}{l}
    \mathbf{if}\;t\_0 \leq 0:\\
    \;\;\;\;\tan^{-1} 1\\
    
    \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\
    \;\;\;\;\tan^{-1} \left(\frac{\frac{v\_m}{\sqrt{19.6}}}{\sqrt{-H}}\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\tan^{-1} 1\\
    
    
    \end{array}
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) < 0.0 or 2.00000000000000016e-5 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H)))))

      1. Initial program 67.6%

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

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

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

        if 0.0 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) < 2.00000000000000016e-5

        1. Initial program 67.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. 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. lift-*.f64N/A

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

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

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

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

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) \cdot H + \color{blue}{\left|v\right| \cdot \left|v\right|}}}\right) \]
          7. fp-cancel-sign-sub-invN/A

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) \cdot H - \left(\mathsf{neg}\left(\left|v\right|\right)\right) \cdot \left|v\right|}}}\right) \]
          8. fp-cancel-sub-sign-invN/A

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

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{H \cdot \left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right)} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|v\right|\right)\right)\right)\right) \cdot \left|v\right|}}\right) \]
          10. distribute-lft-neg-outN/A

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{H \cdot \left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|v\right|\right)\right) \cdot \left|v\right|\right)\right)}}}\right) \]
          11. distribute-rgt-neg-outN/A

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{H \cdot \left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\left|v\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|v\right|\right)\right)}}}\right) \]
          12. sqr-neg-revN/A

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{H \cdot \left(\mathsf{neg}\left(2 \cdot \frac{49}{5}\right)\right) + \color{blue}{\left|v\right| \cdot \left|v\right|}}}\right) \]
          13. sqr-abs-revN/A

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

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

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

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

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

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

          \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\mathsf{fma}\left(H, -19.6, v \cdot v\right)}}}\right) \]
        4. Step-by-step derivation
          1. lift-sqrt.f64N/A

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

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

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

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\frac{-98}{5} \cdot H} + v \cdot v}}\right) \]
          5. sum-to-mult-revN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{19.6}} \cdot \sqrt{-H}}\right) \]
          2. Step-by-step derivation
            1. lift-/.f64N/A

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

              \[\leadsto \tan^{-1} \left(\frac{v}{\color{blue}{\sqrt{\frac{98}{5}} \cdot \sqrt{-H}}}\right) \]
            3. associate-/r*N/A

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

              \[\leadsto \tan^{-1} \color{blue}{\left(\frac{\frac{v}{\sqrt{\frac{98}{5}}}}{\sqrt{-H}}\right)} \]
            5. lower-/.f6439.4

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

            \[\leadsto \tan^{-1} \color{blue}{\left(\frac{\frac{v}{\sqrt{19.6}}}{\sqrt{-H}}\right)} \]
        8. Recombined 2 regimes into one program.
        9. Add Preprocessing

        Alternative 3: 95.0% accurate, 0.3× speedup?

        \[\begin{array}{l} v\_m = \left|v\right| \\ v\_s = \mathsf{copysign}\left(1, v\right) \\ \begin{array}{l} t_0 := \tan^{-1} \left(\frac{v\_m}{\sqrt{v\_m \cdot v\_m - \left(2 \cdot 9.8\right) \cdot H}}\right)\\ v\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\tan^{-1} 1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\tan^{-1} \left(\frac{v\_m}{\sqrt{-19.6 \cdot H}}\right)\\ \mathbf{else}:\\ \;\;\;\;\tan^{-1} 1\\ \end{array} \end{array} \end{array} \]
        v\_m = (fabs.f64 v)
        v\_s = (copysign.f64 #s(literal 1 binary64) v)
        (FPCore (v_s v_m H)
         :precision binary64
         (let* ((t_0 (atan (/ v_m (sqrt (- (* v_m v_m) (* (* 2.0 9.8) H)))))))
           (*
            v_s
            (if (<= t_0 0.0)
              (atan 1.0)
              (if (<= t_0 2e-5) (atan (/ v_m (sqrt (* -19.6 H)))) (atan 1.0))))))
        v\_m = fabs(v);
        v\_s = copysign(1.0, v);
        double code(double v_s, double v_m, double H) {
        	double t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
        	double tmp;
        	if (t_0 <= 0.0) {
        		tmp = atan(1.0);
        	} else if (t_0 <= 2e-5) {
        		tmp = atan((v_m / sqrt((-19.6 * H))));
        	} else {
        		tmp = atan(1.0);
        	}
        	return v_s * tmp;
        }
        
        v\_m =     private
        v\_s =     private
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(8) function code(v_s, v_m, h)
        use fmin_fmax_functions
            real(8), intent (in) :: v_s
            real(8), intent (in) :: v_m
            real(8), intent (in) :: h
            real(8) :: t_0
            real(8) :: tmp
            t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0d0 * 9.8d0) * h)))))
            if (t_0 <= 0.0d0) then
                tmp = atan(1.0d0)
            else if (t_0 <= 2d-5) then
                tmp = atan((v_m / sqrt(((-19.6d0) * h))))
            else
                tmp = atan(1.0d0)
            end if
            code = v_s * tmp
        end function
        
        v\_m = Math.abs(v);
        v\_s = Math.copySign(1.0, v);
        public static double code(double v_s, double v_m, double H) {
        	double t_0 = Math.atan((v_m / Math.sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
        	double tmp;
        	if (t_0 <= 0.0) {
        		tmp = Math.atan(1.0);
        	} else if (t_0 <= 2e-5) {
        		tmp = Math.atan((v_m / Math.sqrt((-19.6 * H))));
        	} else {
        		tmp = Math.atan(1.0);
        	}
        	return v_s * tmp;
        }
        
        v\_m = math.fabs(v)
        v\_s = math.copysign(1.0, v)
        def code(v_s, v_m, H):
        	t_0 = math.atan((v_m / math.sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))))
        	tmp = 0
        	if t_0 <= 0.0:
        		tmp = math.atan(1.0)
        	elif t_0 <= 2e-5:
        		tmp = math.atan((v_m / math.sqrt((-19.6 * H))))
        	else:
        		tmp = math.atan(1.0)
        	return v_s * tmp
        
        v\_m = abs(v)
        v\_s = copysign(1.0, v)
        function code(v_s, v_m, H)
        	t_0 = atan(Float64(v_m / sqrt(Float64(Float64(v_m * v_m) - Float64(Float64(2.0 * 9.8) * H)))))
        	tmp = 0.0
        	if (t_0 <= 0.0)
        		tmp = atan(1.0);
        	elseif (t_0 <= 2e-5)
        		tmp = atan(Float64(v_m / sqrt(Float64(-19.6 * H))));
        	else
        		tmp = atan(1.0);
        	end
        	return Float64(v_s * tmp)
        end
        
        v\_m = abs(v);
        v\_s = sign(v) * abs(1.0);
        function tmp_2 = code(v_s, v_m, H)
        	t_0 = atan((v_m / sqrt(((v_m * v_m) - ((2.0 * 9.8) * H)))));
        	tmp = 0.0;
        	if (t_0 <= 0.0)
        		tmp = atan(1.0);
        	elseif (t_0 <= 2e-5)
        		tmp = atan((v_m / sqrt((-19.6 * H))));
        	else
        		tmp = atan(1.0);
        	end
        	tmp_2 = v_s * tmp;
        end
        
        v\_m = N[Abs[v], $MachinePrecision]
        v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
        code[v$95$s_, v$95$m_, H_] := Block[{t$95$0 = N[ArcTan[N[(v$95$m / N[Sqrt[N[(N[(v$95$m * v$95$m), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(v$95$s * If[LessEqual[t$95$0, 0.0], N[ArcTan[1.0], $MachinePrecision], If[LessEqual[t$95$0, 2e-5], N[ArcTan[N[(v$95$m / N[Sqrt[N[(-19.6 * H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]), $MachinePrecision]]
        
        \begin{array}{l}
        v\_m = \left|v\right|
        \\
        v\_s = \mathsf{copysign}\left(1, v\right)
        
        \\
        \begin{array}{l}
        t_0 := \tan^{-1} \left(\frac{v\_m}{\sqrt{v\_m \cdot v\_m - \left(2 \cdot 9.8\right) \cdot H}}\right)\\
        v\_s \cdot \begin{array}{l}
        \mathbf{if}\;t\_0 \leq 0:\\
        \;\;\;\;\tan^{-1} 1\\
        
        \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\
        \;\;\;\;\tan^{-1} \left(\frac{v\_m}{\sqrt{-19.6 \cdot H}}\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\tan^{-1} 1\\
        
        
        \end{array}
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) < 0.0 or 2.00000000000000016e-5 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H)))))

          1. Initial program 67.6%

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

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

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

            if 0.0 < (atan.f64 (/.f64 v (sqrt.f64 (-.f64 (*.f64 v v) (*.f64 (*.f64 #s(literal 2 binary64) #s(literal 49/5 binary64)) H))))) < 2.00000000000000016e-5

            1. Initial program 67.6%

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

              \[\leadsto \tan^{-1} \left(\frac{v}{\sqrt{\color{blue}{\frac{-98}{5} \cdot H}}}\right) \]
            3. Step-by-step derivation
              1. lower-*.f6439.3

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

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

          Alternative 4: 67.5% accurate, 2.6× speedup?

          \[\begin{array}{l} v\_m = \left|v\right| \\ v\_s = \mathsf{copysign}\left(1, v\right) \\ v\_s \cdot \tan^{-1} 1 \end{array} \]
          v\_m = (fabs.f64 v)
          v\_s = (copysign.f64 #s(literal 1 binary64) v)
          (FPCore (v_s v_m H) :precision binary64 (* v_s (atan 1.0)))
          v\_m = fabs(v);
          v\_s = copysign(1.0, v);
          double code(double v_s, double v_m, double H) {
          	return v_s * atan(1.0);
          }
          
          v\_m =     private
          v\_s =     private
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(v_s, v_m, h)
          use fmin_fmax_functions
              real(8), intent (in) :: v_s
              real(8), intent (in) :: v_m
              real(8), intent (in) :: h
              code = v_s * atan(1.0d0)
          end function
          
          v\_m = Math.abs(v);
          v\_s = Math.copySign(1.0, v);
          public static double code(double v_s, double v_m, double H) {
          	return v_s * Math.atan(1.0);
          }
          
          v\_m = math.fabs(v)
          v\_s = math.copysign(1.0, v)
          def code(v_s, v_m, H):
          	return v_s * math.atan(1.0)
          
          v\_m = abs(v)
          v\_s = copysign(1.0, v)
          function code(v_s, v_m, H)
          	return Float64(v_s * atan(1.0))
          end
          
          v\_m = abs(v);
          v\_s = sign(v) * abs(1.0);
          function tmp = code(v_s, v_m, H)
          	tmp = v_s * atan(1.0);
          end
          
          v\_m = N[Abs[v], $MachinePrecision]
          v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
          code[v$95$s_, v$95$m_, H_] := N[(v$95$s * N[ArcTan[1.0], $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          v\_m = \left|v\right|
          \\
          v\_s = \mathsf{copysign}\left(1, v\right)
          
          \\
          v\_s \cdot \tan^{-1} 1
          \end{array}
          
          Derivation
          1. Initial program 67.6%

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

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

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

            Alternative 5: 1.8% accurate, 2.6× speedup?

            \[\begin{array}{l} v\_m = \left|v\right| \\ v\_s = \mathsf{copysign}\left(1, v\right) \\ v\_s \cdot \tan^{-1} -1 \end{array} \]
            v\_m = (fabs.f64 v)
            v\_s = (copysign.f64 #s(literal 1 binary64) v)
            (FPCore (v_s v_m H) :precision binary64 (* v_s (atan -1.0)))
            v\_m = fabs(v);
            v\_s = copysign(1.0, v);
            double code(double v_s, double v_m, double H) {
            	return v_s * atan(-1.0);
            }
            
            v\_m =     private
            v\_s =     private
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(v_s, v_m, h)
            use fmin_fmax_functions
                real(8), intent (in) :: v_s
                real(8), intent (in) :: v_m
                real(8), intent (in) :: h
                code = v_s * atan((-1.0d0))
            end function
            
            v\_m = Math.abs(v);
            v\_s = Math.copySign(1.0, v);
            public static double code(double v_s, double v_m, double H) {
            	return v_s * Math.atan(-1.0);
            }
            
            v\_m = math.fabs(v)
            v\_s = math.copysign(1.0, v)
            def code(v_s, v_m, H):
            	return v_s * math.atan(-1.0)
            
            v\_m = abs(v)
            v\_s = copysign(1.0, v)
            function code(v_s, v_m, H)
            	return Float64(v_s * atan(-1.0))
            end
            
            v\_m = abs(v);
            v\_s = sign(v) * abs(1.0);
            function tmp = code(v_s, v_m, H)
            	tmp = v_s * atan(-1.0);
            end
            
            v\_m = N[Abs[v], $MachinePrecision]
            v\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[v]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
            code[v$95$s_, v$95$m_, H_] := N[(v$95$s * N[ArcTan[-1.0], $MachinePrecision]), $MachinePrecision]
            
            \begin{array}{l}
            v\_m = \left|v\right|
            \\
            v\_s = \mathsf{copysign}\left(1, v\right)
            
            \\
            v\_s \cdot \tan^{-1} -1
            \end{array}
            
            Derivation
            1. Initial program 67.6%

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

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

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

              Reproduce

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