fix sessions and CE oracles
[why3.git] / tests / test_compute.why
blobfe2823860e3748781336fb161c58c34f95ac3e1c
2 theory Lambda
4 use int.Int
6 constant f : int -> int = (\x:int.x+1)
8 constant a : int
10 goal g1: f 42 = a
12 constant compose : ('b -> 'c) -> ('a -> 'b) -> ('a -> 'c) =
13          (\f:'b->'c.(\g:'a->'b.(\x:'a.f (g x))))
15 goal g2: compose f f 42 = a
17 constant h : int -> int
19 axiom a1 : h 42 = 56
21 meta "rewrite" prop a1
23 goal g3: h 42 = 4
25 end
27 theory A
29   predicate p
30   predicate q
32   goal G1 : p /\ q
33   goal G2 : p -> q
34   goal G3 : p && q
36   use bool.Bool
38   type t
40   function f t : bool
41   predicate r t
43   axiom a : forall x:t. f x = True <-> r x
45   constant c : t
47   meta "rewrite" prop a
49   goal g : f c <-> r c
51 end
53 theory Test
55   goal g1: true
57   goal g2: true /\ false
59   goal g3: true /\ true
61   goal g10: if true then 1=1 else 3=4
63   goal g11: let x=1 in x=1
65 end
67 theory TestArith
69   use int.Int
71   goal h1: 2+2=4
73   goal h2: 2+(-2)=0
75   goal h3: 10 = 0xA
77   function g int : int
79   axiom g4: g 4 = 7
81   meta "rewrite" prop g4
83   goal j1: g (2+2) = 7
85   use int.Power
87   meta "rewrite" prop Power_0
88 (* not a rule: conditional
89   meta "rewrite" prop Power_s
91   goal k1: power 4 3 = 64
93   constant n : int
95   goal l1: n+0 = n
96   goal l2: 0+n = n
97   goal l3: n+1 = n
98   goal l4: n*0 = n
99   goal l5: 0*n = n
100   goal l6: n*1 = n
101   goal l7: 1*n = n
102   goal l8: n-0 = n
103   goal l9: 0-n = n
105   use int.ComputerDivision
107   goal m1: div 0 1 = 42
108   goal m2: div n 1 = 42
109   goal m3: div 0 n = 42
110   goal m4: div n n = 42
112   use int.MinMax
114   goal n1: max 3 4 = n
115   goal n2: max n n = 42
116   goal n3: min n n = 42
117   goal n4: min 3 4 = n
120   function f int : int
122   axiom a42 : f 42 + 43 = 56
124   meta rewrite prop a42
126   goal o1 : f (6*7) + (42 + 1) = n
130 theory TestRecord
132   use int.Int
134   type t = { f : int }
136   goal i1: let x = { f = 4 } in x.f < 5
138   goal i2: let  x = { f = 4 } in
139     match x with { f = y } -> y + 1 > 3 end
145 theory TestList
147   use int.Int
149   use list.List
151   constant l1 : list int = Cons 12 (Cons 34 (Cons 56 Nil))
153   goal g1: match l1 with Nil -> 0 | Cons x _ -> x end = 12
155   use list.Length
157   goal g2: length l1 = 3
159   use list.HdTlNoOpt
161   meta "rewrite" prop hd_cons
162   meta "rewrite" prop tl_cons
164   goal g3: hd l1 = 12
166   use list.Append
168   constant l2 : list int =
169     Cons 12 (Cons 34 (Cons 56 Nil)) ++ Cons 78 (Cons 90 Nil)
171   goal h1: l2 = l1
173   goal h2: length l2 = 5
175   goal h3: forall x y:int. Cons x Nil = Cons y Nil
177   constant l3 : list int
179   axiom dangerous: Cons 12 Nil = l3
181   meta rewrite prop dangerous
183   goal i1: l3 = Nil ++ Nil
190 theory Rstandard
192    type t
194    constant u : t
196    constant a : t
198    function f t t : t
200    function g t : t
202    axiom a1 : g a = a
204    meta "rewrite" prop a1
208    constant b : t
210    axiom a2 : f b b = g b
212    meta "rewrite" prop a2
215    function h t : t
217    axiom a3 : forall x:t. f (h x) a = g x
219    meta "rewrite" prop a3
221    function i t t : t
223    axiom a4 : forall x y:t. i x y = f x y
225    meta "rewrite" prop a4
227    function j t t : t
229    axiom a5 : forall x:t. j x x = x
231    meta "rewrite" prop a5
235 theory TestStandard
237    use Rstandard
239    goal g00 : u = g a
241    goal g01 : f (g (g a)) u = f a (g a)
243    goal g02 : u = f b b
245    goal g03 : f (f b b) (g b) = f u (f b b)
247    goal g04 : f (h u) a = f (h a) a
249    goal g05 : i a b = u
251    goal g06 : j a b = u
253    goal g07 : j a a = u
258 theory Rgroup
260   type t
262   function ( * ) t t : t
264   function e : t
266   function i t : t
268   axiom assoc : forall x y z:t. (x * y) * z = x * (y * z)
270   meta "rewrite" prop assoc
272   axiom id_left : forall x:t. e * x = x
274   meta "rewrite" prop id_left
276   axiom inv_left : forall x:t. i x * x = e
278   meta "rewrite" prop inv_left
280   constant a:t
281   constant b:t
282   constant c:t
284   goal g0: (a * b) * c = e
286   goal g01: (a * e) * c = a * c
288   goal g1: (b * i a) * a = b
290   goal g2: ((b * i a) * a) * a = b * a
295 theory NonTerm
297   type t
299   constant c : t
301   function f t : t
303   axiom a: f c = f (f c)
305   meta "rewrite" prop a
307   goal g: f c = f c
309   use int.Int
311   type nat = O | S nat
313   function plus (n m:nat) : nat =
314     match n with
315     | O -> m
316     | S k -> S (plus k m)
317     end
319   function fib (n:nat) : nat =
320     match n with
321     | O -> O
322     | S O -> S O
323     | S (S n as m) -> plus (fib n) (fib m)
324     end
326   constant x : nat
328   goal g3 : fib (S (S (S O))) = x
329   goal g4 : fib (S (S (S (S O)))) = x
330   goal g5 : fib (S (S (S (S (S O))))) = x
331   goal g6 : fib (S (S (S (S (S (S O)))))) = x
332   goal g7 : fib (S (S (S (S (S (S (S O))))))) = x
334   meta "compute_max_steps" 100000
336   goal g8 : fib (S (S (S (S (S (S (S (S O)))))))) = x
337   goal g9 : fib (S (S (S (S (S (S (S (S (S O))))))))) = x
338   goal g10 : fib (S (S (S (S (S (S (S (S (S (S O)))))))))) = x
342 theory Rinteger
344    use export int.Int
346    goal g1 : forall y. 2+2 = y
348    goal g2 : forall y.  0 + y + 0 + y - y = y
350    lemma l1 : forall x y z:int. (x + y) + z = z + (y + x)
352    function f int : int
354    goal g3 : (f 1 + f 2) + f 3 = f 4
358 theory TestInteger
360    use Rinteger
362    predicate f1 (y:int) = y > 0 /\ true
364    goal g1 : true /\ false
366    predicate f2 (y:int) = y + 0 >= 1
368    function f3 (y:int) : int = y + 0
370    goal g2 : 1 + 0 = 1
372    goal g3 : 1 + 0 >= 1
377 theory MoreSets
379 use export set.Set
381 meta "rewrite" prop mem_empty
383 meta "rewrite" prop add_def1
385 meta "rewrite" prop union_def1
389 theory TestSets
391 use MoreSets
393 type t = A | B | C | D
395 goal g00 : mem A empty
398 goal g01 : mem A (add B empty)
400 goal g015 : mem A (singleton B)
403 goal g02 : mem A (union (add B empty) (add C empty))
405 goal g025 : mem A (union (singleton B) (singleton C))
410 theory Wrong
412 type t
414 constant a : t
415 constant b : t
417 axiom A : forall x:t. a = x
419 meta "rewrite" prop A
421 goal test : a = b