
(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 -1.35e+154)
(atan -1.0)
(if (<= v 1.35e+109)
(atan (/ v (sqrt (- (* v v) (* 19.6 H)))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.35e+154) {
tmp = atan(-1.0);
} else if (v <= 1.35e+109) {
tmp = atan((v / sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = atan(1.0);
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-1.35d+154)) then
tmp = atan((-1.0d0))
else if (v <= 1.35d+109) then
tmp = atan((v / sqrt(((v * v) - (19.6d0 * h)))))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1.35e+154) {
tmp = Math.atan(-1.0);
} else if (v <= 1.35e+109) {
tmp = Math.atan((v / Math.sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1.35e+154: tmp = math.atan(-1.0) elif v <= 1.35e+109: tmp = math.atan((v / math.sqrt(((v * v) - (19.6 * H))))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1.35e+154) tmp = atan(-1.0); elseif (v <= 1.35e+109) tmp = atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(19.6 * H))))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1.35e+154) tmp = atan(-1.0); elseif (v <= 1.35e+109) tmp = atan((v / sqrt(((v * v) - (19.6 * H))))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.35e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.35e+109], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(19.6 * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.35 \cdot 10^{+109}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.35000000000000003e154Initial program 3.1%
sqr-neg3.1%
sqr-neg3.1%
metadata-eval3.1%
Simplified3.1%
Taylor expanded in v around -inf 100.0%
if -1.35000000000000003e154 < v < 1.35000000000000001e109Initial program 99.8%
sqr-neg99.8%
sqr-neg99.8%
metadata-eval99.8%
Simplified99.8%
if 1.35000000000000001e109 < v Initial program 24.9%
sqr-neg24.9%
sqr-neg24.9%
metadata-eval24.9%
Simplified24.9%
Taylor expanded in v around inf 100.0%
(FPCore (v H)
:precision binary64
(if (<= v -4.7e-35)
(atan -1.0)
(if (<= v 1.18e-40)
(atan (/ v (sqrt (* H -19.6))))
(atan (/ v (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -4.7e-35) {
tmp = atan(-1.0);
} else if (v <= 1.18e-40) {
tmp = atan((v / sqrt((H * -19.6))));
} else {
tmp = atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-4.7d-35)) then
tmp = atan((-1.0d0))
else if (v <= 1.18d-40) then
tmp = atan((v / sqrt((h * (-19.6d0)))))
else
tmp = atan((v / (v + ((-9.8d0) * (h / v)))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -4.7e-35) {
tmp = Math.atan(-1.0);
} else if (v <= 1.18e-40) {
tmp = Math.atan((v / Math.sqrt((H * -19.6))));
} else {
tmp = Math.atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -4.7e-35: tmp = math.atan(-1.0) elif v <= 1.18e-40: tmp = math.atan((v / math.sqrt((H * -19.6)))) else: tmp = math.atan((v / (v + (-9.8 * (H / v))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -4.7e-35) tmp = atan(-1.0); elseif (v <= 1.18e-40) tmp = atan(Float64(v / sqrt(Float64(H * -19.6)))); else tmp = atan(Float64(v / Float64(v + Float64(-9.8 * Float64(H / v))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -4.7e-35) tmp = atan(-1.0); elseif (v <= 1.18e-40) tmp = atan((v / sqrt((H * -19.6)))); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -4.7e-35], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.18e-40], N[ArcTan[N[(v / N[Sqrt[N[(H * -19.6), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v / N[(v + N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -4.7 \cdot 10^{-35}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.18 \cdot 10^{-40}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{H \cdot -19.6}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -4.7e-35Initial program 48.9%
sqr-neg48.9%
sqr-neg48.9%
metadata-eval48.9%
Simplified48.9%
Taylor expanded in v around -inf 93.1%
if -4.7e-35 < v < 1.1799999999999999e-40Initial program 99.6%
sqr-neg99.6%
sqr-neg99.6%
metadata-eval99.6%
Simplified99.6%
add-cube-cbrt98.9%
pow398.8%
Applied egg-rr98.8%
Taylor expanded in H around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt89.9%
rem-cube-cbrt91.3%
distribute-lft-neg-in91.3%
metadata-eval91.3%
*-lft-identity91.3%
Simplified91.3%
if 1.1799999999999999e-40 < v Initial program 58.1%
sqr-neg58.1%
sqr-neg58.1%
metadata-eval58.1%
Simplified58.1%
Taylor expanded in H around 0 89.8%
(FPCore (v H)
:precision binary64
(if (<= v -1.25e-181)
(atan -1.0)
(if (<= v 2.1e-144)
(atan (* v (* -0.10204081632653061 (/ v H))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.25e-181) {
tmp = atan(-1.0);
} else if (v <= 2.1e-144) {
tmp = atan((v * (-0.10204081632653061 * (v / H))));
} else {
tmp = atan(1.0);
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-1.25d-181)) then
tmp = atan((-1.0d0))
else if (v <= 2.1d-144) then
tmp = atan((v * ((-0.10204081632653061d0) * (v / h))))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1.25e-181) {
tmp = Math.atan(-1.0);
} else if (v <= 2.1e-144) {
tmp = Math.atan((v * (-0.10204081632653061 * (v / H))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1.25e-181: tmp = math.atan(-1.0) elif v <= 2.1e-144: tmp = math.atan((v * (-0.10204081632653061 * (v / H)))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1.25e-181) tmp = atan(-1.0); elseif (v <= 2.1e-144) tmp = atan(Float64(v * Float64(-0.10204081632653061 * Float64(v / H)))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1.25e-181) tmp = atan(-1.0); elseif (v <= 2.1e-144) tmp = atan((v * (-0.10204081632653061 * (v / H)))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.25e-181], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2.1e-144], N[ArcTan[N[(v * N[(-0.10204081632653061 * N[(v / H), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.25 \cdot 10^{-181}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2.1 \cdot 10^{-144}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \left(-0.10204081632653061 \cdot \frac{v}{H}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.25e-181Initial program 56.1%
sqr-neg56.1%
sqr-neg56.1%
metadata-eval56.1%
Simplified56.1%
Taylor expanded in v around -inf 81.7%
if -1.25e-181 < v < 2.1000000000000001e-144Initial program 99.6%
sqr-neg99.6%
sqr-neg99.6%
metadata-eval99.6%
Simplified99.6%
clear-num99.5%
inv-pow99.5%
sub-neg99.5%
add-sqr-sqrt99.5%
hypot-define99.5%
*-commutative99.5%
distribute-rgt-neg-in99.5%
metadata-eval99.5%
Applied egg-rr99.5%
unpow-199.5%
associate-/r/99.5%
Applied egg-rr99.5%
Taylor expanded in H around 0 0.0%
associate-/l*0.0%
unpow20.0%
rem-square-sqrt28.8%
Simplified28.8%
Taylor expanded in v around 0 28.8%
if 2.1000000000000001e-144 < v Initial program 65.5%
sqr-neg65.5%
sqr-neg65.5%
metadata-eval65.5%
Simplified65.5%
Taylor expanded in v around inf 78.6%
Final simplification71.5%
(FPCore (v H) :precision binary64 (if (<= v -1.25e-181) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
double tmp;
if (v <= -1.25e-181) {
tmp = atan(-1.0);
} else {
tmp = atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
real(8) function code(v, h)
real(8), intent (in) :: v
real(8), intent (in) :: h
real(8) :: tmp
if (v <= (-1.25d-181)) then
tmp = atan((-1.0d0))
else
tmp = atan((v / (v + ((-9.8d0) * (h / v)))))
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1.25e-181) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan((v / (v + (-9.8 * (H / v)))));
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1.25e-181: tmp = math.atan(-1.0) else: tmp = math.atan((v / (v + (-9.8 * (H / v))))) return tmp
function code(v, H) tmp = 0.0 if (v <= -1.25e-181) tmp = atan(-1.0); else tmp = atan(Float64(v / Float64(v + Float64(-9.8 * Float64(H / v))))); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1.25e-181) tmp = atan(-1.0); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.25e-181], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[N[(v / N[(v + N[(-9.8 * N[(H / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.25 \cdot 10^{-181}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -1.25e-181Initial program 56.1%
sqr-neg56.1%
sqr-neg56.1%
metadata-eval56.1%
Simplified56.1%
Taylor expanded in v around -inf 81.7%
if -1.25e-181 < v Initial program 75.3%
sqr-neg75.3%
sqr-neg75.3%
metadata-eval75.3%
Simplified75.3%
Taylor expanded in H around 0 64.7%
(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 61.8%
sqr-neg61.8%
sqr-neg61.8%
metadata-eval61.8%
Simplified61.8%
Taylor expanded in v around -inf 71.4%
if -4.999999999999985e-310 < v Initial program 72.3%
sqr-neg72.3%
sqr-neg72.3%
metadata-eval72.3%
Simplified72.3%
Taylor expanded in v around inf 63.7%
(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.3%
sqr-neg67.3%
sqr-neg67.3%
metadata-eval67.3%
Simplified67.3%
Taylor expanded in v around -inf 35.0%
herbie shell --seed 2024131
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))