Cyclic systems¶
A plan whose recursion contract is LinearCyclic and whose
algebra is a Star solves its system component by component.
solve builds the derived hypergraph as a
packed forest, splits it into
strongly connected components by
components, visits them so that every premise outside
a component is final first, and solves each one through the algebra's closure. Each
Component records the side it was solved on.
The system of a component¶
Inside a component every edge must have at most one premise in the component; an edge with two is refused as nonlinear. With the products read in premise order and the rule weight last, an edge concluding \(x\) whose premise in the component is \(y\), at position \(k\), contributes
where every \(v(p_i)\) other than \(v(y)\) is final. Whether a coefficient is the unit is decided by the rule, not by the numbers: \(a\) is the unit when \(y\) is the first premise, and \(c\) when \(y\) is the last and the rule has no weight. The remaining edges and the inputs give the constant term \(b(x)\).
Theorem (one-sided solutions). Let the algebra be a Star, whose
closure \(A^* = I \oplus A \oplus A^2 \oplus \cdots\) is the sum of the weights of all paths and the
least solution of \(X = I \oplus A X\) on its declared domain (Lehmann 1977). If every edge of a
component has \(c\) the unit, the value of each item of the component, the sum over its derivations
of their products, is \((M^* b)_x\) with \(M_{xy} = \bigoplus a\) over its edges from \(y\) to \(x\). If
every edge has \(a\) the unit, it is \((b N^*)_x\) with \(N_{yx} = \bigoplus c\). Neither needs the
product to commute.
Proof. In the right-linear case a derivation of \(x\) is a path \(x = x_0 \leftarrow x_1 \leftarrow \cdots \leftarrow x_m\) of edges inside the component, followed by a derivation of a term of \(b(x_m)\). Each edge's coefficient \(a\) stands to the left of the value it multiplies and its \(c\) is the unit, so the product of the derivation is \(a_1 \otimes \cdots \otimes a_m \otimes \beta\) with \(\beta\) that term's product, the coefficients in the order of the path. By distributivity, summing over the edges of each step and the terms of \(b\) gives \((M^m b)_x\) for the paths of length \(m\), and over every length \(\bigoplus_m (M^m b)_x = (M^* b)_x\), the closure's series. It solves \(v = b \oplus M v\), since \(M^* = I \oplus M M^*\). In the left-linear case each \(c\) stands to the right, the product is \(\beta \otimes c_m \otimes \cdots \otimes c_1\), and the sum is \((b N^*)_x\) by the mirror argument. QED
Outside the closure's domain the series has no value; the algebra raises, and the run is refused.
Mixed sides. A component in which some edge has \(c\) not the unit and another (or the same) has
\(a\) not the unit multiplies its unknowns on both sides. With a commutative product,
\(a \otimes v \otimes c = (a \otimes c) \otimes v\), and the component is right linear with
\(M_{xy} = \bigoplus a \otimes c\); the record says "commuted". Without a claim that the product
commutes, established by the algebra's own evidence, no one-sided system describes it, and the run
is refused with mixed-sides, naming a rule multiplying on each side.
Refusals¶
PlanRefusal |
when |
|---|---|
inadmissible |
the algebra does not establish the closure's least-solution law |
nonlinear-cycle |
an edge has two premises in its own component |
mixed-sides |
a component multiplies on both sides of a product not established to commute |
divergent |
the closure lies outside the algebra's domain, or rounding cannot decide whether it does |
A divergent closure has no value: no partial sum is returned. The cost is
CYCLIC_WORK: the edges, plus \(S^3\) operations of the
algebra for a component of \(S\) items, which a ring would lower to \(S^\omega\).
Parallel unary steps in a span¶
The span executor gives each extra parallel step in a cyclic LogProb
closure its own auxiliary state. An arc of weight \(w\) from \(i\) to \(j\)
becomes a step of weight \(w\) from \(i\) to that state followed by a unit
step to \(j\). Every walk between original states has a unique expansion
of the same weight. Conversely, a walk between original states must
complete each passage through an auxiliary state. Thus the projected
star sums the original walks with their multiplicities. Differentiating
the projected result preserves each original coefficient's contribution
on the open domain of convergence.
The star receives the primitive weights, so a sum of parallel weights near one stays inside its rounding-aware convergence check. With \(N\) categories and \(d\) extra parallel steps, the star eliminates \(N+d\) states and its input matrix holds \((N+d)^2\) elements. The span report counts the augmented pivots and algebra operations. A cyclic span plan refuses a general resource budget, whose full limits the executor does not enforce.
Monotone polynomial systems¶
Under MonotonePolynomial a component may have
edges with several premises inside it. In an algebra with a
RealEmbedding, such as
MarkovAlgebra or
LogProbAlgebra, each item's real value is then a
polynomial with nonnegative coefficients in the component's items, \(x = f(x)\), whose coefficients
carry the values of the components below. Its least fixed point \(\mu\) lies in \([0, \infty]^n\)
(Etessami and Yannakakis 2009). solve_polynomial
solves the components one after another by Newton's method, the decomposed method of Etessami and
Yannakakis (2009, section 6), whose convergence Esparza, Kiefer and Luttenberger (2010) bound.
Theorem (lower bound). Let \(0 \le l \le \mu\), let \(J\) be the Jacobian of \(f\) at \(l\) with spectral radius below one, and let \(d\) satisfy \((I - J)\,d \le f(l) - l\). Then \(l + d \le \mu\).
Proof. Write \(\mu = l + e\) with \(e \ge 0\). A polynomial with nonnegative coefficients has \(f(l + e) \ge f(l) + J e\) (Taylor's expansion, every further term nonnegative), so \((I - J)\,e \ge f(l) - l \ge (I - J)\,d\). Since the spectral radius of \(J \ge 0\) is below one, \((I - J)^{-1} = \sum_k J^k \ge 0\), so \(e \ge d\). QED.
Each step solves \((I - J)\,d = f(l) - l\) in floating point, shortens \(d\), and then checks the two hypotheses in outward rounded arithmetic: \(J v < v\) for \(v = (I - J)^{-1} \mathbf 1 > 0\), which bounds the spectral radius below one (Collatz and Wielandt), and each row of \((I - J)\,d \le f(l) - l\), compared exactly in rationals. The coefficients enter by certified lower bounds, so the theorem holds of a system below \(f\) whose least fixed point is below \(\mu\). The iteration starts at \(l = 0\) and stops when no step moves \(l\), or when the budget's iterations are spent.
Upper bound. A point \(u\) with \(f(u) \le u\) is a pre-fixed point, and the least fixed point is the least pre-fixed point (Knaster and Tarski), so \(\mu \le u\). The candidate is \(u = e + t\,(I - J)^{-1}\mathbf 1\) above the floating estimate \(e\), for growing \(t\), checked with the coefficients' certified upper bounds. A component's interval \([l, u]\) thus holds \(\mu\), and the interval of an item above it holds its value because its coefficients' bounds come from the intervals below. The value returned is the estimate, inside its interval.
At a critical system, where the Jacobian at \(\mu\) has spectral radius one, the only pre-fixed points may be \(\mu\) itself: \(x = x^2/2 + 1/2\) has \(f(u) - u = (u - 1)^2/2\). No upper end then certifies, the run's report has no guarantee and names the spectral radius and the condition number \(\|(I - J)^{-1}\|_\infty\) at the estimate, and the contract refuses the value or returns it unestablished. A component with \(f(l) > l\) in every item has \(l < \mu\); below a finite least fixed point of a strongly connected clean system the spectral radius is below one (Esparza, Kiefer and Luttenberger 2010, section 4), so a spectral radius certified at least one there shows \(\mu\) infinite, and the plan refuses it as divergent.
Idempotent algebras. In an algebra without an embedding whose sum is idempotent, whose
product commutes and which has a Star, such as
TropicalAlgebra or
MaxPlusAlgebra, the Newton sequence is
\(\nu^{(0)} = f(0)\) and \(\nu^{(i+1)} = Df|_{\nu^{(i)}}^*\,(f(\nu^{(i)}))\) (Esparza, Kiefer and
Luttenberger 2010, Newtonian program analysis, Proposition 7.1), and for a system of \(n\)
variables \(\nu^{(n)} = \mu f\) (their Theorem 7.7), in the omega-continuous completion of the
weights. With a commutative product \(Df|_v\) is the matrix \(J(v)\) of formal derivatives, whose
repeated occurrences add to one occurrence, so each step is \(J(v)^* f(v)\) by the algebra's star on
its declared domain; a star outside it is refused, so a returned value is the completion's least
fixed point and lies in the carrier. Each component of \(n\) items takes \(n\) steps, and the report
states the result exact; a budget that ends the steps first leaves it without a guarantee.
Derivative. At the fixed point \(x = F(x, w)\) the implicit derivative is \(dx = (I - J)^{-1}\,\partial F / \partial w \; dw\), which exists when the spectral radius at \(\mu\) is below one; the solver certifies it from \(J(u)\,v < v\), since \(J\) grows with its argument. The value is returned as \(x + (I - J)^{-1}(F - F_{\text{detached}})\), which is \(x\) and has that derivative.
References¶
- Etessami, K., and Yannakakis, M. (2009). Recursive Markov chains, stochastic grammars, and monotone systems of nonlinear equations. Journal of the ACM 56(1), 1-66. doi:10.1145/1462153.1462154
- Esparza, J., Kiefer, S., and Luttenberger, M. (2010). Newtonian program analysis. Journal of the ACM 57(6), 33:1-33:47. doi:10.1145/1857914.1857917
- Esparza, J., Kiefer, S., and Luttenberger, M. (2010). Computing the least fixed point of positive polynomial systems. SIAM Journal on Computing 39(6), 2282-2335. doi:10.1137/090749591
- Lehmann, D. J. (1977). Algebraic structures for transitive closure. Theoretical Computer Science 4(1), 59-76. doi:10.1016/0304-3975(77)90056-1
recursion
¶
Cyclic systems, solved component by component: linear ones by the algebra's closure, monotone polynomial ones by decomposed Newton.
The derived hypergraph of a run is split into strongly connected
components, visited so that every premise outside a component is final
before the component is. Inside a component every edge has at most one
premise in the component, so with the products in premise order an edge
concluding x from y contributes a ⊗ v(y) ⊗ c, where a is
the product of the premises before y and c that of the premises
after it, then the rule weight. When every such edge has c the unit
the component is right linear, v = b ⊕ M v, and its least solution is
M* b; when every one has a the unit it is left linear,
v = b ⊕ v N, with least solution b N* (Lehmann 1977). Neither
needs the product to commute. Only a component that mixes the sides, or
has an edge with both coefficients, does: with a commutative product
a ⊗ v ⊗ c = (a ⊗ c) ⊗ v, and the component is right linear.
Whether a coefficient is the unit is decided by the rule, not by the
numbers: a is the unit when the premise is the first, c when it
is the last and the rule has no weight.
A monotone polynomial system, whose components may have edges with
several premises inside them, is solved in the reals of the algebra's
quivers.core.algebras.RealEmbedding by solve_polynomial: Newton's
method from zero on each component keeps a certified lower bound, a
pre-fixed point bounds it from above, both in outward rounded arithmetic,
and the value carries the implicit derivative of the fixed point. In an
algebra without an embedding whose sum is idempotent and which has a
star, each component of n items is solved exactly by n Newton
steps (Esparza, Kiefer and Luttenberger 2010, Newtonian program analysis,
theorem 7.7).
References
Etessami, K., and Yannakakis, M. (2009). Recursive Markov chains, stochastic grammars, and monotone systems of nonlinear equations. Journal of the ACM 56(1), 1-66. doi:10.1145/1462153.1462154
Esparza, J., Kiefer, S., and Luttenberger, M. (2010). Computing the least fixed point of positive polynomial systems. SIAM Journal on Computing 39(6), 2282-2335. doi:10.1137/090749591
Esparza, J., Kiefer, S., and Luttenberger, M. (2010). Newtonian program analysis. Journal of the ACM 57(6), 33:1-33:47. doi:10.1145/1857914.1857917
Lehmann, D. J. (1977). Algebraic structures for transitive closure. Theoretical Computer Science, 4(1), 59-76. doi:10.1016/0304-3975(77)90056-1
Side
¶
How a component is solved: no cycle, M* b, b N*, or M* b
after commuting both coefficients to the left.
CyclicRefusal
¶
Bases: str, Enum
Why a linear cyclic system has no solution here.
CyclicRefused
¶
CyclicRefused(code: CyclicRefusal, reason: str)
Bases: ValueError
A cyclic system is refused, with the reason.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
The kind of reason.
TYPE:
|
reason
|
The reason.
TYPE:
|
Source code in src/quivers/stochastic/recursion.py
CyclicWork
didactic-model
¶
Bases: QiecModel
The algebra's operations a cyclic solve performed.
| PARAMETER | DESCRIPTION |
|---|---|
sums
|
Sums, one per element summed into another.
TYPE:
|
products
|
Products, one per element.
TYPE:
|
pivots
|
States the closures eliminated, each a closure of one element.
TYPE:
|
exact
|
Operations of the closures' exact or enclosed decisions.
TYPE:
|
Component
didactic-model
¶
Component(*, items: tuple[Item, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), side: Side = 'none')
Bases: QiecModel
One strongly connected component of a run and how it was solved.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
Its items.
TYPE:
|
side
|
How it was solved.
TYPE:
|
Divergent
¶
Bases: ValueError
A monotone polynomial system whose least fixed point is infinite.
| PARAMETER | DESCRIPTION |
|---|---|
reason
|
The certificate of divergence.
TYPE:
|
Source code in src/quivers/stochastic/recursion.py
NewtonComponent
didactic-model
¶
NewtonComponent(*, items: tuple[Item, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), iterations: int = 0, spectral: float | None = None, condition: float | None = None, certified: bool = False, implicit: bool = False)
Bases: QiecModel
One strongly connected component solved by Newton's method.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
Its items.
TYPE:
|
iterations
|
Newton steps taken.
TYPE:
|
spectral
|
An estimate of the spectral radius of the Jacobian at the solution,
TYPE:
|
condition
|
TYPE:
|
certified
|
Whether both ends of every item's interval were certified.
TYPE:
|
implicit
|
Whether the spectral radius at the upper end is certified below one, so that the implicit derivative exists.
TYPE:
|
PolynomialSolution
didactic-model
¶
PolynomialSolution(*, values: dict[Item, Tensor] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), lower: dict[Item, float] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), upper: dict[Item, float] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), components: tuple[NewtonComponent, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), iterations: int = 0, sums: int = 0, products: int = 0, exact: int = 0, stopped: Literal['completed', 'budget'] = 'completed', decided: bool = False)
Bases: ValueModel
The least fixed point of a monotone polynomial system, with its enclosure.
| PARAMETER | DESCRIPTION |
|---|---|
values
|
The value of every item in the algebra, with the implicit derivative in its inputs.
TYPE:
|
lower
|
A certified lower bound of every item's real value.
TYPE:
|
upper
|
A certified upper bound,
TYPE:
|
components
|
The components, premises' components first.
TYPE:
|
iterations
|
Newton steps over all components.
TYPE:
|
sums
|
Sums of reals in point arithmetic.
TYPE:
|
products
|
Products of reals in point arithmetic.
TYPE:
|
exact
|
Operations in outward rounded arithmetic.
TYPE:
|
stopped
|
TYPE:
|
decided
|
Whether the values are exact, by Newton's method in an idempotent semiring; then there are no intervals.
TYPE:
|
components
¶
components(forest: DerivationForest) -> list[list[Item]]
The strongly connected components, premises' components first.
Tarjan's algorithm on the graph from each premise to its conclusion, without recursion. It emits a component after every component it reaches, so the reverse of its order puts premises first.
| PARAMETER | DESCRIPTION |
|---|---|
forest
|
The derived hypergraph.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of list of Item
|
The components, each in discovery order, premises' components before their conclusions'. |
Source code in src/quivers/stochastic/recursion.py
solve
¶
solve(forest: DerivationForest, algebra: OrderPreservingSemiring, inputs: Mapping[InputId, Tensor], *, like: Tensor) -> tuple[dict[Item, Tensor], tuple[Component, ...], CyclicWork]
The least solution of a linear system over a derived hypergraph.
| PARAMETER | DESCRIPTION |
|---|---|
forest
|
The derived hypergraph, every instance and input an edge.
TYPE:
|
algebra
|
The algebra; it is a
TYPE:
|
inputs
|
The weights.
TYPE:
|
like
|
The dtype and device of units and zeros.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of dict, tuple of Component and CyclicWork
|
The value of every item, each component with its side, and the algebra's operations of building each component's system, closing it (as the closure reports its own work) and applying the closure to the constants. |
| RAISES | DESCRIPTION |
|---|---|
CyclicRefused
|
If an edge has two premises in its component, a component mixes the sides without a commutative product, or a closure diverges or cannot be decided. |
TypeError
|
If the algebra has no closure. |
Source code in src/quivers/stochastic/recursion.py
370 371 372 373 374 375 376 377 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 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
solve_polynomial
¶
solve_polynomial(forest: DerivationForest, algebra: OrderPreservingSemiring, inputs: Mapping[InputId, Tensor], *, like: Tensor, budget: int | None = None) -> PolynomialSolution
The least fixed point of a monotone polynomial system, by decomposed Newton.
The derived hypergraph's strongly connected components are solved one
after another, premises' components first (Etessami and Yannakakis
2009, decomposed Newton's method; Esparza, Kiefer and Luttenberger
2010 for its convergence). In the reals of the algebra's embedding,
each item's value is the sum over its edges of the edge's weight times
its premises' values: a polynomial with nonnegative coefficients in
the component's items, whose coefficients carry the values of the
components below. Each component's Newton iteration starts at zero
and keeps a certified lower bound (_newton); a certified pre-fixed
point bounds it from above (_upper). The bounds of a component's
coefficients come from the bounds of the components below, so every
interval holds the exact least fixed point. The value returned is the
last iterate, inside its interval, and carries the implicit
derivative (I - J)^-1 dF of the fixed point in the inputs.
In an idempotent algebra with a star and no embedding, each component
of n items is solved exactly by n Newton steps instead
(_idempotent).
| PARAMETER | DESCRIPTION |
|---|---|
forest
|
The derived hypergraph, every instance and input an edge.
TYPE:
|
algebra
|
The algebra: a
TYPE:
|
inputs
|
The weights.
TYPE:
|
like
|
The dtype and device of units and zeros.
TYPE:
|
budget
|
The most Newton steps over all components;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PolynomialSolution
|
The values, their intervals, and the work. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the forest is not a derivation forest. |
CyclicRefused
|
If the product is not established to commute, the algebra has neither a real embedding nor an idempotent sum with a star, or a component's least fixed point is certified infinite. |
Source code in src/quivers/stochastic/recursion.py
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 | |