rsin A (should all be same)

?

Percentage Accurate: 77.1% → 99.5%
Time: 20.1s
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)}

Local Percentage Accuracy?

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 15 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Derivation?

  1. Initial program 77.8%

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

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

    [Start]77.8

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

    +-commutative [=>]77.8

    \[ \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]77.8

    \[ \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.6%

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

    [Start]99.5

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

    sub-neg [=>]99.5

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

    +-commutative [=>]99.5

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

    distribute-rgt-neg-in [=>]99.5

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

    fma-def [=>]99.6

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

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

Alternatives

Alternative 1
Accuracy99.4%
Cost32704
\[\sin b \cdot \frac{r}{\cos b \cdot \cos a - \sin b \cdot \sin a} \]
Alternative 2
Accuracy99.5%
Cost32704
\[r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \]
Alternative 3
Accuracy99.5%
Cost32704
\[\frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a} \]
Alternative 4
Accuracy99.4%
Cost32512
\[\frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, -\sin a\right)} \]
Alternative 5
Accuracy77.9%
Cost26048
\[r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, 0\right)} \]
Alternative 6
Accuracy76.8%
Cost13385
\[\begin{array}{l} \mathbf{if}\;b \leq -0.000115 \lor \neg \left(b \leq 0.00365\right):\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \end{array} \]
Alternative 7
Accuracy76.8%
Cost13384
\[\begin{array}{l} \mathbf{if}\;b \leq -6.6 \cdot 10^{-5}:\\ \;\;\;\;\sin b \cdot \frac{r}{\cos b}\\ \mathbf{elif}\;b \leq 0.00365:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \mathbf{else}:\\ \;\;\;\;\frac{r}{\frac{\cos b}{\sin b}}\\ \end{array} \]
Alternative 8
Accuracy77.0%
Cost13248
\[\sin b \cdot \frac{r}{\cos \left(b + a\right)} \]
Alternative 9
Accuracy77.0%
Cost13248
\[\frac{r \cdot \sin b}{\cos \left(b - a\right)} \]
Alternative 10
Accuracy55.0%
Cost13120
\[\sin b \cdot \frac{r}{\cos a} \]
Alternative 11
Accuracy55.2%
Cost6985
\[\begin{array}{l} \mathbf{if}\;b \leq -0.46 \lor \neg \left(b \leq 1.26\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;r \cdot \frac{b}{\cos a}\\ \end{array} \]
Alternative 12
Accuracy55.2%
Cost6985
\[\begin{array}{l} \mathbf{if}\;b \leq -0.64 \lor \neg \left(b \leq 1.12\right):\\ \;\;\;\;r \cdot \sin b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{r}{\cos a}\\ \end{array} \]
Alternative 13
Accuracy38.0%
Cost6592
\[r \cdot \sin b \]
Alternative 14
Accuracy34.0%
Cost192
\[r \cdot b \]

Reproduce?

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