Documentation

CslibFrontier.Algorithms.WordRAM.CYK

Word-RAM Cocke–Younger–Kasami parsing #

Checked Word-RAM implementation and O((|R| + 1)(|w| + 1)³) running-time bound (with constant 21-instruction handling of the empty word) for the Cocke–Younger–Kasami membership algorithm of CslibFrontier.Algorithms.Lean.CYK.Basic on grammars in Chomsky normal form.

An encoded instance (CYKInstance) presents a Chomsky normal form grammar over nonterminals Fin numNTs and natural-number terminals ℕ, together with an input word word : List ℕ. In State.init I.encode, the header [numNTs, initial, nilRule, |R|, |w|] is followed by 4 |R| words encoding the rules ([0, A, a, 0] for leaf A a and [1, A, B, C] for node A B C) and |w| terminal words. Above the input (dpBase = I.encode.length + 1), all memory cells are 0 in State.init; the program maintains an n × n × numNTs Boolean membership table at dpBase + ((l - 1) * n + i) * numNTs + A, scanning all |R| rules for each of the n length-one subwords and each of the C(n + 1, 3) pairs (i, l, k) of a longer subword and split point.

Main definitions #

Main results #

References #

Problem instances and flat word encoding #

Four-word encoding of a Chomsky normal form rule over terminals ℕ and nonterminals Fin V: [0, A, a, 0] for leaf A a and [1, A, B, C] for node A B C.

An encoded Chomsky normal form membership instance for the Word-RAM: nonterminals Fin numNTs, natural-number terminal words, a rule list satisfying the standard nilRule invariant, and an input word word : List ℕ.

@[reducible, inline]

View I as a ChomskyNormalFormGrammar ℕ.

Word-RAM input layout [numNTs, initial, nilRule, |rules|, |word|] ++ encodeRules ++ word.

@[reducible, inline]

Word-width condition for CYKInstance: input addresses and the |w| × |w| × numNTs Boolean CYK table fit in w bits.

Step budget of cykProgram on I: 21 instructions on the empty word and 42 (|R| + 1) |w|³ instructions on nonempty words.

Uniform cubic upper bound across both empty and nonempty words.

Register layout and structured CYK program #

Fixed standard-basis Word-RAM program computing (cyk I.grammar I.word).toNat and deciding I.word ∈ I.grammar.toCFG.language.

Input-slice and table-address helpers #

Setup and invariant predicates #

Execution of a counted loop followed by a counter increment #

Execution of the leaf level (d = 0) #

Execution of the node levels (1 ≤ d < |w|) #

Top-level execution and public running-time theorems #

Word-RAM functional running time of CYK. cykProgram computes (cyk I.grammar I.word).toNat in at most I.timeBound instructions (21 on [], and 42 (|R| + 1) |w|³ on nonempty words) at every fitting word width w.

Word-RAM decision running time of CYK. cykProgram decides membership in I.grammar.toCFG.language within I.timeBound instructions (21 on [], and 42 (|R| + 1) |w|³ on nonempty words) at every fitting word width w.

Uniform cubic Word-RAM decidability of CYK. Membership in the language of an encoded Chomsky normal form grammar is uniformly decidable on a standard-basis Word-RAM in at most 42 (|R| + 1) (|w| + 1)³ instructions, bundling width admissibility CYKInstance.inputAdmissible.