
(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 7 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+154) (atan (fma (/ (/ H v) v) -9.8 -1.0)) (if (<= v 1e+129) (atan (/ v (sqrt (fma v v (* H -19.6))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(fma(((H / v) / v), -9.8, -1.0));
} else if (v <= 1e+129) {
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 <= -1e+154) tmp = atan(fma(Float64(Float64(H / v) / v), -9.8, -1.0)); elseif (v <= 1e+129) 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, -1e+154], N[ArcTan[N[(N[(N[(H / v), $MachinePrecision] / v), $MachinePrecision] * -9.8 + -1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 1e+129], 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 -1 \cdot 10^{+154}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(\frac{\frac{H}{v}}{v}, -9.8, -1\right)\right)\\
\mathbf{elif}\;v \leq 10^{+129}:\\
\;\;\;\;\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 < -1.00000000000000004e154Initial program 3.0%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
metadata-eval3.0
Applied rewrites3.0%
Taylor expanded in v around -inf
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6499.4
Applied rewrites99.4%
associate-/r*N/A
lower-/.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
if -1.00000000000000004e154 < v < 1e129Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
if 1e129 < v Initial program 20.4%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(if (<= v -4.3e+15)
(atan (fma (/ (/ H v) v) -9.8 -1.0))
(if (<= v 8e-57)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (fma H (/ -9.8 v) v))))))
double code(double v, double H) {
double tmp;
if (v <= -4.3e+15) {
tmp = atan(fma(((H / v) / v), -9.8, -1.0));
} else if (v <= 8e-57) {
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 <= -4.3e+15) tmp = atan(fma(Float64(Float64(H / v) / v), -9.8, -1.0)); elseif (v <= 8e-57) 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, -4.3e+15], N[ArcTan[N[(N[(N[(H / v), $MachinePrecision] / v), $MachinePrecision] * -9.8 + -1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 8e-57], 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 -4.3 \cdot 10^{+15}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(\frac{\frac{H}{v}}{v}, -9.8, -1\right)\right)\\
\mathbf{elif}\;v \leq 8 \cdot 10^{-57}:\\
\;\;\;\;\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 < -4.3e15Initial program 45.3%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
metadata-eval45.3
Applied rewrites45.3%
Taylor expanded in v around -inf
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6495.5
Applied rewrites95.5%
associate-/r*N/A
lower-/.f64N/A
lower-/.f6495.9
Applied rewrites95.9%
if -4.3e15 < v < 7.99999999999999964e-57Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites99.5%
Taylor expanded in v around 0
lower-/.f6489.3
Applied rewrites89.3%
if 7.99999999999999964e-57 < v Initial program 55.8%
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
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6492.5
Applied rewrites92.5%
Final simplification92.4%
(FPCore (v H)
:precision binary64
(if (<= v -4.3e+15)
(atan (fma H (/ -9.8 (* v v)) -1.0))
(if (<= v 8e-57)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (fma H (/ -9.8 v) v))))))
double code(double v, double H) {
double tmp;
if (v <= -4.3e+15) {
tmp = atan(fma(H, (-9.8 / (v * v)), -1.0));
} else if (v <= 8e-57) {
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 <= -4.3e+15) tmp = atan(fma(H, Float64(-9.8 / Float64(v * v)), -1.0)); elseif (v <= 8e-57) 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, -4.3e+15], N[ArcTan[N[(H * N[(-9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 8e-57], 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 -4.3 \cdot 10^{+15}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{-9.8}{v \cdot v}, -1\right)\right)\\
\mathbf{elif}\;v \leq 8 \cdot 10^{-57}:\\
\;\;\;\;\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 < -4.3e15Initial program 45.3%
Taylor expanded in v around -inf
sub-negN/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6495.5
Applied rewrites95.5%
if -4.3e15 < v < 7.99999999999999964e-57Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites99.5%
Taylor expanded in v around 0
lower-/.f6489.3
Applied rewrites89.3%
if 7.99999999999999964e-57 < v Initial program 55.8%
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
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6492.5
Applied rewrites92.5%
Final simplification92.3%
(FPCore (v H)
:precision binary64
(if (<= v -4.3e+15)
(atan (fma H (/ -9.8 (* v v)) -1.0))
(if (<= v 1e-56)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -4.3e+15) {
tmp = atan(fma(H, (-9.8 / (v * v)), -1.0));
} else if (v <= 1e-56) {
tmp = atan((v * sqrt((-0.05102040816326531 / H))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -4.3e+15) tmp = atan(fma(H, Float64(-9.8 / Float64(v * v)), -1.0)); elseif (v <= 1e-56) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -4.3e+15], N[ArcTan[N[(H * N[(-9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 1e-56], 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 -4.3 \cdot 10^{+15}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{-9.8}{v \cdot v}, -1\right)\right)\\
\mathbf{elif}\;v \leq 10^{-56}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -4.3e15Initial program 45.3%
Taylor expanded in v around -inf
sub-negN/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6495.5
Applied rewrites95.5%
if -4.3e15 < v < 1e-56Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites99.5%
Taylor expanded in v around 0
lower-/.f6489.3
Applied rewrites89.3%
if 1e-56 < v Initial program 55.8%
Taylor expanded in v around inf
Applied rewrites92.2%
Final simplification92.2%
(FPCore (v H)
:precision binary64
(if (<= v -1.45e-131)
(atan -1.0)
(if (<= v 1.6e-109)
(atan (/ (* (* v v) -0.10204081632653061) H))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.45e-131) {
tmp = atan(-1.0);
} else if (v <= 1.6e-109) {
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.45d-131)) then
tmp = atan((-1.0d0))
else if (v <= 1.6d-109) 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.45e-131) {
tmp = Math.atan(-1.0);
} else if (v <= 1.6e-109) {
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.45e-131: tmp = math.atan(-1.0) elif v <= 1.6e-109: 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.45e-131) tmp = atan(-1.0); elseif (v <= 1.6e-109) 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.45e-131) tmp = atan(-1.0); elseif (v <= 1.6e-109) tmp = atan((((v * v) * -0.10204081632653061) / H)); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.45e-131], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 1.6e-109], 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.45 \cdot 10^{-131}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 1.6 \cdot 10^{-109}:\\
\;\;\;\;\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.4500000000000001e-131Initial program 57.6%
Taylor expanded in v around -inf
Applied rewrites80.2%
if -1.4500000000000001e-131 < v < 1.6000000000000001e-109Initial program 99.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
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6418.5
Applied rewrites18.5%
Taylor expanded in v around 0
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6418.5
Applied rewrites18.5%
if 1.6000000000000001e-109 < v Initial program 59.4%
Taylor expanded in v around inf
Applied rewrites88.0%
Final simplification70.5%
(FPCore (v H) :precision binary64 (if (<= v 1.06e-306) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= 1.06e-306) {
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.06d-306) 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.06e-306) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= 1.06e-306: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= 1.06e-306) 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.06e-306) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, 1.06e-306], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq 1.06 \cdot 10^{-306}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < 1.06e-306Initial program 67.7%
Taylor expanded in v around -inf
Applied rewrites61.9%
if 1.06e-306 < v Initial program 66.9%
Taylor expanded in v around inf
Applied rewrites72.5%
(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
Applied rewrites30.2%
herbie shell --seed 2024212
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))