File: enumSTProofs.v

package info (click to toggle)
coq-quickchick 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,432 kB
  • sloc: ml: 4,367; ansic: 789; makefile: 388; sh: 27; python: 4; lisp: 2; perl: 2
file content (233 lines) | stat: -rw-r--r-- 7,700 bytes parent folder | download | duplicates (4)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
From QuickChick Require Import QuickChick Tactics TacticsUtil Instances Classes
     DependentClasses CheckerProofs EnumProofs.

Require Import String. Open Scope string.
Require Import List micromega.Lia.
Require Import enumProofs. 

Import ListNotations.
From mathcomp Require Import ssreflect ssrfun ssrbool ssrnat eqtype seq.

From Ltac2 Require Import Ltac2.

#[local] Open Scope set_scope.

Inductive square_of : nat -> nat -> Prop :=
  sq : forall n m, m = n * n -> square_of n m.

Derive EnumSizedSuchThat for (fun x => square_of x n).

Inductive tree1 :=
| Leaf1 : tree1
| Node1 : nat -> tree1 -> tree1 -> tree1.

Inductive perfect' : nat -> tree1 -> Prop :=
| PerfectLeaf : perfect' 0 Leaf1
| PerfectNode : forall x l r n, perfect' n l -> perfect' n r ->
                                perfect' (S n) (Node1 x l r).

Derive DecOpt for (perfect' n t).

Derive EnumSizedSuchThat for (fun n => perfect' n t).

Inductive perfect : tree1 -> Prop :=
| Perfect : forall n t, perfect' n t -> perfect t.

Derive DecOpt for (perfect t).

Lemma semProdSizeOpt_bicupNone A s (S : set A) :
  (\bigcup_(x in [:: returnEnum (@None A)]) semProdSizeOpt x s \subset S).
Proof.
  intros x Hin. inv Hin. inv H. inv H0.
  - inv H1. congruence.
    inv H.
  - inv H.
Qed.

Set Bullet Behavior "Strict Subproofs".

Inductive In' {A} : A -> list A -> Prop :=
| In_hd :
    forall x l, In' x (cons x l)
| In_tl :
    forall x y l, In' x l -> In' x (cons y l).


Derive DecOpt for (In' a l).
 
Instance DecOptIn'_listSizeMonotonic A {_ : Enum A} {_ : Dec_Eq A}
         (x : A) (l : list A) : DecOptSizeMonotonic (In' x l).
Proof. derive_mon (). Qed.

Instance DecOptIn'_list_sound A {_ : Enum A} {_ : Dec_Eq A} (x : A) (l : list A) :
  DecOptSoundPos (In' x l).
Proof. derive_sound (). Qed.

Instance DecOptIn'_list_complete A {_ : Enum A} {_ : Dec_Eq A} (x : A) (l : list A) :
  DecOptCompletePos (In' x l).
Proof. derive_complete (). Qed.

Derive ArbitrarySizedSuchThat for (fun x => In' x l).
Derive EnumSizedSuchThat for (fun x => In' x l).

Instance EnumSizedSuchThatIn'_SizedMonotonic A {_ : Enum A} {_ : Dec_Eq A} l :
  SizedMonotonicOpt (@enumSizeST A _ (EnumSizedSuchThatIn' l)).
Proof. derive_enumST_SizedMonotonic (). Qed.

Instance EnumSizedSuchThatIn'_SizeMonotonic  A {_ : Enum A} {_ : Dec_Eq A}
         (* `{EnumMonotonic A} *) l :
  forall s, SizeMonotonicOpt (@enumSizeST _ _ (EnumSizedSuchThatIn' l) s).
Proof. derive_enumST_SizeMonotonic (). Qed.


Instance EnumSizedSuchThatIn'_Correct A {_ : Enum A}  {_ : Dec_Eq A}
         (* `{EnumMonotonicCorrect A} *) l :
  CorrectSizedST (fun x => In' x l) (@enumSizeST _ _ (EnumSizedSuchThatIn' l)).
Proof. derive_enumST_Correct (). Admitted. (* TODO *)
 
Derive EnumSizedSuchThat for (fun l => In' x l).


Inductive bst : nat -> nat -> tree1 -> Prop :=
| BstLeaf : forall n1 n2, bst n1 n2 Leaf1
| BstNode : forall min max n t1 t2,
    le min max -> le min n -> le n max ->
    bst min n t1 -> bst n max t2 ->
    bst min max (Node1 n t1 t2).

Derive DecOpt for (le min max).
Derive EnumSizedSuchThat for (fun m => le n m).

Derive EnumSizedSuchThat for (fun t => bst min max t).

Derive ArbitrarySizedSuchThat for (fun m => le n m).
Derive ArbitrarySizedSuchThat for (fun t => bst min max t).

Derive DecOpt for (bst min max t).
  
Instance EnumSizedSuchThatle_SizedAMonotonic n :
  SizedMonotonicOptFP (@enumSizeST _ _ (@EnumSizedSuchThatle n)).
Proof. derive_enumST_SizedMonotonicFP (). Qed. 

Instance EnumSizedSuchThatle_SizedMonotonic n :
  SizedMonotonicOpt (@enumSizeST _ _ (@EnumSizedSuchThatle n)).
Proof. derive_enumST_SizedMonotonic (). Qed.

Instance EnumSizedSuchThatle_SizeMonotonic n :
  forall s, SizeMonotonicOpt (@enumSizeST _ _ (@EnumSizedSuchThatle n) s).
Proof. derive_enumST_SizeMonotonic (). Qed.

Instance EnumSizedSuchThatle_SizeMonotonicFP n :
  forall s, SizeMonotonicOptFP (@enumSizeST _ _ (@EnumSizedSuchThatle n) s).
Proof. derive_enumST_SizeMonotonicFP (). Qed. 

(* XXX predicate must be eta expanded, otherwise typeclass resolution fails *)
Instance EnumSizedSuchThatle_Correct n :
  CorrectSizedST [eta le n] (@enumSizeST _ _ (@EnumSizedSuchThatle n)).
Proof. derive_enumST_Correct (). Qed.

Instance EnumSizedSuchThatbst_SizedMonotonicFP min max :
  SizedMonotonicOptFP (@enumSizeST _ _ (@EnumSizedSuchThatbst min max)).
Proof. derive_enumST_SizedMonotonicFP (). Qed.

Instance EnumSizedSuchThatbst_SizedMonotonic min max :
  SizedMonotonicOpt (@enumSizeST _ _ (@EnumSizedSuchThatbst min max)).
Proof. derive_enumST_SizedMonotonic (). Qed.  

Instance EnumSizedSuchThatbst_SizeMonotonic min max :
  forall s, SizeMonotonicOpt (@enumSizeST _ _ (@EnumSizedSuchThatbst min max) s).
Proof. derive_enumST_SizeMonotonic (). Qed.

Instance EnumSizedSuchThatbst_SizeMonotonicFP min max :
  forall s, SizeMonotonicOptFP (@enumSizeST _ _ (@EnumSizedSuchThatbst min max) s).
Proof. derive_enumST_SizeMonotonicFP (). Qed.
  
Instance EnumSizedSuchThatbst_Correct n m :
  CorrectSizedST (bst n m) (@enumSizeST _ _ (@EnumSizedSuchThatbst n m)).
Proof. derive_enumST_Correct (). Qed.


(* XXX missing enum list instances. *) 
(* Instance EnumSizedSuchThatIn'0_SizedMonotonic A {_ : Enum A} x : *)
(*   SizedMonotonicOpt (@enumSizeST _ _ (EnumSizedSuchThatIn'0 x)). *)
(* Proof. derive_enumST_SizedMonotonic (). Qed. *)


Inductive ltest : list nat -> nat -> Prop :=
  | ltestnil :
      ltest [] 0
  | ltestcons :
      forall x m' m l,
        (m' + 1) = m ->
        (* In' m' l -> *)
        ltest l m' ->
        ltest (x :: l) m.


Derive EnumSizedSuchThat for (fun n => eq x n).
Derive EnumSizedSuchThat for (fun n => eq n x).

Derive DecOpt for (ltest l n).

Instance DecOptltest_listSizeMonotonic l x : DecOptSizeMonotonic (ltest l x).
Proof. derive_mon (). Qed.

Instance DecOptltest_listsound l x : DecOptSoundPos (ltest l x).
Proof. derive_sound (). Qed. 

Instance DecOptIn'ltest_complete A {_ : Enum A} {_ : Dec_Eq A} x l :
  DecOptCompletePos (ltest x l).
Proof. derive_complete (). Qed.

(* Set Typeclasses Debug. *)
(* QuickChickDebug Debug On. *)

(* XXX error *)
(* Derive EnumSizedSuchThat for (fun l => ltest l n). *)

Inductive goodTree : nat -> tree nat  -> Prop :=
| GL : forall a, goodTree 0 (Leaf nat a)
| GN :
    forall k t1 t2 n (* m : nat)*),
      (* le m n -> *)
      goodTree n t1 ->
      goodTree n t1 ->
      goodTree (S n) (Node nat k t1 t2).

Derive DecOpt for (goodTree n t).

(* XXX this fails if tree has type param A ... *) 

Instance DecOptgoodTree_listSizeMonotonic n t : DecOptSizeMonotonic (goodTree n t).
Proof. derive_mon (). Qed.

Instance DecOptgoodTree_list_sound n t : DecOptSoundPos (goodTree n t).
Proof. derive_sound (). Qed.

Instance DecOptgoodTree_list_complete n t : DecOptCompletePos (goodTree n t).
Proof. derive_complete (). Qed.

Derive EnumSizedSuchThat for (fun t => goodTree k t).



Instance EnumSizedSuchThatgoodTree_SizedMonotonic n :
  SizedMonotonicOpt (@enumSizeST _ _ (@EnumSizedSuchThatgoodTree n)).
Proof. derive_enumST_SizedMonotonic (). Qed.

Instance EnumSizedSuchThatgoodTree_SizeMonotonic n :
  forall s, SizeMonotonicOpt (@enumSizeST _ _ (@EnumSizedSuchThatgoodTree n) s).
Proof. derive_enumST_SizeMonotonic (). Qed.

Instance EnumSizedSuchThatgoodTree_SizedMonotonicFP n :
  SizedMonotonicOptFP (@enumSizeST _ _ (@EnumSizedSuchThatgoodTree n)).
Proof. derive_enumST_SizedMonotonicFP (). Qed.
   
Instance EnumSizedSuchThatgoodTree_SizeMonotonicFP n :
  forall s, SizeMonotonicOptFP (@enumSizeST _ _ (@EnumSizedSuchThatgoodTree n) s).
Proof. derive_enumST_SizeMonotonicFP (). Qed.


Instance EnumSizedSuchThatgoodTree_Correct n :
  CorrectSizedST (goodTree n) (@enumSizeST _ _ (@EnumSizedSuchThatgoodTree n)).
Proof. derive_enumST_Correct (). Qed.