
(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 -1e+157) (atan -1.0) (if (<= v 6.6e+91) (atan (/ v (sqrt (- (* v v) (* 19.6 H))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+157) {
tmp = atan(-1.0);
} else if (v <= 6.6e+91) {
tmp = atan((v / sqrt(((v * v) - (19.6 * 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 <= (-1d+157)) then
tmp = atan((-1.0d0))
else if (v <= 6.6d+91) then
tmp = atan((v / sqrt(((v * v) - (19.6d0 * h)))))
else
tmp = atan(1.0d0)
end if
code = tmp
end function
public static double code(double v, double H) {
double tmp;
if (v <= -1e+157) {
tmp = Math.atan(-1.0);
} else if (v <= 6.6e+91) {
tmp = Math.atan((v / Math.sqrt(((v * v) - (19.6 * H)))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1e+157: tmp = math.atan(-1.0) elif v <= 6.6e+91: tmp = math.atan((v / math.sqrt(((v * v) - (19.6 * H))))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1e+157) tmp = atan(-1.0); elseif (v <= 6.6e+91) tmp = atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(19.6 * H))))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1e+157) tmp = atan(-1.0); elseif (v <= 6.6e+91) tmp = atan((v / sqrt(((v * v) - (19.6 * H))))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1e+157], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 6.6e+91], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(19.6 * H), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1 \cdot 10^{+157}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 6.6 \cdot 10^{+91}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - 19.6 \cdot H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -9.99999999999999983e156Initial program 3.1%
sqr-neg3.1%
sqr-neg3.1%
metadata-eval3.1%
Simplified3.1%
Taylor expanded in v around -inf 100.0%
if -9.99999999999999983e156 < v < 6.60000000000000034e91Initial program 99.2%
sqr-neg99.2%
sqr-neg99.2%
metadata-eval99.2%
Simplified99.2%
if 6.60000000000000034e91 < v Initial program 28.8%
sqr-neg28.8%
sqr-neg28.8%
metadata-eval28.8%
Simplified28.8%
Taylor expanded in v around inf 100.0%
(FPCore (v H)
:precision binary64
(if (<= v -1e-30)
(atan -1.0)
(if (<= v 3.5e-73)
(atan (/ v (sqrt (* H -19.6))))
(atan (/ v (+ v (* -9.8 (/ H v))))))))
double code(double v, double H) {
double tmp;
if (v <= -1e-30) {
tmp = atan(-1.0);
} else if (v <= 3.5e-73) {
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 <= (-1d-30)) then
tmp = atan((-1.0d0))
else if (v <= 3.5d-73) 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 <= -1e-30) {
tmp = Math.atan(-1.0);
} else if (v <= 3.5e-73) {
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 <= -1e-30: tmp = math.atan(-1.0) elif v <= 3.5e-73: 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 <= -1e-30) tmp = atan(-1.0); elseif (v <= 3.5e-73) 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 <= -1e-30) tmp = atan(-1.0); elseif (v <= 3.5e-73) 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, -1e-30], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 3.5e-73], 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 \cdot 10^{-30}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 3.5 \cdot 10^{-73}:\\
\;\;\;\;\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 < -1e-30Initial program 55.6%
sqr-neg55.6%
sqr-neg55.6%
metadata-eval55.6%
Simplified55.6%
Taylor expanded in v around -inf 93.3%
if -1e-30 < v < 3.4999999999999998e-73Initial program 99.8%
sqr-neg99.8%
sqr-neg99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in v around 0 85.7%
*-commutative85.7%
Simplified85.7%
if 3.4999999999999998e-73 < v Initial program 52.5%
sqr-neg52.5%
sqr-neg52.5%
metadata-eval52.5%
Simplified52.5%
Taylor expanded in H around 0 92.0%
(FPCore (v H)
:precision binary64
(if (<= v -1.07e-128)
(atan -1.0)
(if (<= v 2.2e-106)
(atan (* v (* -0.10204081632653061 (/ v H))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1.07e-128) {
tmp = atan(-1.0);
} else if (v <= 2.2e-106) {
tmp = atan((v * (-0.10204081632653061 * (v / 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.07d-128)) then
tmp = atan((-1.0d0))
else if (v <= 2.2d-106) then
tmp = atan((v * ((-0.10204081632653061d0) * (v / 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.07e-128) {
tmp = Math.atan(-1.0);
} else if (v <= 2.2e-106) {
tmp = Math.atan((v * (-0.10204081632653061 * (v / H))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1.07e-128: tmp = math.atan(-1.0) elif v <= 2.2e-106: tmp = math.atan((v * (-0.10204081632653061 * (v / H)))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1.07e-128) tmp = atan(-1.0); elseif (v <= 2.2e-106) tmp = atan(Float64(v * Float64(-0.10204081632653061 * Float64(v / H)))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1.07e-128) tmp = atan(-1.0); elseif (v <= 2.2e-106) tmp = atan((v * (-0.10204081632653061 * (v / H)))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.07e-128], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 2.2e-106], N[ArcTan[N[(v * N[(-0.10204081632653061 * N[(v / H), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -1.07 \cdot 10^{-128}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 2.2 \cdot 10^{-106}:\\
\;\;\;\;\tan^{-1} \left(v \cdot \left(-0.10204081632653061 \cdot \frac{v}{H}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.06999999999999997e-128Initial program 62.7%
sqr-neg62.7%
sqr-neg62.7%
metadata-eval62.7%
Simplified62.7%
Taylor expanded in v around -inf 85.7%
if -1.06999999999999997e-128 < v < 2.19999999999999994e-106Initial program 99.7%
sqr-neg99.7%
sqr-neg99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in H around 0 30.6%
Taylor expanded in v around 0 30.6%
associate-*r/30.6%
*-commutative30.6%
associate-/l*30.6%
Simplified30.6%
clear-num30.6%
associate-/r/30.6%
*-commutative30.6%
associate-/r*30.6%
clear-num30.6%
div-inv30.6%
metadata-eval30.6%
Applied egg-rr30.6%
Taylor expanded in v around 0 30.6%
if 2.19999999999999994e-106 < v Initial program 55.9%
sqr-neg55.9%
sqr-neg55.9%
metadata-eval55.9%
Simplified55.9%
Taylor expanded in v around inf 88.3%
Final simplification77.1%
(FPCore (v H) :precision binary64 (if (<= v -1.07e-128) (atan -1.0) (atan (/ v (+ v (* -9.8 (/ H v)))))))
double code(double v, double H) {
double tmp;
if (v <= -1.07e-128) {
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 <= (-1.07d-128)) 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 <= -1.07e-128) {
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 <= -1.07e-128: 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 <= -1.07e-128) 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 <= -1.07e-128) tmp = atan(-1.0); else tmp = atan((v / (v + (-9.8 * (H / v))))); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1.07e-128], 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 -1.07 \cdot 10^{-128}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{v + -9.8 \cdot \frac{H}{v}}\right)\\
\end{array}
\end{array}
if v < -1.06999999999999997e-128Initial program 62.7%
sqr-neg62.7%
sqr-neg62.7%
metadata-eval62.7%
Simplified62.7%
Taylor expanded in v around -inf 85.7%
if -1.06999999999999997e-128 < v Initial program 68.4%
sqr-neg68.4%
sqr-neg68.4%
metadata-eval68.4%
Simplified68.4%
Taylor expanded in H around 0 71.8%
(FPCore (v H) :precision binary64 (if (<= v -2.3e-299) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -2.3e-299) {
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 <= (-2.3d-299)) 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 <= -2.3e-299) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -2.3e-299: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -2.3e-299) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -2.3e-299) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -2.3e-299], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -2.3 \cdot 10^{-299}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -2.3000000000000001e-299Initial program 68.4%
sqr-neg68.4%
sqr-neg68.4%
metadata-eval68.4%
Simplified68.4%
Taylor expanded in v around -inf 73.1%
if -2.3000000000000001e-299 < v Initial program 64.4%
sqr-neg64.4%
sqr-neg64.4%
metadata-eval64.4%
Simplified64.4%
Taylor expanded in v around inf 72.0%
(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 66.2%
sqr-neg66.2%
sqr-neg66.2%
metadata-eval66.2%
Simplified66.2%
Taylor expanded in v around -inf 34.4%
herbie shell --seed 2024144
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))