
(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+154)
(atan -1.0)
(if (<= v 5e+131)
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H)))))
(atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(-1.0);
} else if (v <= 5e+131) {
tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * 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+154)) then
tmp = atan((-1.0d0))
else if (v <= 5d+131) then
tmp = atan((v / sqrt(((v * v) - ((2.0d0 * 9.8d0) * 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+154) {
tmp = Math.atan(-1.0);
} else if (v <= 5e+131) {
tmp = Math.atan((v / Math.sqrt(((v * v) - ((2.0 * 9.8) * H)))));
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -1e+154: tmp = math.atan(-1.0) elif v <= 5e+131: tmp = math.atan((v / math.sqrt(((v * v) - ((2.0 * 9.8) * H))))) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 5e+131) tmp = atan(Float64(v / sqrt(Float64(Float64(v * v) - Float64(Float64(2.0 * 9.8) * H))))); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 5e+131) tmp = atan((v / sqrt(((v * v) - ((2.0 * 9.8) * H))))); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -1e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5e+131], N[ArcTan[N[(v / N[Sqrt[N[(N[(v * v), $MachinePrecision] - N[(N[(2.0 * 9.8), $MachinePrecision] * H), $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} -1\\
\mathbf{elif}\;v \leq 5 \cdot 10^{+131}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{v \cdot v - \left(2 \cdot 9.8\right) \cdot H}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.00000000000000004e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -1.00000000000000004e154 < v < 4.99999999999999995e131Initial program 99.8%
if 4.99999999999999995e131 < v Initial program 19.7%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H) :precision binary64 (if (<= v -1e+154) (atan -1.0) (if (<= v 5e+131) (atan (/ v (sqrt (fma v v (* -19.6 H))))) (atan 1.0))))
double code(double v, double H) {
double tmp;
if (v <= -1e+154) {
tmp = atan(-1.0);
} else if (v <= 5e+131) {
tmp = atan((v / sqrt(fma(v, v, (-19.6 * H)))));
} else {
tmp = atan(1.0);
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -1e+154) tmp = atan(-1.0); elseif (v <= 5e+131) tmp = atan(Float64(v / sqrt(fma(v, v, Float64(-19.6 * H))))); else tmp = atan(1.0); end return tmp end
code[v_, H_] := If[LessEqual[v, -1e+154], N[ArcTan[-1.0], $MachinePrecision], If[LessEqual[v, 5e+131], N[ArcTan[N[(v / N[Sqrt[N[(v * v + 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^{+154}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{elif}\;v \leq 5 \cdot 10^{+131}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\sqrt{\mathsf{fma}\left(v, v, -19.6 \cdot H\right)}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -1.00000000000000004e154Initial program 3.1%
Taylor expanded in v around -inf
Applied rewrites100.0%
if -1.00000000000000004e154 < v < 4.99999999999999995e131Initial program 99.8%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
if 4.99999999999999995e131 < v Initial program 19.7%
Taylor expanded in v around inf
Applied rewrites100.0%
(FPCore (v H)
:precision binary64
(if (<= v -9.8e-79)
(atan (- (* -9.8 (/ H (* v v))) 1.0))
(if (<= v 7.5e-54)
(atan (* (sqrt (/ -0.05102040816326531 H)) v))
(atan (/ v (fma (/ H v) -9.8 v))))))
double code(double v, double H) {
double tmp;
if (v <= -9.8e-79) {
tmp = atan(((-9.8 * (H / (v * v))) - 1.0));
} else if (v <= 7.5e-54) {
tmp = atan((sqrt((-0.05102040816326531 / H)) * v));
} else {
tmp = atan((v / fma((H / v), -9.8, v)));
}
return tmp;
}
function code(v, H) tmp = 0.0 if (v <= -9.8e-79) tmp = atan(Float64(Float64(-9.8 * Float64(H / Float64(v * v))) - 1.0)); elseif (v <= 7.5e-54) tmp = atan(Float64(sqrt(Float64(-0.05102040816326531 / H)) * v)); else tmp = atan(Float64(v / fma(Float64(H / v), -9.8, v))); end return tmp end
code[v_, H_] := If[LessEqual[v, -9.8e-79], N[ArcTan[N[(N[(-9.8 * N[(H / N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 7.5e-54], N[ArcTan[N[(N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision] * v), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(v / N[(N[(H / v), $MachinePrecision] * -9.8 + v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -9.8 \cdot 10^{-79}:\\
\;\;\;\;\tan^{-1} \left(-9.8 \cdot \frac{H}{v \cdot v} - 1\right)\\
\mathbf{elif}\;v \leq 7.5 \cdot 10^{-54}:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\frac{v}{\mathsf{fma}\left(\frac{H}{v}, -9.8, v\right)}\right)\\
\end{array}
\end{array}
if v < -9.8000000000000001e-79Initial program 53.3%
Taylor expanded in v around -inf
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6486.9
Applied rewrites86.9%
if -9.8000000000000001e-79 < v < 7.5000000000000005e-54Initial program 99.6%
Taylor expanded in v around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-atan.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in v around 0
Applied rewrites96.9%
if 7.5000000000000005e-54 < v Initial program 64.1%
Taylor expanded in H around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6485.4
Applied rewrites85.4%
(FPCore (v H)
:precision binary64
(let* ((t_0 (/ H (* v v))))
(if (<= v -9.8e-79)
(atan (- (* -9.8 t_0) 1.0))
(if (<= v 7.5e-54)
(atan (* (sqrt (/ -0.05102040816326531 H)) v))
(atan (fma 9.8 t_0 1.0))))))
double code(double v, double H) {
double t_0 = H / (v * v);
double tmp;
if (v <= -9.8e-79) {
tmp = atan(((-9.8 * t_0) - 1.0));
} else if (v <= 7.5e-54) {
tmp = atan((sqrt((-0.05102040816326531 / H)) * v));
} else {
tmp = atan(fma(9.8, t_0, 1.0));
}
return tmp;
}
function code(v, H) t_0 = Float64(H / Float64(v * v)) tmp = 0.0 if (v <= -9.8e-79) tmp = atan(Float64(Float64(-9.8 * t_0) - 1.0)); elseif (v <= 7.5e-54) tmp = atan(Float64(sqrt(Float64(-0.05102040816326531 / H)) * v)); else tmp = atan(fma(9.8, t_0, 1.0)); end return tmp end
code[v_, H_] := Block[{t$95$0 = N[(H / N[(v * v), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[v, -9.8e-79], N[ArcTan[N[(N[(-9.8 * t$95$0), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[v, 7.5e-54], N[ArcTan[N[(N[Sqrt[N[(-0.05102040816326531 / H), $MachinePrecision]], $MachinePrecision] * v), $MachinePrecision]], $MachinePrecision], N[ArcTan[N[(9.8 * t$95$0 + 1.0), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{H}{v \cdot v}\\
\mathbf{if}\;v \leq -9.8 \cdot 10^{-79}:\\
\;\;\;\;\tan^{-1} \left(-9.8 \cdot t\_0 - 1\right)\\
\mathbf{elif}\;v \leq 7.5 \cdot 10^{-54}:\\
\;\;\;\;\tan^{-1} \left(\sqrt{\frac{-0.05102040816326531}{H}} \cdot v\right)\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} \left(\mathsf{fma}\left(9.8, t\_0, 1\right)\right)\\
\end{array}
\end{array}
if v < -9.8000000000000001e-79Initial program 53.3%
Taylor expanded in v around -inf
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6486.9
Applied rewrites86.9%
if -9.8000000000000001e-79 < v < 7.5000000000000005e-54Initial program 99.6%
Taylor expanded in v around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-atan.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in v around 0
Applied rewrites96.9%
if 7.5000000000000005e-54 < v Initial program 64.1%
Taylor expanded in v around inf
+-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6484.6
Applied rewrites84.6%
(FPCore (v H) :precision binary64 (if (<= v -9.8e-296) (atan -1.0) (atan 1.0)))
double code(double v, double H) {
double tmp;
if (v <= -9.8e-296) {
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 <= (-9.8d-296)) 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 <= -9.8e-296) {
tmp = Math.atan(-1.0);
} else {
tmp = Math.atan(1.0);
}
return tmp;
}
def code(v, H): tmp = 0 if v <= -9.8e-296: tmp = math.atan(-1.0) else: tmp = math.atan(1.0) return tmp
function code(v, H) tmp = 0.0 if (v <= -9.8e-296) tmp = atan(-1.0); else tmp = atan(1.0); end return tmp end
function tmp_2 = code(v, H) tmp = 0.0; if (v <= -9.8e-296) tmp = atan(-1.0); else tmp = atan(1.0); end tmp_2 = tmp; end
code[v_, H_] := If[LessEqual[v, -9.8e-296], N[ArcTan[-1.0], $MachinePrecision], N[ArcTan[1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -9.8 \cdot 10^{-296}:\\
\;\;\;\;\tan^{-1} -1\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1} 1\\
\end{array}
\end{array}
if v < -9.7999999999999997e-296Initial program 66.7%
Taylor expanded in v around -inf
Applied rewrites62.9%
if -9.7999999999999997e-296 < v Initial program 76.1%
Taylor expanded in v around inf
Applied rewrites58.8%
(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 71.8%
Taylor expanded in v around -inf
Applied rewrites29.8%
herbie shell --seed 2024326
(FPCore (v H)
:name "Optimal throwing angle"
:precision binary64
(atan (/ v (sqrt (- (* v v) (* (* 2.0 9.8) H))))))