μ^∪ from μ^⊎ #
A set recursion μ^∪R.(q₀, q₁) whose recursive term is L(R) ⊎ C, with
L reading R once under a projection, a selection, a product, the left
side of an apply (and nothing else), is simulated by a bag recursion
over pairs of a tuple and a counter: the base is (q₀ ⊎ C) × E^K for a
relation E of counters, and a round applies L to the tuple part of
every row and moves its counter to every strictly larger one (in the
lexicographic order of E^K). A row's counters then form a strictly
increasing chain, so the bag recursion ends after |E|^K rounds – it
always settles – and its rounds carry, as sets, the rounds of the set
recursion, which reach the fixpoint within |F| rounds, F the
fixpoint. So ε(Π_tuple(S)) = F as soon as |E|^K ≥ |F|
(AggQueryIn.evaluatePlain_simResult).
This module has the construction and its correctness for any counter
relation E of non-null values that is large enough. What E can be
read off the query is the other half: the values of the instance at the
recursion's leaves, its constants and the context, with two constants of
the domain (counterRel), and a width K fixed by the query. A count
inside the term takes values that no such set enumerates, which is where
the order-type lemma enters: the fixpoint is duplicate-free
over those values and the counts the recursion computes, of which there
are polynomially many (AggQueryIn.exists_card_bound_muSet in
Provenance.Genericity), so |F| ≤ |E|^K for a K read off that
polynomial.
Linear recursive terms #
The typing of a recursive term admits the recursive relation under a
⊎, with the other side
closed; the simulation needs the term without that side – which is the
q₁' half of the split the generation pass produces – and reading the
relation at a fixed arity.
A term reading the recursive relation s once, at arity n, and
linearly: under a projection, a selection on regular columns, either
side of a product or the left side of an apply, with the other side
closed. No ⊎: its closed side is the C of q₁ = L ⊎ C.
Equations
- AggQueryIn.recLinear s n (AggQueryIn.Rel x✝ a) = False
- AggQueryIn.recLinear s n (AggQueryIn.Hole x✝¹ s' x✝) = (s' = s ∧ x✝¹ = n)
- AggQueryIn.recLinear s n (AggQueryIn.Param pv x✝) = False
- AggQueryIn.recLinear s n AggQueryIn.Empty = False
- AggQueryIn.recLinear s n (AggQueryIn.Proj ps q) = AggQueryIn.recLinear s n q
- AggQueryIn.recLinear s n (AggQueryIn.Sel φ q hφ) = (φ.hasAggAtom = false ∧ AggQueryIn.recLinear s n q)
- AggQueryIn.recLinear s n (q₁.Prod q₂) = (AggQueryIn.recLinear s n q₁ ∧ l₂ = [] ∧ AggQueryIn.noMention s q₂ ∨ l₁ = [] ∧ AggQueryIn.noMention s q₁ ∧ AggQueryIn.recLinear s n q₂)
- AggQueryIn.recLinear s n (q₁.Apply q₂) = (AggQueryIn.recLinear s n q₁ ∧ AggQueryIn.noMention s q₂)
- AggQueryIn.recLinear s n (a.Sum a_1) = False
- AggQueryIn.recLinear s n (AggQueryIn.Explode k a q) = AggQueryIn.recLinear s n q
- AggQueryIn.recLinear s n (AggQueryIn.Retag h q) = AggQueryIn.recLinear s n q
- AggQueryIn.recLinear s n a.Dedup = False
- AggQueryIn.recLinear s n (a.Diff a_1) = False
- AggQueryIn.recLinear s n (AggQueryIn.Mu s_1 a a_1) = False
- AggQueryIn.recLinear s n (AggQueryIn.MuSet s_1 a a_1) = False
- AggQueryIn.recLinear s n (AggQueryIn.Gamma is ts fs a keep ord) = False
- AggQueryIn.recLinear s n (AggQueryIn.GammaScalar ts fs a ord) = False
- AggQueryIn.recLinear s n (AggQueryIn.GammaNest is his p f a) = False
- AggQueryIn.recLinear s n (AggQueryIn.ProvSum is his t a) = False
- AggQueryIn.recLinear s n (AggQueryIn.GammaTok is his ts fs a a_1 keep) = False
- AggQueryIn.recLinear s n (AggQueryIn.Win P O o w t f a a_1 dist keep) = False
- AggQueryIn.recLinear s n (AggQueryIn.WinExpr P O o ws ts fs g a keeps) = False
Instances For
Dependency graph
The rounds of a set recursion reach its fixpoint within its size #
Counters: strictly increasing chains in a finite order #
The bag of counters a row can hold after j moves: the whole set at
first, then the counters strictly above a counter of the previous round.
Equations
Instances For
Dependency graph
Replacing the recursive relation by a query #
The holes of a term, the recursive relation's taken out.
Instances For
Dependency graph
Dependency graph
Dependency graph
A term, its hole index rewritten.
Equations
- AggQueryIn.castIdx h q = h ▸ q
Instances For
Dependency graph
Admissibility of a selection's predicate survives taking a hole out.
Dependency graph
The recursive relation replaced by one row read off the context:
every hole of its name and arity becomes the parameter leaf reading pv,
at the hole's own kinds, so the holes of the result are the term's with
that one taken out; nothing else is touched.
Equations
- One or more equations did not get rendered due to their size.
- AggQueryIn.substRel s pv (AggQueryIn.Param pv' x✝) = AggQueryIn.Param pv' x✝
- AggQueryIn.substRel s pv (AggQueryIn.Proj ps q) = AggQueryIn.Proj ps (AggQueryIn.substRel s pv q)
- AggQueryIn.substRel s pv (AggQueryIn.Sel φ q hφ) = AggQueryIn.Sel φ (AggQueryIn.substRel s pv q) ⋯
- AggQueryIn.substRel s pv (q₁.Prod q₂) = AggQueryIn.castIdx ⋯ ((AggQueryIn.substRel s pv q₁).Prod (AggQueryIn.substRel s pv q₂))
- AggQueryIn.substRel s pv (q₁.Apply q₂) = (AggQueryIn.substRel s pv q₁).Apply q₂
- AggQueryIn.substRel s pv (q₁.Sum q₂) = AggQueryIn.castIdx ⋯ ((AggQueryIn.substRel s pv q₁).Sum (AggQueryIn.substRel s pv q₂))
- AggQueryIn.substRel s pv (AggQueryIn.Explode k hk q) = AggQueryIn.Explode k hk (AggQueryIn.substRel s pv q)
- AggQueryIn.substRel s pv (AggQueryIn.Retag hk q) = AggQueryIn.Retag hk (AggQueryIn.substRel s pv q)
- AggQueryIn.substRel s pv (AggQueryIn.Rel x✝ s') = AggQueryIn.Rel x✝ s'
- AggQueryIn.substRel s pv AggQueryIn.Empty = AggQueryIn.Empty
- AggQueryIn.substRel s pv q.Dedup = q.Dedup
- AggQueryIn.substRel s pv (q₁.Diff q₂) = q₁.Diff q₂
- AggQueryIn.substRel s pv (AggQueryIn.Mu s' q₀ q₁) = AggQueryIn.Mu s' q₀ q₁
- AggQueryIn.substRel s pv (AggQueryIn.MuSet s' q₀ q₁) = AggQueryIn.MuSet s' q₀ q₁
- AggQueryIn.substRel s pv (AggQueryIn.Gamma is ts fs q keep ord) = AggQueryIn.Gamma is ts fs q keep ord
- AggQueryIn.substRel s pv (AggQueryIn.GammaScalar ts fs q ord) = AggQueryIn.GammaScalar ts fs q ord
- AggQueryIn.substRel s pv (AggQueryIn.GammaNest is his p f q) = AggQueryIn.GammaNest is his p f q
- AggQueryIn.substRel s pv (AggQueryIn.ProvSum is his t q) = AggQueryIn.ProvSum is his t q
- AggQueryIn.substRel s pv (AggQueryIn.GammaTok is his ts fs a q keep) = AggQueryIn.GammaTok is his ts fs a q keep
- AggQueryIn.substRel s pv (AggQueryIn.Win P O o w t f q hrr dist keep) = AggQueryIn.Win P O o w t f q hrr dist keep
- AggQueryIn.substRel s pv (AggQueryIn.WinExpr P O o ws ts fs g q_1 keeps) = AggQueryIn.WinExpr P O o ws ts fs g q_1 keeps
Instances For
Dependency graph
The counters: a power of a unary relation, read lexicographically #
E^K, the K-fold product of a unary relation.
Instances For
Dependency graph
The values of a unary relation.
Equations
- AggQueryIn.unaryVals E = Multiset.map (fun (y : Tuple T 1) => y 0) E
Instances For
Dependency graph
The lexicographic order on the counters is a total order #
The relation the counters are sorted by.
Instances For
Dependency graph
And the strict one the rounds move along.
Instances For
Dependency graph
Equations
Dependency graph
Equations
Dependency graph
Dependency graph
Dependency graph
Dependency graph
Dependency graph
The construction #
The columns of the right side of the apply the round is built on.
Equations
- AggQueryIn.dropLeft n K w j = w (Fin.natAdd (n + K) j)
Instances For
Dependency graph
The tuple part of a row of the simulation.
Equations
- AggQueryIn.leftPart n K u i = u (Fin.castAdd K i)
Instances For
Dependency graph
Dependency graph
The current row's tuple part, read off the outer columns of the apply: the parameters a hole of the recursive term is replaced by.
Equations
- AggQueryIn.rowPv n K i = Sum.inr (Fin.castAdd c (Fin.castAdd K i))
Instances For
Dependency graph
The counter moves up: the row's counter is strictly above the current row's, lexicographically.
Equations
- AggQueryIn.ltSel n K = (OrderSpec.asc K).ltPredOn (fun (k : Fin K) => TermGIn.outer (Fin.castAdd c (Fin.natAdd n k))) (fun (k : Fin K) => TermGIn.index k ⋯) (List.finRange K)
Instances For
Dependency graph
One round of the simulation: for each row of the recursive relation, the term at the row's tuple part, paired with every counter above the row's.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The simulation, and what it computes #
The product of two relations, as the bag of appended rows.
Equations
- AggQueryIn.pairRel A M = A.bind fun (a : Tuple T n) => Multiset.map (fun (m : Fin K → T) => Fin.append a m) M
Instances For
Dependency graph
The simulation: a bag recursion over rows pairing a tuple with a
counter, from (q₀ ⊎ C) × E^K, each round applying the term to the
tuple part and moving the counter up.
Equations
- AggQueryIn.sim s s' n K EQ BQ L = AggQueryIn.Mu s' (BQ.prodA (EQ.pow K)) (AggQueryIn.simBody s s' n K EQ L)
Instances For
Dependency graph
Dependency graph
Duplicate elimination as a grouping by every column with no
aggregate: the shape the bases without ε use.
Equations
- q.dedupG = AggQueryIn.castKind ⋯ (AggQueryIn.Gamma (fun (k : Fin n) => k) (fun (j : Fin 0) => j.elim0) (fun (j : Fin 0) => j.elim0) q)
Instances For
Dependency graph
Its tuple parts, without duplicates: the set recursion's value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The term applied to one row of the recursive relation.
Equations
- AggQueryIn.rowTerm s n L D γ t = L.evaluatePlain (Database.assign s {t} D) γ
Instances For
Dependency graph
One round of the simulation, as a function of the recursive relation.
Equations
- AggQueryIn.simStep s s' n K EQ L D γ Y = (AggQueryIn.simBody s s' n K EQ L).evaluatePlain (Database.assign s' Y D) γ
Instances For
Dependency graph
The counters.
Equations
- EQ.counters K D γ = (EQ.pow K).evaluatePlain D γ
Instances For
Dependency graph
The set recursion's rounds, as the term iterated on the base #
The step of a set recursion μ^∪R.(B, L(R)) with L linear, as a
bag before the duplicate elimination.
Instances For
Dependency graph
The simulation computes the set recursion #
μ^∪ from μ^⊎ (the correctness of the construction): for a
set recursion μ^∪R.(q₀, q₁) whose term splits as
L ⊎ C with L linear, a base query computing q₀ ⊎ C, and a counter
relation E of non-null values with |E|^K at least the size of the
fixpoint, the simulation's tuples are the fixpoint, wherever the
recursion is defined.
Dependency graph
The counter relation #
The simulation runs its counter over E^K for a unary relation E of
non-null values with |E|^K at least the size of the fixpoint. E is
computed from what the fixpoint's values can be – the values of the base
(so of q₀ and of C), of the relations the term reads off the instance,
the term's constants and the context's values – with two constants of the
domain so that it holds at least two values, and a selection keeping the
non-null ones.
The sum of a list of queries.
Equations
- AggQueryIn.listSum [] = AggQueryIn.emptyRel n
- AggQueryIn.listSum (q :: l) = q.Sum (AggQueryIn.listSum l)
Instances For
Dependency graph
Column i of a query, as a unary relation.
Equations
- q.colRel i = AggQueryIn.castKind AggQueryIn.colRel._proof_1 (AggQueryIn.Proj (fun (x : Fin 1) => ProjColIn.term (TermGIn.index i ⋯)) q)
Instances For
Dependency graph
A constant, as a one-row unary relation.
Equations
- AggQueryIn.constRel a = AggQueryIn.castKind AggQueryIn.colRel._proof_1 (AggQueryIn.Proj (fun (x : Fin 1) => ProjColIn.term (TermGIn.const a)) AggQueryIn.unitC)
Instances For
Dependency graph
A context value, as a one-row unary relation.
Equations
- AggQueryIn.outerRel j = AggQueryIn.castKind AggQueryIn.colRel._proof_1 (AggQueryIn.Proj (fun (x : Fin 1) => ProjColIn.term (TermGIn.outer j)) AggQueryIn.unitC)
Instances For
Dependency graph
x IS NOT NULL, spelled x = x: the comparison is unknown exactly
at the null.
Equations
Instances For
Dependency graph
The unary relations the counter relation is the union of.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The counter relation: the non-null values among the columns of
B, the columns of the relations ls names, the constants cs and the
context's values.
Equations
- B.counterRel ls cs = AggQueryIn.Sel AggQueryIn.nonNullPred (AggQueryIn.listSum (B.counterParts ls cs)) ⋯
Instances For
Dependency graph
What the simulation is made of #
The structural facts the pass needs of the simulation: which classes it uses, that its recursion is restricted, its signature, its schema, its names. Each is read off its parts.
Bridges for the pass #
The set recursion replaced #
The simulation as the pass needs it: where the target classes hold no
μ^∪, a set recursion is replaced by
the simulation – its base the rewritten base and closed part summed, its
term the rewritten body, its counter the counter relation over the values
the fixpoint can hold – and the unions the counter relation is built with
go by the bag recursion afterwards.
The whole algebra with one recursion #
The basis of the whole algebra in the minimal universe: the
construction's classes and the windows, {∅, Π, σ, apply, γ, win, μ^⊎}.
basisRecOps_generatesOnRec says it generates, and
Provenance.RecursionBasisTheorem that no proper subset does.
Equations
Instances For
Dependency graph
μ^∪ is not needed, for every restricted term: over a schema
declaring finitely many names, every query of the
whole algebra in the minimal universe with restricted recursions is
matched over ∅, Π, σ, the apply, γ, win and μ^⊎ – defined
wherever the query is and equal to it there. A set recursion is simulated
by a bag recursion whose counter runs over the instance's values at the
recursion's leaves, the recursion's constants and its context: the
fixpoint is duplicate-free over those values and the counts the recursion
computes, of which there are polynomially many
(AggQueryIn.exists_card_bound_muSet, off the order types of
Provenance.Genericity), so a counter of a width fixed by the query
covers it. With the necessary classes (required_mem_of_generatesOnRec),
a basis of the whole algebra in the minimal universe is ∅, Π, γ,
μ^⊎, one of σ and −, one of ×
and the apply, and win (Provenance.WinRow); μ^∪ is in none.
Dependency graph
And without the window class, for the windows an apply derives
(evaluatePlain_winByApplyOf): the six classes ∅, Π, σ, the apply, γ and μ^⊎ match
every query of the whole algebra in the minimal universe whose windows
are derivable (AggQueryIn.WinsDerivable).