ó
Ħĵ\c           @  sj  d  d l  m Z m Z d  d l m Z d  d l 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	 g Z e i d
 d 6d d 6f e i d d 6f f Z e e f Z e e
 e e f Z d   Z e d  Z d d  Z e e d e d  Z d   d e d  Z d Z i d d 6d d 6Z e d   d e e d  Z! d S(    i˙˙˙˙(   t   print_functiont   division(   t   Basic(   t   Expr(   t   Symbol(   t   Integert   Rationalt   Float(   t   default_sort_key(   t   Add(   t   Mult   dotprintt   bluet   colort   ellipset   shapet   blackc         C  sŻ   t  |  t  s t |   St |   t k rS g  |  j D] } t |  |  ^ q5 } n3 t |   t k r} t |  j	 d t
 } n	 |  j	 } d t |   j d j t t |   f S(   s:    A string that follows obj = type(obj)(*obj.args) exactly t   keys   %s(%s)s   , (   t
   isinstanceR   t   strt   typet   slotClassest	   __slots__t   getattrt   sort_classest   sortedt   argsR   t   __name__t   joint   mapt   purestr(   t   xt   slotR   (    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pyR      s    
(	c         C  sC   t    } x3 | D]+ \ } } t |  |  r | j |  q q W| S(   sÔ   Merge style dictionaries in order

    Examples
    ========

    >>> from sympy import Symbol, Basic, Expr
    >>> from sympy.printing.dot import styleof
    >>> styles = [(Basic, {'color': 'blue', 'shape': 'ellipse'}),
    ...           (Expr,  {'color': 'black'})]

    >>> styleof(Basic(1), styles)
    {'color': 'blue', 'shape': 'ellipse'}

    >>> x = Symbol('x')
    >>> styleof(x + 1, styles)  # this is an Expr
    {'color': 'black', 'shape': 'ellipse'}
    (   t   dictR   t   update(   t   exprt   stylest   stylet   typt   sty(    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pyt   styleof!   s
    	s   , c         C  s#   | j  d   t |  j    D  S(   sÙ    Print a dictionary of attributes

    Examples
    ========

    >>> from sympy.printing.dot import attrprint
    >>> print(attrprint({'color': 'blue', 'shape': 'ellipse'}))
    "color"="blue", "shape"="ellipse"
    c         s  s   |  ] } d  | Vq d S(   s	   "%s"="%s"N(    (   t   .0t   item(    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pys	   <genexpr>C   s    (   R   R   t   items(   t   dt	   delimiter(    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pyt	   attrprint9   s    
c         C  s   t  |  |  } t |  t  r= |  j r= t |  j j  } n | |   } | | d <t |   } | r| | d t |  7} n  d | t |  f S(   sç    String defining a node

    Examples
    ========

    >>> from sympy.printing.dot import dotnode
    >>> from sympy.abc import x
    >>> print(dotnode(x))
    "Symbol(x)_()" ["color"="black", "label"="x", "shape"="ellipse"];
    t   labels   _%ss
   "%s" [%s];(	   R(   R   R   t   is_AtomR   t	   __class__R   R   R.   (   R#   R$   t	   labelfunct   post   repeatR%   R/   t   expr_str(    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pyt   dotnodeE   s    
c         C  s   t  |  t  S(   N(   R   R   (   R   (    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pyt   <lambda>]   t    c   	      C  sş   | |   r g  St  |   } g  |  j D] } t  |  ^ q& } | r | d t |  7} g  t |  D]' \ } } | d t | | f  ^ qe } n  g  | D] } d | | f ^ q Sd S(   s   List of strings for all expr->expr.arg pairs

    See the docstring of dotprint for explanations of the options.

    Examples
    ========

    >>> from sympy.printing.dot import dotedges
    >>> from sympy.abc import x
    >>> for e in dotedges(x+2):
    ...     print(e)
    "Add(Integer(2), Symbol(x))_()" -> "Integer(2)_(0,)";
    "Add(Integer(2), Symbol(x))_()" -> "Symbol(x)_(1,)";
    s   _%ss   "%s" -> "%s";N(   R   R   R   t	   enumerate(	   R#   t   atomR3   R4   R5   t   argt   arg_strst   it   arg_str(    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pyt   dotedges]   s    "=s|   digraph{

# Graph style
%(graphstyle)s

#########
# Nodes #
#########

%(nodes)s

#########
# Edges #
#########

%(edges)s
}t   TDt   rankdirt   outt   orderingc         C  s   t  |  t  S(   N(   R   R   (   R   (    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pyR7      s   c      	     s   t  j   } | j |  g   g   d          f d    |  d  t i t | d d d 6d j   d 6d j   d 6S(	   sO  
    DOT description of a SymPy expression tree

    Options are

    ``styles``: Styles for different classes.  The default is::

        [(Basic, {'color': 'blue', 'shape': 'ellipse'}),
        (Expr, {'color': 'black'})]``

    ``atom``: Function used to determine if an arg is an atom.  The default is
          ``lambda x: not isinstance(x, Basic)``.  Another good choice is
          ``lambda x: not x.args``.

    ``maxdepth``: The maximum depth.  The default is None, meaning no limit.

    ``repeat``: Whether to different nodes for separate common subexpressions.
          The default is True.  For example, for ``x + x*y`` with
          ``repeat=True``, it will have two nodes for ``x`` and with
          ``repeat=False``, it will have one (warning: even if it appears
          twice in the same object, like Pow(x, x), it will still only appear
          only once.  Hence, with repeat=False, the number of arrows out of an
          object might not equal the number of args it has).

    ``labelfunc``: How to label leaf nodes.  The default is ``str``.  Another
          good option is ``srepr``. For example with ``str``, the leaf nodes
          of ``x + 1`` are labeled, ``x`` and ``1``.  With ``srepr``, they
          are labeled ``Symbol('x')`` and ``Integer(1)``.

    Additional keyword arguments are included as styles for the graph.

    Examples
    ========

    >>> from sympy.printing.dot import dotprint
    >>> from sympy.abc import x
    >>> print(dotprint(x+2)) # doctest: +NORMALIZE_WHITESPACE
    digraph{
    <BLANKLINE>
    # Graph style
    "ordering"="out"
    "rankdir"="TD"
    <BLANKLINE>
    #########
    # Nodes #
    #########
    <BLANKLINE>
    "Add(Integer(2), Symbol(x))_()" ["color"="black", "label"="Add", "shape"="ellipse"];
    "Integer(2)_(0,)" ["color"="black", "label"="2", "shape"="ellipse"];
    "Symbol(x)_(1,)" ["color"="black", "label"="x", "shape"="ellipse"];
    <BLANKLINE>
    #########
    # Edges #
    #########
    <BLANKLINE>
    "Add(Integer(2), Symbol(x))_()" -> "Integer(2)_(0,)";
    "Add(Integer(2), Symbol(x))_()" -> "Symbol(x)_(1,)";
    }

    c      
     s°    j  t |   d  d | d    r> |  k r> d  S j t |  d   d | d   g  t |  j  D]5 \ } }   |  ss  | | d | | f  ^ qs d  S(   NR2   R3   R4   R:   i   (   t   appendR6   t   extendR?   R9   R   (   t   et   depthR3   R=   R;   (   R:   t   edgesR2   t   maxdeptht   nodesR4   R$   t   traverse(    s1   lib/python2.7/site-packages/sympy/printing/dot.pyRK   Ó   s
    (%i    R-   s   
t
   graphstyleRJ   RH   (    (   t   _graphstylet   copyR"   t   templateR.   R   (   R#   R$   R:   RI   R4   R2   t   kwargsRL   (    (   R:   RH   R2   RI   RJ   R4   R$   RK   s1   lib/python2.7/site-packages/sympy/printing/dot.pyR      s    A'N(    (    ("   t
   __future__R    R   t   sympy.core.basicR   t   sympy.core.exprR   t   sympy.core.symbolR   t   sympy.core.numbersR   R   R   t   sympy.core.compatibilityR   t   sympy.core.addR	   t   sympy.core.mulR
   t   __all__t   default_stylesR   R   R   R(   R.   R   t   TrueR6   R?   RO   RM   t   NoneR   (    (    (    s1   lib/python2.7/site-packages/sympy/printing/dot.pyt   <module>   s*   		,	