The Proofs and Programs Club @ RHUL

Laws at a Glance

Notation

WriteReadDefined in
\(\sel{p}(R)\)the rows of \(R\) that satisfy \(p\) (selection)2F, 2T
\(f[R]\), \(\pi_1[R]\)\(f\) applied to every row (image, projection)3F, 4T
\(R \times S\)every row of \(R\) paired with every row of \(S\) (product)3F, 4T
\(R \cup S\)the rows in \(R\) or \(S\) (union)3F, 2T
\(R - S\), \(R \cap S\)the rows of \(R\) not in \(S\); in both4F, 3T
\(R \join_{k_1 = k_2} S\)the pairs whose keys agree (join)4F
\(\proj{A}(R)\), \(\ren{a}{b}(R)\)keep the attributes \(A\); rename \(a\) to \(b\)5F
\(R \join S\), \(R \div S\)natural join; division5F
\(\lBrack q \rBrack\)the answer of the query \(q\)5F
\(\mathit{table}(l)\)the table the list \(l\) represents1, 6

The laws

LawHolds whenProved
1\(\sel{p}(\sel{q}(R)) = \sel{p \wedge q}(R)\)always2T; for lists 5T, 6
2\(\sel{p}(\sel{q}(R)) = \sel{q}(\sel{p}(R))\)always2T
3\(\sel{p}(R \cup S) = \sel{p}(R) \cup \sel{p}(S)\)always2T
4\(\sel{p}(R - S) = \sel{p}(R) - S\)always3T
5\(\sel{p}(R \times S) = \sel{p}(R) \times S\)\(p\) mentions only \(R\)4T; for queries 7
6\(\sel{p}(R \join S) = \sel{p}(R) \join S\)\(p\) mentions only \(R\)7
7\(\proj{A}(\proj{B}(R)) = \proj{A}(R)\)\(A \subseteq B\)7
8\(\proj{A}(R \cup S) = \proj{A}(R) \cup \proj{A}(S)\)always7; images 4T
9\(\proj{A}(\sel{p}(R)) = \sel{p}(\proj{A}(R))\)\(p\) mentions only \(A\)7
10\(R \join S = S \join R\)always7
11\((R \join S) \join T = R \join (S \join T)\)always7

A side condition is part of the law: without it, the two sides differ, or one of them makes no sense (Exercise 4T.3, Question 7.B).

Traps: these are not laws

Looks like a lawButSee
\(\proj{A}(R - S) = \proj{A}(R) - \proj{A}(S)\)false: projection can forget what made two rows differQuestion 7.A
\(f[R \cap S] = f[R] \cap f[S]\)only \(\subseteq\) holdsQuestion 4T.B
\(\pi_1[R \times S] = R\)only when \(S\) is not emptyQuestion 4T.A
\(R \times S = S \times R\)false with positional columns; true with namesQuestion 3F.D
\(R - (R - S) = S\)it is \(R \cap S\)Question 3T.C
\(l \cat l = l\), for liststrue for the tables they represent, not for listsQuestion 3F.F

Every definition, fact and law, level by level

Level 1: Tables, and Your First Proof

Level 2F: Selection, as a Program

Level 3F: Projection, Product and Union, as Programs

Level 4F: Difference and Joins, by Comparing Rows

Level 5F: Named Columns, and a Query Language

Level 2T: Selection and Union, Proved

Level 3T: Difference, Proved: “Not”, and Classical Logic

Level 4T: Product and Projection, Proved: “For All” and “There Exists”

Level 5T: Induction on Lists

Level 6: Lists Represent Tables

Level 7: The Laws, for Every Query

Level 8: An Optimiser

Level 9: Fast Joins