Windows are needed in every basis of the whole algebra #
win is in every basis of the whole algebra in the minimal universe. The
witness is count(*) OVER (… EXCLUDE CURRENT ROW) on a unary relation
holding n copies of one value, which writes n − 1 on every row. A
window-free query of the minimal universe writes, on that family of
instances and for n large, only values p(n) for finitely many
polynomials p with natural coefficients, which n − 1 is not.
The polynomials are Mathlib's Polynomial ℕ; what the invariant needs
of them is that two of them are eventually equal, or eventually strictly
ordered one way, which is read off their real asymptotics.
The instance holding n copies of the row (1) in R.
Instances For
Dependency graph
The whole partition less the current row: ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE CURRENT ROW.
Equations
- WinRow.wholeExcludeSelf = { cond := FrameCond.whole, self := false }
Instances For
Dependency graph
The witness: count(#1) OVER (EXCLUDE CURRENT ROW) on R.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
Eventual comparison of polynomials with natural coefficients #
A polynomial with natural coefficients, read as a function of n.
Equations
Instances For
Dependency graph
How two polynomials compare from some point on.
- lt {p q : Poly} {N : ℕ} (h : ∀ n ≥ N, Polynomial.eval n p < Polynomial.eval n q) : p.Cmp q N
- eq {p q : Poly} {N : ℕ} (h : ∀ n ≥ N, Polynomial.eval n p = Polynomial.eval n q) : p.Cmp q N
- gt {p q : Poly} {N : ℕ} (h : ∀ n ≥ N, Polynomial.eval n q < Polynomial.eval n p) : p.Cmp q N
Instances For
Dependency graph
Every pair of a finite set of polynomials is decided from N on.
Equations
- WinRow.Decided V N = ∀ p ∈ V, ∀ q ∈ V, p.Cmp q N
Instances For
Dependency graph
Polynomial bags #
A relation computed on the instance with n copies is, for n large, a
bag of finitely many shapes: a row of polynomials, each repeated a
polynomial number of times.
Dependency graph
Dependency graph
The copies of a shape at n.
Equations
- s.inst n = Multiset.replicate (Polynomial.eval n s.mult) (s.rowAt n)
Instances For
Dependency graph
Dependency graph
The relation a bag of shapes stands for at n.
Instances For
Dependency graph
The polynomials the rows of a bag hold.
Instances For
Dependency graph
The multiplicities of a bag.
Instances For
Dependency graph
Scaling every multiplicity.
Equations
- WinRow.PolyBag.scale m L = List.map (fun (s : WinRow.Shape k) => { mult := m * s.mult, row := s.row }) L
Instances For
Dependency graph
Mapping the rows.
Equations
- WinRow.PolyBag.mapRows f L = List.map (fun (s : WinRow.Shape k) => { mult := s.mult, row := f s.row }) L
Instances For
Dependency graph
A bag of shapes under each shape, as an apply reads its right side.
Equations
- L₁.bindShapes F = List.flatMap (fun (s : WinRow.Shape k₁) => List.map (fun (t : WinRow.Shape k₂) => { mult := s.mult * t.mult, row := Fin.append s.row t.row }) (F s)) L₁
Instances For
Dependency graph
Symbolic terms, and the shift from the threshold #
A function-free term over a row of polynomials is a polynomial. A
predicate over decided polynomials reads alike at the threshold and at
every larger n, because the values at n are the image of the values
at the threshold under a faithful map (Provenance.Genericity).
Dependency graph
The constants of a query as polynomials.
Equations
- WinRow.Cset A = (fun (a : ℕ) => Polynomial.C a) '' ↑A
Instances For
Dependency graph
The polynomial a function-free term reads as.
Equations
- WinRow.TermIn.polyOf (TermIn.const a) row cγ = Polynomial.C a
- WinRow.TermIn.polyOf (TermIn.outer j) row cγ = cγ j
- WinRow.TermIn.polyOf (#j) row cγ = row j
- WinRow.TermIn.polyOf t row cγ = 0
Instances For
Dependency graph
The polynomial a function-free term of the general syntax reads as.
Equations
- WinRow.TermGIn.polyOf (TermGIn.const a) row cγ = Polynomial.C a
- WinRow.TermGIn.polyOf (TermGIn.outer j) row cγ = cγ j
- WinRow.TermGIn.polyOf (TermGIn.index j a) row cγ = row j
- WinRow.TermGIn.polyOf (TermGIn.provIndex j a) row cγ = row j
- WinRow.TermGIn.polyOf t row cγ = 0
Instances For
Dependency graph
The polynomial a function-free projection column reads as.
Equations
- WinRow.ProjColIn.polyOf (ProjColIn.term t) row cγ = WinRow.TermGIn.polyOf t row cγ
- WinRow.ProjColIn.polyOf (ProjColIn.token j a) row cγ = row j
- WinRow.ProjColIn.polyOf (ProjColIn.aggTerm k_1 a a_1) row cγ = 0
- WinRow.ProjColIn.polyOf (ProjColIn.aggTermOf j a t) row cγ = WinRow.TermIn.polyOf t (fun (i : Fin 0) => i.elim0) fun (x : Fin 1) => row j
- WinRow.ProjColIn.polyOf (ProjColIn.provTerm t) row cγ = WinRow.TermGIn.polyOf t row cγ
Instances For
Dependency graph
The count polynomials of a query #
A polynomial is a count polynomial of a query if, for n large, its
value is one of the counts the query computes on the instance with n
copies (AggQueryIn.countValsAll, over every context). There are finitely
many, because the counts a query computes on that instance are at most a
constant in number (AggQueryIn.exists_polyBound_countTypes over a base
set of constant size).
The count polynomials of a closed query.
Equations
- WinRow.CountPolys q = {p : WinRow.Poly | ∃ (N : ℕ), ∀ n ≥ N, Polynomial.eval n p ∈ q.countValsAll (WinRow.dRep n)}
Instances For
Dependency graph
The count polynomials of a term with a hole, over every binding of it.
Equations
- WinRow.CountPolysHole q s m = {p : WinRow.Poly | ∃ (N : ℕ), ∀ n ≥ N, ∃ (X : Relation ℕ m), Polynomial.eval n p ∈ q.countValsAll (Database.assign s X (WinRow.dRep n))}
Instances For
Dependency graph
The base set of the instance family: the instance's value, the zero, and the query's constants.
Equations
- WinRow.baseSet A = insert 0 (insert 1 A)
Instances For
Dependency graph
The invariant's vocabulary #
The values a closed query may write at a context of polynomials: its constants, the instance's value, the context, and its counts.
Equations
- WinRow.Univ q cγ = WinRow.Cset q.allConsts ∪ {1} ∪ Set.range cγ ∪ WinRow.CountPolys q
Instances For
Dependency graph
The same for a term with a hole, its counts taken over every binding.
Equations
- WinRow.UnivHole q s m cγ = WinRow.Cset q.allConsts ∪ {1} ∪ Set.range cγ ∪ WinRow.CountPolysHole q s m
Instances For
Dependency graph
The invariant for a closed query: for n large its result on the
instance with n copies is a bag of shapes, with values in Univ, and
whether it settles there does not depend on n.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The invariant for a term with a hole: uniformly in the bag the hole is bound to, provided its values lie in a given finite set.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
Bag lemmas the cases need #
Every multiplicity is the zero polynomial: the bag is empty at every n ≥ 1.
Instances For
Dependency graph
Duplicate elimination at the threshold: one copy of each row the
shapes of non-zero multiplicity have at N, the last of them kept.
Equations
Instances For
Dependency graph
Universe bookkeeping #
Counting the rows of a bag #
The invariant #
The row #
Windows are needed: win is in every basis of the whole algebra over ℕ
with the counting aggregate.