-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMu.v
110 lines (84 loc) · 2.71 KB
/
Mu.v
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(** * Mu.V *)
(** Derivation of "positive-retractive" types. [Mu] is a least fixed-point
operator for signature functors which are positive (but needn't be strictly
positive). *)
Require Import Kinds.
Require Import CastAlg.
Require Import Functors.
Require Import Coq.Setoids.Setoid.
Section Mu.
Variable F : Set -> Set.
Context {FunF : Functor F}.
Definition MAlgebra
(A : Set) :=
forall (R : Set), (R -> A) -> F R -> A.
Inductive Mu : Set :=
mu : MAlgebra Mu.
Definition inMu(d : F Mu) : Mu :=
mu Mu (fun x => x) d.
Definition outMu(m : Mu) : F Mu :=
match m with
| mu A r d => fmap r d
end.
Definition retraction : forall(d : F Mu), outMu (inMu d) = d.
simpl.
intro d.
rewrite fmapId.
trivial.
Qed.
(** The definitions below show that canonicity can be recovered using a
normalization equivalence relation; these definitions are not used elsewhere in
our development, though. *)
Definition IndMu(m : Mu) : Set :=
forall X : Mu -> Set,
(forall(R:Set)(reveal : R -> Mu),
(forall r : R, X (reveal r)) ->
forall d : F R ,
X (mu R reveal d))->
X m.
Fixpoint Mu_fold
{A : Set}
(alg : MAlgebra A)
(m : Mu)
{struct m} : A :=
match m with
mu A reveal d => alg _ (fun r => Mu_fold alg (reveal r) ) d
end.
Definition normalize_Mu (m : Mu) : Mu :=
Mu_fold (fun R rec fr => inMu (fmap rec fr)) m.
Definition Mu_equiv (m1 m2 : Mu) : Prop := normalize_Mu m1 = normalize_Mu m2.
Lemma Mu_equiv_refl : Reflexive Mu_equiv.
unfold Reflexive; reflexivity.
Qed.
Lemma Mu_equiv_sym : Symmetric Mu_equiv.
unfold Symmetric; symmetry; eauto.
Qed.
Lemma Mu_equiv_trans : Transitive Mu_equiv.
unfold Transitive; etransitivity; eauto.
Qed.
#[global] Add Relation Mu Mu_equiv
reflexivity proved by Mu_equiv_refl
symmetry proved by Mu_equiv_sym
transitivity proved by Mu_equiv_trans
as Mu_equiv_rel.
Infix "≈" := Mu_equiv (at level 90).
End Mu.
(**
Higher-ordered [Mu] over [KAlg].
This permits non-strictly positive occurrences of [Alg] in defining
[Alg] via its (higher ordered) [AlgF].
*)
Section MuAlg.
Variable F : KAlg -> KAlg.
Variable algMap : forall {A B : KAlg}, CastAlg A B -> CastAlg (F A) (F B).
Inductive MuAlg : KAlg :=
muAlg : forall A : KAlg,
(forall (X : Set -> Set), A X -> MuAlg X) ->
forall (X : Set -> Set), F A X -> MuAlg X.
Definition inMuAlg {X : Set -> Set} (d : (F MuAlg) X) : MuAlg X :=
muAlg MuAlg (fun X x => x) X d.
Definition outMuAlg{X : Set -> Set} (v : MuAlg X) : (F MuAlg) X :=
match v with
| muAlg A r X1 d => algMap r X1 d
end.
End MuAlg.