-
Notifications
You must be signed in to change notification settings - Fork 50
/
perm_props.pvs
87 lines (67 loc) · 2.36 KB
/
perm_props.pvs
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
perm_props[ T:TYPE ]: THEORY % Welcome
%Inputs: T - Type that makes up entries
% of list
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%| Facts about permutations of |%
%| lists that are needed for |%
%| subsequent theories |%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Written By: AD
%----- %
BEGIN
% -----%
%-------------------------------------------
%% Importing more_list_props and sorting
% to have already established properits of
% lists and definition of permutations
%-------------------------------------------
IMPORTING sorting@sorting,
structures@more_list_props[T]
%-------------------------------------------
%% Remove and entry from a nonempty list
%-------------------------------------------
remove(l:(cons?[T]), i: below(length(l))):
list[T] =
append(IF i=0 THEN null[T]
ELSE l^(0,i-1) ENDIF,l^(i+1, length(l)-1))
%-------------------------------------------
%% length and cdr properties of remove
%-------------------------------------------
remove_length: LEMMA
FORALL (l:(cons?[T]), i: below(length(l))):
length(remove(l,i)) = length(l) - 1
remove_cdr: LEMMA
FORALL ((l:list[T] | length(l)>=2),
(i: below(length(l)) | i>0)):
cdr(remove(l,i)) = remove(cdr(l), i-1)
%-------------------------------------------
%% Splitting a list into three parts
%-------------------------------------------
list_splitting_nth: LEMMA
FORALL (l:(cons?[T]), i: below(length(l))):
l = append(append(IF i=0 THEN null[T]
ELSE l^(0,i-1) ENDIF,(: nth(l,i) :)),
l^(i+1, length(l)-1))
%-------------------------------------------
%% Occurrence properties of remove
%-------------------------------------------
occurrences_remove_not: LEMMA
FORALL (l:(cons?[T]), i: below(length(l)), x:T):
x/= nth(l, i) IMPLIES
occurrences(l)(x) = occurrences(remove(l,i))(x)
occurrences_remove: LEMMA
FORALL (l:(cons?[T]), i: below(length(l))):
occurrences(l)(nth(l, i)) =
occurrences(remove(l,i))(nth(l, i)) + 1
%-------------------------------------------
%% Showing invariant property under the
% remove function, given certain conditions
%-------------------------------------------
remove_perm: LEMMA
FORALL (l1, l2 : (cons?[T])):
permutations(l1, l2) IMPLIES
EXISTS (i:below(length(l2))):
(car(l1) = nth(l2,i) AND
permutations(cdr(l1),remove(l2,i)))
%~ The End ~%
END perm_props