Operations¶
Summary
A builder of a stage is composed of primitive operators, and its card lists them under its operations, one row each, with what the row reads, what it writes and its rule. Every row of a card is of one of eight kinds. This page says which lines of a stage file form a row of each kind and in which builder it stands, and lists the operations of the package's table of definitions, the eight kinds and the one relation that is no kind, each with its defining expression, the operator of the Bellman calculus it denotes and the entry of the table that defines it.
Relationship with other documents
Formal account — Appendix E.3 Operators §4: the operator each kind realizes, with its domain and codomain. Builds on — The builders graphs and A builder: the builders, their cards and the names of their rows, printed from the package. See also — Shock distributions: what an expectation integrates against and a distribution extension extends a measure by; Methodization §2: the places at which a method may be typed.
Key terminology
| Term | What it names |
|---|---|
| Builder | The operator one block of a stage file denotes: backward on value functions, forward on finite measures of the states, such as their probability distribution. A builder is reached by the pair of perches it joins, stage.builder["cntn", "dcsn"], or from the perch its edge leaves, stage.dcsn.builder.bwd or stage.arvl.builder.fwd; the policy builder is stage.dcsn.builder.policy. |
| Card | What a builder, or one of the operators in it, prints: its inputs and outputs, its operations and the lines of the stage file they come from. print(stage.dcsn.builder.bwd) prints the card of the decision builder. |
| Row | One primitive operator of a builder, listed on the card under its operations with a number, a name, what it reads (in), what it writes (out) and its rule. |
| Grain | How far the boxes of a graph, the operators it holds, are opened: stage.builder.bwd holds one box per builder, and at the primitive grain, stage.builder.bwd.primitives, one box per primitive operator; see semgraph. |
| Kind | Which of the eight primitive operators a row is, named in the row's name after the builder or the line: Pullback in cntn_to_dcsn:Pullback. |
| Rule | The equation or relation a row states, printed under the row, read at a point of the row's domain. |
| Edge | The step from one perch to the next that one forward builder carries. |
| Law of motion | The map 𝑔 that a forward block's lines define, from the states of one perch, with the control and the shock where the block reads them, to the states of the next. |
| Value aggregator 𝐺 | The map a backward line applies pointwise to the functions it reads, its right side read as a function of them; see aggregation. |
| Policy | The function the policy builder writes, 𝑐 of the decision state. A builder stated at the policy reads it as a fixed function, which the builder's card names under At. |
| Declared carrier | The set of functions in which the stage declares an output to lie: from the states of its perch to the set its block's header declares for it, and for a policy only the functions whose values are feasible. |
1 Reading a row¶
A card lists the rows of a builder in the order in which they apply, each after every row whose output it reads. A row has a number, a name, what it reads, what it writes and its rule. The name is the builder, or the address of the line the row realizes, followed by the kind: cntn_to_dcsn:Pullback, policy.InvEuler:Aggregation, policy:Evaluation; the builder's own card leaves out the builder, InvEuler:Aggregation, Evaluation. Where one builder or one line holds several rows of one kind, a number, a label or the shocks the row concerns tell them apart, value:Expectation:1, arvl_to_dcsn:DistributionExtension:ψ. An input written as a number in brackets, (1), is the output of the row with that number. The API page on a builder, linked in the box above, prints the cards of cons.bl, the consumption stage of the portfolio application, and says how each entry of a card's Operations is read.
Five kinds stand in the backward builders, which act on functions, and three in the forward builders, which act on finite measures. Each builder is named below by the pair of perches it joins, as the title of its card prints it, cntn → dcsn for the decision builder, which stage.builder["cntn", "dcsn"] reads (The builders graphs §1); the policy builder is named by its own key, policy. The lines of a stage file form the rows of each kind as follows.
Pullback: the lines of a backward block that read functions of the later perch at the states of an earlier perch form one row that composes those functions with the law of motion of the forward block on the same edge,a = m_d - cincons.bl. Such a row stands incntn → dcsn, along 𝑔≻ read at the policy, and indcsn → arvl, along 𝑔≺; inpolicyone stands along 𝑔≻ where an objective or residuals that the builder constructs read such a function, as thesolve_{…}(…)line ofport.bldoes, and the identification line of §4 forms another, along the coordinate map 𝑚_d≻. Where the forward block branches, as inret_choice.bl, one such row stands for each branch,Pullback:workandPullback:retire, along the law of motion read at that branch's label,𝑔_work≻(a_d) = 𝑔≻(a_d, work). A policy line written at the continuation perch, its left side marked[>], such asc[>] <= 𝑑𝑢𝑖𝑛𝑣(D_{a}V[>]) ⟂ a >= 0in the methods file ofcons.bl, reads the function at the continuation states and forms none.Aggregation: the lines of a backward block that write its values together form one in the block's builder,dcsn → arvlorcntn → dcsn, each right side read as the value aggregator 𝐺 and printed as one equation of the row's rule, asV = 𝑢(c) + V[>]alone forms theAggregationofcntn → dcsnincons.bl. A derivative line of the same block,D_{m_d}V = 𝑑𝑢(c), forms no part of it: it states the derivative of the value the builder writes and stands at the builder'sEvaluation. In a policy block, or in the block of a methods file that brings the lines of a solution method to the policy builder (Methodization §5), adjacent explicit lines written at the continuation perch together form one, asc[>] = 𝑑𝑢𝑖𝑛𝑣(β*D_{a}V[>])andm[>] = a + c[>]of the blockpolicyof the buffer-stock methods file,applications/buffer-stock/declaration/stages/buffer_stock/methods.bl, formg_cntn_to_dcsn:Aggregation, and a line stating a relation, asolve_{…}(…)line and the objective of anargmax_{…}(…)line not marked!doceach form one, inpolicy(§4). In both kinds of block, a line that takes the expectation of an expression other than one function it reads forms one more for that expression,value:Aggregation:1ofdcsn → arvlin the buffer-stock stage file andfoc:Aggregation:1ofpolicyinport.bl. A derivative line forms none: the derivative line ofcntn → dcsninport.bl, which takes the expectation of such an expression, stands at the builder'sEvaluation, and the builder's card listsPullback,value:Expectation:1,AggregationandEvaluation. A line marked!nodeforms its own in its sub-builder and joins no other.Expectation: an occurrenceE_{θ}(·)in a line of a backward block forms one, one row per occurrence on the builder's card,value:Expectation:1; at the primitive grain of the whole graph,stage.builder.bwd.primitives, the box keeps the name of its line, prefixed by the id of its block,cntn_to_dcsn.value:Expectation:1inport.bl, which is the name the table below shows. Inpolicy, the objective of anargmax_{…}(…)line forms one where it holds an expectation, as inez_savings.bl.Argmax: anargmax_{…}(…)line of a policy block that is not marked!docforms one, inpolicy, asd = argmax_{d}(V_w[>] - δ, V_r[>])inret_choice.bl.Evaluation: no line forms one. It is the closing row of every backward builder, the policy builder among them, and of every sub-builder, the operator a line marked!nodedenotes, and it places each output in its declared carrier. On the card ofpolicyofcons.blits rule is the declared carrier with its feasibility,𝑐 : Xm → ℝ₊₊, 𝑐(m_d) ∈ Γ(m_d), since the relation that defines the function it carries is printed at the row that forms it,cons_choice:Pullback; the row's own card,stage.dcsn.builder.policy["Evaluation"], prints that relation underRule,𝑐(𝑚_d≻(a)) = 𝑐≻(a) on 𝑚_d≻(Xa).DistributionExtension: a~line declaring the distribution of a shock forms one, one row per declaration, in the forward builder whose block lists the shock among its inputs.PolicyInsertion: no line forms one, and no card shows one (§3).Pushforward: the lines of a forward block, which define its law of motion,a = m_d - cincons.bl, form one. It is the closing row of every forward builder,arvl → dcsnanddcsn → cntn, the latter along the law of motion read at the policy (§3).
2 The kinds and the relation¶
The table has one row for each operation that the package's table of definitions, PRIMITIVE_DEFINITIONS, defines, in that table's order: the eight kinds, and the relation that the rows of §4 read, which is no kind. The column operation names it, and kind of a row says whether a row of a card can be of it. written gives the first row of it on the stage files under applications/, read with cons.bl and port.bl of the portfolio application first: the lines of the file that the row realizes, as the row's card quotes them under Source, each on one line and without its annotation, then the row's name, the file and the builder that holds it, written as the key of stage.builder that reads it; where no stage file forms such a row, the cell says so. A pullback's card quotes the law of motion it composes along; an expectation's, the declaration of its shock's law and the line the expectation stands in; a distribution extension's, that declaration alone; and an Evaluation's, the derivative lines its block states, which form no part of the aggregation (§1). reads and writes gives what that row reads and writes, its in and out lines as its card prints them. rule gives that row's rule as the row's own card prints it, stated for the row's own functions, and §§1, 3 and 4 quote those of cons.bl; definition gives the operation's defining expression in the table of definitions, as the package prints it. denotes links to the section of Appendix E.3 that defines the operator the operation realizes. read from names the module, the table and the key of the definition, which states the defining map and its conditions exactly; primitive_definition in the same module returns the definition by its key.
| operation | kind of a row | written | reads and writes | rule | definition | denotes | read from |
|---|---|---|---|---|---|---|---|
Pullback |
yes | a = m_d - ccntn_to_dcsn:Pullback of applications/portfolio-choice/declaration/stages/cons/cons.bl, in the builder stage.builder["cntn", "dcsn"] |
in 𝑉≻ : Xa → [−∞, ∞)out 𝑉≻∘𝑔(·, 𝑐) : Xm → [−∞, ∞) |
(𝑉≻ ∘ 𝑔≻(·, 𝑐))(m_d) = 𝑉≻(𝑔≻(m_d, 𝑐(m_d))) |
v ↦ d ↦ v(g(d)) |
E.3 §4 Constituent operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Pullback" |
Aggregation |
yes | V = 𝑢(c) + V[>]cntn_to_dcsn:Aggregation of applications/portfolio-choice/declaration/stages/cons/cons.bl, in the builder stage.builder["cntn", "dcsn"] |
in 𝑉≻∘𝑔(·, 𝑐) : Xm → [−∞, ∞)out 𝑉 : Xm → [−∞, ∞) |
𝑉(m_d) = 𝑢(𝑐(m_d)) + 𝑉≻(𝑔≻(m_d, 𝑐(m_d))) |
w ↦ d ↦ G(w(d), d) |
E.3 §4 Constituent operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Aggregation" |
Expectation |
yes | (Ψ, θ) ~ LogNormal((μ_Ψ, μ_θ), ((σ_Ψ^2, ρ_ζ*σ_Ψ*σ_θ), (ρ_ζ*σ_Ψ*σ_θ, σ_θ^2)))V = E_{Ψ,θ}(V[>])cntn_to_dcsn.value:Expectation:1 of applications/portfolio-choice/declaration/stages/port/port.bl, in the builder stage.builder["cntn", "dcsn"] |
in 𝑉≻∘𝑔(·, 𝜍, ·, ·) : ℝ₊ × ℝ₊₊ × ℝ₊₊ → ℝout k_d ↦ E_{Ψ, θ}[𝑉≻(𝑔(k_d, 𝜍(k_d), Ψ, θ))] : ℝ₊ → ℝ |
value:Expectation:1(k_d) = E_{Ψ, θ}[𝑉≻(𝑔≻(k_d, 𝜍(k_d), Ψ, θ))] |
p ↦ h ↦ ∫_{z ∈ Z} [p[2](h, z)] p[1](h)(dz) |
E.3 §4 Constituent operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Expectation" |
Evaluation |
yes | D_{m_d}V = 𝑑𝑢(c)cntn_to_dcsn:Evaluation of applications/portfolio-choice/declaration/stages/cons/cons.bl, in the builder stage.builder["cntn", "dcsn"] |
in 𝑉 : Xm → [−∞, ∞)out 𝑉 : Xm → [−∞, ∞) |
𝑉(m_d) = 𝑢(𝑐(m_d)) + 𝑉≻(𝑔≻(m_d, 𝑐(m_d)))𝑉 : Xm → [−∞, ∞)D_{m_d}𝑉(m_d) = 𝑑𝑢(𝑐(m_d)) |
f ↦ f |
E.3 §4 Constituent operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Evaluation" |
Argmax |
yes | c = argmax_{cp : Γ(m_d)}(𝑢(cp) + V[>])policy.optimality:Argmax of applications/portfolio-choice/declaration/stages/cons/cons.bl, in the builder stage.builder.policy |
in (m_d, c) ↦ 𝑢(c) + 𝑉≻(𝑔(m_d, c)) : {m_d, c ∈ Xm × ℝ₊₊ | c ∈ Γ(m_d)} → [−∞, ∞)out {c ∈ (Xm → ℝ₊₊) | ∀ m_d ∈ Xm: (∀ c ∈ Γ(m_d): (policy.optimality:Aggregation(m_d, c(m_d)) ≥ policy.optimality:Aggregation(m_d, c)))} : 𝒫({c ∈ (Xm → ℝ₊₊) | c(m_d) ∈ Γ(m_d)}) |
𝑐(m_d) ∈ argmax_{cp ∈ Γ(m_d)} [𝑢(cp) + 𝑉≻(𝑔≻(m_d, cp))] |
q ↦ {pi ∈ {pi ∈ (X → C) | ∀ x ∈ X: (pi(x) ∈ Gamma(x))} | ∀ x ∈ X: (∀ c ∈ Gamma(x): (q(x, pi(x)) ≥ q(x, c)))} |
E.3 §4 Constituent operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Argmax" |
Relation |
no | no stage file under applications/ forms a row of this kind |
— | — | w ↦ {f ∈ F | ∀ d ∈ {d ∈ D | d ∈ A(w)}: (R(w, d, f(h(w, d))) = 1)} |
E.3 §7 Implicit and auxiliary operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Relation" |
Pushforward |
yes | m_d = marvl_to_dcsn:Pushforward of applications/portfolio-choice/declaration/stages/cons/cons.bl, in the builder stage.builder["arvl", "dcsn"] |
in μ≺ : finite measure on Xm × ℝ₊out μ : finite measure on Xm |
μ(B) = μ≺({m≺, l≺ ∈ Xm × ℝ₊ | 𝑔≺(m≺, l≺) ∈ B}) |
lambda ↦ measure on Y given by B ↦ lambda({measure-point ∈ D | g(measure-point) ∈ B}) |
E.3 §4 Constituent operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Pushforward" |
PolicyInsertion |
yes | no stage file under applications/ forms a row of this kind |
— | — | lambda ↦ measure on H given by B ↦ lambda({measure-point ∈ X | (x ↦ (x, pi(x)))(measure-point) ∈ B}) |
E.3 §4 Constituent operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "PolicyInsertion" |
DistributionExtension |
yes | (Ψ, θ) ~ LogNormal((μ_Ψ, μ_θ), ((σ_Ψ^2, ρ_ζ*σ_Ψ*σ_θ), (ρ_ζ*σ_Ψ*σ_θ, σ_θ^2)))dcsn_to_cntn:DistributionExtension:Ψ_θ of applications/portfolio-choice/declaration/stages/port/port.bl, in the builder stage.builder["dcsn", "cntn"] |
in μ : finite measure on ℝ₊out μ⊗P_{Ψ, θ} : finite measure on ℝ₊ × ℝ₊₊ × ℝ₊₊ |
μ⊗P_{Ψ, θ}(B)= ∫_{k_d ∈ ℝ₊} [P_{Ψ, θ}({Ψ, θ ∈ ℝ₊₊ × ℝ₊₊ | (k_d, Ψ, θ) ∈ B})] μ(dk_d) |
lambda ↦ measure on H × Z given by B ↦ ∫_{h ∈ H} [mu(h)({z ∈ Z | (h, z) ∈ B})] lambda(dh) |
E.3 §4 Constituent operations | typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "DistributionExtension" |
3 Rows at the policy¶
The backward decision builder and the forward decision builder are each stated at the policy: the law of motion, the value aggregator and any conditional distribution of a shock read the policy as a fixed function, and none of them takes the policy builder's output as an input. The law of motion read at the policy, the map m_d ↦ 𝑔≻(m_d, 𝑐(m_d)), which a card writes out where a rule reads it and names nowhere, holds the insertion of the policy: a Pushforward along it is the insertion followed by the push-forward along 𝑔≻, and a Pullback along it the pullback along 𝑔≻ followed by the insertion, as Appendix E.3 §4 states. That is why no card shows a PolicyInsertion row, while the table of definitions keeps the insertion as a kind.
On the cards of cons.bl, the Pullback of cntn → dcsn has the rule (𝑉≻ ∘ 𝑔≻(·, 𝑐))(m_d) = 𝑉≻(𝑔≻(m_d, 𝑐(m_d))) and its Aggregation the rule 𝑉(m_d) = 𝑢(𝑐(m_d)) + 𝑉≻(𝑔≻(m_d, 𝑐(m_d))), and the closing Pushforward of dcsn → cntn has the rule μ≻(B) = μ({m_d ∈ Xm | 𝑔≻(m_d, 𝑐(m_d)) ∈ B}). Each reads the policy 𝑐 as a fixed function.
4 Lines that state their output implicitly¶
In a policy block, a line may state its output only implicitly. Appendix C R8 and R10 state how such a line is read. In the methods file of cons.bl, applications/portfolio-choice/declaration/stages/cons/methods.bl, whose lines the operative policy builder holds (Methodization §5), the line m_d[>] = a + c[>] defines the coordinate map 𝑚_d≻, the cash on hand at each saving, and the identification line c = c[>] forms a Pullback whose rule equates the policy read along the coordinate map with the candidate policy 𝑐≻ at each saving, the grid relation 𝑐(𝑚_d≻(a)) = 𝑐≻(a) on 𝑚_d≻(Xa); a line stating a relation, c[>] <= 𝑑𝑢𝑖𝑛𝑣(D_{a}V[>]) ⟂ a >= 0, forms an Aggregation whose rule is that relation, 𝑐≻(a) ≤ 𝑑𝑢𝑖𝑛𝑣(D_{a}𝑉≻(a)) ⟂ a ≥ 0 on the card of policy; and a solve_{…}(…) line forms an Aggregation whose rule is its system of residuals. The identification row, the row of a solve_{…}(…) line and the row of a relation line that holds its output on both sides each denote the set of the functions that satisfy their rule at every point the row admits, which may be empty or hold several functions, and read the one relation definition of the same table, which is the definition of no kind; stage.dcsn.builder.policy["identification:Pullback"].signature() prints that set on the methodized stage. A relation line one of whose sides is the output's name alone and the other an explicit function of the row's inputs, as c[>] <= 𝑑𝑢𝑖𝑛𝑣(D_{a}V[>]) ⟂ a >= 0 in that methods file, is read by the definition of its kind, the relation with its clause standing as its rule. Its output is a correspondence, a map that gives each point a set of values, which a card writes with ⇉: the clause admits at each positive saving the one value 𝑑𝑢𝑖𝑛𝑣(D_{a}𝑉≻(a)) and at zero saving every value up to it (Appendix C, R10), so stage.dcsn.builder.policy["InvEuler:Aggregation"].signature() prints 𝑐≻ : Xa ⇉ ℝ₊₊. Its kernel() answers the map of the explicit side, 𝑑𝑢𝑖𝑛𝑣(D_{a}𝑉≻), and compile_kernel() compiles that map, the derivative term among the function's arguments, since 𝑑𝑢𝑖𝑛𝑣 is defined in closed form; a kernel that calls a function defined by a derivative or an inverse, 𝑑𝑢 := D_{c}(𝑢), is refused under kernel-form (Expression forms §3). No row selects a member of a set: a selection is the numerical method's.
5 Lines that form no row¶
Two kinds of line form no row. A line marked !doc states what the construction is meant to reach and prints under Declared, and a line attached to another by a dotted id is a property of that line: it forms no row, the row of that line holds it, and that row's own card lists the property line under Source. Methodization §3 states at which rows and builders a method may be bound, and stage.places() lists them for one stage.