Let $ A, B \subset \{ a, b\}^* $ and $A, B$ be regular. Lets define: $ A \circ B = \{ w \in A | \exists y \in B , \#_aw = \#_ay \}$ where,for example: for $ w = aaabaaba$
$\#_aw = 6, \#_bw = 2 $ Prove, that $A \circ B $ is regular.
My idea: Let modify DFA for $B$. ($DFA(B)$).
The only modification is function: $f'(q, a) = \{ f(q,a) , q) \}$
In words, after reading $a$ we are stay at the place $(f'(q,a) = q)$ and behave normally( $f'(q,a ) = f(q,a)$)
Now, we take a product of DFA(A) and modified DFA(B).
Please mark.