## Show that the language is decidable - dfa

How do I show this language
{<C,A,B> | C,A,B are DFAs, L(C) contains the shuffle of L(A) and L(B)}
is decidable ?
I believe if I can construct automatas for A and B, then I can get an automata that contains the shuffle of them.
I am also thinking about using emptiness testing but I have not made any progress yet.

Given DFAs A and B, construct a DFA D such that L(D) is equal to the shuffle of L(A) and L(B).
Then, construct two DFAs using the Cartesian Product Machine construction for the languages L(M1) = L(C) \ L(D) and L(M2) = L(D) \ L(C).
Determine which, if either of L(M1) and/or L(M2) is empty.
if L(M1) is empty and L(M2) is empty, L(C) is the shuffle of L(A) and L(B)
if L(M1) is empty, L(C) is a subset of the shuffle of L(A) and L(B)
if L(M2) is empty, L(C) is a superset of the shuffle of L(A) and L(B)
To do #1: create a new DFA whose states are triples (x, y, z) where:
x is a state from A
y is a state from B
z is either 1 or 2
The initial state of the DFA will be (qi_A, qi_B, 1). The input alphabet will be the union of the input alphabets of A and B. The transitions will be such that:
f((x,y,1), a) = (x',y,2) where f(x,a) = x' in machine A
f((x,y,2), b) = (x,y',1) where f(y,b) = y' in machine B
The accepting states shall be the states with are accepting in either A or B (or just B if you prefer).
To do #2: create a new DFA whose states are pairs (x, y) where:
x is a state from D
y is a state from C
The initial state of he DFA will be (qi_D, qi_C). The input alphabet will be the union of input alphabets of A and C. The transitions will be such that:
f((x,y),c) = (x',y') where f(x,c) = x' in D and f(y,c) = y' in C.
The accepting states will be:
states that are accepting in D but not C, for L(D) \ L(C)
states that are accepting in C but not D, for L(C) \ L(D)
To do #3:
You can minimize the DFAs using the well-known DFA minimization algorithm. Iff you end up with a DFA that has a single non-accepting state, the language is empty.
You can try all input strings up to the pumping length for the resulting DFA (strings that don't cause the DFA to enter any state more than once). If none of these are accepted by the DFA, then the DFA accepts no strings and the language is empty.

## Related

### Why is this DFA not accepted?

So I am supposed to construct a DFA that accepts sets of all strings over {0,1} of length 2: So sigma = {0,1} L = {00, 01, 10, 11} What I initially tried was : Why is it wrong?

Assuming B is final state, it can even accept string of length 1. Thats why. Add one more state to mark length 2 and it should be good. A 0,1 B 0,1 (C) 0,1 D ( ) - accepted state Also make sure anything more than length 3 results in non terminal state by adding a D.

This is the DFA you want: This way, if another input symbol is present after the second one - you go from C to D and can never go back to an accepting state. By the way, and perhaps more importantly - I didn't draw this image myself. I used graphviz, which is a neet tool you might use to visualize your DFAs. The code is: digraph G { node [shape="circle"]; Start [shape="none" label=""]; C [shape="doublecircle"]; Start -> A; A -> B [label="0,1"]; B -> C [label="0,1"]; C -> D [label="0,1"]; D -> D [label="0,1"]; } and there are online renderers even, like this one. The "Start" node is a hack to get an arrow to point at the initial state of the DFA (this is why the image is centered on B despite there being 4 states).

### Union and intersection of two languages

Given the language L1 = {(i|l)p(f|g)n(f|h)m(f|i)r(l|m)p : n + m > r > 0, p >= 0} and L2 = (f|g)*(h|i)+ make an automaton for L1 ∪ L2 and (another one for) L1 ∩ L2. I know that the L1 is a CFL and you need a PDA to parse it and I know that L2 is a RL and a DFA is to be used. My question is: how do you make the intersection (and the union)? That is, what is the actual language L3 = L1 ∩ L2 on which you make the automaton and how do you compute it?

Union is easy - if you have PDAs for two languages, a nondeterministic PDA that accepts the union can be had by introducing a new initial state with epsilon transitions to each of the initial states of the automata for your languages. The accepted language will be exactly whatever is accepted by either (or both) automata. Intersection is a little more tricky. Now, you say you want an automaton - that could refer to any theoretical machine, including Turing machines or, equivalently, two-stack PDAs. If you are OK with creating a two-stack PDA then your task is straightforward. Use the Cartesian product machine construction used to construct a DFA for A and B given DFAs for A and B, and have each transition of the form ((a, b), w) -> (a', b') push a symbol (x, y) onto the stack iff (a, w)->a' pushes x onto A's stack and (b, w)->b' pushes y onto B's stack. Of course, if you start with a DFA for the RL and perform the above construction you only need one stack and the resulting automaton is a PDA, not a two-stack PDA.

### What does the perm_invK lemma in Ssreflect prove?

The following code is from perm.v in the Ssreflect Coq library. I want to know what this result is. Lemma perm_invK s : cancel (fun x => iinv (perm_onto s x)) s. Proof. by move=> x /=; rewrite f_iinv. Qed.

Definitions in Ssreflect can involve lots of concepts, and sometimes it is hard to understand what is actually going on. Let's analyze this by parts. iinv (defined in fintype.v) has type iinv : forall (T : finType) (T' : eqType) (f : T -> T') (A : pred T) (y : T'), y \in [seq f x | x in A] -> T What this does is to invert any function f : T -> T' whose restriction to a subdomain A \subset T is surjective on T'. Put in other words, if you give me an y that is in the list of results of applying f to all elements of A, then I can find you an x \in A such that f x = y. Notice that this relies crucially on the fact that T is a finite type and that T' has decidable equality. The correctness of iinv is stated in lemma f_iinv, which is used above. perm_onto has type codom s =i predT, where s is some permutation defined on a finite type T. This is saying, as its name implies, that s is surjective (which is obvious, since it is injective, by the definition of permutations in perm.v, and by the fact that the domain and codomain are the same). Thus, fun x => iinv (perm_onto s x) is a function that maps an element x to an element y such that s y = x. In other words, its the inverse of s. perm_invK is simply stating that this function is indeed the inverse (to be more precise, it is saying that it is the left inverse of s). The definition that is actually useful, however, is perm_inv, which appears right below. What it does is that it packages fun x => iinv (perm_onto s x) with its proof of correctness perm_invK to define an element of perm_inv s of type {perm T} such that perm_inv s * s = s * perm_inv s = 1. Thus, you can view it as saying that the type {perm T} is closed under inverses, which allows you to use a lot of the ssr machinery for e.g. finite groups and monoids.

### Regular Languages and Concatenation

Regular languages are closed under concatenation - this is demonstrable by having the accepting state(s) of one language with an epsilon transition to the start state of the next language. If we consider the language L = {a^n | n >=0}, this language is regular (it is simply a*). If we concatenate it with another language L = {b^n | n >=0}, which is also regular, we end up with a^nb^n, but we obviously know this isn't regular. Where am I going wrong with my logic here?

The definition of the concatenation of two languages L1 and L2 is the set of all strings wx where w ∈ L1 and x ∈ L2. This means that L1L2 consists of all possible strings formed by pairing one string from L1 and one string from L2, which isn't necessarily the same as pairing up matching strings from each language. As a result, as #Oli Charlesworth pointed out, the language you get back here isn't actually { anbn | n in N }. Instead, it's the language { anbm | n in N and m in N }, which is the language a*b*. This language is regular, since it's given by the regular languages. Hope this helps!

### Concatenation of a infinite language and a finite language

Why is it that the concatenation of a infinite language and a finite language always finite iff the language is not the empty set? I thought concatenating an infinite language with the empty set would just be the infinite language.

This statement is false. Try concatenating Σ* and Σ. This gives back Σ+, which is infinite. I think that you meant The concatenation of an infinite language I and a finite language F is infinite iff F ≠ ∅ This statement is true. If F = ∅ then IF is the empty set because the concatenation of any language and the empty language is the empty language. Specifically, IF = { wx | w in I and x in F }, so if F is empty, there are no x's that satisfy the condition x in F. On the other hand, if x ≠ ∅ we can prove that IF is infinite. Consider any string w ∈ I whose length is longer than any string in F. Then the set wF = { wx | x in F } is infinite because there's at least one string in wF in-between any two multiples of |w|. Since wF ⊆ IF, this means that IF is infinite. Hope this helps!