Axiom#
- class discopy.testable.Axiom(equation, *, category=None, name=None, subspaces=None, broken=False)[source]#
Bases:
Generic[P,T]An axiom of a category, stated once on an abstract base class and inherited by every category below it.
The category is the class the axiom is bound to, e.g.
discopy.cat.Arrowfor the axioms ofdiscopy.abc.Category. The axiom is a classmethod of it, implicitly: its first parameter is the category and the remaining ones are generated from their annotations — an object for the typing of identities, three composable arrows for the associativity of composition, a term of the category itself forTestable.transparency().Calling a bound axiom returns its own verdict:
NotImplementedwhen the structure does not apply to the category, and the equation itself otherwise; a law declared broken raises anAxiomFailurecarrying that equation instead of returning it.A law is broken when some argument is a counterexample, not every one, so
brokenis declared byfailing()before any argument is generated — the property matrix marks such an axiom as an expected failure and lets the search find the counterexample.- Parameters:
equation (Callable[[Concatenate[type[T], P]], Equation]) – The function stating the law, from the category and the arguments annotated with
C0,C1,typing.Selfor aTestableto anEquation, or toNotImplementedwhen the structure does not apply.category (type[T]) – The class the axiom is bound to,
Noneuntilbind()or the attribute access on a class binds it.name (str) – The attribute the law is stored under, the name of the equation by default.
subspaces (dict) – The strategies the named parameters are generated from instead of their annotations, declared by
weaken().broken (bool) – Whether the law is declared broken by
failing().
- bind(category)[source]#
Bind the axiom to a concrete category.
- Parameters:
category (type[T])
- Return type:
Axiom[P, T]
- modulo(up_to)[source]#
The same law with its equation compared up to a function, so that a category weakens an inherited axiom in one statement, e.g. a diagram compares the interchange law up to its normal form:
Diagram.bifunctoriality = MonoidalCategory.bifunctoriality.modulo( Diagram.normal_form).- Return type:
Axiom[P, T]
- failing(reason)[source]#
The same law declared broken: calling it raises an
AxiomFailurewith the reason as message and the equation evaluated on the arguments, e.g.braid_naturality = BraidedCategory.braid_naturality.failing("A free braid is a box.").- Parameters:
reason (str)
- Return type:
Axiom[P, T]
- inapplicable(reason)[source]#
The same law declared not to apply to the category: it takes no argument and returns
NotImplemented, with the reason as its documentation, e.g.trace_vanishing = TracedCategory.trace_vanishing.inapplicable("No trace.").- Parameters:
reason (str)
- Return type:
Axiom[P, T]
- weaken(**subspaces)[source]#
The same law quantified over a subspace of the named arguments, e.g.
unitality_of_loops = Category.unitality.weaken(f=Endo[C1])for a wrapperEndoof the endomorphisms: each named parameter is generated from its subspace strategy, whose wrapper validates membership on construction and is unwrapped before the body reads it. Assigned to its own attribute beside a.failingdeclaration, it shows the matrix one expected failure and one green cell instead of one blanket expected failure.- Return type:
Axiom[P, T]
- property parameters: tuple[Parameter, ...]#
all but the first, which is the category.
- Type:
The parameters whose arguments the property matrix generates
- property scope: dict#
the category itself for
typing.Self, and its objects and arrows forC0andC1. A monoid, having no objects of its own, stands for both; a class of functors is the arrows ofCat, and the category it maps from, where the arguments a functor is applied to live, is reachable asSelf.dom.- Type:
What the names in the annotations of the axiom stand for
- strategy()[source]#
Generate the arguments the bound axiom expects: one per required parameter, from its annotation evaluated in the
scopeof the category or from the subspaceweaken()declared for it.Only the parameters’ annotations are evaluated: the law’s return annotation may name a type its module imports for checking only.
- Return type:
st.SearchStrategy
- falsify(**params)[source]#
Search for a shrunk counterexample to the bound axiom: arguments for which the verdict fails — the equation is false, or the implementation refuses to build its terms — raising
hypothesis.errors.NoSuchExamplewhen no counterexample is found. Keyword arguments are passed tohypothesis.find().>>> from discopy.cat import Arrow >>> Arrow.associativity.falsify() Traceback (most recent call last): ... hypothesis.errors.NoSuchExample: No examples found of condition ...
- Return type:
tuple
- arguments(*args, **kwargs)[source]#
Bind the arguments to the
parametersof the bound axiom, unwrapping those asubspaceswrapper validated on construction.- Parameters:
args (P.args)
kwargs (P.kwargs)
- Return type:
dict