-
Notifications
You must be signed in to change notification settings - Fork 5
/
sum-spec.k
53 lines (43 loc) · 1.46 KB
/
sum-spec.k
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
requires "../../06-procedures/procedures.k"
requires "domains.md"
module SUM-SPEC-SYNTAX
imports PROCEDURES-SYNTAX
syntax Id ::= "$n" [token] | "$s" [token] | "$sum" [token]
endmodule
module VERIFICATION
imports K-EQUAL
imports SUM-SPEC-SYNTAX
imports PROCEDURES
rule ((K |-> V) _M) [ K' ] => V requires K ==K K' [simplification]
rule ((K |-> _V) M) [ K' ] => M [ K' ] requires K =/=K K' [simplification]
rule ((K |-> _V) M) [ K' <- V' ] => (K |-> V') M requires K ==K K' [simplification]
rule ((K |-> V) M) [ K' <- V' ] => (K |-> V) (M [ K' <- V' ]) requires K =/=K K' [simplification]
endmodule
module SUM-SPEC
imports VERIFICATION
claim <k> while ( 0 < NID ) {
SID = SID + NID ;
NID = NID - 1 ;
}
=> . ... </k>
<store> SID |-> (S:Int => S +Int ((N +Int 1) *Int N /Int 2))
NID |-> (N:Int => 0)
</store>
requires N >=Int 0
andBool S >=Int 0
claim <k> def $sum($n, .Ids) {
$s = 0 ;
while (0 < $n) {
$s = $s + $n ;
$n = $n - 1 ;
}
return $s ;
}
return $sum(N:Int, .Ints) ;
=> return (N +Int 1) *Int N /Int 2 ;
</k>
<funcs> .Map => ?_ </funcs>
<store> .Map => ?_ </store>
<stack> .List </stack>
requires N >=Int 0
endmodule