Current section

Files

Jump to
tempus stuff background.md
Raw

stuff/background.md

# Mathematical Background
## 𝕋erminology
The pair of two elements is called a `Slot` if the following conditions are met
- each element is either `nil` or an instance of a datetime with defined timezone
- if both elements are datetimes, the first element does not superseed the second one
- if either element is `nil`, the `Slot` is called _open_, if both are `nil`, it’s called _identity_
`Slot` id denoted `[from β†’ to]`. Let’s define a binary _union_ operation on slots, denoted `βˆͺ`. Slots do not form a group with `βˆͺ`, but sorted sets of slots of arbitrary length having no joint slots (denoted `π•₯` or more verbose `π•₯[[from₁, to₁], [fromβ‚‚, toβ‚‚], …]`) do indeed form a group, denoted `𝕋`, together with a binary operation `βˆͺ` on `𝕋`, such as the following group axioms are satisfied:
### Associativity
βˆ€ π•₯₁, π•₯β‚‚, π•₯₃ ∈ 𝕋, (π•₯₁ βˆͺ π•₯β‚‚) βˆͺ π•₯₃ = π•₯₁ βˆͺ (π•₯β‚‚ βˆͺ π•₯₃)
### Identity element
βˆƒ π•₯β‚€ ∈ 𝕋 (`π•₯[]`) such that, for every π•₯ in 𝕋, (π•₯ βˆͺ π•₯β‚€) = (π•₯β‚€ βˆͺ π•₯) = π•₯
### Inverse element
For each π•₯ in 𝕋, there exist π•₯Β―ΒΉ such that π•₯ βˆͺ π•₯Β―ΒΉ = π•₯Β―ΒΉ βˆͺ π•₯ = π•₯β‚€
That said, slots form an Abelian group with union binary operation and empty set as identity element.
## Slots Semigroup
Slots themselves form a semigroup with a binary union operation, an identity element `[nil β†’ nil]`, without inverse.
## Binary Operation
βˆ€ π•₯₁ = π•₯[[from₁ β†’ to₁]], π•₯β‚‚ = π•₯[[fromβ‚‚ β†’ toβ‚‚]] ∈ 𝕋, π•₯₁ βˆͺ π•₯β‚‚ is defined as
- π•₯[[from₁ β†’ to₁], [fromβ‚‚ β†’ toβ‚‚]] if to₁ < fromβ‚‚
- π•₯[[fromβ‚‚ β†’ toβ‚‚], [from₁ β†’ to₁]] if toβ‚‚ < from₁
- π•₯[[min(from₁, fromβ‚‚) β†’ max(to₁ β†’ toβ‚‚)]] otherwise
`nil` is considered to be less than any datetime _and_ greater than any datetime, thus `π•₯[[nil β†’ to₁]] βˆͺ π•₯[[fromβ‚‚ β†’ toβ‚‚]]` would be either `π•₯[[nil β†’ max(to₁, toβ‚‚)]]` if `to₁ > fromβ‚‚` or `π•₯[[nil β†’ to₁], [fromβ‚‚ β†’ toβ‚‚]]` otherwise.
## Mergeability
Once `𝕋` is a group, each two elements of it _might be merged_. Even if they are infinite. That’s why `Stream` implementation of `𝕋` exists.