
(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 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v H) :precision binary64 (atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))
double code(double v, double H) {
return atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
code = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * h)))))
end function
public static double code(double v, double H) {
return Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
}
def code(v, H): return math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H)))))
function code(v, H) return atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))) end
function tmp = code(v, H) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); end
code[v_, H_] := N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)
\end{array}
(FPCore (v H)
:precision binary64
(if (<= v -1e+154)
(atan -1.0)
(if (<= v 4e+131)
(atan (/ v (sqrt (fma v v (/ (* -384.16 H) 19.6)))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(-1.0);
} else if (v <= 4e+131) {
tmp = atan((v / sqrt(fma(v, v, ((-384.16 * H) / 19.6)))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 4e+131) tmp = atan(Float64(v / sqrt(fma(v, v, Float64(Float64(-384.16 * H) / 19.6))))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -1e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 4e+131], N[ArcTan[N[(v / N[Sqrt[N[(v * v + N[(N[(-384.16 * H), $MachinePrecision] / 19.6), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 4 \cdot 10^{+131}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, \frac{-384.16 \cdot H}{19.6}\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.00000000000000004e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -1.00000000000000004e154 < v < 3.9999999999999996e131Initial program 99.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
lift-*.f64N/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-neg-inN/A
neg-sub0N/A
mul0-lftN/A
lift-*.f64N/A
flip--N/A
Applied rewrites75.6%
metadata-evalN/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-+.f64N/A
+-lft-identityN/A
associate-/l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval99.7
Applied rewrites99.7%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
lower-/.f6499.8
Applied rewrites99.8%
if 3.9999999999999996e131 < v Initial program 19.7%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(if (<= v -1e+154)
(atan -1.0)
(if (<= v 4e+131)
(atan (* (/ (- -1.0) (sqrt (fma -19.6 H (* v v)))) v))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(-1.0);
} else if (v <= 4e+131) {
tmp = atan(((-(-1.0) / sqrt(fma(-19.6, H, (v * v)))) * v));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 4e+131) tmp = atan(Float64(Float64(Float64(-(-1.0)) / sqrt(fma(-19.6, H, Float64(v * v)))) * v)); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -1e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 4e+131], N[ArcTan[N[(N[((--1.0) / N[Sqrt[N[(-19.6 * H + N[(v * v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * v), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 4 \cdot 10^{+131}:\\
\;\;\;\;\tan^{-1} \left(\frac{--1}{\sqrt{\mathsf{fma}\left(-19.6, H, v \cdot v\right)}} \cdot v\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.00000000000000004e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -1.00000000000000004e154 < v < 3.9999999999999996e131Initial program 99.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites99.8%
if 3.9999999999999996e131 < v Initial program 19.7%
Taylor expanded in v around inf
Applied rewrites100.0%
Final simplification99.9%
(FPCore (v H)
:precision binary64
(if (<= v -1.7e+105)
(atan -1.0)
(if (<= v 4e+131)
(atan (* (sqrt (/ 1.0 (fma -19.6 H (* v v)))) v))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.7e+105) {
tmp = atan(-1.0);
} else if (v <= 4e+131) {
tmp = atan((sqrt((1.0 / fma(-19.6, H, (v * v)))) * v));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1.7e+105) tmp = atan(-1.0); elseif (v <= 4e+131) tmp = atan(Float64(sqrt(Float64(1.0 / fma(-19.6, H, Float64(v * v)))) * v)); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -1.7e+105], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 4e+131], N[ArcTan[N[(N[Sqrt[N[(1.0 / N[(-19.6 * H + N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * v), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.7 \cdot 10^{+105}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 4 \cdot 10^{+131}:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{1}{\mathsf{fma}\left(-19.6, H, v \cdot v\right)}} \cdot v\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.7e105Initial program 23.7%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -1.7e105 < v < 3.9999999999999996e131Initial program 99.7%
Taylor expanded in v around 0
cancel-sign-sub-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.8
Applied rewrites99.8%
if 3.9999999999999996e131 < v Initial program 19.7%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H) :precision binary64 (if (<= v -1e+154) (atan -1.0) (if (<= v 4e+131) (atan (/ v (sqrt (fma v v (* -19.6 H))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(-1.0);
} else if (v <= 4e+131) {
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 <= -1e+154) tmp = atan(-1.0); elseif (v <= 4e+131) 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, -1e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 4e+131], N[ArcTan[N[(v / N[Sqrt[N[(v * v + N[(-19.6 * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 4 \cdot 10^{+131}:\\
\;\;\;\;\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 < -1.00000000000000004e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -1.00000000000000004e154 < v < 3.9999999999999996e131Initial program 99.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
if 3.9999999999999996e131 < v Initial program 19.7%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(if (<= v -1.58e+19)
(atan -1.0)
(if (<= v 1.28e-67)
(atan (* (sqrt (/ -0.05102040816326531 H)) v))
(atan (/ v (fma (/ -9.8 v) H v))))))
double code(double v, double H) {
double tmp;
if (v <= -1.58e+19) {
tmp = atan(-1.0);
} else if (v <= 1.28e-67) {
tmp = atan((sqrt((-0.05102040816326531 / H)) * v));
} else {
tmp = atan((v / fma((-9.8 / v), H, v)));
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1.58e+19) tmp = atan(-1.0); elseif (v <= 1.28e-67) tmp = atan(Float64(sqrt(Float64(-0.05102040816326531 / H)) * v)); else tmp = atan(Float64(v / fma(Float64(-9.8 / v), H, v))); end return tmp end
code[v_, H_] := If[LessEqual[v, -1.58e+19], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.28e-67], N[ArcTan[N[(N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision] * v), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v / N[(N[(-9.8 / v), $MachinePrecision] * H + v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.58 \cdot 10^{+19}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.28 \cdot 10^{-67}:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\mathsf{fma}\left(\frac{-9.8}{v}, H, v\right)}\right)\\
\end{array}
\end{array}
if v < -1.58e19Initial program 42.1%
Taylor expanded in v around -inf
Applied rewrites95.8%
if -1.58e19 < v < 1.28e-67Initial program 99.5%
Taylor expanded in v around 0
cancel-sign-sub-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 rewrites86.9%
if 1.28e-67 < v Initial program 68.8%
Taylor expanded in H around 0
+-commutativeN/A
associate-*r/N/A
associate-*l/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-*r/N/A
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6492.9
Applied rewrites92.9%
(FPCore (v H)
:precision binary64
(if (<= v -1.58e+19)
(atan -1.0)
(if (<= v 1.28e-67)
(atan (* (sqrt (/ -0.05102040816326531 H)) v))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.58e+19) {
tmp = atan(-1.0);
} else if (v <= 1.28e-67) {
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.58d+19)) then
tmp = atan((-1.0d0))
else if (v <= 1.28d-67) 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.58e+19) {
tmp = Math.atan(-1.0);
} else if (v <= 1.28e-67) {
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.58e+19: tmp = math.atan(-1.0) elif v <= 1.28e-67: 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.58e+19) tmp = atan(-1.0); elseif (v <= 1.28e-67) 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.58e+19) tmp = atan(-1.0); elseif (v <= 1.28e-67) tmp = atan((sqrt((-0.05102040816326531 / H)) * v)); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.58e+19], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.28e-67], 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.58 \cdot 10^{+19}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.28 \cdot 10^{-67}:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.58e19Initial program 42.1%
Taylor expanded in v around -inf
Applied rewrites95.8%
if -1.58e19 < v < 1.28e-67Initial program 99.5%
Taylor expanded in v around 0
cancel-sign-sub-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 rewrites86.9%
if 1.28e-67 < v Initial program 68.8%
Taylor expanded in v around inf
Applied rewrites92.4%
(FPCore (v H) :precision binary64 (if (<= v -3.1e-305) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -3.1e-305) {
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 <= (-3.1d-305)) 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 <= -3.1e-305) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -3.1e-305: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -3.1e-305) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -3.1e-305) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -3.1e-305], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -3.1 \cdot 10^{-305}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -3.0999999999999998e-305Initial program 63.9%
Taylor expanded in v around -inf
Applied rewrites66.3%
if -3.0999999999999998e-305 < v Initial program 75.6%
Taylor expanded in v around inf
Applied rewrites74.2%
(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 69.2%
Taylor expanded in v around -inf
Applied rewrites37.0%
herbie shell --seed 2024332
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))