Skip to content
Snippets Groups Projects
Commit 2f62cb98 authored by Regis Blanc's avatar Regis Blanc Committed by Etienne Kneuss
Browse files

more xlang max sum testcases

parent 4dc34574
No related branches found
No related tags found
No related merge requests found
......@@ -35,4 +35,27 @@ object MaxSum {
rec(0)
}
def summ(to : Int): Int = ({
require(to >= 0)
var i = 0
var s = 0
(while (i < to) {
s = s + i
i = i + 1
}) invariant (s >= 0 && i >= 0 && s == i*(i-1)/2 && i <= to)
s
}) ensuring(res => res >= 0 && res == to*(to-1)/2)
def sumsq(to : Int): Int = ({
require(to >= 0)
var i = 0
var s = 0
(while (i < to) {
s = s + i*i
i = i + 1
}) invariant (s >= 0 && i >= 0 && s == (i-1)*i*(2*i-1)/6 && i <= to)
s
}) ensuring(res => res >= 0 && res == (to-1)*to*(2*to-1)/6)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment