
(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 4e+149) (atan (/ v (sqrt (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 <= 4e+149) {
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+154) tmp = atan(-1.0); elseif (v <= 4e+149) 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+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 4e+149], 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^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 4 \cdot 10^{+149}:\\
\;\;\;\;\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.00000000000000007e154Initial program 3.1%
Taylor expanded in v around -inf
Simplified100.0%
if -2.00000000000000007e154 < v < 4.0000000000000002e149Initial program 99.7%
sub-negN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
metadata-eval99.7
Applied egg-rr99.7%
if 4.0000000000000002e149 < v Initial program 5.5%
Taylor expanded in v around inf
Simplified100.0%
(FPCore (v H)
:precision binary64
(if (<= v -6.6e-58)
(atan -1.0)
(if (<= v 3.3e-39)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (fma H (/ -9.8 v) v))))))
double code(double v, double H) {
double tmp;
if (v <= -6.6e-58) {
tmp = atan(-1.0);
} else if (v <= 3.3e-39) {
tmp = atan((v * sqrt((-0.05102040816326531 / H))));
} else {
tmp = atan((v / fma(H, (-9.8 / v), v)));
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -6.6e-58) tmp = atan(-1.0); elseif (v <= 3.3e-39) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(Float64(v / fma(H, Float64(-9.8 / v), v))); end return tmp end
code[v_, H_] := If[LessEqual[v, -6.6e-58], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 3.3e-39], N[ArcTan[N[(v * N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v / N[(H * N[(-9.8 / v), $MachinePrecision] + v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -6.6 \cdot 10^{-58}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 3.3 \cdot 10^{-39}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\mathsf{fma}\left(H, \frac{-9.8}{v}, v\right)}\right)\\
\end{array}
\end{array}
if v < -6.60000000000000052e-58Initial program 51.5%
Taylor expanded in v around -inf
Simplified87.6%
if -6.60000000000000052e-58 < v < 3.29999999999999985e-39Initial program 99.6%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
Applied egg-rr99.6%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
/-lowering-/.f64N/A
unpow2N/A
rem-square-sqrt91.2
Simplified91.2%
if 3.29999999999999985e-39 < v Initial program 49.7%
Taylor expanded in H around 0
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
associate-*r/N/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f6490.3
Simplified90.3%
Final simplification89.7%
(FPCore (v H)
:precision binary64
(if (<= v -6.6e-58)
(atan -1.0)
(if (<= v 2.7e-39)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -6.6e-58) {
tmp = atan(-1.0);
} else if (v <= 2.7e-39) {
tmp = atan((v * sqrt((-0.05102040816326531 / 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 <= (-6.6d-58)) then
tmp = atan((-1.0d0))
else if (v <= 2.7d-39) then
tmp = atan((v * sqrt(((-0.05102040816326531d0) / h))))
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-58) {
tmp = Math.atan(-1.0);
} else if (v <= 2.7e-39) {
tmp = Math.atan((v * Math.sqrt((-0.05102040816326531 / H))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -6.6e-58: tmp = math.atan(-1.0) elif v <= 2.7e-39: tmp = math.atan((v * math.sqrt((-0.05102040816326531 / H)))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -6.6e-58) tmp = atan(-1.0); elseif (v <= 2.7e-39) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -6.6e-58) tmp = atan(-1.0); elseif (v <= 2.7e-39) tmp = atan((v * sqrt((-0.05102040816326531 / H)))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -6.6e-58], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2.7e-39], N[ArcTan[N[(v * N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -6.6 \cdot 10^{-58}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2.7 \cdot 10^{-39}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -6.60000000000000052e-58Initial program 51.5%
Taylor expanded in v around -inf
Simplified87.6%
if -6.60000000000000052e-58 < v < 2.7000000000000001e-39Initial program 99.6%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
Applied egg-rr99.6%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
/-lowering-/.f64N/A
unpow2N/A
rem-square-sqrt91.2
Simplified91.2%
if 2.7000000000000001e-39 < v Initial program 49.7%
Taylor expanded in v around inf
Simplified89.8%
Final simplification89.5%
(FPCore (v H)
:precision binary64
(if (<= v -1.05e-153)
(atan -1.0)
(if (<= v 1.1e-194)
(atan (/ (* (* v v) -0.10204081632653061) H))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.05e-153) {
tmp = atan(-1.0);
} else if (v <= 1.1e-194) {
tmp = atan((((v * v) * -0.10204081632653061) / 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.05d-153)) then
tmp = atan((-1.0d0))
else if (v <= 1.1d-194) then
tmp = atan((((v * v) * (-0.10204081632653061d0)) / 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.05e-153) {
tmp = Math.atan(-1.0);
} else if (v <= 1.1e-194) {
tmp = Math.atan((((v * v) * -0.10204081632653061) / H));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1.05e-153: tmp = math.atan(-1.0) elif v <= 1.1e-194: tmp = math.atan((((v * v) * -0.10204081632653061) / H)) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1.05e-153) tmp = atan(-1.0); elseif (v <= 1.1e-194) tmp = atan(Float64(Float64(Float64(v * v) * -0.10204081632653061) / H)); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1.05e-153) tmp = atan(-1.0); elseif (v <= 1.1e-194) tmp = atan((((v * v) * -0.10204081632653061) / H)); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.05e-153], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.1e-194], N[ArcTan[N[(N[(N[(v * v), $MachinePrecision] * -0.10204081632653061), $MachinePrecision] / H), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.05 \cdot 10^{-153}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.1 \cdot 10^{-194}:\\
\;\;\;\;\tan^{-1} \left(\frac{\left(v \cdot v\right) \cdot -0.10204081632653061}{H}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.05000000000000002e-153Initial program 60.4%
Taylor expanded in v around -inf
Simplified75.1%
if -1.05000000000000002e-153 < v < 1.1000000000000001e-194Initial program 99.6%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
metadata-eval95.0
Applied egg-rr95.0%
Taylor expanded in v around inf
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6447.7
Simplified47.7%
Taylor expanded in H around inf
associate-*r/N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6447.7
Simplified47.7%
if 1.1000000000000001e-194 < v Initial program 60.4%
Taylor expanded in v around inf
Simplified74.3%
(FPCore (v H) :precision binary64 (if (<= v -6.5e-304) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -6.5e-304) {
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 <= (-6.5d-304)) 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 <= -6.5e-304) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -6.5e-304: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -6.5e-304) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -6.5e-304) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -6.5e-304], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -6.5 \cdot 10^{-304}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -6.50000000000000011e-304Initial program 67.0%
Taylor expanded in v around -inf
Simplified63.1%
if -6.50000000000000011e-304 < v Initial program 67.6%
Taylor expanded in v around inf
Simplified61.3%
(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%
Taylor expanded in v around -inf
Simplified34.4%
herbie shell --seed 2024204
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))