Luckily, we can exploit the structure of the problem to efficiently compute the partition function, where T (u) is the set of all trees under the grammar that have yield u.
we make use of the inside algorithm, which is just CKY (Aho and Ullman, 1979) in the (+, ×) semiring (Goodman, 1998), which runs in O(|G| • |u| 3 ) time, where |G| is the size of the grammar.