-
Notifications
You must be signed in to change notification settings - Fork 248
Some lemmas related to renamings and substitutions #1750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bdb964d
Changed the fixity of _/Var_.
nad 3ec8125
Added some lemmas relating renamings to substitutions.
nad 41f796f
added fixity change
jamesmckinna c392073
fixing whitespace per library convention
jamesmckinna 6123b7d
cosmetic, but significant, overhaul after review comments
jamesmckinna a3dc1e1
resolved merge conflict
jamesmckinna 2c3e68d
Merge branch 'master' into renamings_and_substitutions
jamesmckinna c61d7fa
Merge branch 'master' into renamings_and_substitutions
MatthewDaggitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- An example of how Data.Fin.Substitution can be used: a definition | ||
-- of substitution for the untyped λ-calculus, along with some lemmas | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
module README.Data.Fin.Substitution.UntypedLambda where | ||
|
||
open import Data.Fin.Substitution | ||
open import Data.Fin.Substitution.Lemmas | ||
open import Data.Nat.Base hiding (_/_) | ||
open import Data.Fin.Base using (Fin) | ||
open import Data.Vec.Base | ||
open import Relation.Binary.PropositionalEquality.Core | ||
using (_≡_; refl; sym; cong; cong₂; module ≡-Reasoning) | ||
open import Relation.Binary.Construct.Closure.ReflexiveTransitive | ||
using (Star; ε; _◅_) | ||
|
||
open ≡-Reasoning | ||
|
||
private | ||
variable | ||
m n : ℕ | ||
|
||
------------------------------------------------------------------------ | ||
-- A representation of the untyped λ-calculus. Uses de Bruijn indices. | ||
|
||
infixl 9 _·_ | ||
|
||
data Lam (n : ℕ) : Set where | ||
var : (x : Fin n) → Lam n | ||
ƛ : (t : Lam (suc n)) → Lam n | ||
_·_ : (t₁ t₂ : Lam n) → Lam n | ||
|
||
------------------------------------------------------------------------ | ||
-- Code for applying substitutions. | ||
|
||
module LamApp {ℓ} {T : ℕ → Set ℓ} (l : Lift T Lam) where | ||
open Lift l hiding (var) | ||
|
||
-- Applies a substitution to a term. | ||
|
||
infixl 8 _/_ | ||
|
||
_/_ : Lam m → Sub T m n → Lam n | ||
var x / ρ = lift (lookup ρ x) | ||
ƛ t / ρ = ƛ (t / ρ ↑) | ||
t₁ · t₂ / ρ = (t₁ / ρ) · (t₂ / ρ) | ||
|
||
open Application (record { _/_ = _/_ }) using (_/✶_) | ||
|
||
-- Some lemmas about _/_. | ||
|
||
ƛ-/✶-↑✶ : ∀ k {t} (ρs : Subs T m n) → | ||
ƛ t /✶ ρs ↑✶ k ≡ ƛ (t /✶ ρs ↑✶ suc k) | ||
ƛ-/✶-↑✶ k ε = refl | ||
ƛ-/✶-↑✶ k (ρ ◅ ρs) = cong (_/ _) (ƛ-/✶-↑✶ k ρs) | ||
|
||
·-/✶-↑✶ : ∀ k {t₁ t₂} (ρs : Subs T m n) → | ||
t₁ · t₂ /✶ ρs ↑✶ k ≡ (t₁ /✶ ρs ↑✶ k) · (t₂ /✶ ρs ↑✶ k) | ||
·-/✶-↑✶ k ε = refl | ||
·-/✶-↑✶ k (ρ ◅ ρs) = cong (_/ _) (·-/✶-↑✶ k ρs) | ||
|
||
lamSubst : TermSubst Lam | ||
lamSubst = record { var = var; app = LamApp._/_ } | ||
|
||
open TermSubst lamSubst hiding (var) | ||
|
||
------------------------------------------------------------------------ | ||
-- Substitution lemmas. | ||
|
||
lamLemmas : TermLemmas Lam | ||
lamLemmas = record | ||
{ termSubst = lamSubst | ||
; app-var = refl | ||
; /✶-↑✶ = Lemma./✶-↑✶ | ||
} | ||
where | ||
module Lemma {T₁ T₂} {lift₁ : Lift T₁ Lam} {lift₂ : Lift T₂ Lam} where | ||
|
||
open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_) | ||
open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_) | ||
|
||
/✶-↑✶ : (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) → | ||
(∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) → | ||
∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k | ||
/✶-↑✶ ρs₁ ρs₂ hyp k (var x) = hyp k x | ||
/✶-↑✶ ρs₁ ρs₂ hyp k (ƛ t) = begin | ||
ƛ t /✶₁ ρs₁ ↑✶₁ k ≡⟨ LamApp.ƛ-/✶-↑✶ _ k ρs₁ ⟩ | ||
ƛ (t /✶₁ ρs₁ ↑✶₁ suc k) ≡⟨ cong ƛ (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) t) ⟩ | ||
ƛ (t /✶₂ ρs₂ ↑✶₂ suc k) ≡⟨ sym (LamApp.ƛ-/✶-↑✶ _ k ρs₂) ⟩ | ||
ƛ t /✶₂ ρs₂ ↑✶₂ k ∎ | ||
/✶-↑✶ ρs₁ ρs₂ hyp k (t₁ · t₂) = begin | ||
t₁ · t₂ /✶₁ ρs₁ ↑✶₁ k ≡⟨ LamApp.·-/✶-↑✶ _ k ρs₁ ⟩ | ||
(t₁ /✶₁ ρs₁ ↑✶₁ k) · (t₂ /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong₂ _·_ (/✶-↑✶ ρs₁ ρs₂ hyp k t₁) | ||
(/✶-↑✶ ρs₁ ρs₂ hyp k t₂) ⟩ | ||
(t₁ /✶₂ ρs₂ ↑✶₂ k) · (t₂ /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (LamApp.·-/✶-↑✶ _ k ρs₂) ⟩ | ||
t₁ · t₂ /✶₂ ρs₂ ↑✶₂ k ∎ | ||
|
||
open TermLemmas lamLemmas public hiding (var) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.