import Base import ../../../spec/lib/common.bend as SC import ../../../src/containers/queue.bend as Q # The two-list queue QU{front, back, count} as a Data shadow: the two lists, # with the count their total length. # model(sh) = front ++ reverse(back) the elements, oldest first type Shadow<-T: Data> is Data: Sh{front: List<&2, T>, back: List<&2, T>} def initial(-T: Data) -> Shadow: Sh{Nil{}, Nil{}} def real(-T: Data, sh: Shadow) -> Q.Queue: match sh: case Sh{+f, +b}: Q.QU{f, b, Nat.add(SC.length(T, f), SC.length(T, b))} def model(-T: Data, sh: Shadow) -> List<&2, T>: match sh: case Sh{f, b}: SC.append(T, f, SC.reverse(T, b)) def unreal(-T: Data, q: Q.Queue) -> Shadow: Q.QU{f, b, n} = q Sh{f, b} def unreal_real(-T: Data, +sh: Shadow) -> {unreal(T, real(T, sh)) == sh : Shadow}: match sh: case Sh{f, b}: {==} # a queue determines its shadow def real_inj(-T: Data, +a: Shadow, +b: Shadow, +e: {real(T, a) == real(T, b) : Q.Queue}) -> {a == b : Shadow}: Equal.trans(Shadow, a, unreal(T, real(T, a)), b, Equal.sym(Shadow, unreal(T, real(T, a)), a, unreal_real(T, a)), Equal.trans(Shadow, unreal(T, real(T, a)), unreal(T, real(T, b)), b, Equal.cong(Q.Queue, Shadow, d => unreal(T, d), real(T, a), real(T, b), e), unreal_real(T, b)))