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 #
Cslib.Algorithms.WordRAM.CYK.encodeRule: four-word encoding of a Chomsky normal form rule.Cslib.Algorithms.WordRAM.CYK.CYKInstance: a Chomsky normal form grammar overFin numNTsandℕpaired with an input word, its word layoutCYKInstance.encode, its time boundCYKInstance.timeBound, and its word-width conditionCYKInstance.FitsWidth.Cslib.Algorithms.WordRAM.CYK.cykProgram: fixedProgram .standard 24deciding membership inI.grammar.toCFG.language.
Main results #
Cslib.Algorithms.WordRAM.CYK.computesInTime_cyk:cykProgramcomputes(cyk I.grammar I.word).toNatwithinI.timeBoundinstructions (21on[], and42 (|R| + 1) |w|³on nonempty words) at every fitting width.Cslib.Algorithms.WordRAM.CYK.decidesInTime_cyk:cykProgramdecides{I | I.word ∈ I.grammar.toCFG.language}withinI.timeBoundinstructions at every fitting width.Cslib.Algorithms.WordRAM.CYK.uniformDecidableInTime_cyk: uniform Word-RAM decidability of{I | I.word ∈ I.grammar.toCFG.language}in42 (|R| + 1) (|w| + 1)³instructions, bundling width admissibility (CYKInstance.inputAdmissible).
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.
View I as a ChomskyNormalFormGrammar ℕ.
Concatenated 4-word encodings of I.rules.
Word-RAM input layout [numNTs, initial, nilRule, |rules|, |word|] ++ encodeRules ++ word.
Word-width condition for CYKInstance: input addresses and the |w| × |w| × numNTs Boolean
CYK table fit in w bits.
Every CYKInstance admits a fitting word width.
Step budget of cykProgram on I: 21 instructions on the empty word and
42 (|R| + 1) |w|³ instructions on nonempty words.
Register layout and structured CYK program #
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.