rsin B (should all be same)

Percentage Accurate: 76.3% → 99.5%
Time: 14.9s
Alternatives: 10
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ r \cdot \frac{\sin b}{\cos \left(a + b\right)} \end{array} \]
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
	return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
	return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b):
	return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b)
	return Float64(r * Float64(sin(b) / cos(Float64(a + b))))
end
function tmp = code(r, a, b)
	tmp = r * (sin(b) / cos((a + b)));
end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 76.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ r \cdot \frac{\sin b}{\cos \left(a + b\right)} \end{array} \]
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
	return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
	return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b):
	return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b)
	return Float64(r * Float64(sin(b) / cos(Float64(a + b))))
end
function tmp = code(r, a, b)
	tmp = r * (sin(b) / cos((a + b)));
end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}

Alternative 1: 99.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (* r (/ (sin b) (- (* (cos b) (cos a)) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
	return r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
	return r * (Math.sin(b) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b):
	return r * (math.sin(b) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a))))
function code(r, a, b)
	return Float64(r * Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a)))))
end
function tmp = code(r, a, b)
	tmp = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))));
end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Derivation
  1. Initial program 80.4%

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. +-commutative80.4%

      \[\leadsto r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}} \]
    2. cos-sum99.5%

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
  4. Applied egg-rr99.5%

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
  5. Add Preprocessing

Alternative 2: 76.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.0058 \lor \neg \left(b \leq 8000\right):\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -0.0058) (not (<= b 8000.0)))
   (* (sin b) (/ r (cos b)))
   (*
    (/ 1.0 (cos (+ b a)))
    (* b (+ r (* -0.16666666666666666 (* r (* b b))))))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.0058) || !(b <= 8000.0)) {
		tmp = sin(b) * (r / cos(b));
	} else {
		tmp = (1.0 / cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b <= (-0.0058d0)) .or. (.not. (b <= 8000.0d0))) then
        tmp = sin(b) * (r / cos(b))
    else
        tmp = (1.0d0 / cos((b + a))) * (b * (r + ((-0.16666666666666666d0) * (r * (b * b)))))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.0058) || !(b <= 8000.0)) {
		tmp = Math.sin(b) * (r / Math.cos(b));
	} else {
		tmp = (1.0 / Math.cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -0.0058) or not (b <= 8000.0):
		tmp = math.sin(b) * (r / math.cos(b))
	else:
		tmp = (1.0 / math.cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -0.0058) || !(b <= 8000.0))
		tmp = Float64(sin(b) * Float64(r / cos(b)));
	else
		tmp = Float64(Float64(1.0 / cos(Float64(b + a))) * Float64(b * Float64(r + Float64(-0.16666666666666666 * Float64(r * Float64(b * b))))));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -0.0058) || ~((b <= 8000.0)))
		tmp = sin(b) * (r / cos(b));
	else
		tmp = (1.0 / cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.0058], N[Not[LessEqual[b, 8000.0]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(b * N[(r + N[(-0.16666666666666666 * N[(r * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0058 \lor \neg \left(b \leq 8000\right):\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -0.0058 or 8e3 < b

    1. Initial program 60.2%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative60.2%

        \[\leadsto r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}} \]
      2. cos-sum99.2%

        \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
    4. Applied egg-rr99.2%

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
    5. Taylor expanded in r around 0 99.3%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
    6. Step-by-step derivation
      1. associate-/l*99.2%

        \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
      2. /-rgt-identity99.2%

        \[\leadsto \color{blue}{\frac{r}{1}} \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin a \cdot \sin b} \]
      3. sub-neg99.2%

        \[\leadsto \frac{r}{1} \cdot \frac{\sin b}{\color{blue}{\cos a \cdot \cos b + \left(-\sin a \cdot \sin b\right)}} \]
      4. *-commutative99.2%

        \[\leadsto \frac{r}{1} \cdot \frac{\sin b}{\cos a \cdot \cos b + \left(-\color{blue}{\sin b \cdot \sin a}\right)} \]
      5. sub0-neg99.2%

        \[\leadsto \frac{r}{1} \cdot \frac{\sin b}{\cos a \cdot \cos b + \color{blue}{\left(0 - \sin b \cdot \sin a\right)}} \]
      6. *-commutative99.2%

        \[\leadsto \frac{r}{1} \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a} + \left(0 - \sin b \cdot \sin a\right)} \]
      7. times-frac99.3%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{1 \cdot \left(\cos b \cdot \cos a + \left(0 - \sin b \cdot \sin a\right)\right)}} \]
      8. *-commutative99.3%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{1 \cdot \left(\cos b \cdot \cos a + \left(0 - \sin b \cdot \sin a\right)\right)} \]
      9. times-frac99.1%

        \[\leadsto \color{blue}{\frac{\sin b}{1} \cdot \frac{r}{\cos b \cdot \cos a + \left(0 - \sin b \cdot \sin a\right)}} \]
      10. /-rgt-identity99.1%

        \[\leadsto \color{blue}{\sin b} \cdot \frac{r}{\cos b \cdot \cos a + \left(0 - \sin b \cdot \sin a\right)} \]
      11. associate-+r-99.1%

        \[\leadsto \sin b \cdot \frac{r}{\color{blue}{\left(\cos b \cdot \cos a + 0\right) - \sin b \cdot \sin a}} \]
    7. Simplified99.1%

      \[\leadsto \color{blue}{\sin b \cdot \frac{r}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
    8. Taylor expanded in a around 0 60.3%

      \[\leadsto \sin b \cdot \color{blue}{\frac{r}{\cos b}} \]

    if -0.0058 < b < 8e3

    1. Initial program 97.7%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r/97.5%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}} \]
      2. clear-num97.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(a + b\right)}{r \cdot \sin b}}} \]
      3. associate-/r/97.6%

        \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(r \cdot \sin b\right)} \]
      4. *-commutative97.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(\sin b \cdot r\right)} \]
    4. Applied egg-rr97.6%

      \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(\sin b \cdot r\right)} \]
    5. Taylor expanded in b around 0 97.6%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(b \cdot \left(r + -0.16666666666666666 \cdot \left({b}^{2} \cdot r\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-commutative97.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \color{blue}{\left(r \cdot {b}^{2}\right)}\right)\right) \]
      2. unpow297.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \color{blue}{\left(b \cdot b\right)}\right)\right)\right) \]
    7. Simplified97.6%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -0.0058 \lor \neg \left(b \leq 8000\right):\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 76.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.0023:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{elif}\;b \leq 8000:\\ \;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos b}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= b -0.0023)
   (* r (/ (sin b) (cos b)))
   (if (<= b 8000.0)
     (*
      (/ 1.0 (cos (+ b a)))
      (* b (+ r (* -0.16666666666666666 (* r (* b b))))))
     (/ (* r (sin b)) (cos b)))))
double code(double r, double a, double b) {
	double tmp;
	if (b <= -0.0023) {
		tmp = r * (sin(b) / cos(b));
	} else if (b <= 8000.0) {
		tmp = (1.0 / cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	} else {
		tmp = (r * sin(b)) / cos(b);
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= (-0.0023d0)) then
        tmp = r * (sin(b) / cos(b))
    else if (b <= 8000.0d0) then
        tmp = (1.0d0 / cos((b + a))) * (b * (r + ((-0.16666666666666666d0) * (r * (b * b)))))
    else
        tmp = (r * sin(b)) / cos(b)
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if (b <= -0.0023) {
		tmp = r * (Math.sin(b) / Math.cos(b));
	} else if (b <= 8000.0) {
		tmp = (1.0 / Math.cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	} else {
		tmp = (r * Math.sin(b)) / Math.cos(b);
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if b <= -0.0023:
		tmp = r * (math.sin(b) / math.cos(b))
	elif b <= 8000.0:
		tmp = (1.0 / math.cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))))
	else:
		tmp = (r * math.sin(b)) / math.cos(b)
	return tmp
function code(r, a, b)
	tmp = 0.0
	if (b <= -0.0023)
		tmp = Float64(r * Float64(sin(b) / cos(b)));
	elseif (b <= 8000.0)
		tmp = Float64(Float64(1.0 / cos(Float64(b + a))) * Float64(b * Float64(r + Float64(-0.16666666666666666 * Float64(r * Float64(b * b))))));
	else
		tmp = Float64(Float64(r * sin(b)) / cos(b));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if (b <= -0.0023)
		tmp = r * (sin(b) / cos(b));
	elseif (b <= 8000.0)
		tmp = (1.0 / cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	else
		tmp = (r * sin(b)) / cos(b);
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[LessEqual[b, -0.0023], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8000.0], N[(N[(1.0 / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(b * N[(r + N[(-0.16666666666666666 * N[(r * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0023:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\

\mathbf{elif}\;b \leq 8000:\\
\;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -0.0023

    1. Initial program 56.9%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 57.2%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    4. Step-by-step derivation
      1. associate-/l*57.3%

        \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos b}} \]
      2. *-commutative57.3%

        \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]
    5. Simplified57.3%

      \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]

    if -0.0023 < b < 8e3

    1. Initial program 97.7%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r/97.5%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}} \]
      2. clear-num97.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(a + b\right)}{r \cdot \sin b}}} \]
      3. associate-/r/97.6%

        \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(r \cdot \sin b\right)} \]
      4. *-commutative97.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(\sin b \cdot r\right)} \]
    4. Applied egg-rr97.6%

      \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(\sin b \cdot r\right)} \]
    5. Taylor expanded in b around 0 97.6%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(b \cdot \left(r + -0.16666666666666666 \cdot \left({b}^{2} \cdot r\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-commutative97.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \color{blue}{\left(r \cdot {b}^{2}\right)}\right)\right) \]
      2. unpow297.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \color{blue}{\left(b \cdot b\right)}\right)\right)\right) \]
    7. Simplified97.6%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)} \]

    if 8e3 < b

    1. Initial program 63.3%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 63.4%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -0.0023:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{elif}\;b \leq 8000:\\ \;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 76.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.0068:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{elif}\;b \leq 8000:\\ \;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= b -0.0068)
   (* r (/ (sin b) (cos b)))
   (if (<= b 8000.0)
     (*
      (/ 1.0 (cos (+ b a)))
      (* b (+ r (* -0.16666666666666666 (* r (* b b))))))
     (* (sin b) (/ r (cos b))))))
double code(double r, double a, double b) {
	double tmp;
	if (b <= -0.0068) {
		tmp = r * (sin(b) / cos(b));
	} else if (b <= 8000.0) {
		tmp = (1.0 / cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	} else {
		tmp = sin(b) * (r / cos(b));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= (-0.0068d0)) then
        tmp = r * (sin(b) / cos(b))
    else if (b <= 8000.0d0) then
        tmp = (1.0d0 / cos((b + a))) * (b * (r + ((-0.16666666666666666d0) * (r * (b * b)))))
    else
        tmp = sin(b) * (r / cos(b))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if (b <= -0.0068) {
		tmp = r * (Math.sin(b) / Math.cos(b));
	} else if (b <= 8000.0) {
		tmp = (1.0 / Math.cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	} else {
		tmp = Math.sin(b) * (r / Math.cos(b));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if b <= -0.0068:
		tmp = r * (math.sin(b) / math.cos(b))
	elif b <= 8000.0:
		tmp = (1.0 / math.cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))))
	else:
		tmp = math.sin(b) * (r / math.cos(b))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if (b <= -0.0068)
		tmp = Float64(r * Float64(sin(b) / cos(b)));
	elseif (b <= 8000.0)
		tmp = Float64(Float64(1.0 / cos(Float64(b + a))) * Float64(b * Float64(r + Float64(-0.16666666666666666 * Float64(r * Float64(b * b))))));
	else
		tmp = Float64(sin(b) * Float64(r / cos(b)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if (b <= -0.0068)
		tmp = r * (sin(b) / cos(b));
	elseif (b <= 8000.0)
		tmp = (1.0 / cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	else
		tmp = sin(b) * (r / cos(b));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[LessEqual[b, -0.0068], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8000.0], N[(N[(1.0 / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(b * N[(r + N[(-0.16666666666666666 * N[(r * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0068:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\

\mathbf{elif}\;b \leq 8000:\\
\;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -0.00679999999999999962

    1. Initial program 56.9%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 57.2%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    4. Step-by-step derivation
      1. associate-/l*57.3%

        \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos b}} \]
      2. *-commutative57.3%

        \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]
    5. Simplified57.3%

      \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]

    if -0.00679999999999999962 < b < 8e3

    1. Initial program 97.7%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r/97.5%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}} \]
      2. clear-num97.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(a + b\right)}{r \cdot \sin b}}} \]
      3. associate-/r/97.6%

        \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(r \cdot \sin b\right)} \]
      4. *-commutative97.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(\sin b \cdot r\right)} \]
    4. Applied egg-rr97.6%

      \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(\sin b \cdot r\right)} \]
    5. Taylor expanded in b around 0 97.6%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(b \cdot \left(r + -0.16666666666666666 \cdot \left({b}^{2} \cdot r\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-commutative97.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \color{blue}{\left(r \cdot {b}^{2}\right)}\right)\right) \]
      2. unpow297.6%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \color{blue}{\left(b \cdot b\right)}\right)\right)\right) \]
    7. Simplified97.6%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)} \]

    if 8e3 < b

    1. Initial program 63.3%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative63.3%

        \[\leadsto r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}} \]
      2. cos-sum99.1%

        \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
    4. Applied egg-rr99.1%

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
    5. Taylor expanded in r around 0 99.3%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
    6. Step-by-step derivation
      1. associate-/l*99.1%

        \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
      2. /-rgt-identity99.1%

        \[\leadsto \color{blue}{\frac{r}{1}} \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin a \cdot \sin b} \]
      3. sub-neg99.1%

        \[\leadsto \frac{r}{1} \cdot \frac{\sin b}{\color{blue}{\cos a \cdot \cos b + \left(-\sin a \cdot \sin b\right)}} \]
      4. *-commutative99.1%

        \[\leadsto \frac{r}{1} \cdot \frac{\sin b}{\cos a \cdot \cos b + \left(-\color{blue}{\sin b \cdot \sin a}\right)} \]
      5. sub0-neg99.1%

        \[\leadsto \frac{r}{1} \cdot \frac{\sin b}{\cos a \cdot \cos b + \color{blue}{\left(0 - \sin b \cdot \sin a\right)}} \]
      6. *-commutative99.1%

        \[\leadsto \frac{r}{1} \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a} + \left(0 - \sin b \cdot \sin a\right)} \]
      7. times-frac99.3%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{1 \cdot \left(\cos b \cdot \cos a + \left(0 - \sin b \cdot \sin a\right)\right)}} \]
      8. *-commutative99.3%

        \[\leadsto \frac{\color{blue}{\sin b \cdot r}}{1 \cdot \left(\cos b \cdot \cos a + \left(0 - \sin b \cdot \sin a\right)\right)} \]
      9. times-frac99.2%

        \[\leadsto \color{blue}{\frac{\sin b}{1} \cdot \frac{r}{\cos b \cdot \cos a + \left(0 - \sin b \cdot \sin a\right)}} \]
      10. /-rgt-identity99.2%

        \[\leadsto \color{blue}{\sin b} \cdot \frac{r}{\cos b \cdot \cos a + \left(0 - \sin b \cdot \sin a\right)} \]
      11. associate-+r-99.2%

        \[\leadsto \sin b \cdot \frac{r}{\color{blue}{\left(\cos b \cdot \cos a + 0\right) - \sin b \cdot \sin a}} \]
    7. Simplified99.2%

      \[\leadsto \color{blue}{\sin b \cdot \frac{r}{\cos a \cdot \cos b - \sin a \cdot \sin b}} \]
    8. Taylor expanded in a around 0 63.3%

      \[\leadsto \sin b \cdot \color{blue}{\frac{r}{\cos b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -0.0068:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{elif}\;b \leq 8000:\\ \;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 76.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ r \cdot \frac{\sin b}{\cos \left(b + a\right)} \end{array} \]
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ b a)))))
double code(double r, double a, double b) {
	return r * (sin(b) / cos((b + a)));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = r * (sin(b) / cos((b + a)))
end function
public static double code(double r, double a, double b) {
	return r * (Math.sin(b) / Math.cos((b + a)));
}
def code(r, a, b):
	return r * (math.sin(b) / math.cos((b + a)))
function code(r, a, b)
	return Float64(r * Float64(sin(b) / cos(Float64(b + a))))
end
function tmp = code(r, a, b)
	tmp = r * (sin(b) / cos((b + a)));
end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \frac{\sin b}{\cos \left(b + a\right)}
\end{array}
Derivation
  1. Initial program 80.4%

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Final simplification80.4%

    \[\leadsto r \cdot \frac{\sin b}{\cos \left(b + a\right)} \]
  4. Add Preprocessing

Alternative 6: 55.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ r \cdot \frac{\sin b}{\cos a} \end{array} \]
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos a))))
double code(double r, double a, double b) {
	return r * (sin(b) / cos(a));
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = r * (sin(b) / cos(a))
end function
public static double code(double r, double a, double b) {
	return r * (Math.sin(b) / Math.cos(a));
}
def code(r, a, b):
	return r * (math.sin(b) / math.cos(a))
function code(r, a, b)
	return Float64(r * Float64(sin(b) / cos(a)))
end
function tmp = code(r, a, b)
	tmp = r * (sin(b) / cos(a));
end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \frac{\sin b}{\cos a}
\end{array}
Derivation
  1. Initial program 80.4%

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in b around 0 58.0%

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos a}} \]
  4. Add Preprocessing

Alternative 7: 55.3% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -49 \lor \neg \left(b \leq 1.25 \cdot 10^{+19}\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -49.0) (not (<= b 1.25e+19)))
   (* r (sin b))
   (*
    (/ 1.0 (cos (+ b a)))
    (* b (+ r (* -0.16666666666666666 (* r (* b b))))))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -49.0) || !(b <= 1.25e+19)) {
		tmp = r * sin(b);
	} else {
		tmp = (1.0 / cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b <= (-49.0d0)) .or. (.not. (b <= 1.25d+19))) then
        tmp = r * sin(b)
    else
        tmp = (1.0d0 / cos((b + a))) * (b * (r + ((-0.16666666666666666d0) * (r * (b * b)))))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((b <= -49.0) || !(b <= 1.25e+19)) {
		tmp = r * Math.sin(b);
	} else {
		tmp = (1.0 / Math.cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -49.0) or not (b <= 1.25e+19):
		tmp = r * math.sin(b)
	else:
		tmp = (1.0 / math.cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -49.0) || !(b <= 1.25e+19))
		tmp = Float64(r * sin(b));
	else
		tmp = Float64(Float64(1.0 / cos(Float64(b + a))) * Float64(b * Float64(r + Float64(-0.16666666666666666 * Float64(r * Float64(b * b))))));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -49.0) || ~((b <= 1.25e+19)))
		tmp = r * sin(b);
	else
		tmp = (1.0 / cos((b + a))) * (b * (r + (-0.16666666666666666 * (r * (b * b)))));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -49.0], N[Not[LessEqual[b, 1.25e+19]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(b * N[(r + N[(-0.16666666666666666 * N[(r * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -49 \lor \neg \left(b \leq 1.25 \cdot 10^{+19}\right):\\
\;\;\;\;r \cdot \sin b\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -49 or 1.25e19 < b

    1. Initial program 59.8%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r/59.8%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}} \]
      2. clear-num59.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(a + b\right)}{r \cdot \sin b}}} \]
      3. associate-/r/59.8%

        \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(r \cdot \sin b\right)} \]
      4. *-commutative59.8%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(\sin b \cdot r\right)} \]
    4. Applied egg-rr59.8%

      \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(\sin b \cdot r\right)} \]
    5. Taylor expanded in b around 0 12.0%

      \[\leadsto \color{blue}{\frac{1}{\cos a}} \cdot \left(\sin b \cdot r\right) \]
    6. Taylor expanded in a around 0 12.3%

      \[\leadsto \color{blue}{r \cdot \sin b} \]

    if -49 < b < 1.25e19

    1. Initial program 96.4%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r/96.3%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}} \]
      2. clear-num96.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(a + b\right)}{r \cdot \sin b}}} \]
      3. associate-/r/96.3%

        \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(r \cdot \sin b\right)} \]
      4. *-commutative96.3%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(\sin b \cdot r\right)} \]
    4. Applied egg-rr96.3%

      \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(\sin b \cdot r\right)} \]
    5. Taylor expanded in b around 0 94.1%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(b \cdot \left(r + -0.16666666666666666 \cdot \left({b}^{2} \cdot r\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-commutative94.1%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \color{blue}{\left(r \cdot {b}^{2}\right)}\right)\right) \]
      2. unpow294.1%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \color{blue}{\left(b \cdot b\right)}\right)\right)\right) \]
    7. Simplified94.1%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -49 \lor \neg \left(b \leq 1.25 \cdot 10^{+19}\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\cos \left(b + a\right)} \cdot \left(b \cdot \left(r + -0.16666666666666666 \cdot \left(r \cdot \left(b \cdot b\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 55.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -54 \lor \neg \left(b \leq 56000000000000\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -54.0) (not (<= b 56000000000000.0)))
   (* r (sin b))
   (* b (/ r (cos a)))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -54.0) || !(b <= 56000000000000.0)) {
		tmp = r * sin(b);
	} else {
		tmp = b * (r / cos(a));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b <= (-54.0d0)) .or. (.not. (b <= 56000000000000.0d0))) then
        tmp = r * sin(b)
    else
        tmp = b * (r / cos(a))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((b <= -54.0) || !(b <= 56000000000000.0)) {
		tmp = r * Math.sin(b);
	} else {
		tmp = b * (r / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -54.0) or not (b <= 56000000000000.0):
		tmp = r * math.sin(b)
	else:
		tmp = b * (r / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -54.0) || !(b <= 56000000000000.0))
		tmp = Float64(r * sin(b));
	else
		tmp = Float64(b * Float64(r / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -54.0) || ~((b <= 56000000000000.0)))
		tmp = r * sin(b);
	else
		tmp = b * (r / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -54.0], N[Not[LessEqual[b, 56000000000000.0]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -54 \lor \neg \left(b \leq 56000000000000\right):\\
\;\;\;\;r \cdot \sin b\\

\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -54 or 5.6e13 < b

    1. Initial program 59.3%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r/59.3%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}} \]
      2. clear-num59.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(a + b\right)}{r \cdot \sin b}}} \]
      3. associate-/r/59.3%

        \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(r \cdot \sin b\right)} \]
      4. *-commutative59.3%

        \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(\sin b \cdot r\right)} \]
    4. Applied egg-rr59.3%

      \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(\sin b \cdot r\right)} \]
    5. Taylor expanded in b around 0 11.9%

      \[\leadsto \color{blue}{\frac{1}{\cos a}} \cdot \left(\sin b \cdot r\right) \]
    6. Taylor expanded in a around 0 12.2%

      \[\leadsto \color{blue}{r \cdot \sin b} \]

    if -54 < b < 5.6e13

    1. Initial program 97.0%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0 94.5%

      \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
    4. Step-by-step derivation
      1. associate-/l*94.7%

        \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
    5. Simplified94.7%

      \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -54 \lor \neg \left(b \leq 56000000000000\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 38.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ r \cdot \sin b \end{array} \]
(FPCore (r a b) :precision binary64 (* r (sin b)))
double code(double r, double a, double b) {
	return r * sin(b);
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = r * sin(b)
end function
public static double code(double r, double a, double b) {
	return r * Math.sin(b);
}
def code(r, a, b):
	return r * math.sin(b)
function code(r, a, b)
	return Float64(r * sin(b))
end
function tmp = code(r, a, b)
	tmp = r * sin(b);
end
code[r_, a_, b_] := N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
r \cdot \sin b
\end{array}
Derivation
  1. Initial program 80.4%

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. associate-*r/80.3%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}} \]
    2. clear-num80.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos \left(a + b\right)}{r \cdot \sin b}}} \]
    3. associate-/r/80.3%

      \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(r \cdot \sin b\right)} \]
    4. *-commutative80.3%

      \[\leadsto \frac{1}{\cos \left(a + b\right)} \cdot \color{blue}{\left(\sin b \cdot r\right)} \]
  4. Applied egg-rr80.3%

    \[\leadsto \color{blue}{\frac{1}{\cos \left(a + b\right)} \cdot \left(\sin b \cdot r\right)} \]
  5. Taylor expanded in b around 0 58.0%

    \[\leadsto \color{blue}{\frac{1}{\cos a}} \cdot \left(\sin b \cdot r\right) \]
  6. Taylor expanded in a around 0 38.4%

    \[\leadsto \color{blue}{r \cdot \sin b} \]
  7. Add Preprocessing

Alternative 10: 34.6% accurate, 69.0× speedup?

\[\begin{array}{l} \\ r \cdot b \end{array} \]
(FPCore (r a b) :precision binary64 (* r b))
double code(double r, double a, double b) {
	return r * b;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = r * b
end function
public static double code(double r, double a, double b) {
	return r * b;
}
def code(r, a, b):
	return r * b
function code(r, a, b)
	return Float64(r * b)
end
function tmp = code(r, a, b)
	tmp = r * b;
end
code[r_, a_, b_] := N[(r * b), $MachinePrecision]
\begin{array}{l}

\\
r \cdot b
\end{array}
Derivation
  1. Initial program 80.4%

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in b around 0 54.3%

    \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
  4. Step-by-step derivation
    1. associate-/l*54.4%

      \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
  5. Simplified54.4%

    \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
  6. Taylor expanded in a around 0 34.5%

    \[\leadsto b \cdot \color{blue}{r} \]
  7. Final simplification34.5%

    \[\leadsto r \cdot b \]
  8. Add Preprocessing

Reproduce

?
herbie shell --seed 2024097 
(FPCore (r a b)
  :name "rsin B (should all be same)"
  :precision binary64
  (* r (/ (sin b) (cos (+ a b)))))