rsin A (should all be same)

Percentage Accurate: 76.6% → 99.5%
Time: 14.5s
Alternatives: 14
Speedup: 0.4×

Specification

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

\\
\frac{r \cdot \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 14 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.6% accurate, 1.0× speedup?

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

\\
\frac{r \cdot \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, -\sin b \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, -\sin b \cdot \sin a\right)}
\end{array}
Derivation
  1. Initial program 75.5%

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

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

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

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

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

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

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

Alternative 2: 99.4% accurate, 0.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 76.3% accurate, 1.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;r \cdot \frac{1}{\frac{1}{\tan b} - a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -0.0038999999999999998 or 6.1e10 < a

    1. Initial program 51.8%

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

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

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

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

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

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

    if -0.0038999999999999998 < a < 6.1e10

    1. Initial program 96.3%

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

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

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

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

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} + -1 \cdot a}} \]
    5. Step-by-step derivation
      1. mul-1-neg96.9%

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

        \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
    6. Simplified96.9%

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
    7. Step-by-step derivation
      1. div-inv97.0%

        \[\leadsto \color{blue}{r \cdot \frac{1}{\frac{\cos b}{\sin b} - a}} \]
      2. clear-num96.9%

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

        \[\leadsto r \cdot \frac{1}{\frac{1}{\color{blue}{\tan b}} - a} \]
    8. Applied egg-rr97.1%

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

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

Alternative 6: 76.3% accurate, 1.0× speedup?

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

\mathbf{elif}\;a \leq 61000000000:\\
\;\;\;\;r \cdot \frac{1}{\frac{1}{\tan b} - a}\\

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


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

    1. Initial program 48.7%

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

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

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

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

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

    if -0.00220000000000000013 < a < 6.1e10

    1. Initial program 96.3%

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

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

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

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

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} + -1 \cdot a}} \]
    5. Step-by-step derivation
      1. mul-1-neg96.9%

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

        \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
    6. Simplified96.9%

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
    7. Step-by-step derivation
      1. div-inv97.0%

        \[\leadsto \color{blue}{r \cdot \frac{1}{\frac{\cos b}{\sin b} - a}} \]
      2. clear-num96.9%

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

        \[\leadsto r \cdot \frac{1}{\frac{1}{\color{blue}{\tan b}} - a} \]
    8. Applied egg-rr97.1%

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

    if 6.1e10 < a

    1. Initial program 54.1%

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

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

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

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

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

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

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

Alternative 7: 76.3% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;a \leq 61000000000:\\
\;\;\;\;r \cdot \frac{1}{\frac{1}{\tan b} - a}\\

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


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

    1. Initial program 48.7%

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

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

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

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

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

    if -1.65e-4 < a < 6.1e10

    1. Initial program 96.3%

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

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

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

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

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} + -1 \cdot a}} \]
    5. Step-by-step derivation
      1. mul-1-neg96.9%

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

        \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
    6. Simplified96.9%

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
    7. Step-by-step derivation
      1. div-inv97.0%

        \[\leadsto \color{blue}{r \cdot \frac{1}{\frac{\cos b}{\sin b} - a}} \]
      2. clear-num96.9%

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

        \[\leadsto r \cdot \frac{1}{\frac{1}{\color{blue}{\tan b}} - a} \]
    8. Applied egg-rr97.1%

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

    if 6.1e10 < a

    1. Initial program 54.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{r}{\frac{\cos \left(b + a\right)}{\sin b}}} \]
  4. Step-by-step derivation
    1. associate-/r/75.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. Final simplification75.5%

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

Alternative 9: 76.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.00014 \lor \neg \left(b \leq 0.000106\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 -0.00014) (not (<= b 0.000106)))
   (* r (tan b))
   (* r (/ b (cos a)))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.00014) || !(b <= 0.000106)) {
		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 <= (-0.00014d0)) .or. (.not. (b <= 0.000106d0))) 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 <= -0.00014) || !(b <= 0.000106)) {
		tmp = r * Math.tan(b);
	} else {
		tmp = r * (b / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -0.00014) or not (b <= 0.000106):
		tmp = r * math.tan(b)
	else:
		tmp = r * (b / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -0.00014) || !(b <= 0.000106))
		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 <= -0.00014) || ~((b <= 0.000106)))
		tmp = r * tan(b);
	else
		tmp = r * (b / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.00014], N[Not[LessEqual[b, 0.000106]], $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 -0.00014 \lor \neg \left(b \leq 0.000106\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 < -1.3999999999999999e-4 or 1.06e-4 < b

    1. Initial program 51.4%

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

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

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

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

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

      \[\leadsto \frac{\sin b}{\color{blue}{\cos b}} \cdot r \]
    5. Step-by-step derivation
      1. expm1-log1p-u36.9%

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

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{\sin b}{\cos b}\right)} - 1\right)} \cdot r \]
      3. quot-tan36.6%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\tan b}\right)} - 1\right) \cdot r \]
    6. Applied egg-rr36.6%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\tan b\right)} - 1\right)} \cdot r \]
    7. Step-by-step derivation
      1. expm1-def37.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan b\right)\right)} \cdot r \]
      2. expm1-log1p52.2%

        \[\leadsto \color{blue}{\tan b} \cdot r \]
    8. Simplified52.2%

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

    if -1.3999999999999999e-4 < b < 1.06e-4

    1. Initial program 98.5%

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

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

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

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

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

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

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

Alternative 10: 76.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.00014 \lor \neg \left(b \leq 0.000102\right):\\
\;\;\;\;r \cdot \tan b\\

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


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

    1. Initial program 51.4%

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

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

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

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

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

      \[\leadsto \frac{\sin b}{\color{blue}{\cos b}} \cdot r \]
    5. Step-by-step derivation
      1. expm1-log1p-u36.9%

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

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{\sin b}{\cos b}\right)} - 1\right)} \cdot r \]
      3. quot-tan36.6%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\tan b}\right)} - 1\right) \cdot r \]
    6. Applied egg-rr36.6%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\tan b\right)} - 1\right)} \cdot r \]
    7. Step-by-step derivation
      1. expm1-def37.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan b\right)\right)} \cdot r \]
      2. expm1-log1p52.2%

        \[\leadsto \color{blue}{\tan b} \cdot r \]
    8. Simplified52.2%

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

    if -1.3999999999999999e-4 < b < 1.01999999999999999e-4

    1. Initial program 98.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\sin b \cdot r} \]
  8. Final simplification42.0%

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

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

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

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

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

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

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

    \[\leadsto \frac{\sin b}{\color{blue}{\cos b}} \cdot r \]
  5. Step-by-step derivation
    1. expm1-log1p-u54.2%

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

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{\sin b}{\cos b}\right)} - 1\right)} \cdot r \]
    3. quot-tan33.0%

      \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\tan b}\right)} - 1\right) \cdot r \]
  6. Applied egg-rr33.0%

    \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\tan b\right)} - 1\right)} \cdot r \]
  7. Step-by-step derivation
    1. expm1-def54.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan b\right)\right)} \cdot r \]
    2. expm1-log1p61.7%

      \[\leadsto \color{blue}{\tan b} \cdot r \]
  8. Simplified61.7%

    \[\leadsto \color{blue}{\tan b} \cdot r \]
  9. Final simplification61.7%

    \[\leadsto r \cdot \tan b \]

Alternative 13: 35.2% accurate, 18.8× speedup?

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

\\
r \cdot \frac{1}{b \cdot -0.3333333333333333 + \frac{1}{b}}
\end{array}
Derivation
  1. Initial program 75.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{\sin b}}} \cdot r \]
    2. inv-pow61.6%

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

    \[\leadsto \color{blue}{{\left(\frac{\cos b}{\sin b}\right)}^{-1}} \cdot r \]
  7. Step-by-step derivation
    1. unpow-161.6%

      \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{\sin b}}} \cdot r \]
  8. Simplified61.6%

    \[\leadsto \color{blue}{\frac{1}{\frac{\cos b}{\sin b}}} \cdot r \]
  9. Taylor expanded in b around 0 38.8%

    \[\leadsto \frac{1}{\color{blue}{-0.3333333333333333 \cdot b + \frac{1}{b}}} \cdot r \]
  10. Final simplification38.8%

    \[\leadsto r \cdot \frac{1}{b \cdot -0.3333333333333333 + \frac{1}{b}} \]

Alternative 14: 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%

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

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

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

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

    \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} + -1 \cdot a}} \]
  5. Step-by-step derivation
    1. mul-1-neg59.3%

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

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
  6. Simplified59.3%

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

    \[\leadsto \color{blue}{r \cdot b} \]
  8. Final simplification37.9%

    \[\leadsto r \cdot b \]

Reproduce

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