%PDF- %PDF-
Mini Shell

Mini Shell

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

�
;�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]w}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|| |	�}
|||
�qOqOWqZWqGWg}�j�jf}x�t	�j�D]�\}}|\}}|�j|<�j|�}�j|�}||kr�||kr�||f}|j
|�|�j|<q�q�Wt|��jkr�|�_n�jr"Pq"q"Wtd|�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
iis�KnuthBendix.make_confluent did not terminate in %d iterations.
Check your equations or specify an higher max_iterations value.'
(trangeRtlistRtfreducetindexRtfindRt	enumerateRt
ValueError(R	RRtreds_testedtitredstu1tv1tu2tv2tredRtuuuRtlu1tnewrtnullredtuvtutvtrutrvturv((R	sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyRasX		
 
#

	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((R@RA(((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyRD�sc
Cs�ddddg}dd
ddg}t|d	d
�}d
g|gg|D]9}|gg|D]}|jd||f�^q]^qJ}|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.iRE(RCR(tGR
tRRRtT((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyttest2�s	T	cCsdg}t|dd�}ddg}t|�}|jd	�}|jd
�}dg}t|dd�}|jd�}|jd�}|jd
�}ddg}t|dd�}|jd�}|jd�}d d!g}t|dd�}|jd�}|jd�}dS("Ns.a.s.b.RRFtfhktghtmtkkmt	fffghkkkmtffghkmtaas.bb.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.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.(s.a.s.b.(RKRL(RMRN(s.a.s.b.(s.f.h.k.s.g.h.(s.m.s.k.k.m.(s
.f.ff.fff.s	.ffff.ff.(s.fffff.s.fff.fff.fffff.(RCR(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
tHbtHatHaatHabtHcatHactHcbtabbtbbtcbtacbtbaatbabtbactbbatbcatbcbtbbctcabtcbatcbbtcbctccbtHacatHacctbbbbtbbbctbbcctbbbtbccatccaatcccatcacca(RSRT(RURV(RWRX(RYRZ(R[R
(R\R](R^R](R_R](R`Ra(RbRa(RSRT(RURV(RWRX(RcRd(RZRe(RfRe(RgRV(RhRd(RiRe(RjRd(RkRe(RlRm(RnRe(RoRe(RpRm(RqRd(RrRd(RsRa(RtR](RuRd(RvRe(RwRx(RyRd(R[R
(RzRV(R{Re(R|Re(RCtcanon(R
RR}((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyttest31s 		N(((t__doc__RR<RCRDRJRRR~(((sH/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/KnuthBendix.pyt<module>@s�					)

Zerion Mini Shell 1.0