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.

- 393,674

- 1,051
-
"or" can be represented by the "max" function – The Chaz 2.0 Jun 01 '17 at 15:02
-
3Sets are not the appropriate structure for this. In a set, order doesn't matter, and repeated elements are removed, so ${1,0,0}={0,0,1}={0,1}$. Instead, use ordered $n$-tuples, like $(1,0,0)$. – Théophile Jun 01 '17 at 15:03
-
This is a bit different with sets, because for your boolean operation the orders matters, while for sets the order in which elements are listed does not matter. You would have to construct a specific space where the order matters for this to work. – Paul Jun 01 '17 at 15:04
-
Do you know the "logic" thing? They use ^ for and ∨ for or, but that's not math. – MCCCS Jun 01 '17 at 15:04
-
He could use vectors instead, right? – The Chaz 2.0 Jun 01 '17 at 15:05
-
5@MCCCS: "that's not math": are you serious ? – Jun 01 '17 at 15:09
-
@Théophile which binary operation could be used on tuples? – Archie Gertsman Jun 01 '17 at 15:09
-
I think $(1, 0, 0)∨(0, 0, 1) ≡ (1, 0, 1)$ is the best choice. And @YvesDaoust I thought logic is a seperate thing from math. – MCCCS Jun 01 '17 at 15:10
-
@MCCCS "but that's not math" That's news to me. – Noah Schweber Jun 01 '17 at 15:11
-
@Noah: I guess you missed it, but logic and set theory are not mathematics at all... :P – Asaf Karagila Jun 01 '17 at 15:16
-
This question, however, is definitely not a question about set theory. And it would be wise to read the tag excerpt before blindly picking tags for your question. – Asaf Karagila Jun 01 '17 at 15:16
-
@AsafKaragila since I don't know which area of math is applicable and that's part of my question, I chose the tag the described how I thought about this intuitively. – Archie Gertsman Jun 01 '17 at 15:18
-
In fact, $A$ and $B$ can both be non-negative integers, and you can define bitwise OR and bitwise AND operations. There are examples here and here. – David K Jun 01 '17 at 15:20
-
Archie, I figured that much. And I pointed out that there are explanations to these tags which explain to you when and how to use them. Not knowing where the nearest public restroom is located is not a valid excuse for pissing on someone else's door. – Asaf Karagila Jun 01 '17 at 15:23
3 Answers
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}$$

- 24,627
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}$.

- 1,884
- 7
- 15
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.

- 393,674
-
It feels good to know that I feel awkward starting the indexing from $1$ and not from $0$. – Asaf Karagila Jun 01 '17 at 15:26