| Alternative 1 | |
|---|---|
| Error | 23.8% |
| Cost | 13385 |
\[\begin{array}{l}
\mathbf{if}\;b \leq -0.0009 \lor \neg \left(b \leq 0.096\right):\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot b}{\cos \left(a + b\right)}\\
\end{array}
\]
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (cos (+ a b))))
(FPCore (r a b) :precision binary64 (/ r (- (/ (cos a) (tan b)) (sin 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 / ((cos(a) / tan(b)) - sin(a));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (r * sin(b)) / cos((a + b))
end function
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r / ((cos(a) / tan(b)) - sin(a))
end function
public static double code(double r, double a, double b) {
return (r * Math.sin(b)) / Math.cos((a + b));
}
public static double code(double r, double a, double b) {
return r / ((Math.cos(a) / Math.tan(b)) - Math.sin(a));
}
def code(r, a, b): return (r * math.sin(b)) / math.cos((a + b))
def code(r, a, b): return r / ((math.cos(a) / math.tan(b)) - math.sin(a))
function code(r, a, b) return Float64(Float64(r * sin(b)) / cos(Float64(a + b))) end
function code(r, a, b) return Float64(r / Float64(Float64(cos(a) / tan(b)) - sin(a))) end
function tmp = code(r, a, b) tmp = (r * sin(b)) / cos((a + b)); end
function tmp = code(r, a, b) tmp = r / ((cos(a) / tan(b)) - sin(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[(r / N[(N[(N[Cos[a], $MachinePrecision] / N[Tan[b], $MachinePrecision]), $MachinePrecision] - N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{r \cdot \sin b}{\cos \left(a + b\right)}
\frac{r}{\frac{\cos a}{\tan b} - \sin a}
Results
Initial program 23.61
Simplified23.69
[Start]23.61 | \[ \frac{r \cdot \sin b}{\cos \left(a + b\right)}
\] |
|---|---|
associate-/l* [=>]23.69 | \[ \color{blue}{\frac{r}{\frac{\cos \left(a + b\right)}{\sin b}}}
\] |
+-commutative [=>]23.69 | \[ \frac{r}{\frac{\cos \color{blue}{\left(b + a\right)}}{\sin b}}
\] |
Applied egg-rr0.69
Simplified0.59
[Start]0.69 | \[ \frac{r}{\frac{1}{\sin b} \cdot \left(\cos b \cdot \cos a\right) + \frac{1}{\sin b} \cdot \left(\left(-\sin b\right) \cdot \sin a\right)}
\] |
|---|---|
distribute-lft-neg-in [<=]0.69 | \[ \frac{r}{\frac{1}{\sin b} \cdot \left(\cos b \cdot \cos a\right) + \frac{1}{\sin b} \cdot \color{blue}{\left(-\sin b \cdot \sin a\right)}}
\] |
associate-*l/ [=>]0.64 | \[ \frac{r}{\color{blue}{\frac{1 \cdot \left(\cos b \cdot \cos a\right)}{\sin b}} + \frac{1}{\sin b} \cdot \left(-\sin b \cdot \sin a\right)}
\] |
*-lft-identity [=>]0.64 | \[ \frac{r}{\frac{\color{blue}{\cos b \cdot \cos a}}{\sin b} + \frac{1}{\sin b} \cdot \left(-\sin b \cdot \sin a\right)}
\] |
associate-*l/ [<=]0.66 | \[ \frac{r}{\color{blue}{\frac{\cos b}{\sin b} \cdot \cos a} + \frac{1}{\sin b} \cdot \left(-\sin b \cdot \sin a\right)}
\] |
fma-def [=>]0.64 | \[ \frac{r}{\color{blue}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, \frac{1}{\sin b} \cdot \left(-\sin b \cdot \sin a\right)\right)}}
\] |
associate-*l/ [=>]0.61 | \[ \frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, \color{blue}{\frac{1 \cdot \left(-\sin b \cdot \sin a\right)}{\sin b}}\right)}
\] |
*-lft-identity [=>]0.61 | \[ \frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, \frac{\color{blue}{-\sin b \cdot \sin a}}{\sin b}\right)}
\] |
distribute-frac-neg [=>]0.61 | \[ \frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, \color{blue}{-\frac{\sin b \cdot \sin a}{\sin b}}\right)}
\] |
associate-*l/ [<=]0.59 | \[ \frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, -\color{blue}{\frac{\sin b}{\sin b} \cdot \sin a}\right)}
\] |
distribute-lft-neg-in [=>]0.59 | \[ \frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, \color{blue}{\left(-\frac{\sin b}{\sin b}\right) \cdot \sin a}\right)}
\] |
*-inverses [=>]0.59 | \[ \frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, \left(-\color{blue}{1}\right) \cdot \sin a\right)}
\] |
metadata-eval [=>]0.59 | \[ \frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, \color{blue}{-1} \cdot \sin a\right)}
\] |
mul-1-neg [=>]0.59 | \[ \frac{r}{\mathsf{fma}\left(\frac{\cos b}{\sin b}, \cos a, \color{blue}{-\sin a}\right)}
\] |
Applied egg-rr0.55
Simplified0.55
[Start]0.55 | \[ \frac{r}{0 - \left(\sin a - \frac{\cos a}{\tan b}\right)}
\] |
|---|---|
associate--r- [=>]0.55 | \[ \frac{r}{\color{blue}{\left(0 - \sin a\right) + \frac{\cos a}{\tan b}}}
\] |
+-commutative [=>]0.55 | \[ \frac{r}{\color{blue}{\frac{\cos a}{\tan b} + \left(0 - \sin a\right)}}
\] |
sub0-neg [=>]0.55 | \[ \frac{r}{\frac{\cos a}{\tan b} + \color{blue}{\left(-\sin a\right)}}
\] |
sub-neg [<=]0.55 | \[ \frac{r}{\color{blue}{\frac{\cos a}{\tan b} - \sin a}}
\] |
Final simplification0.55
| Alternative 1 | |
|---|---|
| Error | 23.8% |
| Cost | 13385 |
| Alternative 2 | |
|---|---|
| Error | 23.8% |
| Cost | 13385 |
| Alternative 3 | |
|---|---|
| Error | 23.8% |
| Cost | 13385 |
| Alternative 4 | |
|---|---|
| Error | 23.66% |
| Cost | 13376 |
| Alternative 5 | |
|---|---|
| Error | 23.63% |
| Cost | 13248 |
| Alternative 6 | |
|---|---|
| Error | 23.61% |
| Cost | 13248 |
| Alternative 7 | |
|---|---|
| Error | 23.69% |
| Cost | 13248 |
| Alternative 8 | |
|---|---|
| Error | 45% |
| Cost | 13120 |
| Alternative 9 | |
|---|---|
| Error | 44.72% |
| Cost | 7113 |
| Alternative 10 | |
|---|---|
| Error | 44.73% |
| Cost | 6985 |
| Alternative 11 | |
|---|---|
| Error | 44.75% |
| Cost | 6985 |
| Alternative 12 | |
|---|---|
| Error | 60.93% |
| Cost | 6592 |
| Alternative 13 | |
|---|---|
| Error | 65.52% |
| Cost | 192 |
herbie shell --seed 2023103
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))