How to generate all possible linear extensions (i.e., topological sortings) of a partial order?

23 views
Skip to first unread message

hengx...@gmail.com

unread,
Apr 6, 2021, 5:20:56 AM4/6/21
to tlaplus
Hi All,

I am writing a TLA+ specification of a consistency model which is defined based on relations. I need to generate all possible linear extensions (i.e., topological sortings) of a partial order.

The following TLA+ code can be found at https://github.com/hengxin/tla-causal-consistency/blob/main/RelationUtils.tla.

I am able to generate an arbitrary linear extension of a partial order as follows (I use this algorithm: https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm):

AnyLinearExtension.png

where Minimal(R, S) returns the set of minimal elements of S given relation R,
and LeftRestriction(R, m) returns the set of pairs whose first element is m.

However, I failed to generate all possible linear extensions of a partial order:

AllLinearExtensions.png

TLC reports an error: Unknown operator 'm'.

So how to generate all possible linear extensions of a partial order?

Best regards,
Hengfeng Wei (hengxin)

Stephan Merz

unread,
Apr 6, 2021, 6:19:36 AM4/6/21
to tla...@googlegroups.com
Hello,

I am not trying to understand your definition but simply suggest how to make it syntactically legal. In the syntactic form

  { e : x \in S, y \in T }

the identifier x is not allowed to occur in S or T (cf. Specifying Systems, section 16.1.6). You must therefore use a nested set comprehension as in

...
ELSE LET Extend(m) == { <<m>> \o l : l \in LinearExtensionsUtil(...) }
     IN  UNION { Extend(m) : m \in Minimal(...) }

(Of course, you do not actually need to use a LET but can also replace the use of Extend in the body by its definition. However, I find it easier to read in this way.)

Stephan


On 6 Apr 2021, at 11:20, hengx...@gmail.com <hengx...@gmail.com> wrote:

Hi All,

I am writing a TLA+ specification of a consistency model which is defined based on relations. I need to generate all possible linear extensions (i.e., topological sortings) of a partial order.

The following TLA+ code can be found at https://github.com/hengxin/tla-causal-consistency/blob/main/RelationUtils.tla.

I am able to generate an arbitrary linear extension of a partial order as follows (I use this algorithm: https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm):

<AnyLinearExtension.png>

where Minimal(R, S) returns the set of minimal elements of S given relation R,
and LeftRestriction(R, m) returns the set of pairs whose first element is m.

However, I failed to generate all possible linear extensions of a partial order:

<AllLinearExtensions.png>

TLC reports an error: Unknown operator 'm'.

So how to generate all possible linear extensions of a partial order?

Best regards,
Hengfeng Wei (hengxin)

--
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/52111fcc-e8df-469e-8894-c113ae398056n%40googlegroups.com.
<AnyLinearExtension.png><AllLinearExtensions.png>

hengx...@gmail.com

unread,
Apr 6, 2021, 7:06:00 AM4/6/21
to tlaplus
Hi Stephan,

Great thanks. It works (also replace "<<>>" line 13 by "{<<>>}").

Best regards,
Hengfeng Wei (hengxin)

Reply all
Reply to author
Forward
0 new messages