Average Error: 30.1 → 5.4
Time: 18.9s
Precision: 64
$\cos \left(\tan^{-1} \left(\frac{r}{d}\right)\right)$
$\begin{array}{l} \mathbf{if}\;\frac{r}{d} \le 0.14671766062712469:\\ \;\;\;\;{\left(1 + \frac{r}{d} \cdot \frac{r}{d}\right)}^{\frac{-1}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{r}{d}}\\ \end{array}$
\cos \left(\tan^{-1} \left(\frac{r}{d}\right)\right)
\begin{array}{l}
\mathbf{if}\;\frac{r}{d} \le 0.14671766062712469:\\
\;\;\;\;{\left(1 + \frac{r}{d} \cdot \frac{r}{d}\right)}^{\frac{-1}{2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{r}{d}}\\

\end{array}
double f(double r, double d) {
double r46807737 = r;
double r46807738 = d;
double r46807739 = r46807737 / r46807738;
double r46807740 = atan(r46807739);
double r46807741 = cos(r46807740);
return r46807741;
}


double f(double r, double d) {
double r46807742 = r;
double r46807743 = d;
double r46807744 = r46807742 / r46807743;
double r46807745 = 0.14671766062712469;
bool r46807746 = r46807744 <= r46807745;
double r46807747 = 1.0;
double r46807748 = r46807744 * r46807744;
double r46807749 = r46807747 + r46807748;
double r46807750 = -0.5;
double r46807751 = pow(r46807749, r46807750);
double r46807752 = r46807747 / r46807744;
double r46807753 = r46807746 ? r46807751 : r46807752;
return r46807753;
}



Try it out

Results

 In Out
Enter valid numbers for all inputs

Derivation

1. Split input into 2 regimes
2. if (/ r d) < 0.14671766062712469

1. Initial program 20.5

$\cos \left(\tan^{-1} \left(\frac{r}{d}\right)\right)$
2. Using strategy rm
3. Applied cos-atan6.7

$\leadsto \color{blue}{\frac{1}{\sqrt{1 + \frac{r}{d} \cdot \frac{r}{d}}}}$
4. Using strategy rm
5. Applied pow1/26.7

$\leadsto \frac{1}{\color{blue}{{\left(1 + \frac{r}{d} \cdot \frac{r}{d}\right)}^{\frac{1}{2}}}}$
6. Applied pow-flip6.7

$\leadsto \color{blue}{{\left(1 + \frac{r}{d} \cdot \frac{r}{d}\right)}^{\left(-\frac{1}{2}\right)}}$
7. Simplified6.7

$\leadsto {\left(1 + \frac{r}{d} \cdot \frac{r}{d}\right)}^{\color{blue}{\frac{-1}{2}}}$

if 0.14671766062712469 < (/ r d)

1. Initial program 58.8

$\cos \left(\tan^{-1} \left(\frac{r}{d}\right)\right)$
2. Using strategy rm
3. Applied cos-atan18.9

$\leadsto \color{blue}{\frac{1}{\sqrt{1 + \frac{r}{d} \cdot \frac{r}{d}}}}$
4. Taylor expanded around inf 1.5

$\leadsto \frac{1}{\color{blue}{\frac{r}{d}}}$
3. Recombined 2 regimes into one program.
4. Final simplification5.4

$\leadsto \begin{array}{l} \mathbf{if}\;\frac{r}{d} \le 0.14671766062712469:\\ \;\;\;\;{\left(1 + \frac{r}{d} \cdot \frac{r}{d}\right)}^{\frac{-1}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{r}{d}}\\ \end{array}$

Reproduce

herbie shell --seed 1
(FPCore (r d)
:name "cos(atan(r/d))"
(cos (atan (/ r d))))