rsin A (should all be same)

Percentage Accurate: 76.0% → 99.5%
Time: 15.4s
Alternatives: 13
Speedup: 0.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 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.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 0.3× speedup?

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

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

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

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

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

      \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
    2. sub-neg99.5%

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

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

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

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

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

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

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

Alternative 2: 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.9%

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

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

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

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

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

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

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

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

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

Alternative 3: 77.2% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{\sqrt{\left(-\sin b\right) \cdot \left(-\sin b\right)}} \cdot \sin a\right)} \]
    3. sqr-neg87.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \frac{\left(\cos b \cdot \cos a + \color{blue}{\left(-\sin b\right)} \cdot \sin a\right) - \cos \left(b + a\right)}{2}\right)} \]
    13. distribute-lft-neg-out75.9%

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

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

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

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

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

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

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

Alternative 4: 75.8% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;a \leq 1.28 \cdot 10^{-5}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos b}\\

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


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

    1. Initial program 48.8%

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

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

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

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

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

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

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

    if -4.20000000000000018 < a < 1.2799999999999999e-5

    1. Initial program 98.0%

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

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

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

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

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

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

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

    if 1.2799999999999999e-5 < a

    1. Initial program 50.7%

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

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

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

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

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

      \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. log1p-expm1-u50.7%

        \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
    6. Applied egg-rr50.7%

      \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
    7. Taylor expanded in b around 0 51.0%

      \[\leadsto r \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\color{blue}{\cos a}}\right)\right) \]
    8. Step-by-step derivation
      1. log1p-expm1-u51.0%

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

        \[\leadsto r \cdot \color{blue}{\frac{1}{\frac{\cos a}{\sin b}}} \]
    9. Applied egg-rr51.1%

      \[\leadsto r \cdot \color{blue}{\frac{1}{\frac{\cos a}{\sin b}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 75.9% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -4.20000000000000018 or 2.9e-4 < a

    1. Initial program 49.8%

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

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

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

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

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

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

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

    if -4.20000000000000018 < a < 2.9e-4

    1. Initial program 98.0%

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

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

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

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

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

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

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

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

Alternative 6: 75.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.2 \lor \neg \left(a \leq 1.32 \cdot 10^{-5}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -4.20000000000000018 or 1.32000000000000007e-5 < a

    1. Initial program 49.8%

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

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

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

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

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

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

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

    if -4.20000000000000018 < a < 1.32000000000000007e-5

    1. Initial program 98.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos b}} \]
    7. Simplified98.0%

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

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

Alternative 7: 76.0% 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.9%

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

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

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

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

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

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

Alternative 8: 55.1% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

Alternative 9: 55.0% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.3 \cdot 10^{+37} \lor \neg \left(b \leq 1.85 \cdot 10^{+38}\right):\\
\;\;\;\;r \cdot \sin b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -2.30000000000000002e37 or 1.8500000000000001e38 < b

    1. Initial program 53.7%

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

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

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

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

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

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

        \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
    6. Applied egg-rr53.4%

      \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
    7. Taylor expanded in b around 0 13.2%

      \[\leadsto r \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\color{blue}{\cos a}}\right)\right) \]
    8. Taylor expanded in a around 0 12.4%

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

    if -2.30000000000000002e37 < b < 1.8500000000000001e38

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

Alternative 10: 55.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -650 \lor \neg \left(b \leq 14.6\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -650.0) (not (<= b 14.6))) (* r (sin b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -650.0) || !(b <= 14.6)) {
		tmp = r * sin(b);
	} else {
		tmp = r * (b / cos(a));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b <= (-650.0d0)) .or. (.not. (b <= 14.6d0))) then
        tmp = r * sin(b)
    else
        tmp = r * (b / cos(a))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((b <= -650.0) || !(b <= 14.6)) {
		tmp = r * Math.sin(b);
	} else {
		tmp = r * (b / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -650.0) or not (b <= 14.6):
		tmp = r * math.sin(b)
	else:
		tmp = r * (b / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -650.0) || !(b <= 14.6))
		tmp = Float64(r * sin(b));
	else
		tmp = Float64(r * Float64(b / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -650.0) || ~((b <= 14.6)))
		tmp = r * sin(b);
	else
		tmp = r * (b / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -650.0], N[Not[LessEqual[b, 14.6]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -650 \lor \neg \left(b \leq 14.6\right):\\
\;\;\;\;r \cdot \sin b\\

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


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

    1. Initial program 53.2%

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

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

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

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

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

      \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. log1p-expm1-u52.9%

        \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
    6. Applied egg-rr52.9%

      \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
    7. Taylor expanded in b around 0 12.6%

      \[\leadsto r \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\color{blue}{\cos a}}\right)\right) \]
    8. Taylor expanded in a around 0 11.8%

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

    if -650 < b < 14.5999999999999996

    1. Initial program 97.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b \cdot r}{\cos a}} \]
    6. Step-by-step derivation
      1. *-commutative97.2%

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

        \[\leadsto \color{blue}{r \cdot \frac{b}{\cos a}} \]
    7. Simplified97.3%

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

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

Alternative 11: 55.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -0.58 \lor \neg \left(b \leq 14\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \end{array} \end{array} \]
(FPCore (r a b)
 :precision binary64
 (if (or (<= b -0.58) (not (<= b 14.0))) (* r (sin b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.58) || !(b <= 14.0)) {
		tmp = r * sin(b);
	} else {
		tmp = b * (r / cos(a));
	}
	return tmp;
}
real(8) function code(r, a, b)
    real(8), intent (in) :: r
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b <= (-0.58d0)) .or. (.not. (b <= 14.0d0))) then
        tmp = r * sin(b)
    else
        tmp = b * (r / cos(a))
    end if
    code = tmp
end function
public static double code(double r, double a, double b) {
	double tmp;
	if ((b <= -0.58) || !(b <= 14.0)) {
		tmp = r * Math.sin(b);
	} else {
		tmp = b * (r / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -0.58) or not (b <= 14.0):
		tmp = r * math.sin(b)
	else:
		tmp = b * (r / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -0.58) || !(b <= 14.0))
		tmp = Float64(r * sin(b));
	else
		tmp = Float64(b * Float64(r / cos(a)));
	end
	return tmp
end
function tmp_2 = code(r, a, b)
	tmp = 0.0;
	if ((b <= -0.58) || ~((b <= 14.0)))
		tmp = r * sin(b);
	else
		tmp = b * (r / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.58], N[Not[LessEqual[b, 14.0]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.58 \lor \neg \left(b \leq 14\right):\\
\;\;\;\;r \cdot \sin b\\

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


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

    1. Initial program 53.2%

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

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

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

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

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

      \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. log1p-expm1-u52.9%

        \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
    6. Applied egg-rr52.9%

      \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
    7. Taylor expanded in b around 0 12.6%

      \[\leadsto r \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\color{blue}{\cos a}}\right)\right) \]
    8. Taylor expanded in a around 0 11.8%

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

    if -0.57999999999999996 < b < 14

    1. Initial program 97.4%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{b \cdot \frac{r}{\cos a}} \]
    7. Simplified97.2%

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

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

Alternative 12: 38.4% accurate, 2.0× speedup?

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

\\
r \cdot \sin b
\end{array}
Derivation
  1. Initial program 73.9%

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

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

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

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

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

    \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. log1p-expm1-u73.8%

      \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
  6. Applied egg-rr73.8%

    \[\leadsto r \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\cos \left(b + a\right)}\right)\right)} \]
  7. Taylor expanded in b around 0 52.3%

    \[\leadsto r \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin b}{\color{blue}{\cos a}}\right)\right) \]
  8. Taylor expanded in a around 0 37.2%

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

Alternative 13: 34.3% accurate, 69.0× speedup?

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

\\
r \cdot b
\end{array}
Derivation
  1. Initial program 73.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{b \cdot r} \]
  9. Step-by-step derivation
    1. *-commutative33.0%

      \[\leadsto \color{blue}{r \cdot b} \]
  10. Simplified33.0%

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

Reproduce

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