rsin B (should all be same)

Percentage Accurate: 76.1% → 99.5%
Time: 13.1s
Alternatives: 16
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 16 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.1% 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.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin b \cdot \sin a\\ \frac{r \cdot \sin b}{\mathsf{fma}\left(-\sin b, \sin a, t_0\right) + \left(\cos a \cdot \cos b - t_0\right)} \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (let* ((t_0 (* (sin b) (sin a))))
   (/
    (* r (sin b))
    (+ (fma (- (sin b)) (sin a) t_0) (- (* (cos a) (cos b)) t_0)))))
double code(double r, double a, double b) {
	double t_0 = sin(b) * sin(a);
	return (r * sin(b)) / (fma(-sin(b), sin(a), t_0) + ((cos(a) * cos(b)) - t_0));
}
function code(r, a, b)
	t_0 = Float64(sin(b) * sin(a))
	return Float64(Float64(r * sin(b)) / Float64(fma(Float64(-sin(b)), sin(a), t_0) + Float64(Float64(cos(a) * cos(b)) - t_0)))
end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]}, N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[((-N[Sin[b], $MachinePrecision]) * N[Sin[a], $MachinePrecision] + t$95$0), $MachinePrecision] + N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin b \cdot \sin a\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(-\sin b, \sin a, t_0\right) + \left(\cos a \cdot \cos b - t_0\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 75.5%

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

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

      \[\leadsto \frac{r \cdot \sin b}{\cos \color{blue}{\left(b + a\right)}} \]
  3. Simplified75.6%

    \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(b + a\right)}} \]
  4. Step-by-step derivation
    1. cos-sum99.6%

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

    \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
  6. Step-by-step derivation
    1. *-un-lft-identity99.6%

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

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, -\left(\sin b \cdot \sin a\right) \cdot 1\right) + \mathsf{fma}\left(-\sin b \cdot \sin a, 1, \left(\sin b \cdot \sin a\right) \cdot 1\right)}} \]
  7. Applied egg-rr99.5%

    \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, -\left(\sin b \cdot \sin a\right) \cdot 1\right) + \mathsf{fma}\left(-\sin b \cdot \sin a, 1, \left(\sin b \cdot \sin a\right) \cdot 1\right)}} \]
  8. Step-by-step derivation
    1. fma-udef99.6%

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\left(\cos b \cdot \cos a + \left(-\left(\sin b \cdot \sin a\right) \cdot 1\right)\right)} + \mathsf{fma}\left(-\sin b \cdot \sin a, 1, \left(\sin b \cdot \sin a\right) \cdot 1\right)} \]
    2. *-rgt-identity99.6%

      \[\leadsto \frac{r \cdot \sin b}{\left(\cos b \cdot \cos a + \left(-\color{blue}{\sin b \cdot \sin a}\right)\right) + \mathsf{fma}\left(-\sin b \cdot \sin a, 1, \left(\sin b \cdot \sin a\right) \cdot 1\right)} \]
    3. unsub-neg99.6%

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

      \[\leadsto \frac{r \cdot \sin b}{\left(\color{blue}{\cos a \cdot \cos b} - \sin b \cdot \sin a\right) + \mathsf{fma}\left(-\sin b \cdot \sin a, 1, \left(\sin b \cdot \sin a\right) \cdot 1\right)} \]
    5. fma-udef99.6%

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

      \[\leadsto \frac{r \cdot \sin b}{\left(\cos a \cdot \cos b - \sin b \cdot \sin a\right) + \left(\color{blue}{\left(-\sin b \cdot \sin a\right)} + \left(\sin b \cdot \sin a\right) \cdot 1\right)} \]
    7. distribute-lft-neg-in99.6%

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

      \[\leadsto \frac{r \cdot \sin b}{\left(\cos a \cdot \cos b - \sin b \cdot \sin a\right) + \left(\left(-\sin b\right) \cdot \sin a + \color{blue}{\sin b \cdot \sin a}\right)} \]
    9. fma-udef99.6%

      \[\leadsto \frac{r \cdot \sin b}{\left(\cos a \cdot \cos b - \sin b \cdot \sin a\right) + \color{blue}{\mathsf{fma}\left(-\sin b, \sin a, \sin b \cdot \sin a\right)}} \]
  9. Simplified99.6%

    \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\left(\cos a \cdot \cos b - \sin b \cdot \sin a\right) + \mathsf{fma}\left(-\sin b, \sin a, \sin b \cdot \sin a\right)}} \]
  10. Final simplification99.6%

    \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(-\sin b, \sin a, \sin b \cdot \sin a\right) + \left(\cos a \cdot \cos b - \sin b \cdot \sin a\right)} \]

Alternative 2: 99.5% accurate, 0.4× speedup?

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

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

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

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

    \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
  4. Step-by-step derivation
    1. cos-sum99.6%

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

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
  6. Final simplification99.5%

    \[\leadsto r \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a} \]

Alternative 3: 99.5% accurate, 0.4× speedup?

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

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

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Step-by-step derivation
    1. *-commutative75.5%

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

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

      \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
  3. Simplified75.5%

    \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
  4. Step-by-step derivation
    1. div-inv75.5%

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

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

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

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

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

    \[\leadsto \frac{r}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \cdot \sin b \]
  8. Final simplification99.5%

    \[\leadsto \sin b \cdot \frac{r}{\cos a \cdot \cos b - \sin b \cdot \sin a} \]

Alternative 4: 99.5% accurate, 0.4× speedup?

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

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

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

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

      \[\leadsto \frac{r \cdot \sin b}{\cos \color{blue}{\left(b + a\right)}} \]
  3. Simplified75.6%

    \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(b + a\right)}} \]
  4. Step-by-step derivation
    1. cos-sum99.6%

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

    \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
  6. Final simplification99.6%

    \[\leadsto \frac{r \cdot \sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a} \]

Alternative 5: 74.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -0.00034 \lor \neg \left(a \leq 7 \cdot 10^{+53}\right):\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= a -0.00034) (not (<= a 7e+53)))
   (* r (/ (sin b) (cos a)))
   (* r (/ (sin b) (cos b)))))
double code(double r, double a, double b) {
	double tmp;
	if ((a <= -0.00034) || !(a <= 7e+53)) {
		tmp = r * (sin(b) / cos(a));
	} 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 ((a <= (-0.00034d0)) .or. (.not. (a <= 7d+53))) then
        tmp = r * (sin(b) / cos(a))
    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 ((a <= -0.00034) || !(a <= 7e+53)) {
		tmp = r * (Math.sin(b) / Math.cos(a));
	} else {
		tmp = r * (Math.sin(b) / Math.cos(b));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (a <= -0.00034) or not (a <= 7e+53):
		tmp = r * (math.sin(b) / math.cos(a))
	else:
		tmp = r * (math.sin(b) / math.cos(b))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((a <= -0.00034) || !(a <= 7e+53))
		tmp = Float64(r * Float64(sin(b) / cos(a)));
	else
		tmp = Float64(r * Float64(sin(b) / cos(b)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((a <= -0.00034) || ~((a <= 7e+53)))
		tmp = r * (sin(b) / cos(a));
	else
		tmp = r * (sin(b) / cos(b));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.00034], N[Not[LessEqual[a, 7e+53]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.00034 \lor \neg \left(a \leq 7 \cdot 10^{+53}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -3.4e-4 or 7.00000000000000038e53 < a

    1. Initial program 56.8%

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

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

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

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

    if -3.4e-4 < a < 7.00000000000000038e53

    1. Initial program 94.9%

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

        \[\leadsto r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}} \]
    3. Simplified94.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -0.00034 \lor \neg \left(a \leq 7 \cdot 10^{+53}\right):\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \end{array} \]

Alternative 6: 74.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -0.0019:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos a}\\ \mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= a -0.0019)
   (* (sin b) (/ r (cos a)))
   (if (<= a 7e+53) (* r (/ (sin b) (cos b))) (* r (/ (sin b) (cos a))))))
double code(double r, double a, double b) {
	double tmp;
	if (a <= -0.0019) {
		tmp = sin(b) * (r / cos(a));
	} else if (a <= 7e+53) {
		tmp = r * (sin(b) / cos(b));
	} else {
		tmp = r * (sin(b) / 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 (a <= (-0.0019d0)) then
        tmp = sin(b) * (r / cos(a))
    else if (a <= 7d+53) then
        tmp = r * (sin(b) / cos(b))
    else
        tmp = r * (sin(b) / cos(a))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if (a <= -0.0019) {
		tmp = Math.sin(b) * (r / Math.cos(a));
	} else if (a <= 7e+53) {
		tmp = r * (Math.sin(b) / Math.cos(b));
	} else {
		tmp = r * (Math.sin(b) / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if a <= -0.0019:
		tmp = math.sin(b) * (r / math.cos(a))
	elif a <= 7e+53:
		tmp = r * (math.sin(b) / math.cos(b))
	else:
		tmp = r * (math.sin(b) / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if (a <= -0.0019)
		tmp = Float64(sin(b) * Float64(r / cos(a)));
	elseif (a <= 7e+53)
		tmp = Float64(r * Float64(sin(b) / cos(b)));
	else
		tmp = Float64(r * Float64(sin(b) / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if (a <= -0.0019)
		tmp = sin(b) * (r / cos(a));
	elseif (a <= 7e+53)
		tmp = r * (sin(b) / cos(b));
	else
		tmp = r * (sin(b) / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[LessEqual[a, -0.0019], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 7e+53], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\

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


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

    1. Initial program 60.1%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(b + a\right)}{r}}} \]
    4. Step-by-step derivation
      1. div-inv60.3%

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

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

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

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

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

    if -0.0019 < a < 7.00000000000000038e53

    1. Initial program 94.9%

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

        \[\leadsto r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}} \]
    3. Simplified94.9%

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

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

    if 7.00000000000000038e53 < a

    1. Initial program 53.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -0.0019:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos a}\\ \mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \]

Alternative 7: 74.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -2.4 \cdot 10^{-5}:\\ \;\;\;\;\frac{\sin b}{\frac{\cos a}{r}}\\ \mathbf{elif}\;a \leq 1.1 \cdot 10^{+54}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= a -2.4e-5)
   (/ (sin b) (/ (cos a) r))
   (if (<= a 1.1e+54) (* r (/ (sin b) (cos b))) (* r (/ (sin b) (cos a))))))
double code(double r, double a, double b) {
	double tmp;
	if (a <= -2.4e-5) {
		tmp = sin(b) / (cos(a) / r);
	} else if (a <= 1.1e+54) {
		tmp = r * (sin(b) / cos(b));
	} else {
		tmp = r * (sin(b) / 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 (a <= (-2.4d-5)) then
        tmp = sin(b) / (cos(a) / r)
    else if (a <= 1.1d+54) then
        tmp = r * (sin(b) / cos(b))
    else
        tmp = r * (sin(b) / cos(a))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if (a <= -2.4e-5) {
		tmp = Math.sin(b) / (Math.cos(a) / r);
	} else if (a <= 1.1e+54) {
		tmp = r * (Math.sin(b) / Math.cos(b));
	} else {
		tmp = r * (Math.sin(b) / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if a <= -2.4e-5:
		tmp = math.sin(b) / (math.cos(a) / r)
	elif a <= 1.1e+54:
		tmp = r * (math.sin(b) / math.cos(b))
	else:
		tmp = r * (math.sin(b) / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if (a <= -2.4e-5)
		tmp = Float64(sin(b) / Float64(cos(a) / r));
	elseif (a <= 1.1e+54)
		tmp = Float64(r * Float64(sin(b) / cos(b)));
	else
		tmp = Float64(r * Float64(sin(b) / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if (a <= -2.4e-5)
		tmp = sin(b) / (cos(a) / r);
	elseif (a <= 1.1e+54)
		tmp = r * (sin(b) / cos(b));
	else
		tmp = r * (sin(b) / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[LessEqual[a, -2.4e-5], N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.1e+54], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.4 \cdot 10^{-5}:\\
\;\;\;\;\frac{\sin b}{\frac{\cos a}{r}}\\

\mathbf{elif}\;a \leq 1.1 \cdot 10^{+54}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if a < -2.4000000000000001e-5

    1. Initial program 60.1%

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

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

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

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

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

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

    if -2.4000000000000001e-5 < a < 1.09999999999999995e54

    1. Initial program 94.9%

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

        \[\leadsto r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}} \]
    3. Simplified94.9%

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

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

    if 1.09999999999999995e54 < a

    1. Initial program 53.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -2.4 \cdot 10^{-5}:\\ \;\;\;\;\frac{\sin b}{\frac{\cos a}{r}}\\ \mathbf{elif}\;a \leq 1.1 \cdot 10^{+54}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \]

Alternative 8: 74.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -0.00013:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos a}\\ \mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= a -0.00013)
   (/ (* r (sin b)) (cos a))
   (if (<= a 7e+53) (* r (/ (sin b) (cos b))) (* r (/ (sin b) (cos a))))))
double code(double r, double a, double b) {
	double tmp;
	if (a <= -0.00013) {
		tmp = (r * sin(b)) / cos(a);
	} else if (a <= 7e+53) {
		tmp = r * (sin(b) / cos(b));
	} else {
		tmp = r * (sin(b) / 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 (a <= (-0.00013d0)) then
        tmp = (r * sin(b)) / cos(a)
    else if (a <= 7d+53) then
        tmp = r * (sin(b) / cos(b))
    else
        tmp = r * (sin(b) / cos(a))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if (a <= -0.00013) {
		tmp = (r * Math.sin(b)) / Math.cos(a);
	} else if (a <= 7e+53) {
		tmp = r * (Math.sin(b) / Math.cos(b));
	} else {
		tmp = r * (Math.sin(b) / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if a <= -0.00013:
		tmp = (r * math.sin(b)) / math.cos(a)
	elif a <= 7e+53:
		tmp = r * (math.sin(b) / math.cos(b))
	else:
		tmp = r * (math.sin(b) / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if (a <= -0.00013)
		tmp = Float64(Float64(r * sin(b)) / cos(a));
	elseif (a <= 7e+53)
		tmp = Float64(r * Float64(sin(b) / cos(b)));
	else
		tmp = Float64(r * Float64(sin(b) / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if (a <= -0.00013)
		tmp = (r * sin(b)) / cos(a);
	elseif (a <= 7e+53)
		tmp = r * (sin(b) / cos(b));
	else
		tmp = r * (sin(b) / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[LessEqual[a, -0.00013], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 7e+53], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if a < -1.29999999999999989e-4

    1. Initial program 60.1%

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

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

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

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

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

    if -1.29999999999999989e-4 < a < 7.00000000000000038e53

    1. Initial program 94.9%

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

        \[\leadsto r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}} \]
    3. Simplified94.9%

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

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

    if 7.00000000000000038e53 < a

    1. Initial program 53.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -0.00013:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos a}\\ \mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \]

Alternative 9: 74.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := r \cdot \sin b\\ \mathbf{if}\;a \leq -0.00185:\\ \;\;\;\;\frac{t_0}{\cos a}\\ \mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\ \;\;\;\;\frac{t_0}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (let* ((t_0 (* r (sin b))))
   (if (<= a -0.00185)
     (/ t_0 (cos a))
     (if (<= a 7e+53) (/ t_0 (cos b)) (* r (/ (sin b) (cos a)))))))
double code(double r, double a, double b) {
	double t_0 = r * sin(b);
	double tmp;
	if (a <= -0.00185) {
		tmp = t_0 / cos(a);
	} else if (a <= 7e+53) {
		tmp = t_0 / cos(b);
	} else {
		tmp = r * (sin(b) / 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) :: t_0
    real(8) :: tmp
    t_0 = r * sin(b)
    if (a <= (-0.00185d0)) then
        tmp = t_0 / cos(a)
    else if (a <= 7d+53) then
        tmp = t_0 / cos(b)
    else
        tmp = r * (sin(b) / cos(a))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double t_0 = r * Math.sin(b);
	double tmp;
	if (a <= -0.00185) {
		tmp = t_0 / Math.cos(a);
	} else if (a <= 7e+53) {
		tmp = t_0 / Math.cos(b);
	} else {
		tmp = r * (Math.sin(b) / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	t_0 = r * math.sin(b)
	tmp = 0
	if a <= -0.00185:
		tmp = t_0 / math.cos(a)
	elif a <= 7e+53:
		tmp = t_0 / math.cos(b)
	else:
		tmp = r * (math.sin(b) / math.cos(a))
	return tmp
function code(r, a, b)
	t_0 = Float64(r * sin(b))
	tmp = 0.0
	if (a <= -0.00185)
		tmp = Float64(t_0 / cos(a));
	elseif (a <= 7e+53)
		tmp = Float64(t_0 / cos(b));
	else
		tmp = Float64(r * Float64(sin(b) / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	t_0 = r * sin(b);
	tmp = 0.0;
	if (a <= -0.00185)
		tmp = t_0 / cos(a);
	elseif (a <= 7e+53)
		tmp = t_0 / cos(b);
	else
		tmp = r * (sin(b) / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.00185], N[(t$95$0 / N[Cos[a], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 7e+53], N[(t$95$0 / N[Cos[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := r \cdot \sin b\\
\mathbf{if}\;a \leq -0.00185:\\
\;\;\;\;\frac{t_0}{\cos a}\\

\mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\
\;\;\;\;\frac{t_0}{\cos b}\\

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


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

    1. Initial program 60.1%

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

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

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

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

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

    if -0.0018500000000000001 < a < 7.00000000000000038e53

    1. Initial program 94.9%

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

        \[\leadsto r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}} \]
    3. Simplified94.9%

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

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

    if 7.00000000000000038e53 < a

    1. Initial program 53.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -0.00185:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos a}\\ \mathbf{elif}\;a \leq 7 \cdot 10^{+53}:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \]

Alternative 10: 76.1% 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 75.5%

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Final simplification75.5%

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

Alternative 11: 76.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{r \cdot \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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

      \[\leadsto \frac{r \cdot \sin b}{\cos \color{blue}{\left(b + a\right)}} \]
  3. Simplified75.6%

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

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

Alternative 12: 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 75.5%

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

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

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

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos a}} \]
  5. Final simplification54.6%

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

Alternative 13: 55.1% accurate, 1.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -1.19999999999999996 or 3200 < b

    1. Initial program 52.7%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative52.7%

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

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

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified52.7%

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

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

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

    if -1.19999999999999996 < b < 3200

    1. Initial program 99.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.2 \lor \neg \left(b \leq 3200\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \]

Alternative 14: 55.1% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.2:\\ \;\;\;\;\frac{\sin b}{\frac{1}{r}}\\ \mathbf{elif}\;b \leq 3200:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \sin b\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= b -1.2)
   (/ (sin b) (/ 1.0 r))
   (if (<= b 3200.0) (* r (/ b (cos a))) (* r (sin b)))))
double code(double r, double a, double b) {
	double tmp;
	if (b <= -1.2) {
		tmp = sin(b) / (1.0 / r);
	} else if (b <= 3200.0) {
		tmp = r * (b / cos(a));
	} else {
		tmp = r * sin(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 <= (-1.2d0)) then
        tmp = sin(b) / (1.0d0 / r)
    else if (b <= 3200.0d0) then
        tmp = r * (b / cos(a))
    else
        tmp = r * sin(b)
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if (b <= -1.2) {
		tmp = Math.sin(b) / (1.0 / r);
	} else if (b <= 3200.0) {
		tmp = r * (b / Math.cos(a));
	} else {
		tmp = r * Math.sin(b);
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if b <= -1.2:
		tmp = math.sin(b) / (1.0 / r)
	elif b <= 3200.0:
		tmp = r * (b / math.cos(a))
	else:
		tmp = r * math.sin(b)
	return tmp
function code(r, a, b)
	tmp = 0.0
	if (b <= -1.2)
		tmp = Float64(sin(b) / Float64(1.0 / r));
	elseif (b <= 3200.0)
		tmp = Float64(r * Float64(b / cos(a)));
	else
		tmp = Float64(r * sin(b));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if (b <= -1.2)
		tmp = sin(b) / (1.0 / r);
	elseif (b <= 3200.0)
		tmp = r * (b / cos(a));
	else
		tmp = r * sin(b);
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[LessEqual[b, -1.2], N[(N[Sin[b], $MachinePrecision] / N[(1.0 / r), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3200.0], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2:\\
\;\;\;\;\frac{\sin b}{\frac{1}{r}}\\

\mathbf{elif}\;b \leq 3200:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\

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


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

    1. Initial program 56.9%

      \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
    2. Step-by-step derivation
      1. *-commutative56.9%

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

        \[\leadsto \color{blue}{\frac{\sin b}{\frac{\cos \left(a + b\right)}{r}}} \]
      3. +-commutative56.9%

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified56.9%

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

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

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

    if -1.19999999999999996 < b < 3200

    1. Initial program 99.4%

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

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

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

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

    if 3200 < b

    1. Initial program 48.4%

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

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

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

        \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
    3. Simplified48.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.2:\\ \;\;\;\;\frac{\sin b}{\frac{1}{r}}\\ \mathbf{elif}\;b \leq 3200:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \sin b\\ \end{array} \]

Alternative 15: 38.8% 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 75.5%

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Step-by-step derivation
    1. *-commutative75.5%

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

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

      \[\leadsto \frac{\sin b}{\frac{\cos \color{blue}{\left(b + a\right)}}{r}} \]
  3. Simplified75.5%

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

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

    \[\leadsto \color{blue}{\sin b \cdot r} \]
  6. Final simplification37.3%

    \[\leadsto r \cdot \sin b \]

Alternative 16: 34.7% 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 75.5%

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

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

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

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

    \[\leadsto \color{blue}{r \cdot b} \]
  6. Final simplification32.9%

    \[\leadsto r \cdot b \]

Reproduce

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