| Alternative 1 | |
|---|---|
| Error | 15.3 |
| Cost | 13384 |
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
(FPCore (r a b) :precision binary64 (if (<= a -0.0007) (* r (/ (sin b) (cos a))) (if (<= a 0.00155) (/ (* (sin b) r) (cos b)) (/ r (/ (cos 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) {
double tmp;
if (a <= -0.0007) {
tmp = r * (sin(b) / cos(a));
} else if (a <= 0.00155) {
tmp = (sin(b) * r) / cos(b);
} else {
tmp = r / (cos(a) / sin(b));
}
return tmp;
}
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
real(8) :: tmp
if (a <= (-0.0007d0)) then
tmp = r * (sin(b) / cos(a))
else if (a <= 0.00155d0) then
tmp = (sin(b) * r) / cos(b)
else
tmp = r / (cos(a) / sin(b))
end if
code = tmp
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) {
double tmp;
if (a <= -0.0007) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else if (a <= 0.00155) {
tmp = (Math.sin(b) * r) / Math.cos(b);
} else {
tmp = r / (Math.cos(a) / Math.sin(b));
}
return tmp;
}
def code(r, a, b): return r * (math.sin(b) / math.cos((a + b)))
def code(r, a, b): tmp = 0 if a <= -0.0007: tmp = r * (math.sin(b) / math.cos(a)) elif a <= 0.00155: tmp = (math.sin(b) * r) / math.cos(b) else: tmp = r / (math.cos(a) / math.sin(b)) return tmp
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(a + b)))) end
function code(r, a, b) tmp = 0.0 if (a <= -0.0007) tmp = Float64(r * Float64(sin(b) / cos(a))); elseif (a <= 0.00155) tmp = Float64(Float64(sin(b) * r) / cos(b)); else tmp = Float64(r / Float64(cos(a) / sin(b))); end return tmp end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((a + b))); end
function tmp_2 = code(r, a, b) tmp = 0.0; if (a <= -0.0007) tmp = r * (sin(b) / cos(a)); elseif (a <= 0.00155) tmp = (sin(b) * r) / cos(b); else tmp = r / (cos(a) / sin(b)); end tmp_2 = tmp; 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_] := If[LessEqual[a, -0.0007], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.00155], N[(N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision], N[(r / N[(N[Cos[a], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\begin{array}{l}
\mathbf{if}\;a \leq -0.0007:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{elif}\;a \leq 0.00155:\\
\;\;\;\;\frac{\sin b \cdot r}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\frac{\cos a}{\sin b}}\\
\end{array}
Results
if a < -6.99999999999999993e-4Initial program 29.2
Simplified29.2
[Start]29.2 | \[ r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\] |
|---|---|
rational.json-simplify-1 [=>]29.2 | \[ r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}}
\] |
Taylor expanded in b around 0 29.3
if -6.99999999999999993e-4 < a < 0.00154999999999999995Initial program 0.6
Simplified0.6
[Start]0.6 | \[ r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\] |
|---|---|
rational.json-simplify-1 [=>]0.6 | \[ r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}}
\] |
Taylor expanded in a around 0 0.7
if 0.00154999999999999995 < a Initial program 30.0
Simplified30.0
[Start]30.0 | \[ r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\] |
|---|---|
rational.json-simplify-1 [=>]30.0 | \[ r \cdot \frac{\sin b}{\cos \color{blue}{\left(b + a\right)}}
\] |
Applied egg-rr30.0
Taylor expanded in b around 0 30.1
Applied egg-rr41.3
Simplified41.3
[Start]41.3 | \[ \left(\sin b \cdot \sin b\right) \cdot \frac{4}{\frac{\cos a}{r} \cdot \left(\sin b \cdot 4\right)}
\] |
|---|---|
rational.json-simplify-46 [=>]41.3 | \[ \left(\sin b \cdot \sin b\right) \cdot \color{blue}{\frac{\frac{4}{\frac{\cos a}{r}}}{\sin b \cdot 4}}
\] |
rational.json-simplify-44 [=>]41.3 | \[ \left(\sin b \cdot \sin b\right) \cdot \color{blue}{\frac{\frac{4}{\sin b \cdot 4}}{\frac{\cos a}{r}}}
\] |
rational.json-simplify-2 [=>]41.3 | \[ \left(\sin b \cdot \sin b\right) \cdot \frac{\frac{4}{\color{blue}{4 \cdot \sin b}}}{\frac{\cos a}{r}}
\] |
rational.json-simplify-46 [=>]41.3 | \[ \left(\sin b \cdot \sin b\right) \cdot \frac{\color{blue}{\frac{\frac{4}{4}}{\sin b}}}{\frac{\cos a}{r}}
\] |
metadata-eval [=>]41.3 | \[ \left(\sin b \cdot \sin b\right) \cdot \frac{\frac{\color{blue}{1}}{\sin b}}{\frac{\cos a}{r}}
\] |
Applied egg-rr30.4
Simplified30.0
[Start]30.4 | \[ \frac{1}{\frac{\cos a}{r} \cdot \frac{1}{\sin b}} + 0
\] |
|---|---|
rational.json-simplify-4 [=>]30.4 | \[ \color{blue}{\frac{1}{\frac{\cos a}{r} \cdot \frac{1}{\sin b}}}
\] |
rational.json-simplify-46 [=>]30.1 | \[ \color{blue}{\frac{\frac{1}{\frac{\cos a}{r}}}{\frac{1}{\sin b}}}
\] |
rational.json-simplify-44 [=>]30.1 | \[ \color{blue}{\frac{\frac{1}{\frac{1}{\sin b}}}{\frac{\cos a}{r}}}
\] |
rational.json-simplify-61 [=>]30.0 | \[ \frac{\color{blue}{\frac{\sin b}{\frac{1}{1}}}}{\frac{\cos a}{r}}
\] |
metadata-eval [=>]30.0 | \[ \frac{\frac{\sin b}{\color{blue}{1}}}{\frac{\cos a}{r}}
\] |
rational.json-simplify-7 [=>]30.0 | \[ \frac{\color{blue}{\sin b}}{\frac{\cos a}{r}}
\] |
rational.json-simplify-61 [=>]30.0 | \[ \color{blue}{\frac{r}{\frac{\cos a}{\sin b}}}
\] |
Final simplification15.3
| Alternative 1 | |
|---|---|
| Error | 15.3 |
| Cost | 13384 |
| Alternative 2 | |
|---|---|
| Error | 15.3 |
| Cost | 13384 |
| Alternative 3 | |
|---|---|
| Error | 15.3 |
| Cost | 13384 |
| Alternative 4 | |
|---|---|
| Error | 15.3 |
| Cost | 13384 |
| Alternative 5 | |
|---|---|
| Error | 15.3 |
| Cost | 13248 |
| Alternative 6 | |
|---|---|
| Error | 15.3 |
| Cost | 13248 |
| Alternative 7 | |
|---|---|
| Error | 29.1 |
| Cost | 13120 |
| Alternative 8 | |
|---|---|
| Error | 30.6 |
| Cost | 7624 |
| Alternative 9 | |
|---|---|
| Error | 29.3 |
| Cost | 6984 |
| Alternative 10 | |
|---|---|
| Error | 39.5 |
| Cost | 6592 |
| Alternative 11 | |
|---|---|
| Error | 42.4 |
| Cost | 192 |
herbie shell --seed 2023075
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))