pi[i,j,A] holds the maximum probability for a constituent with non-terminal index A spanning words i through j For example, p[2,4,NP] holds the maximum probability for an NP spanning words 2 through 4 Nonterminals: ['S', 'NP', 'VP', 'V', 'PP', 'P'] Words: ['John', 'called', 'Mary', 'from', 'Denver'] The Grammar: NP --> Mary VP --> VP PP NP --> John V --> called PP --> P NP NP --> Denver S --> NP VP VP --> V NP P --> from NP --> NP PP Base cases If S --> John is in grammar then pi[ 1 1 S ] = P( S --> John ) If NP --> John is in grammar then pi[ 1 1 NP ] = P( NP --> John ) If VP --> John is in grammar then pi[ 1 1 VP ] = P( VP --> John ) If V --> John is in grammar then pi[ 1 1 V ] = P( V --> John ) If PP --> John is in grammar then pi[ 1 1 PP ] = P( PP --> John ) If P --> John is in grammar then pi[ 1 1 P ] = P( P --> John ) If S --> called is in grammar then pi[ 2 2 S ] = P( S --> called ) If NP --> called is in grammar then pi[ 2 2 NP ] = P( NP --> called ) If VP --> called is in grammar then pi[ 2 2 VP ] = P( VP --> called ) If V --> called is in grammar then pi[ 2 2 V ] = P( V --> called ) If PP --> called is in grammar then pi[ 2 2 PP ] = P( PP --> called ) If P --> called is in grammar then pi[ 2 2 P ] = P( P --> called ) If S --> Mary is in grammar then pi[ 3 3 S ] = P( S --> Mary ) If NP --> Mary is in grammar then pi[ 3 3 NP ] = P( NP --> Mary ) If VP --> Mary is in grammar then pi[ 3 3 VP ] = P( VP --> Mary ) If V --> Mary is in grammar then pi[ 3 3 V ] = P( V --> Mary ) If PP --> Mary is in grammar then pi[ 3 3 PP ] = P( PP --> Mary ) If P --> Mary is in grammar then pi[ 3 3 P ] = P( P --> Mary ) If S --> from is in grammar then pi[ 4 4 S ] = P( S --> from ) If NP --> from is in grammar then pi[ 4 4 NP ] = P( NP --> from ) If VP --> from is in grammar then pi[ 4 4 VP ] = P( VP --> from ) If V --> from is in grammar then pi[ 4 4 V ] = P( V --> from ) If PP --> from is in grammar then pi[ 4 4 PP ] = P( PP --> from ) If P --> from is in grammar then pi[ 4 4 P ] = P( P --> from ) Here are the 1-word assignments that are made (the rest are set to 0) pi[ 1 1 NP ] = P( NP --> John ) pi[ 2 2 V ] = P( V --> called ) pi[ 3 3 NP ] = P( NP --> Mary ) pi[ 4 4 P ] = P( P --> from ) Recursive cases (not printing entries for rules A --> B C not in the grammar) prob = pi[1,1,NP] * pi[2,2,VP] * P(S --> NP VP) if pi[1,2,S] < prob then update it to prob and save back[1,2,S] = <1,NP,VP> prob = pi[1,1,NP] * pi[2,2,PP] * P(NP --> NP PP) if pi[1,2,NP] < prob then update it to prob and save back[1,2,NP] = <1,NP,PP> prob = pi[1,1,VP] * pi[2,2,PP] * P(VP --> VP PP) if pi[1,2,VP] < prob then update it to prob and save back[1,2,VP] = <1,VP,PP> prob = pi[1,1,V] * pi[2,2,NP] * P(VP --> V NP) if pi[1,2,VP] < prob then update it to prob and save back[1,2,VP] = <1,V,NP> prob = pi[1,1,P] * pi[2,2,NP] * P(PP --> P NP) if pi[1,2,PP] < prob then update it to prob and save back[1,2,PP] = <1,P,NP> prob = pi[2,2,NP] * pi[3,3,VP] * P(S --> NP VP) if pi[2,3,S] < prob then update it to prob and save back[2,3,S] = <2,NP,VP> prob = pi[2,2,NP] * pi[3,3,PP] * P(NP --> NP PP) if pi[2,3,NP] < prob then update it to prob and save back[2,3,NP] = <2,NP,PP> prob = pi[2,2,VP] * pi[3,3,PP] * P(VP --> VP PP) if pi[2,3,VP] < prob then update it to prob and save back[2,3,VP] = <2,VP,PP> prob = pi[2,2,V] * pi[3,3,NP] * P(VP --> V NP) if pi[2,3,VP] < prob then update it to prob and save back[2,3,VP] = <2,V,NP> prob = pi[2,2,P] * pi[3,3,NP] * P(PP --> P NP) if pi[2,3,PP] < prob then update it to prob and save back[2,3,PP] = <2,P,NP> prob = pi[3,3,NP] * pi[4,4,VP] * P(S --> NP VP) if pi[3,4,S] < prob then update it to prob and save back[3,4,S] = <3,NP,VP> prob = pi[3,3,NP] * pi[4,4,PP] * P(NP --> NP PP) if pi[3,4,NP] < prob then update it to prob and save back[3,4,NP] = <3,NP,PP> prob = pi[3,3,VP] * pi[4,4,PP] * P(VP --> VP PP) if pi[3,4,VP] < prob then update it to prob and save back[3,4,VP] = <3,VP,PP> prob = pi[3,3,V] * pi[4,4,NP] * P(VP --> V NP) if pi[3,4,VP] < prob then update it to prob and save back[3,4,VP] = <3,V,NP> prob = pi[3,3,P] * pi[4,4,NP] * P(PP --> P NP) if pi[3,4,PP] < prob then update it to prob and save back[3,4,PP] = <3,P,NP> prob = pi[4,4,NP] * pi[5,5,VP] * P(S --> NP VP) if pi[4,5,S] < prob then update it to prob and save back[4,5,S] = <4,NP,VP> prob = pi[4,4,NP] * pi[5,5,PP] * P(NP --> NP PP) if pi[4,5,NP] < prob then update it to prob and save back[4,5,NP] = <4,NP,PP> prob = pi[4,4,VP] * pi[5,5,PP] * P(VP --> VP PP) if pi[4,5,VP] < prob then update it to prob and save back[4,5,VP] = <4,VP,PP> prob = pi[4,4,V] * pi[5,5,NP] * P(VP --> V NP) if pi[4,5,VP] < prob then update it to prob and save back[4,5,VP] = <4,V,NP> prob = pi[4,4,P] * pi[5,5,NP] * P(PP --> P NP) if pi[4,5,PP] < prob then update it to prob and save back[4,5,PP] = <4,P,NP> prob = pi[1,1,NP] * pi[2,3,VP] * P(S --> NP VP) if pi[1,3,S] < prob then update it to prob and save back[1,3,S] = <1,NP,VP> prob = pi[1,1,NP] * pi[2,3,PP] * P(NP --> NP PP) if pi[1,3,NP] < prob then update it to prob and save back[1,3,NP] = <1,NP,PP> prob = pi[1,1,VP] * pi[2,3,PP] * P(VP --> VP PP) if pi[1,3,VP] < prob then update it to prob and save back[1,3,VP] = <1,VP,PP> prob = pi[1,1,V] * pi[2,3,NP] * P(VP --> V NP) if pi[1,3,VP] < prob then update it to prob and save back[1,3,VP] = <1,V,NP> prob = pi[1,1,P] * pi[2,3,NP] * P(PP --> P NP) if pi[1,3,PP] < prob then update it to prob and save back[1,3,PP] = <1,P,NP> prob = pi[1,2,NP] * pi[3,3,VP] * P(S --> NP VP) if pi[1,3,S] < prob then update it to prob and save back[1,3,S] = <2,NP,VP> prob = pi[1,2,NP] * pi[3,3,PP] * P(NP --> NP PP) if pi[1,3,NP] < prob then update it to prob and save back[1,3,NP] = <2,NP,PP> prob = pi[1,2,VP] * pi[3,3,PP] * P(VP --> VP PP) if pi[1,3,VP] < prob then update it to prob and save back[1,3,VP] = <2,VP,PP> prob = pi[1,2,V] * pi[3,3,NP] * P(VP --> V NP) if pi[1,3,VP] < prob then update it to prob and save back[1,3,VP] = <2,V,NP> prob = pi[1,2,P] * pi[3,3,NP] * P(PP --> P NP) if pi[1,3,PP] < prob then update it to prob and save back[1,3,PP] = <2,P,NP> prob = pi[2,2,NP] * pi[3,4,VP] * P(S --> NP VP) if pi[2,4,S] < prob then update it to prob and save back[2,4,S] = <2,NP,VP> prob = pi[2,2,NP] * pi[3,4,PP] * P(NP --> NP PP) if pi[2,4,NP] < prob then update it to prob and save back[2,4,NP] = <2,NP,PP> prob = pi[2,2,VP] * pi[3,4,PP] * P(VP --> VP PP) if pi[2,4,VP] < prob then update it to prob and save back[2,4,VP] = <2,VP,PP> prob = pi[2,2,V] * pi[3,4,NP] * P(VP --> V NP) if pi[2,4,VP] < prob then update it to prob and save back[2,4,VP] = <2,V,NP> prob = pi[2,2,P] * pi[3,4,NP] * P(PP --> P NP) if pi[2,4,PP] < prob then update it to prob and save back[2,4,PP] = <2,P,NP> prob = pi[2,3,NP] * pi[4,4,VP] * P(S --> NP VP) if pi[2,4,S] < prob then update it to prob and save back[2,4,S] = <3,NP,VP> prob = pi[2,3,NP] * pi[4,4,PP] * P(NP --> NP PP) if pi[2,4,NP] < prob then update it to prob and save back[2,4,NP] = <3,NP,PP> prob = pi[2,3,VP] * pi[4,4,PP] * P(VP --> VP PP) if pi[2,4,VP] < prob then update it to prob and save back[2,4,VP] = <3,VP,PP> prob = pi[2,3,V] * pi[4,4,NP] * P(VP --> V NP) if pi[2,4,VP] < prob then update it to prob and save back[2,4,VP] = <3,V,NP> prob = pi[2,3,P] * pi[4,4,NP] * P(PP --> P NP) if pi[2,4,PP] < prob then update it to prob and save back[2,4,PP] = <3,P,NP> prob = pi[3,3,NP] * pi[4,5,VP] * P(S --> NP VP) if pi[3,5,S] < prob then update it to prob and save back[3,5,S] = <3,NP,VP> prob = pi[3,3,NP] * pi[4,5,PP] * P(NP --> NP PP) if pi[3,5,NP] < prob then update it to prob and save back[3,5,NP] = <3,NP,PP> prob = pi[3,3,VP] * pi[4,5,PP] * P(VP --> VP PP) if pi[3,5,VP] < prob then update it to prob and save back[3,5,VP] = <3,VP,PP> prob = pi[3,3,V] * pi[4,5,NP] * P(VP --> V NP) if pi[3,5,VP] < prob then update it to prob and save back[3,5,VP] = <3,V,NP> prob = pi[3,3,P] * pi[4,5,NP] * P(PP --> P NP) if pi[3,5,PP] < prob then update it to prob and save back[3,5,PP] = <3,P,NP> prob = pi[3,4,NP] * pi[5,5,VP] * P(S --> NP VP) if pi[3,5,S] < prob then update it to prob and save back[3,5,S] = <4,NP,VP> prob = pi[3,4,NP] * pi[5,5,PP] * P(NP --> NP PP) if pi[3,5,NP] < prob then update it to prob and save back[3,5,NP] = <4,NP,PP> prob = pi[3,4,VP] * pi[5,5,PP] * P(VP --> VP PP) if pi[3,5,VP] < prob then update it to prob and save back[3,5,VP] = <4,VP,PP> prob = pi[3,4,V] * pi[5,5,NP] * P(VP --> V NP) if pi[3,5,VP] < prob then update it to prob and save back[3,5,VP] = <4,V,NP> prob = pi[3,4,P] * pi[5,5,NP] * P(PP --> P NP) if pi[3,5,PP] < prob then update it to prob and save back[3,5,PP] = <4,P,NP> prob = pi[1,1,NP] * pi[2,4,VP] * P(S --> NP VP) if pi[1,4,S] < prob then update it to prob and save back[1,4,S] = <1,NP,VP> prob = pi[1,1,NP] * pi[2,4,PP] * P(NP --> NP PP) if pi[1,4,NP] < prob then update it to prob and save back[1,4,NP] = <1,NP,PP> prob = pi[1,1,VP] * pi[2,4,PP] * P(VP --> VP PP) if pi[1,4,VP] < prob then update it to prob and save back[1,4,VP] = <1,VP,PP> prob = pi[1,1,V] * pi[2,4,NP] * P(VP --> V NP) if pi[1,4,VP] < prob then update it to prob and save back[1,4,VP] = <1,V,NP> prob = pi[1,1,P] * pi[2,4,NP] * P(PP --> P NP) if pi[1,4,PP] < prob then update it to prob and save back[1,4,PP] = <1,P,NP> prob = pi[1,2,NP] * pi[3,4,VP] * P(S --> NP VP) if pi[1,4,S] < prob then update it to prob and save back[1,4,S] = <2,NP,VP> prob = pi[1,2,NP] * pi[3,4,PP] * P(NP --> NP PP) if pi[1,4,NP] < prob then update it to prob and save back[1,4,NP] = <2,NP,PP> prob = pi[1,2,VP] * pi[3,4,PP] * P(VP --> VP PP) if pi[1,4,VP] < prob then update it to prob and save back[1,4,VP] = <2,VP,PP> prob = pi[1,2,V] * pi[3,4,NP] * P(VP --> V NP) if pi[1,4,VP] < prob then update it to prob and save back[1,4,VP] = <2,V,NP> prob = pi[1,2,P] * pi[3,4,NP] * P(PP --> P NP) if pi[1,4,PP] < prob then update it to prob and save back[1,4,PP] = <2,P,NP> prob = pi[1,3,NP] * pi[4,4,VP] * P(S --> NP VP) if pi[1,4,S] < prob then update it to prob and save back[1,4,S] = <3,NP,VP> prob = pi[1,3,NP] * pi[4,4,PP] * P(NP --> NP PP) if pi[1,4,NP] < prob then update it to prob and save back[1,4,NP] = <3,NP,PP> prob = pi[1,3,VP] * pi[4,4,PP] * P(VP --> VP PP) if pi[1,4,VP] < prob then update it to prob and save back[1,4,VP] = <3,VP,PP> prob = pi[1,3,V] * pi[4,4,NP] * P(VP --> V NP) if pi[1,4,VP] < prob then update it to prob and save back[1,4,VP] = <3,V,NP> prob = pi[1,3,P] * pi[4,4,NP] * P(PP --> P NP) if pi[1,4,PP] < prob then update it to prob and save back[1,4,PP] = <3,P,NP> prob = pi[2,2,NP] * pi[3,5,VP] * P(S --> NP VP) if pi[2,5,S] < prob then update it to prob and save back[2,5,S] = <2,NP,VP> prob = pi[2,2,NP] * pi[3,5,PP] * P(NP --> NP PP) if pi[2,5,NP] < prob then update it to prob and save back[2,5,NP] = <2,NP,PP> prob = pi[2,2,VP] * pi[3,5,PP] * P(VP --> VP PP) if pi[2,5,VP] < prob then update it to prob and save back[2,5,VP] = <2,VP,PP> prob = pi[2,2,V] * pi[3,5,NP] * P(VP --> V NP) if pi[2,5,VP] < prob then update it to prob and save back[2,5,VP] = <2,V,NP> prob = pi[2,2,P] * pi[3,5,NP] * P(PP --> P NP) if pi[2,5,PP] < prob then update it to prob and save back[2,5,PP] = <2,P,NP> prob = pi[2,3,NP] * pi[4,5,VP] * P(S --> NP VP) if pi[2,5,S] < prob then update it to prob and save back[2,5,S] = <3,NP,VP> prob = pi[2,3,NP] * pi[4,5,PP] * P(NP --> NP PP) if pi[2,5,NP] < prob then update it to prob and save back[2,5,NP] = <3,NP,PP> prob = pi[2,3,VP] * pi[4,5,PP] * P(VP --> VP PP) if pi[2,5,VP] < prob then update it to prob and save back[2,5,VP] = <3,VP,PP> prob = pi[2,3,V] * pi[4,5,NP] * P(VP --> V NP) if pi[2,5,VP] < prob then update it to prob and save back[2,5,VP] = <3,V,NP> prob = pi[2,3,P] * pi[4,5,NP] * P(PP --> P NP) if pi[2,5,PP] < prob then update it to prob and save back[2,5,PP] = <3,P,NP> prob = pi[2,4,NP] * pi[5,5,VP] * P(S --> NP VP) if pi[2,5,S] < prob then update it to prob and save back[2,5,S] = <4,NP,VP> prob = pi[2,4,NP] * pi[5,5,PP] * P(NP --> NP PP) if pi[2,5,NP] < prob then update it to prob and save back[2,5,NP] = <4,NP,PP> prob = pi[2,4,VP] * pi[5,5,PP] * P(VP --> VP PP) if pi[2,5,VP] < prob then update it to prob and save back[2,5,VP] = <4,VP,PP> prob = pi[2,4,V] * pi[5,5,NP] * P(VP --> V NP) if pi[2,5,VP] < prob then update it to prob and save back[2,5,VP] = <4,V,NP> prob = pi[2,4,P] * pi[5,5,NP] * P(PP --> P NP) if pi[2,5,PP] < prob then update it to prob and save back[2,5,PP] = <4,P,NP> prob = pi[1,1,NP] * pi[2,5,VP] * P(S --> NP VP) if pi[1,5,S] < prob then update it to prob and save back[1,5,S] = <1,NP,VP> prob = pi[1,1,NP] * pi[2,5,PP] * P(NP --> NP PP) if pi[1,5,NP] < prob then update it to prob and save back[1,5,NP] = <1,NP,PP> prob = pi[1,1,VP] * pi[2,5,PP] * P(VP --> VP PP) if pi[1,5,VP] < prob then update it to prob and save back[1,5,VP] = <1,VP,PP> prob = pi[1,1,V] * pi[2,5,NP] * P(VP --> V NP) if pi[1,5,VP] < prob then update it to prob and save back[1,5,VP] = <1,V,NP> prob = pi[1,1,P] * pi[2,5,NP] * P(PP --> P NP) if pi[1,5,PP] < prob then update it to prob and save back[1,5,PP] = <1,P,NP> prob = pi[1,2,NP] * pi[3,5,VP] * P(S --> NP VP) if pi[1,5,S] < prob then update it to prob and save back[1,5,S] = <2,NP,VP> prob = pi[1,2,NP] * pi[3,5,PP] * P(NP --> NP PP) if pi[1,5,NP] < prob then update it to prob and save back[1,5,NP] = <2,NP,PP> prob = pi[1,2,VP] * pi[3,5,PP] * P(VP --> VP PP) if pi[1,5,VP] < prob then update it to prob and save back[1,5,VP] = <2,VP,PP> prob = pi[1,2,V] * pi[3,5,NP] * P(VP --> V NP) if pi[1,5,VP] < prob then update it to prob and save back[1,5,VP] = <2,V,NP> prob = pi[1,2,P] * pi[3,5,NP] * P(PP --> P NP) if pi[1,5,PP] < prob then update it to prob and save back[1,5,PP] = <2,P,NP> prob = pi[1,3,NP] * pi[4,5,VP] * P(S --> NP VP) if pi[1,5,S] < prob then update it to prob and save back[1,5,S] = <3,NP,VP> prob = pi[1,3,NP] * pi[4,5,PP] * P(NP --> NP PP) if pi[1,5,NP] < prob then update it to prob and save back[1,5,NP] = <3,NP,PP> prob = pi[1,3,VP] * pi[4,5,PP] * P(VP --> VP PP) if pi[1,5,VP] < prob then update it to prob and save back[1,5,VP] = <3,VP,PP> prob = pi[1,3,V] * pi[4,5,NP] * P(VP --> V NP) if pi[1,5,VP] < prob then update it to prob and save back[1,5,VP] = <3,V,NP> prob = pi[1,3,P] * pi[4,5,NP] * P(PP --> P NP) if pi[1,5,PP] < prob then update it to prob and save back[1,5,PP] = <3,P,NP> prob = pi[1,4,NP] * pi[5,5,VP] * P(S --> NP VP) if pi[1,5,S] < prob then update it to prob and save back[1,5,S] = <4,NP,VP> prob = pi[1,4,NP] * pi[5,5,PP] * P(NP --> NP PP) if pi[1,5,NP] < prob then update it to prob and save back[1,5,NP] = <4,NP,PP> prob = pi[1,4,VP] * pi[5,5,PP] * P(VP --> VP PP) if pi[1,5,VP] < prob then update it to prob and save back[1,5,VP] = <4,VP,PP> prob = pi[1,4,V] * pi[5,5,NP] * P(VP --> V NP) if pi[1,5,VP] < prob then update it to prob and save back[1,5,VP] = <4,V,NP> prob = pi[1,4,P] * pi[5,5,NP] * P(PP --> P NP) if pi[1,5,PP] < prob then update it to prob and save back[1,5,PP] = <4,P,NP> When you are done, build-tree(back[1,numwords,S],pi[1,numwords,S)