I was trying to reverse a doubly linked list in alloy, I created a signature for it. This is the signature
sig node{}
//define each field as disjoint subset of node
sig first extends node{}
sig last extends node{}
sig element extends node{}
sig doublylinkedlist{
head:one first, //define one head pointer
null:one last, //define one null pointer
ele:set element, //elements of the linked list
links:ele->ele, //paths between elements of a linked list
headpoint:head->one ele, //head points to one element of linked list
nullpoint:ele->null //one element of linked list points to null
}{
no links & iden // no self refrence
one nullpoint //only one element points to null
links=links + ~links //elements can point to prev element
all e:ele | e.(^(links))=ele // elements are connected
all e:ele | one r:head, n:null | (r->e) in headpoint => (e->n) not in nullpoint //element being pointed by head cannot point to null
all e:ele | #(e.(links))<3 and #((links).e)<3 //elements cannot have more than 3 indegree and more than 3 outdegree
all e:ele | one r:head | (r->e) in headpoint => #((links).e)=1 && #(e.(links))=1 //element being pointed by head has indegree and outdegree 1
all e:ele | one n:null | (e->n) in nullpoint => #((links).e)=1 && #(e.(links))=1 //element being pointing to null has indegree and outdegree 1
}
pred reverse{
}
run reverse for 1 doublylinkedlist, exactly 4 element ,exactly 1 first,exactly 1 last,exactly 0 node
The problem is that it gives desired result when i run for exactly 8 elemnts. After that it shows instances where one element has more than 3 indegree and 3 outdegree.