§ Logical Relations (Sterling)
- Key idea is to consider relations Rτ between closed terms of types τl and τr. That is, we have have a relation Rτ⊆{(tl,tr):(⋅⊢tl:τl),(⋅⊢tr:τr).
- We write a relation between two closed terms τL and τR as: Rτ≡(⋅⊢τL)×(⋅⊢τR).
- A morphism of relations f:RσtoRτ is given by two functions fl:σl→τl and fr:σr→τrsuch that aRσb⟹fl(a)Rτfr(b).
§ Logical relations for function spaces
- Given this, we can build up logical relations for more complex cases like function types and quantified types. For example, given logical relations Rσ and Rτ, we build Rσ→τ to be the relation between types (⋅⊢σl→τl)×(⋅⊢σr→τr), and given by the formula:
(fl:σl→τl,fr:σr→τr):Rσ→τ≡∀(xl:σl,xr:σr)∈Rσ,(fl(xl),fr(xr))∈Rτ
- This satisfies the universal property of functions in the category of logical relations, ie, there is an adjunction between Rρ→σ→Rτ and Rρ→Rσ→τ.
- Next, we can interpret a base type like
bool
by the logical relation that encodes equality on that type. so Rbool:(⋅⊢bool)×(⋅⊢bool) and is given by:
§ Logical relations for data types
Rbool≡{(true, true),(false, false)}
§ Logical relations for parametric types
- for a type of the form τ(α) that is parametric in α, suppose we have a family of relations Rτα⊆{(⋅⊢τl(αl)×(⋅⊢τr(αr)}Rαwhich vary in Rα.
- Then we define the logical relation for the type R∀α,τ(α)⊆(⋅⊢∀ατl(α))×(⋅⊢∀ατr(α)) as:
R∀α,τ(α)≡{(fl:∀α,τl(α),fr:∀α,τr(α))∣∀Rα,(fl(αl),fr(αr))∈Rτ(α)}
§ Proving things using logical relations
- For f:∀α,α→bool, we have that f@unit(())=f@bool(true)That is, the function value at
() : unit
determines the value of the function also at true: bool
(and more generally, everwhere).
- To prove this, we first invoke that by soundness , we have that (f,f)∈R∀α.α→bool. On unwrapping this, this means that:
∀Rα,∀(xl,xr)∈Rα,((f(xl),f(xr))∈Rbool)
- Plugging in Rbool, this gives us an equality:
∀Rα,∀(xl,xr)∈Rα,(f(xl)=f(xr))
- We now choose Rα⊆(⋅⊢unit)×(⋅⊢bool), with the singleton element {((),true)}.
§ (x/p) is x(p−1)/2
- Since x is coprime to p, we have that 1≡xp−1
- This can be written as 12−x(p−1/2)2=0. [ (p−1) is even when p>2].
- That is, (1−x(p−1)/2)(1+x(p−1)/2)=0.
- Since we are in an integral domain (really a field), this means that x(p−1)/2≡±1(modp).