Laws¶
A Law is a named statement about a carrier, or about the tensors an
implementation returns. Every member of the algebra hierarchy is
Lawful: its class lists the laws it introduces, and the member
reports a LawClaim for each law it has. The claim's status is
read from its evidence: Proved for a written argument,
Decided for a decision procedure on a stated domain,
Tested for finitely many cases of a larger domain, and
Assumed for a declaration. Proved and decided claims are
established. The arguments of the shipped classes are in
Semirings, t-norms, and change of base §8.
laws
¶
Laws, the evidence for them, and the structures that claim them.
A Law is a named statement about a carrier, or about the tensors an
implementation returns. A LawClaim says that a law holds of a subject
and carries its evidence; the claim's status is read from the kind of
evidence, so the two cannot disagree:
Proved: a written argument, with the published results it uses;Decided: a procedure that decides the law on the stated domain, such as every tuple of a finite carrier;Tested: finitely many points of a larger domain, which can refute a law and cannot establish it;Assumed: a declaration and nothing more.
Proved and decided claims are established. A structure of the algebra
hierarchy is Lawful: its class lists the laws it introduces, and it
reports a claim for each law it has, with evidence declared by its own
class and never inherited, since a subclass may replace an operation.
Requirement pairs a law with the subject it must hold of, which is
what a plan asks for.
PLUS_ASSOCIATIVE
module-attribute
¶
PLUS_ASSOCIATIVE = Law(name='plus-associative', statement='(a + b) + c = a + (b + c) for all a, b, c')
Associativity of the sum.
PLUS_COMMUTATIVE
module-attribute
¶
PLUS_COMMUTATIVE = Law(name='plus-commutative', statement='a + b = b + a for all a, b')
Commutativity of the sum, which licenses reordering a finite sum.
PLUS_UNIT
module-attribute
¶
PLUS_UNIT = Law(name='plus-unit', statement='0 + a = a + 0 = a for all a')
Zero is the unit of the sum.
TIMES_ASSOCIATIVE
module-attribute
¶
TIMES_ASSOCIATIVE = Law(name='times-associative', statement='(a * b) * c = a * (b * c) for all a, b, c')
Associativity of the product.
TIMES_COMMUTATIVE
module-attribute
¶
TIMES_COMMUTATIVE = Law(name='times-commutative', statement='a * b = b * a for all a, b')
Commutativity of the product, which licenses elimination orders.
TIMES_UNIT
module-attribute
¶
TIMES_UNIT = Law(name='times-unit', statement='1 * a = a * 1 = a for all a')
One is the unit of the product.
DISTRIBUTIVE
module-attribute
¶
DISTRIBUTIVE = Law(name='distributive', statement='a * (b + c) = a * b + a * c and (a + b) * c = a * c + b * c')
Distributivity, which licenses merging pending contributions.
ZERO_ANNIHILATES
module-attribute
¶
ZERO_ANNIHILATES = Law(name='zero-annihilates', statement='0 * a = a * 0 = 0 for all a')
Zero annihilates the product.
PLUS_IDEMPOTENT
module-attribute
¶
PLUS_IDEMPOTENT = Law(name='plus-idempotent', statement='a + a = a for all a')
Idempotence, which licenses dropping a repeated contribution.
PLUS_SELECTIVE
module-attribute
¶
PLUS_SELECTIVE = Law(name='plus-selective', statement='a + b is a or b for all a, b')
Selectivity, which a best derivation and its witness need.
SUPERIOR
module-attribute
¶
SUPERIOR = Law(name='superior', statement='under the declared total order, a * b is no better than a and no better than b, and the product is monotone in each argument')
Superiority (Knuth 1977), which licenses stopping best-first at the goal.
STAR_LEAST_SOLUTION
module-attribute
¶
STAR_LEAST_SOLUTION = Law(name='star-least-solution', statement='star(A) is the least solution X of X = I + A X on the declared domain')
The star of a matrix solves its linear system, which linear cycles need.
DIVISION
module-attribute
¶
DIVISION = Law(name='division', statement='(a * b) / b = a for all a and every nonzero b')
Division by nonzero elements, which normalizing needs.
ADDITIVE_INVERSE
module-attribute
¶
ADDITIVE_INVERSE = Law(name='additive-inverse', statement='a + (-a) = 0 for all a')
An additive inverse, which subtraction needs.
ZERO_SUM_FREE
module-attribute
¶
ZERO_SUM_FREE = Law(name='zero-sum-free', statement='a + b = 0 implies a = b = 0')
No sum of nonzero elements is zero.
NO_ZERO_DIVISORS
module-attribute
¶
NO_ZERO_DIVISORS = Law(name='no-zero-divisors', statement='a * b = 0 implies a = 0 or b = 0')
No product of nonzero elements is zero.
SEMIMODULE_ACTION
module-attribute
¶
SEMIMODULE_ACTION = Law(name='semimodule-action', statement='the action of the weights on the statistics is associative with the product, unital, distributes over the sum of the weights and over the sum of the statistics, and either zero annihilates it')
The action that carries expected statistics.
OMEGA_CONTINUOUS
module-attribute
¶
OMEGA_CONTINUOUS = Law(name='omega-continuous', statement='the natural order is a complete partial order on increasing chains, and sum and product preserve their suprema')
Continuity, which gives a least fixed point of a monotone polynomial system.
REAL_EMBEDDING
module-attribute
¶
REAL_EMBEDDING = Law(name='real-embedding', statement='to_reals is an injective homomorphism of semirings into the nonnegative reals that preserves the natural order, and from_reals inverts it on its image')
An embedding into the nonnegative reals, whose completion [0, inf] gives a
monotone polynomial system its least fixed point and its certificate.
FOLD_LINEAR
module-attribute
¶
FOLD_LINEAR = Law(name='fold-linear', statement='h(x + y) = h(x) + h(y) and h(k x) = k h(x) for weights k')
Linearity of a fold of the detailed meaning over the weights.
OPERATIONS_CLOSED
module-attribute
¶
OPERATIONS_CLOSED = Law(name='operations-closed', statement='a + b, and a * b and the action when the carrier has them, lie in the carrier whenever their operands do')
The operations do not leave the carrier.
JOIN_ITERATED
module-attribute
¶
JOIN_ITERATED = Law(name='join-iterated', statement='a sum over several axes equals the sums over one axis at a time, in any order')
A reduction over several axes is iterated, which a contraction plan needs.
COMPOSITION_ASSOCIATIVE
module-attribute
¶
COMPOSITION_ASSOCIATIVE = Law(name='composition-associative', statement='(f >> g) >> h = f >> (g >> h) for composable matrices')
Associativity of matrix composition.
ZERO_FORM
module-attribute
¶
ZERO_FORM = Law(name='zero-form', statement='zero_like(shape, like) is the zero with shape (*shape, *element_shape), the dtype and device of like, and no gradient, and a dtype that cannot hold it is refused', scope='implementation')
The zero is made in the shape, dtype and device a computation needs.
UNIT_FORM
module-attribute
¶
UNIT_FORM = Law(name='unit-form', statement='unit_like(shape, like) is the unit with shape (*shape, *element_shape), the dtype and device of like, and no gradient, and a dtype that cannot hold it is refused', scope='implementation')
The unit is made in the shape, dtype and device a computation needs.
EMPTY_JOIN
module-attribute
¶
EMPTY_JOIN = Law(name='empty-join', statement='a sum over an axis of size zero is the zero of the remaining shape, in the dtype and device of its input, and its derivative is zero', scope='implementation')
A reduction over no terms is the zero.
TIE_FIRST_MAXIMIZER
module-attribute
¶
TIE_FIRST_MAXIMIZER = Law(name='tie-first-maximizer', statement='a selective sum returns as its witness the first best operand in row-major order of the reduced axes, and that operand receives the whole derivative, in every operation', scope='implementation')
The one tie rule of a selective sum, as its implementation keeps it.
STAR_DECIDED
module-attribute
¶
STAR_DECIDED = Law(name='star-decided', statement='star returns a value exactly on its declared domain: for a matrix outside it raises DivergentClosureError, and when rounding cannot decide which side of the boundary a cycle lies on it raises UndecidedClosureError', scope='implementation')
The closure refuses where it has no value and where rounding cannot decide.
SEMIRING_LAWS
module-attribute
¶
SEMIRING_LAWS: tuple[Law, ...] = (PLUS_ASSOCIATIVE, PLUS_COMMUTATIVE, PLUS_UNIT, TIMES_ASSOCIATIVE, TIMES_UNIT, DISTRIBUTIVE, ZERO_ANNIHILATES)
The laws of a semiring whose product need not commute.
LAWS
module-attribute
¶
LAWS: Mapping[str, Law] = MappingProxyType({law.name: law for law in (*SEMIRING_LAWS, TIMES_COMMUTATIVE, PLUS_IDEMPOTENT, PLUS_SELECTIVE, SUPERIOR, STAR_LEAST_SOLUTION, STAR_DECIDED, DIVISION, ADDITIVE_INVERSE, ZERO_SUM_FREE, NO_ZERO_DIVISORS, SEMIMODULE_ACTION, OMEGA_CONTINUOUS, REAL_EMBEDDING, FOLD_LINEAR, OPERATIONS_CLOSED, JOIN_ITERATED, COMPOSITION_ASSOCIATIVE, ZERO_FORM, UNIT_FORM, EMPTY_JOIN, TIE_FIRST_MAXIMIZER)})
The catalogue of laws, by name.
FIRST_MAXIMIZER
module-attribute
¶
FIRST_MAXIMIZER = TieRule(name='first-maximizer', statement='the first maximizer in declared order receives the whole subgradient, and the value carries it as the witness')
The one tie rule of every selective sum.
LAW_GRID
module-attribute
¶
The test that checks the laws of the shipped structures.
TEST_DOMAINS
module-attribute
¶
TEST_DOMAINS: Mapping[str, str] = MappingProxyType({ZERO_FORM.name: 'dtypes float64, float32, int64 and bool, and index shapes (), (0,), (3,), (2, 0) and (0, 2, 3), on the CPU', UNIT_FORM.name: 'dtypes float64, float32, int64 and bool, and index shapes (), (0,), (3,), (2, 0) and (0, 2, 3), on the CPU', EMPTY_JOIN.name: 'six index shapes with an axis of size zero, reduced over one or two axes, in float64 and float32', STAR_DECIDED.name: "every matrix of the row's closure cases inside and outside the domain, of orders zero to three, in float64 and float32", TIE_FIRST_MAXIMIZER.name: "every pair, triple and four-tuple of the row's samples, ties included, in float64 and float32"})
Where the tests of the laws about the implementation take their cases.
LawScope
¶
What a law is about: the mathematical carrier, or the tensors of an implementation.
Citation
didactic-model
¶
Bases: Model
A published source and the place in it that is relied on.
| PARAMETER | DESCRIPTION |
|---|---|
reference
|
Authors, year and title.
TYPE:
|
locator
|
The section, theorem, equation, page, or the notion relied on.
TYPE:
|
doi
|
The digital object identifier, when the source has one.
TYPE:
|
Law
didactic-model
¶
Law(*, name: str, statement: str, scope: LawScope = 'carrier')
Bases: Model
An equation or property that an executor may rely on.
A law about the carrier is a statement over the mathematical carrier; a floating point implementation satisfies no algebraic law exactly, and its rounding is a separate matter. A law about the implementation states a property of the tensors the code returns, such as their shape, dtype, device and derivative.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
A short name, unique among laws.
TYPE:
|
statement
|
The statement, quantified over the carrier.
TYPE:
|
scope
|
TYPE:
|
TieRule
didactic-model
¶
Bases: Model
The element of the subdifferential that a selection returns at a tie.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
A short name.
TYPE:
|
statement
|
Which operand receives the gradient.
TYPE:
|
ClaimSubject
didactic-model
¶
ClaimSubject(*, kind: Literal['algebra', 'computation', 'interpretation', 'operation', 'presentation', 'estimator'], name: str)
Bases: Model
What a law claim is about.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
TYPE:
|
name
|
The subject's qualified Python name or stable identifier text.
TYPE:
|
LawEvidence
didactic-model
¶
Bases: TaggedUnion
Why a law is believed: an argument, a decision, a test, or a declaration.
Proved
didactic-model
¶
Proved(*, argument: str, sources: tuple[Citation, ...] = (), tag: Literal['proved'] = 'proved')
Bases: LawEvidence
Evidence that is a written argument.
| PARAMETER | DESCRIPTION |
|---|---|
argument
|
Where the argument is written, as a documentation path and anchor.
TYPE:
|
sources
|
The published results the argument uses.
TYPE:
|
tag
|
Always
TYPE:
|
Decided
didactic-model
¶
Decided(*, procedure: Literal['exhaustive', 'polynomial-identity', 'real-closed-field'], domain: str, check: str, tag: Literal['decided'] = 'decided')
Bases: LawEvidence
Evidence from a procedure that decides the law on the carrier.
| PARAMETER | DESCRIPTION |
|---|---|
procedure
|
TYPE:
|
domain
|
The carrier the decision covers.
TYPE:
|
check
|
The test that runs the procedure again.
TYPE:
|
tag
|
Always
TYPE:
|
Tested
didactic-model
¶
Bases: LawEvidence
Evidence from tests on finitely many points of a larger domain.
A test can refute a law and cannot establish one on an infinite domain, so tested laws license no exact or certified result.
| PARAMETER | DESCRIPTION |
|---|---|
check
|
The test.
TYPE:
|
cases
|
How many points it evaluates, at least one.
TYPE:
|
domain
|
Where the points come from.
TYPE:
|
tag
|
Always
TYPE:
|
Assumed
didactic-model
¶
Bases: LawEvidence
A law that is declared and neither proved, decided nor tested.
| PARAMETER | DESCRIPTION |
|---|---|
declared_by
|
Who or what declares it.
TYPE:
|
reason
|
Why it is assumed.
TYPE:
|
tag
|
Always
TYPE:
|
LawStatus
¶
Bases: str, Enum
The status a law claim has, fixed by its evidence.
LawClaim
didactic-model
¶
LawClaim(*, law: Law, subject: ClaimSubject, evidence: LawEvidence)
Bases: Model
A claim that a law holds of a subject, with its evidence.
The status is read from the evidence, so the two cannot disagree. QIEC equality evidence and registrations in a type class are not law evidence: they prove index equalities and record declarations.
| PARAMETER | DESCRIPTION |
|---|---|
law
|
The law.
TYPE:
|
subject
|
What it holds of.
TYPE:
|
evidence
|
Why it is believed.
TYPE:
|
status
property
¶
status: LawStatus
The status of the claim.
| RETURNS | DESCRIPTION |
|---|---|
LawStatus
|
Proved, decided, tested or assumed, by the kind of evidence. |
established
property
¶
Whether the claim is proved or decided.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when an argument or a decision procedure stands behind the claim. Only established claims license exact, certified and probabilistic results. |
Requirement
didactic-model
¶
Requirement(*, law: Law, subject: ClaimSubject)
Bases: Model
A law that a plan needs to hold of a subject.
| PARAMETER | DESCRIPTION |
|---|---|
law
|
The law.
TYPE:
|
subject
|
What it must hold of.
TYPE:
|
Lawful
¶
Bases: ABC
A structure whose class membership claims laws.
A class lists in introduces the laws (from LAWS) that
membership in it adds; laws collects them along the class
hierarchy. The evidence of a claim comes from declarations on the
member's own class, never from a parent class, since a subclass may
replace an operation: proof is the argument for every claimed law
about the carrier, and tested gives, for each law about the
implementation that the law grid checks, the number of cases it
evaluates. A law without either is assumed.
name
abstractmethod
property
¶
The structure's name.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A human-readable name. |
subject
property
¶
subject: ClaimSubject
What the structure's claims are about.
| RETURNS | DESCRIPTION |
|---|---|
ClaimSubject
|
The qualified name of the structure's class. |
laws
classmethod
¶
laws() -> tuple[Law, ...]
The laws that membership in this class claims.
| RETURNS | DESCRIPTION |
|---|---|
tuple of Law
|
Each law once, in the order the hierarchy introduces them. |
Source code in src/quivers/core/laws.py
evidence
¶
evidence(law: Law) -> LawEvidence
The evidence for one claimed law.
| PARAMETER | DESCRIPTION |
|---|---|
law
|
A law of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LawEvidence
|
The evidence the member's own class declares. |
Source code in src/quivers/core/laws.py
assumption
¶
assumption(reason: str) -> Assumed
Evidence that a law is only declared.
| PARAMETER | DESCRIPTION |
|---|---|
reason
|
Why it is assumed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Assumed
|
The declaration by the member's class. |
Source code in src/quivers/core/laws.py
claim
¶
The claim that one law holds, with its evidence.
| PARAMETER | DESCRIPTION |
|---|---|
law
|
A law of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LawClaim
|
The claim. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the member does not claim the law. |
Source code in src/quivers/core/laws.py
claims
¶
claims() -> tuple[LawClaim, ...]
The claims of every law of laws.
| RETURNS | DESCRIPTION |
|---|---|
tuple of LawClaim
|
One claim per law. |
establishes
¶
establishes(*laws: Law) -> bool
Whether every given law is claimed and established.
| PARAMETER | DESCRIPTION |
|---|---|
*laws
|
Laws of the catalogue.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when each law is claimed with a proved or decided status,
read from its evidence as |
Source code in src/quivers/core/laws.py
requirements
¶
requirements(laws: Iterable[Law], subject: ClaimSubject) -> tuple[Requirement, ...]
Pair laws with the subject they must hold of.
| PARAMETER | DESCRIPTION |
|---|---|
laws
|
The laws.
TYPE:
|
subject
|
The subject.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of Requirement
|
One requirement per law, in order. |
Source code in src/quivers/core/laws.py
weakest
¶
The weakest status among claims.
| PARAMETER | DESCRIPTION |
|---|---|
claims
|
The claims; none at all is proved.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LawStatus
|
The status no claim falls below, in the order assumed, tested, decided, proved. |