Substituting the outer columns #
The apply is defined by substitution: the right side of q₁ ⋈ᴬ q₂ is
read, for each row u of the left, as the closed query q₂[u]. The
evaluators of Provenance.AggQuery read it under an outer valuation
instead, which is what makes them structurally recursive. This module
defines the substitution and proves the two readings agree – in the plain
semantics for every substitution (AggQueryIn.evaluatePlain_subst), and in
the annotated one for a renaming (AggQueryIn.evaluate_substMap): an
aggregating operator records the values of the parameters it reads in the
family it stamps, and a constant put in a parameter's place is not read
as one.
substMap sends each outer position either to a value or to an outer
position of the target context. That generality is what the Apply case
of the recursion needs: the right side of an apply reads its left
neighbor's columns and the ambient outer ones, and closing the
ambient part must leave the neighbor's alone. Closing everything is the
special case subst.
The valuation a substitution induces #
Reading the source context through a substitution: an outer position sent to a value reads that value, one sent to an outer position of the target reads the target's valuation there.
Instances For
Dependency graph
Substitution on terms, predicates and projection columns #
Substitute the outer columns of a term.
Equations
- TermIn.substMap θ (TermIn.const a) = TermIn.const a
- TermIn.substMap θ (TermIn.outer k) = Sum.elim TermIn.const TermIn.outer (θ k)
- TermIn.substMap θ #k = #k
- TermIn.substMap θ (t₁.add t₂) = (TermIn.substMap θ t₁).add (TermIn.substMap θ t₂)
- TermIn.substMap θ (t₁.sub t₂) = (TermIn.substMap θ t₁).sub (TermIn.substMap θ t₂)
- TermIn.substMap θ (t₁.mul t₂) = (TermIn.substMap θ t₁).mul (TermIn.substMap θ t₂)
- TermIn.substMap θ (TermIn.caseWhen op t₁ t₂ t₃ t₄) = TermIn.caseWhen op (TermIn.substMap θ t₁) (TermIn.substMap θ t₂) (TermIn.substMap θ t₃) (TermIn.substMap θ t₄)
- TermIn.substMap θ (t₁.coalesce t₂) = (TermIn.substMap θ t₁).coalesce (TermIn.substMap θ t₂)
Instances For
Dependency graph
Substituting the outer columns reads no column of the row, so what a
term reads of them is unchanged – which is what a window's
WinReadsReg asks of its term.
Dependency graph
Substitute the outer columns of a generalized term.
Equations
- TermGIn.substMap θ (TermGIn.const a) = TermGIn.const a
- TermGIn.substMap θ (TermGIn.outer k) = Sum.elim TermGIn.const TermGIn.outer (θ k)
- TermGIn.substMap θ (TermGIn.index k h) = TermGIn.index k h
- TermGIn.substMap θ (TermGIn.provIndex k h) = TermGIn.provIndex k h
- TermGIn.substMap θ (TermGIn.cmpAgg k h op t) = TermGIn.cmpAgg k h op (TermGIn.substMap θ t)
- TermGIn.substMap θ (TermGIn.chiGate op t₁ t₂) = TermGIn.chiGate op (TermGIn.substMap θ t₁) (TermGIn.substMap θ t₂)
- TermGIn.substMap θ (t₁.add t₂) = (TermGIn.substMap θ t₁).add (TermGIn.substMap θ t₂)
- TermGIn.substMap θ (t₁.sub t₂) = (TermGIn.substMap θ t₁).sub (TermGIn.substMap θ t₂)
- TermGIn.substMap θ (t₁.mul t₂) = (TermGIn.substMap θ t₁).mul (TermGIn.substMap θ t₂)
- TermGIn.substMap θ (TermGIn.caseWhen op t₁ t₂ t₃ t₄) = TermGIn.caseWhen op (TermGIn.substMap θ t₁) (TermGIn.substMap θ t₂) (TermGIn.substMap θ t₃) (TermGIn.substMap θ t₄)
- TermGIn.substMap θ (t₁.coalesce t₂) = (TermGIn.substMap θ t₁).coalesce (TermGIn.substMap θ t₂)
Instances For
Dependency graph
Substitute the outer columns of a generalized predicate.
Equations
- GenPredIn.substMap θ (GenPredIn.cmp op t₁ t₂) = GenPredIn.cmp op (TermGIn.substMap θ t₁) (TermGIn.substMap θ t₂)
- GenPredIn.substMap θ (GenPredIn.aggCmp k h op t) = GenPredIn.aggCmp k h op (TermGIn.substMap θ t)
- GenPredIn.substMap θ (GenPredIn.aggRange k h op₁ t₁ op₂ t₂) = GenPredIn.aggRange k h op₁ (TermGIn.substMap θ t₁) op₂ (TermGIn.substMap θ t₂)
- GenPredIn.substMap θ (φ.and ψ) = (GenPredIn.substMap θ φ).and (GenPredIn.substMap θ ψ)
- GenPredIn.substMap θ (φ.or ψ) = (GenPredIn.substMap θ φ).or (GenPredIn.substMap θ ψ)
- GenPredIn.substMap θ φ.not = (GenPredIn.substMap θ φ).not
Instances For
Dependency graph
Dependency graph
Substitute the outer columns of a projection column.
Equations
- ProjColIn.substMap θ (ProjColIn.term t) = ProjColIn.term (TermGIn.substMap θ t)
- ProjColIn.substMap θ (ProjColIn.token k h) = ProjColIn.token k h
- ProjColIn.substMap θ (ProjColIn.aggTerm k h gf) = ProjColIn.aggTerm k h gf
- ProjColIn.substMap θ (ProjColIn.aggTermOf k h gf) = ProjColIn.aggTermOf k h gf
- ProjColIn.substMap θ (ProjColIn.provTerm t) = ProjColIn.provTerm (TermGIn.substMap θ t)
Instances For
Dependency graph
The substitution does not change an output column's kind.
Dependency graph
Substitution on queries #
The parameters a substituted operator reads: those the source's parameters are sent to.
Equations
Instances For
Dependency graph
Substitute the outer columns of a query. The right side of an apply reads its left neighbor's columns first and the ambient outer ones after, so the substitution passes under it by leaving the neighbor's block alone and shifting the ambient one.
Equations
- One or more equations did not get rendered due to their size.
- AggQueryIn.substMap θ (AggQueryIn.Rel n s) = AggQueryIn.Rel n s
- AggQueryIn.substMap θ (AggQueryIn.Hole n s κ) = AggQueryIn.Hole n s κ
- AggQueryIn.substMap θ (AggQueryIn.Param pv κ) = AggQueryIn.Param (fun (k : Fin n) => Sum.elim Sum.inl θ (pv k)) κ
- AggQueryIn.substMap θ AggQueryIn.Empty = AggQueryIn.Empty
- AggQueryIn.substMap θ (AggQueryIn.Proj ps q_2) = AggQueryIn.castKind ⋯ (AggQueryIn.Proj (fun (j : Fin n) => ProjColIn.substMap θ (ps j)) (AggQueryIn.substMap θ q_2))
- AggQueryIn.substMap θ (AggQueryIn.Sel φ q_2 hφ) = AggQueryIn.Sel (GenPredIn.substMap θ φ) (AggQueryIn.substMap θ q_2) ⋯
- AggQueryIn.substMap θ (q₁.Prod q₂) = (AggQueryIn.substMap θ q₁).Prod (AggQueryIn.substMap θ q₂)
- AggQueryIn.substMap θ (q₁.Sum q₂) = (AggQueryIn.substMap θ q₁).Sum (AggQueryIn.substMap θ q₂)
- AggQueryIn.substMap θ q_2.Dedup = (AggQueryIn.substMap θ q_2).Dedup
- AggQueryIn.substMap θ (q₁.Diff q₂) = (AggQueryIn.substMap θ q₁).Diff (AggQueryIn.substMap θ q₂)
- AggQueryIn.substMap θ (AggQueryIn.Explode k h q_2) = AggQueryIn.Explode k h (AggQueryIn.substMap θ q_2)
- AggQueryIn.substMap θ (AggQueryIn.Mu s q₀ q₁) = AggQueryIn.Mu s (AggQueryIn.substMap θ q₀) (AggQueryIn.substMap θ q₁)
- AggQueryIn.substMap θ (AggQueryIn.MuSet s q₀ q₁) = AggQueryIn.MuSet s (AggQueryIn.substMap θ q₀) (AggQueryIn.substMap θ q₁)
- AggQueryIn.substMap θ (AggQueryIn.Gamma is ts fs q_2 keep ord) = AggQueryIn.Gamma is (fun (j : Fin n₂) => TermIn.substMap θ (ts j)) fs (AggQueryIn.substMap θ q_2) keep ord
- AggQueryIn.substMap θ (AggQueryIn.GammaScalar ts fs q_2 ord) = AggQueryIn.GammaScalar (fun (j : Fin n) => TermIn.substMap θ (ts j)) fs (AggQueryIn.substMap θ q_2) ord
- AggQueryIn.substMap θ (AggQueryIn.GammaNest is his p f q_2) = AggQueryIn.GammaNest is his (ProjColIn.substMap θ p) f (AggQueryIn.substMap θ q_2)
- AggQueryIn.substMap θ (AggQueryIn.ProvSum is his t q_2) = AggQueryIn.ProvSum is his (TermGIn.substMap θ t) (AggQueryIn.substMap θ q_2)
- AggQueryIn.substMap θ (AggQueryIn.Retag h q_2) = AggQueryIn.Retag h (AggQueryIn.substMap θ q_2)
- AggQueryIn.substMap θ (AggQueryIn.Win P O o w t f q_2 hrr dist keep) = AggQueryIn.Win P O o w (TermIn.substMap θ t) f (AggQueryIn.substMap θ q_2) ⋯ dist keep
- AggQueryIn.substMap θ (AggQueryIn.WinExpr P O o ws ts fs g q_3 keeps) = AggQueryIn.WinExpr P O o ws (fun (l : Fin q_2) => TermIn.substMap θ (ts l)) fs g (AggQueryIn.substMap θ q_3) keeps
Instances For
Dependency graph
Close a query: give every outer column a value, written q[u].
Equations
- AggQueryIn.subst u q = AggQueryIn.substMap (fun (k : Fin c) => Sum.inl (u k)) q
Instances For
Dependency graph
Substituting a context of general values: a constant becomes a regular value.
Instances For
Dependency graph
The environment a substituted query is read in, seen from the source: its context substituted.
Instances For
Dependency graph
The two readings agree #
Substituting and evaluating is evaluating under the substituted valuation, for the plain semantics.
Dependency graph
Tokens under substitution #
The parameters a substituted query reads #
A family records the values of the parameters its operator reads, so a
substitution moves the family exactly when it moves those values. A
renaming – every outer column sent to an outer column, in order – moves
nothing: the substituted operator reads the renamed columns, which hold
the same values in the same order. That is the substitution an apply's
right side is read through (applyOuter). A substitution sending a
parameter to a constant does change the family: the constant is no
parameter of the substituted operator, so its value leaves the family.
A substitution that renames the outer columns, in order.
Equations
- IsRenaming θ = ∃ (e : Fin c → Fin d), StrictMono e ∧ ∀ (k : Fin c), θ k = Sum.inr (e k)
Instances For
Dependency graph
Substituting and evaluating is evaluating under the substituted valuation, for the annotated semantics.
Dependency graph
Closing a query: q[u] #
Evaluating a closed instance is evaluating under the values it was closed with, in the plain semantics.
Dependency graph
Plain counterpart: ⟦q₁ ⋈ᴬ q₂⟧ = {(u, v) ∣ u ∈ ⟦q₁⟧, v ∈ ⟦q₂[u]⟧}.
Dependency graph
Stripping commutes with substituting #
What an apply's right side reads of its left row #
A row with its annotation finalized, its columns kept: what every reading of an annotated evaluation reads of a row.
Instances For
Dependency graph
Substitution keeps a query well-kinded #
A substitution sends a parameter to a constant or to a parameter of the new context; it keeps the query well-kinded when it sends each parameter to one of the same kind, a constant being regular.