
(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 -5e+154)
(atan -1.0)
(if (<= v 1e+140)
(atan (* v (pow (fma v v (* H -19.6)) -0.5)))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -5e+154) {
tmp = atan(-1.0);
} else if (v <= 1e+140) {
tmp = atan((v * pow(fma(v, v, (H * -19.6)), -0.5)));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -5e+154) tmp = atan(-1.0); elseif (v <= 1e+140) tmp = atan(Float64(v * (fma(v, v, Float64(H * -19.6)) ^ -0.5))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -5e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1e+140], N[ArcTan[N[(v * N[Power[N[(v * v + N[(H * -19.6), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 10^{+140}:\\
\;\;\;\;\tan^{-1} \left(v \cdot {\left(\mathsf{fma}\left(v, v, H \cdot -19.6\right)\right)}^{-0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -5.00000000000000004e154Initial program 3.1%
sqr-neg3.1%
sqr-neg3.1%
metadata-eval3.1%
Simplified3.1%
Taylor expanded in v around -inf 100.0%
if -5.00000000000000004e154 < v < 1.00000000000000006e140Initial program 99.7%
sqr-neg99.7%
sqr-neg99.7%
metadata-eval99.7%
Simplified99.7%
sub-neg99.7%
+-commutative99.7%
add-sqr-sqrt79.6%
hypot-define79.6%
*-commutative79.6%
distribute-rgt-neg-in79.6%
metadata-eval79.6%
Applied egg-rr79.6%
hypot-undefine79.6%
add-sqr-sqrt99.7%
unpow299.7%
+-commutative99.7%
unpow299.7%
add-sqr-sqrt79.6%
hypot-undefine79.6%
div-inv79.6%
*-commutative79.6%
Applied egg-rr79.6%
inv-pow79.6%
hypot-undefine79.6%
sqrt-pow279.6%
add-sqr-sqrt99.8%
fma-define99.8%
metadata-eval99.8%
Applied egg-rr99.8%
if 1.00000000000000006e140 < v Initial program 11.7%
sqr-neg11.7%
sqr-neg11.7%
metadata-eval11.7%
Simplified11.7%
Taylor expanded in v around inf 100.0%
Final simplification99.8%
(FPCore (v H) :precision binary64 (if (<= v -5e+154) (atan -1.0) (if (<= v 1.3e+140) (atan (/ v (sqrt (- (* v v) (* H 19.6))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -5e+154) {
tmp = atan(-1.0);
} else if (v <= 1.3e+140) {
tmp = atan((v / sqrt(((v * v) - (H * 19.6)))));
} 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+154)) then
tmp = atan((-1.0d0))
else if (v <= 1.3d+140) then
tmp = atan((v / sqrt(((v * v) - (h * 19.6d0)))))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -5e+154) {
tmp = Math.atan(-1.0);
} else if (v <= 1.3e+140) {
tmp = Math.atan((v / Math.sqrt(((v * v) - (H * 19.6)))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -5e+154: tmp = math.atan(-1.0) elif v <= 1.3e+140: tmp = math.atan((v / math.sqrt(((v * v) - (H * 19.6))))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -5e+154) tmp = atan(-1.0); elseif (v <= 1.3e+140) tmp = atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(H * 19.6))))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -5e+154) tmp = atan(-1.0); elseif (v <= 1.3e+140) tmp = atan((v / sqrt(((v * v) - (H * 19.6))))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -5e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.3e+140], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(H * 19.6), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.3 \cdot 10^{+140}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - H \cdot 19.6}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -5.00000000000000004e154Initial program 3.1%
sqr-neg3.1%
sqr-neg3.1%
metadata-eval3.1%
Simplified3.1%
Taylor expanded in v around -inf 100.0%
if -5.00000000000000004e154 < v < 1.3000000000000001e140Initial program 99.7%
sqr-neg99.7%
sqr-neg99.7%
metadata-eval99.7%
Simplified99.7%
if 1.3000000000000001e140 < v Initial program 11.7%
sqr-neg11.7%
sqr-neg11.7%
metadata-eval11.7%
Simplified11.7%
Taylor expanded in v around inf 100.0%
Final simplification99.8%
(FPCore (v H)
:precision binary64
(if (<= v -6.6e-197)
(atan -1.0)
(if (<= v 2.4e-138)
(atan (* -0.10204081632653061 (/ v (/ H v))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -6.6e-197) {
tmp = atan(-1.0);
} else if (v <= 2.4e-138) {
tmp = atan((-0.10204081632653061 * (v / (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 <= (-6.6d-197)) then
tmp = atan((-1.0d0))
else if (v <= 2.4d-138) then
tmp = atan(((-0.10204081632653061d0) * (v / (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 <= -6.6e-197) {
tmp = Math.atan(-1.0);
} else if (v <= 2.4e-138) {
tmp = Math.atan((-0.10204081632653061 * (v / (H / v))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -6.6e-197: tmp = math.atan(-1.0) elif v <= 2.4e-138: tmp = math.atan((-0.10204081632653061 * (v / (H / v)))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -6.6e-197) tmp = atan(-1.0); elseif (v <= 2.4e-138) tmp = atan(Float64(-0.10204081632653061 * Float64(v / Float64(H / v)))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -6.6e-197) tmp = atan(-1.0); elseif (v <= 2.4e-138) tmp = atan((-0.10204081632653061 * (v / (H / v)))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -6.6e-197], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2.4e-138], N[ArcTan[N[(-0.10204081632653061 * N[(v / N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -6.6 \cdot 10^{-197}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2.4 \cdot 10^{-138}:\\
\;\;\;\;\tan^{-1} \left(-0.10204081632653061 \cdot \frac{v}{\frac{H}{v}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -6.5999999999999995e-197Initial program 66.3%
sqr-neg66.3%
sqr-neg66.3%
metadata-eval66.3%
Simplified66.3%
Taylor expanded in v around -inf 73.1%
if -6.5999999999999995e-197 < v < 2.3999999999999999e-138Initial program 99.6%
sqr-neg99.6%
sqr-neg99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in H around 0 25.3%
Taylor expanded in v around 0 25.3%
*-un-lft-identity25.3%
times-frac25.3%
metadata-eval25.3%
Applied egg-rr25.3%
if 2.3999999999999999e-138 < v Initial program 62.8%
sqr-neg62.8%
sqr-neg62.8%
metadata-eval62.8%
Simplified62.8%
Taylor expanded in v around inf 81.7%
(FPCore (v H) :precision binary64 (if (<= v -6.6e-197) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
double tmp;
if (v <= -6.6e-197) {
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 <= (-6.6d-197)) 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 <= -6.6e-197) {
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 <= -6.6e-197: 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 <= -6.6e-197) 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 <= -6.6e-197) tmp = atan(-1.0); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -6.6e-197], 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 -6.6 \cdot 10^{-197}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -6.5999999999999995e-197Initial program 66.3%
sqr-neg66.3%
sqr-neg66.3%
metadata-eval66.3%
Simplified66.3%
Taylor expanded in v around -inf 73.1%
if -6.5999999999999995e-197 < v Initial program 73.1%
sqr-neg73.1%
sqr-neg73.1%
metadata-eval73.1%
Simplified73.1%
Taylor expanded in H around 0 66.1%
(FPCore (v H) :precision binary64 (if (<= v 1.2e-308) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= 1.2e-308) {
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 <= 1.2d-308) 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 <= 1.2e-308) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= 1.2e-308: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= 1.2e-308) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= 1.2e-308) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, 1.2e-308], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq 1.2 \cdot 10^{-308}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < 1.1999999999999998e-308Initial program 69.9%
sqr-neg69.9%
sqr-neg69.9%
metadata-eval69.9%
Simplified69.9%
Taylor expanded in v around -inf 65.6%
if 1.1999999999999998e-308 < v Initial program 70.6%
sqr-neg70.6%
sqr-neg70.6%
metadata-eval70.6%
Simplified70.6%
Taylor expanded in v around inf 65.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 70.3%
sqr-neg70.3%
sqr-neg70.3%
metadata-eval70.3%
Simplified70.3%
Taylor expanded in v around -inf 31.7%
herbie shell --seed 2024110
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))