Abstract. We consider commutative regular and context-free grammars, or, in other words, Parikh images of regular and context-free languages. By using linear algebra and a branching analog of the classic Euler theorem, we show that, under an assumption that the terminal alphabet is fixed, the membership problem for regular grammars (given v in binary and a regular commutative grammar G, does G generate v?) is P, and that the equivalence problem for context free grammars (do G1 and G2 generate the same language?) is in Π P 2 .
IntroductionLet Σ be a finite alphabet. By Σ * we denote the set of words over Σ, or finite sequences of elements of Σ. For a word w ∈ Σ * , by Ψ(w) (the Parikh image of w) we denote the function from Σ to non-negative integers N, such that eachContext free and regular languages are one of the most important classes of languages in computer science [HU79]. By a famous result of Parikh [Par66], a subset of N Σ is a Parikh image of a context free language if and only if it is a semilinear set, or a union of finitely many linear sets.In this paper, we explore the complexity of various problems related to Parikh images of context free languages, such as the following:• Membership: Given a context-free grammar G and v ∈ N Σ (given in binary). Is v a member of the Ψ(G), the Parikh image of the language generated by G? • Universality: Given two context-free grammars G, is Ψ(G) equal to N Σ ?• Inclusion: Given two context-free grammars G 1 and G 2 , does Ψ(G 1 ) ⊆ Ψ(G 2 )?• Equality: Given two context-free grammars G 1 and G 2 , does Ψ(G 1 ) = Ψ(G 2 )?• Disjointness: Given two context-free grammars G 1 and G 2 , is Ψ(G 1 ) ∩ Ψ(G 2 ) nonempty?Since in this paper we are never interested in the order of terminals or non-terminals, we treat everything in a commutative way. This allows us to identify the commutative languages (subsets of Σ * ) with their Parikh images (subsets of N Σ ).