
    oVh;-                         d dl mZmZmZmZmZ d dlmZmZ d dl	m
Z
 dZdZdZd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zy)    )deduce_alpha_implicationsapply_beta_to_alpha_routerules_2prereq	FactRulesFactKB)AndNot)raisesTFNc                     d  ddg      \  } }| dddhddht        d      t        d      ht        d      t        d      t        d      hik(  sJ |ddhddhddhdk(  sJ  g d      \  } }| dddhddht        d      t        d      ht        d      t        d      t        d      hik(  sJ |ddhddhddhdk(  sJ  d	d	g      i i fk(  sJ  dd
g      ddhddht        d      t        d      ht        d      t        d      hidhdhdfk(  sJ t        t        fd       t        t        fd       t        t        fd        dt        d      fdg      \  } }| dt        d      t        d      hdt        d      hddt        d      ht        d      t        d      hik(  sJ |ddhddhddhdk(  sJ  t        d      dfdg      \  } }| ddht        d      dht        d      ddht        d      t        d      dhik(  sJ |ddhddhddhdk(  sJ  g d      \  } }| dh ddh ddddhddht        d      t        d      ht        d      t        d      t        d      ht        d      t        d      t        d      t        d      ht        d      t        d      t        d      t        d      t        d      hik(  sJ |h dh dh dh dh ddk(  sJ  ddg      \  } }| dddhddht        d      t        d      t        d      ht        d      t        d      hik(  sJ |ddhddhddhdk(  sJ y ) Nc                     t        |       }t        |j                         D ci c]  \  }}|df|D ch c]  }|df c} c}}}      }||fS c c}w c c}}}w )NT)r   r   items)iIkSvPs         K/home/dcms/DCMS/lib/python3.12/site-packages/sympy/core/tests/test_facts.pyDz)test_deduce_alpha_implications.<locals>.D   sh    %a(:;'')E E26!QQI1-aD	--E F!t .Es   AAAAabr   cr   r   r   r   r   r   )r   r   r   )r   r   r   r   c                  ,      dt        d      fg      S )Nr   r	   r   s   r   <lambda>z0test_deduce_alpha_implications.<locals>.<lambda>$   s    q3C/!23     c                  .      ddt        d      fg      S )Nr   r   r   r   r   s   r   r    z0test_deduce_alpha_implications.<locals>.<lambda>%   s    q*sCHo!>? r!   c            	      2      ddddt        d      fg      S )Nr   r   )r   nar$   r   r   r   s   r   r    z0test_deduce_alpha_implications.<locals>.<lambda>&   s#    q*j+#c("   r!   )r   r   )r   r   )r   r   )r   d)r%   e>   r   r   r%   r&   >   r   r%   r&   r%   r&   >   r   r   r%   r&   >   r   r   r%   r&   >   r   r   r   r&   >   r   r   r   r%   r   r   r   r%   r&   )ratreal)intr(   r*   r(   r)   )r(   r)   r*   )r	   r
   
ValueError)r   r   r   s     @r   test_deduce_alpha_implicationsr,      s    j*%&DAqsCj#uc#h	S
CHs3xS24 4 4 4sCjSzc
CCCC 12DAqsCj#uc#hS
CHsSVxY\]`YaNbccccsCjSzc
CCCC j*%&2r(222j*%&	seS3%SCH:s3x#c(Le3% +" " " "
 :34
:?@
:   sCHoz*+DAqs3xS*C#c(S3C/SVWZS[^abe^f]ghhhhsCjSzc
CCCCs3xoz*+DAqseSXuc#h9	
c(SXsO& & & &sCjSzc
CCCC =>DAq*Cc3ZseSXCzC3s8SX&C3s8SXH33x#c(CHc#hC!IK K K K * 2'.B!# # # #
 o~./DAqFc%j#e*-s5zCJ<I I I I%v       r!   c            	      0   t         } d }ddhi}t        dd      dfg} | ||      dhg f |d       |d      dk(  sJ ddhi}t        dt        d            dfg} | ||      ddhg ft        d       |d      d |d      ik(  sJ dddhi}t        dd      dfg} | ||      h dg f |d       |d      dk(  sJ ddhi}t        dd      d	fg} | ||      dhdgf |d       |d      dk(  sJ dh di}t        dd      dfg} | ||      h dg f |d       |d      dk(  sJ dddhi}t        ddd      d	fg} | ||      ddhdgf |d       |d       |d      d
k(  sJ ddhdhd}t        dd      dfg} | ||      h dg fdhg f |d       |d      dk(  sJ ddhdhd}t        dd      dft        dd      dfg} | ||      h dg fddhg f |d       |d       |d      dk(  sJ dddhi}t        dd	      dft        dd      d	fg} | ||      h dg ft               ddgf |d       |d      dk(  sJ dddhi}t        dt        d            dfg} | ||      dddhg fd |d      t        d       |d      ik(  sJ t        d      t        d      t        d      hi}t        t        d      d      dfg} | ||      t        d      t        d      t        d      hg ft        d       |d      d |d      ik(  sJ dddhi}t        dd      t        d      fg} | ||      ddhg f |d       |d      dk(  sJ ddhddhd}t        dd      dfg} | ||      h dg fddhg f |d       |d      dk(  sJ y )Nc                     t               | gfS N)set)bidxs    r   Qz)test_apply_beta_to_alpha_route.<locals>.QK   s    vr!   xr   r   r   )r3   r   r   r   >   r   r   r   y)r3   r   r   r   r%   )r3   r   >   r   r   r   r%   )r3   r   r   r   r&   >   r   r   r   r%   r&      )r3   r   r   r   r%   z>   r   r   r4   r6   )r3   r   r4   r   )r3   r   r   p>   r   r   r   r7   )r   r   r	   r0   )APPLYr2   ABs       r   test_apply_beta_to_alpha_router;   G   s   %E 
seA
c3-	AA;#!A$QqTBBBB 
seA
c3s8
c	"#AA;3#SXqtS!A$GGGG 
sCjA
c3-	AA;#!A$QqT:; ; ; 
seA
c3-	AA;#1Q4adCCCC 
oA
c3-	AA;#!A$QqT:; ; ; 
sCjA
c3
c	"#AA;SzA3ad1AaDAB B B
 Cju%A
c3-	AA;!5r :eR[qt!A$0 0 0 0
 Cju%A
c3-	Cs34AA;!:B ?Cj"AaDqt!A$@ @ @ @
 
sCjA
c3-	Cs34AA;!5r :eaV_1Q4ad4 4 4 4 
sCjA
c3s8
c	"#AA;	Sz2QqT3s8QqT:; ; ; 
SCHc#h'(A
c#h
c	"#AA;	SSXs3x("-s3x1sAaDIJ J J 
sCjA
c3-S	"#AA;#sR 0qt!A$GGGG CjSz*A
c3-	AA;!5r :Cj"AaDqt5 5 5 5r!   c                  N   t        d      } | j                  dhdhdk(  sJ t        d      } | j                  dhdhdk(  sJ t        d      } | j                  dhdhdk(  sJ t        d      } | j                  dhdhdk(  sJ t        d      } | j                  d	hd
hdk(  sJ y )Na -> br   r   r   za -> !bz!a -> bz!a -> !bz!z == nznzr6   )r6   r>   )r   prereqfs    r   test_FactRules_parserB      s    (A88cU#////)A88cU#////)A88cU#////*A88cU#////*A88dVC51111r!   c                  &    t        t        d        y )Nc                      t        d      S )Nza -> !a)r    r!   r   r    z'test_FactRules_parse2.<locals>.<lambda>   s    y3 r!   )r
   r+   rE   r!   r   test_FactRules_parse2rF      s    
:34r!   c                     t        g d      fd}  | dt        i      t        t        t        t        t        dk(  sJ  | dt        i      t        t        t        t        dk(  sJ  | dt        i      t        t        dk(  sJ  | d	t        i      d	t        ik(  sJ  | d
t        i      d
t        ik(  sJ  | dt        i      dt        ik(  sJ  | dt        i      t        t        dk(  sJ  | dt        i      t        t        t        dk(  sJ  | d	t        i      t        t        t        dk(  sJ  | dt        i      dt        ik(  sJ y )N)r=   zb -> czb -> dzc -> ec                 @    t              }|j                  |        |S r/   r   deduce_all_factsfactskbrA   s     r   r   z test_FactRules_deduce.<locals>.D       AY
E"	r!   r   r'   r   )r   r   r%   r&   r   )r   r&   r%   r&   r   r   )r   r   r%   )r   TFUr   rA   s    @r   test_FactRules_deducerS      s0   :;A
 c1X;BBBBc1X;BBBBc1X;BBBBc1X;3BBBBc1X;3BBBBc1X;3BBBBc1X;BBBBc1X;BBBBc1X;BBBBc1X;3("""r!   c                      t        ddg      fd}  | dt        i      t        t        t        dk(  sJ  | dt        i      dt        ik(  sJ  | dt        i      t        t        dk(  sJ  | dt        i      dt        ik(  sJ  | dt        i      t        t        d	k(  sJ  | dt        i      dt        ik(  sJ t        g d
       | dt        i      t        t        t        dk(  sJ  | dt        i      dt        ik(  sJ  | dt        i      t        t        t        dk(  sJ  | dt        i      dt        ik(  sJ  | dt        i      t        t        t        dk(  sJ  | dt        i      dt        ik(  sJ y )Npos -> !neg	pos -> !zc                 @    t              }|j                  |        |S r/   rI   rK   s     r   r   z!test_FactRules_deduce2.<locals>.D   rN   r!   pos)rX   negr6   rY   )rX   rY   r6   )rX   r6   )rU   zneg -> !posrV   z	neg -> !zr   rO   rP   rR   s    @r   test_FactRules_deduce2r[      sr   =+./A
 eQZ=Aaa8888eQZ=UA8888eQZ=Aa8888eQZ=ua8888c1X;!A6666c1X;sA6666 	JKAeQZ=Aaa8888eQZ=UA8888eQZ=Aaa8888eQZ=ua8888c1X;!AA6666c1X;sA6666r!   c                     t        dg      fd}  | dt        i      dt        ik(  sJ  | dt        i      t        t        t        dk(  sJ  | dt        i      t        t        dk(  sJ  | dt        i      t        t        dk(  sJ  | t        t        d	      t        t        t        dk(  sJ  | t        t        d      t        t        t        dk(  sJ  | t        t        d      t        t        t        dk(  sJ  | t        t        d	      t        t        t        dk(  sJ  | t        t        d	      t        t        t        dk(  sJ y )
Nzreal == pos | nposc                 @    t              }|j                  |        |S r/   rI   rK   s     r   r   z)test_FactRules_deduce_multiple.<locals>.D   rN   r!   r)   )r)   rX   nposrX   r)   rX   r^   )r)   r^   )rX   r^   rZ   rR   s    @r   test_FactRules_deduce_multipler`      s"   '()A
 fa[>fa[(((fa[>a1====eQZ=Qq1111fa[>a3333 Q"#!Q'GGGGa"#!Q'GGGGa#$1a(HHHHQ"#!Q'GGGGQ"#!Q'GGGGr!   c                     t        dg      fd}  | dt        i      dt        ik(  sJ  | dt        i      t        t        t        t        dk(  sJ  | dt        i      t        t        dk(  sJ  | dt        i      t        t        dk(  sJ  | d	t        i      t        t        d
k(  sJ  | t        t        t        d      t        t        t        t        dk(  sJ  | t        t        d      t        t        dk(  sJ  | t        t        d      t        t        dk(  sJ  | t        t        d
      t        t        d
k(  sJ  | t        t        t        d      t        t        t        t        dk(  sJ  | t        t        t        d      t        t        t        t        dk(  sJ  | t        t        t        d      t        t        t        t        dk(  sJ  | t        t        t        d      t        t        t        t        dk(  sJ  | t        t        t        d      t        t        t        t        dk(  sJ  | t        t        t        d      t        t        t        t        dk(  sJ y )Nzreal == neg | zero | posc                 @    t              }|j                  |        |S r/   rI   rK   s     r   r   z*test_FactRules_deduce_multiple2.<locals>.D   rN   r!   r)   r)   rY   zerorX   rY   r)   rY   rd   )r)   rd   rX   r_   )rY   rd   rX   )r)   rd   rX   )r)   rY   rX   )r)   rY   rd   rZ   rR   s    @r   test_FactRules_deduce_multiple2rf      s1   -./A
 fa[>fa[(((fa[>a1QGGGGeQZ=Qq1111fa[>a3333eQZ=Qq1111 Q!,-!Aq2" " " "a"#!'<<<<a#$A(>>>>a"#!'<<<<a1Q78Qq=, , , ,aQ78Qq=, , , ,a178Qq=, , , , Q!,-!Aq2" " " "Q!,-!Aq2" " " "Q!,-!Aq2" " " "r!   c                      t        g d      } t        |       }|j                  t        t        d       |t        t        dk(  sJ |j                  dt        i       |t        t        t        t        dk(  sJ y )N)real  == neg | zero | posneg   -> real & !zero & !pospos   -> real & !zero & !negre   rd   rc   )r   r   rJ   rO   rP   )rA   bases     r   test_FactRules_deduce_baserl     sm     	 3 	4A !9D1Q/0Aa((((61+&Aa1====r!   c                      t        g d      } d| j                  d   v sJ d| j                  d   v sJ d| j                  d   v sJ d| j                  d   v sJ y )N)rh   ri   rj   znneg  == real & !negznpos  == real & !pos)r^   T)rY   T)nnegT)rX   T)rd   T)r   full_implicationsr@   s    r   test_FactRules_deduce_staticextrp   -  sw     + 	,A Q00????Q00????Q00@@@@Q00@@@@r!   )sympy.core.factsr   r   r   r   r   sympy.core.logicr   r	   sympy.testing.pytestr
   rO   rP   rQ   r,   r;   rB   rF   rS   r[   r`   rf   rl   rp   rE   r!   r   <module>rt      s^   E E % '	8 xS5l2"5#,76H.!"H>Ar!   