
(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+155) (atan -1.0) (if (<= v 2e+93) (atan (/ v (sqrt (fma v v (* H -19.6))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -2e+155) {
tmp = atan(-1.0);
} else if (v <= 2e+93) {
tmp = atan((v / sqrt(fma(v, v, (H * -19.6)))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -2e+155) tmp = atan(-1.0); elseif (v <= 2e+93) tmp = atan(Float64(v / sqrt(fma(v, v, Float64(H * -19.6))))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -2e+155], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2e+93], N[ArcTan[N[(v / N[Sqrt[N[(v * v + N[(H * -19.6), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2 \cdot 10^{+155}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2 \cdot 10^{+93}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, H \cdot -19.6\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -2.00000000000000001e155Initial program 3.1%
sqr-neg3.1%
sqr-neg3.1%
fma-neg3.1%
*-commutative3.1%
distribute-rgt-neg-in3.1%
metadata-eval3.1%
metadata-eval3.1%
Simplified3.1%
Taylor expanded in v around -inf 100.0%
if -2.00000000000000001e155 < v < 2.00000000000000009e93Initial program 99.8%
sqr-neg99.8%
sqr-neg99.8%
fma-neg99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
if 2.00000000000000009e93 < v Initial program 26.1%
sqr-neg26.1%
sqr-neg26.1%
fma-neg26.1%
*-commutative26.1%
distribute-rgt-neg-in26.1%
metadata-eval26.1%
metadata-eval26.1%
Simplified26.1%
Taylor expanded in v around inf 100.0%
(FPCore (v H) :precision binary64 (if (<= v -2e+155) (atan -1.0) (if (<= v 4e+93) (atan (/ v (sqrt (- (* v v) (* H 19.6))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -2e+155) {
tmp = atan(-1.0);
} else if (v <= 4e+93) {
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 <= (-2d+155)) then
tmp = atan((-1.0d0))
else if (v <= 4d+93) 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 <= -2e+155) {
tmp = Math.atan(-1.0);
} else if (v <= 4e+93) {
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 <= -2e+155: tmp = math.atan(-1.0) elif v <= 4e+93: 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 <= -2e+155) tmp = atan(-1.0); elseif (v <= 4e+93) 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 <= -2e+155) tmp = atan(-1.0); elseif (v <= 4e+93) 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, -2e+155], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 4e+93], 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 -2 \cdot 10^{+155}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 4 \cdot 10^{+93}:\\
\;\;\;\;\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 < -2.00000000000000001e155Initial program 3.1%
sqr-neg3.1%
sqr-neg3.1%
fma-neg3.1%
*-commutative3.1%
distribute-rgt-neg-in3.1%
metadata-eval3.1%
metadata-eval3.1%
Simplified3.1%
Taylor expanded in v around -inf 100.0%
if -2.00000000000000001e155 < v < 4.00000000000000017e93Initial program 99.8%
sqr-neg99.8%
sqr-neg99.8%
metadata-eval99.8%
Simplified99.8%
if 4.00000000000000017e93 < v Initial program 26.1%
sqr-neg26.1%
sqr-neg26.1%
fma-neg26.1%
*-commutative26.1%
distribute-rgt-neg-in26.1%
metadata-eval26.1%
metadata-eval26.1%
Simplified26.1%
Taylor expanded in v around inf 100.0%
Final simplification99.9%
(FPCore (v H)
:precision binary64
(if (<= v -1.35e-61)
(atan -1.0)
(if (<= v 5e-59)
(atan (/ v (sqrt (* H -19.6))))
(atan (/ v (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -1.35e-61) {
tmp = atan(-1.0);
} else if (v <= 5e-59) {
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 <= (-1.35d-61)) then
tmp = atan((-1.0d0))
else if (v <= 5d-59) 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 <= -1.35e-61) {
tmp = Math.atan(-1.0);
} else if (v <= 5e-59) {
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 <= -1.35e-61: tmp = math.atan(-1.0) elif v <= 5e-59: 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 <= -1.35e-61) tmp = atan(-1.0); elseif (v <= 5e-59) 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 <= -1.35e-61) tmp = atan(-1.0); elseif (v <= 5e-59) 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, -1.35e-61], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5e-59], 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 -1.35 \cdot 10^{-61}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5 \cdot 10^{-59}:\\
\;\;\;\;\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 < -1.34999999999999997e-61Initial program 53.7%
sqr-neg53.7%
sqr-neg53.7%
fma-neg53.7%
*-commutative53.7%
distribute-rgt-neg-in53.7%
metadata-eval53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in v around -inf 90.0%
if -1.34999999999999997e-61 < v < 5.0000000000000001e-59Initial program 99.8%
sqr-neg99.8%
sqr-neg99.8%
metadata-eval99.8%
Simplified99.8%
add-cube-cbrt99.0%
pow399.1%
Applied egg-rr99.1%
Taylor expanded in H around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt88.2%
associate-*r*88.2%
metadata-eval88.2%
rem-cube-cbrt89.8%
Simplified89.8%
add-log-exp15.1%
*-un-lft-identity15.1%
log-prod15.1%
metadata-eval15.1%
add-log-exp89.8%
*-un-lft-identity89.8%
Applied egg-rr89.8%
+-lft-identity89.8%
Simplified89.8%
if 5.0000000000000001e-59 < v Initial program 55.5%
sqr-neg55.5%
sqr-neg55.5%
metadata-eval55.5%
Simplified55.5%
Taylor expanded in H around 0 87.7%
(FPCore (v H) :precision binary64 (if (<= v -9.5e-162) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
double tmp;
if (v <= -9.5e-162) {
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 <= (-9.5d-162)) 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 <= -9.5e-162) {
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 <= -9.5e-162: 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 <= -9.5e-162) 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 <= -9.5e-162) tmp = atan(-1.0); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -9.5e-162], 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 -9.5 \cdot 10^{-162}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -9.5000000000000004e-162Initial program 60.0%
sqr-neg60.0%
sqr-neg60.0%
fma-neg60.0%
*-commutative60.0%
distribute-rgt-neg-in60.0%
metadata-eval60.0%
metadata-eval60.0%
Simplified60.0%
Taylor expanded in v around -inf 82.2%
if -9.5000000000000004e-162 < v Initial program 71.6%
sqr-neg71.6%
sqr-neg71.6%
metadata-eval71.6%
Simplified71.6%
Taylor expanded in H around 0 63.2%
(FPCore (v H) :precision binary64 (if (<= v -4e-310) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -4e-310: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -4e-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 <= -4e-310) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -4e-310], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -3.999999999999988e-310Initial program 66.7%
sqr-neg66.7%
sqr-neg66.7%
fma-neg66.8%
*-commutative66.8%
distribute-rgt-neg-in66.8%
metadata-eval66.8%
metadata-eval66.8%
Simplified66.8%
Taylor expanded in v around -inf 68.8%
if -3.999999999999988e-310 < v Initial program 67.1%
sqr-neg67.1%
sqr-neg67.1%
fma-neg67.1%
*-commutative67.1%
distribute-rgt-neg-in67.1%
metadata-eval67.1%
metadata-eval67.1%
Simplified67.1%
Taylor expanded in v around inf 67.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.0%
sqr-neg67.0%
sqr-neg67.0%
fma-neg67.0%
*-commutative67.0%
distribute-rgt-neg-in67.0%
metadata-eval67.0%
metadata-eval67.0%
Simplified67.0%
Taylor expanded in v around -inf 34.0%
herbie shell --seed 2024111
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))