I am stuck on an exercise from "A Book of Abstract Algebra" by Charles C. Pinter, and there are technically three parts to the question:
Given that the weight of a binary word $x$ is the number of $1$s in the word and is denoted by $w(x)$, prove the following:
a) If words $x$ and $y$ have even weight, so does $x+y$.
b) If words $x$ and $y$ have odd weight, then $x+y$ has even weight.
c) If word $x$ has odd and $y$ has even weight, then $x+y$ has odd weight.
Note that both $x$ and $y$ must be of the same length.
My attempt of proving these statements was along the line of using the identity $w(x+y) = d(x,y)$ where $d(x,y)$ refers to the distance between the words $x$ and $y$. I then noticed that if both $x$ and $y$ have the same parity, suppose at the $i$-th digit we have $x_i \neq y_i$, then there exists another digit $j$ such that $x_j \neq y_j$. This shows that the resulting $x+y$ has even weight. However, I cannot prove this. I just needed a hint and not the whole solution to the given problems.
To clarify some of the terminologies used in this post:
- If a word $x=x_1x_2...x_n$ and a word $y=y_1y_2...y_n$, then the resulting sum $x+y$ is $z=z_1z_2...z_n$, where
$$\ z_i = \begin{cases} 0 & \text{if } a_i = b_i \\ 1 & \text{if } a_i \neq b_i \end{cases} \\$$
- The distance $d(x,y)$ refers to the number of position in which the words $x$ and $y$ differ.
It is easy to show that w(a+b) = w(a) + w(b) - 2w(a&b), where the operator '&' is the bitwise AND operator. Now, w(a) and w(b) are both even, so we can express them as 2x and 2y, respectively, where x and y are non-negative integers. That gives us w(a+b) = 2x + 2y - 2w(a&b) or w(a+b) = 2(x+y-w(a&b)) that is always even. That proves (a). You can do a similar approach for (b) and (c) knowing that the sum of 2 odd numbers is even, and the sum of an odd number and an even number is an odd number.