<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>Juliana K. F. Bowles[</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>A Formally Veri ed SMT Approach to True Concurrency?</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>School of Computer Science</institution>
          ,
          <addr-line>University of St Andrews St Andrews KY16 9SX</addr-line>
          ,
          <country country="UK">United Kingdom</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>0000</year>
      </pub-date>
      <volume>0002</volume>
      <abstract>
        <p>Many problems related to distributed and parallel systems, such as scheduling and optimisation, are computationally hard, thereby justifying the adoption of SMT solvers. The latter provide standard arithmetic as interpreted functions, naturally leading to express concurrent executions as a linearly-ordered sequentialisation (or interleaving) of events, which have an obvious correspondence with integer segments and therefore permit to take advantage of such arithmetical capabilities. However, there are alternative semantic approaches (also known as true concurrent) not imposing the extra step of interleaving events, which brings the question of how to computationally exploit SMT solvers in these approaches. This paper presents a solution to this problem, and introduces a metric, made possible by adopting a true concurrent paradigm, which relates mutually distinct solutions of a family of distributed optimisation problems. We also contribute an original, computational de nition of degree of parallelism, which we compare with the existing ones. Finally, we use theorem proving to formally certify a basic correctness property of our true concurrent approach.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>There are many possible models to capture the behaviour of distributed and
parallel systems. Here we use labelled (prime) event structures [24], or event
structures for short. Event structures have been widely studied in the literature,
and have been used to give a true concurrent semantics to process calculi such as
CCS, CSP, SCCS and ACP (e.g., [23]). The advantages of prime event structures
include their underlying simplicity and how they naturally describe fundamental
notions present in behavioural models including sequential, parallel and iterative
behaviour (or the unfoldings thereof) as well as nondeterminism (cf. [14]), and
are hence our model of choice. Event structures consist of sets of events and
binary relations over events to represent these notions. When used to capture the
behaviour of a system, for example, event structures can be further equipped with
labelling (total or partial) functions that associate information to these events,
such as the action performed, action synchronisations, or any additional metric
that may be relevant within the context. For instance, in a medical context an
event may be associated with taking a particular medication, and a measure of
interest may be the e cacy of the chosen medication for the underlying treatment.</p>
      <p>Event structures have well-de ned composition operators (cf. e.g., [18]).
However, these composition mechanisms ignore labels and are hence inadequate for
our use here. In practice we are not interested in computing the composition of
models, but rather in nding optimal paths of execution in such a composition
with respect to a certain measure of interest (usually a certain integer value
which we want to maximise or minimise). Again, within a medical context this
may be to maximise the e cacy of the medications given to patients following
multiple treatment plans (which may be the case if patients have
multimorbidities, i.e., multiple ongoing chronic conditions). In this case, we are searching for
optimal treatment plans which also avoid adverse drug reactions between chosen
medications (i.e., maximise e cacy whilst minimising adverse reactions).</p>
      <p>When measures of interest can be quanti ed, we can make use of SMT
(Satis ability Modulo Theories) solvers to search for the optimal solution. We
have used the SMT solver Z3 [17] in our earlier work (see for instance [5,6,7]).
However, in that work we have ignored the true concurrent nature of event
structures and treated the inherent parallelism within executions as interleaving.</p>
      <p>In this paper, we turn our attention to the problem of computing and
selecting trace executions in a true-concurrent manner, as opposed to an implicit
non-deterministic choice among allowed sequentialisations (or interleaving) of
events. While work exists providing theoretical frameworks to characterise and
reason about true-concurrency [1], [10], [15], true-concurrent approaches to the
computational problem introduced above are rare. Other existing works we are
aware of (see, for example, [12]) deal with notions of distance between di erent
event structures, rather than between trace executions of one event structure.
In [16] a problem similar to the one considered here is studied, but within the
theoretical framework of Petri nets, and without including a numerical interaction
between sets of concurrent events to in uence the execution choice, as we do here:
there, the focus is more on the theoretical study of the complexity associated
with checking the optimality of a number of resources (concurrency threshold)
for the execution of a given parallel process. Our work presents similar di
erences with [9], where an encoding of timed BPMN models into rewriting logic is
presented; this permits to use the rewriting logic implementation Maude [8] in
order to re ect about a notion of parallelism degree.</p>
      <p>The contributions we provide are: an SMT-viable model for a true-concurrent
handling of trace executions, a notion of metric to be able to choose among such
executions, and, at the same time, to quantify the degree of concurrency of a trace
execution; nally, a formal veri cation of a basic sanity property of our approach
through the theorem prover Isabelle/HOL, where Isabelle is foundation-agnostic
proof assistant and Isabelle/HOL is the strain based on higher-order logic (HOL)
[19]1</p>
      <p>This paper is structured as follows. Section 2 describes the formal model
used, how con gurations and paths/traces of executions are de ned, as well as
what resources we care to maximise/minimise when searching for the optimal
path. Our SMT-based formulation of the problem is shown in Section 3 and
how veri cation is done is described in Section 4. This is followed by concluding
remarks in Section 5.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Formal Model</title>
      <p>In an event structure, we have a set of event occurrences together with binary
relations for expressing causal dependency (called causality) and nondeterminism
(called con ict ). The causality relation implies a (partial) order among event
occurrences, while the con ict relation expresses how the occurrence of certain
events excludes the occurrence of others. From the two relations de ned over
the set of events, a further relation is derived, namely the concurrency relation
co. Two events are concurrent if and only if they are completely unrelated, i.e.,
neither related by causality nor by con ict.</p>
      <p>
        The formal de nition of an event structure, as in [14], is as follows.
De nition 1. An event structure is a triple E = (Ev; ! ; #) where Ev is a
set of events and ! ; # Ev Ev are binary relations called causality and
con ict, respectively. Causality ! is a partial order. Con ict # is symmetric and
irre exive, and propagates over causality, i.e., e#e0 ^ e0 ! e00 ) e#e00 for all
e; e0 ; e00 2 Ev. Two events e; e0 2 Ev are concurrent, e co e0 i :(e ! e0 _ e0 !
e _ e#e0 ). C Ev is a con guration i (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) C is con ict-free: 8e; e0 2 C:( e#e0)
and (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) downward-closed: e 2 C and e0 ! e implies e0 2 C.
      </p>
      <p>We assume discrete event structures. Discreteness imposes a niteness
constraint on the model, i.e., there are always only a nite number of causally related
predecessors to an event, known as the local con guration of the event (written
# e). A further motivation for this constraint is given by the fact that every
execution has a starting point or con guration. A maximal con guration is called
a trace. An event e may have an immediate successor e0 according to the order
! , written e ! e0, where ! denotes immediate causality i there is no possible
intermediate event. Fig. 1 shows a visual depiction of a simple event structure.</p>
      <p>Here, event e0 marks the initial event, and events e1#e8 are in con ict.
According to con ict propagation, events e1#e9 are also in con ict. Immediate
causality is shown, and any events not related by causality or con ict are
concurrent. For instance, e2 co e6 are concurrent. Two con gurations are shown
surrounding some of the events: in red to the left (X1), and in green to the right
(X2). X1 contains concurrency, whereas X2 does not. Moreover, X1 =#e7 and
X2 =#e10.
1 We will often write just Isabelle in lieu of Isabelle/HOL.</p>
      <p>To make a connection between the semantic model (an event structure) and
the syntactic model (ignored here) it is describing, we need to associate additional
information to individual events. Let L be a given set of labels.</p>
      <p>De nition 2. A labelled event structure over L is a triple M = (Ev; ; ) where
and are partial labelling functions : Ev ! 2L and : Ev ! N N.</p>
      <p>Labelled event structures are event structures enriched with two labelling
functions and . The function maps events onto a subset of elements of L.
The labels in the set L either denote formulas (constraints over integer variables,
e.g., x &gt; 9 or y = 5), logical propositions (e.g., pro1) or actions (e.g., ma1). If
for an event e 2 Ev, (e) contains an action 2 L, then e denotes an occurrence
of that action . If (e) contains a formula or logical proposition ' 2 L, then '
must hold when e occurs.</p>
      <p>The labelling function associates to each event its priority and duration,
for instance, (e) = (p; d) indicates that p is the priority and d is the duration
associated with e. The higher the value of p, the higher the priority associated to
the event. The duration d indicates the time units spent at event e. Sometimes, we
will write 1 or 2 for the function returning only the rst or second component
of the pair returned by .</p>
      <p>Giving di erent priority values to events is meaningful in the presence of
alternatives (con icting events), where the highest value can be used to determine
the ideal con guration in a model. For instance, event e2 may have a higher
priority than e8. Further labels may be added to the framework as partial
functions if required. We call a labelled event structure a model in what follows.
In addition, we de ne a map
labels as follows.</p>
      <p>specifying the level of con ict between event
De nition 3. Label con icts are given by a (possibly partial) function
Z:
: 2L !</p>
      <p>When we are interested to the value of in a restricted subset of L, we use
the notation (l1; l2; v), indicating that l1 and l2 are in con ict with an interaction
score of value v. We consider that the lower the value of v the higher the severity
of the label con ict. This permits to add further expressiveness to our model: for
example, two events may not be in con ict, but the possible choice for their labels
could have a bad interaction score, which could lead to alternative solutions. For
the event structure in Fig. 1, we assume that (e4) = ma2 and (e3) = mb2, and
a label con ict such that (fma2; mb2g) = 100.</p>
      <p>The labels of some of the events (e3 and e4 in the example) are con icting
according to . When obtaining the optimal trace execution within the event
structure above we need to make sure label inconsistencies are detected and
avoided. A trace execution that avoids a label con ict is given by an execution of
the con guration X2. However, this is too restrictive since the priority of e2 is
higher than e8, and X1 may hence lead to an overall better trace execution. The
label con icts are only a problem if the events occur simultaneously.</p>
      <p>In our earlier approach [7], events in a con guration would be linearised and
hence the label con ict automatically avoided. The loss of parallelism would,
however, be too signi cant, and instead we want to choose trace executions for
con gurations that avoid label con icts but achieve the best possible measure of
concurrency. Consider a few options for traces execution for X1 shown in Fig. 2.
We show a timeline from left to right and event durations, where overlapping
events denote simultaneous execution. As highlighted, trace1 (shorthand name for
execution number 1 of the trace) is problematic since the simultaneous execution
of e3 and e4 would contribute to a label con ict. Both trace2 and trace3 avoid
label con icts, but trace2 has a higher degree of concurrency as it takes less time
to execute (more events are executed in parallel). Because the notion of how
many events are executed in parallel seems more complicated to de ne formally,
we take the execution time as a de nition of degree of parallelism. While the two
notions are intuitively strongly correlated, this does not mean that this measure
will pick an execution having the highest number of parallel events at all instants.</p>
      <p>Let us focus on a given subset of events C (which could be, for example,
the events in a trace), and introduce the idea of how to associate to di erent
executions of C a number measuring how parallel they are. The lowest degree of
parallelism will correspond to the number e2C 2(e) + ; given by the sum of
all event durations (yielded by the function 2) and an additional parameter
representing idle time in between events. is a parameter to describe optional
slack in the execution, and can be set to zero when not needed. The highest
possible (loose) upper bound to the degree of parallelism will correspond to the
maximal duration of an event in C.</p>
      <p>In our example, let C1 = fe2; e3g and C2 = fe4; e5; e6g. The degree of
concurrency for di erent executions of C1 would be in the range [2; 3 + ], where
2(e2) = 1 and 2(e3) = 2; and for C2 in [2; 4 + ] where 2(e4) = 2(e6) = 1 and
2(e5) = 2. In Fig. 2, executions trace1 and trace2 have the highest degree of
concurrency. In the sequel, we will give a precise de nition to this idea of degree
of concurrency, allowing us to compute its exact value for any execution, picked
from the range introduced above.
3</p>
    </sec>
    <sec id="sec-3">
      <title>An SMT-oriented Formulation</title>
      <p>The e ciency of SMT solvers comes at a price: rst, one has to nd a formulation
of their problem which must be in rst-order logic, because SMT-LIB (the
standardised input format for SMT solvers [3]) is a rst-order language, although
with some added interpreted relations (whence the letters M and T in SMT).
Secondly, the SMT-LIB code one obtains after managing to do that is typically
very little readable for a human, as we will see in this section. We will deal with
the rst problem in this section, and with the second in Section 4.</p>
      <p>We will use the natural index i to range over (1; : : : ; n) where n is the number
of models (event structures) we are considering for composition. Since we will need
to impose conditions on all of them, in the sequel we will often implicitly quantify
over i. We denote by Gi the set of ordered pairs representing the immediate
causality relation !i; that is, given events e0, e1 in the i-th event structure:
(e0; e1) 2 Gi $ e0 !i e1:
This is the standard way of representing relations (such as !i) in set theory. Gi
can also be viewed as the set of edges of a directed graph (given by the transitive
reduction of the partial order !i ): this graph-theoretical view will sometimes be
useful and gives us the relevant jargon, allowing us to refer to nodes instead of
events, etc. We also denote with</p>
      <p>G := [iGi
Ev := [ Evi</p>
      <p>i
the union of all the immediate causality relations and with</p>
      <p>Evi := dom Gi [ ran Gi
the set of all the events of the i-th event structure (dom and ran take the domain
and the range set, respectively, of any given relation). Finally,
is the set of all the events.
3.1</p>
      <p>
        Trace Selection
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
(
        <xref ref-type="bibr" rid="ref2">2</xref>
        )
(
        <xref ref-type="bibr" rid="ref3">3</xref>
        )
(
        <xref ref-type="bibr" rid="ref4">4</xref>
        )
Recall that a con guration Xi for Evi is a set of events of Evi which is downward
closed and con ict-free:
8e1 2 ran (Gi) :e1 2 Xi !
8e0; e1 2 Evi: e0 2 Xi ^ e1 2 Xi ! :(e0#e1)
^
      </p>
      <p>e0 2 Xi
e02(Gi 1)!fe1g
Here R! represents the function mapping a set to its image set through a given
relation R. We note that, since Gi represents a relation as a set of ordered pairs,
Gi 1 is the inverse relation. Further, recall that a con guration Xi is a trace
exactly when it is maximal, that is,
8Y</p>
      <p>
        Evi satisfying (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ){(
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) ; Y
      </p>
      <p>
        Xi:
Now, the quanti cation appearing in (
        <xref ref-type="bibr" rid="ref3">3</xref>
        ) is not directly expressible, because
a quanti cation over relations is second-order logic, and any SMT-LIB theory
is within rst-order logic. The mathematical language used in (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ), (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) and
3 allows us to convey ideas to the reader in a more compact and, hopefully,
more understandable way than crude SMT-LIB code would. However, it also
hides di culties such the one just explained, arising from the gap between the
expressiveness of rst-order logic and that of standard mathematical notation.
This problem can have several solutions: in [6] we used bit-vectors to represent sets
and, in [7] we showed condition (
        <xref ref-type="bibr" rid="ref3">3</xref>
        ) to be equivalent to the following, rst-order
ones:
8e1 2 EvinXi: 9e0 2 Evi:
      </p>
      <p>((e0#e1 ^ e0 2 Xi) _
((e0; e1) 2 Gi ^ e0 2= Xi))
This allows us to formulate the problem of trace nding in SMT-LIB.
The next step is to de ne a measure of concurrency which will allow us to execute
a given trace (or con guration) without violating the constraints given by the
causality and con ict relations. Since any con guration is con ict-free, we only
need to focus on not violating the causality relation when executing it.
1. Consider that every event in the con guration has a start time and an end
time, with the latter not smaller than the former;
2. Any two ordered events should not overlap;
3. Any successor (according to ! ) of an event should happen after it.</p>
      <p>These conditions normally leave quite some freedom in the arrangement of the
events for an execution as shown in Fig. 2 for a con guration X1. A conceptually
simple approach (commonly referred to as interleaving or sequentialising) is to
nd a linear order respecting ! : this means nding an order morphism from the
con guration (seen as equipped with the partial order ! ) to Z (equipped with
its standard linear, total order). This way of handling execution is particularly
well-suited to an SMT solver due to its awareness of integer arithmetics, and is
the one we adopted in [7].</p>
      <p>
        This approach is usually contrasted, in the literature, with the true concurrent
one, whereby the restriction given by this linearisation is dropped, with an
additional number of possible execution arrangements becoming possible which
still comply with the three conditions above. This amounts to permitting to take
advantage of possible parallelism, which gets lost in the interleaving process: in
the latter approach, compliance with conditions (
        <xref ref-type="bibr" rid="ref1">1</xref>
        )-(
        <xref ref-type="bibr" rid="ref3">3</xref>
        ) is attained by ruling out
overlaps between any pair of distinct events, thereby including concurrent events
(recall that two events are concurrent if they are not related by ! nor by #).
      </p>
      <p>We now introduce an SMT way of
{ modelling this increased choice of possible executions for the traces selected
in the previous subsection and
{ ranking them according to their e ciency, that is, their degree of concurrency.
It will rely on two functions, s and t, de ned on all the events, and returning the
time each of them starts and ends, respectively.</p>
      <p>
        The rst constraint we impose on them is that any single event must respect
time:
(
        <xref ref-type="bibr" rid="ref5">5</xref>
        )
(
        <xref ref-type="bibr" rid="ref6">6</xref>
        )
8e 2 Evi:t (e) s (e) = 2 (e) :
      </p>
      <p>Let us recall that we assume that our event structures are nite so that,
in particular, we can de ne a function pi over the set of non-source nodes for
the directed graph ran Gi returning, for each such node, its parent node in the
considered trace Xi which terminates last:
8e1 2 ran Gi:
(</p>
      <p>pi (e1) 2 Xi \ Gi 1! (fe1g)
8e0 2 Xi \ Gi 1! (fe1g) : t (pi (e1))
t (e0) :
We have only one requirement to impose on p:
8e 2 ran Gi: s (e)
t (p (e)) :
This last requirement can be tightened to 8e 2 ran Gi: s (e) = t (p (e)) in case we
are seeking for executions without idle times between subsequent events.</p>
      <p>
        The formulas introduced in this section capture the linearly interleaved (or
sequentialised) executions we described above, but add more possible executions.
Intuitively, the former are the least possible concurrent execution, and in this
sense they are also the least e cient ones. To make this kind of comparison more
precise, we introduce a measure to rank all the di erent possible executions. This
will give a metric, or distance, between executions according to their degree of
concurrency. Consider, for a given Gi, the event which terminates last in a given
execution of the trace Xi, denoted zi; it can be described by the formulas
zi 2 Xi \ (ran Gin dom Gi)
8e 2 Xi \ (ran Gin dom Gi) : t (zi)
t (e) :
(
        <xref ref-type="bibr" rid="ref7">7</xref>
        )
(
        <xref ref-type="bibr" rid="ref8">8</xref>
        )
(
        <xref ref-type="bibr" rid="ref9">9</xref>
        )
We will consider an execution of Xi less concurrent than another whenever t (zi)
is larger for the former than for the latter. In this sense, we can use, e.g., an
optimising SMT solver [17] to nd the most concurrent execution by simply
asking it to minimise the quantity t (zi). In particular, this de nition of amount
of concurrency can be reconciled with the intuition that sequentialised executions
are the least concurrent ones: the number above will not be maximum for such
executions, given a xed Xi. This fact is also practically useful: since we know
that a linearised execution has maximal duration, and since such duration is
obviously bounded by the sum of all the event durations, we can pass this bound
as an assertion to the SMT solver to reduce its search space when computing a
generic execution.
      </p>
      <p>Finally, among the several possible traces captured by the assertions of
Section 3.1, we want to select the best one (see the example in Section 2). To do
this, we consider one generic trace Xi for each Gi, and describe which labels are
active at a given time y, via the function l:
l (y) =</p>
      <p>[
e2Si Xi</p>
      <p>b ( (e)) (y 2 [s (e) ; t (e)[):</p>
      <p>Here, (e) describes the selected label for the event e (which is imposed to
be in the set of allowed labels through an assertion we omit here), and b(j) sets
the j-th bit in a bit-vector of length equal to the overall number of all labels.
Therefore, l(y) is a bit-vector whose 1-bits correspond exactly to the labels active
at time y, because the term in the rightmost pair of brackets lters exactly the
active events (note that our convention is that the when the ending time t (e) of
an event ticks, we consider the event instantly o , so that the range in that term
is right-open). We nally ask the SMT solver to maximise
maxift(zi)g</p>
      <p>X
where is a function returning the interaction between the labels denoted by
l (t).
4</p>
    </sec>
    <sec id="sec-4">
      <title>Veri cation</title>
      <p>
        We have seen in Section 3.1 how the gap in expressiveness between standard
mathematical notation and the rst-order language of SMT solvers can cause
di culties when translating a mathematical problem for its computation in an
SMT setting. In some cases, reformulations are needed (recall how we passed from
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) and (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) to (
        <xref ref-type="bibr" rid="ref4">4</xref>
        ) earlier). Even when the translation is more straightforward,
several choices a ect the nal SMT code passed to the solver. One common
choice is to instantiate universal quanti ers appearing in formulas exploiting
the fact that they quantify over nite domains which are easy to compute
separately, because this can considerably help the solver. For example, (
        <xref ref-type="bibr" rid="ref9">9</xref>
        ) features
a universal quanti er ranging over a subset of the sinks of Gi, which is easily
computed, for non-trivial graphs, as the set-theoretical di erence between the
set all children of some node of Gi and the set of all parents of some node
of Gi. Performing this computation before invoking the SMT solver helps by
removing a universal quanti er and by carefully restricting the possible cases
over which it is instantiated; this kind of pre-processing is done often to obtain
better performing SMT problems, but comes with a signi cant drawback: the
SMT code thus obtained becomes exceedingly verbose, and, typically, di cult to
peruse. In other words, the nal SMT code usually looks extremely di erent (and
extremely longer) than the original pen-and-paper mathematical formulation of
the problem; in our case, we can compare the concise mathematical formulation
in Section 3 with the nal SMT code we e ectively run for a simple example, a
small (necessarily truncated) excerpt of which is in Listing 1.1, representing (
        <xref ref-type="bibr" rid="ref6">6</xref>
        )
and (
        <xref ref-type="bibr" rid="ref7">7</xref>
        ).
      </p>
      <p>
        Listing 1.1. SMT macro for (
        <xref ref-type="bibr" rid="ref6">6</xref>
        ) and (
        <xref ref-type="bibr" rid="ref7">7</xref>
        ), in the case of a small example (excerpt)
( define fun trueConcurrencySMT ( ) Bool
( let ( ( $x206 ( and true (=&gt; ( isSelected g0 )
(&gt;= ( endTime ( lastParent g1 ) ) ( endTime g0 ) ) ) ) ) )
( let ( ( $x212 ( and ( or false ( and ( isSelected g0 )
(= ( lastParent g1 ) g0 ) ) ) $x206 (= ( idleTime g1 )
( ( startTime g1 ) ( endTime ( lastParent g1 ) ) ) )
(&gt;= ( idleTime g1 ) 0 ) ) ) ) ( let ( ( $x165 ( isSelected g1 ) ) )
( let ( ( $x195 ( and ( or false ( and $x165
(= ( lastParent g2 ) g1 ) ) ) ( and true (=&gt; $x165
(&gt;= ( endTime ( lastParent g2 ) ) ( endTime g1 ) ) ) )
(= ( idleTime g2 ) ( ( startTime g2 ) ( endTime ( lastParent g2 ) ) ) )
(&gt;= ( idleTime g2 ) 0 ) ) ) ) ( let ( ( $x142 ( isSelected g2 ) ) )
( let ( ( $x180 ( and ( or false ( and $x165 (= ( lastParent g3 ) g1 ) ) )
( and true (=&gt; $x165 (&gt;= ( endTime ( lastParent g3 ) ) ( endTime g1 ) ) ) )
(= ( idleTime g3 ) ( ( startTime g3 ) ( endTime ( lastParent g3 ) ) ) )
(&gt;= ( idleTime g3 ) 0 ) ) ) )
( let ( ( $x146 ( isSelected g3 ) ) ) [ . . . ]
      </p>
      <p>The striking di erence between them is clearly a problem when examining
the SMT code and in particular when this code needs to have some degree of
con dence in the result it produces.</p>
      <p>However, nobody prevents us from keeping two SMT codes: one (let us call it
code A) closer to the mathematical formulation (and likely less e cient), and
the other (code B) which underwent a series of transformations as hinted just
above. If the SMT solver returns no models satisfying one code and not the
other, then we can be con dent about their equivalence, assuming correctness of
the solver. But, more than that, code A is usually compact enough to be easily
formulated within a theorem prover whose foundations entail the rst-order logic
(plus arithmetics) featured in an SMT solver, such as Isabelle/HOL [20]. And,
if we manage to do that, we can use existing SMT code generators from within
the theorem prover, which means that the de nitions formulated in the theorem
provers can be used both to prove their correctness and to generate code A. On
top of that, we can arbitrarily introduce intermediate equivalent codes between A
and B, if this eases the veri cation process. We now see a particular application
of this general veri cation mechanism.</p>
      <p>In Isabelle/HOL, we can introduce the following function:
abbreviation " trueConcur01 ' G X lastParent startTime endTime
== 8 child . ( X child &amp; ( 9 parent . G parent child ) ) !
( X ( lastParent child ) &amp; ( G ( lastParent child ) child ) &amp;
( 8 parent . ( X parent &amp; G parent child ) !</p>
      <p>endTime ( lastParent child ) endTime parent ) &amp;
startTime ( child ) endTime ( lastParent ( child ) ) ) "</p>
      <p>
        It is carefully crafted to be equivalent, as the one in listing 1.1, to (
        <xref ref-type="bibr" rid="ref6">6</xref>
        ) and (
        <xref ref-type="bibr" rid="ref7">7</xref>
        )
and to only feature mathematical objects available in the rst-order logic of
an SMT solver; this means no sets, no higher-order functions, no lists, etc:
everything is represented as functions and predicates (for example, instead of
writing child 2 X, we write X child, where X is a predicate, or boolean function).
This allows us, on one hand, to export it to an SMT constant (let us call it
trueConcurrencyIsabelle) taking advantage of the translator provided by Isabelle's
Sledgehammer tool [4], and to check its equivalence to trueConcurrencySMT
inside an SMT solver (expecting the answer unsat):
( assert ( or
( and trueConcurrencySMT ( not trueConcurrencyIsabelle ) )
( and ( not trueConcurrencySMT ) ( trueConcurrencyIsabelle ) )
)
)
      </p>
      <p>
        On the other hand, the Isabelle de nition can be proved correctness theorems
about, thereby granting automatically that such correctness proofs carry over
to trueConcurrencySMT. Let us focus on a basic property we expect from any
execution, namely that expressed by requirements (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) and (
        <xref ref-type="bibr" rid="ref3">3</xref>
        ) of Section 3.2. The
rst step is usually to formulate the SMT-friendly Isabelle de nition above into
an equivalent one, but possibly more convenient when coming to formal proofs.
This does not compromise the veri cation e orts because these new de nitions
can be provided with formal theorems proving their equivalence to the original
ones. In this case, we will use
abbreviation
" TrueConcur00 ' P X lastParent startTime endTime ==
8 child 2 X \ ( Range P ) . ( lastParent ( child ) 2 X \
immediatePredecessors ' P f child g &amp;
endTime ( lastParent ( child ) )
      </p>
      <p>Max ( endTime ` ( X \ ( immediatePredecessors ' P f child g ) ) ) &amp;
startTime ( child ) ge endTime ( lastParent ( child ) ) ) " ,
all the relations have been expressed as sets of ordered pairs, the immediate
causality relation G (corresponding to !) has been substituted by its
transitivere exive closure P (corresponding to ! ), and the in x operator ` takes the
image of a set through a function. We note that the custom-de ned operator
immediatePredecessors only makes sense for discrete relations; this is not a
problem here, because we are in a nite setting. We omit the relevant equivalence
proof, and only state the main correctness formal theorem:
theorem fixes startTime : : "_ =&gt; nat " assumes " wf ( strict P ) "
" wf ( strict ( P ^ 1))" " atomicTimeArrow P startTime endTime "
" isPo P"
" TrueConcur00 ' P X lastParent startTime endTime " shows
"f e2 2 X \ events P . e2 j
( 9 e0 2 X \ ( strict P )^ 1 ` `f e2 g .</p>
      <p>startTime ( e2)&lt;endTime ( e0 ))g=fg"</p>
      <p>
        The thesis (introduced by the shows keyword) states that the set of the events
in X possibly admitting a predecessor ending after they start is empty (please
note that (strict P)^ 1 is the strict causality relation reversed, and ``{e2}
takes all the images of the singleton {e2} through it, thereby meaning all the
predecessors of e2 through P). Between the keywords assumes and shows there are
ve hypotheses. atomicTimeArrow formalises requirement (
        <xref ref-type="bibr" rid="ref5">5</xref>
        ), while isPo' ensures
that P is a partial order. Finally, wf is a predicate returning whether or not a given
relation is well-founded, meaning that it supports trans nite induction [11]. Since
this property is trivially entailed by niteness, we showed that our correctness
result holds in a more general setting than the one we employ it on.
      </p>
      <p>To keep this generality, we had to prove several additional formal theorems
about well-foundedness, some of independent interest. The following one, for
example, is fundamental to the previous one, and states the intuitive idea that
between two elements related by a well-founded order relation P, there must be a
third one which is immediately related to one of them:
lemma mm05ll : assumes " reflex P" " trans P"
" antisym P" " wf ( strict P ) " " ( x , z ) in P"
"z 6= x" shows
"9 y . ( ( y , z ) 2 P &amp; y 2 next1 P fx g ) " .</p>
      <p>Here, next1 P {x} denotes the immediate successors of x according to the
order relation P: the lemma states that for well-ordered relations, this function
yields what is expected.</p>
      <p>To recapitulate, our general approach to verifying SMT-LIB code proposes a
chain of equivalent de nitions, with one end expressed in Isabelle/HOL and the
other directly in SMT-LIB. Each of them is proven equivalent to the next either
using the SMT solver or a formal Isabelle proof. At one point in the chain, we
pass from an Isabelle de nition to an SMT-LIB one: here, we trust Sledgehammer
to produce a rst-order SMT-LIB de nition from an Isabelle/HOL de nition
restricted to the rst-order fragment of HOL.</p>
      <p>This very last passage raises a key question: why should we trust Sledgehammer
in building the formal proofs of our SMT-LIB code? After all, Isabelle itself
does not trust Sledgehammer, but only uses its results to obtain guidance from
various solvers, with the nal proof thus obtained re-checked for correctness
inside Isabelle.</p>
      <p>The answer starts from a basic observation: ultimately, veri cation is about
reducing the amount of code to be trusted. Ideally, to a core small enough to
be uncontroversial (see the de Bruijn criterion [2] which, nevertheless, implies
trusting software/hardware below small core). But even reducing the trusted code
from the extremely verbose SMT-LIB code to a limited amount of Sledgehammer's
ML code is desirable, for various reasons. First, the latter stays the same when
di erent SMT-LIB problems are considered. Second, possible soundness problems
are linked to the fact that higher-order logic is much richer than SMT-LIB
rst-order logic: in our approach, this issue is greatly mitigated by the fact
that we use Sledgehammer translator for code (e.g., trueConcur01') which only
uses a rst-order logic fragment of HOL, while the type-richer de nitions are
con ned to duplicate Isabelle de nitions (e.g., trueConcur00') which are used
for theorem proving and which are proved equivalent, within Isabelle, to the
rst-order de nitions seen by the translator generating SMT code. Third, the
limited portion of the SMT translator we need has had much more exposure
and testing than any particular SMT-LIB code that we would need to trust
without this approach. Fourth, ML (the functional, higher order language in
which Isabelle and Sledgehammer are implemented) is arguably more readable
than SMT-LIB. Fifth, contrary to the Isabelle case, we need to trust the SMT
solver anyway because we are not using it to obtain proofs (which Isabelle
can then reconstruct), but computations. And the size and complexity of the
Sledgehammer implementation is vastly negligible in comparison.
5</p>
    </sec>
    <sec id="sec-5">
      <title>Conclusions</title>
      <p>We presented an SMT formulation for nding optimal true concurrent traces
of execution. The typical issue of the SMT code getting rapidly unreadable is
addressed by using a theorem prover to generate equivalent SMT assertions and
then to prove correctness theorem about the latter. In previous work, we explored
the problem of searching optimal traces of executions subject to linear interleaving.
Here, we provided a novel approach to use an SMT solver for nding executions
of optimal traces with a varying degree of concurrency. Future work could see
the application of a similar approach to resource scheduling and optimisation
problems.</p>
      <p>This paper also contributes a way of characterising and computing a notion
of degree of parallelism for arbitrary computations. Our de nition has some
advantages over existing ones: contrary to [22], it does not require an empirical
implementation on given hardware in order to analyse and compute the degree of
parallelism of a given algorithm; it does not require to express the algorithm in a
speci c language, as in [21]; it reduces to computing a numerical value through a
simple procedure, rather than introducing de nitions (see functionals in Sections
1 and 2 of [21]) which are very useful for abstract analysis but, to the best of our
knowledge, currently have no concrete implementation.</p>
      <p>To make our work more useful, we plan to introduce additional metrics:
besides the degree of concurrency, an user could nd useful to have further ways
of comparing possible executions. For example, by considering how many events
two possible solutions have in common, and what is their time distance.</p>
      <p>We also plan to investigate possible connections between the SMT
formalisation proposed here and other framework formalising concepts related to the ones
emerging in this paper; for example, in Event Calculus [13], events and time are
central.</p>
      <p>Finally, we will continue exploiting the interplay between SMT solvers and
theorem provers. As shown in the current and previous works, this interaction
can be quite general and fertile. However, it has to be adapted on a case by case
basis. This could be made easier by providing systematic, generic procedures to
automate it at least in its most common use cases, for example the instantiation
of a universal quanti er, which we faced in Section 4.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>Paolo</given-names>
            <surname>Baldan</surname>
          </string-name>
          and
          <string-name>
            <given-names>Silvia</given-names>
            <surname>Crafa</surname>
          </string-name>
          .
          <article-title>A logic for true concurrency</article-title>
          .
          <source>In International Conference on Concurrency Theory</source>
          , pages
          <volume>147</volume>
          {
          <fpage>161</fpage>
          . Springer,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>Henk</given-names>
            <surname>Barendregt</surname>
          </string-name>
          and
          <string-name>
            <given-names>Herman</given-names>
            <surname>Geuvers</surname>
          </string-name>
          .
          <article-title>Proof-assistants using dependent type systems</article-title>
          .
          <source>Handbook of automated reasoning</source>
          ,
          <volume>2</volume>
          :
          <fpage>1149</fpage>
          {
          <fpage>1238</fpage>
          ,
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Clark</surname>
            <given-names>Barrett</given-names>
          </string-name>
          , Aaron Stump, and
          <string-name>
            <given-names>Cesare</given-names>
            <surname>Tinelli</surname>
          </string-name>
          .
          <source>The SMT-LIB Standard: Version 2</source>
          .0. In A. Gupta and D. Kroening, editors,
          <source>Proceedings of the 8th International Workshop on Satis ability Modulo Theories (Edinburgh, UK)</source>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>Jasmin</given-names>
            <surname>Christian</surname>
          </string-name>
          <string-name>
            <surname>Blanchette</surname>
          </string-name>
          , Sascha Bohme, and Lawrence C Paulson.
          <article-title>Extending Sledgehammer with SMT solvers</article-title>
          .
          <source>Journal of automated reasoning</source>
          ,
          <volume>51</volume>
          (
          <issue>1</issue>
          ):
          <volume>109</volume>
          {
          <fpage>128</fpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>J. K. F. Bowles</surname>
            and
            <given-names>M. B.</given-names>
          </string-name>
          <string-name>
            <surname>Caminati</surname>
          </string-name>
          .
          <article-title>Balancing prescriptions with constraint solvers</article-title>
          . In P. Lio and P. Zuliani, editors,
          <source>Automated Reasoning for Systems Biology and Medicine</source>
          , volume
          <volume>30</volume>
          of Computational Biology, pages
          <volume>243</volume>
          {
          <fpage>267</fpage>
          . Springer,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>J. K. F. Bowles</surname>
            and
            <given-names>M. B.</given-names>
          </string-name>
          <string-name>
            <surname>Caminati</surname>
          </string-name>
          .
          <article-title>An integrated approach to a combinatorial optimisation problem</article-title>
          .
          <source>In Integrated Formal Methods (iFM</source>
          <year>2019</year>
          ), volume
          <volume>11918</volume>
          <source>of LNCS</source>
          , pages
          <volume>284</volume>
          {
          <fpage>302</fpage>
          ,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>J. K. F. Bowles</surname>
            and
            <given-names>M. B.</given-names>
          </string-name>
          <string-name>
            <surname>Caminati</surname>
          </string-name>
          .
          <article-title>Correct composition in the presence of behavioural con icts and dephasing</article-title>
          .
          <source>Science of Computer Programming</source>
          ,
          <volume>185</volume>
          ,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>Manuel</given-names>
            <surname>Clavel</surname>
          </string-name>
          , Francisco Duran, Steven Eker, Patrick Lincoln, Narciso Mart - Oliet, Jose Meseguer, and
          <string-name>
            <given-names>Carolyn</given-names>
            <surname>Talcott</surname>
          </string-name>
          .
          <article-title>All About Maude-A High-Performance Logical Framework: How to Specify, Program, and Verify Systems in Rewriting Logic</article-title>
          , volume
          <volume>4350</volume>
          . Springer,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9. Francisco Duran, Camilo Rocha, and
          <article-title>Gwen Salaun. Computing the parallelism degree of timed bpmn processes</article-title>
          .
          <source>In Federation of International Conferences on Software Technologies: Applications and Foundations</source>
          , pages
          <volume>320</volume>
          {
          <fpage>335</fpage>
          . Springer,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Vashti C Galpin</surname>
          </string-name>
          .
          <article-title>Equivalence semantics for concurrency: comparison and application</article-title>
          .
          <year>1998</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <given-names>Egbert</given-names>
            <surname>Harzheim</surname>
          </string-name>
          .
          <source>Ordered sets</source>
          , volume
          <volume>7</volume>
          . Springer Science &amp; Business
          <string-name>
            <surname>Media</surname>
          </string-name>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Joost-Pieter</surname>
            <given-names>Katoen</given-names>
          </string-name>
          , Christel Baier, and Diego Latella.
          <article-title>Metric semantics for true concurrent real time</article-title>
          .
          <source>Theoretical Computer Science</source>
          ,
          <volume>254</volume>
          (
          <issue>1-2</issue>
          ):
          <volume>501</volume>
          {
          <fpage>542</fpage>
          ,
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <given-names>Robert</given-names>
            <surname>Kowalski</surname>
          </string-name>
          and
          <string-name>
            <given-names>Marek</given-names>
            <surname>Sergot</surname>
          </string-name>
          .
          <article-title>A logic-based calculus of events</article-title>
          .
          <source>In Foundations of knowledge base management</source>
          , pages
          <volume>23</volume>
          {
          <fpage>55</fpage>
          . Springer,
          <year>1989</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14. J. Kuster-Filipe.
          <article-title>Modelling concurrent interactions</article-title>
          .
          <source>Theoretical Computer Science</source>
          ,
          <volume>351</volume>
          :
          <fpage>203</fpage>
          {
          <fpage>220</fpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          15.
          <string-name>
            <surname>Kamal</surname>
            <given-names>Lodaya</given-names>
          </string-name>
          , Madhavan Mukund, Ramaswamy Ramanujam, and PS Thiagarajan.
          <article-title>Models and logics for true concurrency</article-title>
          .
          <source>Sadhana</source>
          ,
          <volume>17</volume>
          (
          <issue>1</issue>
          ):
          <volume>131</volume>
          {
          <fpage>165</fpage>
          ,
          <year>1992</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          16.
          <string-name>
            <surname>Philipp</surname>
          </string-name>
          J Meyer, Javier Esparza, and
          <article-title>Hagen Volzer. Computing the concurrency threshold of sound free-choice work ow nets</article-title>
          .
          <source>In International Conference on Tools and Algorithms for the Construction and Analysis of Systems</source>
          , pages
          <fpage>3</fpage>
          <lpage>{</lpage>
          19. Springer,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          17. L. De Moura and
          <string-name>
            <surname>N.</surname>
          </string-name>
          <article-title>Bj rner. Z3: An e cient SMT solver</article-title>
          .
          <source>In TACAS</source>
          <year>2008</year>
          , volume
          <volume>4963</volume>
          <source>of LNCS</source>
          , pages
          <volume>337</volume>
          {
          <fpage>340</fpage>
          . Springer,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          18.
          <string-name>
            <surname>M. Nielsen</surname>
            ,
            <given-names>G.</given-names>
            Plotkin, and G.
          </string-name>
          <string-name>
            <surname>Winskel</surname>
          </string-name>
          .
          <article-title>Petri nets, event structures and domains, part i</article-title>
          .
          <source>TCS</source>
          ,
          <volume>13</volume>
          :
          <fpage>85</fpage>
          {
          <fpage>108</fpage>
          ,
          <year>1981</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          19.
          <string-name>
            <given-names>T.</given-names>
            <surname>Nipkow</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L. C.</given-names>
            <surname>Paulson</surname>
          </string-name>
          , and M. Wenzel. Isabelle/HOL |
          <article-title>A Proof Assistant for Higher-Order Logic</article-title>
          , volume
          <volume>2283</volume>
          <source>of LNCS</source>
          . Springer,
          <year>2002</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          20.
          <string-name>
            <given-names>Tobias</given-names>
            <surname>Nipkow</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L. C.</given-names>
            <surname>Paulson</surname>
          </string-name>
          , and Markus Wenzel. Isabelle/HOL:
          <article-title>a proof assistant for higher-order logic</article-title>
          . Springer-Verlag, London, UK,
          <year>2002</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          21.
          <string-name>
            <given-names>V</given-names>
            <surname>Yu</surname>
          </string-name>
          <article-title>Sazonov</article-title>
          .
          <article-title>Degrees of parallelism in computations</article-title>
          .
          <source>In International Symposium on Mathematical Foundations of Computer Science</source>
          , pages
          <volume>517</volume>
          {
          <fpage>523</fpage>
          . Springer,
          <year>1976</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          22.
          <string-name>
            <given-names>K</given-names>
            <surname>Sevcik</surname>
          </string-name>
          .
          <article-title>Characterizations of parallelism in applications and their use in scheduling</article-title>
          .
          <source>Perform</source>
          . Eval.,
          <volume>17</volume>
          :
          <fpage>171</fpage>
          {
          <fpage>180</fpage>
          ,
          <year>1989</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          23. G. Winskel.
          <article-title>Event structure semantics for CCS and related languages</article-title>
          . In M. Nielsen and E.M. Schmidt, editors,
          <source>Automata, Languages, and Programming</source>
          , volume
          <volume>140</volume>
          <source>of LNCS</source>
          , pages
          <volume>561</volume>
          {
          <fpage>576</fpage>
          . Springer,
          <year>1982</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          24. G. Winskel and
          <string-name>
            <given-names>M.</given-names>
            <surname>Nielsen</surname>
          </string-name>
          .
          <article-title>Models for Concurrency</article-title>
          . In S. Abramsky,
          <string-name>
            <given-names>D.M.</given-names>
            <surname>Gabbay</surname>
          </string-name>
          , and T.S.E. Maibaum, editors,
          <source>Handbook of Logic in Computer Science</source>
          , Vol.
          <volume>4</volume>
          ,
          <string-name>
            <surname>Semantic</surname>
            <given-names>Modelling</given-names>
          </string-name>
          , pages
          <volume>1</volume>
          {
          <fpage>148</fpage>
          . Oxford Science Publications,
          <year>1995</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>