e(0 d d Z ddlZ G d d Zd Zd Z G d d Zd Zd Zd ZdS )a An implementation of the Knuth-Bendix algorithm, as described in (1), p. 143. For determining if two paths in a category are equal. The algorithm as given here, takes a set of equations in the form of a sequence: E = [(a, b), (c, d) ...] where a, b, c, d are 'paths'. Paths are given as strings, for example: E = [ ('fhk', 'gh'), ('m', 'kkm') ] means that the path 'fhk' equals 'gh' and 'm' equals 'kkm'. Each arrow in the path is here a single character. If longer arrow names are required, a delimiter string can be specified as in: kb(E, delim='.') The paths must then be given by the delimiter between each arrow; E = [ ('h_arrow.g_arrow', 'g_arrow.k_arrow') ... ] The function kb(E) returns an object, say A, which is o callable: A(a, b)->boolean determines if two paths given by a, b are equal. o has a method A.reduce(a)->pathstring, which reduces a path to normal form. An optional parameter to kb, max_iterations, determines the maximum number of iterations the algorithm should try making the reduction system 'confluent'. The algorithm is not guaranteed to terminate with a confluent system in a finite number of iterations, so if the number of iterations needed exceeds max_iterations an exception (ValueError) will be raised. The default is 100. References (1) @book{walters91categories, title={Categories and Computer Science}, author={R. F. C. Walters}, publisher={Cambridge University Press}, location={Cambridge}, year=1991} (2) @book{grimaldi94discrete, author="Ralph P. Grimaldi". title="Discrete and Combinatorial Mathematics: An Applied Introduction", publisher="Addison-Wesley", location="Readin, Massachusetts", year=1994 } Nc H e Zd Zd dZd Zd Zd Zd Zd Zdd Z d Z d Zd S )KnuthBendix d c H g | _ || _ |D ]g\ }}|r*| | }| | }| || r||}}| j ||f h| | | d S N) reductionsdelim wrap_delimgtappendmake_confluentsort)selfEr max_iterationsabs i/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib64/python3.11/site-packages/guppy/etc/KnuthBendix.py__init__zKnuthBendix.__init__D s + +DAq 'OOA&&OOA&&wwq!}} !1O""Aq6****N+++ c Z | | | | k S r reduce)r xys r __call__zKnuthBendix.__call__Q s! {{1~~Q//r c | j }|rt | }t | }n*| | }| | }||k rdS ||k rdS ||k S )N r )r lencount)r r r r lalbs r r zKnuthBendix.gtT sl QBQBBBB 771 7711ur c fd}i }t | D ]P}d _ t j }|D ][\ }}|D ]Q\ }} |||| f} | |v rd|| <