%------------------------------------------------------------------------ % % This theory defines additional properties of lists. % % Author: Kristin Y. Rozier, % Formal Methods Group, NASA Langley Research Center % with thanks to Paul Miner and Ben Di Vito for their helpful % comments and suggestions % Cesar Munoz 2012, Anthony Narkawicz 2013 %------------------------------------------------------------------------
more_list_props [ T : TYPE ]
: THEORY
BEGIN
m, n: VAR nat
L: VAR list[T]
p: VAR PRED[T]
A: VAR finite_set[T]
B: VAR list[T]
X, Y: VAR list[T]
l1, l2, l3: VAR list[T]
pair: VAR [nat, nat]
t: VAR T
% % Functions %
prefix?(x: list[T],
y: list[T]): RECURSIVE bool = IF length(y) < length(x) THENFALSE ELSE CASES x OF
null: TRUE,
cons(sigma_x, x1): CASES y OF
null: FALSE,
cons(sigma_y, y1): IF sigma_x = sigma_y AND prefix?(x1, y1) THENTRUE ELSEFALSE ENDIF ENDCASES ENDCASES ENDIF MEASURE length(x)
suffix?(x: list[T],
y: list[T]): RECURSIVE bool = IF length(y) < length(x) THENFALSE ELSE CASES reverse(x) OF
null: TRUE,
cons(sigma_x, x1): CASES reverse(y) OF
null: FALSE,
cons(sigma_y, y1): IF sigma_x = sigma_y AND suffix?(x1, y1) THENTRUE ELSEFALSE ENDIF ENDCASES ENDCASES ENDIF MEASURE length(x)
%Multiple concatenation of a list: w^3 means (: w w w :).
;
^(l1, n): RECURSIVE list[T] = IF n = 0 THEN (null) ELSE append( l1, ^(l1, n-1) ) ENDIF MEASURE n
% Just like for sequences, a sub-list can be extracted with the operator '^'. % Note that ^ allows any natural numbers m and n to define the range; % if m > n then the empty sequence is returned.
;
^(l1, pair): RECURSIVE list[T] = LET (m, n) = pair INIF m > n OR m >= length(l1) OR m < 0 THEN null ELSIF m = n THEN cons( nth(l1, m), null) ELSE cons( nth(l1, m), ^(l1, (m+1, n))) ENDIF MEASUREIF pair`2 > pair`1 THEN pair`2 - pair`1 ELSE 0 ENDIF
%If the length of the list of elements from set A is greater than the %cardinality of the set, then there is at least one repeated element %in the list.
list_pigeonhole: THEOREM
every(A)(B) AND
length(B) > card(A) IMPLIES EXISTS (n:below[length(B)], m:below[length(B)]):
n /= m AND nth(B, n) = nth(B, m)
nth_append : LEMMA FORALL(i:nat): i < length(l1)+length(l2) IMPLIES
nth(append(l1,l2),i) = IF i < length(l1) THEN nth(l1,i) ELSE nth(l2,i-length(l1)) ENDIF
expand_list: LEMMA
null?(L) OR L = cons(car(L),cdr(L))
append_null_left: LEMMA append(null,L) = L
END more_list_props
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.11Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.