%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib64/python3.7/site-packages/guppy/etc/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/guppy/etc/__pycache__/KnuthBendix.cpython-37.pyc

B

�]?#�@sTdZddlZGdd�d�Zdd�Zdd�ZGd	d
�d
�Zdd�Zd
d�Zdd�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@sXeZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zddd�Z	dd�Z
dd�ZdS)�KnuthBendix��dcCsrg|_||_xN|D]F\}}|r2|�|�}|�|�}|�||�rH||}}|j�||f�qW|�|�|��dS)N)�
reductions�delim�
wrap_delim�gt�append�make_confluent�sort)�self�Er�max_iterations�a�b�r�H/opt/alt/python37/lib64/python3.7/site-packages/guppy/etc/KnuthBendix.py�__init__Ds



zKnuthBendix.__init__cCs|�|�|�|�kS)N)�reduce)r�x�yrrr�__call__QszKnuthBendix.__call__cCsP|j}|rt|�}t|�}n|�|�}|�|�}||kr<dS||krHdS||kS)N�r)r�len�count)rrrrZlaZlbrrrrTs


zKnuthBendix.gtc
sN�fdd�}i}�x6t|�D�]}d�_t�j�}�x8|D�].\}}�x"|D�]\}}	||||	f}
|
|krlqLd||
<||kr��|�}|�|�}xT|dkr�|d|�|	||t|�d�}��|�}
|||
�|�||d�}q�Wt|�}xvtd|t�j��D]^}|d||�||d�k�r��||||d��}��|d|�|	�}
|||
��qWqLWq:Wd|k�s|t	�g}�j�jf}xpt
�j�D]b\}}|\}}|�j|<��|�}��|�}||k�r�||k�r�||f}|�|�|�j|<n�q�Wt|��jk�r"d|k�st	�|�_d�jk�s2t	��jrPqWtd|��dS)Ncs@||kr<��||�r&�j�||f�n�j�||f�d�_dS)Nr)rrr	�	confluent)�p�q)rrr�
add_reductioncs
z1KnuthBendix.make_confluent.<locals>.add_reductionrr)rrz�KnuthBendix.make_confluent did not terminate in %d iterations.
Check your equations or specify an higher max_iterations value.'
)
�ranger�listr�freduce�indexr�findr�AssertionError�	enumerater	�
ValueError)rrrZreds_tested�i�redsZu1Zv1Zu2Zv2ZredrZuuurZlu1ZnewrZnullred�uv�u�vZru�rvZurvr)rrr
bs\



$





zKnuthBendix.make_confluentcCs2x,|}x|jD]}|j|�}qW||krPqW|S)N)r�replace)rrrr)rrrr!�szKnuthBendix.freducecCs0|jr|�|�}|�|�}|jr,|�|j�}|S)N)rrr!�strip)rrrrrr�s

zKnuthBendix.reduceNcs0|dkr�j}�fdd�}|jt�|�d�dS)Ncs0|\}}|\}}��||�r dS||kr,dSdS)Nrr���)r)Zxxx_todo_changemeZxxx_todo_changeme1r�_r�__)rrr�cmp�szKnuthBendix.sort.<locals>.cmp)�key)rr�	functools�
cmp_to_key)rr(r2r)rrr�szKnuthBendix.sortcCst|j�dS)N)�	printredsr)rrrr�pp�szKnuthBendix.ppcCs0|�|j�s|j|}|�|j�s,||j}|S)N)�
startswithr�endswith)rrrrrr�s


zKnuthBendix.wrap_delim)rr)N)�__name__�
__module__�__qualname__rrrr
r!rrr7rrrrrrCs

>
rcCsXx<t|�D]0\}}td|fdd�|dddkr
t�q
W|dddkrTt�dS)Nz%s	� )�endr�r)r%�print)r(r'r)rrrr6�s
r6cOst|f|�|�S)N)r)r
r�krrr�kb�srBc@seZdZdS)�_GLUECLAMP_N)r:r;r<rrrrrC�srCc
s�ddddg�ddddg}t|d	d
��d	g�g��fdd��D�}|d	ddddgdddddgdddddgdddddgdddddggks�t��S)
N�1z-1r'z-i)z1.ir')zi.iz-1)zi.i.iz-i)zi.i.i.irD�.)rcs&g|]��g��fdd��D��qS)csg|]}��d�|f��qS)z%s.%s)r)�.0r)�Rrrr�
<listcomp>�sz$test2.<locals>.<listcomp>.<listcomp>r)rF)�GrG)rrrH�sztest2.<locals>.<listcomp>)rBr$)r
�Tr)rIrGr�test2�s rKcCsZdg}t|dd�}|dd�s t�ddg}t|�}|�d�}|�d	�}|d
ksPt�|dks\t�|||�rjt�dg}t|dd�}|�d�}|dks�t�|�d
�}|dks�t�|�d�}|dks�t�ddg}t|dd�}|�d�}|�d�}|s�t|dk��|dk�st�|dk�st�ddg}t|dd�}|�d�}|�d�}|dk�sHt�|dk�sVt�dS)N)z.a.z.b.rE)rz.a.z.b.)ZfhkZgh)�mZkkmZ	fffghkkkmZffghkmZffffhmZfffhmZaaz.bb.�bbrr)z.f.h.k.z.g.h.)z.m.z.k.k.m.z.f.f.f.g.h.k.k.k.m.z
.f.f.g.h.k.m.)z
.f.f.f.f.h.m.z.f.f.f.h.m.zf.f.f.f.h.mz	f.f.f.h.m)z
.f.ff.fff.z	.ffff.ff.)z.fffff.z.fff.fff.fffff.z!.f.f.f.ffff.ff.fff.fff.fff.fffff.z.f.f.ffff.ff.fff.fffff.zf.f.f.f.ff.fffffzf.f.f.ff.fffff)rBr$r)r
rrrrrr�test�s>








rNc Csddddddg}t|�}dddd	d
dddddd
dddddddddddddddddddd d!g }||_|S)"N)ZHcc�H)Zaab�ba)ZaacZca)Zcccb�abc)Zcacar)ZHb�Ha)ZHaarR)ZHabrR)ZHca�Hac)ZHcbrS)ZabbrM)rQ�cb)ZacbrT)ZbaarP)ZbabrM)ZbacrT)ZbbarM)ZbcarT)Zbcb�bbc)ZcabrT)ZcbarT)ZcbbrU)ZcbcrM)ZccbrM)ZHacarS)ZHaccrR)ZbbbbrM)ZbbbcrT)ZbbccZbbb)ZbccarM)ZccaarP)ZcccarT)ZcaccarT)rB�canon)r
rrVrrr�test3%s rW)	�__doc__r4rr6rBrCrKrNrWrrrr�<module>>s	(

Zerion Mini Shell 1.0