?

Average Error: 23.54% → 0.49%
Time: 15.7s
Precision: binary64
Cost: 39040

?

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

Error?

Derivation?

  1. Initial program 23.54

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

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

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

    [Start]0.52

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

    +-commutative [=>]0.52

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

    *-commutative [=>]0.52

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

    fma-def [=>]0.51

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

    *-commutative [=>]0.51

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

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

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

    [Start]0.52

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

    associate-/l* [=>]0.61

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

    associate-/r/ [=>]0.5

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

    +-commutative [=>]0.5

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

    *-commutative [<=]0.5

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

    *-commutative [<=]0.5

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

    mul-1-neg [=>]0.5

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

    unsub-neg [=>]0.5

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

    *-commutative [=>]0.5

    \[ \frac{\sin b}{\color{blue}{\cos a \cdot \cos b} - \sin b \cdot \sin a} \cdot r \]
  6. Applied egg-rr0.49

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

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

Alternatives

Alternative 1
Error0.5%
Cost32704
\[r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \]
Alternative 2
Error0.57%
Cost32512
\[\frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, -\sin a\right)} \]
Alternative 3
Error23.7%
Cost13385
\[\begin{array}{l} \mathbf{if}\;b \leq -0.0095 \lor \neg \left(b \leq 2.9 \cdot 10^{-8}\right):\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot r}{\cos \left(b + a\right)}\\ \end{array} \]
Alternative 4
Error23.69%
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -0.0095:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-8}:\\ \;\;\;\;\frac{b \cdot r}{\cos \left(b + a\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{\cos b}{\sin b}}\\ \end{array} \]
Alternative 5
Error23.7%
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -0.0095:\\ \;\;\;\;\frac{\sin b}{\frac{\cos b}{r}}\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-8}:\\ \;\;\;\;\frac{b \cdot r}{\cos \left(b + a\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{\cos b}{\sin b}}\\ \end{array} \]
Alternative 6
Error23.7%
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -0.0095:\\ \;\;\;\;\frac{\sin b \cdot r}{\cos b}\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-8}:\\ \;\;\;\;\frac{b \cdot r}{\cos \left(b + a\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{\cos b}{\sin b}}\\ \end{array} \]
Alternative 7
Error23.52%
Cost13248
\[r \cdot \frac{\sin b}{\cos \left(b + a\right)} \]
Alternative 8
Error23.66%
Cost13248
\[\frac{\sin b \cdot r}{\cos \left(b - a\right)} \]
Alternative 9
Error44.97%
Cost13120
\[\sin b \cdot \frac{r}{\cos a} \]
Alternative 10
Error44.74%
Cost7113
\[\begin{array}{l} \mathbf{if}\;b \leq -35 \lor \neg \left(b \leq 3.3\right):\\ \;\;\;\;\sin b \cdot r\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot r}{\cos \left(b + a\right)}\\ \end{array} \]
Alternative 11
Error44.74%
Cost6985
\[\begin{array}{l} \mathbf{if}\;b \leq -1.7 \lor \neg \left(b \leq 4.8\right):\\ \;\;\;\;\sin b \cdot r\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \]
Alternative 12
Error44.76%
Cost6985
\[\begin{array}{l} \mathbf{if}\;b \leq -1.75 \lor \neg \left(b \leq 4.8\right):\\ \;\;\;\;\sin b \cdot r\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \end{array} \]
Alternative 13
Error61.21%
Cost6592
\[\sin b \cdot r \]
Alternative 14
Error65.5%
Cost192
\[b \cdot r \]

Error

Reproduce?

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