Documentation

Provenance.AggQueryProbability

Possible-world foundations for the general evaluator #

The token-level ingredients of the random-world commutation for AggQuery.evaluate over 𝔹[X] (the general-evaluator counterpart of randomWorld_evaluateAnnotated, whose target statement is

genRandomWorld v (q.evaluate d) = q.evaluatePlain (d.randomWorld v)

– under a valuation v, specializing the general evaluation's surviving rows is the plain evaluation of the realized world):

def AggValue.realized {T X : Type} (a : AggValue T (BoolFunc X)) (v : X β†’ Bool) :

The positions of a token's occurrences realized by a valuation.

Equations
Instances For
    Dependency graph
    theorem AggValue.specialize_eval {T X : Type} (a : AggValue T (BoolFunc X)) (v : X β†’ Bool) :
    (a.specialize fun (Ξ± : BoolFunc X) => Ξ± v) = a.valOn (a.realized v)

    The world-faithful reading under a valuation is the per-world reading at the realized world.

    Dependency graph
    theorem AggValue.predProv_eval_iff {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] (a : AggValue T (BoolFunc X)) (op : CompOp) (c : T) (v : X β†’ Bool) :
    a.predProv op c v = true ↔ (a.realized v).Nonempty ∧ op.eval (a.specialize fun (Ξ± : BoolFunc X) => Ξ± v) c

    The token-level PQE bridge. Under a valuation v, the predicate provenance of ⟨token⟩ op c is true iff the token's realized group is non-empty and its specialized aggregate value satisfies the comparison. The Οƒ-aggregate case of the random-world commutation reduces to this.

    Dependency graph
    def GenValue.specializeAt {T X : Type} (v : X β†’ Bool) :
    GenValue T (BoolFunc X) β†’ T

    The specialized reading of a lifted value: regular values are themselves, a token aggregates its realized occurrences.

    Equations
    Instances For
      Dependency graph
      def GenRow.specializeTuple {T X : Type} {n : β„•} (v : X β†’ Bool) (u : Tuple (GenValue T (BoolFunc X)) n) :
      Tuple T n

      The specialized reading of a row's tuple.

      Equations
      Instances For
        Dependency graph
        def genRandomWorld {T X : Type} {n : β„•} (v : X β†’ Bool) (R : Multiset (GenRow T (BoolFunc X) n)) :

        The realized world of a general evaluation: the rows whose finalized annotation is true under the valuation, with tokens specialized.

        Equations
        Instances For
          Dependency graph

          Evaluation of factored annotations #

          def annGuard {X : Type} (l : List (BoolFunc X)) (v : X β†’ Bool) :

          Truth of a group's existence guard under a valuation: some occurrence annotation is realized.

          Equations
          Instances For
            Dependency graph
            @[instance_reducible]
            instance instDecidableAnnGuard {X : Type} (l : List (BoolFunc X)) (v : X β†’ Bool) :
            Equations
            Dependency graph
            theorem GenAnn.finalize_eval_iff {X : Type} (a : GenAnn (BoolFunc X)) (v : X β†’ Bool) :
            a.finalize v = true ↔ a.base v = true ∧ βˆ€ l ∈ a.pending, annGuard l v

            Pointwise truth of a finalized factored annotation: the concrete part holds and every pending group is realized non-empty (Ξ΄ is the identity on 𝔹[X]).

            Dependency graph

            A token's existence guard is the non-emptiness of its realized world.

            Dependency graph

            Specialized readings under kind conformance #

            theorem GenValue.eq_inl_of_kindOf_reg {T K' : Type} {x : GenValue T K'} (h : x.kindOf = ColKind.reg) :
            βˆƒ (w : T), x = Sum.inl w

            A regular-kinded value is a left injection.

            Dependency graph
            theorem GenValue.eq_inr_of_kindOf_agg {T K' : Type} {x : GenValue T K'} (h : x.kindOf = ColKind.agg) :
            βˆƒ (a : AggValue T K'), x = Sum.inr a

            A token-kinded value is a right injection.

            Dependency graph
            theorem TermG.eval_specialize {T : Type} [ValueType T] {X : Type} {n : β„•} {ΞΊ : Fin n β†’ ColKind} (t : TermG T ΞΊ) (u : Tuple (GenValue T (BoolFunc X)) n) (hconf : βˆ€ (k : Fin n), (u k).kindOf = (ΞΊ k).base) (v : X β†’ Bool) :

            On a kind-conformant tuple, a term's lifted evaluation is its plain evaluation on the specialized tuple (regular columns hold regular values, on which both readings are the identity).

            Dependency graph
            theorem GenPred.holds_iff_specialize {T : Type} [ValueType T] {X : Type} {n : β„•} {ΞΊ : Fin n β†’ ColKind} (Ο† : GenPred T ΞΊ) (hΟ† : Ο†.hasAggAtom = false) (u : Tuple (GenValue T (BoolFunc X)) n) (hconf : βˆ€ (k : Fin n), (u k).kindOf = (ΞΊ k).base) (v : X β†’ Bool) :

            On a kind-conformant tuple, an aggregate-atom-free predicate holds iff its plain reading holds on the specialized tuple.

            Dependency graph

            The Οƒ-aggregate row lemma #

            def GenPred.selCompared {T K' : Type} {n : β„•} {ΞΊ : Fin n β†’ ColKind} (Ο† : GenPred T ΞΊ) (u : Tuple (GenValue T K') n) :

            The annotation lists of the tokens compared by a predicate on a row (the evaluator's compared).

            Equations
            Instances For
              Dependency graph
              def GenPred.selPending {T K' : Type} [DecidableEq K'] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (Ο† : GenPred T ΞΊ) (u : Tuple (GenValue T K') n) (p : Multiset (List K')) :

              The pending factors after a Οƒ with aggregate atoms (the evaluator's update, definitionally).

              Equations
              Instances For
                Dependency graph
                theorem GenPred.predsem_eval_iff {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (Ο† : GenPred T ΞΊ) (neg : Bool) (u : Tuple (GenValue T (BoolFunc X)) n) (hconf : βˆ€ (k : Fin n), (u k).kindOf = (ΞΊ k).base) (v : X β†’ Bool) (hg : βˆ€ k ∈ Ο†.comparedCols, βˆ€ (a : AggValue T (BoolFunc X)), u k = Sum.inr a β†’ (a.realized v).Nonempty) :

                Predicate provenance evaluation, under existence guards. On a kind-conformant row all of whose compared groups are realized non-empty, the predicate provenance is true iff the (polarity-adjusted) plain predicate holds on the specialized tuple.

                Dependency graph
                theorem GenPred.entails_guard {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (Ο† : GenPred T ΞΊ) (neg : Bool) (u : Tuple (GenValue T (BoolFunc X)) n) (v : X β†’ Bool) (β„“β‚€ : List (BoolFunc X)) (huni : βˆ€ k ∈ Ο†.comparedCols, βˆ€ (a : AggValue T (BoolFunc X)), u k = Sum.inr a β†’ List.map Prod.snd a.occs = β„“β‚€) (hent : Ο†.entailsExistence neg = true) (hp : Ο†.predsem neg u v = true) :
                annGuard β„“β‚€ v

                Existence entailment extracts the guard. When a predicate entails existence and all its compared tokens carry the annotation list β„“β‚€, a true predicate provenance realizes β„“β‚€.

                Dependency graph

                Finalize algebra (any m-semiring) #

                theorem GenAnn.finalize_cash {K' : Type} [CommSemiringWithMonus K'] [DecidableEq K'] (b : K') (p kept : Multiset (List K')) (hle : kept ≀ p) :
                { base := b * (Multiset.map (fun (l : List K') => SemiringWithMonus.delta l.sum) (p - kept)).prod, pending := kept }.finalize = { base := b, pending := p }.finalize

                Cashing pending factors into the concrete part preserves the finalized annotation (the projection case of the evaluator).

                Dependency graph
                theorem GenAnn.finalize_mul {K' : Type} [CommSemiringWithMonus K'] (a₁ aβ‚‚ : GenAnn K') :
                { base := a₁.base * aβ‚‚.base, pending := a₁.pending + aβ‚‚.pending }.finalize = a₁.finalize * aβ‚‚.finalize

                The finalized annotation of a product row is the product of the finalized annotations.

                Dependency graph

                The row-level Οƒ lemmas #

                theorem GenPred.sel_finalize_old {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (Ο† : GenPred T ΞΊ) (u : Tuple (GenValue T (BoolFunc X)) n) (b : BoolFunc X) (p : Multiset (List (BoolFunc X))) (v : X β†’ Bool) (h : { base := b * Ο†.predsem false u, pending := Ο†.selPending u p }.finalize v = true) :
                { base := b, pending := p }.finalize v = true

                A Οƒ with aggregate atoms only strengthens the annotation: the finalized updated annotation implies the finalized original one (the superseded factors are recovered from the predicate provenance through existence entailment).

                Dependency graph
                theorem GenPred.sel_finalize_eval_iff {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (Ο† : GenPred T ΞΊ) (u : Tuple (GenValue T (BoolFunc X)) n) (b : BoolFunc X) (p : Multiset (List (BoolFunc X))) (v : X β†’ Bool) (hconf : βˆ€ (k : Fin n), (u k).kindOf = (ΞΊ k).base) (hguard : { base := b, pending := p }.finalize v = true β†’ βˆ€ (k : Fin n) (a : AggValue T (BoolFunc X)), u k = Sum.inr a β†’ (a.realized v).Nonempty) :
                { base := b * Ο†.predsem false u, pending := Ο†.selPending u p }.finalize v = true ↔ { base := b, pending := p }.finalize v = true ∧ Ο†.holdsPlain (GenRow.specializeTuple v u)

                The Οƒ-aggregate row lemma. On a kind-conformant, guarded row, the updated annotation is realized iff the original annotation is realized and the plain predicate holds on the specialized tuple.

                Dependency graph

                The guardedness invariant #

                theorem AggQuery.evaluate_guarded {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] [HasAltLinearOrder (BoolFunc X)] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (q : AggQuery T n ΞΊ) (d : AnnotatedDatabase T (BoolFunc X)) (r : GenRow T (BoolFunc X) n) :
                r ∈ q.evaluate d β†’ βˆ€ (v : X β†’ Bool), r.2.finalize v = true β†’ βˆ€ (k : Fin n) (a : AggValue T (BoolFunc X)), r.1 k = Sum.inr a β†’ (a.realized v).Nonempty

                Guardedness of the general evaluator: on any row it produces, whenever the finalized annotation is realized, every token's group is realized non-empty – the group-existence guard of each token is carried either by a pending factor or by a predicate provenance in the concrete part.

                Dependency graph

                Realized-world plumbing #

                The Gamma case helpers #

                The random-world commutation #

                theorem AggQuery.genRandomWorld_evaluate {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] [HasAltLinearOrder (BoolFunc X)] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (q : AggQuery T n ΞΊ) (_hq : q.noProvSum) (d : AnnotatedDatabase T (BoolFunc X)) (v : X β†’ Bool) :

                Random-world commutation for the general evaluator (over 𝔹[X]): specializing the realized rows of the general annotated evaluation is the plain evaluation of the realized world. The Οƒ-aggregate case is the row lemma GenPred.sel_finalize_eval_iff under the conformance and guardedness invariants; the Gamma case rests on groupSeq_randomWorld.

                Dependency graph

                Unrestricted probabilistic query evaluation (PQE) #

                noncomputable def AggQuery.booleanProv {T : Type} [ValueType T] {X : Type} [HasAltLinearOrder (BoolFunc X)] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (q : AggQuery T n ΞΊ) (d : AnnotatedDatabase T (BoolFunc X)) :

                The Boolean provenance of a general query: the βŠ•-sum of the finalized annotations of its rows – true in a world iff some row is realized.

                Equations
                Instances For
                  Dependency graph
                  theorem AggQuery.booleanProv_eval_iff {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] [HasAltLinearOrder (BoolFunc X)] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (q : AggQuery T n ΞΊ) (hq : q.noProvSum) (d : AnnotatedDatabase T (BoolFunc X)) (v : X β†’ Bool) :

                  Pointwise PQE bridge, general form: the Boolean provenance of a general query is true in a world iff the plain evaluation of that world is non-empty. Immediate from the random-world commutation.

                  Dependency graph
                  noncomputable def AggQuery.booleanProb {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (P : ProbAssignment X) (q : AggQuery T n ΞΊ) (d : AnnotatedDatabase T (BoolFunc X)) :

                  Probability that a random world of d satisfies the Boolean query q (non-empty answer), over a tuple-independent probabilistic database.

                  Equations
                  Instances For
                    Dependency graph
                    theorem AggQuery.boolean_pqe {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] [HasAltLinearOrder (BoolFunc X)] {n : β„•} {ΞΊ : Fin n β†’ ColKind} (P : ProbAssignment X) (q : AggQuery T n ΞΊ) (hq : q.noProvSum) (d : AnnotatedDatabase T (BoolFunc X)) :

                    Unrestricted probabilistic query evaluation. For any general query – aggregate comparisons anywhere, through joins, projections, unions and further selections – over a tuple-independent probabilistic database, the probability that a random world satisfies the Boolean query equals the probability of its Boolean provenance. This removes the top-level restriction of the fused booleanHaving_pqe.

                    Dependency graph
                    noncomputable def AggQuery.tupleProv {T : Type} [ValueType T] {X : Type} [HasAltLinearOrder (BoolFunc X)] {n : β„•} (q : AggQuery T n (ColKind.allReg n)) (d : AnnotatedDatabase T (BoolFunc X)) (t : Tuple T n) :

                    The provenance of a tuple t in a general query with all-regular output: the βŠ•-sum of the finalized annotations of the rows whose data part is t.

                    Equations
                    Instances For
                      Dependency graph

                      Pointwise tuple-marginal bridge: the provenance of t is true in a world iff t belongs to the plain evaluation of that world.

                      Dependency graph
                      noncomputable def AggQuery.tupleProb {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] {n : β„•} (P : ProbAssignment X) (q : AggQuery T n (ColKind.allReg n)) (d : AnnotatedDatabase T (BoolFunc X)) (t : Tuple T n) :

                      The marginal probability that t belongs to a random world's answer.

                      Equations
                      Instances For
                        Dependency graph
                        theorem AggQuery.tuple_pqe {T : Type} [ValueType T] {X : Type} [Fintype X] [DecidableEq X] [HasAltLinearOrder (BoolFunc X)] {n : β„•} (P : ProbAssignment X) (q : AggQuery T n (ColKind.allReg n)) (hq : q.noProvSum) (d : AnnotatedDatabase T (BoolFunc X)) (t : Tuple T n) :
                        tupleProb P q d t = P.funcProb (q.tupleProv d t)

                        Unrestricted tuple-marginal PQE: for a general query with all-regular output over a tuple-independent probabilistic database, the marginal probability of an answer tuple is the probability of its provenance. This is the general-evaluator counterpart of the classical intensional-PQE theorem ProbAssignment.theorem_12, with aggregate comparisons allowed anywhere in the query.

                        Dependency graph