| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 32704 |
\[r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\]
(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)}
Initial program 76.8%
Simplified76.8%
[Start]76.8 | \[ r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\] |
|---|---|
+-commutative [=>]76.8 | \[ r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}}
\] |
Applied egg-rr99.5%
[Start]76.8 | \[ r \cdot \frac{\sin b}{\cos \left(b + a\right)}
\] |
|---|---|
cos-sum [=>]99.5 | \[ r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a - \sin b \cdot \sin a}}
\] |
Applied egg-rr99.5%
[Start]99.5 | \[ r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\] |
|---|---|
prod-diff [=>]99.5 | \[ r \cdot \frac{\sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, -\sin a \cdot \sin b\right) + \mathsf{fma}\left(-\sin a, \sin b, \sin a \cdot \sin b\right)}}
\] |
*-commutative [<=]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, -\color{blue}{\sin b \cdot \sin a}\right) + \mathsf{fma}\left(-\sin a, \sin b, \sin a \cdot \sin b\right)}
\] |
fma-neg [<=]99.5 | \[ r \cdot \frac{\sin b}{\color{blue}{\left(\cos b \cdot \cos a - \sin b \cdot \sin a\right)} + \mathsf{fma}\left(-\sin a, \sin b, \sin a \cdot \sin b\right)}
\] |
cancel-sign-sub-inv [=>]99.5 | \[ r \cdot \frac{\sin b}{\color{blue}{\left(\cos b \cdot \cos a + \left(-\sin b\right) \cdot \sin a\right)} + \mathsf{fma}\left(-\sin a, \sin b, \sin a \cdot \sin b\right)}
\] |
associate-+l+ [=>]99.5 | \[ r \cdot \frac{\sin b}{\color{blue}{\cos b \cdot \cos a + \left(\left(-\sin b\right) \cdot \sin a + \mathsf{fma}\left(-\sin a, \sin b, \sin a \cdot \sin b\right)\right)}}
\] |
distribute-lft-neg-in [<=]99.5 | \[ r \cdot \frac{\sin b}{\cos b \cdot \cos a + \left(\color{blue}{\left(-\sin b \cdot \sin a\right)} + \mathsf{fma}\left(-\sin a, \sin b, \sin a \cdot \sin b\right)\right)}
\] |
distribute-rgt-neg-in [=>]99.5 | \[ r \cdot \frac{\sin b}{\cos b \cdot \cos a + \left(\color{blue}{\sin b \cdot \left(-\sin a\right)} + \mathsf{fma}\left(-\sin a, \sin b, \sin a \cdot \sin b\right)\right)}
\] |
*-commutative [<=]99.5 | \[ r \cdot \frac{\sin b}{\cos b \cdot \cos a + \left(\sin b \cdot \left(-\sin a\right) + \mathsf{fma}\left(-\sin a, \sin b, \color{blue}{\sin b \cdot \sin a}\right)\right)}
\] |
Simplified99.5%
[Start]99.5 | \[ r \cdot \frac{\sin b}{\cos b \cdot \cos a + \left(\sin b \cdot \left(-\sin a\right) + \mathsf{fma}\left(-\sin a, \sin b, \sin b \cdot \sin a\right)\right)}
\] |
|---|---|
associate-+r+ [=>]99.5 | \[ r \cdot \frac{\sin b}{\color{blue}{\left(\cos b \cdot \cos a + \sin b \cdot \left(-\sin a\right)\right) + \mathsf{fma}\left(-\sin a, \sin b, \sin b \cdot \sin a\right)}}
\] |
+-commutative [<=]99.5 | \[ r \cdot \frac{\sin b}{\color{blue}{\left(\sin b \cdot \left(-\sin a\right) + \cos b \cdot \cos a\right)} + \mathsf{fma}\left(-\sin a, \sin b, \sin b \cdot \sin a\right)}
\] |
fma-udef [=>]99.5 | \[ r \cdot \frac{\sin b}{\left(\sin b \cdot \left(-\sin a\right) + \cos b \cdot \cos a\right) + \color{blue}{\left(\left(-\sin a\right) \cdot \sin b + \sin b \cdot \sin a\right)}}
\] |
*-commutative [<=]99.5 | \[ r \cdot \frac{\sin b}{\left(\sin b \cdot \left(-\sin a\right) + \cos b \cdot \cos a\right) + \left(\color{blue}{\sin b \cdot \left(-\sin a\right)} + \sin b \cdot \sin a\right)}
\] |
associate-+r+ [=>]99.4 | \[ r \cdot \frac{\sin b}{\color{blue}{\left(\left(\sin b \cdot \left(-\sin a\right) + \cos b \cdot \cos a\right) + \sin b \cdot \left(-\sin a\right)\right) + \sin b \cdot \sin a}}
\] |
Taylor expanded in a around inf 99.5%
Simplified99.5%
[Start]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \mathsf{fma}\left(\cos b, \cos a, -1 \cdot \left(\sin a \cdot \sin b\right) + \sin a \cdot \sin b\right)\right)}
\] |
|---|---|
+-commutative [=>]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \mathsf{fma}\left(\cos b, \cos a, \color{blue}{\sin a \cdot \sin b + -1 \cdot \left(\sin a \cdot \sin b\right)}\right)\right)}
\] |
mul-1-neg [=>]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \mathsf{fma}\left(\cos b, \cos a, \sin a \cdot \sin b + \color{blue}{\left(-\sin a \cdot \sin b\right)}\right)\right)}
\] |
sub-neg [<=]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \mathsf{fma}\left(\cos b, \cos a, \color{blue}{\sin a \cdot \sin b - \sin a \cdot \sin b}\right)\right)}
\] |
+-inverses [=>]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \mathsf{fma}\left(\cos b, \cos a, \color{blue}{0}\right)\right)}
\] |
Applied egg-rr99.5%
[Start]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \mathsf{fma}\left(\cos b, \cos a, 0\right)\right)}
\] |
|---|---|
fma-udef [=>]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \color{blue}{\cos b \cdot \cos a + 0}\right)}
\] |
+-rgt-identity [=>]99.5 | \[ r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \color{blue}{\cos b \cdot \cos a}\right)}
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 32704 |
| Alternative 2 | |
|---|---|
| Accuracy | 75.6% |
| Cost | 13384 |
| Alternative 3 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 13384 |
| Alternative 4 | |
|---|---|
| Accuracy | 75.6% |
| Cost | 13384 |
| Alternative 5 | |
|---|---|
| Accuracy | 75.6% |
| Cost | 13384 |
| Alternative 6 | |
|---|---|
| Accuracy | 76.8% |
| Cost | 13248 |
| Alternative 7 | |
|---|---|
| Accuracy | 55.0% |
| Cost | 13120 |
| Alternative 8 | |
|---|---|
| Accuracy | 55.0% |
| Cost | 13120 |
| Alternative 9 | |
|---|---|
| Accuracy | 55.3% |
| Cost | 6985 |
| Alternative 10 | |
|---|---|
| Accuracy | 55.3% |
| Cost | 6985 |
| Alternative 11 | |
|---|---|
| Accuracy | 39.0% |
| Cost | 6592 |
| Alternative 12 | |
|---|---|
| Accuracy | 34.5% |
| Cost | 192 |
herbie shell --seed 2023136
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))