//--------------------------------------------//
// Especificacion Algebraica TAD Cola //
// Autor: Pablo Sanchez (p.sanchez@unican.es) //
// http://personales.unican.es/sanchezbp //
//--------------------------------------------//

espec Cola

usa Boolean, Natural

generos PriorityQueue(Element) as PQueue

parametro
generos Element como E

greaterThan(x,x) = FALSE
[greaterThan(x,y) and greaterThan(y,z)] greaterThan(x,z) = TRUE
[NOT(equal(x,y)) and NOT(greaterThan(y,x))]
greaterThan(x,y) = TRUE
[NOT(equal(x,y)) and greaterThan(x,y))]
greaterThan(y,x) = FALSE

fparametro

operaciones
emptyPQueue : -> PQueue
add : PQueue E -> PQueue
parcial peek : PQueue -> E
parcial remove : PQueue -> PQueue
isEmpty : PQueue -> Boolean
size : PQueue -> Natural

// Funciones auxiliares
max : PQueue -> Element
vars
q : PQueue; x, y, z : Element;

precondiciones
[isEmpty(s) != TRUE] remove(q), peek(q), max(q)

ecuaciones
// Las generadoras son emptyPQueue y add(q,x) y no
// son libres
// Los patrones del tipo son:
// - emptyPQueue
// - add(q,x)

[greaterThan(y,x) == TRUE]
add(add(q,x),y) = add(add(q,y),x)

max(add(emptyPQueue,x)) = x
[greaterThan(x,max(q)) == TRUE] max(add(q,x)) = x
[greaterThan(x,max(q)) != TRUE] max(add(q,x)) = max(q)


size(emptyPQueue) = 0
size(add(q,x)) = 1 + size(q)

remove(add(emptyPQueue,x)) = emptyPQueue
[greaterThan(y,max(add(q,x))) == TRUE]
remove(add(add(q,x),y)) = add(q,x)
[greaterThan(y,max(add(q,x))) != TRUE]
remove(add(add(q,x),y)) = add(remove(add(q,x)),y)

peek(add(emptyPQueue,x)) = x
[greaterThan(y,max(add(q,x))) == TRUE]
peek(add(add(q,x),y)) = y
[greaterThan(y,max(add(q,x))) != TRUE]
peek(add(add(q,x),y)) = peek(add(q,x))

isEmpty(emptyPQueue) = TRUE
isEmpty(add(q,y)) = FALSE

fespec

Last modified: Friday, 26 May 2017, 11:22 AM