Defining Cardinality with TLA

64 views
Skip to first unread message

marta zhango

unread,
Apr 25, 2024, 4:36:13 PMApr 25
to tlaplus
How can I define the cardinality of a set as the number of elements in a set S
using the notation |S| using TLA.

marta zhango

unread,
Apr 25, 2024, 5:17:00 PMApr 25
to tlaplus
Like this for instance ?

Cardinality (S) = |S| == Count ( e \in S )

marta zhango

unread,
Apr 25, 2024, 7:53:34 PMApr 25
to tlaplus
Have thought something like this too

Cardinality(set) == (+ e \in DOMAIN set: IF set[e] THEN 1 ELSE 0)

Markus Kuppe

unread,
Apr 25, 2024, 7:55:57 PMApr 25
to tla...@googlegroups.com

marta zhango

unread,
Apr 25, 2024, 8:22:33 PMApr 25
to tlaplus
Is the line

IN  CS[S]

part of the definition of cardinality ?

Stephan Merz

unread,
Apr 26, 2024, 12:37:27 AMApr 26
to tla...@googlegroups.com
As Markus pointed out, cardinality of finite sets is defined in a standard module of TLA+. A collection of lemmas about finite sets and cardinality, useful for actually reasoning about these notions, is available at https://github.com/tlaplus/tlapm/blob/main/library/FiniteSetTheorems.tla (included in the distribution of TLAPS).

Stephan

--
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/f2c82e65-92e1-4c06-b61a-dfd78d19a017n%40googlegroups.com.

Stephan Merz

unread,
Apr 26, 2024, 12:39:07 AMApr 26
to tla...@googlegroups.com
P.S.: Proofs of these theorems checked by TLAPS are given in https://github.com/tlaplus/tlapm/blob/main/library/FiniteSetTheorems_proofs.tla.

marta zhango

unread,
Apr 26, 2024, 4:11:55 AMApr 26
to tlaplus
That is what I needed to see as I am new to all this, with no idea where to start.

Lee

unread,
Apr 26, 2024, 7:17:46 AMApr 26
to tlaplus
Hi Marta,

If you want to know more about Cardinality please see this page by Hillel Wayne (https://learntla.com/core/operators.html?highlight=cardinality) . Since you said you're new, I can also recommend reading his entire tutorial page and blog posts in addition to his book (https://www.amazon.se/-/en/Hillel-Wayne/dp/1484238281). Other resources when you're done working these are:

- Specifying Systems by Leslie Lamport (which is only TLA+) 
- http://lamport.azurewebsites.net/tla/learning.html - great way to get into how to think about this

Regards
Lee

marta zhango

unread,
Apr 26, 2024, 7:54:26 AMApr 26
to tlaplus
How can I declare or define a symbol to mean Cardinality such as |S|

Something like this maybe, to say that |S| means or in equivalent to Cardinality(S)

|S| == Cardinality (S)

Does one also use the keyword LET or something else ?

Felipe Oliveira Carvalho

unread,
Apr 26, 2024, 10:35:57 AMApr 26
to tla...@googlegroups.com
That's not currently possible because the TLA+ doesn't support
user-defined syntax constructs this advanced.

--
Felipe
> To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/a98df958-c39e-4597-bcab-f08e8b5040e9n%40googlegroups.com.

Hillel Wayne

unread,
Apr 26, 2024, 12:19:34 PMApr 26
to tla...@googlegroups.com

You can define S^#, though!

S^# == Cardinality(S)

H

marta zhango

unread,
Apr 26, 2024, 5:39:04 PMApr 26
to tlaplus
Ok, So I can define.  But just not with | 

Is that right ?
Reply all
Reply to author
Forward
0 new messages