| Alternative 1 | |
|---|---|
| Error | 0.52% |
| 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 24.14
Simplified24.14
[Start]24.14 | \[ r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\] |
|---|---|
+-commutative [=>]24.14 | \[ r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}}
\] |
Applied egg-rr0.52
Applied egg-rr0.52
Simplified0.52
[Start]0.52 | \[ 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+ [=>]0.51 | \[ 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 [<=]0.51 | \[ 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 [=>]0.52 | \[ 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 [<=]0.52 | \[ 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+ [=>]0.57 | \[ 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 0.5
Simplified0.5
[Start]0.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 [=>]0.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 [=>]0.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 [<=]0.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 [=>]0.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-rr0.5
Final simplification0.5
| Alternative 1 | |
|---|---|
| Error | 0.52% |
| Cost | 32704 |
| Alternative 2 | |
|---|---|
| Error | 0.53% |
| Cost | 32704 |
| Alternative 3 | |
|---|---|
| Error | 24.57% |
| Cost | 13385 |
| Alternative 4 | |
|---|---|
| Error | 24.55% |
| Cost | 13384 |
| Alternative 5 | |
|---|---|
| Error | 24.14% |
| Cost | 13248 |
| Alternative 6 | |
|---|---|
| Error | 24.14% |
| Cost | 13248 |
| Alternative 7 | |
|---|---|
| Error | 45.89% |
| Cost | 13120 |
| Alternative 8 | |
|---|---|
| Error | 49.28% |
| Cost | 7232 |
| Alternative 9 | |
|---|---|
| Error | 50.19% |
| Cost | 6720 |
| Alternative 10 | |
|---|---|
| Error | 50.19% |
| Cost | 6720 |
| Alternative 11 | |
|---|---|
| Error | 65.84% |
| Cost | 192 |
herbie shell --seed 2023090
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))