rsin B (should all be same)

Percentage Accurate: 76.1% → 99.5%
Time: 11.9s
Alternatives: 9
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 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 76.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 0.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 73.4%

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

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

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

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos a \cdot \cos b} - \sin a \cdot \sin b} \]
    4. lower-cos.f64N/A

      \[\leadsto r \cdot \frac{\sin b}{\color{blue}{\cos a} \cdot \cos b - \sin a \cdot \sin b} \]
    5. lower-cos.f64N/A

      \[\leadsto r \cdot \frac{\sin b}{\cos a \cdot \color{blue}{\cos b} - \sin a \cdot \sin b} \]
    6. lift-sin.f64N/A

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

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

      \[\leadsto r \cdot \frac{\sin b}{\cos a \cdot \cos b - \color{blue}{\sin b \cdot \sin a}} \]
    9. lower-sin.f6499.5

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

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

Alternative 2: 75.6% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(b + a\right)\\
t_1 := \frac{\sin b}{t\_0}\\
t_2 := r \cdot \tan b\\
\mathbf{if}\;t\_1 \leq -0.02:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 10^{-12}:\\
\;\;\;\;\frac{r \cdot b}{t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -0.0200000000000000004 or 9.9999999999999998e-13 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b)))

    1. Initial program 52.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos \color{blue}{\left(b + a\right)}}}{\frac{1}{\sin b}} \]
      12. lower-/.f6452.2

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

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

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

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    7. Applied rewrites52.5%

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

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
      2. lift-/.f64N/A

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{1}{\color{blue}{\sin b}}} \]
      4. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\sin b\right)}}} \]
      5. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{-1}}{\mathsf{neg}\left(\sin b\right)}} \]
      6. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      7. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      8. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      9. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      10. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\sin \left(\mathsf{neg}\left(b\right)\right)}} \]
      11. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      12. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      13. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\sin b\right)}}} \]
      14. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      15. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      16. lift-/.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      17. lift-/.f64N/A

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

        \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
      19. lower-*.f6452.5

        \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
    9. Applied rewrites52.6%

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

    if -0.0200000000000000004 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 9.9999999999999998e-13

    1. Initial program 98.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{r \cdot \sin b}{\cos \color{blue}{\left(b + a\right)}} \]
      9. lower-+.f6498.4

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

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

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

        \[\leadsto \frac{\color{blue}{b \cdot r}}{\cos \left(b + a\right)} \]
    7. Applied rewrites98.4%

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

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

Alternative 3: 75.6% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\sin b}{\cos \left(b + a\right)}\\
t_1 := r \cdot \tan b\\
\mathbf{if}\;t\_0 \leq -0.02:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 10^{-12}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -0.0200000000000000004 or 9.9999999999999998e-13 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b)))

    1. Initial program 52.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos \color{blue}{\left(b + a\right)}}}{\frac{1}{\sin b}} \]
      12. lower-/.f6452.2

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

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

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

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    7. Applied rewrites52.5%

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

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
      2. lift-/.f64N/A

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{1}{\color{blue}{\sin b}}} \]
      4. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\sin b\right)}}} \]
      5. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{-1}}{\mathsf{neg}\left(\sin b\right)}} \]
      6. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      7. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      8. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      9. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      10. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\sin \left(\mathsf{neg}\left(b\right)\right)}} \]
      11. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      12. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      13. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\sin b\right)}}} \]
      14. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      15. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      16. lift-/.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      17. lift-/.f64N/A

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

        \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
      19. lower-*.f6452.5

        \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
    9. Applied rewrites52.6%

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

    if -0.0200000000000000004 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 9.9999999999999998e-13

    1. Initial program 98.4%

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

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

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

        \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
      3. lower-/.f64N/A

        \[\leadsto b \cdot \color{blue}{\frac{r}{\cos a}} \]
      4. lower-cos.f6498.3

        \[\leadsto b \cdot \frac{r}{\color{blue}{\cos a}} \]
    5. Applied rewrites98.3%

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

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

Alternative 4: 76.1% accurate, 1.0× speedup?

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

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

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

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

Alternative 5: 75.9% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.0045:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{elif}\;b \leq 0.0046:\\ \;\;\;\;\frac{b \cdot \mathsf{fma}\left(-0.16666666666666666, r \cdot \left(b \cdot b\right), r\right)}{\cos \left(b + a\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{1}{\tan b}}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= b -0.0045)
   (* r (tan b))
   (if (<= b 0.0046)
     (/ (* b (fma -0.16666666666666666 (* r (* b b)) r)) (cos (+ b a)))
     (/ r (/ 1.0 (tan b))))))
double code(double r, double a, double b) {
	double tmp;
	if (b <= -0.0045) {
		tmp = r * tan(b);
	} else if (b <= 0.0046) {
		tmp = (b * fma(-0.16666666666666666, (r * (b * b)), r)) / cos((b + a));
	} else {
		tmp = r / (1.0 / tan(b));
	}
	return tmp;
}
function code(r, a, b)
	tmp = 0.0
	if (b <= -0.0045)
		tmp = Float64(r * tan(b));
	elseif (b <= 0.0046)
		tmp = Float64(Float64(b * fma(-0.16666666666666666, Float64(r * Float64(b * b)), r)) / cos(Float64(b + a)));
	else
		tmp = Float64(r / Float64(1.0 / tan(b)));
	end
	return tmp
end
code[r_, a_, b_] := If[LessEqual[b, -0.0045], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 0.0046], N[(N[(b * N[(-0.16666666666666666 * N[(r * N[(b * b), $MachinePrecision]), $MachinePrecision] + r), $MachinePrecision]), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(r / N[(1.0 / N[Tan[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0045:\\
\;\;\;\;r \cdot \tan b\\

\mathbf{elif}\;b \leq 0.0046:\\
\;\;\;\;\frac{b \cdot \mathsf{fma}\left(-0.16666666666666666, r \cdot \left(b \cdot b\right), r\right)}{\cos \left(b + a\right)}\\

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


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

    1. Initial program 54.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos \color{blue}{\left(b + a\right)}}}{\frac{1}{\sin b}} \]
      12. lower-/.f6454.0

        \[\leadsto r \cdot \frac{\frac{1}{\cos \left(b + a\right)}}{\color{blue}{\frac{1}{\sin b}}} \]
    4. Applied rewrites54.0%

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

      \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    6. Step-by-step derivation
      1. lower-cos.f6455.2

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    7. Applied rewrites55.2%

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

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
      2. lift-/.f64N/A

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{1}{\color{blue}{\sin b}}} \]
      4. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\sin b\right)}}} \]
      5. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{-1}}{\mathsf{neg}\left(\sin b\right)}} \]
      6. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      7. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      8. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      9. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      10. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\sin \left(\mathsf{neg}\left(b\right)\right)}} \]
      11. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      12. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      13. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\sin b\right)}}} \]
      14. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      15. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      16. lift-/.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      17. lift-/.f64N/A

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

        \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
      19. lower-*.f6455.2

        \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
    9. Applied rewrites55.4%

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

    if -0.00449999999999999966 < b < 0.0045999999999999999

    1. Initial program 98.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{r \cdot \sin b}{\cos \color{blue}{\left(b + a\right)}} \]
      9. lower-+.f6498.4

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{b \cdot \left(r + {b}^{2} \cdot \left(\frac{-1}{6} \cdot r\right)\right)}}{\cos \left(b + a\right)} \]
      5. +-commutativeN/A

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

        \[\leadsto \frac{b \cdot \left({b}^{2} \cdot \color{blue}{\left(r \cdot \frac{-1}{6}\right)} + r\right)}{\cos \left(b + a\right)} \]
      7. associate-*r*N/A

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

        \[\leadsto \frac{b \cdot \left(\color{blue}{\frac{-1}{6} \cdot \left({b}^{2} \cdot r\right)} + r\right)}{\cos \left(b + a\right)} \]
      9. lower-fma.f64N/A

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

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

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

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

        \[\leadsto \frac{b \cdot \mathsf{fma}\left(-0.16666666666666666, r \cdot \color{blue}{\left(b \cdot b\right)}, r\right)}{\cos \left(b + a\right)} \]
    7. Applied rewrites98.4%

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

    if 0.0045999999999999999 < b

    1. Initial program 48.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos \color{blue}{\left(b + a\right)}}}{\frac{1}{\sin b}} \]
      12. lower-/.f6448.0

        \[\leadsto r \cdot \frac{\frac{1}{\cos \left(b + a\right)}}{\color{blue}{\frac{1}{\sin b}}} \]
    4. Applied rewrites48.0%

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

      \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    6. Step-by-step derivation
      1. lower-cos.f6447.4

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    7. Applied rewrites47.4%

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

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
      2. lift-/.f64N/A

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{1}{\color{blue}{\sin b}}} \]
      4. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\sin b\right)}}} \]
      5. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{-1}}{\mathsf{neg}\left(\sin b\right)}} \]
      6. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      7. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      8. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      9. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      10. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\sin \left(\mathsf{neg}\left(b\right)\right)}} \]
      11. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      12. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      13. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\sin b\right)}}} \]
      14. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      15. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      16. lift-/.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      17. lift-/.f64N/A

        \[\leadsto r \cdot \frac{\color{blue}{\frac{1}{\cos b}}}{\frac{1}{\sin b}} \]
      18. associate-/l/N/A

        \[\leadsto r \cdot \color{blue}{\frac{1}{\frac{1}{\sin b} \cdot \cos b}} \]
    9. Applied rewrites47.6%

      \[\leadsto \color{blue}{\frac{r}{\frac{1}{\tan b}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification73.6%

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

Alternative 6: 75.9% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.0045:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{elif}\;b \leq 0.0046:\\ \;\;\;\;r \cdot \frac{\mathsf{fma}\left(b, b \cdot \left(b \cdot -0.16666666666666666\right), b\right)}{\cos \left(b + a\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{1}{\tan b}}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (<= b -0.0045)
   (* r (tan b))
   (if (<= b 0.0046)
     (* r (/ (fma b (* b (* b -0.16666666666666666)) b) (cos (+ b a))))
     (/ r (/ 1.0 (tan b))))))
double code(double r, double a, double b) {
	double tmp;
	if (b <= -0.0045) {
		tmp = r * tan(b);
	} else if (b <= 0.0046) {
		tmp = r * (fma(b, (b * (b * -0.16666666666666666)), b) / cos((b + a)));
	} else {
		tmp = r / (1.0 / tan(b));
	}
	return tmp;
}
function code(r, a, b)
	tmp = 0.0
	if (b <= -0.0045)
		tmp = Float64(r * tan(b));
	elseif (b <= 0.0046)
		tmp = Float64(r * Float64(fma(b, Float64(b * Float64(b * -0.16666666666666666)), b) / cos(Float64(b + a))));
	else
		tmp = Float64(r / Float64(1.0 / tan(b)));
	end
	return tmp
end
code[r_, a_, b_] := If[LessEqual[b, -0.0045], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 0.0046], N[(r * N[(N[(b * N[(b * N[(b * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r / N[(1.0 / N[Tan[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0045:\\
\;\;\;\;r \cdot \tan b\\

\mathbf{elif}\;b \leq 0.0046:\\
\;\;\;\;r \cdot \frac{\mathsf{fma}\left(b, b \cdot \left(b \cdot -0.16666666666666666\right), b\right)}{\cos \left(b + a\right)}\\

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


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

    1. Initial program 54.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos \color{blue}{\left(b + a\right)}}}{\frac{1}{\sin b}} \]
      12. lower-/.f6454.0

        \[\leadsto r \cdot \frac{\frac{1}{\cos \left(b + a\right)}}{\color{blue}{\frac{1}{\sin b}}} \]
    4. Applied rewrites54.0%

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

      \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    6. Step-by-step derivation
      1. lower-cos.f6455.2

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    7. Applied rewrites55.2%

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

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
      2. lift-/.f64N/A

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{1}{\color{blue}{\sin b}}} \]
      4. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\sin b\right)}}} \]
      5. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{-1}}{\mathsf{neg}\left(\sin b\right)}} \]
      6. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      7. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      8. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      9. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      10. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\sin \left(\mathsf{neg}\left(b\right)\right)}} \]
      11. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      12. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      13. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\sin b\right)}}} \]
      14. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      15. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      16. lift-/.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      17. lift-/.f64N/A

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

        \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
      19. lower-*.f6455.2

        \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
    9. Applied rewrites55.4%

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

    if -0.00449999999999999966 < b < 0.0045999999999999999

    1. Initial program 98.4%

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

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

        \[\leadsto r \cdot \frac{b \cdot \color{blue}{\left(\frac{-1}{6} \cdot {b}^{2} + 1\right)}}{\cos \left(a + b\right)} \]
      2. distribute-lft-inN/A

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

        \[\leadsto r \cdot \frac{b \cdot \left(\frac{-1}{6} \cdot {b}^{2}\right) + \color{blue}{b}}{\cos \left(a + b\right)} \]
      4. lower-fma.f64N/A

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

        \[\leadsto r \cdot \frac{\mathsf{fma}\left(b, \frac{-1}{6} \cdot \color{blue}{\left(b \cdot b\right)}, b\right)}{\cos \left(a + b\right)} \]
      6. associate-*r*N/A

        \[\leadsto r \cdot \frac{\mathsf{fma}\left(b, \color{blue}{\left(\frac{-1}{6} \cdot b\right) \cdot b}, b\right)}{\cos \left(a + b\right)} \]
      7. *-commutativeN/A

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

        \[\leadsto r \cdot \frac{\mathsf{fma}\left(b, \color{blue}{b \cdot \left(\frac{-1}{6} \cdot b\right)}, b\right)}{\cos \left(a + b\right)} \]
      9. *-commutativeN/A

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

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

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

    if 0.0045999999999999999 < b

    1. Initial program 48.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos \color{blue}{\left(b + a\right)}}}{\frac{1}{\sin b}} \]
      12. lower-/.f6448.0

        \[\leadsto r \cdot \frac{\frac{1}{\cos \left(b + a\right)}}{\color{blue}{\frac{1}{\sin b}}} \]
    4. Applied rewrites48.0%

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

      \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    6. Step-by-step derivation
      1. lower-cos.f6447.4

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    7. Applied rewrites47.4%

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

        \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
      2. lift-/.f64N/A

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

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{1}{\color{blue}{\sin b}}} \]
      4. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\sin b\right)}}} \]
      5. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{-1}}{\mathsf{neg}\left(\sin b\right)}} \]
      6. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      7. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      8. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      9. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      10. metadata-evalN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\sin \left(\mathsf{neg}\left(b\right)\right)}} \]
      11. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
      12. lift-neg.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
      13. sin-negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\sin b\right)}}} \]
      14. lift-sin.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
      15. frac-2negN/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      16. lift-/.f64N/A

        \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
      17. lift-/.f64N/A

        \[\leadsto r \cdot \frac{\color{blue}{\frac{1}{\cos b}}}{\frac{1}{\sin b}} \]
      18. associate-/l/N/A

        \[\leadsto r \cdot \color{blue}{\frac{1}{\frac{1}{\sin b} \cdot \cos b}} \]
    9. Applied rewrites47.6%

      \[\leadsto \color{blue}{\frac{r}{\frac{1}{\tan b}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification73.6%

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

Alternative 7: 59.9% accurate, 2.1× 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 73.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto r \cdot \frac{\frac{1}{\cos \color{blue}{\left(b + a\right)}}}{\frac{1}{\sin b}} \]
    12. lower-/.f6473.3

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

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

    \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
  6. Step-by-step derivation
    1. lower-cos.f6460.3

      \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
  7. Applied rewrites60.3%

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

      \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos b}}}{\frac{1}{\sin b}} \]
    2. lift-/.f64N/A

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

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{1}{\color{blue}{\sin b}}} \]
    4. frac-2negN/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\sin b\right)}}} \]
    5. metadata-evalN/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{-1}}{\mathsf{neg}\left(\sin b\right)}} \]
    6. lift-sin.f64N/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
    7. sin-negN/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
    8. lift-neg.f64N/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
    9. lift-sin.f64N/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{-1}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
    10. metadata-evalN/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\color{blue}{\mathsf{neg}\left(1\right)}}{\sin \left(\mathsf{neg}\left(b\right)\right)}} \]
    11. lift-sin.f64N/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\sin \left(\mathsf{neg}\left(b\right)\right)}}} \]
    12. lift-neg.f64N/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\sin \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}}} \]
    13. sin-negN/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\sin b\right)}}} \]
    14. lift-sin.f64N/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\color{blue}{\sin b}\right)}} \]
    15. frac-2negN/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
    16. lift-/.f64N/A

      \[\leadsto r \cdot \frac{\frac{1}{\cos b}}{\color{blue}{\frac{1}{\sin b}}} \]
    17. lift-/.f64N/A

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

      \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
    19. lower-*.f6460.3

      \[\leadsto \color{blue}{\frac{\frac{1}{\cos b}}{\frac{1}{\sin b}} \cdot r} \]
  9. Applied rewrites60.4%

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

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

Alternative 8: 37.5% accurate, 2.1× 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 73.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto r \cdot \frac{\frac{1}{\cos \color{blue}{\left(b + a\right)}}}{\frac{1}{\sin b}} \]
    12. lower-/.f6473.3

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

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

    \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos a}}}{\frac{1}{\sin b}} \]
  6. Step-by-step derivation
    1. lower-cos.f6451.8

      \[\leadsto r \cdot \frac{\frac{1}{\color{blue}{\cos a}}}{\frac{1}{\sin b}} \]
  7. Applied rewrites51.8%

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

    \[\leadsto r \cdot \color{blue}{\sin b} \]
  9. Step-by-step derivation
    1. lower-sin.f6439.0

      \[\leadsto r \cdot \color{blue}{\sin b} \]
  10. Applied rewrites39.0%

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

Alternative 9: 33.3% accurate, 36.7× 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 73.4%

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

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

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

      \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
    3. lower-/.f64N/A

      \[\leadsto b \cdot \color{blue}{\frac{r}{\cos a}} \]
    4. lower-cos.f6448.2

      \[\leadsto b \cdot \frac{r}{\color{blue}{\cos a}} \]
  5. Applied rewrites48.2%

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

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

      \[\leadsto \color{blue}{b \cdot r} \]
  8. Applied rewrites35.1%

    \[\leadsto \color{blue}{b \cdot r} \]
  9. Final simplification35.1%

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

Reproduce

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