I have been given the following problem and was wondering if my solution is correct: Say that a variable $A$ in CFG $G$ is necessary if it appears in every derivation of some string $w$ where $w$ is in $G$. Let $$\text{NECESSARY}_{\text{CFG}} =\{\langle G,A\rangle \mid G\text{ is a CFG and }A\text{ is a necessary variable in }G\}$$
- Show that $\text{NECESSARY}_{\text{CFG}}$ is Turing-recognizable.
- Show that $\text{NECESSARY}_{\text{CFG}}$ is undecidable.
This problem is a textbook exercise in the book Introduction to the Theory of Computation by Martin Sipser.
This is my solution to part 1.
$D$ = On input $\langle G,A\rangle$:
- Create a CFG $H$ by eliminating the $A$ variable from the derivations of $G$.
- Create list of strings $w$ generated by grammar $G$.
- Create a decider for $\text{A}_{\text{CFG}}$ and check if each string of $w$ can also be generated by $H$.
- If $w$ strings cannot be generated by $H$ then accept.
- If some string cannot be generated by $H$ then reject.
For part 2, I don't have a solution. My thoughts would be to somehow reduce this to $\text{ALL}_{\text{CFG}}$ which is known to be undecidable.