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

espec Vector

usa Boolean, Natural

generos Vector(Element) como Vector(E)

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
parcial newVector : Natural -> Vector(E)
parcial set : Vector(E) Natural E -> Vector(E)
parcial get : Vector(E) Natural -> E
equal : Vector(E) Vector(E) -> Boolean
size : Vector(E) -> Natural
parcial isSet : Vector(E) Natural -> Boolean
parcial resize : Vector(E) Natural -> Vector(E)

// Funciones auxiliares
parcial equalElementByElementUntil:
Vector(E) Vector(E) Natural -> Boolean

vars
v, v2 : Vector(E); x, y : Element; i, j, n, m : Natural;

precondiciones
[(0 <= i < size(v))] set(v,i,e)
[(0 <= i < size(v)) and (isSet(v,i) == TRUE)] get(v,i)
[0 < n] newVector(n)
[n > size(v)] resize(v,n)
[(0<= n < size(v2)) and (0<= n < size(v2))]
equalElementByElementUntil(v,v2,n)

ecuaciones
// Las generadoras son newVector(n) y set(v,i,x) y no
// son libres
// Los patrones del tipo son:
// - newVector(n)
// - set(v,i,x)

[i == j] set(set(v,i,x),j,y) = set(v,i,y)
[i != j] set(set(v,i,x),j,y)) = set(set(v,j,y),i,x)

[i == j] get(set(v,i,x),j) = x
[i != j] get(set(v,i,x),j) = get(v,j)

isSet(newVector(n),i) = FALSE
[i == j] isSet(set(v,i,x),j) = TRUE
[i != j] isSet(set(v,i,x),j) = isSet(v,j)

size(newVector(n)) = n
size(set(v,i,x)) = size(v)

resize(newVector(n),m) = newVector(m)
resize(set(v,i,x)) = set(resize(v,n),i,x)

[size(v) != size(v2)]
equal(v,v2) = FALSE
[size(v) == size(v2)]
equal(v,v2) = equalElementByElementUntil(v,v2,size(v)-1)

[n == 0]
equalElementByElementUntil(v,v2,n) =
or(
and(isSet(v,0),isSet(v2,0),
equal(get(v,0),get(v2,0))),
and(not(isSet(v,0)),not(isSet(v2,0)))
)

[n != 0]
equalElementByElementUntil(v,v2,n) =
and(
or(
and(isSet(v,n),isSet(v2,n),
equal(get(v,n),get(v2,n))),
and(not(isSet(v,n)),not(isSet(v2,n)))
),
equalElementByElementUntil(v,v2,n-1))

fespec

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