[PostScript]
Deque (E, C): trait
  % Double ended queue operators
  includes Integer
  introduces
    empty: -> C
    __ \precat __: E, C -> C
    __ \postcat __: C, E -> C
    count: E, C -> Int
    __ \in __: E, C -> Bool
    head, last: C -> E
    tail, init: C -> C
    len: C -> Int
    isEmpty: C -> Bool
  asserts
    C generated by empty, \postcat
    forall e, e1, e2: E, d: C
      count(e, empty) == 0;
      count(e, e1 \precat d) ==
        count(e, d) + (if e = e1 then 1 else 0);
      e \in d == count(e, d) > 0;
      e \precat empty == empty \postcat e;
      (e1 \precat d) \postcat e2 == e1 \precat (d \postcat e2);
      head(e \precat d) == e;
      last(d \postcat e) == e;
      tail(e \precat d) == d;
      init(d \postcat e) == d;
      len(empty) == 0;
      len(d \postcat e) == len(d) + 1;
      isEmpty(d) == d = empty
  implies
    Stack (head for top, tail for pop,
           \precat for push, len for size),
    Queue (\precat for append, last for head, 
           init for tail)
    C generated by empty, \precat
    C partitioned by len, head, tail
    C partitioned by len, last, init
    forall d: C
      d \neq empty
        => (head(d) \precat tail(d) = d
            /\ init(d) \postcat last(d) = d)
    converts head, last, tail, init, len
      exempting head(empty), last(empty),
        tail(empty), init(empty)
[Table of Contents] [Index]