bolsas

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

espec Bags (tb. Multisets)

usa Boolean, Natural

generos Bag(Element)

parametro
generos Element as 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
emptyBag : -> Bag
add : Bag E -> Bag
size : Bag -> Natural
contains/exists : Bag E -> Booleano
remove : Bag E -> Bag
removeOne: Bag E -> Bag
isEmpty : Bag -> Booleano
number : Bag E -> Natural
var
b : Bag, x, y: E

ecuaciones
// Las generadoras son emptyBag y add y no son libres
add(add(b,x),y) = add(add(b,y),x)

// Operaciones
size(emptyBag) = 0
size(add(b,x)) = 1 + size(b)

contains(emptyBag,x) = FALSE
[igual(x,y) == TRUE] contains(add(b,x),y) = TRUE
[igual(x,y) == FALSE] contains(add(b,x),y) = contains(b,y)

remove(emptyBag,x) = emptyBag
[igual(x,y) == TRUE] remove(add(b,x),y) = remove(b,y)
[igual(x,y) == FALSE] remove(add(b,x),y) = add(remove(b,y),x)

removeOne(emptyBag,x) = emptyBag
[igual(x,y) == TRUE] removeOne(add(b,x),y) = b
[igual(x,y) == FALSE] removeOne(add(b,x),y) = add(remove(b,y),x)

isEmpty(emptyBag) = TRUE
isEmpty(add(b,x)) = FALSE

number(emptyBag,x) = 0
[igual(x,y) == TRUE] number(add(b,x),y) = 1 + number(b,y)
[igual(x,y) == FALSE] number(add(b,x),y) = number(b,y)
fespec

Last modified: Friday, 26 May 2017, 10:26 AM