anchor.diff:              compute l mid |> ignore
               if mid < stringSize + 1 then
                   compute mid m |> ignore
  +
           if mid < stringSize + 1 then
               completeT (l, mid, mid, m)
   
       and completeT (l1, m1, l2, m2) =
           assert (m1 - l1 = m2 - l2)
   
  +        let addProbToMatrix (matrix: Map<_, double [,]>) row column key prob = 
  +                (matrix.Item key).[row, column] <- (matrix.Item key).[row, column] + prob
  +                
  +        let updateTMatrixCell row column (nonTerm, prob) = addProbToMatrix tMatrix row column nonTerm prob
  +
           if m1 - l1 = 1 && m1 = l2 then
               let currentChar = strToParse.[l1]
  -            srl.Item currentChar |> List.map (fun (nt, prob) -> (tMatrix.Item nt).[l1, l1 + 1] <- prob) |> ignore
  +            let nonTerms = simpleRules.Item currentChar
  +
  +            nonTerms
  +            |> List.iter (updateTMatrixCell l1 (l1 + 1))
  +
           else if m1 - l1 = 1 && m1 < l2 then
  +            assert (m2 <= stringSize + 1)
  +
               let headsFromTail (tail, tailProb) = 
  -                if crl.ContainsKey tail then 
  -                    crl.Item tail |> List.map (fun (head, headProb) -> (head, headProb * tailProb)) 
  +                if complexRules.ContainsKey tail then 
  +                    complexRules.Item tail |> List.map (fun (head, headProb) -> head, headProb * tailProb)
                   else 
                       []
   
               let tails = pMatrix |> Map.map (fun _ probs -> probs.[l1, l2]) |> Map.filter (fun _ prob -> prob > 0.)
  -            let heads = tails |> Map.toSeq |> Seq.map headsFromTail |> Seq.concat
  -
  -            heads |> Seq.map (fun (head, prob) -> (tMatrix.Item head).[l1, l2] <- (tMatrix.Item head).[l1, l2] + prob) |> List.ofSeq |> ignore
  +            let heads = tails |> Map.toList |> List.map headsFromTail |> List.concat
  +
  +            heads 
  +            |> List.iter (updateTMatrixCell l1 l2)
   
           else if m1 - l1 > 1 then
  +            assert (l2 < stringSize + 1)
  +
               let mid1: int = int (l1 + m1) / 2
               let mid2: int = int (l2 + m2) / 2
   
  
positive.code:     probability: double;
  } 
  
  // works only for string of 2^n-1 length
  let recognize (strToParse: string) 
                (crl: Dictionary<NonTerminal * NonTerminal, (NonTerminal * double) list>)
                (srl: Dictionary<char, (NonTerminal * double) list>)
                (erl: NonTerminal list) 
                (nonterminals : NonTerminal [])
                S = 
  
      let stringSize = String.length strToParse
  
      let strSizeExponent = (System.Math.Log (double stringSize)) / (System.Math.Log 2.) |> System.Math.Ceiling |> int
      let roundedSize = (1 <<< strSizeExponent) - 1
  
  
      // left-bottom triangle and diagonal of tMatrix and pMatrix are not used
      let tMatrix = new Map<NonTerminal, double [,]>(
                              nonterminals 
                              |> Seq.map (fun x -> (x, Array2D.init (stringSize + 1) (stringSize + 1) (fun x y -> 0.))))
  
      let pMatrix = new Map<NonTerminal * NonTerminal, double [,]>(
                              crl.Keys
                              |> Seq.map (fun x -> (x, Array2D.init (stringSize + 1) (stringSize + 1) (fun x y -> 0.)))) 
  
      let addToP nts (matrix: double [,]) (l1, m1, l2, m2) =
          let where = pMatrix.[nts]
  
negative.code:                                     
      let completeP where from1 from2 = 
          let completeOnePair (nt1, nt2) =
                  addToP (nt1, nt2) (subMatrixMult tMatrix.[nt1] tMatrix.[nt2] from1 from2) where
          pMatrix |> Map.iter (fun nts _ -> completeOnePair nts)
  
      
      let rec compute l m =
  