rsin A (should all be same)

Percentage Accurate: 75.8% → 99.5%
Time: 20.2s
Alternatives: 15
Speedup: 0.5×

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 15 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: 75.8% 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(\sin a, -\sin b, \cos a \cdot \cos b\right)} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (/ (* r (sin b)) (fma (sin a) (- (sin b)) (* (cos a) (cos b)))))
double code(double r, double a, double b) {
	return (r * sin(b)) / fma(sin(a), -sin(b), (cos(a) * cos(b)));
}
function code(r, a, b)
	return Float64(Float64(r * sin(b)) / fma(sin(a), Float64(-sin(b)), Float64(cos(a) * cos(b))))
end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[a], $MachinePrecision] * (-N[Sin[b], $MachinePrecision]) + N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

    \[\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. sub-neg99.4%

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

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(-\sin a\right)\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(sin(b) * Float64(-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 \left(-\sin a\right)\right)}
\end{array}
Derivation
  1. Initial program 77.8%

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

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

    \[\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. fma-neg99.4%

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

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

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

Alternative 3: 99.5% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-\sin b \cdot -1}}{\cos \left(a + b\right)} \cdot r \]
    12. distribute-rgt-neg-in77.8%

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

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

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

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

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

    \[\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 a \cdot \cos b - \sin b \cdot \sin a} \]

Alternative 4: 99.4% accurate, 0.4× speedup?

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

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

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

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

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

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

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

Alternative 5: 99.5% accurate, 0.4× speedup?

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

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

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

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

    \[\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 a \cdot \cos b - \sin b \cdot \sin a} \]

Alternative 6: 76.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \frac{r \cdot \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(Float64(r * sin(b)) / fma(cos(b), cos(a), 0.0))
end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + 0.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

    \[\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. fma-neg99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 75.0% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -2.14999999999999994e24 or 22 < a

    1. Initial program 55.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.14999999999999994e24 < a < 22

    1. Initial program 97.7%

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

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

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

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

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

        \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} + -1 \cdot a}} \]
      2. mul-1-neg97.5%

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

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

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
    7. Step-by-step derivation
      1. expm1-log1p-u75.8%

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{r}{\frac{\cos b}{\sin b} - a}\right)} - 1} \]
      3. clear-num35.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{r}{\color{blue}{\frac{1}{\frac{\sin b}{\cos b}}} - a}\right)} - 1 \]
      4. quot-tan35.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{r}{\frac{1}{\color{blue}{\tan b}} - a}\right)} - 1 \]
    8. Applied egg-rr35.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{r}{\frac{1}{\tan b} - a}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def75.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{r}{\frac{1}{\tan b} - a}\right)\right)} \]
      2. expm1-log1p97.5%

        \[\leadsto \color{blue}{\frac{r}{\frac{1}{\tan b} - a}} \]
    10. Simplified97.5%

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

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

Alternative 8: 75.0% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -2.14999999999999994e24 or 22 < a

    1. Initial program 55.5%

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

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

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

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

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

    if -2.14999999999999994e24 < a < 22

    1. Initial program 97.7%

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

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

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

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

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

        \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} + -1 \cdot a}} \]
      2. mul-1-neg97.5%

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

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

      \[\leadsto \frac{r}{\color{blue}{\frac{\cos b}{\sin b} - a}} \]
    7. Step-by-step derivation
      1. expm1-log1p-u75.8%

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{r}{\frac{\cos b}{\sin b} - a}\right)} - 1} \]
      3. clear-num35.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{r}{\color{blue}{\frac{1}{\frac{\sin b}{\cos b}}} - a}\right)} - 1 \]
      4. quot-tan35.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{r}{\frac{1}{\color{blue}{\tan b}} - a}\right)} - 1 \]
    8. Applied egg-rr35.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{r}{\frac{1}{\tan b} - a}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def75.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{r}{\frac{1}{\tan b} - a}\right)\right)} \]
      2. expm1-log1p97.5%

        \[\leadsto \color{blue}{\frac{r}{\frac{1}{\tan b} - a}} \]
    10. Simplified97.5%

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

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

Alternative 9: 75.8% 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 77.8%

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

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

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

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

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

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

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

Alternative 10: 75.6% accurate, 1.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -9.6000000000000002e-5 or 0.00160000000000000008 < b

    1. Initial program 59.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin b \cdot -1}}{\cos \left(a + b\right)} \cdot r \]
      12. distribute-rgt-neg-in59.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\tan b} \cdot r \]
      2. expm1-log1p-u50.0%

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

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

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

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

        \[\leadsto \color{blue}{\tan b} \cdot r \]
    8. Simplified58.9%

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

    if -9.6000000000000002e-5 < b < 0.00160000000000000008

    1. Initial program 98.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9.6 \cdot 10^{-5} \lor \neg \left(b \leq 0.0016\right):\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;r \cdot \left(b \cdot \frac{1}{\cos a}\right)\\ \end{array} \]

Alternative 11: 75.6% accurate, 1.9× speedup?

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

    1. Initial program 59.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin b \cdot -1}}{\cos \left(a + b\right)} \cdot r \]
      12. distribute-rgt-neg-in59.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\tan b} \cdot r \]
      2. expm1-log1p-u50.0%

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

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

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

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

        \[\leadsto \color{blue}{\tan b} \cdot r \]
    8. Simplified58.9%

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

    if -7.7999999999999999e-5 < b < 0.0015

    1. Initial program 98.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-\sin b \cdot -1}}{\cos \left(a + b\right)} \cdot r \]
    12. distribute-rgt-neg-in77.8%

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

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

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

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

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

    \[\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 \]
  5. Taylor expanded in a around 0 37.3%

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

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

Alternative 13: 59.9% 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 77.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-\sin b \cdot -1}}{\cos \left(a + b\right)} \cdot r \]
    12. distribute-rgt-neg-in77.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\tan b} \cdot r \]
    2. expm1-log1p-u56.7%

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

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

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

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

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

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

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

Alternative 14: 35.3% accurate, 23.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{r}{\mathsf{fma}\left(b, \color{blue}{\cos a \cdot \left(-0.5 - -0.16666666666666666\right)}, \frac{\cos a}{b}\right) - \sin a} \]
    6. metadata-eval50.3%

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

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

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

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

Alternative 15: 34.9% 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 77.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-\sin b \cdot -1}}{\cos \left(a + b\right)} \cdot r \]
    12. distribute-rgt-neg-in77.8%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{b \cdot r} \]
  6. Step-by-step derivation
    1. *-commutative32.5%

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

    \[\leadsto \color{blue}{r \cdot b} \]
  8. Final simplification32.5%

    \[\leadsto r \cdot b \]

Reproduce

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