Let $f$ be an arithmetical function. Suppose that $f(n)>0$ if $n$ is in an integer set $A$ and that $f(n)<0$ for another integer set $B.$ Is there a result from number theory or an elementary result that allows us to determine the first sign changes of the sequence $(f(n))$ and to compute its number of sign changes in terms of element of the sets $A$ or $B$?
Thanks in advance.



Sign changes of a sequence
I must agree with Lspice that usually, one requires further “structure” for $f$—like multiplicativity—or for $A$ and $B$—like prime numbers/integers in certain residue classes to be able to adequately answer you question. This allows for the right number-theoretic and analytical\algebraic tools to be exploited and brought to bear on the problem. Now, if your sets $A$ and $B$ are finite sets, then unless their maximum elements are beyond that which can be handled by modern computers, then the best way is to check by a computer program. The interesting case is then when the sets are infinite and are not susceptible to elementary combinatorial manipulations in abstracting an answer to your questions. In that case, knowing the “precise” answer to your questions may become infeasible and an “approximate” or asymptotic solution may be required; the following approach may be useful and explains why an underlying arithmetical structure for $f$ or the sets is so important; it is however, regrettably, not “elementary” as I am thinking you might want it to be, but the generic nature of your question demands that an elementary procedure is at best infeasible.


Since you said it is an “arithmetical” function, I presume the domain is the natural numbers and that it is of some number-theoretic flavor; (note that any function on the real numbers restricts to a function on the natural numbers, but rarely does one consider these restrictions as arithmetical functions if they’re not apparently connected to the numbers in a non-trivial/interesting way.


Now, let $\sigma(0):=0$ and define the sign  

$$\sigma\colon\mathbb{N}\to\{-1,0,1\}\,,~\,~\,~\,~n\mapsto\left\lbrace\begin{array}{ll}\frac{f(n)}{|f(n)|}&\mbox{if $n\in A\cup B$}\\0&\mbox{if otherwise}\end{array}\right.$$
For the precise number of sign changes between the sets up to a bound $N\ge 1$, you want to obtain the following quantity
$$\sum\_{1\le n\le N}\frac{1}{2}|\sigma(n)-\sigma(n-1)|\,.$$
But obtaining this sum may be impractical in most cases, as it deals directly with knowing the sign changes a priori, so one may want to obtain a weighted quantity
$$\eta(N):=\sum\_{n\le N}\chi(n)\,,~\,~\,~\,~\chi(n):=\omega(n)\sigma(n)\,,$$
where $\omega $ is a relevant suitable positive weight function depending on $f$ and the sets. For instance, suppose $\omega(n)=1$ for all $n$, then what does $\eta$ tell us? First if $\eta(N)=0$, then we know that there exactly the same number of elements—and, by at most an extra count, the same number of sign changes—between $A$ and $B$ up to $N$. Second if $\eta$ changes sign often, then there are intermittent sign changes between $A$ and $B$; monotonicity in a certain range then indicates no sign changes, and a break in monotonicity indicates a change in sign.


It follows from the above that knowing $\eta$ will be helpful in answering your questions; however, more often than not, it may be difficult to evaluate it directly, and this is where we need some structure as intimated in my opening paragraph above. If, on the one hand, $f$ is determined by the additive structure of the natural numbers, then a natural analytic object to consider is the power/Fourier series
$$E(z,\chi):=\sum\_{n\ge 1}\chi(n)z^{n-1}\,.$$
Presumably, the “additive” structure will make $E$ a much “nicer” and “malleable” function; we can formally obtain $\eta$ from $E$ via the identity
$$\eta(N)=\frac{1}{2\pi i}\oint\_CE(z,\chi)\frac{z^{-N}-1}{z^{-1}-1}\frac{dz}{z}\,~\,~\,~\,~\,~\,~ (Eq~1)\,,$$
where the contour integral is over some appropriate closed curve. If, on the other hand, $f$ is determined by the multiplicative structure of the natural numbers, then a natural analytic object to consider is the Dirichlet series
$$L(s,\chi):=\sum\_{n\ge 1}\chi(n)n^{-s}\,.$$
Here too, presumably, the “multiplicative” structure will make $L$ into a nicer and malleable function, from which we can formally determine $\eta$ as follows:
$$\eta(N)= \frac{1}{2\pi i}\oint\_{c-i\infty}^{c+i\infty}L(s,\chi)N^s\frac{ds}{s}\,~\,~\,~\,~\,~\,~ (Eq ~2)\,$$
where $c$ is some appropriate constant. Equations (1) and (2) most often could be evaluated using complex analytic methods up to a controlled error term, which allows one to have an asymptotic nature of how $\eta$ really behaves as $N$ increases without bound.


(Remarks): I have glossed over technical details just to explain the ideas involved; for instance Eq(2) may not give the exact equality when $N$ is an integer.


