Logic and Computer

Computers are built on (propositional) logic. The reason ( ) around “propositional” is that propositional logic is not the only choice of logic for computers. There are ternary computers based on 3-valued logic. (In 3-valued logic a statement can be either true, false, or neither.) In principle, you can build computers out of any $n$-valued logic. There are also computers based upon infinite-valued logic. Examples of such computers include fuzzy computers (based upon fuzzy logic) and quantum computers (based upon the laws of the quantum world!). There are so many interesting things to talk about these uncoventional computers but our discussion here is about conventional computers that are based upon propositional logic.

Computers carry out logical calculations. Arithmetic operations such as adding two numbers are in fact logical calculations as we will see later. Computers (conventional binary computers to be clear) can understand only the bits 0 (switch on-current) and 1 (switch off-no current). Hence everything in a computer is represented as patterns of of 0s and 1s. 0 and 1 can be understood as the two truth values, true and false, of propositional logic. For example, 0 could represent true while 1 does false. Using propositional logic one can design physical devices, called logic circuits, that perform intended results by producing bits (output) from bits (input). The design of logic circuits is called computer logic. The smallest units of a circuit are called the logic gates or gates in short, i.e. logic gates are building blocks of a logic circuit. Gates correspond to the operations of propositional logic, such as $\vee$, $\wedge$, $\oplus$, and $\neg$.

Example. The diagram of Or Gate.

Or Gate

Example. The diagram of And Gate.

And Gate

Example. The diagram of Exclusive Or Gate.

Exclusive Or Gate

Example. The diagram of Not Gate

Not Gate

In practice, however, not all these operations are available to a circuit designer. For example, exclusive or can be performed using $\vee$, $\wedge$ and $\neg$ as we have seen here. $$x\oplus y\equiv(x\wedge\neg y)\vee(\neg x\wedge y)$$ The following figure shows a logic circuit that computes $x\oplus y$. The semi circle on a wire represents that the wire is crossing over another i.e. they are not connected.

A circuit to compute Exclusive Or Gate

Not gate often simply represented by a bubble. With this convention, the above circuit can be simplified as in the following figure.

A circuit to compute Exclusive Or Gate

There is a very useful gate called NAND (NOT-AND) Gate. It is defined by nand operator $$p|q\equiv\neg(p\wedge q)$$ What’s interesting about nand operator is that any conventional operator can be expressed using only nand operator. For example, \begin{align*}\neg p&\equiv p|p\\p\wedge q&\equiv\neg(p|q)\equiv(p|q)|(p|q)\end{align*}

Example. The diagram of NAND Gate.

NAND Gate

Binary Arithmetic

The basic rules of binary arithmetic: \begin{equation}\begin{aligned}0+0&=0\\0+1&=1\\1+0&=1\\1+1&=0,\ \mbox{carry}\ 1\end{aligned}\label{eq:binadd}\end{equation}As shown, when adding 1 to 1, the result is 0 but a 1 is carried into the next position to the left. For example,adding 1 to 10111 results in 11000 with three carries. $$\begin{array}{cccccc}& & 1 & 1 & 1 & \\& 1 & 0 & 1 & 1 & 1\\+& & & & & 1\\\hline & 1 & 1 & 0 & 0 & 0\end{array}$$ Here is another example $10101+01111$. \begin{equation}\begin{array}{ccccccc}& & 1 & 1 & 1 & 1 & \\& & 1 & 0 & 1 & 0 & 1\\+& & 0 & 1 & 1 & 1 & 1\\\hline & 1 & 0 & 0 & 1 & 0 & 0\end{array}\label{eq:binadd2}\end{equation} The question is how do we design hardware to do binary arithmetic? The simplest operation is the addition of two bits shown in \eqref{eq:binadd}. The equations in \eqref{eq:binadd} actually create two output bits, a sum $s$ and a carry $c$, from two input bits $x$ and $y$. The carry bit was not mentioned for the first three because it is 1 only when both input bits are 1. On the other hand, the sum is 1 only when one of the input bits is 1 and the other is 0. Hence, the device that performs the addition of two bits, called a half adder can be represented by the following diagram.

A Half Adder

However, a half adder is not adequate to compute more complex binary sums such as \eqref{eq:binadd2} because when adding numbers with multiple digits we sometimes need three input bits. A full adder takes three input bits $X$, $Y$, and the carry-in bit $C_{\mathrm{in}}$ and produce two output bits, the sum $S$ and the carry-out bit $C_{\mathrm{out}}$. Th following is the truth table for computing the two output bits $S$ and $C_{\mathrm{out}}$ from the three input bits $X$, $Y$, and $C_{\mathrm{in}}$. $$\begin{array}{|c|c|c|c|c|}\hline X & Y & C_{\mathrm{in}} & S & C_{\mathrm{out}}\\\hline 0 & 0& 0 & 0 & 0\\\hline0 & 0 & 1 & 1 & 0\\\hline0 & 1 & 0 & 1 & 0\\\hline 0 & 1 & 1 & 0 &1\\\hline 1 & 0 & 0 & 1 &0\\\hline 1 & 0 & 1 & 0 & 1\\\hline 1 & 1 &0 & 0 &1\\\hline 1 & 1 & 1 & 1 & 1\\\hline\end{array}$$ The following diagram shows a way to construct a full adder using two half adders (represented by a box called HA). The circuit produces the sum bit by adding $X$ and $Y$ and then adding $C_{\mathrm{in}}$ to the result. The $C_{\mathrm{out}}$ is 1 if there is a carry from either the first or the second of these additions.

A Full Adder

References.

[1] Essential Discrete Mathematics for Computer Science, Harry Lewis and Rachel Zax, Princeton University Press, 2019

Normal Forms

In this note, we study some standard ways (normal forms) of representing formulas. The rules are:

  1. Only $\wedge$, $\vee$, and $\neg$ are used.
  2. Any negations are attached to propositional variables, not to larger expressions.
  3. The $\vee$’s and the $\wedge$’s are organized in the manner described below: A literal is either a propositional variable (such as $p$) or the negation of a single variable (such as $\neg q$). If a formula is an $\wedge$ of $\vee$’s of literals we say it is in CNF (Conjunctive Normal Form). For example, \begin{align*}(p\vee q)\wedge(\neg p\vee q)\wedge(p\vee\neg q)\wedge(\neg p\vee \neg q)\\p\wedge\neg p\\(p\vee\neg q\vee r)\wedge(\neg s\vee t)\end{align*} are all in CNF. One may wonder why $p\wedge\neg p$ is in CNF. That’s because it is logically equivalent to $(p\vee p)\wedge(\neg p\vee\neg p)$. A formula is in DNF (Disjunctive Normal Form), on the other hand, is an $\vee$ of $\wedge$’s of literals. For example, $$(p\wedge\neg q\wedge r)\vee(\neg r\wedge t)$$ is in DNF. $p\wedge\neg p$ is also in DNF because it is logically equivalent to $(p\wedge\neg p)\vee (p\wedge\neg p)$. Similarly, $p\vee q$ is in both CNF and DNF.

Example. $(p\vee\neg q\vee r)\wedge(\neg q\vee t)$ is in CNF. Formulae $p\vee\neg q\vee r$ and $\neg q\vee t$ are clauses of the formula. The clauses of a CNF formula are disjuncts of literals while the clauses of a DNF formula are conjuncts of literals. That is to say, a CNF formula is a conjunction of disjuncts of literals and a DNF formula is a disjunction of conjuncts of literals.

A CNF formula is true if at least one literal from each clause is true. Similarly, a DNF formula is true if and only of there is at least one disjunct (clause) in which all the literals are true. For example, the DNF formula $$(\neg p\wedge q)\vee(p\wedge r)$$ is true when $p$ is false and $q$ is true.

Theorem. (De Morgan’s Law) \begin{align*}\neg(p\wedge q)&\equiv\neg p\vee\neg q\\\neg(p\vee q)&\equiv\neg p\wedge\neg q\end{align*}

Proof. It can be easily proved by truth table. We prove only the first one here. The proof of the second one is left for exercise. $$\begin{array}{|c|c|c|c|c|c|c|}\hline p & q & p\wedge q &\neg(p\wedge q) & \neg p & \neg q & \neg p\vee\neg q\\\hline T & T & T & F & F & F &F\\\hline T & F & F & T &F & T & T\\\hline F & T & F & T & T & F & T\\\hline F & F & F & T & T & T & T\\\hline\end{array}$$

Example. Using commutative laws, associative laws, distributive laws we learned here along with De Morgan’s law, we can write a given formula into its equivalent formula in a normal form. To see this let us consider the formula $$p\vee(q\wedge(r\vee(s\wedge t)))$$ It can be written into an equivalent formula in conjunctive normal form. \begin{align*}p\vee(q\wedge(r\vee(s\wedge t)))&\equiv (p\vee q)\wedge(p\vee(r\vee(s\wedge t))\\&\equiv(p\vee q)\wedge(p\vee((r\vee s)\wedge(r\vee t))\\&\equiv(p\vee q)\wedge(p\vee(r\vee s))\wedge(p\vee(r\vee t))\\&\equiv(p\vee q)\wedge(p\vee r\vee s)\wedge(p\vee r\vee t)\end{align*} But then it can also be written into an equivalent formula in disjunctive normal form. \begin{align*}p\vee(q\wedge(r\vee(s\wedge t)))&\equiv p\vee((q\wedge r)\vee(q\wedge(s\wedge t)))\\&\equiv p\vee(q\wedge r)\vee(q\wedge s\wedge t)\end{align*} In general, the following theorem holds.

Theorem. Every formula is equivalent to one in conjunctive normal form, and also to one in disjunctive normal form.

We are not going to prove the theorem here but interesting readers can find a proof in the reference [1] below.

Example. Write $(\neg p\vee q)\Longrightarrow\neg p$ in disjunctive normal form.

Solution. \begin{align*}(\neg p\vee q)\Longrightarrow\neg p&\equiv\neg(\neg p\vee q)\vee\neg q\\&\equiv(\neg\neg p\wedge\neg q)\vee\neg q\\&\equiv p\vee\neg q\vee\neg q\\&\equiv p\vee\neg p\vee\neg q\end{align*} Since $p\vee\neg p$ is a tautology, $(\neg p\vee q)\Longrightarrow\neg p$ is a tautology.

As shown in the above example, any expression that can be simplified to become a tautology must be a tautology itself. Determining whether a formula is a tautology is a fundamental problem of computer science. Using truth table is in deed not an effective method to tackle the problem because the truth table of a formula with a large number of variables would become too big to handle for us. For instance, the truth table for a formula with 30 variables would have $2^{30}=1,073,741,824$ rows, more than a billion rows! It is yet unknown if there is an effective algorithm to determine satisfiability, in particular whether a formula is a tautology.

References.

[1] Essential Discrete Mathematics for Computer Science, Harry Lewis and Rachel Zax, Princeton University Press, 2019

Propositional Logic

A proposition is a statement that is either true or false. We can combine one or more propositions to create more complicated propositions using conjunctions. Those conjunctions include:

  1. Negation: $\neg p$, meaning not $p$.
  2. Inclusive Or: $p\vee q$, meaning $p$ or $q$ (could be both).
  3. And: $p\wedge q$, meaning $p$ and $q$.
  4. Exclusive Or: $p\oplus q$, meaning either $p$ or $q$.
  5. Implies: $p\Longrightarrow q$, meaning if $p$ then $q$ ($p$ implies $q$). $p$ and $q$ are called the hypothesis and the conclusion, respectively.
  6. Equivalence: $p\Longleftrightarrow q$, meaning $p$ if and only if $q$. $p\Longleftrightarrow q$ is shorthand for $(p\Longrightarrow q)\wedge(p\Longleftarrow q)$.

Definition. A propositional formula is defined by the following.

PF1. Any propositional variable (such as $p$ and $q$) is a formula.

PF2. If $\alpha$ and $\beta$ are formulas, so are

  1. $\alpha\vee\beta$
  2. $\alpha\wedge\beta$
  3. $\neg\alpha$

For example $\neg(p\vee q)$ is a formula.

Truth Tables

The truth value of a formula can be found by its truth table. A formula is said to be satisfiable if at least one truth assignment satisfies it. A formula is called a tautology if every truth assignment satisfies it. A formula is said to be unsatisfiable if no truth assignment satisfies it.

Here are some examples.

  1. The truth table of $\neg p$ $$\begin{array}{|c|c|}\hline p & \neg p\\\hline T & F\\\hline F & T\\\hline\end{array}$$
  2. The truth table of $p\wedge q$ $$\begin{array}{|c|c|c|}\hline p & q & p\wedge q\\\hline T & T & T\\\hline T & F & F\\\hline F & T & F\\\hline F & F & F\\\hline\end{array}$$
  3. The truth table of $p\wedge\neg p$. $$\begin{array}{|c|c|c|}\hline p & \neg p & p\wedge\neg p\\\hline T & F & F\\\hline F & T & F\\\hline\end{array}$$ $p\wedge\neg p$ is unsatisfiable.
  4. The truth table of $p\vee q$ $$\begin{array}{|c|c|c|}\hline p & q & p\vee q\\\hline T & T & T\\\hline T & F & T\\\hline F & T & T\\\hline F & F & F\\\hline\end{array}$$
  5. The truth table of $p\vee\neg p$. $$\begin{array}{|c|c|c|}\hline p & \neg p & p\vee\neg p\\\hline T & F & T\\\hline F & T & T\\\hline\end{array}$$ $p\vee\neg p$ is a tautology.
  6. The truth table of $p\oplus q$ $$\begin{array}{|c|c|c|}\hline p & q & p\oplus q\\\hline T & T & F\\\hline T & F & T\\\hline F & T & T\\\hline F & F & F\\\hline\end{array}$$
  7. The truth table of $p\Longrightarrow q$ $$\begin{array}{|c|c|c|}\hline p & q & p\Longrightarrow q\\\hline T & T & T\\\hline T & F & F\\\hline F & T & T\\\hline F & F & T\\\hline\end{array}$$ It must be puzzling for readers as to why a false hypothesis can imply anything. Remember that we are doing propositional logic and any statement of our concern should be either true or false. So it comes down to the decision on what truth value to assign to a conditional statement with false hypothesis. If we were to assign the truth value F, all hell will break loose. Here is why. Consider the conditional statement “if $p$ then $\neg p$” and assume that $p$ is false. That must mean $\neg p$ is true since $p$ is a proposition. However, we decided to assign the truth value $F$ to the conditional statement hence $\neg p$ must also be false. This is a contradiction! To avoid this sort of disastrous contradiction, we should assign the truth value T to a conditional statement with false hypothesis. We claimed without a proof that the empty set is a subset of every set here. The statement “$x\in\emptyset\Longrightarrow x\in A$” is always true because the hypothesis $x\in\emptyset$ is false. Hence $\emptyset\subseteq A$ for any set $A$.
  8. The truth value of $p\Longleftrightarrow q$. $$\begin{array}{|c|c|c|c|c|}\hline p & q & p\Longrightarrow q & p\Longleftarrow q & p\Longleftrightarrow q\\\hline T & T & T & T & T\\\hline T & F & F & T & F\\\hline F & T & T & F & F\\\hline F & F & T & T & T\\\hline\end{array}$$
  9. The truth value of $p\wedge q\Longrightarrow r$. $$\begin{array}{|c|c|c|c|c|}\hline p & q & r & p\wedge q & p\wedge q\Longrightarrow r\\\hline T & T & T & T & T\\\hline T & T & F & T & F\\\hline T & F & T & F & F\\\hline T & F & F & F & T\\\hline F & T & T & F & T\\\hline F & T & F & F & T\\\hline F & F & T & F & T\\\hline F & F & F & F & T\\\hline\end{array}$$

When two fomulae $\alpha$ and $\beta$ have the same truth table, we say $\alpha$ is logically equivalent to $\beta$ and write $\alpha\equiv\beta$.

Theorem. $p\Longrightarrow q\equiv\neg p\vee q$.

Proof. $$\begin{array}{|c|c|c|c|c|}\hline p & q & p\Longrightarrow q & \neg p & \neg p\vee q\\\hline T & T & T & F & T\\\hline T & F & F & F & F\\\hline F & T & T & T & T\\\hline F & F & T & T & T\\\hline\end{array}$$

Theorem. $p\oplus q\equiv(p\wedge\neg q)\vee(\neg p\wedge q)$.

Proof. Left to readers as an exercise.

$\vee$ and $\wedge$ can be considered as operations on formulae and the following laws hold:

Commutative Laws. For any formulae $\alpha$ and $\beta$, \begin{align*}\mbox{(CL1)}\ \alpha\vee\beta&\equiv\beta\vee\alpha\\\mbox{(CL2)}\ \alpha\wedge\beta&\equiv\beta\wedge\alpha\end{align*}

Associative Laws. For any formulae $\alpha$, $\beta$ and $\gamma$, \begin{align*}\mbox{(AL1)}\ (\alpha\vee\beta)\vee\gamma&\equiv\alpha\vee(\beta\vee\gamma)\\\mbox{(AL2)}\ (\alpha\wedge\beta)\wedge\gamma&\equiv\alpha\wedge(\beta\wedge\gamma)\end{align*}

Distributive Laws. For any formulae $\alpha$, $\beta$ and $\gamma$, \begin{align*}\mbox{(DL1)}\ \alpha\vee(\beta\wedge\gamma)&\equiv(\alpha\vee\beta)\wedge(\alpha\vee\gamma)\\\mbox{(DL2)}\ \alpha\wedge(\beta\vee\gamma)&\equiv(\alpha\wedge\beta)\vee(\alpha\wedge\gamma)\end{align*}

These laws can be used to show two formulae are logically equivalent without using truth table. Proof by a truth table can be really cumbersome when concerned formulae are complicated.

References.

[1] Essential Discrete Mathematics for Computer Science, Harry Lewis and Rachel Zax, Princeton University Press, 2019

Graphs and Functions

A graph $G$ from a set $A$ to another set $B$ is a subset $R\subseteq A\times B$. If $A=B$ then $G$ is called a relation in $A$. The inverse of a graph $G\subseteq A\times B$ is defined by $G^{-1}=\{(y,x):(x,y)\in G\}\subseteq B\times A$.

A function $f$ from $A$ to $B$ is a graph $f\subseteq A\times B$ such that

F1. For any $x\in A$ there exists $y\in B$ such that $(x,y)\in f$.

F2. $(x,y_1)\in f$ and $(x,y_2)\in f$ $\Longrightarrow$ $y_1=y_2$.

If $(x,y)\in f$ then we write $y=f(x)$. If $f\subseteq A\times B$ is a function, we write $f: A\longrightarrow B$. We call $A$ and $B$ the domain and the codomain of $f$, respectively. The set \begin{align*}f(A)&=\{y\in B: (x,y)\in f\ \mbox{for some}\ x\in A\}\\&=\{f(x):x\in A\}\end{align*} is called the range of $f$. A function $f: A\longrightarrow B$ is onto or surjective if $f(A)=B$. A function $f: A\longrightarrow B$ is one-to-one or injective if $(x_1,y)\in f$ and $(x_2,y)\in f$ $\Longrightarrow$ $x_1=x_2$. A function $f: A\longrightarrow B$ is bijective if it is both injective and surjective. A bijective function is also called a one-to-one correspondence.

Theorem. An inverse graph $f^{-1}\subseteq B\times A$ of a function $f\subseteq A\times B$ is a function if and only if $f$ is bijective.

Proof. ($\Longrightarrow$) Suppose that $f^{-1}\subseteq A\times B$ is a function. $\forall y\in B$, $\exists x\in A$ such that $(y,x)\in f^{-1}\Longrightarrow (x,y)\in f$. Thus $f$ is surjective. $(x_1,y)\in f$ and $(x_2,y)\in f$ $\Longrightarrow$ $(y,x_1)\in f^{-1}$ and $(y,x_2)\in f^{-1}$ $\Longrightarrow$ $x_1=x_2$. Thus $f$ is injective. Therefore, $f$ is bijective.

($\Longleftarrow$) Suppose that $f: A\longrightarrow B$ is bijective.

F1. Let $y\in B$. Then $\exists x\in A$ such that $(x,y)\in f\Longrightarrow (y,x)\in f^{-1}$.

F2. $(y,x_1)\in f^{-1}$ and $(y,x_2)\in f^{-1}$ $\Longrightarrow$ $(x_1,y)\in f$ and $(x_2,y)\in f$ $\Longrightarrow$ $x_1=x_2$.

Theorem. If $f: A\longrightarrow B$ and $g: B\longrightarrow C$ are bijective then the composition $g\circ f: A\longrightarrow C$ is also bijective.

Proof. F1. Let $x\in A$. Then $\exists y\in B$ such that $y=f(x)$. Also $\exists z\in C$ such that $g(y)=z$. Hence, $$g\circ f(x)=g(f(x))=f(y)=z$$

F2. $$x_1=x_2\Longrightarrow f(x_1)=f(x_2)\Longrightarrow g\circ f(x_1)=g\circ f(x_2)$$

Surjective: Let $z\in C$. Then $\exists y\in B$ such that $g(y)=z$. Also $\exists x\in A$ such that $f(x)=y$. Thus, $g\circ f(x)=z$.

Injective: \begin{align*}g\circ f(x_1)=g\circ f(x_2)&\Longrightarrow g(f(x_1))=g(f(x_2))\\&\Longrightarrow f(x_1)=f(x_2)\\&\Longrightarrow x_1=x_2\end{align*}

References.

[1] Essential Discrete Mathematics for Computer Science, Harry Lewis and Rachel Zax, Princeton University Press, 2019

[2] Set Theory, Charles C. Pinter, Addison Wesley Publishing Company, 1971

Sets

We have already introduced the notion of a set here. Recall that a set is an unordered collection of distinct objects, which are called members or elements. We use $\{\ \}$ to denote a set. For example, the set containing 2, 3, 5 is written as $\{2,3,5\}$. While $\{2,3,5\}=\{3,5,2\}$, the following sets are different.

  1. $\{2,3,5\}$ contains 3 members 2, 3, 5.
  2. $\{\{2\},\{3\},\{5\}\}$ contains three singleton sets $\{2\}$, $\{3\}$, $\{5\}$ as members.
  3. $\{\{2,3,5\}\}$ contains a single element $\{2,3,5\}$.

Example. Some Important Examples of Sets

  1. $\emptyset$=$\{\ \}$=$\Box$=the empty set, the set containing no object. If I remember correctly, the notation $\Box$ for the empty set was introduced by Nicolas Bourbaki, a secretive group of mathematicians.
  2. $\mathbb{N}=\{0,1,2,3,\cdots\}$, the set of all natural numbers.
  3. $\mathbb{Z}=\{\cdots,-3,-2,-1,0,1,2,3,\cdots\}$, the set of all integers.
  4. $\mathbb{Q}$=the set of all rational numbers.
  5. $\mathbb{R}$=the set of all real numbers.

The notation $\in$ is used to express membership. For example, $a\in S$ says $a$ is a member of the set $S$. The set of elements of $A$ that satisfy the predicate $P$ is written as$$\{x\in A: P(x)\}$$

Example. The set of all even integers can be written as $$\{n\in\mathbb{Z}: n\ \mbox{is even}\},$$ $$\{n\in\mathbb{Z}:n=2m\ \mbox{for some}\ m\in\mathbb{Z}\},$$ or $$\{2m: m\in\mathbb{Z}\}$$

A subset $A$ of a set $B$, we write $A\subseteq B$, is defined by $$A\subseteq B\ \mbox{iff}\ [x\in A\Longrightarrow x\in B]$$ If $A\subseteq B$, $B$ is called a superset of $A$. Two sets $A$ and $B$ are said to be equal, we write $A=B$, if $A\subseteq B$ and $B\subseteq A$. If $A\subseteq B$ and $A\ne B$, we write $A\subsetneq B$ and $A$ is called a proper subset of $B$. The notation $A\subset B$ is also frequently used in mathematics to mean that $A$ is a subset of $B$.

Example.

  1. $\emptyset$ is a subset of every set.
  2. Every set is a subset of itself.
  3. $\mathbb{N}\subseteq\mathbb{Z}\subseteq\mathbb{Q}\subseteq\mathbb{R}$.

The power set of a set $A$, denoted by $\wp(A)$ or $2^A$, is the set of all subsets of $A$. For example, if $A=\{3,17\}$, then $\wp(A)=\{\emptyset,\{3\},\{17\},\{3,17\}\}$. If $|A|=n$, then $|\wp(A)|=2^n$.

Now let us discuss set operations. First, we define $A\cup B$, the union of two sets $A$ and $B$ by $$A\cup B=\{x:x\in A\ \mbox{or}\ x\in B\}$$ Next, $A\cap B$, the intersection of two sets $A$ and $B$ is defined by $$A\cap B=\{x:x\in A\ \mbox{and}\ x\in B\}$$ Clearly, $\cup$ and $\cap$ are commutative. $\cup$ and $\cap$ are also associative, namely \begin{align*}(A\cup B)\cup C&=A\cup (B\cup C)\\(A\cap B)\cap C&=A\cap (B\cap C)\end{align*} Lastly, $\bar A=A^c$, the compliment of a set $A$ is defined by $$\bar A=\{x:x\notin A\}$$ Note that while $\cup$ and $\cap$ are binary operations, $\bar{}$ is a unary operation. The empty set $\emptyset$ is an identity element for $\cup$, i.e. for any set $A$, $A\cup\emptyset=A$. $\emptyset$ is also regarded as an operation which is called a nullary operation. Those of you who are interested in learning more details about operations may be referred to [2] below. Using the compliment, we can define $A-B$, the difference of $A$ and $B$ is defined by $$A-B=A\cap\bar B$$ This set minus is not an operation but the composite of two operations $\cap$ and $\bar{}$. If $A\subseteq X$, $X-A$ is also frequently written as $X\setminus A$.

Theorem. Distributive Laws \begin{align*}A\cap(B\cup C)&=(A\cap B)\cup(A\cap C)\\A\cup(B\cap C)&=(A\cup B)\cap(A\cap C)\end{align*}

Proof. We prove only the first one. The proof of the second one is left as an exercise. \begin{align*}x\in A\cap(B\cup C)&\Longleftrightarrow x\in A\ \mbox{and}\ x\in B\cup C\\&\Longleftrightarrow x\in A\ \mbox{and}\ [x\in B\ \mbox{or}\ x\in C]\\&\Longleftrightarrow[x\in A\ \mbox{and}\ x\in B]\ \mbox{or}\ [x\in A\ \mbox{and}\ x\in C]\\&\Longleftrightarrow x\in A\cap B\ \mbox{or}\ x\in A\cap C\\&\Longleftrightarrow x\in(A\cap B)\cup(A\cap C)\end{align*}

The Cartesian product of two sets $A$ and $B$, denoted by $A\times B$, is defined by the set of ordered pairs with the first component taken from $A$ and the second component taken from $B$. $$A\times B=\{(a,b):a\in A\ \mbox{and}\ b\in B\}$$ Note that $\times$ is not an operation.

References.

[1] Essential Discrete Mathematics for Computer Science, Harry Lewis and Rachel Zax, Princeton University Press, 2019

[2] A Course in Universal Algebra, Stanley N. Burris and H. P. Sankappanavar, Graduate Texts in Mathematics, Springer-Verlag, 1981. The book is available online for free at the first named author’s web page here.