From 77ff379d8e8e9f8f310852b4b77f7212ec2a17a8 Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Sun, 16 Aug 2020 18:07:44 -0600 Subject: [PATCH] off-by-ones added and removed here --- cfg_utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cfg_utils.py b/cfg_utils.py index 7d18eb4..c460856 100644 --- a/cfg_utils.py +++ b/cfg_utils.py @@ -471,10 +471,18 @@ class CFGBoltzmann: # Here, L will be the number of characters produced by X_ijk # L will therefore go from 1 (we disallow epsilon-productions so - # X_ijk must produce at least one character) to: + # X_ijk must produce at least one character) (INCLUSIVE) to (INCLUSIVE): # Total Characters Requested - (minimum number of characters generated by k+1 to end of rule) # which will be: - # + # Total Characters Requested - (T_ij -(k+1)+1) = TCR - (T_ij-k) + # But T_ij is the INDEX of the last element of the rule, aka len(rule)-1 + # so the expression is + # Total Characters Requested - (len(rule)-k-1) + # exact_length_total - len(rule) - how_far_into_the_RHS - 1 + + # in the range() call we lop off the "-1" because we want to be inclusive and range gives us [) + # bounds. Phantasmagoria of off-by-ones here we go! + for l in range(1, exact_length_total - len(RHS_in_question) - how_far_into_the_RHS) return 0 -- GitLab