<p>Thank you very much for posting this question!</p>

<p>I am very enthusiastic about these kinds of research problems.  Although I don't have a precise answer, I think that the following will be of help.</p>

<p><strong>The Input Format Matters</strong></p>

<p>A context-free language can be represented as CFG or a PDA.  Given that there is a polynomial blow-up in converting from one form to another, we have to be particular about whether $n$ denotes the number of non-terminals from the CFG or the number of states from the PDA.</p>

<p>Similarly, for regular languages, $n$ could denote the length of the regular expression or the number of states from the DFA.</p>

<p>Given that I am personally more comfortable with automata, I will assume that the inputs are given as automata and $n$ will denote the number of states from the larger (or largest) automaton.</p>

<p><strong>A More General Problem</strong></p>

<blockquote>
  <p>Consider that we are given a PDA $P$ and $k$ DFA's $D_1, D_2, ..., D_k$.</p>
  
  <p>If we are promised that the intersection of these automata is non-empty (that is, $L(P) \cap \bigcap_{i\in [k]} L(D_i)$ is non-empty), then in terms of $n$ and $k$, what is the length of the shortest string in the intersection?</p>
</blockquote>

<p>Now, you may ask, in the worst case, how large can this shortest string be?  It turns out that there is a constant $c \leq 1$ such that it is always possible to construct a PDA $P$ and DFA's $D_1, D_2, ..., D_k$ so that the shortest string in the intersection has length $2^{n^{c \cdot k}}$.</p>

<p><strong>Note:</strong> You will see where $c$ comes from below, but you can probably make it close to $1$.  Maybe even $1 - \varepsilon$?</p>

<p><strong>Construction</strong></p>

<blockquote>
  <p><strong>Disclaimer:</strong> This is one possible construction although, it might not be the
  preferred construction nor is it necessarily optimal.  One interesting thing about the construction is that there is only one string in the intersection.  The
  construction is inspired by <a href="http://dl.acm.org/citation.cfm?id=321625" rel="nofollow noreferrer">Cook (1971)</a>.</p>
</blockquote>

<p>Let a number $n$ be given.  Consider an auxiliary pushdown automaton.  That is, a state machine with a stack and a bounded work tape.</p>

<p>If we have $k\log(n)$ bits on the work tape, then we can represent any integer from $1$ to $n^k$.  You can use this integer to represent a stack height.  Now, it is possible to design an auxiliary pushdown automaton with only $k\log(n)$ bits of memory on the tape that counts from $1$ to $2^{n^k}$ and then accepts.  It does this by enumerating through every single configuration of the stack of height at most $n^k$ where the current height is always stored in the $k\log(n)$ bits on the work tape.</p>

<blockquote>
  <p>Please let me know if you need more detail in the preceding description.  Otherwise, we will continue our construction.</p>
</blockquote>

<p>Now that we have an auxiliary pushdown automaton with only $k\log(n)$ bits on the work tape that runs for $2^{n^k}$ steps before accepting, we can construct $P$ along with $D_1, D_2, ..., D_k$.  This construction is inspired by <a href="http://dl.acm.org/citation.cfm?id=1382559" rel="nofollow noreferrer">Kozen (1977)</a> and related works.</p>

<p>The idea is to build the PDA and DFA's to read in a string that encodes a computation of the auxiliary pushdown automaton.  The computation is accepting if and only if the PDA and DFA's all accept its encoding.</p>

<p>The computation is a sequence of configurations.  Each configuration can be encoded by a string so that all of the strings concatenated together make up the computations encoding.  Then, the DFA's each are assigned to a $\log(n)$ length chunk of the work tape and verify that the computation for their respective chunk of the work tape carries on correctly.  Finally, the PDA pushes, pops, and peeks, as is instructed by the configurations and simultaneously verifies that what is on the stack actually matches what the configuration says is on top of the stack.  They accept if both their respective verification is successful and the accepting configuration is reached.</p>

<p>Because the auxiliary pushdown automaton requires a computation of length $2^{n^k}$, the smallest string in the intersection has length at least $2^{n^k}$.  And, although it wasn't discussed in detail, the automata can be built to have polynomial in $n$ states.  The smaller the degree of the polynomial, the closer that $c$ can be made to 1.</p>

<p><strong>Other Works</strong></p>

<ul>
<li><p>There is a great <a href="https://uwspace.uwaterloo.ca/handle/10012/5162" rel="nofollow noreferrer">master's thesis</a> by Thomas Ang on the length of the
shortest string in the intersection of regular languages.</p></li>
<li><p>Also, I made a small contribution to <a href="http://link.springer.com/chapter/10.1007/978-3-662-49630-5_27" rel="nofollow noreferrer">a paper</a> with D. Chistikov, W.
Czerwinski, P. Hofman, and M. Pilipczuk where we show that the
shortest string accepted by a one counter automaton has length at most $c
   n^2$ for an appropriate constant $c$ (the previously known upper bound was $n^3$).</p></li>
</ul>

<p>Dmitry and I have been discussing for a couple years about what the upper bound is for the shortest string accepted by a PDA.  You can get a lower bound of $2^n$ and an upper bound of $2^{n^2}$, but can you improve either of these bounds?  Even just a small improvement on the upper bound to $2^{\frac{n^2}{\log(n)}}$ would be a breakthrough.</p>

<p>Sorry for such a long reply and for excluding many details.  Feel free to shoot me an email if you would like to discuss offline.  Thank you and I hope you have a great week!</p>

CC BY-SA 3.0
2017-02-08T21:41:45.690Z
Thank you for the answer! If we just take the product construction of all those DFAs. You have shown that there is some constant $c$, such that exist $L$($k$ state PDA) and $R$($n$ state DFA), where the shortest string in $L\cap R$ has length at least $2^{cnk}$ for some $c$.
Chao Xu
CC BY-SA 3.0
2017-02-09T05:23:11.937Z
Yes, that is a great insight.  Thank you for sharing the comment.  :)
Michael Wehar
CC BY-SA 3.0
2017-02-09T05:25:30.257Z
In other words, our current upper bound for your problem is $2^{kn^2}$ and we can likely get a lower bound of $2^{kn}$.  If anyone can get closer to closing this gap, please let us know!  :)
Michael Wehar
CC BY-SA 3.0
2017-02-08T04:39:53.617Z
2017-02-09T05:18:51.530Z
2017-02-09T05:18:51.530Z
Michael Wehar
<p>For a language $X$, define $ss(X) = \min_{x\in X} |x|$, the length of the shortest string in $X$. For simplicity, we define $ss(\emptyset)=0$.
Let $L$ be a context-free language generated by a context-free grammar with $k$ non-terminals. (assuming all context-free grammars are in Chomsky normal form.)
Let $R$ be a regular language recognized by an NFA of $n$ states.</p>

<blockquote>
  <p>What is $ss(L\cap R)$, the length of the shortest string in $L\cap R$?</p>
</blockquote>

<p>A naive upper bound is $2^{kn^2}$: find a context-free grammar for $L\cap R$ with $kn^2$ non-terminals. </p>

<p><strong>Motivation</strong>: Answer to the above question can lead to a better bound for the following problem.</p>

<p>Let $L$ be a fixed context-free language. Let $\mathcal{R}_n$ to be all the set of all regular languages that can be recognized by an NFA of $n$ states.</p>

<p>Define $f_L(n) = \max_{R\in \mathcal{R}_n} ss(L\cap R)$.</p>

<blockquote>
  <p>What can we say about the asymptotics of $f_L(n)$?</p>
</blockquote>

<p>Using the naive bound, we know $f_L(n) = O(2^{n^2})$.</p>

CC BY-SA 3.0
2017-02-11T05:48:49.637Z
Chao and I began discussing offline and found the following relevant paper: https://arxiv.org/abs/1502.02242
Michael Wehar
CC BY-SA 4.0
2020-04-11T17:25:54.000Z
This post is quite related: https://cstheory.stackexchange.com/questions/45915/maximum-shortest-word-accepted-by-pushdown-automata
Michael Wehar
CC BY-SA 4.0
2020-04-11T17:27:26.477Z
If the context-free language is fixed, then I believe that this is the same as rational index.  Tight bounds are known for the rational indexes of context-free languages.  The bound is $2^{\Theta(\frac{n^2}{log(n)})}$.  See "Rational indexes of generators of the cone of context-free languages" by Pierre, Laurent and "The rational index of the Dyck language (D_ 1^{’*})" by Deleage, Jean-Luc and Pierre, Laurent.
Michael Wehar
<fl.formal-languages><automata-theory>
Shortest string in the intersection of a context-free language and a regular language
Chao Xu
# Shortest string in the intersection of a context-free language and a regular language

(Asked by: username_0 on 2017-02-07)

For a language $X$, define $ss(X) = \min\_{x\in X} |x|$, the length of the shortest string in $X$. For simplicity, we define $ss(\emptyset)=0$.
Let $L$ be a context-free language generated by a context-free grammar with $k$ non-terminals. (assuming all context-free grammars are in Chomsky normal form.)
Let $R$ be a regular language recognized by an NFA of $n$ states.

> What is $ss(L\cap R)$, the length of the shortest string in $L\cap R$?

A naive upper bound is $2^{kn^2}$: find a context-free grammar for $L\cap R$ with $kn^2$ non-terminals.

**Motivation**: Answer to the above question can lead to a better bound for the following problem.

Let $L$ be a fixed context-free language. Let $\mathcal{R}\_n$ to be all the set of all regular languages that can be recognized by an NFA of $n$ states.

Define $f\_L(n) = \max\_{R\in \mathcal{R}\_n} ss(L\cap R)$.

> What can we say about the asymptotics of $f\_L(n)$?

Using the naive bound, we know $f\_L(n) = O(2^{n^2})$.

**Tags:** fl.formal-languages, automata-theory
> **Comments:**
> **username_1**: Chao and I began discussing offline and found the following relevant paper: https://arxiv.org/abs/1502.02242  
> **username_1**: This post is quite related: https://cstheory.stackexchange.com/questions/45915/maximum-shortest-word-accepted-by-pushdown-automata  
> **username_1**: If the context-free language is fixed, then I believe that this is the same as rational index.  Tight bounds are known for the rational indexes of context-free languages.  The bound is $2^{\Theta(\frac{n^2}{log(n)})}$.  See "Rational indexes of generators of the cone of context-free languages" by Pierre, Laurent and "The rational index of the Dyck language (D_ 1^{’*})" by Deleage, Jean-Luc and Pierre, Laurent.  

---

## 1 answers

### Answer by username_1 on 2017-02-08. Score: 5 | Accepted answer

Thank you very much for posting this question!

I am very enthusiastic about these kinds of research problems. Although I don't have a precise answer, I think that the following will be of help.

**The Input Format Matters**

A context-free language can be represented as CFG or a PDA. Given that there is a polynomial blow-up in converting from one form to another, we have to be particular about whether $n$ denotes the number of non-terminals from the CFG or the number of states from the PDA.

Similarly, for regular languages, $n$ could denote the length of the regular expression or the number of states from the DFA.

Given that I am personally more comfortable with automata, I will assume that the inputs are given as automata and $n$ will denote the number of states from the larger (or largest) automaton.

**A More General Problem**

> Consider that we are given a PDA $P$ and $k$ DFA's $D\_1, D\_2, ..., D\_k$.
>
> If we are promised that the intersection of these automata is non-empty (that is, $L(P) \cap \bigcap\_{i\in [k]} L(D\_i)$ is non-empty), then in terms of $n$ and $k$, what is the length of the shortest string in the intersection?

Now, you may ask, in the worst case, how large can this shortest string be? It turns out that there is a constant $c \leq 1$ such that it is always possible to construct a PDA $P$ and DFA's $D\_1, D\_2, ..., D\_k$ so that the shortest string in the intersection has length $2^{n^{c \cdot k}}$.

**Note:** You will see where $c$ comes from below, but you can probably make it close to $1$. Maybe even $1 - \varepsilon$?

**Construction**

> **Disclaimer:** This is one possible construction although, it might not be the
> preferred construction nor is it necessarily optimal. One interesting thing about the construction is that there is only one string in the intersection. The
> construction is inspired by [Cook (1971)](http://dl.acm.org/citation.cfm?id=321625).

Let a number $n$ be given. Consider an auxiliary pushdown automaton. That is, a state machine with a stack and a bounded work tape.

If we have $k\log(n)$ bits on the work tape, then we can represent any integer from $1$ to $n^k$. You can use this integer to represent a stack height. Now, it is possible to design an auxiliary pushdown automaton with only $k\log(n)$ bits of memory on the tape that counts from $1$ to $2^{n^k}$ and then accepts. It does this by enumerating through every single configuration of the stack of height at most $n^k$ where the current height is always stored in the $k\log(n)$ bits on the work tape.

> Please let me know if you need more detail in the preceding description. Otherwise, we will continue our construction.

Now that we have an auxiliary pushdown automaton with only $k\log(n)$ bits on the work tape that runs for $2^{n^k}$ steps before accepting, we can construct $P$ along with $D\_1, D\_2, ..., D\_k$. This construction is inspired by [Kozen (1977)](http://dl.acm.org/citation.cfm?id=1382559) and related works.

The idea is to build the PDA and DFA's to read in a string that encodes a computation of the auxiliary pushdown automaton. The computation is accepting if and only if the PDA and DFA's all accept its encoding.

The computation is a sequence of configurations. Each configuration can be encoded by a string so that all of the strings concatenated together make up the computations encoding. Then, the DFA's each are assigned to a $\log(n)$ length chunk of the work tape and verify that the computation for their respective chunk of the work tape carries on correctly. Finally, the PDA pushes, pops, and peeks, as is instructed by the configurations and simultaneously verifies that what is on the stack actually matches what the configuration says is on top of the stack. They accept if both their respective verification is successful and the accepting configuration is reached.

Because the auxiliary pushdown automaton requires a computation of length $2^{n^k}$, the smallest string in the intersection has length at least $2^{n^k}$. And, although it wasn't discussed in detail, the automata can be built to have polynomial in $n$ states. The smaller the degree of the polynomial, the closer that $c$ can be made to 1.

**Other Works**

* There is a great [master's thesis](https://uwspace.uwaterloo.ca/handle/10012/5162) by Thomas Ang on the length of the
  shortest string in the intersection of regular languages.
* Also, I made a small contribution to [a paper](http://link.springer.com/chapter/10.1007/978-3-662-49630-5_27) with D. Chistikov, W.
  Czerwinski, P. Hofman, and M. Pilipczuk where we show that the
  shortest string accepted by a one counter automaton has length at most $c
  n^2$ for an appropriate constant $c$ (the previously known upper bound was $n^3$).

Dmitry and I have been discussing for a couple years about what the upper bound is for the shortest string accepted by a PDA. You can get a lower bound of $2^n$ and an upper bound of $2^{n^2}$, but can you improve either of these bounds? Even just a small improvement on the upper bound to $2^{\frac{n^2}{\log(n)}}$ would be a breakthrough.

Sorry for such a long reply and for excluding many details. Feel free to shoot me an email if you would like to discuss offline. Thank you and I hope you have a great week!

> **Comments:**
> **username_0**: Thank you for the answer! If we just take the product construction of all those DFAs. You have shown that there is some constant $c$, such that exist $L$($k$ state PDA) and $R$($n$ state DFA), where the shortest string in $L\cap R$ has length at least $2^{cnk}$ for some $c$.  
> **username_1**: Yes, that is a great insight.  Thank you for sharing the comment.  :)  
> **username_1**: In other words, our current upper bound for your problem is $2^{kn^2}$ and we can likely get a lower bound of $2^{kn}$.  If anyone can get closer to closing this gap, please let us know!  :)  

---

