math_spec.piecewise
Expand piecewise: blocks into plain variables and constraints.
A block becomes ordinary affine declarations when a caller asks
:meth:~math_spec.model.Spec.expand for them, under names prefixed with the
block's own; what each method emits is tabled in
docs/reference/language/piecewise.md. Every rule a block is held to is
decided at load, before this runs: the names it references in
:class:~math_spec.model.Spec, its links where every expression is typed, and
its frame in :func:curve_frame.
Emitted(name, lam, convexity, set, chord, domain_lo, domain_hi, links, assumptions)
dataclass
#
Every name one block's expansion may write, spelled once for the emitter and the collision check.
The set a block states writes names of its own, and they are reserved whichever method the block declares: which of the two write them is the method's business, and a collision is the file's either way.
assumptions
instance-attribute
#
by_kind
property
#
Each name by the kind of declaration it would collide with.
chord
instance-attribute
#
convexity
instance-attribute
#
domain_hi
instance-attribute
#
domain_lo
instance-attribute
#
lam
instance-attribute
#
links
instance-attribute
#
name
instance-attribute
#
set
instance-attribute
#
of(name, pw)
classmethod
#
The names block name writes.
Source code in src/math_spec/piecewise.py
written(method, *, ungated)
#
The variables and constraints :meth:~math_spec.model.Spec.expand declares for a block of method.
ungated is :func:leaves_ungated of the block's gate. The set a
sos2 or adjacency block states is written out too, since
expand() writes every set.
Source code in src/math_spec/piecewise.py
assumptions_of(block, pw)
#
What block assumes of its numbers, by the name the document prints and a refusal quotes.
Every curve assumes its breakpoints are there: a missing parameter row is
not absence, it is a zero, so an undeclared breakpoint sits the curve on
the origin rather than shortening it. A curve has an x-axis only where two
links tie it, so the increasing condition — and the shape it is checked
with — exist only there; lp alone needs a segment to state a line for;
a mask must be one run.
Read off the block rather than off an expansion, so a model states what it
assumes whether or not its curves have been written out. Each condition is
an assumptions: entry over the parameters the file declared, its
description naming the method and the rewrite that takes a curve of any
shape: the expansion writes them into the model, and a model that still
declares the block resolves the same entries at load.
Source code in src/math_spec/piecewise.py
curve_frame(schema, name, pw, links)
#
The dimensions block name builds one curve per coordinate of: every one its links and its gate carry.
In declaration order, because iterating a set would vary the emitted
dims — and every column index behind it — per process. links are the
block's link expressions typed, as :func:resolve_links answers.
| RAISES | DESCRIPTION |
|---|---|
DimensionError
|
A link or the gate carries the breakpoint dimension, or
a values or |
Source code in src/math_spec/piecewise.py
expand_piecewise(schema)
#
schema with every piecewise: block written out — schema itself where it declares none.
A method: adjacency block states its restriction as the set
method: sos2 states, and then that set is written out here too: the
binaries are what the method is, so the model that comes back carries no
set of its own (:func:math_spec.sos.emit is where they are spelled).
Each block's frame and names are read off the program schema lowered to.
Source code in src/math_spec/piecewise.py
leaves_ungated(gate)
#
Whether a curve gated by gate runs ungated where the gate does not exist, which takes a second convexity row.
A masked gate is absent off its mask, and there the curve sums to 1;
absence: zero reads the gate as 0 there instead, which one row states.
Source code in src/math_spec/piecewise.py
lp_domain_refusal(name, pw, links)
#
The refusal for a method: lp curve whose x-link carries no variable, or None.
The method bounds the curve's domain with two rows comparing the x-link against the first and the last breakpoint, and a row with no variable decides nothing. Decided on the link the file wrote, rather than on the row the expansion would write under a name the file never declared.
Source code in src/math_spec/piecewise.py
resolve_links(name, pw, ns, errors)
#
Block name's link expressions typed, in link order, or None once one failed, its refusal appended.
A link is read affinely, so it is held to degree 1 where it is read.