# Really Basic Question

**URL:** https://alloytools.discourse.group/t/really-basic-question/171
**Category:** Questions
**Created:** [July 28, 2021, 1:22pm UTC](https://alloytools.discourse.group/t/really-basic-question/171 "2021-07-28T13:22:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![OnorioCatenacci](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/onoriocatenacci/32/65_2.png) [@OnorioCatenacci](https://alloytools.discourse.group/u/OnorioCatenacci)
#### Post date: [July 28, 2021, 1:22pm UTC](https://alloytools.discourse.group/t/really-basic-question/171/1 "2021-07-28T13:22:24Z")

</div>

So I’m looking at the online tutorial again–when you’re teaching yourself it’s wise to review materials four or five times till you’re sure you’ve mastered them.

I’m trying to understand the

sig FSObject  
{  
parent: lone Dir  
}

signature in terms of what I’ve seen illustrated about sets before. Hence my question–is this the correct understanding of the set mappings associated with that signature?

 ![AlloyTutorial1](https://global.discourse-cdn.com/free1/uploads/alloytools/original/1X/34fd36f405604f7d073db1bd8b0317d424b56b8e.jpeg)

---

<div class="post-metadata">

### Author: ![grayswandyr](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/grayswandyr/32/17_2.png) [@grayswandyr](https://alloytools.discourse.group/u/grayswandyr)
#### Post date: [July 29, 2021, 7:51am UTC](https://alloytools.discourse.group/t/really-basic-question/171/2 "2021-07-29T07:51:37Z")

</div>

It is indeed: every `FSObject` is mapped to at most one `Dir`, which means some `FSObject`s may not be mapped to anything (e.g. `C` in your sketch). Computer scientists usually call this a _partial function_ (while mathematicians would only call it a _function_). In UML, this corresponds to a `0..1` multiplicity from `FSObject` to `Dir`.

If every `FSObject` is mapped to _exactly_ one `Dir`, then computer scientists usually call this a _total function_ while mathematicians will often call this a _map_. In UML, this corresponds to a `1` multiplicity from `FSObject` to `Dir`.

---

<div class="post-metadata">

### Author: ![OnorioCatenacci](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/onoriocatenacci/32/65_2.png) [@OnorioCatenacci](https://alloytools.discourse.group/u/OnorioCatenacci)
#### Post date: [July 29, 2021, 12:47pm UTC](https://alloytools.discourse.group/t/really-basic-question/171/3 "2021-07-29T12:47:48Z")

</div>

Thanks for taking the time to reply and to confirm my understanding! Also thanks for taking a moment to help my vocabulary!

---

<div class="post-metadata">

### Author: ![OnorioCatenacci](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/onoriocatenacci/32/65_2.png) [@OnorioCatenacci](https://alloytools.discourse.group/u/OnorioCatenacci)
#### Post date: [July 29, 2021, 1:18pm UTC](https://alloytools.discourse.group/t/really-basic-question/171/4 "2021-07-29T13:18:15Z")

</div>

Looking a bit [further on in the tutorial](http://alloytools.org/tutorials/online/frame-FS-3.html) there’s a slightly more complicated relation that I want to insure I’m mapping correctly:

sig FileSystem{  
.  
.  
.  
contents: Dir lone → FSObject  
}

 ![FileModel2](https://global.discourse-cdn.com/free1/uploads/alloytools/original/1X/885bab982339abde1234e1e82648306d90c6346a.jpeg)

Should “contents” label the mapping from Dir to FSObject? After I drew it I thought – I bet I labelled the wrong arrow but I left it in there in order to ask.

I’m wondering if my primitive set representation is a good mental model of what the alloy model is saying.

Regardless thanks for helping to confirm my understanding of the first set of notation.

---

<div class="post-metadata">

### Author: ![grayswandyr](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/grayswandyr/32/17_2.png) [@grayswandyr](https://alloytools.discourse.group/u/grayswandyr)
#### Post date: [July 30, 2021, 10:32am UTC](https://alloytools.discourse.group/t/really-basic-question/171/5 "2021-07-30T10:32:34Z")

</div>

First, the Alloy code you wrote means that `contents` is a ternary relation, that is a set of triples whose first coordinate is in `FileSystem`, the second in `Dir` and the third in `FSObject`. Labelling arrows works well for _binary_ relations, not really for ternary (or more) ones.

OK. So, this was the formalist view, without taking into account the designer’s intent when using this name. The relation could as well be called `foo` or `bar` without changing its mathematical meaning (that is, being a set of triples).

But:

1. The word `contents` wasn’t chosen without a reason. Designers and programmers name things (sets, relations, types, variables, constants, functions, methods…) to convey a mental model, trying to use names as evocative of the modeled situation as possible.
2. A ternary relation on sets _A, B_ and _C_ can also be viewed as (in mathematical terms: is _isomorphic to_) a function from _A_ to _P(A x B)_ or a function from _A x B_ to _P(C)_ (where, given a set _X_, _P(X)_ is the _powerset_ of _X_).

Here, it’s likely that the _ternary_ relation was named `contents` because it is the same to see it as a ternary relation or as a function from _FileSystem x Dir_ to _P(FSObject)_ (if you sit in a given filesystem and a given directory, then you can retrieve \_the set of \_ objects they contain).

I hope it’s clearer.

Notice also that your sketch doesn’t show some interesting situations. For instance, you could also have a triple _(F2, D, O1)_, or _(F2, D, O2)_, or both (remark that, in the first two cases, you can’t easily go on with drawing arrows as you did).

Finally we haven’t spoken of this `lone` multiplicty yet: it adds a further constraint that says that, for all other columns of the relation (`FileSystem` and `FSObject`), there is _at most one_ (lone) directory. In plain English, we rule out situations where, in a given filesystem, a given FSObject may belong to two (or more) different directories. For instance, you cannot have _(F2, D, O3)_.

In Unix terms, this amounts to ruling out so-called “hard links”.

---

<div class="post-metadata">

### Author: ![OnorioCatenacci](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/onoriocatenacci/32/65_2.png) [@OnorioCatenacci](https://alloytools.discourse.group/u/OnorioCatenacci)
#### Post date: [July 30, 2021, 5:01pm UTC](https://alloytools.discourse.group/t/really-basic-question/171/6 "2021-07-30T17:01:56Z")

</div>

Thanks again for another excellent reply!
