+
    ‹°³jÇB  ã                   ó2   € ^ RI Ht ^ RIHt  ! R R4      tR# )é    )Údeque)ÚStateMachinec                   ó’   a € ] tR t^t o RtR tR t]R 4       tR t	R t
RR ltRR ltRR	 ltR
 tRR ltR tR tR tR tRtV tR# )ÚRewritingSystemaˆ  
A class implementing rewriting systems for `FpGroup`s.

References
==========
.. [1] Epstein, D., Holt, D. and Rees, S. (1991).
       The use of Knuth-Bendix methods to solve the word problem in automatic groups.
       Journal of Symbolic Computation, 12(4-5), pp.397-414.

.. [2] GAP's Manual on its KBMAG package
       https://www.gap-system.org/Manuals/pkg/kbmag-1.5.3/doc/manual.pdf

c                ó¾  € Wn         VP                  V n        R V n        RV n        ^dV n        RV n        R V n        / V n        / V n	        \        . ^24      V n        V P                  4        \        V P                  4      pY" Uu. uF  q3R,          NK  	  up,          p\        R\        V P                   4      ,           V4      V n        V P!                  4        R # u upi )Niÿ  FzReduction automaton for éÿÿÿÿ)ÚgroupÚ
generatorsÚalphabetÚ_is_confluentÚmaxeqnsÚtidyintÚ_max_exceededÚreduction_automatonÚ
_new_rulesÚrulesr   Úrules_cacheÚ_init_rulesÚlistr   ÚreprÚconstruct_automaton)Úselfr	   r
   Úgens   &&  Úd/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/combinatorics/rewritingsystem.pyÚ__init__ÚRewritingSystem.__init__   sÊ   € ØŒ
Ø×(Ñ(ˆŒØ!ˆÔð ˆŒØˆŒð #ˆÔð $(ˆÔ ØˆŒð ˆŒ
Ü   R›=ˆÔØ×ÑÔô ˜$Ÿ-™-Ó(ˆ
Ø¨*Ó5©* 3˜B—w�w©*Ñ5Õ5ˆ
ä#/Ð0JÌDÐQU×Q[ÑQ[ÓL\Õ0\Ð^hÓ#iˆÔ Ø× Ñ Ö"ùò 6s   ÂCc                ó@   € WP                   8”  d   RV n        Wn         R# )z6
Set the maximum number of rules that can be defined

FN)r   r   )r   Úns   &&r   Úset_maxÚRewritingSystem.set_max0   s   € ð
 �|‰|ÔØ!&ˆDÔØŒÙó    c                ó`   € V P                   f   V P                  4       V n         V P                   # )z+
Return `True` if the system is confluent

)r   Ú_check_confluence©r   s   &r   Úis_confluentÚRewritingSystem.is_confluent:   s-   € ð ×ÑÒ%Ø!%×!7Ñ!7Ó!9ˆDÔØ×!Ñ!Ð!r!   c                óÂ   € V P                   P                  P                  pV P                   P                   F  pV P	                  W!4       K  	  V P                  4        R # ©N)r	   Ú
free_groupÚidentityÚrelatorsÚadd_ruleÚ_remove_redundancies)r   r*   Úrs   &  r   r   ÚRewritingSystem._init_rulesD   sF   € Ø—:‘:×(Ñ(×1Ñ1ˆØ—‘×$Ô$ˆAØ�M‰M˜!Ö&ñ %à×!Ñ!Ô#Ùr!   c                ó
  € \        V P                  4      ^,           V P                  8”  d(   V P                  4       V n        RV n        \        R4      hW P                  V&   V P                  '       d   W P                  V&   R# R# )z?
Add the rule r1 -> r2 with no checking or further
deductions

TzToo many rules were defined.N)	Úlenr   r   r#   r   r   ÚRuntimeErrorr   r   )r   Úr1Úr2s   &&&r   Ú	_add_ruleÚRewritingSystem._add_ruleK   sj   € ô ˆt�z‰z‹?˜QÕ §¡Ô-Ø!%×!7Ñ!7Ó!9ˆDÔØ!%ˆDÔÜÐ=Ó>Ð>Ø�
‰
�2‰à×#×#Ð#Ø"$�O‰O˜BÓñ $r!   c                ó>  € \        4       pW8X  d   V# W8  d   Y!r!W3V P                  9   d   V# V P                  P                  W34       Yre\        V4      \        V4      ,
          ^8  d¨   WPP                  9  d+   VP                  V4       V'       g   V P                  WV4       VR,          VR,          8”  dY   VR,          V P                  9  dA   VP                  VR,          4       V'       g!   V P                  VR,          VR,          4       \        V4      \        V4      ,
          R8”  dñ   V\        V4      ^,
          ,          pVP                  ^ \        V4      ^,
          4      pWgR,          ,          p\        V4      \        V4      ,
          ^ 8  d?   W`P                  9  d-   V'       g   V P                  We4       VP                  V4       KÆ  KÈ  \        V4      \        V4      ,
          ^8  g   Kê  V P                  WVV4      pVP                  V4       EK  \        V4      \        V4      ,
          R8”  dÚ   V^ ,          pVP                  ^\        V4      4      pVR,          V,          p\        V4      \        V4      ,
          ^ 8  d?   W P                  9  d-   V'       g   V P                  W!4       VP                  V4       K°  K²  \        V4      \        V4      ,
          ^8  g   KÔ  V P                  WV4      pVP                  V4       Kù  V# )é   r   )
Úsetr   Úappendr1   r   Úaddr5   Úsubwordr,   Úupdate)	r   Úw1Úw2ÚcheckÚnew_keysÚs1Ús2ÚgÚnews	   &&&&     r   r,   ÚRewritingSystem.add_ruleZ   sE  € Ü“5ˆàŒ8ØˆOàŒ7Ø�àˆ8�t×'Ñ'Ô'ØˆOØ×Ñ×Ñ  Ô)àˆBô ˆr‹7”S˜“WÕ˜qÔ ØŸ™Ô#Ø—‘˜RÔ ßØ—N‘N 2Ô*Ø�2�v˜˜B�Œ 2 r¥6°·±Ô#;Ø—‘˜R �VÔ$ßØ—N‘N 2 r¥6¨2¨r­6Ô2ô �"‹gœ˜B›Õ "Ô$Ø”3�r“7˜1•9•ˆAØ—‘˜Aœs 2›w q�yÓ)ˆBØ�r•E•ˆBÜ�2‹wœ˜R›Õ  1Ô$ØŸZ™ZÔ'ß ØŸ™ rÔ.Ø—L‘L Ö$ñ (ô �R“œ3˜r›7Õ" QÖ&Ø—m‘m B¨EÓ2�Ø—‘ ×$ô �"‹gœ˜B›Õ "Ô$Ø�1•ˆAØ—‘˜Aœs 2›wÓ'ˆBØ�B•�r•ˆBÜ�2‹wœ˜R›Õ  1Ô$ØŸZ™ZÔ'ß ØŸ™ rÔ.Ø—L‘L Ö$ñ (ô �R“œ3˜r›7Õ" QÖ&Ø—m‘m B¨EÓ2�Ø—‘ Ö$àˆr!   c                óà  € \        4       p\        4       pV P                  P                  4       pV F®  pV P                  WUR7      pV P                  WE,          4      pWe8w  do   V P                  V VP	                  V4       Wg8”  d"   VP	                  V4       WpP                  V&   Kw  Wg8  d"   VP	                  V4       W`P                  V&   Kž  K   WpP                  V&   K°  	  V'       d   W#3# R# )zÞ
Reduce left- and right-hand sides of reduction rules
and remove redundant equations (i.e. those for which
lhs == rhs). If `changes` is `True`, return a set
containing the removed keys and a set containing the
added keys

)ÚexcludeN)r9   r   ÚcopyÚreducer;   )r   ÚchangesÚremovedÚaddedr   r.   ÚvÚws   &&      r   r-   Ú$RewritingSystem._remove_redundancies˜   s¿   € ô “%ˆÜ“ˆØ—
‘
—‘Ó!ˆÛˆAØ—‘˜A�Ó)ˆAØ—‘˜E�HÓ%ˆAØŒvØ—J‘J˜q�MØ—‘˜A”Ø”5Ø—I‘I˜a”LØ$%—J‘J˜q“MØ”UØ—I‘I˜a”LØ$%—J‘J˜q“Mñ ð !"—
‘
˜1“ñ ÷ Ø�>Ð!Ùr!   c                ó¾  a a€ S P                   '       d   S P                  # \        S P                  P	                  4       4      oR pV 3R lp^ p^ pV\        S4      8  EdX   SV,          pV^,          p^ pV\        S4      8  g   K7  SV,          pV^,          pWh8X  d   K,  V! Wh4      p	V	P                  V! VR,          V4      4       V	'       g   K]  V	 FY  p
V! W¦W�4      pV'       d1   V'       d    R# SP                  V4       V\        V4      ,          pKD  VR8X  g   KM  S P                  u # 	  VS P                  8”  g   KÏ  V'       d   KÙ  S P                  RR7      w  rÍ^ pV'       d   \        V3R lV 4       4      pS Uu. uF  qîV9  g   K  VNK  	  upoSP                  V4       Wl9   g   EK@  EKh  RS n        V'       g   S P                  4        R# u upi )zO
Try to make the system confluent using the Knuth-Bendix
completion algorithm

c                 óL  € \        V 4      p\        V4      p. p\        ^W#,           4       Fõ  pV P                  W%,
          W#,           V,
          RR7      VP                  WR,
          VRR7      8X  g   KI  V P                  ^ W%,
          RR7      pWaP                  ^ WR,
          RR7      ,          pVP                  WR,
          VRR7      pVP                  WSRR7      pW€P                  W#,           V,
          VRR7      ,          pVP                  Wg,          V,          4       K÷  	  V# )é   F)Ústrict)r1   Úranger<   r:   )	r3   r4   Úlen1Úlen2ÚresultÚjÚaÚbÚcs	   &&       r   Ú	_overlapsÚ1RewritingSystem.make_confluent.<locals>._overlapsÀ   sí   € Ü�r“7ˆDÜ�r“7ˆDØˆFÜ˜1˜d�kÖ*�Ø—J‘J˜t�x¨­°q­À�JÓGØŸ*™* Q¥X¨q¸˜*Ó?ö@àŸ
™
 1 d¥f°U˜
Ó;�AØŸ*™* Q¨­°u˜*Ó=Õ=�AØŸ
™
 1¥6¨1°U˜
Ó;�AØŸ
™
 1°5˜
Ó9�AØŸ*™* T¥[°1¥_°dÀ5˜*ÓIÕI�AØ—M‘M !¥# a¥%Ö(ñ +ð ˆMr!   c                 óH  <€ V P                  VSP                  V,          4      pSP                  V4      pV P                  VSP                  V,          4      pSP                  V4      pWE8w  d!   V'       d   ^ .#  SP                  WTV4      pV# R#   \         d     R# i ; i)r   FN)Úeliminate_wordr   rJ   r,   r2   )rO   r3   r4   r@   ÚsÚtrA   r   s   &&&&   €r   Ú_process_overlapÚ8RewritingSystem.make_confluent.<locals>._process_overlapÏ   s“   ø€ Ø×$Ñ$ R¨¯©°B­Ó8�Ø—K‘K “N�Ø×$Ñ$ R¨¯©°B­Ó8�Ø—K‘K “N�Ø”6ßà !˜s˜
ð%Ø#'§=¡=°°uÓ#=˜Ø'˜ñ øô (ô %Ú$ð%ús   Á<B ÂB!Â B!FT)rK   c              3   óF   <"  € T F  pSP                  V4      x € K  	  R # 5ir(   )Úindex)Ú.0ra   Úlhss   & €r   Ú	<genexpr>Ú1RewritingSystem.make_confluent.<locals>.<genexpr>  s   øé € Ð8±a° §	¡	¨!§ ³aùs   ƒ!r   )
r   r   r   r   Úkeysr1   Úextendr   r-   Úmin)r   r@   r]   rc   rM   Úir3   rY   r4   ÚoverlapsrO   rA   r.   rZ   Úlrh   s   f&             @r   Úmake_confluentÚRewritingSystem.make_confluent¶   s’  ù€ ð ××ÐØ×%Ñ%Ð%Ü�4—:‘:—?‘?Ó$Ó%ˆò	õ	ð  ˆØˆØ”#�c“(�lØ�Q•ˆBØ��FˆAð ˆAØ”c˜#“h–,Ø˜•V�Ø�Q•�Ø”8ÙÙ$ RÓ,�Ø—‘¡	¨"¨b­&°"Ó 5Ô6ßÙÛ!�AÙ/°°rÓA�Hßß Ú#(ØŸ
™
 8Ô,Ø¤ X£Õ.šØ! UÖ*ð  $×1Ñ1Ò1ñ "ð ˜4Ÿ<™<Ö'·±à×4Ñ4¸TÐ4ÓB‘D�AØ�EßäÔ8±aÓ8Ó8˜Ù&)Ó8¡c °a©ZŸ1˜1¡cÑ8�CØ—J‘J˜q”MØ—wâà!ˆÔßØ×%Ñ%Ô'Ùùò 9s   ÆGÆGc                ó&   € V P                  R R7      # )T)r@   )rq   r$   s   &r   r#   Ú!RewritingSystem._check_confluence  s   € Ø×"Ñ"¨Ð"Ó.Ð.r!   Nc                ód  € V P                    Uu/ uF  q3V8w  g   K  W0P                   V,          bK   	  ppRpTpV'       dk   RpV F`  pTpWC,          R,          VR,          8”  d   VP                  W4V,          RRR7      pMVP                  W4V,          RR7      pWg8w  g   K^  RpKb  	  Kr  V# u upi )z^
Apply reduction rules to `word` excluding the reduction rule
for the lhs equal to `exclude`

TF)Ú_allÚinverse)rv   r   )r   r`   )r   ÚwordrH   r.   r   ÚagainrE   Úprevs   &&&     r   rJ   ÚRewritingSystem.reduce  s®   € ð ,0¯:ª:ÓF©: a¸g¹Ô!�—J‘J˜q•MÒ!©:ˆÐFð ˆØˆßØˆEÛ�Ø�Ø•8˜R•< ! R¥%Ô'Ø×,Ñ,¨Q°aµ¸tÈUÐ,ÓS‘Cà×,Ñ,¨Q°aµ¸tÐ,ÓD�CØ–;Ø ’Eó ð ˆ
ùò! Gs
   �B-œB-c                ól   € / pV F+  pVR,          pW,          R,          pWT8  d   WRV&   K'  WBV&   K-  	  V# )zø
Compute the inverse rules for a given set of rules.
The inverse rules are used in the automaton for word reduction.

Arguments:
    rules (dictionary): Rules for which the inverse rules are to computed.

Returns:
    Dictionary of inverse_rules.

r   © )r   r   Úinverse_rulesr.   Úrule_key_inverseÚrule_value_inverses   &&    r   Ú_compute_inverse_rulesÚ&RewritingSystem._compute_inverse_rules-  sI   € ð ˆÛˆAØ  "�uÐØ"'¥(¨R¥ÐØ"Ô5Ø2DÐ.Ó/à4DÐ0Ó1ñ ð Ðr!   c                ó<   € V P                  V P                  4       R# )a  
Construct the automaton based on the set of reduction rules of the system.

Automata Design:
The accept states of the automaton are the proper prefixes of the left hand side of the rules.
The complete left hand side of the rules are the dead states of the automaton.

N)Ú_add_to_automatonr   r$   s   &r   r   Ú#RewritingSystem.construct_automatonC  s   € ð 	×Ñ˜tŸz™zÖ*r!   c                ó  € . p/ pTpV P                  V4      pVP                  V4       . pV EFj  pW'P                  ,          p. W7&   \        VP                  4      p\	        V4      p	\        ^V	4       Fz  p
WŠ^,
          ,          WŠ,          ,          WŠ&   WŠ^,
          ,          pW°P                  P                  9  g   KL  V P                  P                  VRR7       VP                  V4       K|  	  WƒV&   Wv9   d\   RV P                  P                  V,          n
        WG,          V P                  P                  V,          n        VP                  V4       WpP                  P                  9  g   EKF  V P                  P                  VRWG,          R7       EKm  	  \        V4      pV P                  P                   EFV  pTpV P                  P                  V,          P                  pVR8X  d€   V Fw  pWðP                  P                  9   d/   V P                  P                  V,          P                  Wÿ4       KK  V P                  P                  V,          P                  Wý4       Ky  	  K³  VR8X  g   K¼  V F”  pWß,          p\	        V4      '       d9   VV P                  P                  9  d   VP                  ^\	        V4      4      pKI  \	        V4      '       g   RpV P                  P                  V,          P                  VV4       K–  	  EKY  	  \	        V P                  P                   4      \	        V4      8w  d¼   V F³  pTpV P                  P                    F”  pWß,          p\	        V4      '       d9   VV P                  P                  9  d   VP                  ^\	        V4      4      pKI  \	        V4      '       g   RpV P                  P                  V,          P                  VV4       K–  	  Kµ  	  R# R# )a6  
Add new states and transitions to the automaton.

Summary:
States corresponding to the new rules added to the system are computed and added to the automaton.
Transitions in the previously added states are also modified if necessary.

Arguments:
    rules (dictionary) -- Dictionary of the newly added rules.

rZ   )Ú
state_typeÚd)r‡   Úrh_rulera   ÚstartN)r�   r=   Úletter_form_elmr   r1   rU   r   ÚstatesÚ	add_stater:   r‡   r‰   Úremover9   Úadd_transitionr<   Úautomaton_alphabet)r   r   r�   Úproper_prefixesÚ	all_rulesr~   Úaccept_statesÚruleÚletter_word_arrayÚlen_letter_word_arrayrn   ÚelemÚstateÚcurrent_state_nameÚcurrent_state_typeÚletterÚ_nexts   &&               r   r„   Ú!RewritingSystem._add_to_automatonN  sM  € ð  ÐØˆð ˆ	Ø×3Ñ3°IÓ>ˆØ×Ñ˜Ô'ð ˆäˆDð ×"6Ñ"6Õ6Ðà$&ˆOÑ!Ü $ T×%9Ñ%9Ó :ÐÜ$'Ð(9Ó$:Ð!Ü˜AÐ4Ö5�Ø'8¸1½Õ'=Ð>OÕ>RÕ'RÐ!Ñ$à(¨1­Õ-�Ø×7Ñ7×>Ñ>Ö>Ø×,Ñ,×6Ñ6°tÈÐ6ÔLØ!×(Ñ(¨Ö.ñ 6ð %6˜DÑ!àÔ$ØCF�×(Ñ(×/Ñ/°Õ5Ô@Ø@IÅ�×(Ñ(×/Ñ/°Õ5Ô=Ø×$Ñ$ TÔ*à×3Ñ3×:Ñ:×:Ø×(Ñ(×2Ñ2°4ÀCÐQZÕQ`Ð2×añ/ ô2 !Ð!3Ó4Ðð ×-Ñ-×4Õ4ˆEØ!&ÐØ!%×!9Ñ!9×!@Ñ!@ÀÕ!G×!RÑ!RÐð " SÔ(Û0�FØ×!9Ñ!9×!@Ñ!@Ô@Ø×0Ñ0×7Ñ7¸Õ>×MÑMÈfÖ]à×0Ñ0×7Ñ7¸Õ>×MÑMÈfÖió	 1ð
 $ sÖ*ã0�FØ.Õ5�EÜ˜eŸ*š*¨°d×6NÑ6N×6UÑ6UÔ)UØ %§¡¨a´°U³Ó <šÜ˜uŸ:š:Ø '˜Ø×,Ñ,×3Ñ3°EÕ:×IÑIÈ&ÐRWÖXô 1ñ 5ô0 ˆt×'Ñ'×:Ñ:Ó;¼sÐCUÓ?VÔVÛ&�Ø%*Ð"Ø"×6Ñ6×IÔI�FØ.Õ5�EÜ˜eŸ*š*¨°d×6NÑ6N×6UÑ6UÔ)UØ %§¡¨a´°U³Ó <šÜ˜uŸ:š:Ø '˜Ø×,Ñ,×3Ñ3°EÕ:×IÑIÈ&ÐRWÖXó Jó 'ñ Wr!   c                ó
  € V P                   '       d#   V P                  V P                   4       / V n         ^pV'       dÅ   ^ pV P                  P                  R,          p\	        VP
                  4       FŠ  w  rEVP                  V,          pV P                  P                  V,          pVP                  R8X  dC   VP                  pVP                  V\        V4      ,
          ^,           V^,           V4      p^p KÄ  TpKŒ  	  KÌ  V# )a  
Reduce a word using an automaton.

Summary:
All the symbols of the word are stored in an array and are given as the input to the automaton.
If the automaton reaches a dead state that subword is replaced and the automaton is run from the beginning.
The complete word has to be replaced when the word is read and the automaton reaches a dead state.
So, this process is repeated until the word is read completely and the automaton reaches the accept state.

Arguments:
    word (instance of FreeGroupElement) -- Word that needs to be reduced.

rŠ   rˆ   )r   r„   r   rŒ   Ú	enumerater‹   Útransitionsr‡   r‰   Úsubstituted_wordr1   )	r   rx   ÚflagÚcurrent_statern   ra   Únext_state_nameÚ
next_stateÚsubsts	   &&       r   Úreduce_using_automatonÚ&RewritingSystem.reduce_using_automaton¥  sÜ   € ð �?�?ˆ?Ø×"Ñ" 4§?¡?Ô3Ø ˆDŒOàˆßØˆDØ ×4Ñ4×;Ñ;¸GÕDˆMÜ! $×"6Ñ"6Ö7‘�Ø"/×";Ñ";¸AÕ">�Ø!×5Ñ5×<Ñ<¸_ÕM�
Ø×(Ñ(¨CÔ/Ø&×.Ñ.�EØ×0Ñ0°´S¸Ó5IÕ1IÈAÕ1MÈqÐQRÍsÐTYÓZ�DØ�DÚØ *’ó 8ð ˆr!   )
r   r   r   r   r	   r   r   r   r   r   )Fr(   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Úpropertyr%   r   r5   r,   r-   rq   r#   rJ   r�   r   r„   r§   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r      sj   ø‡ € ñò#ò<ð ñ"ó ð"òò%ô<ô|ô<Zòx/ôò0ò,	+òUY÷n ð  r!   r   N)Úcollectionsr   Ú'sympy.combinatorics.rewritingsystem_fsmr   r   r}   r!   r   Ú<module>r´      s   ðÝ Ý @÷Aó Ar!   