let matrix ts cond = function
  | Empty -> Empty
  | (Field _ | Fullas r -> Index(ts,[cond,r])
  | Index(ts0,kregions) ->
      let d = List.length ts in
      let gregions = List.map
        (fun (cond0,r0) ->
           let gcond = fun xs -> p_and (cond xs) (cond0 (shift d xs)) in
           gcond , r0)
        kregions
      in
      Index( ts @ ts0 , gregions )