aboutsummaryrefslogtreecommitdiff
path: root/EqualProps.thy
blob: 3b0de79e9f10664e7f00bf61ea16f801699139bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(*  Title:  HoTT/EqualProps.thy
    Author: Josh Chen
    Date:   Jun 2018

Properties of equality.
*)

theory EqualProps
  imports
    HoTT_Methods
    Equal
    Prod
begin

section ‹Symmetry / Path inverse›

definition inv :: "[Term, Term, Term] ⇒ Term"  ("(1inv[_,/ _,/ _])")
  where "inv[A,x,y] ≡ ❙λp: (x =⇩A y). indEqual[A] (λx y _. y =⇩A x) (λx. refl(x)) x y p"

lemma inv_type:
  assumes "p : x =⇩A y"
  shows "inv[A,x,y]`p : y =⇩A x"

proof
  show "inv[A,x,y] : (x =⇩A y) → (y =⇩A x)"
  proof (unfold inv_def, standard)
    fix p assume asm: "p : x =⇩A y"
    show "indEqual[A] (λx y _. y =[A] x) refl x y p : y =⇩A x"
    proof standard+
      show "x : A" by (wellformed jdgmt: asm)
      show "y : A" by (wellformed jdgmt: asm)
    qed (assumption | rule | rule asm)+
  qed (wellformed jdgmt: assms)
qed (rule assms)


lemma inv_comp:
  assumes "a : A"
  shows "inv[A,a,a]`refl(a) ≡ refl(a)"

proof -
  have "inv[A,a,a]`refl(a) ≡ indEqual[A] (λx y _. y =⇩A x) (λx. refl(x)) a a refl(a)"
  proof (unfold inv_def, standard)
    show "refl(a) : a =⇩A a" using assms ..

    fix p assume asm: "p : a =⇩A a"
    show "indEqual[A] (λx y _. y =⇩A x) refl a a p : a =⇩A a"
    proof standard+
      show "a : A" by (wellformed jdgmt: asm)
      then show "a : A" .   ‹The elimination rule requires that both arguments to ‹indEqual› be shown to have the correct type.›
    qed (assumption | rule | rule asm)+
  qed

  also have "indEqual[A] (λx y _. y =⇩A x) (λx. refl(x)) a a refl(a) ≡ refl(a)"
    by (standard | assumption | rule assms)+

  finally show "inv[A,a,a]`refl(a) ≡ refl(a)" .
qed

section ‹Transitivity / Path composition›

 ‹"Raw" composition function›
definition compose' :: "Term ⇒ Term"  ("(1compose''[_])")
  where "compose'[A] ≡
    indEqual[A] (λx y _. ∏z:A. ∏q: y =⇩A z. x =⇩A z) (indEqual[A](λx z _. x =⇩A z) (❙λx:A. refl(x)))"

 ‹"Natural" composition function›
abbreviation compose :: "[Term, Term, Term, Term] ⇒ Term"  ("(1compose[_,/ _,/ _,/ _])")
  where "compose[A,x,y,z] ≡ ❙λp:x =⇩A y. ❙λq:y =⇩A z. compose'[A]`x`y`p`z`q"

(**** GOOD CANDIDATE FOR AUTOMATION ****)
lemma compose_comp:
  assumes "a : A"
  shows "compose[A,a,a,a]`refl(a)`refl(a) ≡ refl(a)" using assms Equal_intro[OF assms] unfolding compose'_def by simp

text "The above proof is a good candidate for proof automation; in particular we would like the system to be able to automatically find the conditions of the ‹using› clause in the proof.
This would likely involve something like:
  1. Recognizing that there is a function application that can be simplified.
  2. Noting that the obstruction to applying ‹Prod_comp› is the requirement that ‹refl(a) : a =⇩A a›.
  3. Obtaining such a condition, using the known fact ‹a : A› and the introduction rule ‹Equal_intro›."

lemmas Equal_simps [simp] = inv_comp compose_comp

subsubsection ‹Pretty printing›

abbreviation inv_pretty :: "[Term, Term, Term, Term] ⇒ Term"  ("(1_⇧-⇧1[_, _, _])" 500)
  where "p⇧-⇧1[A,x,y] ≡ inv[A,x,y]`p"

abbreviation compose_pretty :: "[Term, Term, Term, Term, Term, Term] ⇒ Term"  ("(1_ ∙[_, _, _, _]/ _)")
  where "p ∙[A,x,y,z] q ≡ compose[A,x,y,z]`p`q"