I have found one specific problem about regular languages which I am not sure how to solve:
Prove that the following language $$P(L) = \{ w \in L\text{ } |\text{for any prefix } w' \text{ of w, } w' \in L\}$$ is regular, given that L is regular too.
I thought of using closure properties, but I can't think of any other language to use for that. Any tips?
It is possible to construct a non-deterministic automaton for $P(L)$:
Consider a DFA of $L$, and construct an NFA by adding an accepting state with no outgoing edges, and an $\epsilon$ edge from each of the states that have a path to an accepting state in the DFA, to the new accepting state.
This way, if a word is a prefix, then there is a path from the end of its run on the DFA to an accepting state, and there is an $\epsilon$ transition to the new accepting state.
If there is a run which reaches an accepting state, then it is either a run of the DFA (and then the word is in $L\subset P(L)$) or a run reaching the new accepting state, and therefore must be a word that reached a state that has a path to an accepting state in the DFA, therefore a prefix.