Equation#
- class discopy.testable.Equation(*terms, symbol='=', symbols=None, up_to=None)[source]#
Bases:
discopy.utils.ResultAn equation is a list of
termsto be compared up to a functionup_to, the identity by default. Casting it toboolchecks whether its terms are all equal up to that function.- Parameters:
terms – The terms of the equation.
symbol – The symbol between each pair of terms,
"="by default.symbols – The symbols between each pair of terms, overriding
symbol;len(terms) * (symbol, )by default.up_to – The function up to which
bool(equation)compares its terms, overriding the subclass’up_toif given.
Example
The number of boxes inside an arrow is left unchanged by associativity, so we can compare arrows up to the function that counts them modulo 2:
>>> from discopy.cat import Ob, Box, Equation >>> x = Ob('x') >>> f, g = Box('f', x, x), Box('g', x, x) >>> parity = lambda term: len(term.inside) % 2 >>> assert not Equation(f, f >> g >> g) >>> assert Equation(f, f >> g >> g, up_to=parity)
- modulo(up_to)[source]#
The same equation compared up to the given function, rebinding
up_to, whose name the attribute already takes.>>> from discopy.cat import Ob, Box, Equation >>> x = Ob('x') >>> f, g = Box('f', x, x), Box('g', x, x) >>> assert Equation(f >> g, g >> f).modulo(lambda _: True)
- Parameters:
up_to (Callable)
- Return type: