?

Average Error: 23.32% → 0.49%
Time: 15.2s
Precision: binary64
Cost: 39040

?

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

Error?

Derivation?

  1. Initial program 23.32

    \[\frac{r \cdot \sin b}{\cos \left(a + b\right)} \]
  2. Applied egg-rr0.51

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

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

    [Start]0.51

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

    +-commutative [=>]0.51

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

    *-commutative [=>]0.51

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

    fma-def [=>]0.49

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

    *-commutative [=>]0.49

    \[ \frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\sin a, \color{blue}{\cos b \cdot \cos a}\right)} \]
  4. Final simplification0.49

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

Alternatives

Alternative 1
Error0.5%
Cost39040
\[\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos a, \cos b, \sin b \cdot \left(-\sin a\right)\right)} \]
Alternative 2
Error0.51%
Cost32704
\[r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \]
Alternative 3
Error0.59%
Cost32512
\[\frac{r}{\mathsf{fma}\left(\cos b, \frac{\cos a}{\sin b}, -\sin a\right)} \]
Alternative 4
Error0.59%
Cost32512
\[\frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, -\sin a\right)} \]
Alternative 5
Error0.61%
Cost26176
\[\frac{r}{\cos a \cdot \frac{\cos b}{\sin b} - \sin a} \]
Alternative 6
Error23.63%
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -2.5 \cdot 10^{-5}:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{elif}\;b \leq 0.0028:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{1}{\tan b}}\\ \end{array} \]
Alternative 7
Error23.47%
Cost13248
\[\sin b \cdot \frac{r}{\cos \left(b - a\right)} \]
Alternative 8
Error23.31%
Cost13248
\[r \cdot \frac{\sin b}{\cos \left(b + a\right)} \]
Alternative 9
Error23.62%
Cost6985
\[\begin{array}{l} \mathbf{if}\;b \leq -0.0006 \lor \neg \left(b \leq 0.000115\right):\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \end{array} \]
Alternative 10
Error23.65%
Cost6984
\[\begin{array}{l} \mathbf{if}\;b \leq -0.000105:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{elif}\;b \leq 1.75 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{1}{\tan b}}\\ \end{array} \]
Alternative 11
Error23.62%
Cost6984
\[\begin{array}{l} \mathbf{if}\;b \leq -2.6 \cdot 10^{-5}:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{elif}\;b \leq 0.0007:\\ \;\;\;\;\frac{r \cdot b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{1}{\tan b}}\\ \end{array} \]
Alternative 12
Error61.04%
Cost6592
\[r \cdot \sin b \]
Alternative 13
Error39.84%
Cost6592
\[r \cdot \tan b \]
Alternative 14
Error64.69%
Cost576
\[\frac{r}{b \cdot -0.3333333333333333 + \frac{1}{b}} \]
Alternative 15
Error65.52%
Cost192
\[r \cdot b \]

Error

Reproduce?

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