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

espec Sets

usa Boolean, Natural,

generos Set(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
emptySet : -> Set
add : Set E -> Set
size : Set -> Natural
contains/exists : Set E -> Booleano
remove : Set E -> Set
isEmpty : Set -> Booleano
union : Set Set -> Set
intersection : Set Set -> Set
diff : Set Set -> Set
subset : Set Set -> Boolean
equal : Set Set -> Boolean
var
s, s2 : Set, x, y: E

ecuaciones
// Las generadoras son emptySet y add y no son libres
add(add(s,x),x) = add(s,x)
add(add(s,x),y) = add(add(s,y),x)

size(emptySet) = 0
size(add(s,x)) = 1 + size(remove(s,x))

contains(emptySet,x) = FALSE
[igual(x,y) == TRUE] contains(add(s,x),y) = TRUE
[igual(x,y) != TRUE] contains(add(s,x),y) = contains(s,y)

remove(emptySet,x) = emptySet
[igual(x,y) == TRUE] remove(add(s,x),y) = remove(s,y)
[igual(x,y) != TRUE] remove(add(s,x),y) = add(remove(s,y),x)

isEmpty(emptySet) = TRUE
isEmpty(add(s,x)) = FALSE

union(emptySet,s2) = s2
union(add(s,x),s2) = add(union(s,s2),x)

intersection(emptySet,s2) = emptySet
[contains(s2,x) == TRUE]
intersection(add(s,x),s2) =
add(intersection(remove(s,x),remove(s2,x)),x)
[contains(s2,x) == FALSE]
intersection(add(s,x),s2) =
intersection(remove(s,x),remove(s2,x))

diff(emptySet,s2) = emptySet
[contains(s2,x) == TRUE]
diff(add(s,x),s2) =
diff(remove(s,x),remove(s2,x))
[contains(s2,x) == FALSE]
diff(add(s,x),s2) =
add(diff(remove(s,x),remove(s2,x)),x)

subset(emptySet,s2) = TRUE
subset(add(s,x),s2) = and(contains(s2,x),subset(s,s2))

equal(emptySet,emptySet) = TRUE
equal(emptySet,add(s2,x)) = FALSE
equal(add(s,x),emptySet) = FALSE
equal(add(s,x),s2) = and(contains(s2,x),
equal(remove(s,x),remove(s2,x))
fespec

Última modificación: viernes, 26 de mayo de 2017, 10:26