rsin A (should all be same)

?

Percentage Accurate: 76.1% → 99.5%
Time: 20.4s
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 a \cdot \cos b\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 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 (r * sin(b)) / fma(sin(b), -sin(a), (cos(a) * cos(b)));
}
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(a) * cos(b))))
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[a], $MachinePrecision] * N[Cos[b], $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 a \cdot \cos b\right)}

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.

Herbie found 13 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Derivation?

  1. Initial program 80.2%

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

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

    [Start]80.2%

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

    +-commutative [=>]80.2%

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

    \[\leadsto \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
    Step-by-step derivation

    [Start]80.2%

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

    cos-sum [=>]99.5%

    \[ \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}} \]
  4. Applied egg-rr99.5%

    \[\leadsto \frac{r \cdot \sin b}{\cos b \cdot \cos a - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\sin b \cdot \sin a\right)\right)}} \]
    Step-by-step derivation

    [Start]99.5%

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

    log1p-expm1-u [=>]99.5%

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

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

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

    [Start]99.5%

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

    cancel-sign-sub-inv [=>]99.5%

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

    *-commutative [=>]99.5%

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

    *-commutative [<=]99.5%

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

    +-commutative [=>]99.5%

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

    fma-def [=>]99.5%

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

    *-commutative [<=]99.5%

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

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

Alternatives

Alternative 1
Accuracy99.5%
Cost39040
\[\frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\sin a, \cos a \cdot \cos b\right)} \]
Alternative 2
Accuracy99.5%
Cost32704
\[r \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a} \]
Alternative 3
Accuracy99.5%
Cost32704
\[\frac{r \cdot \sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a} \]
Alternative 4
Accuracy76.1%
Cost13248
\[\sin b \cdot \frac{r}{\cos \left(b + a\right)} \]
Alternative 5
Accuracy76.1%
Cost13248
\[\frac{r \cdot \sin b}{\cos \left(b + a\right)} \]
Alternative 6
Accuracy75.9%
Cost7113
\[\begin{array}{l} \mathbf{if}\;b \leq -5.2 \cdot 10^{-5} \lor \neg \left(b \leq 1.35 \cdot 10^{-5}\right):\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;\frac{r \cdot b}{\cos \left(b + a\right)}\\ \end{array} \]
Alternative 7
Accuracy75.8%
Cost6985
\[\begin{array}{l} \mathbf{if}\;b \leq -11.6 \lor \neg \left(b \leq 1.06 \cdot 10^{-5}\right):\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \]
Alternative 8
Accuracy75.8%
Cost6985
\[\begin{array}{l} \mathbf{if}\;b \leq -11.6 \lor \neg \left(b \leq 7.5 \cdot 10^{-6}\right):\\ \;\;\;\;r \cdot \tan b\\ \mathbf{else}:\\ \;\;\;\;\frac{r \cdot b}{\cos a}\\ \end{array} \]
Alternative 9
Accuracy60.2%
Cost6592
\[r \cdot \tan b \]
Alternative 10
Accuracy34.2%
Cost576
\[r \cdot \frac{1}{\frac{1}{b} - a} \]
Alternative 11
Accuracy35.1%
Cost576
\[\frac{r}{b \cdot -0.3333333333333333 + \frac{1}{b}} \]
Alternative 12
Accuracy34.2%
Cost448
\[\frac{r}{\frac{1}{b} - a} \]
Alternative 13
Accuracy34.6%
Cost192
\[r \cdot b \]

Reproduce?

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