Documentation

Provenance.DiffBasis

The difference in place of the selection #

{∅, Π, −, apply, γ, win, μ^⊎} generates the whole algebra in the minimal universe: a selection is an apply of its input with a closed test that holds the empty tuple once where the predicate is true at the row and nothing elsewhere. The tests are built from the difference alone, except for the order: x < y is read by a window counting, over the relation {x, y} (a bag recursion of one round), the rows strictly before y, and that count is compared with 0 as a key, which Explode allows.

The classes of the basis with the difference in place of the selection: ∅, Π, −, the apply, γ, win, μ^⊎.

Equations
Instances For
    Dependency graph

    Truth values as relations of arity 0 #

    @[reducible, inline]
    abbrev DiffBasis.rows {T : Type} {k : ℕ} (X : Relation T k) :

    A relation read as the bag of its rows.

    Equations
    Instances For
      Dependency graph
      def DiffBasis.val {T : Type} {C : ℕ} (γ : Fin C → T) (e : T ⊕ Fin C) :
      T

      The value an expression names: a constant, or a position of the context.

      Equations
      Instances For
        Dependency graph
        def DiffBasis.boolRel {T : Type} (b : Bool) :

        The relation of arity 0 holding the empty tuple once where b holds, and nothing elsewhere.

        Equations
        Instances For
          Dependency graph
          def DiffBasis.param1 {T : Type} {C : ℕ} (e : T ⊕ Fin C) :

          One row, of the value e names.

          Equations
          Instances For
            Dependency graph
            def DiffBasis.proj0 {T : Type} {C k : ℕ} (q : AggQueryIn T C k (ColKind.allReg k)) :

            Every row projected onto no column.

            Equations
            Instances For
              Dependency graph
              @[reducible, inline]
              abbrev DiffBasis.rel {T : Type} {k : ℕ} (X : Multiset (Tuple T k)) :

              A bag of rows read as a relation.

              Equations
              Instances For
                Dependency graph
                def DiffBasis.inter {T : Type} {C k : ℕ} (X Y : AggQueryIn T C k (ColKind.allReg k)) :

                The rows of X that are rows of Y, by two differences.

                Equations
                Instances For
                  Dependency graph
                  def DiffBasis.notT {T : Type} {C : ℕ} (A : AggQueryIn T C 0 (ColKind.allReg 0)) :

                  Truth negated: the unit minus the test.

                  Equations
                  Instances For
                    Dependency graph
                    def DiffBasis.andT {T : Type} {C : ℕ} (A B : AggQueryIn T C 0 (ColKind.allReg 0)) :

                    Both tests hold.

                    Equations
                    Instances For
                      Dependency graph
                      def DiffBasis.orT {T : Type} {C : ℕ} (A B : AggQueryIn T C 0 (ColKind.allReg 0)) :

                      One of the two tests holds.

                      Equations
                      Instances For
                        Dependency graph

                        Equality and nulls #

                        def DiffBasis.eqT {T : Type} {C : ℕ} (a b : T ⊕ Fin C) :

                        The two values are equal.

                        Equations
                        Instances For
                          Dependency graph
                          def DiffBasis.nnT {T : Type} [ValueType T] {C : ℕ} (a : T ⊕ Fin C) :

                          The value is not null.

                          Equations
                          Instances For
                            Dependency graph

                            The order #

                            def DiffBasis.liftE {T : Type} {C : ℕ} (e : T ⊕ Fin C) :
                            T ⊕ Fin (1 + C)

                            An expression read one position further in, past the row of an apply's left side.

                            Equations
                            Instances For
                              Dependency graph
                              def DiffBasis.stepBody {T : Type} {C : ℕ} (s : String) (b : T ⊕ Fin C) :

                              The round of the recursion building {a, b}: the row of b, once per row of the recursive relation other than b.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                Dependency graph
                                def DiffBasis.r1 {T : Type} (a : T) :
                                Tuple T 1

                                The row of a value.

                                Equations
                                Instances For
                                  Dependency graph
                                  def DiffBasis.pairZ {T : Type} {C : ℕ} (s : String) (a b : T ⊕ Fin C) :

                                  {a, b} – {a} where the two are equal – as a bag recursion of one round from a.

                                  Equations
                                  Instances For
                                    Dependency graph
                                    @[reducible, inline]

                                    A way to build {a, b} from two expressions, at every context.

                                    Equations
                                    Instances For
                                      Dependency graph
                                      def DiffBasis.PairSpec {T : Type} [ValueType T] (pr : PairQ T) :

                                      What {a, b} is asked: defined everywhere, {a} where the two are equal and {a, b} otherwise.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        Dependency graph
                                        def DiffBasis.prZ {T : Type} [ValueType T] (s : String) :

                                        {a, b} by a bag recursion of one round.

                                        Equations
                                        Instances For
                                          Dependency graph

                                          The frame of the rows strictly before the current one, its peers and itself excluded.

                                          Equations
                                          Instances For
                                            Dependency graph

                                            No partition.

                                            Equations
                                            Instances For
                                              Dependency graph

                                              Ordered by the one column.

                                              Equations
                                              Instances For
                                                Dependency graph
                                                def DiffBasis.ltO {T : Type} [ValueType T] (a b : T) :

                                                Whether a sorts strictly before b, ascending.

                                                Equations
                                                Instances For
                                                  Dependency graph
                                                  Dependency graph
                                                  def DiffBasis.winZ {T : Type} {C : ℕ} (cnt : SeqAggFunc T) (Z : AggQueryIn T C 1 (ColKind.allReg 1)) :

                                                  {a, b} with, on each row, the number of rows strictly before it, the count read as a key.

                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  Instances For
                                                    Dependency graph
                                                    def DiffBasis.termOf {T : Type} {C k : ℕ} {κ : Fin k → ColKind} (e : T ⊕ Fin C) :
                                                    TermGIn T C κ

                                                    The value an expression names, as a term.

                                                    Equations
                                                    Instances For
                                                      Dependency graph
                                                      def DiffBasis.projB {T : Type} {C : ℕ} (b : T ⊕ Fin C) (W : AggQueryIn T C 2 (ColKind.allReg 2)) :

                                                      Each row's count, beside the value b.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For
                                                        Dependency graph
                                                        def DiffBasis.ltT {T : Type} [ValueType T] {C : ℕ} (cnt : SeqAggFunc T) (pr : PairQ T) (a b : T ⊕ Fin C) :

                                                        a < b, nulls aside: the row of b in {a, b} has a row strictly before it.

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For
                                                          Dependency graph
                                                          theorem DiffBasis.evaluatePlain_ltT {T : Type} [ValueType T] {C : ℕ} {D : Database T} {γ : Fin C → T} {cnt : SeqAggFunc T} (hcnt : cnt.IsCount) {pr : PairQ T} (hpr : PairSpec fun {C : ℕ} => pr) (a b : T ⊕ Fin C) :
                                                          (ltT cnt (fun {C : ℕ} => pr) a b).evaluatePlain D γ = boolRel (ltO (val γ a) (val γ b) && !ValueType.isNull (val γ a))
                                                          Dependency graph

                                                          Comparisons, in Kleene's logic #

                                                          def DiffBasis.opE {T : Type} [ValueType T] {C : ℕ} (cnt : SeqAggFunc T) (pr : PairQ T) (op : CompOp) (a b : T ⊕ Fin C) :

                                                          The comparison holds, read two-valued: the order through ltT, the equalities through eqT.

                                                          Equations
                                                          Instances For
                                                            Dependency graph
                                                            def DiffBasis.cmpTF {T : Type} [ValueType T] {C : ℕ} (cnt : SeqAggFunc T) (pr : PairQ T) (op : CompOp) (a b : T ⊕ Fin C) :

                                                            A comparison's truth and falsity: for a null-strict one, both values non-null and the comparison, or its negation; for IS [NOT] DISTINCT FROM, equality, which is never unknown.

                                                            Equations
                                                            Instances For
                                                              Dependency graph

                                                              Predicates #

                                                              def DiffBasis.termE {T : Type} [ValueType T] {c n : ℕ} {κ : Fin n → ColKind} :
                                                              TermGIn T c κ → T ⊕ Fin (n + c)

                                                              A term of the minimal signature as an expression of the test's context, the row of the selection's input coming first.

                                                              Equations
                                                              Instances For
                                                                Dependency graph
                                                                def DiffBasis.predTF {T : Type} [ValueType T] (cnt : SeqAggFunc T) (pr : PairQ T) {c n : ℕ} {κ : Fin n → ColKind} :
                                                                GenPredIn T c κ → AggQueryIn T (n + c) 0 (ColKind.allReg 0) × AggQueryIn T (n + c) 0 (ColKind.allReg 0)

                                                                The test of a predicate, true and false: the first holds the empty tuple where the predicate is true at the row, the second where it is false.

                                                                Equations
                                                                Instances For
                                                                  Dependency graph

                                                                  The tests are in the fragment #

                                                                  The classes every test uses: ∅, Π, −, γ and win; the pair {a, b} adds its own.

                                                                  Equations
                                                                  Instances For
                                                                    Dependency graph
                                                                    structure DiffBasis.TestOK {T : Type} [ValueType T] (S : Set OpKind) (Θ : Set (SeqAggFunc T)) (Q : Schema → Prop) {C k : ℕ} {κ : Fin k → ColKind} (q : AggQueryIn T C k κ) :

                                                                    What a closed test is asked: its classes, its signature, a schema satisfying Q, no relation mentioned, and defined everywhere.

                                                                    Instances For
                                                                      Dependency graph
                                                                      def DiffBasis.PairOK {T : Type} [ValueType T] (S : Set OpKind) (Θ : Set (SeqAggFunc T)) (Q : Schema → Prop) (pr : PairQ T) :

                                                                      A pair construction whose pairs are in the fragment.

                                                                      Equations
                                                                      Instances For
                                                                        Dependency graph

                                                                        A selection as an apply #

                                                                        Dependency graph
                                                                        def DiffBasis.selX {T : Type} [ValueType T] (cnt : SeqAggFunc T) (pr : PairQ T) {c n : ℕ} {κ : Fin n → ColKind} {l : List (String × ℕ)} (φ : GenPredIn T c κ) (q : AggQueryIn T c n κ l) :
                                                                        AggQueryIn T c n κ l

                                                                        A selection written with the apply: each row of the input meets the test of the predicate at that row, which holds the empty tuple once where the predicate is true and nothing elsewhere.

                                                                        Equations
                                                                        Instances For
                                                                          Dependency graph
                                                                          theorem DiffBasis.evaluatePlain_selX {T : Type} [ValueType T] {cnt : SeqAggFunc T} (hcnt : cnt.IsCount) {pr : PairQ T} (hpr : PairSpec fun {C : ℕ} => pr) {c n : ℕ} {κ : Fin n → ColKind} {l : List (String × ℕ)} (φ : GenPredIn T c κ) (hφ : φ.noFun = true) (q : AggQueryIn T c n κ l) (D : Database T) (γ : Fin c → T) :
                                                                          (selX cnt (fun {C : ℕ} => pr) φ q).evaluatePlain D γ = Multiset.filter (fun (u : Tuple T n) => φ.holdsPlain u γ) (q.evaluatePlain D γ)
                                                                          Dependency graph

                                                                          The pass #

                                                                          The basis with the difference #

                                                                          theorem basisRecDiffOps_generatesOnRec {T : Type} [ValueType T] (sch : Schema) (cnt : SeqAggFunc T) (hcnt : cnt.IsCount) :

                                                                          {∅, Π, −, apply, γ, win, μ^⊎} generates the whole algebra in the minimal universe: every query of the algebra over a schema, in the signature with a count as its only aggregate, is matched by one over those seven classes, defined and equal wherever the query is. First the query is matched over {∅, Π, σ, apply, γ, win, μ^⊎} (basisRecOps_generatesOnRec), then each selection of the match becomes an apply of its test (DiffBasis.exists_selPass), the order being read by a window and its count compared as a key.

                                                                          Dependency graph

                                                                          basisRecDiffOps is a basis of the whole algebra in the minimal universe over ℕ: it generates over every schema, and no proper subset does.

                                                                          Dependency graph