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 as the model loads, before its rows are written: the names it
references in :func:~math_spec.validation.reference_errors, its links and
its where: as lowering types them, and the fit of each link's row to its
expression, its values and the mask in :func:declaration_of. A refusal names
the link or key the file wrote rather than an emitted declaration.
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.
Every name is reserved whichever method the block declares: which method
writes which is the method's business, and a collision is the file's
either way. set holds the names a method that states a set writes
through :func:math_spec.sos.emit.
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
#
reused
property
#
Each link row whose name the block's own rows or variables already take.
rows
property
#
Every constraint the block writes for itself, its link rows aside.
set
instance-attribute
#
ungated
property
#
The second gate row, where the gate variable does not exist.
of(name, curve)
classmethod
#
The names block name writes, a link's row named after the link.
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(name, curve, where)
#
What block name 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 walked link's breakpoints are over
its own rows, so each is asked of the rows that link reads the curve at,
under a name of its own. 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
ragged where: must mark one run.
Each condition is a where string over the parameters the file declared,
so where is the block's where: as the file wrote it — a typed mask
has no text — and curve says how each row reads it. The expansion
writes the conditions into assumptions:, and a model that still
declares the block derives the same text at load. Each is asked only
where a curve runs, so the where: goes into every one of them: a
model written out and read back holds the data to what the block did.
Source code in src/math_spec/piecewise.py
declaration_of(schema, name, pw, links, walks, where)
#
Block name as the program carries it, with links, walks and where typed, every fit rule decided.
A walk reads the curve's weights at the block's own dims, so it consumes
dims of dims:, joins on dims of dims:, and produces dims of its
own. Each link's row is dims:, or its refinement through the link's
walk; its expression carries exactly that row, its values parameter
varies along it and the breakpoint dim and nothing else, and the
where: tests dims: and the breakpoint dim alone. A walked row
reads the where through its relation when the mask carries a dim the
walk consumes. Decided here, on the link the file wrote, rather than on
the emitted declarations, whose refusal would name <block>_lam — a
variable the author never wrote.
| RAISES | DESCRIPTION |
|---|---|
DimensionError
|
A walk that does not fit |
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 rows 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.
Source code in src/math_spec/piecewise.py
resolve_walks(name, pw, ns, errors)
#
Block name's walks by link key, each read as at reads its relation, or None once one failed.
The expansion writes a walked row as at(<block>_lam, by=, over=,
into=), so a walk is held to every rule that call is held to, and
refused here on the link the file wrote. Each refusal is appended to
errors.
Source code in src/math_spec/piecewise.py
through(text, link)
#
text as link's row reads it: through the link's relation where the row reads the where so, else as written.