Presentation is loading. Please wait.

Presentation is loading. Please wait.

June 27, 2002 HornstrupCentret1 Using Compile-time Techniques to Generate and Visualize Invariants for Algorithm Explanation Thursday, 27 June 2002 13:00-13:30.

Similar presentations


Presentation on theme: "June 27, 2002 HornstrupCentret1 Using Compile-time Techniques to Generate and Visualize Invariants for Algorithm Explanation Thursday, 27 June 2002 13:00-13:30."— Presentation transcript:

1 June 27, 2002 HornstrupCentret1 Using Compile-time Techniques to Generate and Visualize Invariants for Algorithm Explanation Thursday, 27 June 2002 13:00-13:30 Reinhard WilhelmTomasz Müldner Informatik Jodrey School of Computer Science Universität des Saarlandes Acadia University Saarbrücken, Germany Wolfville, Canada

2 June 27, 2002 HornstrupCentret 2 Introduction Algorithm : A specific set of instructions for carrying out a procedure or solving a problem, usually with the requirement that the procedure terminate at some point.

3 June 27, 2002 HornstrupCentret 3 Models of Human Understanding Step-by-step textual representation of an algorithm is analytic (reducing a whole to its parts) Visual representation may provide a synthetic view (build up separate elements into a connected whole) But many visual representations are more analytic than synthetic

4 June 27, 2002 HornstrupCentret 4 Analytic versus Synthetic One of animations of Insertion Sort gives these instructions: Start by comparing the first two rectangles in the group, and shift the second rectangle to the left if it is smaller. Look at the next rectangle, compare with the one on its left, and shift it to the left until it is smaller than the one to its right and larger than the one to its left. Repeat step 2 until finished.

5 June 27, 2002 HornstrupCentret 5 Analytic versus Synthetic: Animal

6 June 27, 2002 HornstrupCentret 6 Implementation Standard way to implement visualizations for algorithm explanation: use run-time techniques Our approach use compile-time techniques

7 June 27, 2002 HornstrupCentret 7 Implementation Shape analysis, parameterized with sets of observation properties, which statically determine the invariants of the algorithm Abstract execution of the algorithm showing invariants

8 June 27, 2002 HornstrupCentret 8 What’s “Algorithm Explanation”? It is not: Algorithm animation Debugging (at least in its traditional sense) Proving (partial) correctness It is a tool to help understanding various algorithms Focus on relevant part of data structures

9 June 27, 2002 HornstrupCentret 9 Focus: Insertion to BST Standard algorithm visualization shows the entire tree, even though the insertion takes place only in one of the subtrees One should show an essential invariant, stating that for each inner node, the elements in its left subtree have data components smaller than that of the node and elements in its right subtree have data components larger than that of the node

10 June 27, 2002 HornstrupCentret 10 Our Approach: What to show 1. The designer selects a data structure and an algorithm to be explained. 2. The designer selects a set of properties characterizing the data structure (to be used to formulate invariants for the algorithm).

11 June 27, 2002 HornstrupCentret 11 Our Approach: How to show 3. The designer runs a shape analysis, which will annotate each program point with a set of shape graphs describing all heap contents that may exist when program execution reaches this program point 4. The designer defines a visual representation for the shape graphs computed by the shape analysis

12 June 27, 2002 HornstrupCentret 12 Our Approach: User 5. Now, the user: - selects one particular shape graph at the entry to one particular program statement and then executes the statement and observes the effect on the chosen shape graph - performs a visualized abstract execution of the algorithm.

13 June 27, 2002 HornstrupCentret 13 Example: Insertion Sort (on lists) /* list.h */ typedef struct elem { struct elem* n; double data; }* List;

14 June 27, 2002 HornstrupCentret 14 List insert_sort(List x) { List r, pr, l, pl; r = x; pr = NULL; while (r != NULL) { /* while the suffix r is not empty */ l = x; /* sorted prefix is pointed to by x */ pl = NULL; while (l != r) { … } pr = r; r = r->n; } return x; }

15 June 27, 2002 HornstrupCentret 15 /* inner loop */ while (l != r) { /* P1: */ if (l->data > r->data) { /* P2 : after positive outcome of comparison, move r before l */ pr->n = r->n; r->n = l; if (pl == NULL) x = r; else pl->n = r; r = pr; break; } pl = l; l = l->n; }

16 June 27, 2002 HornstrupCentret 16 Visualization: Point P1 Here, the inner loop has been executed several times and the current execution point is P1: while (l != r) { /* P1: */ if (l->data > r->data) { … }

17 June 27, 2002 HornstrupCentret 17 Visualization: Kinds of nodes Unique nodes (shown as rectangles) represent single concrete elements of the heap, Summary nodes (shown as cubes) represent sets of nodes that are not distinguishable by the selected observation properties Non-empty lists of nodes (shown as cubes with an additional rectangle at the back)

18 June 27, 2002 HornstrupCentret 18 Visualization: Abstract Heap the above figure shows the abstract heap; an infinite set of singly linked lists with a set of pointers pointing into this list and some conditions on the minimal lengths of sublists. horizontal arrows are implicitly labelled by the successor in the singly-linked list Dashed self-loops show that we deal with summarized sublists

19 June 27, 2002 HornstrupCentret 19 Visualization: Partial order The placement on the x-axis indicates the relative value of the represented concrete elements However, not all elements are comparable We need a graphical representation of partial order on nodes, and use ascending chains (shown with patterns) we have two chains x, t1, pl, l, t2, pr x, t1, pl, r suffix

20 June 27, 2002 HornstrupCentret 20 Visualization: Summary The above graph represents all lists for which the prefix of the list, pointed to by x, up to the element pointed to by pr, is already sorted (the sorted prefix). The next element in the list is pointed to by pointer variable r; it is the one to be inserted in the sorted prefix; the suffix of the list following this element is represented by t3.

21 June 27, 2002 HornstrupCentret 21 Visualization: Next step What happens in the transition corresponding to the /* P1: */ if (l->data > r->data) assuming it is true? This transition increases the sortedness of the list

22 June 27, 2002 HornstrupCentret 22 Visualization: Next state There is only one chain, representing the sorted prefix, and the transition, which explains the preservation of the invariant.

23 June 27, 2002 HornstrupCentret 23 Visualization: Summary Shape analysis starts with a description of all possible inputs and has to compute invariants at all program points, in particular show that the postcondition holds, namely that upon termination the elements are sorted Shape analysis abstracts from the values of data- components. Data structure elements are thus incomparable to start with, but “gain comparability” by abstractly executing conditions.

24 June 27, 2002 HornstrupCentret 24 Visualization: Summary Invariants do not refer to actual data, but only mention relative sizes Only a partial order on the elements of the data structure is known to the shape analysis. Abstractly executing comparisons may insert elements into chains, i.e. totally ordered subsets of the partial order.

25 June 27, 2002 HornstrupCentret 25 Conclusion: Current State New approach to algorithm explanation based on compile-time techniques used to automatically generate and visualize invariants The simple example is representative for many similar programs operating on linked lists Our approach involves several steps and only some of them are fully researched; others require additional work. The invariants are pre-computed by shape analysis, implemented in the TVLA system.

26 June 27, 2002 HornstrupCentret 26 Conclusion: Future Work Current analysis produces too many graphs for the users to traverse. Some of the graphs are redundant for the abstract execution and can be eliminated We need to find appropriate visualizations for various kinds of nodes in shape graphs More theoretical work

27 June 27, 2002 HornstrupCentret 27 Conclusion: Promises, promises We believe that our research is promising: Automatic generation of invariants; based on observation properties Abstract execution that runs on all input data Focusing on the relevant part of the data structure

28 June 27, 2002 HornstrupCentret 28 Shape Analysis Shape analysis is concerned with programs operating on heap-based data structures, such as singly and doubly linked lists, trees, etc. To summarize these data structures, use descriptors and Kleene 3-valued logic

29 June 27, 2002 HornstrupCentret 29 Descriptors Descriptors can be represented as “shapes”, and are called shape descriptors. This representation is a possible visualization of data structures.

30 June 27, 2002 HornstrupCentret 30 Shape Analysis, cont. Abstract interpretation of program statements operates on shape descriptors Information that is obtained from shape analysis includes: - structural properties of data - local properties of data


Download ppt "June 27, 2002 HornstrupCentret1 Using Compile-time Techniques to Generate and Visualize Invariants for Algorithm Explanation Thursday, 27 June 2002 13:00-13:30."

Similar presentations


Ads by Google