On-the-Fly Exact Computation of Bisimilarity Distances

Tutorial for the prototype implementation

Authors: Giorgio Bacci, Giovanni Bacci, Kim G. Larsen, and Radu Mardare

This is a tutorial for the prototype implementation of our on-the-fly algorithm for computing the bisimilarity pseudometric of Desharnais et al.
This algorithm has been presented in a paper submitted to TACAS 2013 by the same authors of this tutorial, the Mathematica notebook of this tutorial is available here.

Tutorial

Encoding and manipulating Markov Chains

A Markov chain M is encoded as a term of the form MC[π, ℓ] where π and ℓ are respectively the transition funtion and the label function of M.
The set of states is implicitly respresented as a list of integer numbers {1,..., n} indicating the indices of π and ℓ.
The label function ℓ is encoded as a vector OnTheFlyDist_1.gif (of integers) indicating that the i-th state in M is labelled OnTheFlyDist_2.gif.
The transition function π is encoded as a n × n matrix of the form {{π(1,1),..., π(1,n)},...,{π(n,1),..., π(n,n)}}.

For instance we can encode the Markov chain M = MC[tm, labels] by defining the variables tm and labels as follows:

In[251]:=

OnTheFlyDist_3.gif

The Markov chain M can be displayed by means of its undelying graph. Labels are displayed using different colors.

In[252]:=

OnTheFlyDist_4.gif

Out[252]=

OnTheFlyDist_5.gif

Another way to encode a transition function is by means of a list of terms of the form Edge[i,π(i,j),j], for 1 ≤ i, j ≤ n.

In[253]:=

OnTheFlyDist_6.gif

EdgesList is then transformed in a transtition matrix using the function TransitionMatrix[n,EdgeList]

In[254]:=

OnTheFlyDist_7.gif

Out[254]//MatrixForm=

OnTheFlyDist_8.gif

One can check if the encoding corresponds to a well-formed MC by calling MarkovChainQ

In[255]:=

OnTheFlyDist_9.gif

Out[255]=

OnTheFlyDist_10.gif

Given a sequence of Markov chains OnTheFlyDist_11.gif they can be joined together using the function JoinMC

In[256]:=

OnTheFlyDist_12.gif

Out[259]=

OnTheFlyDist_13.gif

Run the on-the-fly algorithm

Given a MC M = MC[π,ℓ], a discount factor λ ∈ (0,1], and a list of pairs of states Q, the bisimilarity distance of the pairs in Q can be computed as

In[260]:=

OnTheFlyDist_14.gif

Out[261]=

OnTheFlyDist_15.gif

If one is interested is tracing the computation he can set the option Verbose as True

In[262]:=

OnTheFlyDist_16.gif

OnTheFlyDist_17.gif

OnTheFlyDist_18.gif

OnTheFlyDist_19.gif

OnTheFlyDist_20.gif

OnTheFlyDist_21.gif

OnTheFlyDist_22.gif

OnTheFlyDist_23.gif

OnTheFlyDist_24.gif

OnTheFlyDist_25.gif

OnTheFlyDist_26.gif

OnTheFlyDist_27.gif

OnTheFlyDist_28.gif

OnTheFlyDist_29.gif

OnTheFlyDist_30.gif

OnTheFlyDist_31.gif

OnTheFlyDist_32.gif

OnTheFlyDist_33.gif

OnTheFlyDist_34.gif

OnTheFlyDist_35.gif

Out[262]=

OnTheFlyDist_36.gif

If one is iterestes in computing the distance between all pair of states it suffices to ask for All pairs

In[263]:=

OnTheFlyDist_37.gif

Out[263]=

OnTheFlyDist_38.gif

The output is returned as a set of ArrayRules, so that one can easily transform it into a matrix using the function SparseArray

In[264]:=

OnTheFlyDist_39.gif

Out[264]//MatrixForm=

OnTheFlyDist_40.gif

Examples

Example taken from the paper submitted at TACAS 2013

Here we use the MC presented in the paper submitted at TACAS 2013 in order to show most of the features of our on-the-fly algorithm.

In[265]:=

OnTheFlyDist_41.gif

Out[268]=

OnTheFlyDist_42.gif

Let us compute the distance between the state 1 and 4, namely d(1,4)

In[269]:=

OnTheFlyDist_43.gif

OnTheFlyDist_44.gif

OnTheFlyDist_45.gif

OnTheFlyDist_46.gif

OnTheFlyDist_47.gif

OnTheFlyDist_48.gif

OnTheFlyDist_49.gif

OnTheFlyDist_50.gif

OnTheFlyDist_51.gif

OnTheFlyDist_52.gif

OnTheFlyDist_53.gif

OnTheFlyDist_54.gif

OnTheFlyDist_55.gif

OnTheFlyDist_56.gif

OnTheFlyDist_57.gif

OnTheFlyDist_58.gif

OnTheFlyDist_59.gif

OnTheFlyDist_60.gif

OnTheFlyDist_61.gif

OnTheFlyDist_62.gif

Out[269]=

OnTheFlyDist_63.gif

Looking the execution trace we see that during the computation of d(1,4) an over-approximation for the distance d(3,4) is computed.
This happens because the we encountered a coupling that demands d(3,4) for computing an over-approximation of d(1,4).
However, the first improvement of the current coupling makes the computation of d(3,4) no more demanded for d(1,4), so that no further improvement on (3,4) is made.

On the other hand, as shown in the execution trace that follows, the exact computation of d(3,4) demands an exact computation of d(1,3), d(1,4) and d(2,6)

In[270]:=

OnTheFlyDist_64.gif

OnTheFlyDist_65.gif

OnTheFlyDist_66.gif

OnTheFlyDist_67.gif

OnTheFlyDist_68.gif

OnTheFlyDist_69.gif

OnTheFlyDist_70.gif

OnTheFlyDist_71.gif

OnTheFlyDist_72.gif

OnTheFlyDist_73.gif

OnTheFlyDist_74.gif

OnTheFlyDist_75.gif

OnTheFlyDist_76.gif

OnTheFlyDist_77.gif

OnTheFlyDist_78.gif

OnTheFlyDist_79.gif

OnTheFlyDist_80.gif

OnTheFlyDist_81.gif

OnTheFlyDist_82.gif

OnTheFlyDist_83.gif

OnTheFlyDist_84.gif

OnTheFlyDist_85.gif

OnTheFlyDist_86.gif

OnTheFlyDist_87.gif

OnTheFlyDist_88.gif

OnTheFlyDist_89.gif

OnTheFlyDist_90.gif

OnTheFlyDist_91.gif

OnTheFlyDist_92.gif

OnTheFlyDist_93.gif

OnTheFlyDist_94.gif

OnTheFlyDist_95.gif

OnTheFlyDist_96.gif

OnTheFlyDist_97.gif

OnTheFlyDist_98.gif

OnTheFlyDist_99.gif

OnTheFlyDist_100.gif

OnTheFlyDist_101.gif

OnTheFlyDist_102.gif

Out[270]=

OnTheFlyDist_103.gif

We have seen that the exact computation of d(3,4) demands for the exact compuatation of d(1,3), d(1,4), d(2,6).
One would claim that if we ask for the exact computation of d(3,4), d(1,4) and d(2,6) the compuatation will do the same steps made for d(3,4).
In some sense this is true, since we will need to compute the same set of distances, however we have seen that the exact computation of d(1,4) does not need an exact compuation of the remaining pairs.
Thus, considering the pair (1,4) before (3,4) will allow us to reduce the size of the linear equation systems computed for d(3,4).

In[271]:=

OnTheFlyDist_104.gif

OnTheFlyDist_105.gif

OnTheFlyDist_106.gif

OnTheFlyDist_107.gif

OnTheFlyDist_108.gif

OnTheFlyDist_109.gif

OnTheFlyDist_110.gif

OnTheFlyDist_111.gif

OnTheFlyDist_112.gif

OnTheFlyDist_113.gif

OnTheFlyDist_114.gif

OnTheFlyDist_115.gif

OnTheFlyDist_116.gif

OnTheFlyDist_117.gif

OnTheFlyDist_118.gif

OnTheFlyDist_119.gif

OnTheFlyDist_120.gif

OnTheFlyDist_121.gif

OnTheFlyDist_122.gif

OnTheFlyDist_123.gif

OnTheFlyDist_124.gif

OnTheFlyDist_125.gif

OnTheFlyDist_126.gif

OnTheFlyDist_127.gif

OnTheFlyDist_128.gif

OnTheFlyDist_129.gif

OnTheFlyDist_130.gif

OnTheFlyDist_131.gif

OnTheFlyDist_132.gif

OnTheFlyDist_133.gif

OnTheFlyDist_134.gif

OnTheFlyDist_135.gif

OnTheFlyDist_136.gif

OnTheFlyDist_137.gif

OnTheFlyDist_138.gif

OnTheFlyDist_139.gif

OnTheFlyDist_140.gif

OnTheFlyDist_141.gif

OnTheFlyDist_142.gif

OnTheFlyDist_143.gif

OnTheFlyDist_144.gif

OnTheFlyDist_145.gif

OnTheFlyDist_146.gif

OnTheFlyDist_147.gif

OnTheFlyDist_148.gif

OnTheFlyDist_149.gif

OnTheFlyDist_150.gif

OnTheFlyDist_151.gif

OnTheFlyDist_152.gif

OnTheFlyDist_153.gif

OnTheFlyDist_154.gif

OnTheFlyDist_155.gif

Out[271]=

OnTheFlyDist_156.gif

Another way to limit the exploration of the MC is to give estimates for some distances. For instance, we have seen that for computing the distance d(3,4) we need to solve exactly
the problem for the pair (2,6). Assume we have an over-approximation of the exact value for d(2,6), we can use this information in order to further reduce the exploration of the MC.

In[272]:=

OnTheFlyDist_157.gif

OnTheFlyDist_158.gif

OnTheFlyDist_159.gif

OnTheFlyDist_160.gif

OnTheFlyDist_161.gif

OnTheFlyDist_162.gif

OnTheFlyDist_163.gif

OnTheFlyDist_164.gif

OnTheFlyDist_165.gif

OnTheFlyDist_166.gif

OnTheFlyDist_167.gif

OnTheFlyDist_168.gif

OnTheFlyDist_169.gif

OnTheFlyDist_170.gif

OnTheFlyDist_171.gif

OnTheFlyDist_172.gif

OnTheFlyDist_173.gif

OnTheFlyDist_174.gif

OnTheFlyDist_175.gif

OnTheFlyDist_176.gif

OnTheFlyDist_177.gif

Out[272]=

OnTheFlyDist_178.gif

Using the estimate OnTheFlyDist_179.gif for the distance d(2,6) we considerably reduced the number of steps for computing a good over-approximation for d(3,4).

Unfair Tossing Coins

In this example we model two unfair flipping coins.

In[273]:=

OnTheFlyDist_180.gif

Out[275]=

OnTheFlyDist_181.gif

In[276]:=

OnTheFlyDist_182.gif

OnTheFlyDist_183.gif

OnTheFlyDist_184.gif

OnTheFlyDist_185.gif

OnTheFlyDist_186.gif

OnTheFlyDist_187.gif

OnTheFlyDist_188.gif

OnTheFlyDist_189.gif

OnTheFlyDist_190.gif

OnTheFlyDist_191.gif

Out[276]=

OnTheFlyDist_192.gif

The Craps Game

Here we present two different MCs modeling two slightly different versions for the “craps game”. These models have both been taken from the book Principles of Model Checking, Examples 10.4 and 10.23 respectivelty. We compare the two models by means of the distance beteween their initial states.

In[277]:=

OnTheFlyDist_193.gif

In[280]:=

OnTheFlyDist_194.gif

Out[280]=

OnTheFlyDist_195.gif

In[281]:=

OnTheFlyDist_196.gif

In[283]:=

OnTheFlyDist_197.gif

Out[283]=

OnTheFlyDist_198.gif

In[284]:=

OnTheFlyDist_199.gif

OnTheFlyDist_200.gif

OnTheFlyDist_201.gif

OnTheFlyDist_202.gif

OnTheFlyDist_203.gif

OnTheFlyDist_204.gif

OnTheFlyDist_205.gif

OnTheFlyDist_206.gif

OnTheFlyDist_207.gif

OnTheFlyDist_208.gif

OnTheFlyDist_209.gif

OnTheFlyDist_210.gif

OnTheFlyDist_211.gif

OnTheFlyDist_212.gif

OnTheFlyDist_213.gif

OnTheFlyDist_214.gif

OnTheFlyDist_215.gif

OnTheFlyDist_216.gif

OnTheFlyDist_217.gif

OnTheFlyDist_218.gif

OnTheFlyDist_219.gif

OnTheFlyDist_220.gif

OnTheFlyDist_221.gif

OnTheFlyDist_222.gif

OnTheFlyDist_223.gif

OnTheFlyDist_224.gif

OnTheFlyDist_225.gif

OnTheFlyDist_226.gif

OnTheFlyDist_227.gif

OnTheFlyDist_228.gif

OnTheFlyDist_229.gif

OnTheFlyDist_230.gif

OnTheFlyDist_231.gif

OnTheFlyDist_232.gif

OnTheFlyDist_233.gif

Out[284]=

OnTheFlyDist_234.gif

Bisimilarity Distance and Bisimilarity Quotient

Let M be a (randomly generated) Markov chain with 50 states and outer-degree 2

In[366]:=

OnTheFlyDist_235.gif

Out[368]=

OnTheFlyDist_236.gif

the bisimilarity pseudometric can also be used in order to detect all the bisimilarity classes, i.e. the equivalence classes of the set of state w.r.t probabilistic bisimilarity

In[369]:=

OnTheFlyDist_237.gif

Out[369]=

OnTheFlyDist_238.gif

so that this can be used to construct an MC M’ bisimilar to M with all the states that are bisimilar in M lumped together. M’ is also known as the bisimilar quotient of M.

In[370]:=

OnTheFlyDist_239.gif

Out[370]=

OnTheFlyDist_240.gif

Obvousy, for any MC M, the bisimilarity quotient of two copies of M joined together correspons to M itselfs

In[371]:=

OnTheFlyDist_241.gif

Out[371]=

OnTheFlyDist_242.gif

In[372]:=

OnTheFlyDist_243.gif

Out[372]=

OnTheFlyDist_244.gif

Implementation

Utilities

In[292]:=

OnTheFlyDist_245.gif

In[293]:=

OnTheFlyDist_246.gif

In[294]:=

OnTheFlyDist_247.gif

In[295]:=

OnTheFlyDist_248.gif

In[296]:=

OnTheFlyDist_249.gif

In[297]:=

OnTheFlyDist_250.gif

Labelled Markov Chains (LMCs)

In[298]:=

OnTheFlyDist_251.gif

In[299]:=

OnTheFlyDist_252.gif

In[300]:=

OnTheFlyDist_253.gif

Given a list of edges of the form Edge[s,p,t] indicating that there exists a transition from the state s to t with probability p,
TransitionMatrix[|S|,edgeList] returns the transition matrix π induced by them.

In[302]:=

OnTheFlyDist_254.gif

JoinMC returns a graphical representation of a given Markov chain

In[303]:=

OnTheFlyDist_255.gif

PlotMC returns a graphical representation of a given Markov chain

In[305]:=

OnTheFlyDist_256.gif

Random generation of LMCs

In[307]:=

OnTheFlyDist_257.gif

RandomProbDistr gives a pseudorandom list of rationals OnTheFlyDist_258.gifsuch that OnTheFlyDist_259.gif

In[308]:=

OnTheFlyDist_260.gif

In[309]:=

OnTheFlyDist_261.gif

In[311]:=

OnTheFlyDist_262.gif

In[312]:=

OnTheFlyDist_263.gif

In[313]:=

OnTheFlyDist_264.gif

Transportation Problem

Given two ε-numbers x and y, EpsilonLeq[x,y] determines if x ≤ y provided that ε → +0.

In[315]:=

OnTheFlyDist_265.gif

In[316]:=

OnTheFlyDist_266.gif

In[317]:=

OnTheFlyDist_267.gif

In[318]:=

OnTheFlyDist_268.gif

In[319]:=

OnTheFlyDist_269.gif

In[320]:=

OnTheFlyDist_270.gif

In[321]:=

OnTheFlyDist_271.gif

In[323]:=

OnTheFlyDist_272.gif

In[324]:=

OnTheFlyDist_273.gif

In[325]:=

OnTheFlyDist_274.gif

AddtoBase[d, vertex] == {reducedcost, non-basic cell}
returns the non-basic cell which has the minimal reduced cost, if the vertex has no non-basic cells, then it returns {∞, {0,0}}.

In[326]:=

OnTheFlyDist_275.gif

SteppingStone[non-basic cell, vertex] returns the vertex obtained by inserting the given non-basic cell into the base

In[327]:=

OnTheFlyDist_276.gif

In[328]:=

OnTheFlyDist_277.gif

In[329]:=

OnTheFlyDist_278.gif

In[330]:=

OnTheFlyDist_279.gif

Iterative Algorithm

Given the numer of states |S|, BottomDist[|S|] returns the bottom distance

In[332]:=

OnTheFlyDist_280.gif

In[333]:=

OnTheFlyDist_281.gif

The funtion Δ implements the distance transformer

In[334]:=

OnTheFlyDist_282.gif

In[335]:=

OnTheFlyDist_283.gif

On-the-fly Algorithm for computing Bisimilarity Pseudometric

Given as input an indexed vertex v, SubProblems[v] returns the list of active subproblems. This is simply done by selecting the (non-degenerate) basic cells of ω.

In[336]:=

OnTheFlyDist_284.gif

In[337]:=

OnTheFlyDist_285.gif

In[338]:=

OnTheFlyDist_286.gif

In[339]:=

OnTheFlyDist_287.gif

In[341]:=

OnTheFlyDist_288.gif

In[342]:=

OnTheFlyDist_289.gif

Compute the coefficients OnTheFlyDist_290.gif for the given (vertex) schedule

In[343]:=

OnTheFlyDist_291.gif

ActiveProblems maps each active problem to its coefficients OnTheFlyDist_292.gif

In[344]:=

OnTheFlyDist_293.gif

In[347]:=

OnTheFlyDist_294.gif

In[350]:=

OnTheFlyDist_295.gif

In[351]:=

OnTheFlyDist_296.gif

In[352]:=

OnTheFlyDist_297.gif

VertexToChange[dist, {s,t}] == {{i,j}, {redCost, nbcell}} if the problem (i,j) can be further minimized, otherwise it returns {}

In[353]:=

OnTheFlyDist_298.gif

In[354]:=

OnTheFlyDist_299.gif

In[362]:=

OnTheFlyDist_300.gif

In[363]:=

OnTheFlyDist_301.gif

Bisimilarity

BisimQuotient[mc] returns an MC with all bisimilar states lumped together

In[364]:=

OnTheFlyDist_302.gif

BisimClasses[mc] returns the quotient w.r.t. bisimilarity

In[365]:=

OnTheFlyDist_303.gif

Spikey Created with Wolfram Mathematica 8.0