Documentation

Provenance.AggValue

Symbolic aggregate tokens #

AggValue T K is the symbolic aggregate token of the general HAVING semantics: an aggregate function together with the ≼-sorted occurrence payload of the originating group, projected to pairs (value of the aggregated term, occurrence annotation) – exactly the data of Having.havingGroup that the possible-world semantics of an aggregate comparison consumes. It is the one-level analogue of KTensor (deliberately un-quotiented, so the possible worlds of the group can be read off the token); there is no recursion: ProvSQL rejects aggregation, grouping and ordering over aggregate values, and likewise rejects deduplication and difference on token-carrying relations, so no linear order or decidable equality on tokens is required by any permitted downstream operator (SeqAggFunc being a function type, structural decidable equality would not be available anyway).

Readings of a token #

mapAnn pushes a function K → K' through the annotations of a token: value-only readings are unchanged (collapse_mapAnn) and specialize composes with the pushforward (specialize_mapAnn). This is the token layer of the hom-commutation metatheorem for the general evaluator.

Lifted column values #

A column of a token-carrying relation holds either a regular value or a token: T ⊕ AggValue T K. AggValue.mapAnnSum and AggValue.collapseSum extend the pushforward and the deterministic reading to such lifted values; the kind-indexed syntax of the general evaluator governs statically which columns hold which arm.

structure AggValue (T K : Type) :

A symbolic aggregate token: an aggregate function together with the (≼-sorted) occurrence payload of the originating group – for each occurrence, the value of the aggregated term paired with the occurrence annotation.

  • agg : SeqAggFunc T

    The sequence aggregate applied by every reading of the token.

  • occs : List (T × K)

    The occurrence payload: values of the aggregated term paired with the occurrence annotations, in the group's ≼-order.

Instances For
    Dependency graph
    def AggValue.ofGroup {T K : Type} {m : } [ValueType T] (f : SeqAggFunc T) (t : Term T m) (U : List (AnnotatedTuple T K m)) :

    The token of a group with occurrence sequence U, aggregating the term t with f: the projection of the group payload.

    Equations
    Instances For
      Dependency graph
      def AggValue.anns {T K : Type} (a : AggValue T K) :
      Fin a.occs.lengthK

      The occurrence annotations of a token, as a function on positions.

      Equations
      Instances For
        Dependency graph
        def AggValue.valOn {T K : Type} (a : AggValue T K) (W : Finset (Fin a.occs.length)) :
        T

        The aggregate value of the token in the possible world W of its group: the aggregate of the values of the kept occurrences, in order.

        Equations
        Instances For
          Dependency graph
          def AggValue.collapse {T K : Type} (a : AggValue T K) :
          T

          The deterministic reading: the aggregate of the whole occurrence sequence.

          Equations
          Instances For
            Dependency graph
            def AggValue.specialize {T K : Type} (a : AggValue T K) (ν : KBool) :
            T

            The world-faithful reading under a valuation ν of the annotations: restrict to the occurrences whose annotation ν realizes, and aggregate those in order.

            Equations
            Instances For
              Dependency graph
              def AggValue.mapAnn {T K K' : Type} (h : KK') (a : AggValue T K) :

              Pushforward of h : K → K' through the annotations of a token; the values are untouched.

              Equations
              Instances For
                Dependency graph
                def AggValue.predProv {T K : Type} [ValueType T] [CommSemiringWithMonus K] [DecidableEq K] (a : AggValue T K) (op : CompOp) (c : T) :
                K

                Predicate provenance of an atomic comparison against a token: the -sum, over the non-empty possible worlds of the token's group, of the world annotation times the characteristic value of the comparison between the world's aggregate value and the regular value c. Non-empty worlds only: the predicate provenance already enforces group existence, exactly as in the fused semantics Having.havingProv.

                Equations
                Instances For
                  Dependency graph

                  Reindexing bridges #

                  The occurrence payload of ofGroup is a List.map image of the group sequence, so worlds over the token and worlds over the group live over propositionally – not definitionally – equal position types. The bridges below transport seqOf, worldAnn and the two readings along the length-preserving equivalence finCongr.

                  theorem AggValue.seqOf_map {β γ : Type} (g : βγ) (U : List β) (h : U.length = (List.map g U).length) (W : Finset (Fin U.length)) :

                  seqOf commutes with mapping the underlying list, up to reindexing the world along the length equality.

                  Dependency graph
                  theorem AggValue.seqOf_univ {β : Type} (U : List β) :

                  The whole-sequence world: seqOf over univ is the identity.

                  Dependency graph
                  theorem AggValue.filter_eq_seqOf {β : Type} (p : βBool) (U : List β) :
                  List.filter p U = Having.seqOf U {i : Fin U.length | p (U.get i) = true}

                  Filtering a list is taking the subsequence of the positions whose element satisfies the predicate.

                  Dependency graph

                  collapse is the aggregate value of the whole-group world.

                  Dependency graph
                  theorem AggValue.specialize_eq_valOn {T K : Type} (a : AggValue T K) (ν : KBool) :
                  a.specialize ν = a.valOn {i : Fin a.occs.length | ν (a.anns i) = true}

                  specialize is the aggregate value of the world of realized occurrences.

                  Dependency graph

                  ofGroup bridges to the fused semantics #

                  theorem AggValue.length_ofGroup_occs {T K : Type} {m : } [ValueType T] (f : SeqAggFunc T) (t : Term T m) (U : List (AnnotatedTuple T K m)) :

                  The occurrence payload of ofGroup has the length of the group sequence.

                  Dependency graph
                  theorem AggValue.valOn_ofGroup {T K : Type} {m : } [ValueType T] (f : SeqAggFunc T) (t : Term T m) (U : List (AnnotatedTuple T K m)) (W : Finset (Fin U.length)) :

                  The world value of the token of a group is the aggregate value of the fused semantics on that world.

                  Dependency graph
                  theorem AggValue.anns_ofGroup {T K : Type} {m : } [ValueType T] (f : SeqAggFunc T) (t : Term T m) (U : List (AnnotatedTuple T K m)) (i : Fin U.length) :
                  (ofGroup f t U).anns ((finCongr ) i) = (U.get i).2

                  The annotations of the token of a group are the occurrence annotations.

                  Dependency graph
                  theorem AggValue.worldAnn_map_finCongr {K : Type} [CommSemiringWithMonus K] {N M : } (h : N = M) (α : Fin MK) (W : Finset (Fin N)) :
                  Having.worldAnn α (Finset.map (finCongr h).toEmbedding W) = Having.worldAnn (fun (i : Fin N) => α ((finCongr h) i)) W

                  The world annotation transports along the reindexing.

                  Dependency graph
                  theorem AggValue.predProv_ofGroup {T K : Type} {m : } [ValueType T] [CommSemiringWithMonus K] [DecidableEq K] (f : SeqAggFunc T) (t : Term T m) (U : List (AnnotatedTuple T K m)) (op : CompOp) (c : T) :
                  (ofGroup f t U).predProv op c = Having.havingProv U t f op c

                  Regression bridge, token side. The predicate provenance of a comparison against the token of a group is the fused semantics' predicate provenance of the same comparison on that group.

                  Dependency graph

                  Pushforward lemmas #

                  @[simp]
                  theorem AggValue.collapse_mapAnn {T K K' : Type} (h : KK') (a : AggValue T K) :

                  The deterministic reading is unchanged by the pushforward.

                  Dependency graph
                  @[simp]
                  theorem AggValue.specialize_mapAnn {T K K' : Type} (h : KK') (a : AggValue T K) (ν : K'Bool) :
                  (mapAnn h a).specialize ν = a.specialize fun (k : K) => ν (h k)

                  The world-faithful reading composes with the pushforward.

                  Dependency graph

                  Lifted column values #

                  def AggValue.mapAnnSum {T K K' : Type} (h : KK') :
                  T AggValue T KT AggValue T K'

                  Pushforward of h : K → K' on a lifted column value: data is untouched, a token maps its annotations.

                  Equations
                  Instances For
                    Dependency graph
                    def AggValue.collapseSum {T K : Type} :
                    T AggValue T KT

                    Deterministic reading of a lifted column value: data is itself, a token collapses.

                    Equations
                    Instances For
                      Dependency graph
                      @[simp]
                      theorem AggValue.collapseSum_mapAnnSum {T K K' : Type} (h : KK') (x : T AggValue T K) :

                      The deterministic reading of a lifted value is unchanged by the pushforward.

                      Dependency graph