Identity.agda 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module Identity where
  2. data _==_ {A : Set}(x : A) : A -> Set where
  3. refl : x == x
  4. elim== : {A : Set}(x : A)(C : (y : A) -> x == y -> Set) ->
  5. C x refl -> (y : A) -> (p : x == y) -> C y p
  6. elim== x C Cx .x refl = Cx
  7. elim==₁ : {A : Set}(x : A)(C : (y : A) -> x == y -> Set1) ->
  8. C x refl -> (y : A) -> (p : x == y) -> C y p
  9. elim==₁ x C Cx .x refl = Cx
  10. sym : {A : Set}{x y : A} -> x == y -> y == x
  11. sym {A}{x}{y} eq = elim== x (\z _ -> z == x) refl y eq
  12. cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y
  13. cong {A} f {x}{y} eq = elim== x (\z _ -> f x == f z) refl y eq
  14. subst : {A : Set}{x y : A}(P : A -> Set) -> x == y -> P x -> P y
  15. subst P xy px = elim== _ (\z _ -> P z) px _ xy
  16. subst₁ : {A : Set}{x y : A}(P : A -> Set1) -> x == y -> P x -> P y
  17. subst₁ P xy px = elim==₁ _ (\z _ -> P z) px _ xy
  18. symRef : (A : Set)(x : A) -> sym (refl{A}{x}) == refl
  19. symRef A x = refl
  20. symSym : {A : Set}{x y : A}(p : x == y) -> sym (sym p) == p
  21. symSym {A}{x}{y} p = elim== x (\y q -> sym (sym q) == q) refl y p
  22. -- Proving the symmetric elimination rule is not trivial.
  23. elimS : {A : Set}(x : A)(C : (y : A) -> y == x -> Set) ->
  24. C x refl -> (y : A) -> (p : y == x) -> C y p
  25. elimS x C r y p = subst (C y) (symSym p) h
  26. where
  27. h : C y (sym (sym p))
  28. h = elim== x (\y p -> C y (sym p)) r y (sym p)
  29. data _==¹_ {A : Set1}(x : A) : {B : Set1} -> B -> Set where
  30. refl¹ : x ==¹ x
  31. subst¹ : {A : Set1}{x y : A}(P : A -> Set) -> x ==¹ y -> P x -> P y
  32. subst¹ {A} P refl¹ px = px