Rules and their code¶
Summary
Appendix C states the rules by which the equations of a stage file determine the objects of the Bellman calculus. This page lists each rule in one sentence, beside the functions of the package that carry it out and check it, the refusals that the package raises when a file breaks it, and a test that exercises it. It then names the section of the appendix that lists the rules that the package does not yet check, and it lists the refusal rules that other pages state. Every table is printed from the package's own table of the rules, so the page names the code as it stands.
Relationship with other documents
Builds on — Appendix C: the rules themselves, each with its statement and its assumptions; Refusals: every refusal rule, with the smallest example that breaks it. See also — Methodization, A piece and The factory API: three of the pages that state the rules of §5.
1 Reading the tables¶
§2 and §3 keep the numbers of Appendix C. §2 holds one table for each of its sections 2.1 to 2.5, which state the syntax of a stage file and the context in which its lines are read. §3 holds one table for each of its rules R1 to R12. A row states one rule in one sentence, and the appendix states the rule in full.
A refusal is the package's answer to a file that it does not read: it says where the fault is, what stands there, why it is refused and what to write instead, and it names the rule that the file breaks (Refusals §1). The columns of a table are these.
- implemented by names the functions that carry the rule out when the package reads a stage file.
- checked by names the functions that refuse a file that breaks the rule.
- refusals names the rules under which those functions refuse, each linked to its entry on the Refusals page.
- test names one test of the package that exercises the rule, by its file and its function, with the case in brackets where the function has several.
A dash in a column means that the row names nothing there. A rule with a dash under checked by is carried out by the package, and no file is refused under it. A checking function with a dash under refusals refuses without naming a rule, as calibrate refuses a value outside its declared set. A function whose name begins with an underscore is internal to its module.
§4 names the place that lists the rules that the language has and the package does not yet check: §5.3 of Appendix C, whose table gives for each rule what the package does today and the smallest text that shows it. That table is printed from the package's own tables, as this page is, so each of those rules stands once on the site.
§5 lists the refusal rules of the rules that other pages state, such as the rules of a methods file, each beside the page that states it.
Each function below is named by its module, as a path under packages/bellman/bellman/, and its qualified name. A public link to each definition is unavailable until an exported revision holds it.
2 Syntax and the typing context¶
2.1 Declarations¶
The rules of Appendix C §2.1.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
A declaration is a name, a colon and a type, and the type is a set, a role word or both, written with @ between them in either order. |
syntax/lower.py: ToAst.declarationtyping/declarations.py: Declarations.read_declaration, Declarations.classify |
syntax/parse.py: syntax_refusaltyping/declarations.py: Declarations.read_declaration, Declarations.classify |
syntax, readable-form, one-name-one-meaning, field-perch |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[readable-form] |
| A name, a named set, a function and the law of a shock are each declared once. | — | typing/declarations.py: Declarations.read_declaration, Declarations.read_space, Declarations.read_definition, Declarations.read_distribution |
declared-once |
— |
| Several sets in the type of one name declared at the top level declare their intersection, and at most one of them is no interval. | syntax/lower.py: intersection_of_sets, _one_setstage/calibration_requirements.py: _conditioned |
syntax/lower.py: _several_sets_refusaltyping/declarations.py: Declarations.classify |
syntax, readable-form |
packages/bellman/tests/test_refusals.pytest_a_form_the_parser_reads_but_the_language_does_not_is_refused_where_it_is_written[two sets of one type that are no intervals] |
The several sets in the type of one name have a number in common, which the package decides from the endpoints that are numbers or ratios of two integers, 1/3. |
— | syntax/lower.py: _several_sets_refusal |
syntax |
packages/bellman/tests/test_declared_sets.pytest_sets_with_ratio_endpoints_are_refused_only_where_they_leave_no_number_quoting_them |
| A name declared at the top level is a parameter where no block header lists it and a field where one does, and no line writes a parameter. | typing/declarations.py: Declarations.roles, Declarations.parameters |
typing/declarations.py: Declarations.roles, Declarations.check_writes_no_parameter |
parameter-or-field |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[parameter-or-field] |
| The value that a calibration gives a parameter lies in the set that the parameter's declaration names. | stage/calibration_requirements.py: membership |
stage/calibration_requirements.py: calibration_requirements |
— | packages/bellman/tests/test_calibration_and_settings.pytest_calibrate_refuses_a_value_outside_the_declared_set_of_its_parameter |
| A declared function binds its formal arguments, and its body reads its arguments, the names its operators bind and the names the stage declares. | typing/declarations.py: Declarations.read_definition, Declarations.resolve_definitionsfold/stage_fold.py: _statement_definitions |
typing/declarations.py: Declarations.check_definition_body, Declarations.check_definition_name, Declarations.check_definition_call, Declarations.resolve_definitions |
name-in-scope, definition-order |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[definition-order] |
| A named set may be a comprehension, whose bound name is local to the definition, and every set that a typing names is defined. | syntax/lower.py: ToAst.assignmenttyping/declarations.py: Declarations.read_space |
typing/declarations.py: Declarations.check_set_names |
name-in-scope |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[name-in-scope] |
A set marked !categories is a comprehension over ℤ or ℕ bounded by integers, and its annotation gives each member one category name. |
typing/category_codes.py: category_codes, describe |
fold/stage_fold.py: _set_categories, _coded_field_sites |
category-codes |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[category-codes] |
| A category name is no term of the file, and arithmetic reads the integer codes. | stage/kernels.py: compile_kernel |
typing/declarations.py: Declarations.check_names_in_scope |
name-in-scope |
packages/bellman/tests/test_category_codes.pytest_the_compiled_law_of_motion_and_value_aggregation_compute_with_the_integer_codes |
| A law statement gives its shock, or the shocks of a tuple subject jointly, one law. | typing/declarations.py: Declarations.read_distributiondistributions/edges.py: distribution_declarations, joint_distribution |
typing/declarations.py: Declarations.read_distribution |
declared-once, readable-form |
packages/bellman/tests/test_shock_expectations.pytest_an_expectation_over_both_shocks_of_a_joint_normal_law_integrates_the_joint_law |
| Separate law statements on one edge declare the product of their conditional laws, each given its parent shocks, and the product is recorded as a condition. | distributions/edges.py: dependency_order, joint_distribution, factorization_obligationfold/stage_fold.py: _distribution_obligations |
distributions/edges.py: dependency_order |
distribution-dependency |
packages/bellman/tests/test_shock_expectations.pytest_a_factorization_states_the_independence_of_separate_laws_and_none_in_a_hierarchy |
A declared name holds no colon and is none of the words result, declared and merged, which the identities of the stage's objects reserve. |
native/identity.py: refuse_colliding_name |
typing/declarations.py: Declarations.check_identity_collisions |
identity-collision |
packages/bellman/tests/test_parsing.pytest_a_name_that_would_collide_with_the_spelling_of_an_identity_is_refused_where_it_is_written |
| The set of a parameter, of a setting or of a derived parameter reads parameters, derived parameters, named sets and numbers, and no field; a shock is read inside an expectation over it where its law reads no field. | typing/declarations.py: Declarations.field_read_in_set |
typing/declarations.py: Declarations.check_parameter_sets |
readable-form |
packages/bellman/tests/test_declared_sets_at_calibration.pytest_the_set_of_a_parameter_is_refused_only_where_it_reads_a_field |
| Each endpoint of a parameter's set has a value at the calibration; a bound whose arithmetic has no value there refuses the calibration. | stage/calibration_requirements.py: _bound_at |
stage/calibration_requirements.py: judged |
— | packages/bellman/tests/test_declared_sets_at_calibration.pytest_a_bound_refuses_the_calibration_only_at_values_where_it_divides_by_zero |
| The set that a derived parameter's definition declares is a set of numbers that reads no setting, a definition that declares a set reads at least one parameter or derived parameter, by cases as otherwise, and no separate declaration of the name stands beside its definition. | typing/declarations.py: declared_definition, derived_parameter_declaration |
typing/declarations.py: Declarations.check_names, Declarations.read_declaration, Declarations.declared_value_refusal, Declarations.check_derived_parameters, Declarations.declared_set_fault |
one-name-one-meaning, readable-form, derived-parameter |
packages/bellman/tests/test_derived_parameters.pytest_a_definition_on_a_declared_set_in_a_form_that_the_language_does_not_read_is_refused |
A derived parameter's definition may call log and exp, each of one argument, and min and max, each of one argument or more, and a call of any other function, or of one of the four with another number of arguments, is refused. |
typing/declarations.py: derived_parameter_call, derived_parameter_bodyfold/derived_parameters.py: derived_value |
syntax/parse.py: syntax_refusaltyping/declarations.py: derived_parameter_fault, Declarations.check_derived_parameterstyping/context.py: TypingContext._typed_function |
derived-parameter, not-constructed, syntax |
packages/bellman/tests/test_derived_parameters.pytest_a_definition_may_call_min_max_log_and_exp_and_no_other_function |
A derived parameter's definition may be written by cases, if test then a else b, with or without a declared set. A formula by cases may also stand on the right side of an equation. The syntax refuses the form inside arithmetic, in a function's body and at a declared set endpoint. |
syntax/lower.py: ToAst.conditional, ToAst.declared_valuetyping/declarations.py: derived_parameter_body, derived_parameter_declaration |
syntax/parse.py: syntax_refusaltyping/declarations.py: derived_parameter_fault |
syntax |
packages/bellman/tests/test_derived_parameters.pytest_a_conditional_out_of_its_place_is_refused_with_the_advice_on_where_it_stands |
The words if, then and else are no names, and a file that writes one of them as a name, in a declaration, a definition, a binder, a block header or a formula, is refused. |
syntax/lower.py: ToAst.name |
syntax/lower.py: ToAst.namesyntax/parse.py: syntax_refusal |
syntax |
packages/bellman/tests/test_derived_parameters.pytest_if_then_or_else_written_as_a_name_is_refused_at_the_word |
In a derived parameter's definition log, exp, min and max are the functions of the language, and a definition that calls one of them where the stage defines a function of that name is refused. |
— | typing/declarations.py: derived_parameter_fault, Declarations.check_derived_parameters |
derived-parameter |
packages/bellman/tests/test_derived_parameters.pytest_a_derived_parameter_is_refused_at_its_definition[a call of min where the stage defines min] |
| The test of a definition by cases reads what a branch reads, parameters, derived parameters and finite numbers: a set, a field or a function there is refused, and so is a label of a finite set, as it is in arithmetic. | typing/context.py: TypingContext._typed_expression |
typing/context.py: TypingContext._numeric_argumentstyping/declarations.py: derived_parameter_fault |
well-typed, derived-parameter |
packages/bellman/tests/test_derived_parameters.pytest_a_label_in_the_test_of_a_definition_by_cases_is_refused_as_it_is_in_arithmetic |
A derived parameter's value is its definition evaluated at the calibration, which for a definition by cases is the branch that its test chooses, the other branch not evaluated, and a branch written inf or -inf gives that infinity; a definition that reads a name valued at an infinity where it is evaluated, in a formula, a call or a test, as the branch that its test chooses or as its whole right side, has no value, and the calibration is refused at that definition. |
fold/derived_parameters.py: derived_value, _conditional |
fold/derived_parameters.py: derived_values |
derived-parameter |
packages/bellman/tests/test_derived_parameter_values.pytest_calibration_computes_human_wealth_from_its_definition_and_keeps_no_value_of_it |
A branch written inf or -inf is admitted only in a definition whose declared set can hold that infinity, as the form of the set decides, and the set ℝ of a definition that declares none holds neither; calibration holds the value, finite or infinite, to the declared set. |
typing/declarations.py: infinities_writtensyntax/source.py: may_hold_infinity |
typing/declarations.py: infinite_branch_fault, Declarations.check_derived_parametersfold/derived_parameters.py: derived_orderstage/calibration_requirements.py: calibration_requirements |
derived-parameter |
packages/bellman/tests/test_derived_parameters.pytest_an_infinite_branch_is_admitted_only_where_its_declared_set_can_hold_it |
| An endpoint of an interval, or a side of a condition of a set, that is the bare name of a parameter or of a derived parameter valued at an infinity is read as that infinity. | stage/calibration_requirements.py: _infinite_value, _endpoint_at, _side_at, _infinity_in |
stage/calibration_requirements.py: membership, predicate_value |
— | packages/bellman/tests/test_derived_parameter_values.pytest_an_endpoint_that_is_the_bare_name_of_a_parameter_reads_as_its_value_finite_or_infinite |
A bound of a declared set may call log, exp, min and max, which calibration evaluates as in a derived parameter's definition, and a bound that computes with a name valued at an infinity, or with the written inf, has no value and refuses the calibration; a bound that calls another function is not decided, whatever it computes with. |
stage/calibration_requirements.py: _bound_at |
stage/calibration_requirements.py: judged |
— | packages/bellman/tests/test_derived_parameter_values.pytest_a_bound_that_calls_min_is_decided_at_calibration |
| An interval of numbers holds at least one number. | typing/sets.py: literal_faults |
typing/context.py: _refuse_literal_faults |
readable-form |
packages/bellman/tests/test_declared_sets.pytest_an_interval_of_numbers_that_holds_no_number_is_refused_and_one_of_one_number_is_read |
A difference of sets holds at least one number: one whose left side lies within its right side, (0,1) \ ℝ₊, is refused where the package's rules of inclusion decide it, and a difference inside a union is not judged. |
typing/sets.py: literal_faults, within |
typing/context.py: _refuse_literal_faults |
readable-form |
packages/bellman/tests/test_declared_sets.pytest_a_difference_is_refused_as_empty_only_where_its_left_side_lies_within_its_right |
2.2 Blocks and their headers¶
The rules of Appendix C §2.2.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| A block is a bracketed header, with one id and one signature, followed by its statements. | typing/declarations.py: Declarations.read_block, Declarations.block_header, Declarations.read_body_statement |
syntax/parse.py: syntax_refusaltyping/declarations.py: Declarations.block_header, Declarations.read_body_statement |
syntax, readable-form, not-constructed |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[syntax] |
| The id of a block names one block. | — | syntax/lower.py: parse_with_spanstyping/declarations.py: Declarations.check_block_id |
syntax, declared-once |
packages/bellman/tests/test_terms.pytest_addresses_follow_authored_identifiers_and_item_positions |
The perch word after a side places the coordinates that the side lists, and a mark [<] or [>] on a listing agrees with it. |
typing/declarations.py: Declarations.read_side, Declarations.perch_of, Declarations.perch_of_mark |
typing/declarations.py: Declarations.perch_of, Declarations.explicit_perch, Declarations.read_side |
field-perch, readable-form |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[field-perch] |
| A side omits its perch word only where each coordinate it lists that is no shock is placed by a mark, by its own perch word or as a control. | typing/declarations.py: Declarations.side_perch, Declarations.perches_of_side |
typing/declarations.py: Declarations.fields_and_header_sides |
field-perch |
— |
| A shock listed on a side is an argument of the edge and stands at no perch. | typing/declarations.py: Declarations.shock_perch, Declarations.note_shock |
typing/declarations.py: Declarations.shock_perch |
field-perch |
packages/bellman/tests/test_shock_expectations.pytest_the_printed_kernel_of_an_expectation_names_the_edge_that_draws_its_shocks |
| A control stands at the decision perch wherever a header lists it. | typing/declarations.py: Declarations.control_perch, Declarations.perches_of_side |
typing/declarations.py: Declarations.control_perch |
field-perch |
packages/bellman/tests/test_parsing.pytest_a_control_listed_at_the_arrival_perch_on_the_continuation_side_is_refused |
| A derivative line states the derivative of the value that its block writes, once for each derivative term, and adds no field and no output. | typing/line_unknowns.py: derivative_left_sidefold/backward.py: stated_derivatives |
typing/declarations.py: Declarations.check_stated_once |
defined-once |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[defined-once] |
2.3 Statements and annotations¶
The rules of Appendix C §2.3.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| A statement is an equation or an inequality with an optional annotation, and an id in the annotation names one line of its block. | typing/line_unknowns.py: annotation_entries, statement_id |
syntax/lower.py: parse_with_spanstyping/declarations.py: Declarations.check_line_idtyping/line_unknowns.py: annotation_entries |
syntax, declared-once, readable-form |
packages/bellman/tests/test_refusals.pytest_a_form_the_parser_reads_but_the_language_does_not_is_refused_where_it_is_written[two lines under one id] |
A statement marked !doc defines no equation of its block, and the binder of a documentary maximization declares the feasible set of its control. |
stage/construction.py: _line_rolefold/block_lines.py: doc_linesstage/carriers.py: _maximisationsfold/stage_fold.py: _selected_controls |
— | — | packages/bellman/tests/test_policy.pytest_the_doc_line_of_cons_forms_no_operation_of_its_policy_builder |
A statement marked !node is an authored node, which carries an id and forms an operator of its own. |
stage/construction.py: _statement_recordsfold/backward.py: sub_builder_rows |
stage/construction.py: _line_role |
declared-once |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[declared-once] |
The marker !categories is written only in the annotation of a named set. |
typing/category_codes.py: reserved_entries |
fold/stage_fold.py: _misplaced_marker |
category-codes |
packages/bellman/tests/test_category_codes.pytest_the_marker_of_categories_is_refused_on_a_field_declaration_a_function_a_line_or_a_header |
A clause after ⟂ carries one bound, written with the bounded quantity first, or, after an equation, two bounds in ascending order. |
typing/declarations.py: Declarations.clause_reads |
typing/declarations.py: Declarations.clause_reads |
readable-form |
packages/bellman/tests/test_constraints.pytest_a_malformed_multiplier_declaration_or_clause_is_refused_under_its_rule |
A multiplier is declared in the body of a block, once, by a name marked [>], one set and a clause with one bound. |
typing/declarations.py: Declarations.read_multiplier |
typing/declarations.py: Declarations.read_multiplier |
multiplier-declaration, readable-form |
packages/bellman/tests/test_constraints.pytest_a_malformed_multiplier_declaration_or_clause_is_refused_under_its_rule |
2.4 Forming the context¶
The rules of Appendix C §2.4.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| The context is formed from every declaration and every block side before any statement is read. | typing/declarations.py: Declarations.read, Declarations.fields_and_header_sidesstage/construction.py: stage_fields |
— | — | — |
| The declared set of a field is the intersection of the sets written for it at its declaration and at its listings. | stage/construction.py: _field_sortstyping/sets.py: meet |
— | — | packages/bellman/tests/test_declared_sets.pytest_a_field_carries_the_intersection_of_the_sets_of_its_listings |
| The set on which a block writes a field lies in the set on which each other block reads it. | typing/sets.py: within |
fold/declared_sets.py: check_declared_sets |
set-mismatch |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[set-mismatch] |
| A field has one perch, and a name has one role and one meaning: a field, a function, a named set, a shock or a parameter. | typing/declarations.py: Declarations.roles, Declarations.declared_as |
typing/declarations.py: Declarations.explicit_perch, Declarations.note_role, Declarations.check_names, Declarations.check_one_meaning |
field-perch, one-name-one-meaning |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[one-name-one-meaning] |
| A bare name that a line reads and the file declares nowhere is refused and is no parameter, and a call to a function that the file does not declare is read as external and recorded as a condition. | typing/declarations.py: Declarations.parametersfold/wire_terms.py: external_calls |
typing/declarations.py: Declarations.check_names_in_scope |
name-in-scope |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[name-in-scope] |
2.5 Binders, free names, and bound names¶
The rules of Appendix C §2.5.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
An expectation E_{y} integrates over a shock that has a declared law. |
typing/context.py: TypingContext._typed_operatortyping/line_unknowns.py: _references |
typing/line_unknowns.py: _referencestyping/declarations.py: Declarations.check_expectation_subjects |
not-constructed |
— |
The subscript of argmax or solve names the controls or the unknowns that its line determines, in the order of the line's left side. |
fold/policy.py: _chosen, _substitute_arguments |
fold/policy.py: _chosentyping/context.py: TypingContext._typed_line |
not-constructed, well-typed |
packages/bellman/tests/test_joint_choices.pytest_a_subscript_in_another_order_than_the_left_side_is_refused |
| A subscript binds each name once, and a name under nested operators is bound by the innermost. | typing/context.py: TypingContext._subscript, TypingContext._input_named |
typing/context.py: TypingContext._subscript |
declared-once |
packages/bellman/tests/test_refusals.pytest_a_fault_found_when_a_line_is_typed_is_refused_at_the_line_under_its_rule[a binder named twice] |
A derivative D_{c}(𝑢) of a function names one of its formal arguments, a scalar one. |
typing/context.py: TypingContext._binder_input |
typing/context.py: TypingContext._typed_operator, TypingContext._check_derivative_binder |
derivative-one-name, derivative-scalar-coordinate |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[derivative-one-name] |
| The expansion of a function puts the terms it is applied to for its formal arguments and captures no bound name. | typing/typed_expressions.py: substitute, renamed_bound |
— | — | packages/bellman/tests/test_shock_distributions.pytest_a_bound_variable_of_a_definition_is_primed_where_an_argument_reads_its_name |
3 The rules¶
R1 Blocks and their headers¶
The rules of Appendix C R1.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| The kind of a block, a forward transition, a backward value block or a policy block, follows from its header and the roles of its outputs and never from its id. | fold/block_lines.py: block_directiontyping/declarations.py: Declarations.block_is_backward, Declarations.backward_perchesstage/builder_pairs.py: builder_pairs |
— | — | packages/bellman/tests/test_builders.pytest_a_builder_is_read_by_the_pair_that_its_header_joins_whatever_its_block_id |
| A line of a backward value block acts on a value input that its header lists. | fold/backward.py: backward_block |
fold/backward.py: _formal, check_value_roles |
value-input-role |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[value-input-role] |
| A backward header lists the value fields that its block reads and writes and the controls at which its lines are read, and no state. | typing/declarations.py: Declarations.state_perch, Declarations.header_without |
typing/declarations.py: Declarations.check_header_coordinate |
header-coordinate |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[header-coordinate] |
| A forward header lists every field that the lines of its block read and no earlier line defines, and a backward header every value field and every control that its lines read. | typing/line_unknowns.py: listed_identity |
typing/declarations.py: Declarations.check_names_in_scope |
signature-complete |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[signature-complete] |
| A backward line reads a state of its input perch or of a later perch only through the law of motion: under an expectation over the shock of the edge, or on a candidate line. | typing/line_unknowns.py: perch_of_spellingtyping/declarations.py: Declarations.continuation_policy_candidate |
typing/declarations.py: Declarations.check_input_perch_state |
input-perch-state |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[input-perch-state] |
| A statement defines an output, names an alias, is documentation or is an authored node, and an operative equation defines each name once in its block. | stage/construction.py: _statement_records, _line_role |
typing/declarations.py: Declarations.check_defined_once |
defined-once |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[defined-once] |
| The stage reads the continuation values and the arrival state and writes the arrival values and the continuation state, and every field is produced and consumed. | stage/construction.py: _stage_hypergraph |
stage/construction.py: _check_fields_produced_and_consumed |
stage-boundary |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[stage-boundary] |
| A statement of its block determines every output that a header lists, and a policy block that writes a candidate determines its control by the line that identifies the two. | stage/construction.py: _output_equations |
stage/construction.py: _check_block_outputs, _refuse_circular_outputs |
output-defined |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[output-defined] |
| One block writes a field between two perches. | — | typing/declarations.py: Declarations.check_one_builder_per_output |
one-builder-per-output |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[one-builder-per-output] |
| A multiplier is a coordinate of the functions that its block defines at the continuation perch, and no header lists it. | fold/backward.py: perch_domain |
typing/declarations.py: Declarations.check_multipliers_unlisted |
multiplier-declaration |
packages/bellman/tests/test_constraints.pytest_a_declared_multiplier_is_no_wire_of_the_policy_builder |
R2 Ordered statements and substitution¶
The rules of Appendix C R2.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| The explicit definitions of a block are read in dependency order, and an alias is in scope below the line that defines it. | stage/construction.py: _output_equations |
typing/declarations.py: Declarations.check_names_in_scopestage/construction.py: _refuse_circular_outputs |
name-in-scope, output-defined |
packages/bellman/tests/test_kernels.pytest_a_law_whose_second_output_reads_the_first_compiles_to_both_outputs_in_order |
An alias, or a line marked !node, is read through its defining expression, with the shocks and the controls on which that expression depends. |
typing/line_unknowns.py: free_names_with_shocks, mentions_after_aliases |
typing/declarations.py: Declarations.check_forward_reading |
shock-observed |
packages/bellman/tests/test_shock_expectations.pytest_an_expectation_in_an_alias_is_a_piece_of_its_own_reading_the_aggregation_of_its_integrand |
| An explicit statement is solved for a name that occurs in it once and affinely, with a coefficient that is not zero on the declared sets. | typing/ranges.py: solved_for, law_solved_for |
— | — | packages/bellman/tests/test_policy.pytest_a_grid_line_is_accepted_only_where_the_solved_law_of_motion_gives_it[refused-an-identity-of-declared-functions] |
R3 Product outputs¶
The rules of Appendix C R3.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| An output side with several coordinates is a tuple of fields, each defined by its own statement. | typing/declarations.py: Declarations.read_sidefold/stage_fold.py: law_of_motion_equationsstage/defining_expressions.py: law_outputs_rule |
stage/construction.py: _check_block_outputs |
output-defined |
packages/bellman/tests/test_kernels.pytest_a_law_whose_second_output_reads_the_first_compiles_to_both_outputs_in_order |
A tuple left side names the outputs that one argmax or one solve determines together. |
typing/line_unknowns.py: outputs_and_unknowns |
typing/line_unknowns.py: outputs_and_unknowns |
not-constructed, declared-once |
packages/bellman/tests/test_joint_choices.pytest_a_joint_choice_writes_its_outputs_in_the_order_of_its_left_side |
| A tuple of names typed on a product declares one field for each factor, and a name typed on a product is one field whose coordinates a selection reads. | typing/line_unknowns.py: group_coordinatestyping/context.py: TypingContext._selected_type |
typing/line_unknowns.py: group_coordinates |
readable-form |
packages/bellman/tests/test_kernels_on_index_sets.pytest_a_position_selects_a_factor_of_a_product_and_a_fractional_position_is_refused |
| A selection takes a member of a family by a position within the family or by a key of a finite set with as many members. | typing/context.py: TypingContext._selected_typetyping/sets.py: index_within |
typing/line_unknowns.py: _check_family_selectiontyping/context.py: TypingContext._typed_selection |
family-selection |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[family-selection] |
R4 Scope, binding, and information¶
The rules of Appendix C R4.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| A perch mark names the perch of a field and binds no name. | typing/line_unknowns.py: perch_of_spelling, listed_identity, free_names |
— | — | — |
| A line reads a field of a later perch, on its right side and in its clause, only inside an expectation over each shock drawn on the edges between the two perches. | typing/declarations.py: Declarations.shock_edgetyping/line_unknowns.py: free_names_with_shocks |
typing/declarations.py: Declarations.check_known_at_perch, Declarations.check_shock_observed, Declarations.check_forward_reading |
shock-observed |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[shock-observed] |
R5 Fields to functions¶
The rules of Appendix C R5.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| A field is represented by a function on the declared sets of the state coordinates of its perch. | stage/carriers.py: _wire_type, coordinate_domain |
— | — | packages/bellman/tests/test_kernels.pytest_a_backward_aggregation_reads_a_state_of_its_output_perch_as_an_argument_of_its_kernel |
| A value line composes each value input with the law of motion of the edge across which it is read, and its kernel keeps the control as an argument. | fold/backward.py: backward_block, pullback_wire, aggregation_row |
typing/declarations.py: Declarations.block_between |
forward-composite |
packages/bellman/tests/test_policy.pytest_a_policy_kernel_of_a_portfolio_choice_reads_the_share_and_gives_its_value_at_a_point |
A decision state read at the continuation perch is supplied by a coordinate line, m_d[>] = a + c[>], and no other field of an earlier perch is read at a later one. |
fold/policy.py: _coordinate_wires, _explicit_lines_aggregation |
typing/declarations.py: Declarations.check_forward_reading |
forward-composite |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[forward-composite] |
| A shock that a line reaches through the law of motion stays an argument until the expectation that the line writes integrates it, and no expectation is inserted. | fold/backward.py: expectation_rows, pullback_wire |
— | — | packages/bellman/tests/test_shock_expectations.pytest_a_shock_stays_an_argument_through_a_sibling_input_until_an_expectation_integrates_it |
R6 Well-formedness¶
The rules of Appendix C R6.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| A function is applied to arguments in the declared sets of its formal arguments: the inclusion is recorded as a condition of the stage, and no call is refused for it. | fold/conditions.py: domain_conditions, _call_conditions |
— | — | packages/bellman/tests/test_field_equations.pytest_the_conditions_of_a_function_body_stand_once_on_the_definition_that_carries_the_body |
| A divisor written as a number is not zero, and a division that the declared sets do not decide is recorded as a condition. | fold/declared_sets.py: definedness_obligation |
fold/declared_sets.py: _nonzero_divisor |
divisor-nonzero |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[divisor-nonzero] |
| An analytic assumption is recorded as a condition of the stage and is not verified, and a condition that the parameters alone decide is judged at the calibration. | stage/stage_answers.py: obligations, _symbolic_obligations |
stage/binding_verbs.py: calibrated_obligations |
— | packages/bellman/tests/test_calibration_judgment_and_conditions.pytest_calibration_establishes_the_condition_of_the_utility_with_the_value_as_evidence |
R7 The operations a line writes¶
The rules of Appendix C R7.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| The operator of a block is composed of the operations that its lines write: pullbacks, aggregations, expectations, maximizations and evaluations. | fold/backward.py: aggregation_rowfold/policy.py: fold_policy_blockfold/stage_fold.py: block_rows_offold/value_bundles.py: primitive_grain_rows |
— | — | packages/bellman/tests/test_policy.pytest_the_argmax_operations_of_a_stage_are_its_argmax_lines_not_marked_doc |
| Arithmetic and calls act pointwise on values of the kinds they take, and a function is applied to as many arguments as it declares. | fold/backward.py: reduced_termtyping/context.py: TypingContext._typed_call |
typing/line_unknowns.py: _check_calltyping/context.py: TypingContext._numeric_arguments, TypingContext._called_definition |
well-typed, definition-order |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[well-typed] |
D_{c}(𝑢) denotes the derivative of a declared function and Inv(𝑑𝑢) the inverse of one, and the inverse is recorded as a condition. |
typing/declarations.py: Declarations.defines_a_functiontyping/primitive_definitions.py: _derivative, _inversefold/conditions.py: _call_conditions |
typing/declarations.py: Declarations.check_definition_operatortyping/context.py: TypingContext._typed_call |
definition-order, well-typed |
packages/bellman/tests/test_refusals.pytest_a_fault_found_when_a_line_is_typed_is_refused_at_the_line_under_its_rule[Inv of a number] |
| An expectation integrates shocks drawn on the edge of its block, under the conditional law that it selects from the joint law of that edge: a declared conditional, a product of declared conditionals, or a marginal or a conditional of a joint normal law. | fold/backward.py: expectation_rows, _selected_conditionaldistributions/conditionals.py: conditioning_shocks |
distributions/conditionals.py: select_conditional, check_conditioning_covariance |
conditional-not-declared, distribution-edge |
packages/bellman/tests/test_shock_expectations.pytest_the_reversed_order_of_the_expectations_is_refused_naming_the_undeclared_conditional |
| A line does not read a shock again beside a term whose expectation has integrated it. | fold/backward.py: _history_after |
fold/backward.py: _join |
shock-reintroduced |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[shock-reintroduced] |
| A block output depends on no shock, and every shock of the edge is integrated on each path to it. | — | fold/backward.py: check_output_shocks |
shock-observed |
packages/bellman/tests/test_shock_expectations.pytest_a_term_whose_path_integrates_some_shocks_may_read_a_constant_but_not_a_shock |
A maximization on a line not marked !doc forms an Argmax operation whose output is the set of maximizing policies, and the closing Evaluation selects no member of it. |
fold/policy.py: _output_rows, _objective, _policy_evaluationtyping/primitive_definitions.py: _argmax |
fold/policy.py: _chosen |
not-constructed |
packages/bellman/tests/test_policy.pytest_the_policy_builder_of_a_maximization_with_a_property_lists_four_operations |
A feasibility correspondence is a product of sets or a product restricted by conditions, and a call Γ(x) puts x for its formal argument. |
stage/defining_expressions.py: definition_expressionstage/carriers.py: choice_sets, _feasible_domain |
— | — | packages/bellman/tests/test_constraints.pytest_the_maximization_of_a_joint_choice_binds_the_correspondence_at_its_state |
solve_{c}(r_1, …, r_k) forms one Aggregation operation whose rule holds the residuals and whose unknowns are the outputs of its line. |
fold/policy.py: _output_rows, _relation_row |
fold/policy.py: _chosen |
not-constructed |
packages/bellman/tests/test_field_equations.pytest_a_joint_solve_is_one_aggregation_headed_by_its_unknowns_after_its_residual_lines |
An authored evaluate(knots, values, x) reads a table, which a representation typed at its place makes a function between the knots. |
typing/context.py: TypingContext._typed_callstage/representations.py: _holds_authored_table, _node_table |
stage/representation_checks.py: check_sources |
representation-source |
packages/bellman/tests/test_representations.pytest_only_the_places_of_a_node_that_a_table_alone_defines_read_the_table_as_their_data |
A method is typed at a block, at a line marked !node or at an occurrence of an operation, and changes neither the graph nor what the block denotes. |
stage/places.py: inventoryfold/backward.py: sub_builder_rows |
stage/places.py: _check_admission |
method-admission |
packages/bellman/tests/test_two_levels_and_several_methods_files.pytest_a_method_choice_leaves_the_graphs_of_the_stage_unchanged |
| The policy card prints the set that a binder names in the statement of the maximization, also where the binder names a named set. | stage/defining_expressions.py: _resolved_declared_operator, _resolved_symbol |
— | — | — |
R8 Evaluation and policy¶
The rules of Appendix C R8.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| A value builder is the operator at a policy: the decision value is the choice value read at the policy. | fold/backward.py: backward_block, _policiesstage/denotations.py: _policy_denoted |
— | — | packages/bellman/tests/test_policy.pytest_the_decision_builder_is_at_the_policy |
| A candidate line of a policy block writes, under the continuation mark, a control or a state of the decision perch, and a later line of the block reads each candidate. | fold/policy.py: _explicit_lines_aggregation |
typing/declarations.py: Declarations.check_candidate_coordinate, Declarations.check_candidates_read |
candidate-coordinate, candidate-read |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[candidate-read] |
The derivative of a value is no field: a line reads it by the term D_{a}V[>], in a state coordinate of the perch at which the value is read. |
stage/defining_expressions.py: _resolved_derivativetyping/primitive_definitions.py: _derivativestage/stage_answers.py: derivative_reads |
typing/context.py: TypingContext._check_derivative_bindersyntax/lower.py: ToAst._classifier_of_word |
derivative-coordinate, marginal-role-retired |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[derivative-coordinate] |
A derivative line, in the stage file or in a block of the methods file that names the builder's block, is recorded at the builder's Evaluation with the condition marginal-reading, and nothing is differentiated. |
fold/backward.py: stated_derivativesstage/levels.py: operative_levelstage/stage_answers.py: _symbolic_obligations |
— | — | packages/bellman/tests/test_backward_blocks.pytest_the_evaluation_of_a_builder_records_its_derivative_line_as_a_stated_derivative |
The lines of a solution method typed on the policy builder are the rows of the operative builder, the declared builder keeps the maximization, and the endogenous grid method records the condition egm-eligibility. |
stage/levels.py: operative_level, construct, declared_version |
stage/levels.py: _refuse_formula_only |
explicit-solution |
packages/bellman/tests/test_two_levels_and_several_methods_files.pytest_egm_on_the_policy_builder_adds_the_condition_egm_eligibility_and_no_other |
R9 The forward reading¶
The rules of Appendix C R9.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| The forward builders are read from the transition blocks, the law statements and the policy, which enters the edge from the decision perch alone, and from no value. | fold/stage_fold.py: block_rows_of, _forward_edgesstage/denotations.py: _policy_denotedgraphs/builders_graphs.py: _forward_inputs_outputs |
— | — | packages/bellman/tests/test_policy.pytest_the_forward_push_forward_reads_the_policy_and_the_law_of_motion_by_identity |
| Each edge extends the measure by the law of each shock drawn on it, a parent before its children, and pushes it forward through the law of motion to the joint law of the output coordinates. | distributions/edges.py: joint_distribution, dependency_orderfold/block_lines.py: shock_edgesfold/stage_fold.py: block_rows_of |
— | — | packages/bellman/tests/test_shock_expectations.pytest_the_printed_kernel_of_an_expectation_names_the_edge_that_draws_its_shocks |
| Each shock is drawn on the edge of one forward builder, and law statements that read one another are drawn on one edge. | distributions/edges.py: drawn_edges |
distributions/edges.py: shock_builders |
distribution-edge |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[distribution-edge] |
| A law reads its parent shocks and the coordinates of the perch at which its edge begins. | distributions/edges.py: distribution_declarationsfold/stage_fold.py: _forward_edges |
typing/declarations.py: Declarations.check_forward_reading |
forward-composite, shock-observed |
packages/bellman/tests/test_kernels.pytest_the_forward_extension_by_a_law_of_the_control_reads_the_control_through_the_policy |
| A branching block writes one measure for each label, routed by the policy or by the drawn label, and the law of a label shock gives one probability to each label. | fold/stage_fold.py: _branches, block_rows_of |
typing/declarations.py: Declarations.check_draw |
branch-law |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[branch-law] |
R10 Implicit equations¶
The rules of Appendix C R10.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| A statement that defines an output and reads it again through a transition is an implicit statement, and a block holds one for each output. | stage/construction.py: _is_implicit, _implicit_occurrencefold/stage_names.py: occurrences_of |
stage/construction.py: _refuse_second_implicit |
one-implicit-statement |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[one-implicit-statement] |
| An equation whose left side is neither a name nor a tuple of names is a candidate statement; the candidate statements that share a candidate form one system, with as many statements as unknowns. | typing/line_unknowns.py: candidates_of_statement, systems_by_shared_candidatefold/policy.py: candidate_systemsstage/construction.py: _system_solves |
fold/policy.py: _check_system |
not-constructed |
packages/bellman/tests/test_policy.pytest_a_system_with_fewer_statements_than_unknowns_is_refused |
| A candidate statement with no candidate, and an inequality whose left side is no name, are retained as relations that no operation realizes. | fold/policy.py: _forms_no_rowfold/wire_terms.py: names_no_fieldfold/backward.py: retained_relations |
— | — | packages/bellman/tests/test_graphs_and_grains.pytest_a_relation_that_no_operator_realizes_is_retained_with_an_obligation_on_its_line |
A system forms one Aggregation operation of the policy builder, whose rule reads each statement at the decision state, with each continuation value on its right side composed with the law of motion at the policy. |
fold/policy.py: _output_rows, _relation_row, _residual_inputs, _value_wires |
— | — | packages/bellman/tests/test_constraints.pytest_a_first_order_condition_with_its_clause_forms_one_aggregation_read_at_the_point |
| A clause pairs the residual of its line with the slack of its bound: the residual is zero where the bound is slack, nonnegative where a lower bound binds and nonpositive where an upper bound binds. | stage/term_operations.py: kuhn_tucker, slack, residualtyping/ranges.py: clause_regions |
— | — | packages/bellman/tests/test_constraints.pytest_kuhn_tucker_pairs_the_residual_with_the_slack_of_each_kind_of_bound |
The identification c = c[>] states, at the continuation perch, that the policy at the value of the coordinate line equals the candidate, over the pairs that the candidate line admits. |
fold/policy.py: _output_rowsstage/defining_expressions.py: _identification_wires, _admitted_values, _grid_rules |
— | — | packages/bellman/tests/test_kernels.pytest_compile_kernel_refuses_the_identification_of_the_policy_block_as_a_relation |
| The coordinate line agrees with the law of motion solved for the decision coordinate at the candidates. | stage/construction.py: _law_linestyping/ranges.py: law_solved_for, compare_terms |
stage/construction.py: _check_grid_lines |
grid-line-consistency |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[grid-line-consistency] |
The bound of a declared multiplier names continuation states, multipliers of its block, parameters, numbers and inf, and the functions of its block at the continuation perch stand on the observable set that the bound gives. |
stage/carriers.py: observable_restriction, coordinate_domain |
typing/declarations.py: Declarations.check_bound_names |
multiplier-declaration |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[multiplier-declaration] |
A derivative term on a line, D_{a}V[>] or D_{w}V, denotes the derivative of the value function that it names in the named coordinate, read at the point of the line: at the continuation coordinate on a candidate line, and at the image of the law of motion on a line of an earlier perch. |
stage/defining_expressions.py: _resolved_derivative |
— | — | packages/bellman/tests/test_life_cycle_derivative_cards.pytest_derivative_rules_apply_the_partial_at_the_forward_coordinates |
R11 Sub-transitions and the placement of expectations¶
The rules of Appendix C R11.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| The statements of a transition compose into one law of motion that keeps its shock arguments, and none of them holds an expectation. | fold/stage_fold.py: law_of_motion_equations |
fold/stage_fold.py: _law_definitions |
transition-without-expectation |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[transition-without-expectation] |
| An expectation stands where its line writes it, nested expectations are kept apart, and a nonlinear transformation is read in its written order, by the operators that the language holds. | fold/backward.py: expectation_rows, reduced_term |
typing/line_unknowns.py: _references |
not-constructed |
packages/bellman/tests/test_kernels.pytest_the_kernels_of_the_ambiguity_certainty_equivalent_give_its_closed_form |
R12 Envelopes¶
The rules of Appendix C R12.
| rule | implemented by | checked by | refusals | test |
|---|---|---|---|---|
| A branching block holds one nested block for each label of its label coordinate, at least two, in the order of the label set. | typing/declarations.py: Declarations.read_branchfold/stage_fold.py: _branches |
typing/declarations.py: Declarations.check_branch_form, Declarations.read_branch, Declarations.check_branches |
branch-form, branch-labels, not-constructed |
packages/bellman/tests/test_branching.pytest_a_malformed_branching_block_is_refused_under_its_rule |
| The value line selects by one tuple indexed by the label, the policy maximizes over the same tuple, and each continuation value stands at the position of its branch. | typing/context.py: TypingContext._typed_selectiontyping/line_unknowns.py: selection_tuples, selection_positions |
typing/declarations.py: Declarations.check_branch_selection, Declarations.check_positions |
branch-tuple-mismatch, branch-value-position |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[branch-tuple-mismatch] |
An authored upper_env names the candidates that it compares, and a value candidate is written only where an upper_env of the block reads it. |
typing/declarations.py: Declarations.envelope_readstyping/context.py: TypingContext._typed_call |
typing/declarations.py: Declarations.check_candidate_coordinate |
candidate-coordinate |
packages/bellman/tests/test_refusals.pytest_the_smallest_example_breaking_a_rule_of_construction_is_refused_under_it[candidate-coordinate] |
4 Rules that the package does not yet check¶
Appendix C §5.3 lists the rules that the language has and that the package does not yet check, each with what the package does today and the smallest text that shows it. That table is printed from the package's tables of the rules, as this page is, and a test of the package runs each text.
5 Rules that other pages state¶
Each of these refusal rules belongs to a rule that the page named beside it states.