math_spec.typesetting.symbols
Which symbol each declared name prints as, and the sidecar that overrides it.
This module decides which symbol a name gets; a :class:~math_spec.typesetting.format.Format decides how it is written.
SymbolTable(notation, indices=dict(), sets=dict(), names=dict())
dataclass
#
How a reader wants the model to print — notation only, kept out of the model.
Every entry is a spelling, printed verbatim. notation: says which
language they are written in, and a render in the other one refuses::
notation: latex
dimensions:
snapshot: {index: t, set: "\\mathcal{T}"}
plant: {index: n}
names:
marginal_cost: "c^{\\mathrm{marg}}"
An entry naming nothing in the model is an error naming the near miss.
| ATTRIBUTE | DESCRIPTION |
|---|---|
notation |
The language the entries are written in; :meth:
TYPE:
|
indices = field(default_factory=dict)
class-attribute
instance-attribute
#
names = field(default_factory=dict)
class-attribute
instance-attribute
#
notation
instance-attribute
#
sets = field(default_factory=dict)
class-attribute
instance-attribute
#
checked_against(schema)
#
Reject entries naming nothing in schema, with the near miss.
Source code in src/math_spec/typesetting/symbols.py
load(source)
classmethod
#
A table from a YAML path or the mapping it parses to.
| RAISES | DESCRIPTION |
|---|---|
SchemaError
|
An unknown section, a malformed dimension, or a
|
Source code in src/math_spec/typesetting/symbols.py
Symbols(schema, namespace, fmt, table)
#
How every declared name prints: overrides first, derivation for the rest.
Name symbols settle before dimension indices, so an index is kept off a
single letter a variable owns — a dimension plant beside a variable
p would otherwise render p_{t,p}. A parameter is upright, so
\mathrm{p} beside an index p is not a collision.
| RAISES | DESCRIPTION |
|---|---|
SchemaError
|
If table is written in a notation fmt does not read. |
Source code in src/math_spec/typesetting/symbols.py
constraint = {name: table.names[name] if name in table.names else _derive_name_symbol(name, declared, fmt, given=True) for name in schema.constraints}
instance-attribute
#
index = {}
instance-attribute
#
name = {name: table.names[name] if name in table.names else _derive_name_symbol(name, declared, fmt, given=name not in chosen) for name in names}
instance-attribute
#
overridden = frozenset(table.names) & declared
instance-attribute
#
set = {}
instance-attribute
#
chosen_expressions(schema, namespace)
#
The cased expressions the solver decides, rather than is handed.
A when does not move one: a variable there asks whether the variable
exists, which the model settles when it is built. Only a value reaching a
variable does — through a second cased expression's arms too, since
:func:~math_spec.resolution.expression_of expands those where the name stood.
Source code in src/math_spec/typesetting/symbols.py
printed_expressions(schema)
#
The named expressions that print under their own name, in declaration order.
A named expression is substituted where it is used, so it normally prints nothing a symbol could stand for. A cased one is the exception: it prints as a definition of its own, which the equations using it name. The order is the file's, because the definitions print in it.
Source code in src/math_spec/typesetting/symbols.py
reported_expressions(schema)
#
The entries the math never reads, in declaration order — the Reported quantities section's rows.
Decided by :func:math_spec.expansion.read_by_the_math, the same answer
the program carries, so the page and a consumer cannot disagree about which
entries the objective and constraints inline. A cased entry is not here
whether or not the math reads it: it prints as the definition block
:func:printed_expressions already places.