rsin B (should all be same)

Percentage Accurate: 77.2% → 99.5%
Time: 18.2s
Alternatives: 13
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 13 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: 77.2% 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.3× speedup?

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

\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin b\right) \cdot \sin a\right)}
\end{array}
Derivation
  1. Initial program 71.9%

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

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

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

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

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
    2. cancel-sign-sub-inv99.5%

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

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

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

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

Alternative 2: 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 71.9%

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

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

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

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

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

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

Alternative 3: 99.5% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 4: 78.0% accurate, 0.5× speedup?

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

\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, 0\right)}
\end{array}
Derivation
  1. Initial program 71.9%

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

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

    \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. log1p-expm1-u71.9%

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(b + a\right)\right)\right)}} \]
  6. Applied egg-rr71.9%

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

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}\right)\right)} \]
    2. log1p-expm1-u99.4%

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

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, -\sin b \cdot \sin a\right)}} \]
    4. distribute-rgt-neg-in99.5%

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

    \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(-\sin a\right)\right)}} \]
  9. Step-by-step derivation
    1. add-sqr-sqrt46.5%

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \color{blue}{\left(\sqrt{-\sin a} \cdot \sqrt{-\sin a}\right)}\right)} \]
    2. sqrt-unprod84.3%

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \color{blue}{\sqrt{\left(-\sin a\right) \cdot \left(-\sin a\right)}}\right)} \]
    3. sqr-neg84.3%

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \sqrt{\color{blue}{\sin a \cdot \sin a}}\right)} \]
    4. sqrt-unprod37.7%

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \color{blue}{\left(\sqrt{\sin a} \cdot \sqrt{\sin a}\right)}\right)} \]
    5. add-sqr-sqrt71.5%

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

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{\frac{\cos \left(b - a\right) - \cos \left(b + a\right)}{2}}\right)} \]
    7. div-sub73.2%

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{\frac{\cos \left(b - a\right)}{2} - \frac{\cos \left(b + a\right)}{2}}\right)} \]
  10. Applied egg-rr73.3%

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

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{0}\right)} \]
  12. Simplified73.3%

    \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{0}\right)} \]
  13. Final simplification73.3%

    \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, 0\right)} \]
  14. Add Preprocessing

Alternative 5: 77.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.9 \cdot 10^{-5} \lor \neg \left(a \leq 0.000205\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -1.9000000000000001e-5 or 2.05e-4 < a

    1. Initial program 49.7%

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

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

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

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

    if -1.9000000000000001e-5 < a < 2.05e-4

    1. Initial program 98.7%

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

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

      \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-cbrt-cube36.9%

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

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

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

        \[\leadsto \sqrt[3]{{\left(\frac{\color{blue}{\sin b \cdot r}}{\cos \left(b + a\right)}\right)}^{3}} \]
      5. associate-/l*37.0%

        \[\leadsto \sqrt[3]{{\color{blue}{\left(\sin b \cdot \frac{r}{\cos \left(b + a\right)}\right)}}^{3}} \]
    6. Applied egg-rr37.0%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\sin b \cdot \frac{r}{\cos \left(b + a\right)}\right)}^{3}}} \]
    7. Taylor expanded in a around 0 27.6%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{r}^{3} \cdot {\sin b}^{3}}{{\cos b}^{3}}}} \]
    8. Step-by-step derivation
      1. cube-prod37.0%

        \[\leadsto \sqrt[3]{\frac{\color{blue}{{\left(r \cdot \sin b\right)}^{3}}}{{\cos b}^{3}}} \]
    9. Simplified37.0%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}} \]
    10. Step-by-step derivation
      1. cbrt-div37.0%

        \[\leadsto \color{blue}{\frac{\sqrt[3]{{\left(r \cdot \sin b\right)}^{3}}}{\sqrt[3]{{\cos b}^{3}}}} \]
      2. rem-cbrt-cube98.7%

        \[\leadsto \frac{\color{blue}{r \cdot \sin b}}{\sqrt[3]{{\cos b}^{3}}} \]
      3. rem-cbrt-cube98.9%

        \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
      4. clear-num98.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
    11. Applied egg-rr98.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
    12. Step-by-step derivation
      1. clear-num98.9%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
      2. associate-*r/98.7%

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

        \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]
      4. quot-tan98.9%

        \[\leadsto \color{blue}{\tan b} \cdot r \]
    13. Applied egg-rr98.9%

      \[\leadsto \color{blue}{\tan b \cdot r} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification72.1%

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

Alternative 6: 77.2% 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 71.9%

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

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

Alternative 7: 77.1% accurate, 1.0× speedup?

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos \left(b + a\right)}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. *-commutative72.0%

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

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

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

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

Alternative 8: 76.9% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.00023 \lor \neg \left(b \leq 2.9 \cdot 10^{-6}\right):\\
\;\;\;\;r \cdot \tan b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -2.3000000000000001e-4 or 2.9000000000000002e-6 < b

    1. Initial program 51.6%

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

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

      \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-cbrt-cube16.0%

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

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

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

        \[\leadsto \sqrt[3]{{\left(\frac{\color{blue}{\sin b \cdot r}}{\cos \left(b + a\right)}\right)}^{3}} \]
      5. associate-/l*16.1%

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

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\sin b \cdot \frac{r}{\cos \left(b + a\right)}\right)}^{3}}} \]
    7. Taylor expanded in a around 0 15.6%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{r}^{3} \cdot {\sin b}^{3}}{{\cos b}^{3}}}} \]
    8. Step-by-step derivation
      1. cube-prod15.7%

        \[\leadsto \sqrt[3]{\frac{\color{blue}{{\left(r \cdot \sin b\right)}^{3}}}{{\cos b}^{3}}} \]
    9. Simplified15.7%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}} \]
    10. Step-by-step derivation
      1. cbrt-div15.6%

        \[\leadsto \color{blue}{\frac{\sqrt[3]{{\left(r \cdot \sin b\right)}^{3}}}{\sqrt[3]{{\cos b}^{3}}}} \]
      2. rem-cbrt-cube50.9%

        \[\leadsto \frac{\color{blue}{r \cdot \sin b}}{\sqrt[3]{{\cos b}^{3}}} \]
      3. rem-cbrt-cube51.1%

        \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
      4. clear-num51.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
    11. Applied egg-rr51.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
    12. Step-by-step derivation
      1. clear-num51.1%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
      2. associate-*r/51.0%

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

        \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]
      4. quot-tan51.1%

        \[\leadsto \color{blue}{\tan b} \cdot r \]
    13. Applied egg-rr51.1%

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

    if -2.3000000000000001e-4 < b < 2.9000000000000002e-6

    1. Initial program 99.3%

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

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

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

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

        \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
      2. cancel-sign-sub-inv99.7%

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

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

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin b\right) \cdot \sin a\right)}} \]
    7. Taylor expanded in b around 0 99.3%

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

        \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
    9. Simplified99.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -0.00023 \lor \neg \left(b \leq 2.9 \cdot 10^{-6}\right):\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 77.0% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{-6} \lor \neg \left(b \leq 1.95 \cdot 10^{-6}\right):\\
\;\;\;\;r \cdot \tan b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -2.69999999999999998e-6 or 1.95e-6 < b

    1. Initial program 51.6%

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

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

      \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-cbrt-cube16.0%

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

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

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

        \[\leadsto \sqrt[3]{{\left(\frac{\color{blue}{\sin b \cdot r}}{\cos \left(b + a\right)}\right)}^{3}} \]
      5. associate-/l*16.1%

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

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\sin b \cdot \frac{r}{\cos \left(b + a\right)}\right)}^{3}}} \]
    7. Taylor expanded in a around 0 15.6%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{r}^{3} \cdot {\sin b}^{3}}{{\cos b}^{3}}}} \]
    8. Step-by-step derivation
      1. cube-prod15.7%

        \[\leadsto \sqrt[3]{\frac{\color{blue}{{\left(r \cdot \sin b\right)}^{3}}}{{\cos b}^{3}}} \]
    9. Simplified15.7%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}} \]
    10. Step-by-step derivation
      1. cbrt-div15.6%

        \[\leadsto \color{blue}{\frac{\sqrt[3]{{\left(r \cdot \sin b\right)}^{3}}}{\sqrt[3]{{\cos b}^{3}}}} \]
      2. rem-cbrt-cube50.9%

        \[\leadsto \frac{\color{blue}{r \cdot \sin b}}{\sqrt[3]{{\cos b}^{3}}} \]
      3. rem-cbrt-cube51.1%

        \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
      4. clear-num51.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
    11. Applied egg-rr51.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
    12. Step-by-step derivation
      1. clear-num51.1%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
      2. associate-*r/51.0%

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

        \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]
      4. quot-tan51.1%

        \[\leadsto \color{blue}{\tan b} \cdot r \]
    13. Applied egg-rr51.1%

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

    if -2.69999999999999998e-6 < b < 1.95e-6

    1. Initial program 99.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.7 \cdot 10^{-6} \lor \neg \left(b \leq 1.95 \cdot 10^{-6}\right):\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 76.9% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-5}:\\
\;\;\;\;\frac{r}{\frac{1}{\tan b}}\\

\mathbf{elif}\;b \leq 3.9 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\

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


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

    1. Initial program 55.7%

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

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

      \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-cbrt-cube18.0%

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

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

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

        \[\leadsto \sqrt[3]{{\left(\frac{\color{blue}{\sin b \cdot r}}{\cos \left(b + a\right)}\right)}^{3}} \]
      5. associate-/l*18.1%

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

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\sin b \cdot \frac{r}{\cos \left(b + a\right)}\right)}^{3}}} \]
    7. Taylor expanded in a around 0 17.7%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{r}^{3} \cdot {\sin b}^{3}}{{\cos b}^{3}}}} \]
    8. Step-by-step derivation
      1. cube-prod17.7%

        \[\leadsto \sqrt[3]{\frac{\color{blue}{{\left(r \cdot \sin b\right)}^{3}}}{{\cos b}^{3}}} \]
    9. Simplified17.7%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}} \]
    10. Step-by-step derivation
      1. add-cube-cbrt17.6%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\sqrt[3]{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}} \cdot \sqrt[3]{\sqrt[3]{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}}\right) \cdot \sqrt[3]{\sqrt[3]{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}}} \]
      2. pow317.5%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{\sqrt[3]{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}}\right)}^{3}} \]
      3. cbrt-div17.5%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\frac{\sqrt[3]{{\left(r \cdot \sin b\right)}^{3}}}{\sqrt[3]{{\cos b}^{3}}}}}\right)}^{3} \]
      4. rem-cbrt-cube54.4%

        \[\leadsto {\left(\sqrt[3]{\frac{\color{blue}{r \cdot \sin b}}{\sqrt[3]{{\cos b}^{3}}}}\right)}^{3} \]
      5. rem-cbrt-cube54.4%

        \[\leadsto {\left(\sqrt[3]{\frac{r \cdot \sin b}{\color{blue}{\cos b}}}\right)}^{3} \]
      6. associate-/l*54.3%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{r \cdot \frac{\sin b}{\cos b}}}\right)}^{3} \]
    11. Applied egg-rr54.3%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{r \cdot \frac{\sin b}{\cos b}}\right)}^{3}} \]
    12. Step-by-step derivation
      1. rem-cube-cbrt55.0%

        \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos b}} \]
      2. clear-num55.0%

        \[\leadsto r \cdot \color{blue}{\frac{1}{\frac{\cos b}{\sin b}}} \]
      3. un-div-inv55.2%

        \[\leadsto \color{blue}{\frac{r}{\frac{\cos b}{\sin b}}} \]
      4. clear-num55.1%

        \[\leadsto \frac{r}{\color{blue}{\frac{1}{\frac{\sin b}{\cos b}}}} \]
      5. quot-tan55.2%

        \[\leadsto \frac{r}{\frac{1}{\color{blue}{\tan b}}} \]
    13. Applied egg-rr55.2%

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

    if -7.20000000000000018e-5 < b < 3.8999999999999999e-6

    1. Initial program 99.3%

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

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

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

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

    if 3.8999999999999999e-6 < b

    1. Initial program 46.1%

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

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

      \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-cbrt-cube13.4%

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

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

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

        \[\leadsto \sqrt[3]{{\left(\frac{\color{blue}{\sin b \cdot r}}{\cos \left(b + a\right)}\right)}^{3}} \]
      5. associate-/l*13.4%

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

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\sin b \cdot \frac{r}{\cos \left(b + a\right)}\right)}^{3}}} \]
    7. Taylor expanded in a around 0 12.9%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{r}^{3} \cdot {\sin b}^{3}}{{\cos b}^{3}}}} \]
    8. Step-by-step derivation
      1. cube-prod12.9%

        \[\leadsto \sqrt[3]{\frac{\color{blue}{{\left(r \cdot \sin b\right)}^{3}}}{{\cos b}^{3}}} \]
    9. Simplified12.9%

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}} \]
    10. Step-by-step derivation
      1. cbrt-div12.9%

        \[\leadsto \color{blue}{\frac{\sqrt[3]{{\left(r \cdot \sin b\right)}^{3}}}{\sqrt[3]{{\cos b}^{3}}}} \]
      2. rem-cbrt-cube45.4%

        \[\leadsto \frac{\color{blue}{r \cdot \sin b}}{\sqrt[3]{{\cos b}^{3}}} \]
      3. rem-cbrt-cube45.7%

        \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
      4. clear-num45.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
    11. Applied egg-rr45.6%

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
    12. Step-by-step derivation
      1. clear-num45.7%

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
      2. associate-*r/45.6%

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

        \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]
      4. quot-tan45.7%

        \[\leadsto \color{blue}{\tan b} \cdot r \]
    13. Applied egg-rr45.7%

      \[\leadsto \color{blue}{\tan b \cdot r} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification71.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7.2 \cdot 10^{-5}:\\ \;\;\;\;\frac{r}{\frac{1}{\tan b}}\\ \mathbf{elif}\;b \leq 3.9 \cdot 10^{-6}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \tan b\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 39.0% 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 71.9%

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

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

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

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

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

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos a - b \cdot \sin a}} \]
  7. Simplified47.0%

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

    \[\leadsto r \cdot \color{blue}{\sin b} \]
  9. Final simplification34.4%

    \[\leadsto r \cdot \sin b \]
  10. Add Preprocessing

Alternative 12: 60.3% accurate, 2.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-cbrt-cube32.1%

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

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

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

      \[\leadsto \sqrt[3]{{\left(\frac{\color{blue}{\sin b \cdot r}}{\cos \left(b + a\right)}\right)}^{3}} \]
    5. associate-/l*32.2%

      \[\leadsto \sqrt[3]{{\color{blue}{\left(\sin b \cdot \frac{r}{\cos \left(b + a\right)}\right)}}^{3}} \]
  6. Applied egg-rr32.2%

    \[\leadsto \color{blue}{\sqrt[3]{{\left(\sin b \cdot \frac{r}{\cos \left(b + a\right)}\right)}^{3}}} \]
  7. Taylor expanded in a around 0 21.4%

    \[\leadsto \sqrt[3]{\color{blue}{\frac{{r}^{3} \cdot {\sin b}^{3}}{{\cos b}^{3}}}} \]
  8. Step-by-step derivation
    1. cube-prod26.3%

      \[\leadsto \sqrt[3]{\frac{\color{blue}{{\left(r \cdot \sin b\right)}^{3}}}{{\cos b}^{3}}} \]
  9. Simplified26.3%

    \[\leadsto \sqrt[3]{\color{blue}{\frac{{\left(r \cdot \sin b\right)}^{3}}{{\cos b}^{3}}}} \]
  10. Step-by-step derivation
    1. cbrt-div26.3%

      \[\leadsto \color{blue}{\frac{\sqrt[3]{{\left(r \cdot \sin b\right)}^{3}}}{\sqrt[3]{{\cos b}^{3}}}} \]
    2. rem-cbrt-cube56.2%

      \[\leadsto \frac{\color{blue}{r \cdot \sin b}}{\sqrt[3]{{\cos b}^{3}}} \]
    3. rem-cbrt-cube56.3%

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b}} \]
    4. clear-num56.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
  11. Applied egg-rr56.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{r \cdot \sin b}}} \]
  12. Step-by-step derivation
    1. clear-num56.3%

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    2. associate-*r/56.2%

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

      \[\leadsto \color{blue}{\frac{\sin b}{\cos b} \cdot r} \]
    4. quot-tan56.3%

      \[\leadsto \color{blue}{\tan b} \cdot r \]
  13. Applied egg-rr56.3%

    \[\leadsto \color{blue}{\tan b \cdot r} \]
  14. Final simplification56.3%

    \[\leadsto r \cdot \tan b \]
  15. Add Preprocessing

Alternative 13: 35.1% 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 71.9%

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

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

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

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

    \[\leadsto r \cdot \color{blue}{b} \]
  7. Final simplification29.8%

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

Reproduce

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