rsin B (should all be same)

Percentage Accurate: 76.7% → 99.5%
Time: 13.5s
Alternatives: 13
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 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \frac{r \cdot \sin b}{\mathsf{fma}\left(\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 80.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 0.3× speedup?

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

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

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

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

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

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

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

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

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

Alternative 3: 99.5% accurate, 0.4× speedup?

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

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

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

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

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

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

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

Alternative 4: 99.5% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

Alternative 5: 76.4% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 57.2%

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

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

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

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

    if -7.19999999999999967e-6 < b < 1.1e-5

    1. Initial program 99.0%

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

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

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

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

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

Alternative 6: 76.4% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 57.2%

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

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

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

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

    if -1.00000000000000008e-5 < b < 1.59999999999999993e-5

    1. Initial program 99.0%

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

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

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

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

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

Alternative 7: 76.7% 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 80.0%

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Final simplification80.0%

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

Alternative 8: 76.6% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 54.4% 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 80.0%

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

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

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

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

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

Alternative 10: 54.5% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{+14} \lor \neg \left(b \leq 5500000\right):\\
\;\;\;\;r \cdot \sin b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -5.2e14 or 5.5e6 < b

    1. Initial program 57.3%

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

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

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

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

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

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

    if -5.2e14 < b < 5.5e6

    1. Initial program 98.3%

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

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

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

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

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

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

Alternative 11: 54.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -35000000000000 \lor \neg \left(b \leq 250000000\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 -35000000000000.0) (not (<= b 250000000.0)))
   (* r (sin b))
   (* r (/ b (cos a)))))
double code(double r, double a, double b) {
	double tmp;
	if ((b <= -35000000000000.0) || !(b <= 250000000.0)) {
		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 <= (-35000000000000.0d0)) .or. (.not. (b <= 250000000.0d0))) 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 <= -35000000000000.0) || !(b <= 250000000.0)) {
		tmp = r * Math.sin(b);
	} else {
		tmp = r * (b / Math.cos(a));
	}
	return tmp;
}
def code(r, a, b):
	tmp = 0
	if (b <= -35000000000000.0) or not (b <= 250000000.0):
		tmp = r * math.sin(b)
	else:
		tmp = r * (b / math.cos(a))
	return tmp
function code(r, a, b)
	tmp = 0.0
	if ((b <= -35000000000000.0) || !(b <= 250000000.0))
		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 <= -35000000000000.0) || ~((b <= 250000000.0)))
		tmp = r * sin(b);
	else
		tmp = r * (b / cos(a));
	end
	tmp_2 = tmp;
end
code[r_, a_, b_] := If[Or[LessEqual[b, -35000000000000.0], N[Not[LessEqual[b, 250000000.0]], $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 -35000000000000 \lor \neg \left(b \leq 250000000\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 < -3.5e13 or 2.5e8 < b

    1. Initial program 57.3%

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

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

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

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

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

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

    if -3.5e13 < b < 2.5e8

    1. Initial program 98.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -35000000000000 \lor \neg \left(b \leq 250000000\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \]

Alternative 12: 38.1% 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 80.0%

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

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

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

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

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

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

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

Alternative 13: 34.2% 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 80.0%

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

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

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

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

    \[\leadsto \color{blue}{r \cdot b} \]
  6. Final simplification38.6%

    \[\leadsto r \cdot b \]

Reproduce

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