Skip to content

Commit

Permalink
Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jun 28, 2024
1 parent 5d6277d commit dfb25d3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
48 changes: 48 additions & 0 deletions doc/basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Metamorphose primarily provides the `Permutation` class, which is in the
`metamorphose` package and exported to the `soundness` package. You can import
it with,
```scala
import metamorphose.*
```
or,
```scala
import soundness.*
```

There are two ways to construct a new `Permutation`. Firstly, from an ordered
sequence of distinct indexes, for example,
```scala
val permutation = Permutation(Vector(1, 4, 2, 3, 0))
```
which interprets the ordering of the indexes to yield the permutation with
factoradic number 45, i.e. `Permutation(Factoradic(45))`.

Or, if we already know the factoradic number of the permutation, we can pass
that in directly, using the `Factoradic` costructor, like so:
```scala
val permutation = Permutation(Factoradic(45))
```

To check that this is the same permutation, we can expand it with,
```scala
val order: List[Int] = permutation.expansion
```
which gives the original sequence back: `List(1, 4, 2, 3, 0)`.

It's also possible to see the Lehmer code derived from this permutation with,
```scala
permutation.lehmer
```
which produces, `List(1, 3, 1, 1, 0)`.

We can apply this permutation to a sufficiently long sequence just by applying
it to the sequence, i.e. `permutation(list)`.

Permutations are always reversible, and `Permutation#inverse` will construct a
new permutation which will permute a sequence permuted by the original
permutation back to the original list.

That is, for all lists and permutations of the right size it is true that,
```scala
permutation.inverse(permutation(list)) == list
```
3 changes: 3 additions & 0 deletions doc/features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- efficient representation of permutations of collection elements
- bijection between positive integers and permutations
- provides a binary serialization of permutations
6 changes: 6 additions & 0 deletions doc/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A permutation is a rearrangement of the elements in an ordered collection. It
is a one-to-one mapping—a bijection—and therefore reversible.
[Lehmer codes](https://en.wikipedia.org/wiki/Lehmer_code) provide a mapping
between positive integers and permutations, which make it possible to describe
a permutation of _n_ elements in _O(nlog(n))_ space. _Metamorphose_ provides
an implementation of this encoding.
2 changes: 2 additions & 0 deletions doc/logo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The logo shows a butterfly, which has undergone metamorphosis from a
caterpillar.
2 changes: 2 additions & 0 deletions doc/name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When an insect metamorphoses, it permutes the elements of its body from one
form into another.
1 change: 1 addition & 0 deletions doc/status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fledgling

0 comments on commit dfb25d3

Please sign in to comment.