0

In programming, if I did 100 | 001 (| being the "or" operator), I would get 101. Can this be done in math? I.e. with sets: $$A=\{1,0,0\}$$ $$B=\{0,0,1\}$$ $$A ?B = \{1,0,1\}$$ Is there an operator that would satisfy the equation in place of the question mark? Thanks.

Asaf Karagila
  • 393,674

3 Answers3

2

The AND and OR operators can be modelled algebraically thus: $$ \begin{align} a \wedge b &= ab\\ a \vee b &= a+b-ab \end{align}$$

Now, for $A,B \in \Bbb Z_2^n$, that is, $A=(a_1,\ldots,a_n)$ and $B=(b_1,\ldots,b_n)$ where $a_i,b_i \in \{0,1\}$, define $$ \begin{align} A \wedge B &= (a_1\wedge b_1,\ldots,a_n\wedge b_n)\\ A \vee B &= (a_1\vee b_1,\ldots,a_n\vee b_n) \end{align}$$

Théophile
  • 24,627
2

There is a nice way to model this mathematically. Let's represent each number in binary as a set of positions. More formally, construct an injection $f:\mathbb{N\to\mathcal{P}(\mathbb{N})}$ as follows: for every $x \in \mathbb{N}$ $$x=2^{a_n}+2^{a_{n - 1}}+\dots+2^{a_0}\mapsto \{a_n,a_{n-1},\dots,a_0 \}$$ or $$f(x)=\{a_n,a_{n-1}, \dots,a_0\}$$ where $a_n>a_{n-1}>\dots>a_0$ and $a_n,a_{n-1},\dots,a_0 \in \mathbb{N}$. (This is just another way to say a number is the set of positions of bits in binary, e.g. $5_{10}=101_2\mapsto\{2,0\}$ and $7_{10}=111_2\mapsto \{2,1,0\}$. This assumes the fact that every natural number can be written as a sum of distinct powers of 2.)

If we use the same notation as programming ($|$ for bitwise OR and $\&$ for bitwise AND),

As an exercise, you can try to prove that $f(x|y)=f(x)\cup f(y)$ and $f(x \, \& \, y) = f(x) \cap f(y)$ for any $x,y \in \mathbb{N}$.

Anas A. Ibrahim
  • 1,884
  • 7
  • 15
0

First of all, writing $\{0,0,1\}$ is not what you really want. Because sets ignore repetition and order, that would be the same as $\{0,1\}$ and $\{1,1,1,1,1,1,1,1,1,1,1,1,1,1,0\}$ or $\{0,0,1,0,1,0,0,1,0,1\}$.

What you want is to think about sequences, binary sequences. However, you can also think about sets directly.

Say you only care about sequences of length $n$, this will simplify things a bit, then you can think about subsets of $\{1,\ldots,n\}$. If $A$ is a subset of $\{1,\ldots,n\}$, then $k\in A$ if and only if the $k$th indexed bit in the sequence that $A$ represent equals to $1$.

For example with $n=3$, then $\{1,2,3\}$ would be the sequence $(1,1,1)$ and $\{2\}$ would be $(0,1,0)$.

Now we get that $A\cup B$ is the bitwise or operator, $A\cap B$ is the bitwise and operator, and symmetric difference $A\mathbin{\triangle}B$ is the bitwise xor operator.

Asaf Karagila
  • 393,674