Average Error: 14.5 → 0.3
Time: 15.5s
Precision: binary64
Cost: 39040
\[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
\[\frac{\sin b \cdot r}{\mathsf{fma}\left(\sin b, -\sin a, \cos a \cdot \cos b\right)} \]
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
(FPCore (r a b)
 :precision binary64
 (/ (* (sin b) r) (fma (sin b) (- (sin a)) (* (cos a) (cos b)))))
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) * r) / fma(sin(b), -sin(a), (cos(a) * cos(b)));
}
function code(r, a, b)
	return Float64(r * Float64(sin(b) / cos(Float64(a + b))))
end
function code(r, a, b)
	return Float64(Float64(sin(b) * r) / fma(sin(b), Float64(-sin(a)), Float64(cos(a) * cos(b))))
end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision]) + N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\frac{\sin b \cdot r}{\mathsf{fma}\left(\sin b, -\sin a, \cos a \cdot \cos b\right)}

Error

Derivation

  1. Initial program 14.5

    \[r \cdot \frac{\sin b}{\cos \left(a + b\right)} \]
  2. Simplified14.5

    \[\leadsto \color{blue}{r \cdot \frac{\sin b}{\cos \left(b + a\right)}} \]
    Proof
    (*.f64 r (/.f64 (sin.f64 b) (cos.f64 (+.f64 b a)))): 0 points increase in error, 0 points decrease in error
    (*.f64 r (/.f64 (sin.f64 b) (cos.f64 (Rewrite<= +-commutative_binary64 (+.f64 a b))))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.3

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

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

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

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

Alternatives

Alternative 1
Error0.3
Cost32704
\[r \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a} \]
Alternative 2
Error0.3
Cost32704
\[\sin b \cdot \frac{r}{\cos a \cdot \cos b - \sin b \cdot \sin a} \]
Alternative 3
Error0.3
Cost32704
\[\frac{\sin b \cdot r}{\cos a \cdot \cos b - \sin b \cdot \sin a} \]
Alternative 4
Error13.8
Cost19648
\[\frac{\sin b \cdot r}{\cos a \cdot \cos b} \]
Alternative 5
Error14.5
Cost13384
\[\begin{array}{l} t_0 := r \cdot \frac{\sin b}{\cos a}\\ \mathbf{if}\;a \leq -3.5 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a \leq 3.3 \cdot 10^{-6}:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error14.5
Cost13384
\[\begin{array}{l} \mathbf{if}\;a \leq -9 \cdot 10^{-5}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos a}\\ \mathbf{elif}\;a \leq 6.1 \cdot 10^{-5}:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos a}\\ \end{array} \]
Alternative 7
Error14.5
Cost13384
\[\begin{array}{l} \mathbf{if}\;a \leq -6 \cdot 10^{-5}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos a}\\ \mathbf{elif}\;a \leq 2.7 \cdot 10^{-5}:\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin b \cdot r}{\cos a}\\ \end{array} \]
Alternative 8
Error14.5
Cost13376
\[\sin b \cdot \left(r \cdot \frac{1}{\cos \left(b + a\right)}\right) \]
Alternative 9
Error14.5
Cost13248
\[r \cdot \frac{\sin b}{\cos \left(b + a\right)} \]
Alternative 10
Error14.5
Cost13248
\[\sin b \cdot \frac{r}{\cos \left(b + a\right)} \]
Alternative 11
Error14.5
Cost13248
\[\frac{\sin b \cdot r}{\cos \left(b + a\right)} \]
Alternative 12
Error14.7
Cost6984
\[\begin{array}{l} t_0 := r \cdot \tan b\\ \mathbf{if}\;b \leq -1.85:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.8 \cdot 10^{-8}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 13
Error14.7
Cost6984
\[\begin{array}{l} t_0 := r \cdot \tan b\\ \mathbf{if}\;b \leq -1.85:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.8 \cdot 10^{-8}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 14
Error24.9
Cost6592
\[r \cdot \tan b \]
Alternative 15
Error42.0
Cost192
\[b \cdot r \]

Error

Reproduce

herbie shell --seed 2022331 
(FPCore (r a b)
  :name "rsin B"
  :precision binary64
  (* r (/ (sin b) (cos (+ a b)))))