Documentation

Linglib.Core.Time.Allen

Allen's Interval Relations #

@cite{allen-1983}

The thirteen jointly-exhaustive, pairwise-disjoint relations that can hold between two intervals on a linear order. Originally introduced by James F. Allen for temporal reasoning in AI, this is the canonical relation algebra that Reichenbach, Klein, Pancheva, and Declerck all draw from — every temporal predicate in linglib is a (possibly singleton) subset of these thirteen atomic relations.

AtomSymbolInverseDefining inequality
precedespprecededByi.finish < j.start
meetsmmetByi.finish = j.start
overlapsooverlappedByi.start < j.start < i.finish < j.finish
finishedByFfinishesi.start < j.start, i.finish = j.finish
containsDduringi.start < j.start, j.finish < i.finish
startssstartedByi.start = j.start, i.finish < j.finish
equaleequali.start = j.start, i.finish = j.finish
startedBySstartsi.start = j.start, j.finish < i.finish
duringdcontainsj.start < i.start, i.finish < j.finish
finishesffinishedByj.start < i.start, i.finish = j.finish
overlappedByOoverlapsj.start < i.start < j.finish < i.finish
metByMmeetsi.start = j.finish
precededByPprecedesj.finish < i.start

For any two intervals on a linear order, at least one atomic relation holds (holds_exists). When both intervals are non-degenerate (start < finish), exactly one holds (holds_unique). The non-degeneracy hypothesis matches @cite{allen-1983}'s original setup: on point intervals at the same location, meets, metBy, and equal all hold simultaneously, so uniqueness genuinely fails on degenerate inputs. Both proofs use mathlib's order decision procedure for LinearOrder.

Existing Interval predicates (subinterval, isBefore, finalSubinterval, …) are unions of atomic Allen relations — see the Predicate Bridges section.

The Allen algebra also has a 13×13 composition table giving, for each pair (r, s), the set of relations consistent with i r j ∧ j s k. We provide identity laws and the principal compositions used by tense theory; the full table is left as a TODO.

Core.Time.Relation (in Time.lean) is the point analogue (operating on Time × Time); on point intervals it collapses to {precedes, equal, precededBy} (the only three Allen relations consistent with zero-length intervals).

The thirteen atomic Allen relations between two intervals on a linear order (@cite{allen-1983}). Naming follows Allen 1983; each atom has an inverse obtained by swapping the two interval arguments — see AllenRelation.inverse.

  • precedes : AllenRelation

    i.finish < j.start — i ends strictly before j starts.

  • meets : AllenRelation

    i.finish = j.start — i's right endpoint is j's left endpoint.

  • overlaps : AllenRelation

    i.start < j.start < i.finish < j.finish — proper overlap on the right of i.

  • finishedBy : AllenRelation

    i.start < j.start ∧ i.finish = j.finish — j is a final subinterval of i.

  • contains : AllenRelation

    i.start < j.start ∧ j.finish < i.finish — j strictly inside i.

  • starts : AllenRelation

    i.start = j.start ∧ i.finish < j.finish — i is a proper initial subinterval of j.

  • equal : AllenRelation

    i.start = j.start ∧ i.finish = j.finish — identical intervals.

  • startedBy : AllenRelation

    i.start = j.start ∧ j.finish < i.finish — j is a proper initial subinterval of i.

  • during : AllenRelation

    j.start < i.start ∧ i.finish < j.finish — i strictly inside j.

  • finishes : AllenRelation

    j.start < i.start ∧ i.finish = j.finish — i is a final subinterval of j.

  • overlappedBy : AllenRelation

    j.start < i.start < j.finish < i.finish — proper overlap on the left of i.

  • metBy : AllenRelation

    i.start = j.finish — i's left endpoint is j's right endpoint.

  • precededBy : AllenRelation

    j.finish < i.start — j ends strictly before i starts.

Instances For
    @[implicit_reducible]
    Equations
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      equal is the unique self-inverse atom.

      The set of all thirteen atoms — useful for stating exhaustiveness.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Core.Time.AllenRelation.holds {Time : Type u_1} [LinearOrder Time] :
        AllenRelationInterval TimeInterval TimeProp

        r.holds i j is true iff atomic Allen relation r is the one that holds between intervals i and j. The defining inequalities follow @cite{allen-1983}.

        Equations
        Instances For
          theorem Core.Time.AllenRelation.holds_inverse {Time : Type u_1} [LinearOrder Time] (r : AllenRelation) (i j : Interval Time) :
          r.holds i j r.inverse.holds j i

          Holds is symmetric under inversion: r holds of (i, j) iff r⁻¹ holds of (j, i). This is the central algebraic property of the inverse operation.

          def Core.Time.AllenRelation.witness {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :
          { r : AllenRelation // r.holds i j }

          Exhaustiveness (constructive witness): every interval pair satisfies at least one atomic Allen relation, computably. The case-split mirrors @cite{allen-1983}'s exhaustive enumeration: trichotomy on i.finish vs j.start, then i.start vs j.finish, then refinement on i.start vs j.start and i.finish vs j.finish. Used to derive the constructive Interval.allenRel projection.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Core.Time.AllenRelation.holds_exists {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :
            ∃ (r : AllenRelation), r.holds i j

            Exhaustiveness (existence half): every interval pair satisfies at least one atomic Allen relation. Existential projection of witness.

            Each non-degenerate interval pair (i, j) has a four-tuple signature: the pairwise sgn (lt/eq/gt) of every endpoint of i with every endpoint of j. The thirteen Allen atoms correspond bijectively to thirteen of the 81 possible signature tuples (the other 68 are excluded by i.start < i.finish and j.start < j.finish). Factoring uniqueness through this signature reduces the 169-case cross-product cases r₁ <;> cases r₂ (which needs 6× the default heartbeat budget) into two 13-case lemmas.

            def Core.Time.sgn {Time : Type u_1} [LinearOrder Time] (a b : Time) :
            Ordering

            Three-way sign of a vs b on a linear order.

            Equations
            • Core.Time.sgn a b = if a < b then Ordering.lt else if a = b then Ordering.eq else Ordering.gt
            Instances For
              theorem Core.Time.sgn_lt {Time : Type u_1} [LinearOrder Time] {a b : Time} (h : a < b) :
              sgn a b = Ordering.lt
              theorem Core.Time.sgn_eq {Time : Type u_1} [LinearOrder Time] {a b : Time} (h : a = b) :
              sgn a b = Ordering.eq
              theorem Core.Time.sgn_gt {Time : Type u_1} [LinearOrder Time] {a b : Time} (h : b < a) :
              sgn a b = Ordering.gt
              def Core.Time.signature {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :
              Ordering × Ordering × Ordering × Ordering

              The 4-tuple signature of an interval pair: pairwise comparisons of (i.start vs j.start, i.start vs j.finish, i.finish vs j.start, i.finish vs j.finish).

              Equations
              Instances For
                def Core.Time.AllenRelation.expectedSig :
                AllenRelationOrdering × Ordering × Ordering × Ordering

                The expected signature of each Allen atom — the unique 4-tuple of pairwise endpoint comparisons forced by the atom's defining inequalities together with non-degeneracy of both intervals.

                Equations
                Instances For
                  theorem Core.Time.AllenRelation.expectedSig_injective (r₁ r₂ : AllenRelation) (h : r₁.expectedSig = r₂.expectedSig) :
                  r₁ = r₂

                  The thirteen expected signatures are pairwise distinct: any two atoms with the same signature are equal. (13-case diagonal + 156 trivial simp contradictions on Ordering constructor mismatch.)

                  theorem Core.Time.AllenRelation.signature_of_holds {Time : Type u_1} [LinearOrder Time] (r : AllenRelation) (i j : Interval Time) (hi : i.start < i.finish) (hj : j.start < j.finish) (h : r.holds i j) :

                  If atom r holds of a non-degenerate interval pair, the pair's signature is exactly r.expectedSig. (13 cases, each computing four sgn components via Prod.ext + the appropriate sgn_* lemma + order.)

                  theorem Core.Time.AllenRelation.holds_unique {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) (hi : i.start < i.finish) (hj : j.start < j.finish) (r₁ r₂ : AllenRelation) (h₁ : r₁.holds i j) (h₂ : r₂.holds i j) :
                  r₁ = r₂

                  Uniqueness (pairwise disjointness): on non-degenerate intervals (i.start < i.finish and j.start < j.finish), at most one atom holds of a given pair. Combined with holds_exists, this gives the key property of Allen's algebra: the thirteen atoms partition the space of (proper) interval pairs into thirteen exhaustive, pairwise-disjoint cases.

                  The non-degeneracy hypothesis is essential: at a single time point t, taking i = j = ⟨t, t, le_refl t⟩ makes meets (t = t), metBy (t = t), and equal (t = t ∧ t = t) all hold simultaneously. @cite{allen-1983} sidesteps this by assuming strict intervals throughout.

                  Proof: factor through the 4-tuple signature. Both r₁ and r₂ force the same signature (signature_of_holds), and distinct atoms have distinct signatures (expectedSig_injective).

                  Many natural temporal predicates correspond to unions of Allen atoms — "at least one of these atoms holds." We express this uniformly via holdsIn, and name the atom-sets that appear in the Interval predicate API. Each existing Interval predicate is then a projection from a named atom-set: this exposes the algebraic structure (S₁ ⊆ S₂ ⇒ holdsIn S₁ ⇒ holdsIn S₂) and grounds each predicate in the Allen algebra by construction.

                  Singleton sets (`precedesSet`, `meetsSet`) recover individual atoms
                  as predicates; longer sets give the union predicates that linguistic
                  theory typically works with. The atom sets are first-class data, so
                  later modules (`Domain`, `RelationOrigin`, …) can manipulate them
                  uniformly without committing to a specific predicate at the
                  type level. 
                  
                  def Core.Time.AllenRelation.holdsIn {Time : Type u_1} [LinearOrder Time] (S : List AllenRelation) (i j : Interval Time) :

                  "holdsIn S i j" iff some atom in the list S is the relation holding between i and j. Singleton lists yield exact-atom predicates; longer lists yield union predicates.

                  Equations
                  Instances For
                    @[simp]
                    theorem Core.Time.AllenRelation.holdsIn_nil {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :
                    holdsIn [] i j False
                    @[simp]
                    theorem Core.Time.AllenRelation.holdsIn_singleton {Time : Type u_1} [LinearOrder Time] (r : AllenRelation) (i j : Interval Time) :
                    holdsIn [r] i j r.holds i j
                    theorem Core.Time.AllenRelation.holdsIn_cons {Time : Type u_1} [LinearOrder Time] (r : AllenRelation) (S : List AllenRelation) (i j : Interval Time) :
                    holdsIn (r :: S) i j r.holds i j holdsIn S i j
                    theorem Core.Time.AllenRelation.holdsIn_mono {Time : Type u_1} [LinearOrder Time] {S₁ S₂ : List AllenRelation} (h : rS₁, r S₂) (i j : Interval Time) :
                    holdsIn S₁ i jholdsIn S₂ i j

                    Subset monotonicity: enlarging the atom set weakens the predicate.

                    {equal} — interval coincidence; on point intervals collapses to point equality, the relation behind Reichenbach's R = P etc.

                    Equations
                    Instances For

                      {precedes, meets} — i.e., Interval.isBefore: strict precedence plus meeting (the conflation i.finish ≤ j.start represents).

                      Equations
                      Instances For

                        {starts, equal, finishes, during} — i.e., Interval.subinterval: every way i can be contained in j.

                        Equations
                        Instances For

                          {starts, finishes, during} — i.e., Interval.properSubinterval: proper containment (excludes equal).

                          Equations
                          Instances For

                            {finishes, equal} — i.e., Interval.finalSubinterval: contained and sharing the right endpoint.

                            Equations
                            Instances For

                              Eleven atoms — every relation except strict precedence in either direction — i.e., Interval.overlaps's union characterization.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                Existing Interval predicates equated to projections from named Allen atom-sets via holdsIn. The singleton-atom predicates (precedes, meets) collapse to Iff.rfl; the union predicates require structural-form ↔ disjunction-form translations. These are the only place where the structural definitions in Core/Temporal/Time.lean meet the Allen algebra; downstream modules should depend on the Allen side.

                                theorem Core.Time.Interval.precedes_iff_allen {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :

                                Interval.precedes is exactly the Allen precedes atom.

                                theorem Core.Time.Interval.meets_iff_allen {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :

                                Interval.meets is exactly the Allen meets atom.

                                theorem Core.Time.Interval.isBefore_iff_allen {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :

                                Interval.isBefore (≤) is the union {precedes, meets} — Allen's strict precedes plus meets. This conflation of two atoms into one weakened predicate is exactly the kind of imprecision the Allen algebra removes.

                                theorem Core.Time.Interval.isAfter_iff_allen {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :

                                Interval.isAfter is the inverse of isBefore: {precededBy, metBy}.

                                Interval.subinterval (i ⊆ j) is the union {starts, equal, finishes, during} — every way i can be contained in j without sharing the wrong boundary.

                                Interval.finalSubinterval is the union {finishes, equal} — contained in j and sharing j's right endpoint.

                                Interval.properSubinterval is the union {starts, finishes, during} — containment that excludes the equal case.

                                @[implicit_reducible]
                                instance Core.Time.AllenRelation.holds_decidable {Time : Type u_1} [LinearOrder Time] [DecidableEq Time] [DecidableRel fun (x1 x2 : Time) => x1 < x2] (r : AllenRelation) (i j : Interval Time) :
                                Decidable (r.holds i j)

                                holds is decidable on a linear order (provided < and = are).

                                Equations
                                • One or more equations did not get rendered due to their size.

                                The full Allen composition table assigns to each pair (r, s) the set of relations consistent with i r j ∧ j s k. The table has 169 entries and is left as a TODO. We provide the identity laws plus the principal transitive closures used by tense theory.

                                Convention: `holds_*_trans` reads "if r holds of (i, j) and r holds
                                of (j, k), then r holds of (i, k)" for the relations that are transitive. 
                                
                                theorem Core.Time.AllenRelation.holds_equal_left {Time : Type u_1} [LinearOrder Time] {i j k : Interval Time} (r : AllenRelation) (h₁ : equal.holds i j) (h₂ : r.holds j k) :
                                r.holds i k

                                equal is a left identity: if i = j and j r k, then i r k.

                                theorem Core.Time.AllenRelation.holds_equal_right {Time : Type u_1} [LinearOrder Time] {i j k : Interval Time} (r : AllenRelation) (h₁ : r.holds i j) (h₂ : equal.holds j k) :
                                r.holds i k

                                equal is a right identity: if i r j and j = k, then i r k.

                                theorem Core.Time.AllenRelation.holds_precedes_trans {Time : Type u_1} [LinearOrder Time] {i j k : Interval Time} (h₁ : precedes.holds i j) (h₂ : precedes.holds j k) :

                                precedes is transitive: i p j ∧ j p k → i p k. (The composition table entry precedesprecedes is the singleton {precedes}.) The proof chains i.finish < j.start ≤ j.finish < k.start via j.valid.

                                theorem Core.Time.AllenRelation.holds_during_trans {Time : Type u_1} [LinearOrder Time] {i j k : Interval Time} (h₁ : during.holds i j) (h₂ : during.holds j k) :

                                The during relation is transitive: i ⊏ j ∧ j ⊏ k → i ⊏ k. (Composition entry duringduring = {during}.)

                                theorem Core.Time.AllenRelation.holds_contains_trans {Time : Type u_1} [LinearOrder Time] {i j k : Interval Time} (h₁ : contains.holds i j) (h₂ : contains.holds j k) :

                                The contains relation is transitive (mirror of during).

                                The projection from interval pairs to Allen atoms — the inverse direction of holds. Defined by the constructive AllenRelation.witness, which case-splits on endpoint trichotomies. By holds_unique, on non-degenerate intervals the projection is forced — any atom that holds equals it. Together with holdsIn, this gives a full abstraction-and-projection layer over the algebra.

                                def Core.Time.Interval.allenRel {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :

                                The Allen atom currently holding between two intervals. Computable; extracted from the constructive AllenRelation.witness. For non-degenerate intervals this is well-defined: allenRel_unique proves every witness equals the projection.

                                Equations
                                Instances For
                                  theorem Core.Time.Interval.allenRel_holds {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) :
                                  (i.allenRel j).holds i j

                                  The projected atom does hold between the intervals.

                                  theorem Core.Time.Interval.allenRel_unique {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) (hi : i.start < i.finish) (hj : j.start < j.finish) {r : AllenRelation} (h : r.holds i j) :
                                  r = i.allenRel j

                                  For non-degenerate intervals, the projection is unique: every atom that holds equals allenRel i j. This is the core "well- definedness" theorem for the projection — it justifies treating allenRel i j as the Allen relation between the two intervals.

                                  theorem Core.Time.Interval.allenRel_mem_iff_holdsIn {Time : Type u_1} [LinearOrder Time] (i j : Interval Time) (hi : i.start < i.finish) (hj : j.start < j.finish) (S : List AllenRelation) :
                                  i.allenRel j S AllenRelation.holdsIn S i j

                                  The projection lands in the named atom-set iff the corresponding holdsIn predicate holds. (For non-degenerate intervals; uses uniqueness to convert membership to existence.)