rsin B (should all be same)

Percentage Accurate: 76.8% → 99.5%
Time: 18.5s
Alternatives: 15
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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: 76.8% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 0.3× speedup?

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos \left(a + b\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{\left(a + b\right)}\right) \]
    4. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos \left(a + \color{blue}{b}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\left(a + b\right)\right)\right) \]
    6. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\left(b + a\right)\right)\right) \]
    7. +-lowering-+.f6477.5%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right) \]
  3. Simplified77.5%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\cos b \cdot \cos a - \color{blue}{\sin b \cdot \sin a}\right)\right) \]
    2. fmm-defN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\mathsf{fma}\left(\cos b, \color{blue}{\cos a}, \mathsf{neg}\left(\sin b \cdot \sin a\right)\right)\right)\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\mathsf{fma}\left(\cos b, \cos a, \mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right) \]
    4. fma-lowering-fma.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\cos b, \color{blue}{\cos a}, \left(\mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \cos \color{blue}{a}, \left(\mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\mathsf{neg}\left(\sin b \cdot \sin a\right)\right)\right)\right) \]
    8. distribute-rgt-neg-inN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\sin b \cdot \left(\mathsf{neg}\left(\sin a\right)\right)\right)\right)\right) \]
    9. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\sin b, \left(\mathsf{neg}\left(\sin a\right)\right)\right)\right)\right) \]
    10. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \left(\mathsf{neg}\left(\sin a\right)\right)\right)\right)\right) \]
    11. neg-sub0N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \left(0 - \sin a\right)\right)\right)\right) \]
    12. --lowering--.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(0, \sin a\right)\right)\right)\right) \]
    13. sin-lowering-sin.f6499.5%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(a\right)\right)\right)\right)\right) \]
  6. Applied egg-rr99.5%

    \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(0 - \sin a\right)\right)}} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\sin b \cdot \left(0 - \sin a\right) + \color{blue}{\cos b \cdot \cos a}\right)\right) \]
    2. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\left(0 - \sin a\right) \cdot \sin b + \color{blue}{\cos b} \cdot \cos a\right)\right) \]
    3. fma-defineN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\mathsf{fma}\left(0 - \sin a, \color{blue}{\sin b}, \cos b \cdot \cos a\right)\right)\right) \]
    4. fma-lowering-fma.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\left(0 - \sin a\right), \color{blue}{\sin b}, \left(\cos b \cdot \cos a\right)\right)\right) \]
    5. --lowering--.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \sin a\right), \sin \color{blue}{b}, \left(\cos b \cdot \cos a\right)\right)\right) \]
    6. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(a\right)\right), \sin b, \left(\cos b \cdot \cos a\right)\right)\right) \]
    7. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(a\right)\right), \mathsf{sin.f64}\left(b\right), \left(\cos b \cdot \cos a\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(a\right)\right), \mathsf{sin.f64}\left(b\right), \mathsf{*.f64}\left(\cos b, \cos a\right)\right)\right) \]
    9. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(a\right)\right), \mathsf{sin.f64}\left(b\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(b\right), \cos a\right)\right)\right) \]
    10. cos-lowering-cos.f6499.5%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(a\right)\right), \mathsf{sin.f64}\left(b\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right)\right)\right)\right) \]
  8. Applied egg-rr99.5%

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

Alternative 2: 99.4% accurate, 0.3× speedup?

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

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

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

      \[\leadsto r \cdot \frac{1}{\color{blue}{\frac{\cos \left(a + b\right)}{\sin b}}} \]
    2. un-div-invN/A

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

      \[\leadsto \frac{r}{\cos \left(a + b\right)} \cdot \color{blue}{\sin b} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{r}{\cos \left(a + b\right)}\right), \color{blue}{\sin b}\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \cos \left(a + b\right)\right), \sin \color{blue}{b}\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(a + b\right)\right)\right), \sin b\right) \]
    7. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(b + a\right)\right)\right), \sin b\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \sin b\right) \]
    9. sin-lowering-sin.f6477.4%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
  4. Applied egg-rr77.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \left(\cos b \cdot \cos a - \sin b \cdot \sin a\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    2. fmm-defN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \left(\mathsf{fma}\left(\cos b, \cos a, \mathsf{neg}\left(\sin b \cdot \sin a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    3. distribute-rgt-neg-outN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \left(\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(\mathsf{neg}\left(\sin a\right)\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    4. sub0-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \left(\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(0 - \sin a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    5. fma-lowering-fma.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\cos b, \cos a, \left(\sin b \cdot \left(0 - \sin a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \cos a, \left(\sin b \cdot \left(0 - \sin a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    7. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\sin b \cdot \left(0 - \sin a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    8. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\left(0 - \sin a\right) \cdot \sin b\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    9. sub0-negN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\left(\mathsf{neg}\left(\sin a\right)\right) \cdot \sin b\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    10. distribute-lft-neg-outN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    11. neg-lowering-neg.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{neg.f64}\left(\left(\sin a \cdot \sin b\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    12. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{neg.f64}\left(\left(\sin b \cdot \sin a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\sin b, \sin a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    14. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \sin a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    15. sin-lowering-sin.f6499.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{sin.f64}\left(a\right)\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
  6. Applied egg-rr99.5%

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

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

Alternative 3: 99.5% accurate, 0.4× speedup?

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos \left(a + b\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{\left(a + b\right)}\right) \]
    4. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos \left(a + \color{blue}{b}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\left(a + b\right)\right)\right) \]
    6. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\left(b + a\right)\right)\right) \]
    7. +-lowering-+.f6477.5%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right) \]
  3. Simplified77.5%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos \left(a + b\right)\right) \]
    2. cos-sumN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\cos a \cdot \cos b - \color{blue}{\sin a \cdot \sin b}\right)\right) \]
    3. --lowering--.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{\_.f64}\left(\left(\cos a \cdot \cos b\right), \color{blue}{\left(\sin a \cdot \sin b\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\cos a, \cos b\right), \left(\color{blue}{\sin a} \cdot \sin b\right)\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \cos b\right), \left(\sin \color{blue}{a} \cdot \sin b\right)\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \left(\sin a \cdot \sin b\right)\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \left(\sin b \cdot \color{blue}{\sin a}\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \mathsf{*.f64}\left(\sin b, \color{blue}{\sin a}\right)\right)\right) \]
    9. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \sin \color{blue}{a}\right)\right)\right) \]
    10. sin-lowering-sin.f6499.5%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{sin.f64}\left(a\right)\right)\right)\right) \]
  6. Applied egg-rr99.5%

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

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

Alternative 4: 99.4% accurate, 0.4× speedup?

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

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

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

      \[\leadsto r \cdot \frac{1}{\color{blue}{\frac{\cos \left(a + b\right)}{\sin b}}} \]
    2. un-div-invN/A

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

      \[\leadsto \frac{r}{\cos \left(a + b\right)} \cdot \color{blue}{\sin b} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{r}{\cos \left(a + b\right)}\right), \color{blue}{\sin b}\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \cos \left(a + b\right)\right), \sin \color{blue}{b}\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(a + b\right)\right)\right), \sin b\right) \]
    7. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(b + a\right)\right)\right), \sin b\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \sin b\right) \]
    9. sin-lowering-sin.f6477.4%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
  4. Applied egg-rr77.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \left(\cos b \cdot \cos a - \sin b \cdot \sin a\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    2. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \left(\cos b \cdot \cos a - \sin a \cdot \sin b\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    3. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{\_.f64}\left(\left(\cos b \cdot \cos a\right), \left(\sin a \cdot \sin b\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\cos b, \cos a\right), \left(\sin a \cdot \sin b\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(b\right), \cos a\right), \left(\sin a \cdot \sin b\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right)\right), \left(\sin a \cdot \sin b\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right)\right), \left(\sin b \cdot \sin a\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right)\right), \mathsf{*.f64}\left(\sin b, \sin a\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    9. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \sin a\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    10. sin-lowering-sin.f6499.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{sin.f64}\left(a\right)\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
  6. Applied egg-rr99.5%

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

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

Alternative 5: 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 77.4%

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

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \left(\cos a \cdot \cos b - \color{blue}{\sin a \cdot \sin b}\right)\right)\right) \]
    2. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(\left(\cos a \cdot \cos b\right), \color{blue}{\left(\sin a \cdot \sin b\right)}\right)\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\cos a, \cos b\right), \left(\color{blue}{\sin a} \cdot \sin b\right)\right)\right)\right) \]
    4. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \cos b\right), \left(\sin \color{blue}{a} \cdot \sin b\right)\right)\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \left(\sin a \cdot \sin b\right)\right)\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \left(\sin b \cdot \color{blue}{\sin a}\right)\right)\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \mathsf{*.f64}\left(\sin b, \color{blue}{\sin a}\right)\right)\right)\right) \]
    8. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \sin \color{blue}{a}\right)\right)\right)\right) \]
    9. sin-lowering-sin.f6499.5%

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(a\right), \mathsf{cos.f64}\left(b\right)\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{sin.f64}\left(a\right)\right)\right)\right)\right) \]
  4. Applied egg-rr99.5%

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

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

Alternative 6: 76.7% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 55.9%

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

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos b}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{b}\right) \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos b\right) \]
      4. cos-lowering-cos.f6455.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(b\right)\right) \]
    5. Simplified55.5%

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

    if -0.0030000000000000001 < b < 0.00820000000000000069

    1. Initial program 98.5%

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

        \[\leadsto r \cdot \frac{1}{\color{blue}{\frac{\cos \left(a + b\right)}{\sin b}}} \]
      2. un-div-invN/A

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

        \[\leadsto \frac{r}{\cos \left(a + b\right)} \cdot \color{blue}{\sin b} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{r}{\cos \left(a + b\right)}\right), \color{blue}{\sin b}\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \cos \left(a + b\right)\right), \sin \color{blue}{b}\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(a + b\right)\right)\right), \sin b\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(b + a\right)\right)\right), \sin b\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \sin b\right) \]
      9. sin-lowering-sin.f6498.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    4. Applied egg-rr98.5%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \color{blue}{\left(b \cdot \left(1 + \frac{-1}{6} \cdot {b}^{2}\right)\right)}\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \color{blue}{\left(1 + \frac{-1}{6} \cdot {b}^{2}\right)}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{6} \cdot {b}^{2}\right)}\right)\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \color{blue}{\left({b}^{2}\right)}\right)\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \left(b \cdot \color{blue}{b}\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f6498.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \mathsf{*.f64}\left(b, \color{blue}{b}\right)\right)\right)\right)\right) \]
    7. Simplified98.5%

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

    if 0.00820000000000000069 < b

    1. Initial program 53.6%

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

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos b}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{b}\right) \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos b\right) \]
      4. cos-lowering-cos.f6453.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(b\right)\right) \]
    5. Simplified53.5%

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

        \[\leadsto r \cdot \color{blue}{\frac{\sin b}{\cos b}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\sin b}{\cos b} \cdot \color{blue}{r} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\sin b}{\cos b}\right), \color{blue}{r}\right) \]
      4. quot-tanN/A

        \[\leadsto \mathsf{*.f64}\left(\tan b, r\right) \]
      5. tan-lowering-tan.f6453.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{tan.f64}\left(b\right), r\right) \]
    7. Applied egg-rr53.7%

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

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

Alternative 7: 76.8% accurate, 1.0× speedup?

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos \left(a + b\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{\left(a + b\right)}\right) \]
    4. sin-lowering-sin.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos \left(a + \color{blue}{b}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\left(a + b\right)\right)\right) \]
    6. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\left(b + a\right)\right)\right) \]
    7. +-lowering-+.f6477.5%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right) \]
  3. Simplified77.5%

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

Alternative 8: 76.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.4%

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

      \[\leadsto r \cdot \frac{1}{\color{blue}{\frac{\cos \left(a + b\right)}{\sin b}}} \]
    2. un-div-invN/A

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

      \[\leadsto \frac{r}{\cos \left(a + b\right)} \cdot \color{blue}{\sin b} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{r}{\cos \left(a + b\right)}\right), \color{blue}{\sin b}\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \cos \left(a + b\right)\right), \sin \color{blue}{b}\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(a + b\right)\right)\right), \sin b\right) \]
    7. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(b + a\right)\right)\right), \sin b\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \sin b\right) \]
    9. sin-lowering-sin.f6477.4%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
  4. Applied egg-rr77.4%

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

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

Alternative 9: 76.8% accurate, 1.0× speedup?

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

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

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

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

Alternative 10: 76.7% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
t_0 := r \cdot \tan b\\
\mathbf{if}\;b \leq -0.0065:\\
\;\;\;\;t\_0\\

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 54.7%

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

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos b}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{b}\right) \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos b\right) \]
      4. cos-lowering-cos.f6454.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(b\right)\right) \]
    5. Simplified54.5%

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

        \[\leadsto r \cdot \color{blue}{\frac{\sin b}{\cos b}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\sin b}{\cos b} \cdot \color{blue}{r} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\sin b}{\cos b}\right), \color{blue}{r}\right) \]
      4. quot-tanN/A

        \[\leadsto \mathsf{*.f64}\left(\tan b, r\right) \]
      5. tan-lowering-tan.f6454.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{tan.f64}\left(b\right), r\right) \]
    7. Applied egg-rr54.5%

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

    if -0.0064999999999999997 < b < 0.00279999999999999997

    1. Initial program 98.5%

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

        \[\leadsto r \cdot \frac{1}{\color{blue}{\frac{\cos \left(a + b\right)}{\sin b}}} \]
      2. un-div-invN/A

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

        \[\leadsto \frac{r}{\cos \left(a + b\right)} \cdot \color{blue}{\sin b} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{r}{\cos \left(a + b\right)}\right), \color{blue}{\sin b}\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \cos \left(a + b\right)\right), \sin \color{blue}{b}\right) \]
      6. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(a + b\right)\right)\right), \sin b\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\left(b + a\right)\right)\right), \sin b\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \sin b\right) \]
      9. sin-lowering-sin.f6498.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{sin.f64}\left(b\right)\right) \]
    4. Applied egg-rr98.5%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \color{blue}{\left(b \cdot \left(1 + \frac{-1}{6} \cdot {b}^{2}\right)\right)}\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \color{blue}{\left(1 + \frac{-1}{6} \cdot {b}^{2}\right)}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{6} \cdot {b}^{2}\right)}\right)\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \color{blue}{\left({b}^{2}\right)}\right)\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \left(b \cdot \color{blue}{b}\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f6498.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right), \mathsf{*.f64}\left(b, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{6}, \mathsf{*.f64}\left(b, \color{blue}{b}\right)\right)\right)\right)\right) \]
    7. Simplified98.5%

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

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

Alternative 11: 76.7% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := r \cdot \tan b\\ \mathbf{if}\;b \leq -5.9 \cdot 10^{-5}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;b \leq 8.6 \cdot 10^{-6}:\\ \;\;\;\;r \cdot \frac{b}{\cos \left(b + a\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (let* ((t_0 (* r (tan b))))
   (if (<= b -5.9e-5) t_0 (if (<= b 8.6e-6) (* r (/ b (cos (+ b a)))) t_0))))
double code(double r, double a, double b) {
	double t_0 = r * tan(b);
	double tmp;
	if (b <= -5.9e-5) {
		tmp = t_0;
	} else if (b <= 8.6e-6) {
		tmp = r * (b / cos((b + a)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_0
    real(8) :: tmp
    t_0 = r * tan(b)
    if (b <= (-5.9d-5)) then
        tmp = t_0
    else if (b <= 8.6d-6) then
        tmp = r * (b / cos((b + a)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double t_0 = r * Math.tan(b);
	double tmp;
	if (b <= -5.9e-5) {
		tmp = t_0;
	} else if (b <= 8.6e-6) {
		tmp = r * (b / Math.cos((b + a)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(r, a, b):
	t_0 = r * math.tan(b)
	tmp = 0
	if b <= -5.9e-5:
		tmp = t_0
	elif b <= 8.6e-6:
		tmp = r * (b / math.cos((b + a)))
	else:
		tmp = t_0
	return tmp
function code(r, a, b)
	t_0 = Float64(r * tan(b))
	tmp = 0.0
	if (b <= -5.9e-5)
		tmp = t_0;
	elseif (b <= 8.6e-6)
		tmp = Float64(r * Float64(b / cos(Float64(b + a))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	t_0 = r * tan(b);
	tmp = 0.0;
	if (b <= -5.9e-5)
		tmp = t_0;
	elseif (b <= 8.6e-6)
		tmp = r * (b / cos((b + a)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5.9e-5], t$95$0, If[LessEqual[b, 8.6e-6], N[(r * N[(b / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := r \cdot \tan b\\
\mathbf{if}\;b \leq -5.9 \cdot 10^{-5}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;b \leq 8.6 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \frac{b}{\cos \left(b + a\right)}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 55.5%

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

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos b}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{b}\right) \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos b\right) \]
      4. cos-lowering-cos.f6454.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(b\right)\right) \]
    5. Simplified54.7%

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

        \[\leadsto r \cdot \color{blue}{\frac{\sin b}{\cos b}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\sin b}{\cos b} \cdot \color{blue}{r} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\sin b}{\cos b}\right), \color{blue}{r}\right) \]
      4. quot-tanN/A

        \[\leadsto \mathsf{*.f64}\left(\tan b, r\right) \]
      5. tan-lowering-tan.f6454.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{tan.f64}\left(b\right), r\right) \]
    7. Applied egg-rr54.8%

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

    if -5.8999999999999998e-5 < b < 8.60000000000000067e-6

    1. Initial program 99.0%

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

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\color{blue}{b}, \mathsf{cos.f64}\left(\mathsf{+.f64}\left(a, b\right)\right)\right)\right) \]
    4. Step-by-step derivation
      1. Simplified98.7%

        \[\leadsto r \cdot \frac{\color{blue}{b}}{\cos \left(a + b\right)} \]
    5. Recombined 2 regimes into one program.
    6. Final simplification76.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.9 \cdot 10^{-5}:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{elif}\;b \leq 8.6 \cdot 10^{-6}:\\ \;\;\;\;r \cdot \frac{b}{\cos \left(b + a\right)}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \tan b\\ \end{array} \]
    7. Add Preprocessing

    Alternative 12: 76.6% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := r \cdot \tan b\\ \mathbf{if}\;b \leq -5.8 \cdot 10^{-5}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;b \leq 5.3 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (r a b)
     :precision binary64
     (let* ((t_0 (* r (tan b))))
       (if (<= b -5.8e-5) t_0 (if (<= b 5.3e-6) (* b (/ r (cos a))) t_0))))
    double code(double r, double a, double b) {
    	double t_0 = r * tan(b);
    	double tmp;
    	if (b <= -5.8e-5) {
    		tmp = t_0;
    	} else if (b <= 5.3e-6) {
    		tmp = b * (r / cos(a));
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    real(8) function code(r, a, b)
        real(8), intent (in) :: r
        real(8), intent (in) :: a
        real(8), intent (in) :: b
        real(8) :: t_0
        real(8) :: tmp
        t_0 = r * tan(b)
        if (b <= (-5.8d-5)) then
            tmp = t_0
        else if (b <= 5.3d-6) then
            tmp = b * (r / cos(a))
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    public static double code(double r, double a, double b) {
    	double t_0 = r * Math.tan(b);
    	double tmp;
    	if (b <= -5.8e-5) {
    		tmp = t_0;
    	} else if (b <= 5.3e-6) {
    		tmp = b * (r / Math.cos(a));
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(r, a, b):
    	t_0 = r * math.tan(b)
    	tmp = 0
    	if b <= -5.8e-5:
    		tmp = t_0
    	elif b <= 5.3e-6:
    		tmp = b * (r / math.cos(a))
    	else:
    		tmp = t_0
    	return tmp
    
    function code(r, a, b)
    	t_0 = Float64(r * tan(b))
    	tmp = 0.0
    	if (b <= -5.8e-5)
    		tmp = t_0;
    	elseif (b <= 5.3e-6)
    		tmp = Float64(b * Float64(r / cos(a)));
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(r, a, b)
    	t_0 = r * tan(b);
    	tmp = 0.0;
    	if (b <= -5.8e-5)
    		tmp = t_0;
    	elseif (b <= 5.3e-6)
    		tmp = b * (r / cos(a));
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5.8e-5], t$95$0, If[LessEqual[b, 5.3e-6], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := r \cdot \tan b\\
    \mathbf{if}\;b \leq -5.8 \cdot 10^{-5}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;b \leq 5.3 \cdot 10^{-6}:\\
    \;\;\;\;b \cdot \frac{r}{\cos a}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if b < -5.8e-5 or 5.3000000000000001e-6 < b

      1. Initial program 55.5%

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

        \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
      4. Step-by-step derivation
        1. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos b}\right) \]
        2. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{b}\right) \]
        3. sin-lowering-sin.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos b\right) \]
        4. cos-lowering-cos.f6454.7%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(b\right)\right) \]
      5. Simplified54.7%

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

          \[\leadsto r \cdot \color{blue}{\frac{\sin b}{\cos b}} \]
        2. *-commutativeN/A

          \[\leadsto \frac{\sin b}{\cos b} \cdot \color{blue}{r} \]
        3. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\left(\frac{\sin b}{\cos b}\right), \color{blue}{r}\right) \]
        4. quot-tanN/A

          \[\leadsto \mathsf{*.f64}\left(\tan b, r\right) \]
        5. tan-lowering-tan.f6454.8%

          \[\leadsto \mathsf{*.f64}\left(\mathsf{tan.f64}\left(b\right), r\right) \]
      7. Applied egg-rr54.8%

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

      if -5.8e-5 < b < 5.3000000000000001e-6

      1. Initial program 99.0%

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

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

          \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos \left(a + b\right)}\right) \]
        3. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{\left(a + b\right)}\right) \]
        4. sin-lowering-sin.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos \left(a + \color{blue}{b}\right)\right) \]
        5. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\left(a + b\right)\right)\right) \]
        6. +-commutativeN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\left(b + a\right)\right)\right) \]
        7. +-lowering-+.f6498.9%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(\mathsf{+.f64}\left(b, a\right)\right)\right) \]
      3. Simplified98.9%

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

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\cos b \cdot \cos a - \color{blue}{\sin b \cdot \sin a}\right)\right) \]
        2. fmm-defN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\mathsf{fma}\left(\cos b, \color{blue}{\cos a}, \mathsf{neg}\left(\sin b \cdot \sin a\right)\right)\right)\right) \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \left(\mathsf{fma}\left(\cos b, \cos a, \mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right) \]
        4. fma-lowering-fma.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\cos b, \color{blue}{\cos a}, \left(\mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right) \]
        5. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \cos \color{blue}{a}, \left(\mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right) \]
        6. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\mathsf{neg}\left(\sin a \cdot \sin b\right)\right)\right)\right) \]
        7. *-commutativeN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\mathsf{neg}\left(\sin b \cdot \sin a\right)\right)\right)\right) \]
        8. distribute-rgt-neg-inN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \left(\sin b \cdot \left(\mathsf{neg}\left(\sin a\right)\right)\right)\right)\right) \]
        9. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\sin b, \left(\mathsf{neg}\left(\sin a\right)\right)\right)\right)\right) \]
        10. sin-lowering-sin.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \left(\mathsf{neg}\left(\sin a\right)\right)\right)\right)\right) \]
        11. neg-sub0N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \left(0 - \sin a\right)\right)\right)\right) \]
        12. --lowering--.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(0, \sin a\right)\right)\right)\right) \]
        13. sin-lowering-sin.f6499.8%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{fma.f64}\left(\mathsf{cos.f64}\left(b\right), \mathsf{cos.f64}\left(a\right), \mathsf{*.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{\_.f64}\left(0, \mathsf{sin.f64}\left(a\right)\right)\right)\right)\right) \]
      6. Applied egg-rr99.8%

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

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

          \[\leadsto b \cdot \color{blue}{\frac{r}{\cos a}} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(b, \color{blue}{\left(\frac{r}{\cos a}\right)}\right) \]
        3. /-lowering-/.f64N/A

          \[\leadsto \mathsf{*.f64}\left(b, \mathsf{/.f64}\left(r, \color{blue}{\cos a}\right)\right) \]
        4. cos-lowering-cos.f6498.6%

          \[\leadsto \mathsf{*.f64}\left(b, \mathsf{/.f64}\left(r, \mathsf{cos.f64}\left(a\right)\right)\right) \]
      9. Simplified98.6%

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

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

    Alternative 13: 61.2% 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.4%

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

      \[\leadsto \color{blue}{\frac{r \cdot \sin b}{\cos b}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(r \cdot \sin b\right), \color{blue}{\cos b}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \sin b\right), \cos \color{blue}{b}\right) \]
      3. sin-lowering-sin.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \cos b\right) \]
      4. cos-lowering-cos.f6460.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right), \mathsf{cos.f64}\left(b\right)\right) \]
    5. Simplified60.9%

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

        \[\leadsto r \cdot \color{blue}{\frac{\sin b}{\cos b}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\sin b}{\cos b} \cdot \color{blue}{r} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\sin b}{\cos b}\right), \color{blue}{r}\right) \]
      4. quot-tanN/A

        \[\leadsto \mathsf{*.f64}\left(\tan b, r\right) \]
      5. tan-lowering-tan.f6460.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{tan.f64}\left(b\right), r\right) \]
    7. Applied egg-rr60.9%

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \color{blue}{\cos a}\right)\right) \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6455.7%

        \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(\mathsf{sin.f64}\left(b\right), \mathsf{cos.f64}\left(a\right)\right)\right) \]
    5. Simplified55.7%

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

      \[\leadsto \color{blue}{r \cdot \sin b} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(r, \color{blue}{\sin b}\right) \]
      2. sin-lowering-sin.f6439.5%

        \[\leadsto \mathsf{*.f64}\left(r, \mathsf{sin.f64}\left(b\right)\right) \]
    8. Simplified39.5%

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

    Alternative 15: 35.6% accurate, 69.0× speedup?

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

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

      \[\leadsto \mathsf{*.f64}\left(r, \color{blue}{\left(\frac{b}{\cos a}\right)}\right) \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(b, \color{blue}{\cos a}\right)\right) \]
      2. cos-lowering-cos.f6452.3%

        \[\leadsto \mathsf{*.f64}\left(r, \mathsf{/.f64}\left(b, \mathsf{cos.f64}\left(a\right)\right)\right) \]
    5. Simplified52.3%

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

      \[\leadsto \color{blue}{b \cdot r} \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto r \cdot \color{blue}{b} \]
      2. *-lowering-*.f6436.3%

        \[\leadsto \mathsf{*.f64}\left(r, \color{blue}{b}\right) \]
    8. Simplified36.3%

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

    Reproduce

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