aboutsummaryrefslogtreecommitdiffstats
path: root/unit-tests/demo_lfsc_bool.v
blob: 39bc6a16476f221b45a9e89f28601559cca3bfc6 (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
(**************************************************************************)
(*                                                                        *)
(*     SMTCoq                                                             *)
(*     Copyright (C) 2011 - 2021                                          *)
(*                                                                        *)
(*     See file "AUTHORS" for the list of authors                         *)
(*                                                                        *)
(*   This file is distributed under the terms of the CeCILL-C licence     *)
(*                                                                        *)
(**************************************************************************)


Require Import SMTCoq.
Require Import Bool PArray Int63 List ZArith BVList Logic.
Import ListNotations.
Local Open Scope list_scope.
Local Open Scope int63_scope.
Local Open Scope Z_scope.
Local Open Scope bv_scope.


Infix "-->" := implb (at level 60, right associativity) : bool_scope.


Import BVList.BITVECTOR_LIST. 
Require Import FArray.

Section BV.

  Import BVList.BITVECTOR_LIST.

  Local Open Scope bv_scope.

  Goal forall (bv1 bv2 bv3 bv4: bitvector 4),
      bv_eq #b|0|0|0|0| bv1 &&
      bv_eq #b|1|0|0|0| bv2 &&
      bv_eq #b|1|1|0|0| bv3 -->
      bv_eq #b|1|1|1|0| bv4 -->
      bv_ult bv1 bv2  || bv_ult bv3 bv1 --> bv_ult bv1 bv3 --> bv_ult bv1 bv4 || bv_ult bv4 bv1.
  Proof.
     smt.
  Qed.

  Goal forall (a: bitvector 32), bv_eq a a.
  Proof.
    smt.
  Qed.

  Goal forall (bv1 bv2: bitvector 4),
       (Bool.eqb (bv_eq bv1 bv2) (bv_eq bv2 bv1)).
  Proof.
     smt.
  Qed.

  Goal forall (bv1 bv2 bv3 bv4: bitvector 4),
      bv_eq #b|0|0|0|0| bv1 &&
      bv_eq #b|1|0|0|0| bv2 &&
      bv_eq #b|1|1|0|0| bv3 -->
      bv_eq #b|1|1|1|0| bv4 -->
      bv_ult bv1 bv2 || bv_ult bv3 bv1 && bv_ult bv3 bv4.
  Proof.
     smt.
  Qed.

  Goal forall (a b c: bitvector 4),
                                 (bv_eq c (bv_and a b))  -->
                                 (bv_eq (bv_and (bv_and c a) b) c).
  Proof.
     smt.
  Qed.

End BV.

Section Arrays.
  Import BVList.BITVECTOR_LIST.
  Import FArray.

  Local Open Scope farray_scope.
  Local Open Scope bv_scope.

  Goal forall (a:farray Z Z), equal a a.
  Proof.
    smt.
  Qed.

  Goal forall (a b: farray Z Z), Bool.eqb (equal a b) (equal b a).
  Proof. 
    smt.
  Qed.

  Goal forall (a b: farray (bitvector 8) (bitvector 8)), Bool.eqb (equal a b) (equal b a).
  Proof. 
    smt.
  Qed.

  Goal forall (a b c d: farray Z Z),
      equal b[0 <- 4] c -->
      equal d b[0 <- 4][1 <- 4]  &&
      equal a d[1 <- b[1]]  -->
      equal a c.
  Proof.
    smt.
  Qed.

  Goal forall (bv1 bv2 : bitvector 4)
         (a b c d : farray (bitvector 4) Z),
      bv_eq #b|0|0|0|0| bv1  -->
      bv_eq #b|1|0|0|0| bv2  -->
      equal c b[bv1 <- 4] -->
      equal d b[bv1 <- 4][bv2 <- 4] -->
      equal a d[bv2 <- b[bv2]] -->
      equal a c.
  Proof.
    smt.
  Qed.

  Goal forall (a b: farray Z Z)
         (v w x y: Z)
         (g: farray Z Z -> Z)
         (f: Z -> Z),
         (equal a[x <- v] b) && (equal a[y <- w] b) --> (Z.eqb (f x) (f y)) || (Z.eqb (g a) (g b)).
  Proof.
    smt.
  Qed.

Goal forall (a b: farray Z Z) i,
      Z.eqb (select (store (store (store a i 3%Z) 1%Z (select (store b i 4) i)) 2%Z 2%Z) 1%Z) 4.
Proof.
    smt.
    rewrite read_over_other_write; try easy.
    rewrite read_over_same_write; try easy; try apply Z_compdec.
    rewrite read_over_same_write; try easy; try apply Z_compdec.
Qed.

End Arrays.

Section UF.

  Goal forall
         (x y: Z)
         (f: Z -> Z),
         Z.eqb y x --> Z.eqb (f x) (f y).
  Proof.
    smt.
  Qed.

  Goal forall
         (x y: Z)
         (f: Z -> Z),
         Z.eqb (f x) (f y) --> Z.eqb (f y) (f x).
  Proof.
    smt.
  Qed.

  Goal forall
         (x y: Z)
         (f: Z -> Z),
         Z.eqb (x + 1)  (y + 1) --> Z.eqb (f y) (f x).
  Proof.
    smt.
  Qed.

  Goal forall
         (x y: Z)
         (f: Z -> Z),
         Z.eqb x (y + 1) --> Z.eqb (f y) (f (x - 1)).
  Proof.
    smt.
  Qed.


Goal forall (f:Z -> Z -> Z) x y z, (Z.eqb x y) --> Z.eqb (f z x) (f z y).
Proof.
  smt.
Qed.

End UF.


Section LIA.

  Goal forall (a b: Z), Bool.eqb (Z.eqb a b)  (Z.eqb b a).
  Proof.
    smt.
  Qed.

  Goal forall (a b: Z), (Z.eqb a a) && (Z.eqb b b).
  Proof.
    smt.
  Qed.


End LIA.