Joins¶
A rule body \(r_1(\bar x_1), \dots, r_m(\bar x_m)\) is a conjunctive query over \(n\) variables.
body_query reads it off a
Rule: each premise is an atom whose attributes are the variables of its
pattern, and relations makes each atom's relation from the
items of its form that match the pattern, keyed by the values of those variables. Matching flattens
nested constructor patterns and literals; it determines the item from its tuple, since the item's
arguments are the pattern evaluated there. A premise with a sum of two variables, such as
\(u(i + k)\), is refused: its matches are not a relation of its items alone.
Two questions are asked of a body, and they have different algorithms.
| question | algorithm | cost | status |
|---|---|---|---|
| every instance (a forest, requested evidence) | generic_join |
\(O(N + m\,n\,\mathrm{AGM})\) | worst-case optimal in data complexity (GENERIC_JOIN_WORK) |
| sum of products, grouped by the conclusion | eliminate |
\(O(N + n\,m\,W + F)\) for the chosen order | conditional on the exponential time hypothesis (ELIMINATION_WORK) |
| the same, for weights that keep their order | enumerate_aggregate |
that of generic_join |
the products need every instance in premise order |
Listing instances¶
For weights \(x_e \ge 0\) on the atoms with \(\sum_{e \ni v} x_e \ge 1\) for every variable \(v\) (a
fractional edge cover), the join has at most \(\mathrm{AGM} = \prod_e N_e^{x_e}\) tuples, and for
every query and sizes there are relations attaining it up to a constant factor (Atserias, Grohe
and Marx 2013). agm_bound solves the linear program that
minimizes \(\sum_e x_e \log N_e\), rounds its solution to rationals and repairs any variable left
uncovered, so the recorded AGMBound is an exact cover and
its bound holds whether or not it is the least. For the triangle at equal sizes it is
\(x = (\tfrac12, \tfrac12, \tfrac12)\) and \(N^{3/2}\).
Generic Join (Ngo, Re and Rudra 2014) binds the variables in a fixed order. With the variables before \(v\) bound to \(t\), the values of \(v\) are the intersection, over the atoms containing \(v\), of the values their tries allow below \(t\); it iterates the smallest set and probes the others in expected constant time.
Theorem. Generic Join lists each instance once, and iterates at most \(n\,\mathrm{AGM}\) values and makes at most \(m\,n\,\mathrm{AGM}\) probes.
Proof. A binding is extended at depth \(d\) exactly when its first \(d\) variables agree with a tuple of every atom on the variables they share, so each complete binding is an instance and each instance is reached by one path, the values of its variables in order. Let \(v\) be the variable at depth \(d\) and \(E_v\) the atoms containing it. For a prefix \(t\) of the first \(d - 1\) variables, the values iterated are \(\min_{e \in E_v} |R_e[t]|\), where \(R_e[t]\) is the set of values of \(v\) in the tuples of \(R_e\) that agree with \(t\). Since \(\sum_{e \in E_v} x_e \ge 1\), \(\min_e |R_e[t]| \le \prod_{e \in E_v} |R_e[t]|^{x_e}\), and summing over the prefixes that survive, Hölder's inequality bounds the total by the AGM bound of the first \(d\) variables under the restricted cover, which is at most \(\mathrm{AGM}\) because restriction and projection do not grow a relation (Ngo, Re and Rudra 2014, the analysis of Generic Join; Ngo, Porat, Re and Rudra 2018, theorem 5.1). Over \(n\) depths this gives \(n\,\mathrm{AGM}\) values, each probed in at most \(m - 1\) other sets. QED
The bound holds under the conditions stated in the claim: the rule is fixed and the relations grow (data complexity); attributes are flat after matching; hashing costs expected constant time; and the side condition, evaluated on each complete binding, filters the output and is outside the bound. Generic Join is worst-case optimal, not instance optimal: on some inputs another algorithm does less (Ngo, Porat, Re and Rudra 2018, section 7). The indexed chart of a plan joins one premise at a time, and on the triangle with a hub value or a skewed triangle that does \(\Theta(N^2)\) work against the \(N^{3/2}\) bound, which the checks measure.
Aggregates by elimination¶
For a commutative semiring the aggregate of a body, grouped by the conclusion's variables \(F\), is \(\bigoplus_{\bar y} w \otimes \bigotimes_e \phi_e\), the sum over the other variables \(\bar y\) of the products of the premise weights. Eliminating \(y\) joins the factors that contain it and sums it away:
Theorem. If \(\oplus\) is associative and commutative, \(\otimes\) is associative and commutative with unit, and \(\otimes\) distributes over \(\oplus\), every order of eliminating the variables of \(\bar y\) gives the aggregate.
Proof. The display is distributivity applied to the factors free of \(y\), after commuting them to the front; the result is a function of the remaining variables. Repeating it for each variable of the order, and joining the remaining factors over \(F\), gives the sum over \(\bar y\) of the products. Since \(\oplus\) is associative and commutative, summing the variables in one order or another, or all at once, gives the same value. QED
There is one aggregate, the sum, over the variables not in the conclusion; so every order of them
is semantically equivalent, the condition that FAQ needs for mixed aggregates (Abo Khamis, Ngo and
Rudra 2016) holds trivially, and no product aggregate arises. The laws used are
ELIMINATION_LAWS; each must be proved or decided by
the algebra's own claims, so a MatrixSemiring, whose
product does not commute, is refused, and its aggregate is taken by enumerate_aggregate, which
multiplies in premise order and needs only
ENUMERATION_LAWS.
A side condition reads some variables. When the first of them is eliminated, the factors covering all of them are joined into one bag, and the condition filters the bag before the variable is summed out; this is the elimination of the product of the factors with the condition's indicator, which is a factor over those variables. A condition on conclusion variables only filters the output.
Each EliminationStep records its bag and a fractional
cover of the bag by the body's atoms. The bag's join has at most that cover's bound of tuples,
since it lies in the projection of the body's join; the largest is \(W\) of the claim. The
Elimination records the order, the induced width (the
largest bag less one) and the fractional width (the largest cover weight). The order is chosen by
elimination_order, smallest bag first; finding an
order of least width is NP-hard (Arnborg, Corneil and Proskurowski 1987), so the widths are of the
chosen order and are not claimed least. Under the exponential time hypothesis, for classes of
bounded arity no algorithm beats treewidth by more than a logarithmic factor in the exponent (Marx
2010), which is why the claim's status is conditional.
On the star \(r_1(x, y_1), r_2(x, y_2), r_3(x, y_3)\) with one value of \(x\) of degree \(N\), there are \(N^3\) instances; elimination removes each \(y_i\) in a bag \(\{x, y_i\}\) and does linear work.
References¶
- Abo Khamis, M., Ngo, H. Q., and Rudra, A. (2016). FAQ: questions asked frequently. PODS, 13-28. doi:10.1145/2902251.2902280
- Arnborg, S., Corneil, D. G., and Proskurowski, A. (1987). Complexity of finding embeddings in a k-tree. SIAM Journal on Algebraic Discrete Methods 8(2), 277-284. doi:10.1137/0608024
- Atserias, A., Grohe, M., and Marx, D. (2013). Size bounds and query plans for relational joins. SIAM Journal on Computing 42(4), 1737-1767. doi:10.1137/110859440
- Marx, D. (2010). Can you beat treewidth? Theory of Computing 6, 85-112. doi:10.4086/toc.2010.v006a005
- Ngo, H. Q., Porat, E., Re, C., and Rudra, A. (2018). Worst-case optimal join algorithms. Journal of the ACM 65(3), 1-40. doi:10.1145/3180143
- Ngo, H. Q., Re, C., and Rudra, A. (2014). Skew strikes back: new developments in the theory of join algorithms. SIGMOD Record 42(4), 5-16. doi:10.1145/2590989.2590991
joins
¶
Joins of rule bodies: worst-case optimal for full output, elimination for aggregates.
A rule body is a conjunctive query. Each premise is an atom whose attributes are the variables of its pattern; an item of the premise's form that matches the pattern is a tuple of the atom's relation, so a nested constructor pattern is flattened into the variables of its slots. The side condition is a filter on the variables it reads.
generic_join lists every instance of the body, one variable at a time:
the values of a variable are the intersection, over the atoms that
contain it, of the values their tuples allow given the variables already
bound, found by iterating the smallest and probing the others. Its work
is at most the number of atoms and variables times the AGM bound of the
query (Ngo, Porat, Re and Rudra 2018, with the Generic Join of Ngo, Re
and Rudra 2014), and agm_bound computes that bound for a fractional
edge cover. The bound is tight in the worst case over inputs of the same
sizes (Atserias, Grohe and Marx 2013), so no algorithm listing the
output is better in data complexity; it is not instance optimal.
eliminate computes the sum, grouped by the conclusion's variables, of
the products of the premise weights, without listing the body's
instances: each variable that is summed out is removed by joining only
the factors that contain it and summing it away (InsideOut, Abo Khamis,
Ngo and Rudra 2016). Reordering products and sums this way needs a
commutative product that distributes over a commutative sum, so it is
refused for weights that keep their order. The order of elimination is
chosen by a greedy rule and recorded with its widths; it is not claimed
to be optimal, which is NP-hard to find.
References
Ngo, H. Q., Porat, E., Re, C., and Rudra, A. (2018). Worst-case optimal join algorithms. Journal of the ACM 65(3), 1-40. doi:10.1145/3180143
Ngo, H. Q., Re, C., and Rudra, A. (2014). Skew strikes back: new developments in the theory of join algorithms. SIGMOD Record 42(4), 5-16. doi:10.1145/2590989.2590991
Atserias, A., Grohe, M., and Marx, D. (2013). Size bounds and query plans for relational joins. SIAM Journal on Computing 42(4), 1737-1767. doi:10.1137/110859440
Abo Khamis, M., Ngo, H. Q., and Rudra, A. (2016). FAQ: questions asked frequently. PODS, 13-28. doi:10.1145/2902251.2902280
ELIMINATION_LAWS
module-attribute
¶
ELIMINATION_LAWS: tuple[Law, ...] = (PLUS_ASSOCIATIVE, PLUS_COMMUTATIVE, PLUS_UNIT, TIMES_ASSOCIATIVE, TIMES_COMMUTATIVE, TIMES_UNIT, DISTRIBUTIVE, ZERO_ANNIHILATES, JOIN_ITERATED)
The laws elimination reorders by: a commutative semiring on one domain.
Sums are regrouped and reordered, products are regrouped and reordered, a sum is moved inside the product of the factors that do not contain its letter, an absent term is the zero and annihilates its product, a sum over several axes is taken one axis at a time, and a product of no factors is the unit.
ENUMERATION_LAWS
module-attribute
¶
ENUMERATION_LAWS: tuple[Law, ...] = (PLUS_ASSOCIATIVE, PLUS_COMMUTATIVE, TIMES_ASSOCIATIVE)
The laws a sum of products in premise order uses.
GENERIC_JOIN_WORK
module-attribute
¶
GENERIC_JOIN_WORK = ComplexityClaim(query='every instance of one rule body', parameters=(ComplexityParameter(name='N', meaning="tuples of the atoms' relations"), ComplexityParameter(name='AGM', meaning='the bound of a fractional edge cover of the body'), ComplexityParameter(name='n', meaning='variables of the body'), ComplexityParameter(name='m', meaning='atoms of the body')), model=ALGEBRA_OPERATIONS, bounds=(ComplexityBound(phase=Phase.EXECUTION, resource='time', expression='N + m n AGM', status=ProvedOptimal(lower_bound='AGM in the worst case over relations of the same sizes', model=ALGEBRA_OPERATIONS, sources=(_AGM, _NPRR, _GENERIC))), ComplexityBound(phase=Phase.EXECUTION, resource='space', expression='N + n', status=ProvedOptimal(lower_bound='N', model=ALGEBRA_OPERATIONS, sources=(_READ,)))), inapplicable=(PhaseInapplicable(phase=Phase.CONSTRUCTION, reason='the query is read off the rule in its size'), PhaseInapplicable(phase=Phase.DIFFERENTIATION, reason='instances are listed, not weighed'), PhaseInapplicable(phase=Phase.REFIT, reason='instances depend on the items only, not on weights')), conditions=('data complexity: the rule is fixed and the relations grow', 'a natural join over flat attributes; a nested constructor pattern is flattened by matching, and a sum of two variables is refused', 'the side condition filters the output and is outside the bound', 'expected constant-time hashing', 'worst-case optimal, not instance optimal'))
The cost of listing a rule body's instances by Generic Join.
ELIMINATION_WORK
module-attribute
¶
ELIMINATION_WORK = ComplexityClaim(query='sum of products of one rule body, grouped by its conclusion', parameters=(ComplexityParameter(name='N', meaning="tuples of the atoms' relations"), ComplexityParameter(name='W', meaning="the largest bound of a bag's cover over the chosen order"), ComplexityParameter(name='F', meaning='conclusions'), ComplexityParameter(name='n', meaning='variables of the body'), ComplexityParameter(name='m', meaning='atoms of the body')), model=ALGEBRA_OPERATIONS, bounds=(ComplexityBound(phase=Phase.EXECUTION, resource='time', expression='N + n m W + F', status=Conditional(hypothesis='the exponential time hypothesis: for classes of bounded arity no algorithm beats treewidth by more than a logarithmic factor in the exponent', sources=(_FAQ, _MARX))), ComplexityBound(phase=Phase.EXECUTION, resource='space', expression='N + W + F', status=Conditional(hypothesis='as for time', sources=(_FAQ,))), ComplexityBound(phase=Phase.DIFFERENTIATION, resource='time', expression='N + n m W + F', status=Conditional(hypothesis='as for execution', sources=(_FAQ,))), ComplexityBound(phase=Phase.DIFFERENTIATION, resource='space', expression='N + n m W + F', status=Conditional(hypothesis='the autograd tape holds every product and sum', sources=(_FAQ,)))), inapplicable=(PhaseInapplicable(phase=Phase.CONSTRUCTION, reason='the order is chosen from the rule in its size'), PhaseInapplicable(phase=Phase.REFIT, reason='a refit is one more elimination at the new weights')), conditions=('a commutative semiring on one domain sharing zero and one: the laws of ELIMINATION_LAWS, each proved or decided', 'not for weights that keep their order, effects, or algebras that are not semirings; those are summed by enumeration in premise order', 'the order is greedy and its widths are recorded; an order of least width is NP-hard to find and is not claimed', 'the side condition joins the factors covering its variables into one bag'))
The cost of aggregating a rule body by variable elimination.
JoinRefusal
¶
Bases: str, Enum
Why a join is refused.
JoinRefused
¶
JoinRefused(code: JoinRefusal, reason: str)
Bases: ValueError
A join is refused, with the reason.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
The kind of reason.
TYPE:
|
reason
|
The reason.
TYPE:
|
Source code in src/quivers/stochastic/joins.py
Atom
didactic-model
¶
Atom(*, premise: int, family: FamilyId = field(opaque=True, extras=OPAQUE_BY_VALUE), arguments: tuple[IndexTerm, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), variables: tuple[str, ...] = ())
Bases: ValueModel
One premise as a relation over its pattern's variables.
| PARAMETER | DESCRIPTION |
|---|---|
premise
|
The premise's position.
TYPE:
|
family
|
Its form.
TYPE:
|
arguments
|
Its pattern.
TYPE:
|
variables
|
The pattern's variables, in the query's order.
TYPE:
|
BodyQuery
didactic-model
¶
BodyQuery(*, rule: Rule = field(opaque=True, extras=OPAQUE_BY_VALUE), atoms: tuple[Atom, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), variables: tuple[str, ...] = (), free: tuple[str, ...] = (), filtered: tuple[str, ...] = ())
Bases: ValueModel
A rule body as a conjunctive query.
| PARAMETER | DESCRIPTION |
|---|---|
rule
|
The rule.
TYPE:
|
atoms
|
One per premise.
TYPE:
|
variables
|
Every variable of the premises, in order of first occurrence.
TYPE:
|
free
|
The variables of the conclusion, which an aggregate groups by.
TYPE:
|
filtered
|
The variables the side condition reads.
TYPE:
|
Relation
didactic-model
¶
Relation(*, atom: Atom = field(opaque=True, extras=OPAQUE_BY_VALUE), tuples: dict[tuple[Ground, ...], Item] = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: ValueModel
The tuples of one atom: each item matching it, by its variables' values.
Matching determines an item from its tuple, since the item's arguments are the pattern evaluated at the tuple.
| PARAMETER | DESCRIPTION |
|---|---|
atom
|
The atom.
TYPE:
|
tuples
|
Each tuple, over the atom's variables in order, and its item.
TYPE:
|
AGMBound
didactic-model
¶
AGMBound(*, variables: tuple[str, ...] = (), sizes: tuple[int, ...] = (), cover: tuple[Rational, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
A fractional edge cover and the size bound it gives.
For relations of sizes N_e and weights x_e >= 0 that cover
every variable (the weights of the atoms containing it sum to one or
more), the join has at most prod_e N_e^{x_e} tuples (Atserias,
Grohe and Marx 2013). The cover is exact rationals checked to cover;
it comes from a linear program minimizing the bound, and the bound
holds whether or not it is the minimum.
| PARAMETER | DESCRIPTION |
|---|---|
variables
|
The variables covered.
TYPE:
|
sizes
|
The relation sizes.
TYPE:
|
cover
|
The weight of each relation.
TYPE:
|
JoinWork
didactic-model
¶
JoinWork(*, iterated: int = 0, probes: int = 0, tuples: int = 0, outputs: int = 0, conditions: int = 0, products: int = 0, sums: int = 0)
Bases: ValueModel
Counters of a join.
| PARAMETER | DESCRIPTION |
|---|---|
iterated
|
Values iterated from the smallest set of each intersection.
TYPE:
|
probes
|
Membership tests in the other sets.
TYPE:
|
tuples
|
Partial and complete bindings extended.
TYPE:
|
outputs
|
Complete bindings produced.
TYPE:
|
conditions
|
Side conditions evaluated.
TYPE:
|
products
|
Products of the algebra computed.
TYPE:
|
sums
|
Sums of the algebra computed.
TYPE:
|
report
¶
report(phase: Phase) -> WorkReport
The counters as a work report.
| PARAMETER | DESCRIPTION |
|---|---|
phase
|
The phase they counted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
WorkReport
|
Values iterated and probes as key comparisons, the algebra's sums and products, each measured; a join divides nothing. |
Source code in src/quivers/stochastic/joins.py
JoinCounter
¶
Bases: TrieCounter
Mutable counters of a join, read out as a JoinWork.
Source code in src/quivers/stochastic/joins.py
EliminationStep
didactic-model
¶
EliminationStep(*, variable: str, bag: tuple[str, ...] = (), cover: AGMBound = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
One variable summed out.
| PARAMETER | DESCRIPTION |
|---|---|
variable
|
The variable.
TYPE:
|
bag
|
The variables of the factors joined to remove it.
TYPE:
|
cover
|
A fractional cover of the bag by the body's atoms.
TYPE:
|
Elimination
didactic-model
¶
Elimination(*, values: dict[Item, Tensor] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), algorithm: Literal['variable elimination', 'enumeration in premise order'], order: tuple[str, ...] = (), steps: tuple[EliminationStep, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), width: int = 0, fractional_width: Rational = field(default=Rational(numerator=0), opaque=True, extras=OPAQUE_BY_VALUE), work: JoinWork = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: ValueModel
The aggregate of a rule body, and how it was computed.
| PARAMETER | DESCRIPTION |
|---|---|
values
|
The sum, for each conclusion, of the rule weight times the product of the premise weights over the body's instances.
TYPE:
|
algorithm
|
TYPE:
|
order
|
The variables summed out, in order.
TYPE:
|
steps
|
Each step, with its bag and cover.
TYPE:
|
width
|
The largest bag less one, the induced width of the order.
TYPE:
|
fractional_width
|
The largest cover weight of a bag.
TYPE:
|
work
|
The counters.
TYPE:
|
body_query
¶
The conjunctive query of a rule body.
| PARAMETER | DESCRIPTION |
|---|---|
rule
|
The rule.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BodyQuery
|
Its query. |
| RAISES | DESCRIPTION |
|---|---|
JoinRefused
|
If a premise has a sum of two variables, whose matches are not a relation of the premise's items alone; or a premise has hypotheses. |
Source code in src/quivers/stochastic/joins.py
relations
¶
The relation of every atom over a set of items.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
The query.
TYPE:
|
items
|
The items; repeats count once.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of Relation
|
One per atom. |
Source code in src/quivers/stochastic/joins.py
agm_bound
¶
agm_bound(variables: Sequence[str], edges: Sequence[Sequence[str]], sizes: Sequence[int]) -> AGMBound
A fractional edge cover of variables by relations, and its bound.
| PARAMETER | DESCRIPTION |
|---|---|
variables
|
The variables to cover.
TYPE:
|
edges
|
The variables of each relation.
TYPE:
|
sizes
|
The size of each relation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AGMBound
|
A cover; with every size at least two, of least bound up to the rounding of the program's solution, which is then repaired to cover exactly. |
| RAISES | DESCRIPTION |
|---|---|
JoinRefused
|
If a variable is in no relation. |
Source code in src/quivers/stochastic/joins.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
generic_join
¶
generic_join(query: BodyQuery, tables: Sequence[Relation], presentation: RulePresentation, *, order: Sequence[str] | None = None, work: JoinCounter | None = None) -> Iterator[tuple[Binding, tuple[Item, ...]]]
Every instance of a rule body over the relations, by Generic Join.
Variables are bound one at a time in order; each takes the
values in the intersection, over the atoms containing it, of the
values their tries allow below the variables already bound. The side
condition filters each complete binding.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
The query.
TYPE:
|
tables
|
One relation per atom, in atom order.
TYPE:
|
presentation
|
The presentation, for the side condition.
TYPE:
|
order
|
The order of the variables; the query's by default.
TYPE:
|
work
|
Counters to add to.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
tuple of Binding and tuple of Item
|
Each instance's binding and its premise items in premise order. |
| RAISES | DESCRIPTION |
|---|---|
JoinRefused
|
If |
Source code in src/quivers/stochastic/joins.py
elimination_order
¶
elimination_order(query: BodyQuery) -> tuple[str, ...]
A greedy order of the variables to sum out: fewest neighbours first.
The order is quivers.core.elimination.elimination_order over the
atoms' variables and the side condition's, by the number of
variables of each bag, ties in the query's order. Finding an order
of least width is NP-hard, so this order's widths are recorded, not
claimed least.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
The query.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of str
|
The variables not in the conclusion, in elimination order. |
Source code in src/quivers/stochastic/joins.py
eliminate
¶
eliminate(query: BodyQuery, tables: Sequence[Relation], presentation: RulePresentation, algebra: OrderPreservingSemiring, weights: Mapping[Item, Tensor], *, like: Tensor, rule_weight: Tensor | None = None, order: Sequence[str] | None = None) -> Elimination
The aggregate of a rule body by eliminating its summed variables.
Each step joins the factors containing the variable (and, while the side condition is pending, the factors covering its variables, so that it filters the bag), sums the variable out, and replaces those factors by the result. What is left, over the conclusion's variables, is joined and multiplied by the rule weight.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
The query.
TYPE:
|
tables
|
One relation per atom.
TYPE:
|
presentation
|
The presentation, for the side condition.
TYPE:
|
algebra
|
The algebra.
TYPE:
|
weights
|
The weight of each premise item; a missing one is the unit.
TYPE:
|
like
|
The dtype and device of the unit.
TYPE:
|
rule_weight
|
The rule's weight; the unit by default.
TYPE:
|
order
|
The variables to sum out, in order;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Elimination
|
The weight of each conclusion, the order, and its widths. |
| RAISES | DESCRIPTION |
|---|---|
JoinRefused
|
If the algebra does not establish |
Source code in src/quivers/stochastic/joins.py
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | |
enumerate_aggregate
¶
enumerate_aggregate(query: BodyQuery, tables: Sequence[Relation], presentation: RulePresentation, algebra: OrderPreservingSemiring, weights: Mapping[Item, Tensor], *, like: Tensor, rule_weight: Tensor | None = None, order: Sequence[str] | None = None) -> Elimination
The aggregate of a rule body by listing its instances.
Each instance's product is taken in premise order, then the rule
weight, as a derivation's factors are read, so the product need not
commute; the cost is that of
generic_join, the number of instances at worst.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
The query.
TYPE:
|
tables
|
One relation per atom.
TYPE:
|
presentation
|
The presentation, for the side condition.
TYPE:
|
algebra
|
The algebra.
TYPE:
|
weights
|
The weight of each premise item; a missing one is the unit.
TYPE:
|
like
|
The dtype and device of the unit.
TYPE:
|
rule_weight
|
The rule's weight; the unit by default.
TYPE:
|
order
|
The join's variable order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Elimination
|
The weight of each conclusion. |
| RAISES | DESCRIPTION |
|---|---|
JoinRefused
|
If the algebra does not establish |
Source code in src/quivers/stochastic/joins.py
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 | |