
(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 -2e+154) (atan -1.0) (if (<= v 4e+136) (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+136) {
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+136) 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+136], 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^{+136}:\\
\;\;\;\;\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
Applied rewrites100.0%
if -2.00000000000000007e154 < v < 4.00000000000000023e136Initial program 99.7%
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.7
Applied rewrites99.7%
if 4.00000000000000023e136 < v Initial program 14.4%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(if (<= v -1.06e-67)
(atan (fma H (/ -9.8 (* v v)) -1.0))
(if (<= v 9.2e-43)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (/ v (fma H (/ -9.8 v) v))))))
double code(double v, double H) {
double tmp;
if (v <= -1.06e-67) {
tmp = atan(fma(H, (-9.8 / (v * v)), -1.0));
} else if (v <= 9.2e-43) {
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 <= -1.06e-67) tmp = atan(fma(H, Float64(-9.8 / Float64(v * v)), -1.0)); elseif (v <= 9.2e-43) 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, -1.06e-67], N[ArcTan[N[(H * N[(-9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 9.2e-43], 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 -1.06 \cdot 10^{-67}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{-9.8}{v \cdot v}, -1\right)\right)\\
\mathbf{elif}\;v \leq 9.2 \cdot 10^{-43}:\\
\;\;\;\;\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 < -1.06e-67Initial program 59.1%
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-*.f6493.5
Applied rewrites93.5%
if -1.06e-67 < v < 9.1999999999999995e-43Initial program 99.5%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites99.4%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
lower-/.f64N/A
unpow2N/A
rem-square-sqrt89.6
Applied rewrites89.6%
if 9.1999999999999995e-43 < v Initial program 55.1%
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-/.f6494.2
Applied rewrites94.2%
Final simplification92.3%
(FPCore (v H)
:precision binary64
(if (<= v -1.06e-67)
(atan (fma H (/ -9.8 (* v v)) -1.0))
(if (<= v 5.5e-26)
(atan (* v (sqrt (/ -0.05102040816326531 H))))
(atan (fma H (/ 9.8 (* v v)) 1.0)))))
double code(double v, double H) {
double tmp;
if (v <= -1.06e-67) {
tmp = atan(fma(H, (-9.8 / (v * v)), -1.0));
} else if (v <= 5.5e-26) {
tmp = atan((v * sqrt((-0.05102040816326531 / H))));
} else {
tmp = atan(fma(H, (9.8 / (v * v)), 1.0));
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1.06e-67) tmp = atan(fma(H, Float64(-9.8 / Float64(v * v)), -1.0)); elseif (v <= 5.5e-26) tmp = atan(Float64(v * sqrt(Float64(-0.05102040816326531 / H)))); else tmp = atan(fma(H, Float64(9.8 / Float64(v * v)), 1.0)); end return tmp end
code[v_, H_] := If[LessEqual[v, -1.06e-67], N[ArcTan[N[(H * N[(-9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 5.5e-26], N[ArcTan[N[(v * N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(H * N[(9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.06 \cdot 10^{-67}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{-9.8}{v \cdot v}, -1\right)\right)\\
\mathbf{elif}\;v \leq 5.5 \cdot 10^{-26}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \sqrt{\frac{-0.05102040816326531}{H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{9.8}{v \cdot v}, 1\right)\right)\\
\end{array}
\end{array}
if v < -1.06e-67Initial program 59.1%
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-*.f6493.5
Applied rewrites93.5%
if -1.06e-67 < v < 5.5000000000000005e-26Initial program 99.5%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites99.4%
Taylor expanded in v around 0
rem-square-sqrtN/A
unpow2N/A
lower-/.f64N/A
unpow2N/A
rem-square-sqrt88.1
Applied rewrites88.1%
if 5.5000000000000005e-26 < v Initial program 53.4%
Taylor expanded in v around inf
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
unpow2N/A
lower-*.f6496.0
Applied rewrites96.0%
Final simplification92.3%
(FPCore (v H) :precision binary64 (if (<= v 1.15e-127) (atan (fma H (/ -9.8 (* v v)) -1.0)) (atan (fma H (/ 9.8 (* v v)) 1.0))))
double code(double v, double H) {
double tmp;
if (v <= 1.15e-127) {
tmp = atan(fma(H, (-9.8 / (v * v)), -1.0));
} else {
tmp = atan(fma(H, (9.8 / (v * v)), 1.0));
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= 1.15e-127) tmp = atan(fma(H, Float64(-9.8 / Float64(v * v)), -1.0)); else tmp = atan(fma(H, Float64(9.8 / Float64(v * v)), 1.0)); end return tmp end
code[v_, H_] := If[LessEqual[v, 1.15e-127], N[ArcTan[N[(H * N[(-9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(H * N[(9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq 1.15 \cdot 10^{-127}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{-9.8}{v \cdot v}, -1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{9.8}{v \cdot v}, 1\right)\right)\\
\end{array}
\end{array}
if v < 1.15000000000000009e-127Initial program 77.9%
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-*.f6454.8
Applied rewrites54.8%
if 1.15000000000000009e-127 < v Initial program 63.4%
Taylor expanded in v around inf
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
unpow2N/A
lower-*.f6481.3
Applied rewrites81.3%
(FPCore (v H) :precision binary64 (if (<= v -1e-94) (atan (fma H (/ -9.8 (* v v)) -1.0)) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -1e-94) {
tmp = atan(fma(H, (-9.8 / (v * v)), -1.0));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1e-94) tmp = atan(fma(H, Float64(-9.8 / Float64(v * v)), -1.0)); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -1e-94], N[ArcTan[N[(H * N[(-9.8 / N[(v * v), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{-94}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(H, \frac{-9.8}{v \cdot v}, -1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -9.9999999999999996e-95Initial program 63.5%
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-*.f6488.9
Applied rewrites88.9%
if -9.9999999999999996e-95 < v Initial program 77.1%
Taylor expanded in v around inf
Applied rewrites51.7%
(FPCore (v H) :precision binary64 (if (<= v -2e-310) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -2e-310: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -2e-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 <= -2e-310) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -2e-310], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.999999999999994e-310Initial program 72.5%
Taylor expanded in v around -inf
Applied rewrites67.2%
if -1.999999999999994e-310 < v Initial program 71.9%
Taylor expanded in v around inf
Applied rewrites63.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 72.2%
Taylor expanded in v around -inf
Applied rewrites33.5%
herbie shell --seed 2024233
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))