Weight (strings)

From HandWiki

The [math]\displaystyle{ a }[/math]-weight of a string, for a letter [math]\displaystyle{ a }[/math], is the number of times that letter occurs in the string. More precisely, let [math]\displaystyle{ A }[/math] be a finite set (called the alphabet), [math]\displaystyle{ a\in A }[/math] a letter of [math]\displaystyle{ A }[/math], and [math]\displaystyle{ c\in A^* }[/math] a string (where [math]\displaystyle{ A^* }[/math] is the free monoid generated by the elements of [math]\displaystyle{ A }[/math], equivalently the set of strings, including the empty string, whose letters are from [math]\displaystyle{ A }[/math]). Then the [math]\displaystyle{ a }[/math]-weight of [math]\displaystyle{ c }[/math], denoted by [math]\displaystyle{ \mathrm{wt}_a(c) }[/math], is the number of times the generator [math]\displaystyle{ a }[/math] occurs in the unique expression for [math]\displaystyle{ c }[/math] as a product (concatenation) of letters in [math]\displaystyle{ A }[/math].

If [math]\displaystyle{ A }[/math] is an abelian group, the Hamming weight [math]\displaystyle{ \mathrm{wt}(c) }[/math] of [math]\displaystyle{ c }[/math], often simply referred to as "weight", is the number of nonzero letters in [math]\displaystyle{ c }[/math].

Examples

  • Let [math]\displaystyle{ A=\{x,y,z\} }[/math]. In the string [math]\displaystyle{ c=yxxzyyzxyzzyx }[/math], [math]\displaystyle{ y }[/math] occurs 5 times, so the [math]\displaystyle{ y }[/math]-weight of [math]\displaystyle{ c }[/math] is [math]\displaystyle{ \mathrm{wt}_y(c)=5 }[/math].
  • Let [math]\displaystyle{ A=\mathbf{Z}_3=\{0,1,2\} }[/math] (an abelian group) and [math]\displaystyle{ c=002001200 }[/math]. Then [math]\displaystyle{ \mathrm{wt}_0(c)=6 }[/math], [math]\displaystyle{ \mathrm{wt}_1(c)=1 }[/math], [math]\displaystyle{ \mathrm{wt}_2(c)=2 }[/math] and [math]\displaystyle{ \mathrm{wt}(c)=\mathrm{wt}_1(c)+\mathrm{wt}_2(c)=3 }[/math].