math_spec.lowering
Lower a validated model to a :class:~math_spec.program.Program.
One lowering, on the language side: it packages the declarations a model
resolved to, with every named expression inlined where the math reads it, and
reaches no consumer. A construct with no lowering raises
:class:~math_spec.errors.LanguageError naming its rewrite.
curve_left_as_written_message(blocks)
#
The refusal for a model lowered with its piecewise: blocks still to be written out.
Source code in src/math_spec/lowering.py
inline(node)
#
node with every :class:~math_spec.program.Named replaced by its body — the tree a program carries.
A region's when is inlined with its value, since a mask may compare
expressions that name an entry.
Source code in src/math_spec/lowering.py
inline_mask(mask)
#
mask with every named expression its comparisons read inlined, as :func:inline does for a tree.
lower_program(expanded)
#
Compile a model whose curves are written out into a :class:~math_spec.program.Program.
A domain: binary variable lowers with fixed 0/1 bounds. A sos:
block lowers as itself — a program carries a set, and
:meth:~math_spec.model.Spec.expand is what states one as binaries
instead. A piecewise: block does not lower at all: it states rows, and
:meth:~math_spec.model.Spec.expand is what writes them, so a model still
carrying one is refused rather than written out on the caller's behalf.
| PARAMETER | DESCRIPTION |
|---|---|
expanded
|
A model with no
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LanguageError
|
A construct outside the language, named with its
rewrite, or a |
Source code in src/math_spec/lowering.py
to_program(spec)
#
spec as a :class:~math_spec.program.Program — the public door.
Takes whatever you have: a YAML path, the YAML itself, a mapping, a loaded
model, or a program already. Idempotent, so a caller that does not know
which it holds can call this and be sure. The model is lowered as it
arrived: nothing is written out here, so a piecewise: block still in
it is refused, naming :meth:~math_spec.model.Spec.expand.
| PARAMETER | DESCRIPTION |
|---|---|
spec
|
What to read the declarations from. |
| RETURNS | DESCRIPTION |
|---|---|
Program
|
Every declaration the file makes, with names resolved and shapes |
Program
|
fixed. |
| RAISES | DESCRIPTION |
|---|---|
SchemaError
|
The file is not a valid model. |
LanguageError
|
A construct outside the language, named with its
rewrite, or a |