# Multisets

```agda
module trees.multisets where
```

<details><summary>Imports</summary>

```agda
open import foundation.dependent-pair-types
open import foundation.empty-types
open import foundation.function-types
open import foundation.universe-levels

open import trees.elementhood-relation-w-types
open import trees.w-types
```

</details>

## Idea

The type of **multisets** of universe level `l` is the W-type of the universal
family over the universe `UU l`.

## Definitions

### The type of small multisets

```agda
š• : (l : Level) ā†’ UU (lsuc l)
š• l = š•Ž (UU l) (Ī» X ā†’ X)
```

### The large type of all multisets

```agda
data
  Large-š• : UUĻ‰
  where
  tree-Large-š• : {l : Level} (X : UU l) ā†’ (X ā†’ Large-š•) ā†’ Large-š•
```

### The elementhood relation on multisets

```agda
infix 6 _āˆˆ-š•_ _āˆ‰-š•_

_āˆˆ-š•_ : {l : Level} ā†’ š• l ā†’ š• l ā†’ UU (lsuc l)
X āˆˆ-š• Y = X āˆˆ-š•Ž Y

_āˆ‰-š•_ : {l : Level} ā†’ š• l ā†’ š• l ā†’ UU (lsuc l)
X āˆ‰-š• Y = is-empty (X āˆˆ-š• Y)
```

### Comprehension for multisets

```agda
comprehension-š• :
  {l : Level} (X : š• l) (P : shape-š•Ž X ā†’ UU l) ā†’ š• l
comprehension-š• X P =
  tree-š•Ž (Ī£ (shape-š•Ž X) P) (component-š•Ž X āˆ˜ pr1)
```