| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 51840 |
\[\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \mathsf{log1p}\left(\mathsf{expm1}\left(\sin a \cdot \left(-\sin b\right)\right)\right)\right)}
\]

(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (fma (cos b) (cos a) (log1p (expm1 (* (sin a) (- (sin 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(cos(b), cos(a), log1p(expm1((sin(a) * -sin(b)))));
}
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(a + b)))) end
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(cos(b), cos(a), log1p(expm1(Float64(sin(a) * Float64(-sin(b))))))) 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[Log[1 + N[(Exp[N[(N[Sin[a], $MachinePrecision] * (-N[Sin[b], $MachinePrecision])), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \mathsf{log1p}\left(\mathsf{expm1}\left(\sin a \cdot \left(-\sin b\right)\right)\right)\right)}
\end{array}
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 81.7%
Simplified81.6%
[Start]81.7% | \[ r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\] |
|---|---|
associate-*r/ [=>]81.6% | \[ \color{blue}{\frac{r \cdot \sin b}{\cos \left(a + b\right)}}
\] |
+-commutative [=>]81.6% | \[ \frac{r \cdot \sin b}{\cos \color{blue}{\left(b + a\right)}}
\] |
Applied egg-rr99.6%
[Start]81.6% | \[ \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}}
\] |
cancel-sign-sub-inv [=>]99.5% | \[ \frac{r \cdot \sin b}{\color{blue}{\cos b \cdot \cos a + \left(-\sin b\right) \cdot \sin a}}
\] |
fma-def [=>]99.6% | \[ \frac{r \cdot \sin b}{\color{blue}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin b\right) \cdot \sin a\right)}}
\] |
Applied egg-rr99.6%
[Start]99.6% | \[ \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin b\right) \cdot \sin a\right)}
\] |
|---|---|
log1p-expm1-u [=>]99.6% | \[ \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-\sin b\right) \cdot \sin a\right)\right)}\right)}
\] |
distribute-lft-neg-out [=>]99.6% | \[ \frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{-\sin b \cdot \sin a}\right)\right)\right)}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 51840 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 39040 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 32704 |
| Alternative 4 | |
|---|---|
| Accuracy | 78.2% |
| Cost | 19648 |
| Alternative 5 | |
|---|---|
| Accuracy | 76.5% |
| Cost | 13385 |
| Alternative 6 | |
|---|---|
| Accuracy | 76.5% |
| Cost | 13385 |
| Alternative 7 | |
|---|---|
| Accuracy | 76.5% |
| Cost | 13384 |
| Alternative 8 | |
|---|---|
| Accuracy | 77.3% |
| Cost | 13248 |
| Alternative 9 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 13120 |
| Alternative 10 | |
|---|---|
| Accuracy | 53.5% |
| Cost | 6980 |
| Alternative 11 | |
|---|---|
| Accuracy | 53.6% |
| Cost | 6852 |
| Alternative 12 | |
|---|---|
| Accuracy | 53.6% |
| Cost | 6852 |
| Alternative 13 | |
|---|---|
| Accuracy | 39.8% |
| Cost | 6592 |
| Alternative 14 | |
|---|---|
| Accuracy | 35.6% |
| Cost | 192 |
herbie shell --seed 2023167
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))