Skip to content
scrambled
Programming Language Theory Book

Chapter 2. Mathematical preliminaries

Concepts Covertypes-and-programming-languages JourneyProgramming Language Theory ParentTypes and programming languages StatusFinished Urlhttps://www.cis.upenn.edu/~bcpierce/tapl/

Sets, Relations, and Functions ​

Sets and Numbers ​

  • Standard notation:

    • Use {...} for explicit lists or comprehension (e.g., {x∈S|...}).

    • ∅ denotes the empty set.

    • S∖T denotes set difference (elements in S but not in T).

    • |S| denotes the size of set S.

    • 𝒫(S) is the powerset (set of all subsets) of S.

  • Natural numbers (ℕ): The set {0,1,2,...}.

  • Countable: A set is countable if it has a one-to-one correspondence with ℕ.

Relations ​

  • n-place relation: An n-ary relation.

  • Predicate: A one-place (unary) relation on a set S.

    Written P(s) or s∈P regarding P as a function mapping to truth values.

  • Binary relation: A two-place relation on sets S and T.

    Often written sRt instead of (s,t)∈R.

  • Mixfix syntax: For readability, relations with 3+ places often use symbols separating elements to form the name (e.g., Γ⊢s:T).

  • Domain & Codomain:

    • Domain (dom(R)): The set of elements s∈S such that (s,t)∈R for some t.

    • Codomain/Range (range(R)): The set of elements t∈T such that (s,t)∈R for some s.

  • Preservation: A predicate P is preserved by a relation R if sRs′ and P(s) implies P(s′).

Functions ​

  • Partial function: A relation R where (s,t1)∈R and (s,t2)∈R implies t1=t2.

    • Defined: Written f(x)↓ means x∈dom(f).

    • Undefined: Written f(x)↑ or f(x)= ⟂ means x∉dom(f).

  • Total function: A partial function where dom(R)=S.

  • Failure: Distinct from divergence.

    Formally, a function that may fail maps S→T∪{fail}.

Ordered sets ​

Properties of binary relations ​

Given a relation R on set S:

  • Reflexive: sRs for all s∈S.

  • Symmetric: sRt implies tRs.

  • Transitive: sRt and tRu implies sRu.

  • Antisymmetric: sRt and tRs implies s=t.

Types of orders ​

  • Preorder: A relation that is reflexive and transitive.

    • Notation: Often written ≤ or ≲.

    • Strict inequality (s<t): Means s≤t∧s≠t.

  • Partial order: A preorder that is also antisymmetric.

  • Total order: A partial order where for every s,t, either s≤t or t≤s.

  • Equivalence: A relation that is reflexive, transitive, and symmetric.

Bounds and Closures ​

  • Join (Least upper bound ∨): An element j is the join of s and t if s≤j, t≤j, and j is less than or equal to any other upper bound k.

  • Meet (Greatest lower bound ∧): An element m is the meet of s and t if m≤s, m≤t, and m is greater than or equal to any other lower bound n.

  • Closures:

    • Reflexive closure: The smallest reflexive relation containing R.

    • Transitive closure (R+): The smallest transitive relation containing R.

    • Reflexive and transitive closure (R∗): The smallest relation containing R that is both reflexive and transitive.

Chains and well-foundedness ​

  • Decreasing chain: A sequence s1,s2,... where si+1<si.

  • Well-founded: A preorder is well-founded if it contains no infinite decreasing chains.

    • Example: Standard order on ℕ is well-founded; standard order on integers is not.

Sequences ​

  • Notation: Elements are separated by commas (e.g., 3,2,1).

  • Cons and Append: The comma serves as both "cons" (adding an element) and "append" (joining sequences).

    • Example: If a=3,2,1, then 0,a is 0,3,2,1.

  • Range: 1..n abbreviates the sequence from 1 to n.

  • Length: |a| denotes the length of sequence a.

  • Empty sequence: Written as ϵ or a blank.

  • Permutation: A sequence containing the same elements as another, possibly in a different order.

Induction ​

Induction on natural numbers ​

  • Axiom: Principle of ordinary induction

    If P(0) holds, and P(i)⟹P(i+1) for all i, then P(n) holds for all n.

  • Axiom: Principle of complete induction

    If showing P(n) is possible assuming P(i) for all i<n, then P(n) holds for all n.

Lexicographic induction ​

  • Lexicographic order: On pairs of numbers, (m,n)≤(m′,n′) iff m<m′ OR (m=m′ and n≤n′).

  • Axiom: Principle of lexicographic induction

    If showing P(m,n) is possible assuming P(m′,n′) for all (m′,n′)<(m,n), then P(m,n) holds for all pairs.

  • Usage: Generalized to triples, 4-tuples, etc. Useful for nested inductions.


Exercises ​

Exercise 2.2.6 ​

Problem: Suppose we are given a relation R on a set S. Define the relation R′ as follows:

R′=R∪{(s,s)|s∈S}

That is, R′ contains all the pairs in R plus all pairs of the form (s,s) .

Task: Show that R′ is the reflexive closure of R.

Solution

Take R′′ to be the reflexive closure of R.

By definition:

  • R′′ is reflexive.

  • R⊆R′′.

  • For any reflexive relation S such that R⊆S, we have R′′⊆S.

By the problem statement, R′ is reflexive and R⊆R′.

Therefore, R′′⊆R′.

Now, it suffices to show that R′⊆R′′.

Take an element x∈R′.

  • If x∈R, then x∈R′′.

  • If x=(s,s) for some s∈S, then x∈R′′ because R′′ is reflexive.

Therefore, R′⊆R′′.

In conclusion, R′≡R′′ or R′ is the reflexive closure of R.

Exercise 2.2.7 ​

Problem: Here is a more constructive definition of the transitive closure of a relation R. First, we define the following sequence of sets of pairs:

  • R0=R

  • Ri+1=Ri∪{(s,u)|for some t,(s,t)∈Ri and (t,u)∈Ri}

That is, we construct each Ri+1 by adding to Ri all the pairs that can be obtained by "one step of transitivity" from pairs already in Ri. Finally, define the relation R+ as the union of all the Ri: R+=⋃iRi.

Task: Show that this R+ is really the transitive closure of R-i.e., that it satisfies the conditions given in Definition 2.2.5.

  • Problem

    Take R′ to be the transitive closure of R.

    By definition:

    • R′ is transitive.

    • R⊆R′.

    • For any transitive relation S such that R⊆S, we have R′⊆S.

    • Prove that R+ is transitive

      Suppose there exist s,r,t such that (s,r)∈R+ and (r,t)∈R+ but (s,t)∉R+.

      Because (s,r)∈R+, there exists i0 such that (s,r)∈Ri0.

      Similarly, there exists i1 such that (r,t)∈Ri1.

      Therefore, we have (s,r)∈Rmin⁡i0,i1 and (r,t)∈Rmin⁡i0,i1. Then, (s,t)∈Rmin⁡i0,i1+1⊆R+. This is a contradiction.

    • It's obvious that R⊆R+.

    • Therefore, R′⊆R+.

    • Prove that R+⊆R′

      It's obvious that R0≡R⊆R′.

      Suppose for Ri⊆R′ for some i≥0.

      We will prove that Ri+1⊆R′. This is trivial.

      By induction, Ri⊆R′ for any i≥0.

      Therefore, R+⊆R′.

    • In conclusion, R+≡R′.

Exercise 2.2.8 ​

Problem: Suppose R is a binary relation on a set S and P is a predicate on S that is preserved by R.

Task: Show that P is also preserved by R∗ (the reflexive and transitive closure of R).

  • Problem

    Because P is a predicate on S that is preserved by R: For any r,t∈S such that rRt, we have P(r)⟹P(t).

    Take Rref to be the reflexive closure of R.

    Then, R∗ is the transitive closure of Rref.

    Assume r,t∈S such that rR∗t.

    • If rRt, it's trivial that P is preserved.

    • If rR̸t but rRreft, then r=t. Therefore, P is also preserved.

    • If rR̸reft but rR∗t, that means rRit for some i≥0, with Ri as defined in the previous exercise.

      Assume i is smallest such number.

      • i must not be 0, else we would have rRreft, a contradiction.

      • Assume that if riRiti then P(ri)⟹P(ti).

        We will prove that if ri+1Ri+1ti+1 then P(ri+1)⟹P(ti+1).

        By assumption, ri+1R̸iti+1.

        Therefore, there exists s such that ri+1Ris and sRiti+1.

        By the induction hypothesis, we have P(ri+1)⟹P(s) and P(s)⟹P(ti+1).

        It follows that, P(ri+1)⟹P(ti+1).

        By induction, if rRit for any i, we have P(r)⟹P(t).

      This concludes our proof.