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

Error

Derivation

  1. Initial program 14.7

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

    \[\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}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
  4. Applied egg-rr0.3

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

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

Alternatives

Alternative 1
Error0.3
Cost32704
\[r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \]
Alternative 2
Error0.3
Cost32704
\[\frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \]
Alternative 3
Error0.8
Cost26432
\[\frac{1}{\frac{\cos a}{r} \cdot \frac{\cos b}{\sin b} - \frac{\sin a}{r}} \]
Alternative 4
Error14.0
Cost26048
\[r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, 0\right)} \]
Alternative 5
Error14.8
Cost13384
\[\begin{array}{l} t_0 := r \cdot \frac{\sin b}{\cos b}\\ \mathbf{if}\;b \leq -4.7 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error14.8
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -5.8 \cdot 10^{-5}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \end{array} \]
Alternative 7
Error14.8
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-5}:\\ \;\;\;\;\frac{r}{\frac{\cos b}{\sin b}}\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \end{array} \]
Alternative 8
Error14.8
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -0.00013:\\ \;\;\;\;\frac{\sin b}{\frac{\cos b}{r}}\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{\sin b}{\cos b}\\ \end{array} \]
Alternative 9
Error14.8
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -0.00038:\\ \;\;\;\;\frac{\sin b}{\frac{\cos b}{r}}\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-6}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;\frac{r \cdot \sin b}{\cos b}\\ \end{array} \]
Alternative 10
Error14.7
Cost13248
\[r \cdot \frac{\sin b}{\cos \left(b + a\right)} \]
Alternative 11
Error14.8
Cost13248
\[r \cdot \frac{\sin b}{\cos \left(b - a\right)} \]
Alternative 12
Error28.4
Cost13120
\[r \cdot \frac{\sin b}{\cos a} \]
Alternative 13
Error31.1
Cost6720
\[r \cdot \frac{b}{\cos a} \]
Alternative 14
Error31.1
Cost6720
\[b \cdot \frac{r}{\cos a} \]
Alternative 15
Error41.5
Cost192
\[r \cdot b \]

Error

Reproduce

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