
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
(FPCore (v H)
:precision binary64
(if (<= v -2e+154)
(atan -1.0)
(if (<= v 5e+112)
(atan
(/
v
(sqrt
(-
(* (* v v) (/ (* v v) (fma 19.6 H (* v v))))
(* (* 384.16 H) (/ H (fma v v (* H 19.6))))))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -2e+154) {
tmp = atan(-1.0);
} else if (v <= 5e+112) {
tmp = atan((v / sqrt((((v * v) * ((v * v) / fma(19.6, H, (v * v)))) - ((384.16 * H) * (H / fma(v, v, (H * 19.6))))))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -2e+154) tmp = atan(-1.0); elseif (v <= 5e+112) tmp = atan(Float64(v / sqrt(Float64(Float64(Float64(v * v) * Float64(Float64(v * v) / fma(19.6, H, Float64(v * v)))) - Float64(Float64(384.16 * H) * Float64(H / fma(v, v, Float64(H * 19.6)))))))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -2e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5e+112], N[ArcTan[N[(v / N[Sqrt[N[(N[(N[(v * v), $MachinePrecision] * N[(N[(v * v), $MachinePrecision] / N[(19.6 * H + N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(384.16 * H), $MachinePrecision] * N[(H / N[(v * v + N[(H * 19.6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5 \cdot 10^{+112}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\left(v \cdot v\right) \cdot \frac{v \cdot v}{\mathsf{fma}\left(19.6, H, v \cdot v\right)} - \left(384.16 \cdot H\right) \cdot \frac{H}{\mathsf{fma}\left(v, v, H \cdot 19.6\right)}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -2.00000000000000007e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -2.00000000000000007e154 < v < 5e112Initial program 99.7%
Applied rewrites81.1%
Applied rewrites99.8%
if 5e112 < v Initial program 23.7%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(let* ((t_0 (fma H 19.6 (* v v))))
(if (<= v -2e+154)
(atan -1.0)
(if (<= v 5e+112)
(atan
(/ v (sqrt (fma (* (* v v) (/ v t_0)) v (* (* -384.16 H) (/ H t_0))))))
(atan 1.0)))))
double code(double v, double H) {
double t_0 = fma(H, 19.6, (v * v));
double tmp;
if (v <= -2e+154) {
tmp = atan(-1.0);
} else if (v <= 5e+112) {
tmp = atan((v / sqrt(fma(((v * v) * (v / t_0)), v, ((-384.16 * H) * (H / t_0))))));
} 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 <= -2e+154) tmp = atan(-1.0); elseif (v <= 5e+112) tmp = atan(Float64(v / sqrt(fma(Float64(Float64(v * v) * Float64(v / t_0)), v, Float64(Float64(-384.16 * H) * Float64(H / t_0)))))); 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, -2e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5e+112], N[ArcTan[N[(v / N[Sqrt[N[(N[(N[(v * v), $MachinePrecision] * N[(v / t$95$0), $MachinePrecision]), $MachinePrecision] * v + N[(N[(-384.16 * H), $MachinePrecision] * N[(H / t$95$0), $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 -2 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5 \cdot 10^{+112}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(\left(v \cdot v\right) \cdot \frac{v}{t\_0}, v, \left(-384.16 \cdot H\right) \cdot \frac{H}{t\_0}\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -2.00000000000000007e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -2.00000000000000007e154 < v < 5e112Initial program 99.7%
Applied rewrites82.3%
metadata-evalN/A
metadata-evalN/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.8%
if 5e112 < v Initial program 23.7%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H) :precision binary64 (if (<= v -2e+154) (atan -1.0) (if (<= v 5e+112) (atan (/ v (sqrt (fma v v (* -19.6 H))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -2e+154) {
tmp = atan(-1.0);
} else if (v <= 5e+112) {
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 <= -2e+154) tmp = atan(-1.0); elseif (v <= 5e+112) 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, -2e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5e+112], 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 -2 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5 \cdot 10^{+112}:\\
\;\;\;\;\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}
if v < -2.00000000000000007e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -2.00000000000000007e154 < v < 5e112Initial program 99.7%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
metadata-eval99.7
Applied rewrites99.7%
if 5e112 < v Initial program 23.7%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(if (<= v -1.95e-91)
(atan -1.0)
(if (<= v 2.5e-29)
(atan (* (sqrt (/ -0.05102040816326531 H)) v))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.95e-91) {
tmp = atan(-1.0);
} else if (v <= 2.5e-29) {
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.95d-91)) then
tmp = atan((-1.0d0))
else if (v <= 2.5d-29) 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.95e-91) {
tmp = Math.atan(-1.0);
} else if (v <= 2.5e-29) {
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.95e-91: tmp = math.atan(-1.0) elif v <= 2.5e-29: 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.95e-91) tmp = atan(-1.0); elseif (v <= 2.5e-29) 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.95e-91) tmp = atan(-1.0); elseif (v <= 2.5e-29) tmp = atan((sqrt((-0.05102040816326531 / H)) * v)); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.95e-91], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2.5e-29], 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.95 \cdot 10^{-91}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2.5 \cdot 10^{-29}:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.94999999999999997e-91Initial program 56.5%
Taylor expanded in v around -inf
Applied rewrites88.8%
if -1.94999999999999997e-91 < v < 2.49999999999999993e-29Initial program 99.6%
Taylor expanded in v around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-atan.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in v around 0
Applied rewrites90.2%
if 2.49999999999999993e-29 < v Initial program 50.9%
Taylor expanded in v around inf
Applied rewrites95.0%
(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}
if v < -4.999999999999985e-310Initial program 66.4%
Taylor expanded in v around -inf
Applied rewrites70.8%
if -4.999999999999985e-310 < v Initial program 69.2%
Taylor expanded in v around inf
Applied rewrites66.1%
(FPCore (v H) :precision binary64 (atan -1.0))
double code(double v, double H) {
return atan(-1.0);
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((-1.0d0))
end function
public static double code(double v, double H) {
return Math.atan(-1.0);
}
def code(v, H): return math.atan(-1.0)
function code(v, H) return atan(-1.0) end
function tmp = code(v, H) tmp = atan(-1.0); end
code[v_, H_] := N[ArcTan[-1.0], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} -1
\end{array}
Initial program 67.7%
Taylor expanded in v around -inf
Applied rewrites39.3%
herbie shell --seed 2024342
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))