secuencias
//--------------------------------------------//
// Especificacion Algebraica TAD Secuencia //
// Autor: Pablo Sanchez (p.sanchez@unican.es) //
// http://personales.unican.es/sanchezbp //
//--------------------------------------------//
espec Sequence (List)
usa Boolean, Natural, Entero
generos Sequence(Element) como Seq
parametro
generos Element como E
operaciones
equal: Element Element -> Boolean
variables
x, y, z : Element;
ecuaciones
equal(x,x) = TRUE
equal(x,y) = equal(y,x)
[equal(x,y) and equal(y,z)] equal(x,z) = TRUE;
fparametro
operaciones
emptySeq : -> Seq
addTail : Seq E -> Seq
addHead : Seq E -> Seq
add : Seq E Natural -> Seq
getTail : Seq -> E
getHead : Seq -> E
get : Seq Natural -> E
replace : Seq Natural E -> Seq
removeAll : Seq E -> Seq
removeFirst : Seq E -> Seq
removeLast : Seq E -> Seq
remove : Seq Natural -> Seq
contains : Seq E -> Boolean
findFirstIndex : Seq E -> Entero
findLastIndex : Seq E -> Entero
size : Seq -> Natural
number : Seq E -> Natural
isEmpty : Seq -> Boolean
concat : Seq Seq -> Seq
equal : Seq Seq -> Boolean
subseq : Seq Seq -> Boolean
vars
s, s2 : Seq; n : Natural; x, y : Element;
precondiciones
[0 <= n <= size(s)] add(s,n)
[isEmpty(s) == FALSE] getTail(s), getHead(s)
[0 <= n < size(s)] get(s,n), remove(s,n), replaces(s,n,x)
ecuaciones
// Las generadoras son emptySeq y addTail y son libres
// Los patrones del tipo son:
// - emptySeq
// - addTail(s,x)
addHead(emptySeq,x) = addTail(emptySeq,x)
addHead(addTail(s,x),y) = addTail(addHead(s,y),x)
size(emptySeq) = 0
size(addTail(s,x)) = 1 + size(s)
add(emptySeq,x,0) = addTail(emptySeq,x)
[n == size(addTail(s,x))]
add(addTail(s,x),y,n) = addTail(addTail(s,x),y)
[n < size(addTail(s,x))]
add(addTail(s,x),y,n) = addTail(add(s,y,n),x)
getTail(addTail(s,x)) = x
getHead(addTail(emptySeq,x)) = x
getHead(addTail(addTail(s,x))) = getHead(addTail(s,x))
[n == (size(s) - 1)] get(addTail(s,x),n) = x
[n < (size(s) - 1)] get(addTail(s,x),n) = get(s,n-1)
removeAll(emptySeq,x) = emptySeq
[equal(x,y) == TRUE]
removeAll(addTail(s,x),y) = removeAll(s,y)
[equal(x,y) != TRUE]
removeAll(addTail(s,x),y) = addTail(removeAll(s,y),x)
[n == (size(s) - 1)]
remove(addTail(s,x),n) = s
[n < (size(s) - 1)]
remove(addTail(s,x),n) = addTail(remove(s,n),x)
replace(s,n,y) = add(remove(s,n),y,n)
contains(emptySeq,x) = FALSE
[equal(x,y) == TRUE]
contains(addTail(s,x),y) = TRUE
[equal(x,y) != TRUE]
contains(addTail(s,x),y) = contains(s,y)
findLastIndex(emptySeq,x) = -1
// NOTA: en la funci�n de arriba, en lugar de -1
// podr�a devolverse cualquier valor no v�lido
[(equal(x,y) == TRUE)]
findLastIndex(addTail(s,x),y) = size(s);
[(equal(x,y) != TRUE)]
findLastIndex(addTail(s,x),y) = findLastIndex(s,y);
findFirstIndex(emptySeq,x) = -1
[(equal(x,y) != TRUE)]
findFirstIndex(addTail(s,x),y) = findFirstIndex(s,y);
[(equal(x,y) == TRUE) and (contains(s,y) == TRUE)]
findFirstIndex(addTail(s,x),y) = findFirstIndex(s,y);
[(equal(x,y) == TRUE) and (contains(s,y) != TRUE)]
findFirstIndex(addTail(s,x),y) = size(s);
[findFirstIndex(s,x) != -1]
removeFirst(s,x) = remove(s,findFirstIndex(s,x));
[findFirstIndex(s,x) == -1]
removeFirst(s,x) = s;
[findLastIndex(s,x) != -1]
removeLast(s,x) = remove(s,findLastIndex(s,x));
[findLastIndex(s,x) == -1]
removeLast(s,x) = s;
number(emptySeq,x) = 0
[equal(x,y) == TRUE]
number(addTail(s,x),y) = 1 + number(s,y)
[equal(x,y) != TRUE]
number(addTail(s,x),y) = number(s,y)
isEmpty(emptySeq) = TRUE
isEmpty(addTail(s,x)) = FALSE
concat(s,emptySeq) = s
concat(s,addTail(s2,x)) = addTail(concat(s,s2),x)
equal(emptySeq,emptySeq) = TRUE
equal(addTail(s,x),emptySeq) = FALSE
equal(emptySeq,addTail(s,x)) = FALSE
[equal(x,y) == TRUE]
equal(addTail(s,x),addTail(s2,y)) = equal(s,s2)
[equal(x,y) != TRUE]
equal(addTail(s,x),addTail(s2,y)) = FALSE
subseq(emptySeq,emptySeq) = TRUE
subseq(addTail(s,x),emptySeq) = FALSE
subseq(emptySeq,addTail(s,x)) = TRUE
[size(s) == size(s2)]
subseq(addTail(s,x),addTail(s2,y)) =
and(equal(x,y),equal(s,s2))
[size(s) > size(s2)]
subseq(addTail(s,x),addTail(s2,y)) = FALSE
[size(s) < size(s2)]
subseq(addTail(s,x),addTail(s2,y)) =
subseq(addTail(s,x),s2)
fespec