## 2 Formal Definitions  
We assume the reader is familiar with basic terms of context-free grammars. An introduction  
\(G\) is called _consistent_ iff \(\sum_{w\in L(G)}\mathcal{P}(w)=1\), i.e., it defines a probability distribution on \(\mathcal{L}(G)\). To avoid the confusion of having two names for the same parameters, we will throughout this paper talk of probabilities on words and derivations even for (possibly) inconsistent grammars where there is no (guaranteed) probability distribution and the respective values thus would be more appropriately called weights._  
As stated in the introduction we want to include the length of the generated subword in the rule probabilities in order to model that the probability of bases being paired depends on how far they are apart in the primary structure. To do this we first need to define the length of a rule application formally:  
**Definition 2**. : _Let \(G=(\mathit{1}\); \(\mathit{T}\); \(\mathit{R}\); \(\mathit{S})\) a CFG, \(\Delta\) a full-parse tree for \(G\) and \(\mathcal{A}\rightarrow\) a specific rule application in \(\Delta\). The length of \(\mathcal{A}\rightarrow\) is defined as the number of terminal symbols that label the leaves of the subtree rooted at this instance of \(\mathcal{A}\) or equivalently the length of the subword eventually generated from \(\mathcal{A}\rightarrow\)._  
Now the straightforward way to make the rule probabilities depend on the length is to make the mapping \(\mathcal{P}\) bivariate, the second parameter being the length of the rule application in question, and change the constraint on the probabilities to \(\forall\mathcal{A}\in\mathit{1}\)\(\forall\mathit{1}\in\mathbb{N}:\sum_{A\rightarrow\alpha\in R}\mathcal{P}( \mathcal{A}\rightarrow\) \(\mathit{\cdot}\mathit{1})=1\). We will use this idea, but in order to ensure that our modified versions of the training algorithms provide consistent grammars--like the original versions do for SCFGs--we need some technical additions to this idea. First we note that that some combinations of rule and length can never occur in a derivation, e.g., a rule \(\mathcal{A}\rightarrow\) with length \(1\). It is reasonable to set the probability of such combinations to \(0\), which is what the training algorithms will do. This requires us to relax the condition to \(\sum_{A\rightarrow\alpha\in R}\mathcal{P}(\mathcal{A}\rightarrow\) \(\mathit{\cdot}\mathit{1})\in\{0\text{\textcent}\cdot 1\}\) in order to cover symbols for which no production can lead to a word of length \(l\). Further problems arise from the fact that while before \(\mathcal{P}(\mathcal{A}\rightarrow\) ) expressed the probability that a parse tree with root \(\mathcal{A}\) starts with rule \(\mathcal{A}\rightarrow\), now \(\mathcal{P}(\mathcal{A}\rightarrow\) \(\mathit{\cdot}\mathit{1})\) expresses the probability that a parse tree with root \(\mathcal{A}\) starts with rule \(\mathcal{A}\rightarrow\), _given that_ it generates a word of length \(l\), but our model currently does not include the probabilities that a parse tree generates a word of a given length. As an example consider the grammar characterised by the rules \(S\rightarrow\mathcal{A}\mathcal{A}\), \(\mathcal{A}\rightarrow\)\(\mathit{a}\mathcal{A}\) and \(\mathcal{A}\rightarrow\). Here for each combination of intermediate symbol and length only one rule is applicable, leading to \(\mathcal{P}(\mathit{\cdot}\mathit{1})=1\) if \(r\) can lead to a word of length \(l\) and \(\mathcal{P}(\mathit{\cdot}\mathit{1})=0\) if it cannot. Thus for this grammar each parse tree will have \"probability\" 1 and each word will have a \"probability\" equal to its degree of ambiguity.