rsin B (should all be same)

Percentage Accurate: 75.9% → 99.5%
Time: 8.7s
Alternatives: 10
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 10 alternatives:

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

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

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

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

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

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

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

      \[\leadsto r \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin a \cdot \color{blue}{\sin b}} \]
    5. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

      \[\leadsto r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{\left(-\sin a\right)} \cdot \sin b\right)} \]
    12. lower-sin.f6499.4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin b \cdot r}{\mathsf{fma}\left(-\sin a, \sin b, \color{blue}{\cos b} \cdot \cos a\right)} \]
    14. lower-cos.f6499.4

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

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

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

    Alternative 2: 75.6% accurate, 0.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sin b}{\cos \left(a + b\right)}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-6} \lor \neg \left(t\_0 \leq 2 \cdot 10^{-8}\right):\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\cos a} \cdot b\\ \end{array} \end{array} \]
    (FPCore (r a b)
     :precision binary64
     (let* ((t_0 (/ (sin b) (cos (+ a b)))))
       (if (or (<= t_0 -2e-6) (not (<= t_0 2e-8)))
         (* (sin b) (/ r (cos b)))
         (* (/ r (cos a)) b))))
    double code(double r, double a, double b) {
    	double t_0 = sin(b) / cos((a + b));
    	double tmp;
    	if ((t_0 <= -2e-6) || !(t_0 <= 2e-8)) {
    		tmp = sin(b) * (r / cos(b));
    	} else {
    		tmp = (r / cos(a)) * 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) :: t_0
        real(8) :: tmp
        t_0 = sin(b) / cos((a + b))
        if ((t_0 <= (-2d-6)) .or. (.not. (t_0 <= 2d-8))) then
            tmp = sin(b) * (r / cos(b))
        else
            tmp = (r / cos(a)) * b
        end if
        code = tmp
    end function
    
    public static double code(double r, double a, double b) {
    	double t_0 = Math.sin(b) / Math.cos((a + b));
    	double tmp;
    	if ((t_0 <= -2e-6) || !(t_0 <= 2e-8)) {
    		tmp = Math.sin(b) * (r / Math.cos(b));
    	} else {
    		tmp = (r / Math.cos(a)) * b;
    	}
    	return tmp;
    }
    
    def code(r, a, b):
    	t_0 = math.sin(b) / math.cos((a + b))
    	tmp = 0
    	if (t_0 <= -2e-6) or not (t_0 <= 2e-8):
    		tmp = math.sin(b) * (r / math.cos(b))
    	else:
    		tmp = (r / math.cos(a)) * b
    	return tmp
    
    function code(r, a, b)
    	t_0 = Float64(sin(b) / cos(Float64(a + b)))
    	tmp = 0.0
    	if ((t_0 <= -2e-6) || !(t_0 <= 2e-8))
    		tmp = Float64(sin(b) * Float64(r / cos(b)));
    	else
    		tmp = Float64(Float64(r / cos(a)) * b);
    	end
    	return tmp
    end
    
    function tmp_2 = code(r, a, b)
    	t_0 = sin(b) / cos((a + b));
    	tmp = 0.0;
    	if ((t_0 <= -2e-6) || ~((t_0 <= 2e-8)))
    		tmp = sin(b) * (r / cos(b));
    	else
    		tmp = (r / cos(a)) * b;
    	end
    	tmp_2 = tmp;
    end
    
    code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e-6], N[Not[LessEqual[t$95$0, 2e-8]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \frac{\sin b}{\cos \left(a + b\right)}\\
    \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-6} \lor \neg \left(t\_0 \leq 2 \cdot 10^{-8}\right):\\
    \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{r}{\cos a} \cdot b\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -1.99999999999999991e-6 or 2e-8 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b)))

      1. Initial program 59.3%

        \[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. *-commutativeN/A

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

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

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

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

          \[\leadsto \sin b \cdot \color{blue}{\frac{r}{\cos b}} \]
        6. lower-cos.f6458.6

          \[\leadsto \sin b \cdot \frac{r}{\color{blue}{\cos b}} \]
      5. Applied rewrites58.6%

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

      if -1.99999999999999991e-6 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 2e-8

      1. Initial program 99.5%

        \[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. *-commutativeN/A

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

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

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

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

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

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

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

    Alternative 3: 75.5% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -3.05 \cdot 10^{-5} \lor \neg \left(a \leq 6.8 \cdot 10^{-6}\right):\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \end{array} \end{array} \]
    (FPCore (r a b)
     :precision binary64
     (if (or (<= a -3.05e-5) (not (<= a 6.8e-6)))
       (* r (/ (sin b) (cos a)))
       (* (sin b) (/ r (cos b)))))
    double code(double r, double a, double b) {
    	double tmp;
    	if ((a <= -3.05e-5) || !(a <= 6.8e-6)) {
    		tmp = r * (sin(b) / cos(a));
    	} else {
    		tmp = sin(b) * (r / cos(b));
    	}
    	return tmp;
    }
    
    real(8) function code(r, a, b)
        real(8), intent (in) :: r
        real(8), intent (in) :: a
        real(8), intent (in) :: b
        real(8) :: tmp
        if ((a <= (-3.05d-5)) .or. (.not. (a <= 6.8d-6))) then
            tmp = r * (sin(b) / cos(a))
        else
            tmp = sin(b) * (r / cos(b))
        end if
        code = tmp
    end function
    
    public static double code(double r, double a, double b) {
    	double tmp;
    	if ((a <= -3.05e-5) || !(a <= 6.8e-6)) {
    		tmp = r * (Math.sin(b) / Math.cos(a));
    	} else {
    		tmp = Math.sin(b) * (r / Math.cos(b));
    	}
    	return tmp;
    }
    
    def code(r, a, b):
    	tmp = 0
    	if (a <= -3.05e-5) or not (a <= 6.8e-6):
    		tmp = r * (math.sin(b) / math.cos(a))
    	else:
    		tmp = math.sin(b) * (r / math.cos(b))
    	return tmp
    
    function code(r, a, b)
    	tmp = 0.0
    	if ((a <= -3.05e-5) || !(a <= 6.8e-6))
    		tmp = Float64(r * Float64(sin(b) / cos(a)));
    	else
    		tmp = Float64(sin(b) * Float64(r / cos(b)));
    	end
    	return tmp
    end
    
    function tmp_2 = code(r, a, b)
    	tmp = 0.0;
    	if ((a <= -3.05e-5) || ~((a <= 6.8e-6)))
    		tmp = r * (sin(b) / cos(a));
    	else
    		tmp = sin(b) * (r / cos(b));
    	end
    	tmp_2 = tmp;
    end
    
    code[r_, a_, b_] := If[Or[LessEqual[a, -3.05e-5], N[Not[LessEqual[a, 6.8e-6]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;a \leq -3.05 \cdot 10^{-5} \lor \neg \left(a \leq 6.8 \cdot 10^{-6}\right):\\
    \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if a < -3.04999999999999994e-5 or 6.80000000000000012e-6 < a

      1. Initial program 53.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{\sin b}{\color{blue}{\cos a}} \]
      4. Step-by-step derivation
        1. lower-cos.f6452.9

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

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

      if -3.04999999999999994e-5 < a < 6.80000000000000012e-6

      1. Initial program 97.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. *-commutativeN/A

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

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

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

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

          \[\leadsto \sin b \cdot \color{blue}{\frac{r}{\cos b}} \]
        6. lower-cos.f6497.6

          \[\leadsto \sin b \cdot \frac{r}{\color{blue}{\cos b}} \]
      5. Applied rewrites97.6%

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

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

    Alternative 4: 75.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

    Alternative 5: 75.9% 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}
    
    Derivation
    1. Initial program 77.3%

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

    Alternative 6: 54.9% accurate, 1.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -2050000000000 \lor \neg \left(b \leq 4.9\right):\\ \;\;\;\;r \cdot \frac{\sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, b, 0\right), b, 1\right), b, 0\right)}{\cos \left(a + b\right)}\\ \end{array} \end{array} \]
    (FPCore (r a b)
     :precision binary64
     (if (or (<= b -2050000000000.0) (not (<= b 4.9)))
       (* r (/ (sin b) 1.0))
       (*
        r
        (/
         (fma (fma (fma -0.16666666666666666 b 0.0) b 1.0) b 0.0)
         (cos (+ a b))))))
    double code(double r, double a, double b) {
    	double tmp;
    	if ((b <= -2050000000000.0) || !(b <= 4.9)) {
    		tmp = r * (sin(b) / 1.0);
    	} else {
    		tmp = r * (fma(fma(fma(-0.16666666666666666, b, 0.0), b, 1.0), b, 0.0) / cos((a + b)));
    	}
    	return tmp;
    }
    
    function code(r, a, b)
    	tmp = 0.0
    	if ((b <= -2050000000000.0) || !(b <= 4.9))
    		tmp = Float64(r * Float64(sin(b) / 1.0));
    	else
    		tmp = Float64(r * Float64(fma(fma(fma(-0.16666666666666666, b, 0.0), b, 1.0), b, 0.0) / cos(Float64(a + b))));
    	end
    	return tmp
    end
    
    code[r_, a_, b_] := If[Or[LessEqual[b, -2050000000000.0], N[Not[LessEqual[b, 4.9]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / 1.0), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[(N[(N[(-0.16666666666666666 * b + 0.0), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 0.0), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;b \leq -2050000000000 \lor \neg \left(b \leq 4.9\right):\\
    \;\;\;\;r \cdot \frac{\sin b}{1}\\
    
    \mathbf{else}:\\
    \;\;\;\;r \cdot \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, b, 0\right), b, 1\right), b, 0\right)}{\cos \left(a + b\right)}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if b < -2.05e12 or 4.9000000000000004 < b

      1. Initial program 58.0%

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

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

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

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

          \[\leadsto r \cdot \frac{\sin b}{\left(\mathsf{neg}\left(\color{blue}{\sin a \cdot b}\right)\right) + \cos a} \]
        4. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

          \[\leadsto r \cdot \frac{\sin b}{1} \]
        3. Step-by-step derivation
          1. Applied rewrites12.1%

            \[\leadsto r \cdot \frac{\sin b}{1} \]

          if -2.05e12 < b < 4.9000000000000004

          1. Initial program 97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto r \cdot \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, b, 0\right), b, 1\right), b, 0\right)}}{\cos \left(a + b\right)} \]
        4. Recombined 2 regimes into one program.
        5. Final simplification52.8%

          \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2050000000000 \lor \neg \left(b \leq 4.9\right):\\ \;\;\;\;r \cdot \frac{\sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, b, 0\right), b, 1\right), b, 0\right)}{\cos \left(a + b\right)}\\ \end{array} \]
        6. Add Preprocessing

        Alternative 7: 54.7% accurate, 1.7× speedup?

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

          1. Initial program 57.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{\sin b}{\color{blue}{\cos a + -1 \cdot \left(b \cdot \sin a\right)}} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

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

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

              \[\leadsto r \cdot \frac{\sin b}{\left(\mathsf{neg}\left(\color{blue}{\sin a \cdot b}\right)\right) + \cos a} \]
            4. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

              \[\leadsto r \cdot \frac{\sin b}{1} \]
            3. Step-by-step derivation
              1. Applied rewrites12.2%

                \[\leadsto r \cdot \frac{\sin b}{1} \]

              if -0.00640000000000000031 < b < 1.65e15

              1. Initial program 98.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto r \cdot \frac{\sin \left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) + \left(b \cdot -1\right) \cdot \color{blue}{\cos \mathsf{PI}\left(\right)}}{\cos \left(a + b\right)} \]
                4. cos-PIN/A

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

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

                  \[\leadsto r \cdot \frac{\sin \left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) + b \cdot \color{blue}{1}}{\cos \left(a + b\right)} \]
                7. *-rgt-identityN/A

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

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

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

                  \[\leadsto r \cdot \frac{\left(\mathsf{neg}\left(\color{blue}{0}\right)\right) + b}{\cos \left(a + b\right)} \]
                11. metadata-eval94.5

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

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -0.0064 \lor \neg \left(b \leq 1.65 \cdot 10^{+15}\right):\\ \;\;\;\;r \cdot \frac{\sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos \left(a + b\right)}\\ \end{array} \]
            6. Add Preprocessing

            Alternative 8: 54.6% accurate, 1.7× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.05 \cdot 10^{+14} \lor \neg \left(b \leq 1320000000000\right):\\ \;\;\;\;r \cdot \frac{\sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\cos a} \cdot b\\ \end{array} \end{array} \]
            (FPCore (r a b)
             :precision binary64
             (if (or (<= b -1.05e+14) (not (<= b 1320000000000.0)))
               (* r (/ (sin b) 1.0))
               (* (/ r (cos a)) b)))
            double code(double r, double a, double b) {
            	double tmp;
            	if ((b <= -1.05e+14) || !(b <= 1320000000000.0)) {
            		tmp = r * (sin(b) / 1.0);
            	} else {
            		tmp = (r / cos(a)) * 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 <= (-1.05d+14)) .or. (.not. (b <= 1320000000000.0d0))) then
                    tmp = r * (sin(b) / 1.0d0)
                else
                    tmp = (r / cos(a)) * b
                end if
                code = tmp
            end function
            
            public static double code(double r, double a, double b) {
            	double tmp;
            	if ((b <= -1.05e+14) || !(b <= 1320000000000.0)) {
            		tmp = r * (Math.sin(b) / 1.0);
            	} else {
            		tmp = (r / Math.cos(a)) * b;
            	}
            	return tmp;
            }
            
            def code(r, a, b):
            	tmp = 0
            	if (b <= -1.05e+14) or not (b <= 1320000000000.0):
            		tmp = r * (math.sin(b) / 1.0)
            	else:
            		tmp = (r / math.cos(a)) * b
            	return tmp
            
            function code(r, a, b)
            	tmp = 0.0
            	if ((b <= -1.05e+14) || !(b <= 1320000000000.0))
            		tmp = Float64(r * Float64(sin(b) / 1.0));
            	else
            		tmp = Float64(Float64(r / cos(a)) * b);
            	end
            	return tmp
            end
            
            function tmp_2 = code(r, a, b)
            	tmp = 0.0;
            	if ((b <= -1.05e+14) || ~((b <= 1320000000000.0)))
            		tmp = r * (sin(b) / 1.0);
            	else
            		tmp = (r / cos(a)) * b;
            	end
            	tmp_2 = tmp;
            end
            
            code[r_, a_, b_] := If[Or[LessEqual[b, -1.05e+14], N[Not[LessEqual[b, 1320000000000.0]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;b \leq -1.05 \cdot 10^{+14} \lor \neg \left(b \leq 1320000000000\right):\\
            \;\;\;\;r \cdot \frac{\sin b}{1}\\
            
            \mathbf{else}:\\
            \;\;\;\;\frac{r}{\cos a} \cdot b\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if b < -1.05e14 or 1.32e12 < b

              1. Initial program 58.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{\sin b}{\color{blue}{\cos a + -1 \cdot \left(b \cdot \sin a\right)}} \]
              4. Step-by-step derivation
                1. +-commutativeN/A

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

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

                  \[\leadsto r \cdot \frac{\sin b}{\left(\mathsf{neg}\left(\color{blue}{\sin a \cdot b}\right)\right) + \cos a} \]
                4. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

                  \[\leadsto r \cdot \frac{\sin b}{1} \]
                3. Step-by-step derivation
                  1. Applied rewrites12.3%

                    \[\leadsto r \cdot \frac{\sin b}{1} \]

                  if -1.05e14 < b < 1.32e12

                  1. Initial program 96.0%

                    \[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. *-commutativeN/A

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

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

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

                      \[\leadsto \color{blue}{\frac{r}{\cos a}} \cdot b \]
                    5. lower-cos.f6491.8

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

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.05 \cdot 10^{+14} \lor \neg \left(b \leq 1320000000000\right):\\ \;\;\;\;r \cdot \frac{\sin b}{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\cos a} \cdot b\\ \end{array} \]
                6. Add Preprocessing

                Alternative 9: 50.8% accurate, 1.9× speedup?

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

                  \[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. *-commutativeN/A

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

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

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

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

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

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

                Alternative 10: 33.9% accurate, 36.7× speedup?

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

                  \[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. *-commutativeN/A

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

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

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

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

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

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

                  \[\leadsto b \cdot \color{blue}{r} \]
                7. Step-by-step derivation
                  1. Applied rewrites32.6%

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

                  Reproduce

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