Lab for Automated Reasoning and Analysis LARA

Simple linked list operation in Jahob

The following is an example of a method and its annotation in the Jahob verification system.

class Node {
    public /*: claimedby List */ Node next;
class List
   private static Node first;  
     public static specvar content :: objset;
     vardefs "content == {x. x ~= null & (first,x) : {(v,w).}^*}";
     public static specvar pointed :: "obj => bool";
     public vardefs "pointed == (% n. EX x. x ~= null & = n)";
     invariant firstUnaliased: "first ~= null --> ~ pointed first";
     invariant isTree: "tree []";
    public static void add(Node n)
    /*: requires "n ~: content & n ~= null & = null & ~ pointed n"
        modifies content, pointed
        ensures "comment ''post'' (content = old content Un {n})"
    { = first;
	first = n;

It is an ordinary Java code with some annotations written in comments. The code manipulates a singly linked list of 'Node' elements. The specification variable 'content' stores all non-null objects reachable from the static variable 'first'. The definition of 'content' uses set comprehension notation '{(v,w). …}' and transitive closure notation 'r^*' to define the set of non-null nodes reachable from the first element.

The 'pointed' shorthand is a predicate that is true for a node 'n' if another node 'x' points to it. The 'pointed' predicate is defined using lambda expression for defining functions.

The invariant 'tree []' means that

  • there are never two objects that point to the same object along field
  • there are no cycles of '' fields

Such invariants apply to trees in general, but also to lists as a special case.

simple_linked_list_operation_in_jahob.txt · Last modified: 2007/05/14 12:01 by vkuncak