ó
¡¼™\c           @  s¿   d  Z  d d l m Z m Z d d l m Z d d l m Z m Z m	 Z	 d d l
 m Z d d l m Z d d l m Z d d l m Z d	 „  Z d
 „  Z d „  Z d „  Z e d „  ƒ Z d S(   s0   Tools for constructing domains for expressions. iÿÿÿÿ(   t   print_functiont   division(   t   sympify(   t   ZZt   QQt   EX(   t	   RealField(   t   build_options(   t   parallel_dict_from_basic(   t   publicc         C  sc  i  t  t  t  f \ } } } } | j t k r9 d „  } n	 d „  } xq |  D]i } | j rm | j s² t } q² qI | j rŒ | s… t } q² t  SqI | | ƒ r® | s§ t } q² t  SqI d SqI W| rÔ t |  | ƒ \ } } n… | rt g  |  D] }	 |	 j	 ^ qä ƒ }
 t
 d |
 ƒ } n | j s| r&t } n t } g  } x$ |  D] } | j | j | ƒ ƒ q9W| | f S(   s?   Handle simple domains, e.g.: ZZ, QQ, RR and algebraic domains. c         S  s   |  j  o |  j S(   N(   t	   is_numbert   is_algebraic(   t   coeff(    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pyt   <lambda>   t    c         S  s   t  S(   N(   t   False(   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pyR      R   t   precN(   R   t	   extensiont   Truet   is_Rationalt
   is_Integert   is_Floatt   Nonet   _construct_algebraict   maxt   _precR   t   fieldR   R   t   appendt
   from_sympy(   t   coeffst   optt   resultt	   rationalst   realst
   algebraicsR   R   t   domaint   ct   max_prec(    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pyt   _construct_simple   s:    						"	c         C  så  d d l  m } g  t g  ƒ } } x­ |  D]¥ } | j rT d d t j | ƒ f } nn | j ƒ  d } | | 8} | j ƒ  d } | | } | j	 | ƒ t j | ƒ } t j | ƒ } | | | f } | j
 | ƒ q* Wt | ƒ } | | d t d t ƒ\ } }	 }
 t g  t |	 | ƒ D] \ } } | | ^ qƒ } t j | | f ƒ | j j } } x„ t | ƒ D]v \ } \ } } } | d k	 r²| | j j |
 | j | ƒ | t ƒ | } n | j j | g | t ƒ } | | | <qaW| | f S(   sD   We know that coefficients are algebraic so construct the extension. iÿÿÿÿ(   t   primitive_elementi    t   ext   polysN(   t   sympy.polys.numberfieldsR'   t   setR   R   R   R   t   as_coeff_addt   as_coeff_mult   addR   t   listR   t   sumt   zipt   algebraic_fieldt   rept	   enumeratet   dtypet	   from_listt   index(   R   R   R'   R   t   extsR   t   at   bt   gt   spant   Ht   st   extt   rootR#   t   i(    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pyR   A   s0    	

!2""0c         C  sñ  g  g  } } x: |  D]2 } | j  ƒ  \ } } | j | ƒ | j | ƒ q Wt | | ƒ \ } } | sj d S| j d k rÔ t d „  | Dƒ ƒ r“ d St g  ƒ }	 x2 | D]' }
 |
 j } |	 | @rÃ d S|	 | O}	 q¦ Wn  t | ƒ } t | ƒ d } | |  } | | } | j	 rt
 } nJ t d | } } x6 | D]. } t | ƒ d k sR| | k r.t
 } Pq.q.Wt g  ƒ }  | sÝxº t | | ƒ D]T \ } } | | } x; | j ƒ  D]- \ } } | | } |  j | ƒ | | | <q¥Wq‚WnR xO t | | ƒ D]> \ } } |  j t | j ƒ  ƒ ƒ |  j t | j ƒ  ƒ ƒ qíWt t } } x? |  D]7 } | j rg| j szt
 } qzqC| j rCt
 } PqCqCW| r¸t g  |  D] } | j ^ qŽƒ } t d | ƒ } n | rÇt } n t } g  } | s?| j | Œ  } xü | D]I } x- | j ƒ  D] \ } } | j | ƒ | | <qW| j | | ƒ ƒ qïWn¨ | j | Œ  } x– t | | ƒ D]… \ } } x- | j ƒ  D] \ } } | j | ƒ | | <qwWx- | j ƒ  D] \ } } | j | ƒ | | <q§W| j | | | f ƒ ƒ q^W| | f S(   s<   Handle composite domains, e.g.: ZZ[X], QQ[X], ZZ(X), QQ(X). c         s  s!   |  ] } | j  o | j Vq d  S(   N(   R
   R   (   t   .0t   gen(    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pys	   <genexpr>{   s    i   i    i   R   N(   i    (   t   as_numer_denomR   R   R   t	   compositet   anyR+   t   free_symbolst   lenR   R   R   R1   t   itemsR.   t   updateR/   t   valuesR   R   R   R   R   R   R   R   t	   poly_ringR   t
   frac_field(   R   R   t   numerst   denomsR   t   numert   denomR)   t   genst   all_symbolsRC   t   symbolst   nt   kt	   fractionst   zerost   monomR    R!   R$   R%   t   groundR   R#   (    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pyt   _construct_compositel   sˆ    	


		

			"	c         C  s>   t  g  } } x$ |  D] } | j | j | ƒ ƒ q W| | f S(   s6   The last resort case, i.e. use the expression domain. (   R   R   R   (   R   R   R#   R   R   (    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pyt   _construct_expressionÒ   s    c         K  s  t  | ƒ } t |  d ƒ rp t |  t ƒ rg |  s@ g  g  } } qm t t t |  j ƒ  ƒ Œ  ƒ \ } } qy |  } n	 |  g } t t t | ƒ ƒ } t	 | | ƒ } | d k	 rÜ | t k	 rÄ | \ } } q3t | | ƒ \ } } nW | j t k rô d } n t | | ƒ } | d k	 r| \ } } n t | | ƒ \ } } t |  d ƒ r}t |  t ƒ rp| t t t | | ƒ ƒ ƒ f S| | f Sn | | d f Sd S(   s9   Construct a minimal domain for the list of coefficients. t   __iter__i    N(   R   t   hasattrt
   isinstancet   dictR/   R1   RI   t   mapR   R&   R   R   R\   RE   R[   (   t   objt   argsR   t   monomsR   R   R#   (    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pyt   construct_domainÜ   s2    '			N(   t   __doc__t
   __future__R    R   t
   sympy.coreR   t   sympy.polys.domainsR   R   R   t   sympy.polys.domains.realfieldR   t   sympy.polys.polyoptionsR   t   sympy.polys.polyutilsR   t   sympy.utilitiesR	   R&   R   R[   R\   Re   (    (    (    s6   lib/python2.7/site-packages/sympy/polys/constructor.pyt   <module>   s   	4	+	f	
