
(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 5 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+153) (atan -1.0) (if (<= v 8.3e+130) (atan (/ v (sqrt (fma H -19.6 (* v v))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+153) {
tmp = atan(-1.0);
} else if (v <= 8.3e+130) {
tmp = atan((v / sqrt(fma(H, -19.6, (v * v)))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1e+153) tmp = atan(-1.0); elseif (v <= 8.3e+130) tmp = atan(Float64(v / sqrt(fma(H, -19.6, Float64(v * v))))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -1e+153], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 8.3e+130], N[ArcTan[N[(v / N[Sqrt[N[(H * -19.6 + N[(v * v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+153}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 8.3 \cdot 10^{+130}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(H, -19.6, v \cdot v\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1e153Initial program 3.1%
Taylor expanded in v around -inf
Simplified100.0%
if -1e153 < v < 8.29999999999999959e130Initial program 98.6%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f64N/A
metadata-evalN/A
metadata-evalN/A
*-lowering-*.f6498.6
Applied egg-rr98.6%
if 8.29999999999999959e130 < v Initial program 17.0%
Taylor expanded in v around inf
Simplified100.0%
(FPCore (v H)
:precision binary64
(if (<= v -3.05e-51)
(atan -1.0)
(if (<= v 1.7e-48)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (fma H (/ -9.8 v) v))))))
double code(double v, double H) {
double tmp;
if (v <= -3.05e-51) {
tmp = atan(-1.0);
} else if (v <= 1.7e-48) {
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 <= -3.05e-51) tmp = atan(-1.0); elseif (v <= 1.7e-48) 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, -3.05e-51], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.7e-48], 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 -3.05 \cdot 10^{-51}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.7 \cdot 10^{-48}:\\
\;\;\;\;\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 < -3.05000000000000017e-51Initial program 50.5%
Taylor expanded in v around -inf
Simplified91.1%
if -3.05000000000000017e-51 < v < 1.70000000000000014e-48Initial program 98.4%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
Applied egg-rr98.4%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
/-lowering-/.f64N/A
unpow2N/A
rem-square-sqrt85.4
Simplified85.4%
if 1.70000000000000014e-48 < v Initial program 52.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-/.f6494.8
Simplified94.8%
Final simplification90.7%
(FPCore (v H)
:precision binary64
(if (<= v -1.28e-54)
(atan -1.0)
(if (<= v 8.6e-47)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.28e-54) {
tmp = atan(-1.0);
} else if (v <= 8.6e-47) {
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 <= (-1.28d-54)) then
tmp = atan((-1.0d0))
else if (v <= 8.6d-47) 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 <= -1.28e-54) {
tmp = Math.atan(-1.0);
} else if (v <= 8.6e-47) {
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 <= -1.28e-54: tmp = math.atan(-1.0) elif v <= 8.6e-47: 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 <= -1.28e-54) tmp = atan(-1.0); elseif (v <= 8.6e-47) 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 <= -1.28e-54) tmp = atan(-1.0); elseif (v <= 8.6e-47) tmp = atan((v * sqrt((-0.05102040816326531 / H)))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.28e-54], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 8.6e-47], 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 -1.28 \cdot 10^{-54}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 8.6 \cdot 10^{-47}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.2800000000000001e-54Initial program 50.5%
Taylor expanded in v around -inf
Simplified91.1%
if -1.2800000000000001e-54 < v < 8.5999999999999995e-47Initial program 98.4%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
Applied egg-rr98.4%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
/-lowering-/.f64N/A
unpow2N/A
rem-square-sqrt85.4
Simplified85.4%
if 8.5999999999999995e-47 < v Initial program 52.7%
Taylor expanded in v around inf
Simplified94.6%
Final simplification90.6%
(FPCore (v H) :precision binary64 (if (<= v 3e-303) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= 3e-303) {
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 <= 3d-303) 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 <= 3e-303) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= 3e-303: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= 3e-303) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= 3e-303) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, 3e-303], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq 3 \cdot 10^{-303}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < 3.00000000000000028e-303Initial program 63.2%
Taylor expanded in v around -inf
Simplified72.7%
if 3.00000000000000028e-303 < v Initial program 67.6%
Taylor expanded in v around inf
Simplified69.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 65.5%
Taylor expanded in v around -inf
Simplified36.2%
herbie shell --seed 2024198
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))