# Finding a minimal DFA whose language has a desired intersection with another

Suppose I have regular languages $B \subseteq A$, with corresponding (known) minimal deterministic finite automata $M_A, M_B$.

I would like to find another regular language $C$ such that $B = A \cap C$ that minimizes the size of $M_C$ (the minimal DFA corresponding to $C$).

In general $M_C$ can be much smaller than $M_B$. e.g. if we let $B$ the set of strings in $A$ that have even length, $M_C$ can be a two-state machine, while $M_B$ may be about as complex (or more) as $M_A$.

This feels like it should be an easy application of existing automaton minimization algorithms, but I'm not seeing it if so.

What looked liked the obvious thing to try to do is to to try and distinguish strings using an analogue of the Myhill-Nerode theorem, with the distinguishing relationship being that $x, y$ are distinct if there is some $s$ such that $xs, ys \in A$ but $xs \in B \neq ys \in B$, but the problem is that the corresponding indistinguishability relation is no longer transitive (I think) - Given $a$ indistinguishable from $b$ indistinguishable from $c$, there might be $s$ such that $as, cs \in A$ with $as \in B \neq cs \in B$, but $bs \not\in A$, so $s$ cannot be used to distinguish $a$ from $c$.

I think this arises from some genuine ambiguity in the problem - unlike normal DFA minimization, there's no reason to expect $M_C$ to be unique - two non-equivalent machines could represent languages $C \neq C'$ such that $A \cap C = A \cap C'$. It might be that those ambiguities don't matter and you can just resolve them arbitrarily, but I haven't been able to convince myself of that.

The problem is at least "reasonably tractable", as the corresponding decision problem is in NP, because such an automaton has size at most $|M_B|$, and we can determine whether a given automaton is a solution by testing its equivalence with the intersection automaton with states $M_A \times M_B$, and testing equivalence is in $P$. There's almost certainly some nice transformation into SAT or ILP that I haven't worked through yet because I'm hoping for a better solution.

Is this some well studied problem? Or can it be reduced to one?

$M_C$ must accept every word of $S^+ = B$ and reject every word of $S^- = A \setminus B$.
Let $A$ and $B$ be finite and such that both $S^+$ and $S^-$ are non-empty. Then exact computation of $M_C$ is NP-hard.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9400933,"math_prob":0.99658614,"size":2131,"snap":"2021-43-2021-49","text_gpt3_token_len":541,"char_repetition_ratio":0.10343207,"word_repetition_ratio":0.0,"special_character_ratio":0.24870953,"punctuation_ratio":0.080882356,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.999658,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-01T03:39:02Z\",\"WARC-Record-ID\":\"<urn:uuid:659d1b02-0604-4aaf-9ea4-67e720c836e0>\",\"Content-Length\":\"136176\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:03e4b627-3366-4683-9a36-ee4ec422d2e2>\",\"WARC-Concurrent-To\":\"<urn:uuid:10c5e43e-f252-4eb6-ba14-9143aea6a7e5>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://cstheory.stackexchange.com/questions/40783/finding-a-minimal-dfa-whose-language-has-a-desired-intersection-with-another/40785\",\"WARC-Payload-Digest\":\"sha1:DWAYLWLEUJRGKNUYOXZZVNN62OH5TULL\",\"WARC-Block-Digest\":\"sha1:A22DVJQFUOTHWUEXSB2DRRVZWYTYDCLU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964359082.78_warc_CC-MAIN-20211201022332-20211201052332-00158.warc.gz\"}"}