
    h                     ^   S r  " S S5      r\S:X  Ga  \" S5        \" 5       r\" S5        \R                  / SQ5      r\" S\S    35        \" S	\S
    35        \" S\S    35        \" S5        \R                  / SQ5      r\" S\S    35        \" S\S    35        \" S5        \R                  SSS5      r\" S\S    35        \" S5        \R                  S5      r\" S\S    35        \" S\S    35        \" S5        \" S5        \" S5        \" S5        \" S5        \" S 5        g!g!)"z?
Abstract Reasoner - Pattern recognition and symbolic thinking
c                   2    \ rS rSrS rS rS rS rS rSr	g)	AbstractReasoner   c                      / U l         0 U l        g N)patterns	analogies)selfs    G/home/james-whalen/eden-agi-project/core/reasoning/abstract_reasoner.py__init__AbstractReasoner.__init__   s        c           	        ^ T(       a  [        T5      S:  a  SS0$ [        S T 5       5      (       Ga!  [        [        T5      S-
  5       Vs/ s H  nTUS-      TU   -
  PM     nn[        [        U5      5      S:X  a  SSUS    3TS	   US   -   S
.$ [        [        T5      S-
  5       Vs/ s H  nTU   S:w  a  TUS-      TU   -  OSPM     nn[        [        U5      5      S:X  a  US   S:w  a  SSUS    3TS	   US   -  S
.$ [        T5      S:  a>  [        U4S j[        S[        T5      5       5       5      nU(       a  SSTS	   TS   -   S
.$ [        S T 5       5      (       aB  T Vs/ s H  n[        U5      PM     nnU[	        U5      :X  a  SSS[        US	   S-   5      -   S
.$ SSS.$ s  snf s  snf s  snf )z(Recognize abstract patterns in sequences   patterninsufficient_datac              3   N   #    U  H  n[        U[        [        45      v   M     g 7fr   )
isinstanceintfloat.0xs     r
   	<genexpr>5AbstractReasoner.recognize_pattern.<locals>.<genexpr>   s     =Hqz!c5\**Hs   #%   
arithmeticzadd     )r   rulenext	geometriczmultiply by    c              3   R   >#    U  H  nTU   TUS -
     TUS-
     -   :H  v   M     g7f)r   r   N )r   isequences     r
   r   r   '   s6      =$;q &a[HQqSMHQqSM,II$;s   $'	fibonaccizsum of previous twoc              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r   strr   s     r
   r   r   1   s     48az!S!!8s   increasing_lengthzstrings get longerstring_of_length_complexznot recognized)r   r   )lenallrangesetsortedr*   )r	   r&   r%   diffsratiosis_fibr   lengthss    `      r
   recognize_pattern"AbstractReasoner.recognize_pattern
   s   3x=1,233 =H===:?Ha:PQ:PQXac]Xa[0:PEQ 3u:!#+"58*-$RL583  $CM!O464 6>a[A5Ehqsmhqk11L4  63v;1$a**6!9+6$RL6!94  8}! =$)!S]$;= =#. 5 (x| ;  48444'/0x!s1vxG0&/)20/#gbkAo2FF  %.>??S R6, 1s   F3-#F80F=c                 L   SSSSSSS.nUR                  5       UR                  5       4U;   ai  UR                  5       XAR                  5       UR                  5       4   S   :X  a2  U S	U S
U S3XAR                  5       UR                  5       4   S   SS.$ U S	U S
U S3SSS.$ )z@A is to B as C is to ?
Example: cat is to meow as dog is to bark)dogbark)fishswim)hotcold)tallshort)icer?   )moondim))catmeow)birdfly)daynight)bigsmall)firer>   )sunbrightr   :z :: z:?r   learned)analogyanswerrelationshipunknown)lower)r	   abcanalogies_dbs        r
   form_analogyAbstractReasoner.form_analogy<   s     ---/,.
 GGIqwwy!\1wwyL'')QWWY)?@CC"#AaSQCr2*GGIqwwy+AB1E$-  AaSQCr*%
 	
r   c                     U(       d  SS0$ [        S U 5       5      (       a  SSUS.$ [        S U 5       5      (       a  SS	US.$ S
S[        U5       S3US.$ )z/Extract abstract concept from concrete examplesconceptnonec              3   Z   #    U  H!  nS [        U5      R                  5       ;   v   M#     g7f)has_legsNr*   rV   r   exs     r
   r   4AbstractReasoner.abstract_concept.<locals>.<genexpr>`   s     @xzSW]]_,x   )+things_with_legszentities that have legs)r^   abstractionexamplesc              3   Z   #    U  H!  nS [        U5      R                  5       ;   v   M#     g7f)moveNrb   rc   s     r
   r   re   g   s     <8RvR(8rf   mobile_entitieszthings that can moverelated_groupz	group of z related items)r/   r.   )r	   ri   s     r
   abstract_concept!AbstractReasoner.abstract_conceptZ   s~    v&& @x@@@-8$  <8<<<,5$  '&s8}o^D 
 	
r   c                    UR                  5       nSU;   aU  SU;   aO  UR                  S5      nUS   R                  SS5      R                  5       nUS   R                  5       nSUUSSS	.$ S
U;   a  SSSS.$ SU;   a  SSSS.$ SSS.$ )zReason about symbolic logicifthenr    r   conditionalzif-thenT)type	conditionconsequencelogicvalidz and conjunctionandzall conditions true)ru   rx   requiresz or disjunctionorzat least one condition truesimple	statement)ru   rx   )rV   splitreplacestrip)r	   r   statement_lowerpartsrv   rw   s         r
   symbolic_reasoning#AbstractReasoner.symbolic_reasoningu   s    #//+ ?"v'@#))&1Ea((r288:I(..*K &&*"  o%%1  _$%9  !;77r   )r   r   N)
__name__
__module____qualname____firstlineno__r   r7   r[   rn   r   __static_attributes__r$   r   r
   r   r      s    0@d
<
6"8r   r   __main__zABSTRACT REASONER TESTu   
🔢 Pattern: [2, 4, 6, 8, ?])r            z   Pattern: r   z	   Rule: r   z	   Next: r    u!   
🔢 Pattern: [1, 1, 2, 3, 5, ?])r   r   r   r"   r   u    
🔗 Analogy: cat:meow :: dog:?rE   rF   r:   z   Answer: rS   u,   
⚡ Logic: 'If it rains then ground is wet'zIf it rains then ground is wetz	   Type: ru   z
   Logic: rx   u   
🧠 Eden can now:z    - Recognize abstract patternsz   - Form analogiesz#   - Extract concepts from examplesz   - Reason symbolicallyu"   
✅ ABSTRACT REASONER OPERATIONALN)	__doc__r   r   printreasonerr7   resultr[   r   r$   r   r
   <module>r      s  R8 R8h z	
"#!H 

+,''5F	L	*+
,-	IfVn%
&'	IfVn%
&'	
./''8F	L	*+
,-	IfVn%
&' 

-.""5&%8F	Kx()
*+ 

9:(()IJF	IfVn%
&'	Jvg'
()	
 !	
,-	
 	
/0	
$%	
/0E r   