Debian Codegraph @

test-suite/success/vm_univ_poly.v

raw
1 (* Basic tests *)
2 Polymorphic Definition pid {T : Type} (x : T) : T := x.
3 (*
4 Definition _1 : pid true = true :=
5 @eq_refl _ true <: pid true = true.
6
7 Polymorphic Definition a_type := Type.
8
9 Definition _2 : a_type@{i} = Type@{i} :=
10 @eq_refl _ Type@{i} <: a_type@{i} = Type@{i}.
11
12 Polymorphic Definition FORALL (T : Type) (P : T -> Prop) : Prop :=
13 forall x : T, P x.
14
15 Polymorphic Axiom todo : forall {T:Type}, T -> T.
16
17 Polymorphic Definition todo' (T : Type) := @todo T.
18
19 Definition _3 : @todo'@{Set} = @todo@{Set} :=
20 @eq_refl _ (@todo@{Set}) <: @todo'@{Set} = @todo@{Set}.
21 *)
22
23 (* Inductive Types *)
24 Inductive sumbool (A B : Prop) : Set :=
25 | left : A -> sumbool A B
26 | right : B -> sumbool A B.
27
28 Definition x : sumbool True False := left _ _ I.
29
30 Definition sumbool_copy {A B : Prop} (H : sumbool A B) : sumbool A B :=
31 match H with
32 | left _ _ x => left _ _ x
33 | right _ _ x => right _ _ x
34 end.
35
36 Definition _4 : sumbool_copy x = x :=
37 @eq_refl _ x <: sumbool_copy x = x.
38
39 (* Polymorphic Inductive Types *)
40 Polymorphic Inductive poption@{i} (T : Type@{i}) : Type@{i} :=
41 | PSome : T -> poption T
42 | PNone : poption T.
43
44 Polymorphic Definition poption_default@{i} {T : Type@{i}} (p : poption@{i} T) (x : T) : T :=
45 match p with
46 | @PSome _ y => y
47 | @PNone _ => x
48 end.
49
50 Polymorphic Inductive plist@{i} (T : Type@{i}) : Type@{i} :=
51 | pnil
52 | pcons : T -> plist T -> plist T.
53
54 Arguments pnil {_}.
55 Arguments pcons {_} _ _.
56
57 Polymorphic Definition pmap@{i j}
58 {T : Type@{i}} {U : Type@{j}} (f : T -> U) :=
59 fix pmap (ls : plist@{i} T) : plist@{j} U :=
60 match ls with
61 | @pnil _ => @pnil _
62 | @pcons _ l ls => @pcons@{j} U (f l) (pmap ls)
63 end.
64
65 Universe Ubool.
66 Inductive tbool : Type@{Ubool} := ttrue | tfalse.
67
68
69 Eval vm_compute in pmap pid (pcons true (pcons false pnil)).
70 Eval vm_compute in pmap (fun x => match x with
71 | pnil => true
72 | pcons _ _ => false
73 end) (pcons pnil (pcons (pcons false pnil) pnil)).
74 Eval vm_compute in pmap (fun x => x -> Type) (pcons tbool (pcons (plist tbool) pnil)).
75
76 Polymorphic Inductive Tree@{i} (T : Type@{i}) : Type@{i} :=
77 | Empty
78 | Branch : plist@{i} (Tree T) -> Tree T.
79
80 Polymorphic Definition pfold@{i u}
81 {T : Type@{i}} {U : Type@{u}} (f : T -> U -> U) :=
82 fix pfold (acc : U) (ls : plist@{i} T) : U :=
83 match ls with
84 | pnil => acc
85 | pcons a b => pfold (f a acc) b
86 end.
87
88 Polymorphic Inductive nat@{i} : Type@{i} :=
89 | O
90 | S : nat -> nat.
91
92 Polymorphic Fixpoint nat_max@{i} (a b : nat@{i}) : nat@{i} :=
93 match a , b with
94 | O , b => b
95 | a , O => a
96 | S a , S b => S (nat_max a b)
97 end.
98
99 Polymorphic Fixpoint height@{i} {T : Type@{i}} (t : Tree@{i} T) : nat@{i} :=
100 match t return nat@{i} with
101 | Empty _ => O
102 | Branch _ ls => S@{i} (pfold@{i i} nat_max O (pmap height ls))
103 end.
104
105 Polymorphic Fixpoint repeat@{i} {T : Type@{i}} (n : nat@{i}) (v : T) : plist@{i} T :=
106 match n return plist@{i} T with
107 | O => pnil
108 | S n => pcons@{i} v (repeat n v)
109 end.
110
111 Polymorphic Fixpoint big_tree@{i} (n : nat@{i}) : Tree@{i} nat@{i} :=
112 match n with
113 | O => @Empty nat@{i}
114 | S n' => Branch@{i} nat@{i} (repeat@{i} n' (big_tree n'))
115 end.
116
117 Eval compute in height (big_tree (S (S (S O)))).
118
119 #[local] Definition big := S (S (S (S (S O)))).
120 Polymorphic Definition really_big@{i} := (S@{i} (S (S (S (S (S (S (S (S (S O)))))))))).
121
122 Time Definition _5 : height (@Empty nat) = O :=
123 @eq_refl nat O <: height (@Empty nat) = O.
124
125 Time Definition _6 : height@{Set} (@Branch nat pnil) = S O :=
126 @eq_refl nat@{Set} (S@{Set} O@{Set}) <: @eq nat@{Set} (height@{Set} (@Branch@{Set} nat@{Set} (@pnil@{Set} (Tree@{Set} nat@{Set})))) (S@{Set} O@{Set}).
127
128 Time Definition _7 : height (big_tree big) = big :=
129 @eq_refl nat big <: height (big_tree big) = big.
130
131 Time Definition _8 : height (big_tree really_big) = really_big :=
132 @eq_refl nat@{Set} (S@{Set}
133 (S@{Set}
134 (S@{Set}
135 (S@{Set}
136 (S@{Set}
137 (S@{Set} (S@{Set} (S@{Set} (S@{Set} (S@{Set} O@{Set}))))))))))
138 <:
139 @eq nat@{Set}
140 (@height nat@{Set} (big_tree really_big@{Set}))
141 really_big@{Set}.