%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/227033/root/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/
Upload File :
Create Path :
Current File : //proc/227033/root/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyc

�
;�Pc@s]dZddd��YZd�Zd�Zddd��YZd�Zd�Zd	�Zd
S(
s�
    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
}


tKnuthBendixcBsbeZddd�Zd�Zd�Zd�Zd�Zd�Zdd�Z	d	�Z
d
�ZRS(tidcCs�g|_||_xs|D]k\}}|rL|j|�}|j|�}n|j||�rn||}}n|jj||f�qW|j|�|j�dS(N(t
reductionstdelimt
wrap_delimtgttappendtmake_confluenttsort(tselftERtmax_iterationstatb((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyt__init__Cs		
cCs|j|�|j|�kS(N(treduce(R	txty((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyt__call__PscCsr|j}|r*t|�}t|�}n|j|�}|j|�}||krXdS||krhdS||kS(Nii(Rtlentcount(R	RR
Rtlatlb((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyRSs	c	s��fd�}i}x�t|�D]�}d�_t�j�}xx|D]p\}}xa|D]Y\}}	||||	f}
|
|kr�qZnd||
<||kr&�j|�}|j|�}xe|dkr"|| |	||t|�}�j|�}
|||
�|j||d�}q�Wnt|�}x~td|t�j��D]`}||| ||krO�j||||�}�j|| |	�}
|||
�qOqOWqZWqGWd|ks�t	�g}�j�jf}x�t
�j�D]�\}}|\}}|�j|<�j|�}�j|�}||kr�||kr�||f}|j|�|�j|<q�q�Wt|��jkr�d|ks�t	�|�_nd�jks�t	��jr"Pq"q"Wtd|�dS(	Ncs]||krY�j||�r7�jj||f�n�jj||f�d�_ndS(Ni(RRRt	confluent(tptq(R	(sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyt
add_reductionbs
iiRs�KnuthBendix.make_confluent did not terminate in %d iterations.
Check your equations or specify an higher max_iterations value.'
(RR(RR(RR(
trangeRtlistRtfreducetindexRtfindRtAssertionErrort	enumerateRt
ValueError(R	RRtreds_testedtitredstu1tv1tu2tv2tredRtuuuRtlu1tnewrtnullredtuvtutvtrutrvturv((R	sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyRas^		
 
#

	cCsDx=|}x |jD]}|j|�}qW||krPqqW|S(N(Rtreplace(R	RRR/((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyR�scCsL|jr|j|�}n|j|�}|jrH|j|j�}n|S(N(RRRtstrip(R	R((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyR�s		cs8|dkr�j}n�fd�}|j|�dS(NcsB|\}}|\}}�j||�r.dS||kr>dSdS(Niii����(R(t.0t.1Rt_Rt__(R	(sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pytcmp�s(tNoneRR(R	R%R;((R	sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyR�scCst|j�dS(N(t	printredsR(R	((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pytpp�scCsH|j|j�s"|j|}n|j|j�sD||j}n|S(N(t
startswithRtendswith(R	R((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyR�s
N(t__name__t
__module__RRRRRRR<RR>R(((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyRBs
			K			cCs\x=t|�D]/\}}d|fG|dddkr
Hq
q
W|dddkrXHndS(Ns%s	iii(R!(R%R$R/((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyR=�scOst|||�S(N(R(R
Rtk((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pytkb�st_GLUECLAMP_cBseZRS((RARB(((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyRE�sc
Cs�ddddg}dd
ddg}t|d	d
�}d
g|gg|D]9}|gg|D]}|jd||f�^q]^qJ}|d
ddddgdddddgdddddgdddddgdddddggks�t�|S(Nt1s-1R$s-is1.isi.isi.i.isi.i.i.iRt.s%s.%s(s1.iR$(si.is-1(si.i.is-i(si.i.i.iRF(RDRR (tGR
tRRRtT((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyttest2�s	T!cCs�d$g}t|dd�}|dd�s0t�d%d&g}t|�}|jd	�}|jd
�}|dksxt�|dks�t�|||�s�t�d'g}t|dd�}|jd
�}|d
ks�t�|jd�}|dks�t�|jd�}|dkst�d(d)g}t|dd�}|jd�}|jd�}|srt|d*k��|dks�t�|dks�t�d+d,g}t|dd�}|jd �}|jd!�}|d"ks�t�|d#ks�t�dS(-Ns.a.s.b.RRGtfhktghtmtkkmt	fffghkkkmtffghkmtffffhmtfffhmtaas.bb.tbbR
Rs.f.h.k.s.g.h.s.m.s.k.k.m.s.f.f.f.g.h.k.k.k.m.s
.f.f.g.h.k.m.s
.f.f.f.f.h.m.s.f.f.f.h.m.sf.f.f.f.h.ms	f.f.f.h.ms
.f.ff.fff.s	.ffff.ff.s.fffff.s.fff.fff.fffff.s!.f.f.f.ffff.ff.fff.fff.fff.fffff.s.f.f.ffff.ff.fff.fffff.sf.f.f.f.ff.fffffsf.f.f.ff.fffff(s.a.s.b.(RLRM(RNRO(s.a.s.b.(s.f.h.k.s.g.h.(s.m.s.k.k.m.(s
.f.f.f.f.h.m.s.f.f.f.h.m.(s
.f.ff.fff.s	.ffff.ff.(s.fffff.s.fff.fff.fffff.(RDR R(R
RRR((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyttests>		c!Cs�d,d-d.d/d0g}t|�}d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPg }||_|S(QNtHcctHtaabtbataactcatcccbtabctcacaR
tHbtHatHaatHabtHcatHactHcbtabbRUtcbtacbtbaatbabtbactbbatbcatbcbtbbctcabtcbatcbbtcbctccbtHacatHacctbbbbtbbbctbbcctbbbtbccatccaatcccatcacca(RWRX(RYRZ(R[R\(R]R^(R_R
(R`Ra(RbRa(RcRa(RdRe(RfRe(RWRX(RYRZ(R[R\(RgRU(R^Rh(RiRh(RjRZ(RkRU(RlRh(RmRU(RnRh(RoRp(RqRh(RrRh(RsRp(RtRU(RuRU(RvRe(RwRa(RxRU(RyRh(RzR{(R|RU(R_R
(R}RZ(R~Rh(RRh(RDtcanon(R
RR�((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyttest31s 		N(((t__doc__RR=RDRERKRVR�(((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyt<module>@s�					)

Zerion Mini Shell 1.0