summaryrefslogtreecommitdiff
path: root/Tests.v
blob: 87cc121c9cc5eea7b012a3af112fdb690e2791da (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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
(***************************************************************************)
(*  This is part of aac_tactics, it is distributed under the terms of the  *)
(*         GNU Lesser General Public License version 3                     *)
(*              (see file LICENSE for more details)                        *)
(*                                                                         *)
(*       Copyright 2009-2010: Thomas Braibant, Damien Pous.                *)
(***************************************************************************)

Require Import AAC.

Section sanity.  

  Context {X} {R} {E: Equivalence R} {plus} {zero}
  {dot} {one} {A: @Op_A X R dot one} {AC: Op_AC R plus zero}.
 

  Notation "x == y"  := (R x y) (at level 70).
  Notation "x * y"   := (dot x y) (at level 40, left associativity).
  Notation "1"       := (one).
  Notation "x + y"   := (plus x y) (at level 50, left associativity).
  Notation "0"       := (zero).

  Section t0.
  Hypothesis H : forall x, x+x == x.
  Goal forall a b, a+b +a == a+b.
    intros a b; aacu_rewrite H; aac_reflexivity.
  Qed.
  End t0.
  
  Section t1.
    Variables a b : X.
    
    Variable P : X -> Prop.
    Hypothesis H : forall x y, P y -> x+y+x == x.
    Hypothesis Hb : P b.
    Goal  a+b +a == a.
      aacu_rewrite H.
      aac_reflexivity.
      auto.
    Qed.
  End t1.

  Section t.
  Variable f : X -> X.
  Hypothesis Hf : Proper (R ==> R) f.
  Hypothesis H : forall x, x+x == x.
  Goal forall y, f(y+y) == f (y).
    intros y.
    aacu_instances H.
    aacu_rewrite H.
    aac_reflexivity.
  Qed.

  Goal forall y z, f(y+z+z+y) == f (y+z).
    intros y z.
    aacu_instances H.
    aacu_rewrite H.
    aac_reflexivity.
  Qed.

  Hypothesis H' : forall x, x*x == x.
  Goal forall y z, f(y*z*y*z) == f (y*z).
    intros y z.
    aacu_instances H'.
    aacu_rewrite H'.
    aac_reflexivity.
  Qed.
  End t.

  Goal forall x y, (plus x y) == (plus y x). intros.
    aac_reflexivity. 
  Qed.

  Goal forall x y, R (plus (dot x one) y) (plus y x). intros.
    aac_reflexivity. 
  Qed.

  Goal (forall f y, f y + f y == y) -> forall a b g (Hg: Proper (R ==> R) g), g (a+b) + g b + g (b+a) == a + b + g b.
    intros.
    try aacu_rewrite H. 
    aacu_rewrite (H g).
    Restart.
    intros.
    set (H' := H g).
    aacu_rewrite H'.
    aac_reflexivity.
  Qed.

  Section t2.
    Variables a b: X.
    Variables g : X ->X.
    Hypothesis Hg:Proper (R ==> R) g.
    Hypothesis H: (forall y, (g y) + y == y).    
    Goal  g (a+b) +  b +a+a == a + b +a.
    intros.
    aacu_rewrite H.
    aac_reflexivity.
  Qed.
  End t2.
  Section t3.
    Variables a b: X.
    Variables g : X ->X.
    Hypothesis Hg:Proper (R ==> R) g.
    Hypothesis H: (forall f y, f y + y == y).
    
    Goal  g (a+b) +  b +a+a == a + b +a.
    intros.
    aacu_rewrite (H g).
    aac_reflexivity.
  Qed.
End t3.

Section null.
  Hypothesis dot_ann : forall x, 0 * x == 0.
  Goal forall a, 0*a == 0.
    intros a. aac_rewrite dot_ann. reflexivity.
  Qed.
End null.

End sanity.

Section abs.
  Context 
    {X} {E: Equivalence (@eq X)} 
    {plus}  {zero}  {AC: @Op_AC X eq plus zero}
    {plus'} {zero'} {AC': @Op_AC X eq plus' zero'}
    {dot}   {one}   {A: @Op_A X eq dot one} 
    {dot'}  {one'}  {A': @Op_A X eq dot' one'}. 
 
  Notation "x * y"   := (dot x y) (at level 40, left associativity).
  Notation "x @ y"   := (dot' x y) (at level 20, left associativity).
  Notation "1"       := (one).
  Notation "1'"      := (one').
  Notation "x + y"   := (plus x y) (at level 50, left associativity).
  Notation "x ^ y"   := (plus' x y) (at level 30, right associativity).
  Notation "0"       := (zero).
  Notation "0'"      := (zero').

  Variables a b c d e k: X.
  Variables f g: X -> X.
  Hypothesis Hf: Proper (eq ==> eq) f.
  Hypothesis Hg: Proper (eq ==> eq) g.

  Variables h: X -> X -> X.
  Hypothesis Hh: Proper (eq ==> eq ==> eq) h.

  Variables q: X -> X -> X -> X.
  Hypothesis Hq: Proper (eq ==> eq ==> eq ==> eq) q.




  Hypothesis dot_ann_left: forall x, 0*x = 0.

  Goal f (a*0*b*c*d) = k.
    aac_rewrite dot_ann_left.
    Restart.
    aac_rewrite dot_ann_left subterm 1 subst 0.
  Abort.




  Hypothesis distr_dp: forall x y z, x*(y+z) = x*y+x*z.
  Hypothesis distr_dp': forall x y z, x*y+x*z = x*(y+z).

  Hypothesis distr_pp: forall x y z, x^(y+z) = x^y+x^z.
  Hypothesis distr_pp': forall x y z, x^y+x^z = x^(y+z).

  Hypothesis distr_dd: forall x y z, x@(y*z) = x@y * x@z.
  Hypothesis distr_dd': forall x y z, x@y * x@z = x@(y*z).


  Goal a*b*(c+d+e) = k.
    aac_instances distr_dp.
    aacu_instances distr_dp.
    aac_rewrite distr_dp subterm 0 subst 4.

    aac_instances distr_dp'.
    aac_rewrite distr_dp'.
  Abort.

  Goal a@(b*c)@d@(e*e) = k.
    aacu_instances distr_dd.
    aac_instances distr_dd.
    aac_rewrite distr_dd.
  Abort.

  Goal a^(b+c)^d^(e+e) = k.
    aacu_instances distr_dd.
    aac_instances distr_dd.
    aacu_instances distr_pp.
    aac_instances distr_pp.
    aac_rewrite distr_pp subterm 9.
  Abort.


    

  Hypothesis plus_idem: forall x, x+x = x.
  Hypothesis plus_idem3: forall x, x+x+x = x.
  Hypothesis dot_idem: forall x, x*x = x.
  Hypothesis dot_idem3: forall x, x*x*x = x.

  Goal a*b*a*b = k.
    aac_instances dot_idem.
    aacu_instances dot_idem.
    aac_rewrite dot_idem.
    aac_instances distr_dp.     (* TODO: no solution -> fail ? *)
    aacu_instances distr_dp.
  Abort.

  Goal a+a+a+a = k.
    aac_instances plus_idem3.
    aac_rewrite plus_idem3.
  Abort.

  Goal a*a*a*a = k.
    aac_instances dot_idem3.
    aac_rewrite dot_idem3.
  Abort.

  Goal a*a*a*a*a*a = k.
    aac_instances dot_idem3.
    aac_rewrite dot_idem3.
  Abort.

  Goal f(a*a)*f(a*a) = k.
    aac_instances dot_idem.
    (* TODO: pas clair qu'on doive réécrire les deux petits
    sous-termes quand on nous demande de n'en réécrire qu'un... 
    d'autant plus que le comportement est nécessairement 
    imprévisible (cf. les deux exemples en dessous)
    ceci dit, je suis conscient que c'est relou à empêcher... *)
    aac_rewrite dot_idem subterm 1. 
  Abort.

  Goal f(a*a*b)*f(a*a*b) = k.
    aac_instances dot_idem.
    aac_rewrite dot_idem subterm 2. (* une seule instance réécrite *)
  Abort.

  Goal f(b*a*a)*f(b*a*a) = k.
    aac_instances dot_idem.
    aac_rewrite dot_idem subterm 2. (* deux instances réécrites *)
  Abort.

  Goal h (a*a) (a*b*c*d*e) = k.
    aac_rewrite dot_idem.       
  Abort.

  Goal h (a+a) (a+b+c+d+e) = k.
    aac_rewrite plus_idem.       
  Abort.

  Goal (a*a+a*a+b)*c = k.
    aac_rewrite plus_idem.
    Restart.
    aac_rewrite dot_idem.
  Abort.

 


  Hypothesis dot_inv: forall x, x*f x = 1.
  Hypothesis plus_inv: forall x, x+f x = 0.
  Hypothesis dot_inv': forall x, f x*x = 1.

  Goal a*f(1)*b = k.
    try aac_rewrite dot_inv.    (* TODO: à terme, j'imagine qu'on souhaite accepter ça, même en aac *)
    aacu_rewrite dot_inv.
  Abort.

  Goal f(1) = k.
    aacu_rewrite dot_inv.   
    Restart.
    aacu_rewrite dot_inv'.  
  Abort.

  Goal b*f(b) = k.
    aac_rewrite dot_inv.  
  Abort.

  Goal f(b)*b = k.
    aac_rewrite dot_inv'.
  Abort.

  Goal a*f(a*b)*a*b*c = k.
    aac_rewrite dot_inv'.
  Abort.

  Goal g (a*f(a*b)*a*b*c+d) = k.
    aac_rewrite dot_inv'.
  Abort.

  Goal g (a+f(a+b)+c+b+b) = k.
    aac_rewrite plus_inv.
  Abort.

  Goal g (a+f(0)+c) = k.
    aac_rewrite plus_inv.
  Abort.





  Goal forall R S, Equivalence R -> Equivalence S -> R a k -> S a k.
    intros R S HR HS H. 
    try (aac_rewrite H ; fail 1 "ne doit pas passer"). 
    try (aac_instances H; fail 1 "ne doit pas passer").
  Abort.

  Goal forall R S, Equivalence R -> Equivalence S -> (forall x, R (f x) k) -> S (f a) k.
    intros R S HR HS H. 
    try (aac_instances H; fail 1 "ne doit pas passer").
    try (aac_rewrite H ; fail 1 "ne doit pas passer"). 
  Abort.





  Hypothesis star_f: forall x y, x*f(y*x) = f(x*y)*x.

  Goal g (a+b*c*d*f(a*b*c*d)+b) = k.
    aac_instances star_f.
    aac_rewrite star_f.
  Abort.

  Goal b*f(a*b)*f(b*b*f(a*b)) = k.
    aac_instances star_f.
    aac_rewrite star_f.
    aac_rewrite star_f.
  Abort.





  Hypothesis dot_select: forall x y, f x * y * g x = g y*x*f y.

  Goal f(a+b)*c*g(b+a) = k.
    aac_rewrite dot_select.
  Abort. 

  Goal f(a+b)*g(b+a) = k.
    try (aac_rewrite dot_select; fail 1 "ne doit pas passer").
    aacu_rewrite dot_select.
  Abort. 

  Goal f b*f(a+b)*g(b+a)*g b = k.
    aacu_instances dot_select.
    aac_instances dot_select.
    aac_rewrite dot_select.
    aacu_rewrite dot_select.
    aacu_rewrite dot_select.
  Abort. 




  Hypothesis galois_dot: forall x y z, h x (y*z) = h (x*y) z.
  Hypothesis galois_plus: forall x y z, h x (y+z) = h (x+y) z.

  Hypothesis select_dot: forall x y, h x (y*x) = h (x*y) x.
  Hypothesis select_plus: forall x y, h x (y+x) = h (x+y) x.

  Hypothesis h_dot: forall x y, h (x*y) (y*x) = h x y.
  Hypothesis h_plus: forall x y, h (x+y) (y+x) = h x y.

End abs.