
    wg.                     T    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	  G d d      Z
y)	    )Tuple)S)Symbol)SympifyError)FunctionTypec                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)	TableForma  
    Create a nice table representation of data.

    Examples
    ========

    >>> from sympy import TableForm
    >>> t = TableForm([[5, 7], [4, 2], [10, 3]])
    >>> print(t)
    5  7
    4  2
    10 3

    You can use the SymPy's printing system to produce tables in any
    format (ascii, latex, html, ...).

    >>> print(t.as_latex())
    \begin{tabular}{l l}
    $5$ & $7$ \\
    $4$ & $2$ \\
    $10$ & $3$ \\
    \end{tabular}

    c                    ddl m} t        ||      r|j                         }t	        |      }|j                  dd      }d}|d}d}t        |      }t        d |D              }t        |      D ]d  \  }}	t	        |	      |k7  r!|	j                  |g|t	        |	      z
  z         t        |	      D ]  \  }
}||s|}n	 t        |      }||	|
<    |	||<   f t        |D cg c]
  }t        |  c} }|j                  d	ddg      }|d
k(  rt        d|dz         t        d|dz         g}n1|\  }}|d
k(  rt        d|dz         }|d
k(  rt        d|dz         }||g}d}|j                  dd      }d } ||      }||v r|g|z  }n4g }|D ]-  } ||      }|j                  |       |dvs!t!        d|z         |d   rt	        |      |dz   k(  r|d   }|dd }nd}t	        |      |k7  rt!        d|dt	        |            |j                  ddg|z        }|j                  dd      }|| _        || _        || _        || _        || _        || _        || _        || _        y# t        $ r t        t        |            }Y w xY wc c}w )a  
        Creates a TableForm.

        Parameters:

            data ...
                            2D data to be put into the table; data can be
                            given as a Matrix

            headings ...
                            gives the labels for rows and columns:

                            Can be a single argument that applies to both
                            dimensions:

                                - None ... no labels
                                - "automatic" ... labels are 1, 2, 3, ...

                            Can be a list of labels for rows and columns:
                            The labels for each dimension can be given
                            as None, "automatic", or [l1, l2, ...] e.g.
                            ["automatic", None] will number the rows

                            [default: None]

            alignments ...
                            alignment of the columns with:

                                - "left" or "<"
                                - "center" or "^"
                                - "right" or ">"

                            When given as a single value, the value is used for
                            all columns. The row headings (if given) will be
                            right justified unless an explicit alignment is
                            given for it and all other columns.

                            [default: "left"]

            formats ...
                            a list of format strings or functions that accept
                            3 arguments (entry, row number, col number) and
                            return a string for the table entry. (If a function
                            returns None then the _print method will be used.)

            wipe_zeros ...
                            Do not show zeros in the table.

                            [default: True]

            pad ...
                            the string to use to indicate a missing value (e.g.
                            elements that are None or those that are missing
                            from the end of a row (i.e. any row that is shorter
                            than the rest is assumed to have missing values).
                            When None, nothing will be shown for values that
                            are missing from the end of a row; values that are
                            None, however, will be shown.

                            [default: None]

        Examples
        ========

        >>> from sympy import TableForm, Symbol
        >>> TableForm([[5, 7], [4, 2], [10, 3]])
        5  7
        4  2
        10 3
        >>> TableForm([list('.'*i) for i in range(1, 4)], headings='automatic')
          | 1 2 3
        ---------
        1 | .
        2 | . .
        3 | . . .
        >>> TableForm([[Symbol('.'*(j if not i%2 else 1)) for i in range(3)]
        ...            for j in range(4)], alignments='rcl')
            .
          . . .
         .. . ..
        ... . ...
        r   MatrixpadNF Tc              3   2   K   | ]  }t        |        y wNlen).0lines     ]/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/printing/tableform.py	<genexpr>z%TableForm.__init__.<locals>.<genexpr>   s     ,tT,   headings	automatic   )lrc
alignmentsr   c                     | j                         j                         } t        |       dkD  rddddj                  | |       S ddddj                  | |       S )Nr   r   r   r   )leftrightcenter)<>^)striplowerr   get)as    r   
_std_alignz&TableForm.__init__.<locals>._std_align   sS    	!A1vz #cSAEEaKK s599!Q??    zalignment "%s" unrecognizedr   z%wrong number of alignments: expected z	 but got formats
wipe_zeros)sympy.matrices.denser   
isinstancetolistr   r(   r   max	enumerateextendr   r   strr   rangeappend
ValueError_w_h_lines	_headings_head_align_alignments_column_formats_wipe_zeros)selfdatakwargr   r9   r   ok_Noner8   ir   jljdr:   r   r;   h1h2allowr   r*   	std_alignr=   r)   r<   r>   r?   s                              r   __init__zTableForm.__init__#   s   f 	0 dF#;;=DY iit$;CGSk,t,,  	GAt4yBSE2D	>23"4 	2:" -rU Q	 DG	 D1q1299Z$6{"q"q&)5BF+;<IFB[ 1b1f%[ 1b1f%RIYY|S1
	@ z*	$+b.KK $&qM	""9-O3$%B"&# $ $	$ Q<C,Q6%a.K%ab/KK{r!S%'( (  ))Ivby9iid3"&&.&u ( -#CG_- 2s   >I& J
&JJc                 "    ddl m}  || d       S Nr   )sstr)orderr4   rO   r@   rO   s     r   __repr__zTableForm.__repr__       D%%r+   c                 "    ddl m}  || d       S rN   rQ   rR   s     r   __str__zTableForm.__str__   rT   r+   c                 2    ddl m}  || j                        S )a  Returns the data of the table in Matrix form.

        Examples
        ========

        >>> from sympy import TableForm
        >>> t = TableForm([[5, 7], [4, 2], [10, 3]], headings='automatic')
        >>> t
          | 1  2
        --------
        1 | 5  7
        2 | 4  2
        3 | 10 3
        >>> t.as_matrix()
        Matrix([
        [ 5, 7],
        [ 4, 2],
        [10, 3]])
        r   r   )r.   r   r:   )r@   r   s     r   	as_matrixzTableForm.as_matrix   s    ( 	0dkk""r+   c                     t        |       S r   r4   )r@   s    r   as_strzTableForm.as_str   s    4yr+   c                     ddl m }  ||       S )Nr   latexr]   )r@   r^   s     r   as_latexzTableForm.as_latex   s     T{r+   c           	         dg| j                   z  }g }| j                  D ]y  }g }t        | j                         D ]L  }t        ||         }| j                  r|dk(  rd}t        |      }|||   kD  r|||<   |j                  |       N |j                  |       { | j                  d   rR| j                  d   D 	cg c]  }	t        |	       c}	| j                  d<   t        d | j                  d   D              }
| j                  d   rog }t        | j                         D ]F  }t        | j                  d   |         }t        |      }|||   kD  r|||<   |j                  |       H || j                  d<   g }d }t        | j                  |      D cg c]  \  }} |||       }}}| j                  d   r5|j                  d || j                  
             |j                  dd       dj                  |      dz   }g }| j                  d   rf| j                  d   }| j                  d   rd	g|z   }|t        |      z  }|j                  |       |j                  d
t        |      dz
  z  dz          t        |      D ]  \  }}t        |      D cg c]-  \  }}| j                  |   dk7  r|n|j!                  ||         / }}}| j                  d   r:| j                  d   |   }| j                  dk7  r|n|j!                  
      }|g|z   }|j                  |t        |      z          d	j                  |      dd S c c}	w c c}}w c c}}w )z
        Returns the string representation of 'self'.

        Examples
        ========

        >>> from sympy import TableForm
        >>> t = TableForm([[5, 7], [4, 2], [10, 3]])
        >>> s = t.as_str()

        r   0r   c              3   2   K   | ]  }t        |        y wr   r   )r   xs     r   r   z&TableForm._sympystr.<locals>.<genexpr>  s     @c!f@r   r   c                 2    d| dk(  rdndt        |      dS )Nz%r   - srZ   )alignws     r   _alignz#TableForm._sympystr.<locals>._align  s!    ",A r+   |
rf   re   r   N)r8   r:   r5   r4   r?   r   r6   r;   r1   zipr=   insertr<   jointupler2   r"   )r@   pcolumn_widthslinesr   new_linerD   rg   ri   rc   _head_width
format_strrj   rh   rG   
first_linerE   r   s                     r   	_sympystrzTableForm._sympystr   sS    dggKK 	#DH477^ #QL##cAF}Q'''(M!$"# LL"	# >>!151B CAQ CDNN1@dnnQ.?@@K>>!H477^ #q)!,-F}Q'''(M!$"# !)DNN1
	
 $**M:<85!fUA& <
 <>>!a(8(8+!FGa%XXj)D0
>>!q!A~~a D1H#eAh.JHHZ HHSC
Oa/0478 ' 	,GAt8A$I041 &&q)S0-*+, IA I~~a NN1%a(**c1QXXk* C!GHHZ%(*+	, wwqz#2Y !D(< Is   ;MM2Mc                    | j                   d   rUg }t        | j                        D ],  }|j                  t	        | j                   d   |                . || j                   d<   g }| j                   d   r@| j                   d   D cg c]  }t	        |       c}| j                   d<   | j
                  g}|j                  | j                         ddj                  |      z   dz   }| j                   d   rE| j                   d   }| j                   d   rdg|z   }dj                  |      dz   d	z   }||z  }|d
z  }t        | j                        D ]  \  }}	g }t        |	      D ]  \  }
}| j                  r|dv r|j                  d       (| j                  |
   }|rEt        |t              r ||||
      }||j                  |      }n||z  }|j                  |       ~|j                  |      }|j                  d|z          | j                   d   r| j                   d   |   g|z   }|dj                  |      dz   d	z   z  } |dz  }|S c c}w )z>
        Returns the string representation of 'self'.
        r   r   z\begin{tabular}{r   z}
rf   z & z \\rl   z\hline
)r   ra   z$%s$z\end{tabular})r;   r5   r8   r6   r4   r<   r3   r=   rp   r2   r:   r?   r>   r/   r   _print)r@   printerru   rD   r   rc   rg   rG   rx   r   rE   fvs                r   _latexzTableForm._latex=  sJ   
 >>!H477^ ;DNN1$5a$8 9:; !)DNN1
>>!151B CAQ CDNN1**+J$**+#((:"66>>>!q!A~~a D1HA/$6JOA!!A - 	/GAtA!$ )1##hHHSM((+!!\2aAJ9 'q 1AEHHQKq)AHHVaZ()  ~~a ^^A&q)*Q.A'$..A)	/* 	
G !Ds   IN)__name__
__module____qualname____doc__rL   rS   rV   rX   r[   r_   ry   r    r+   r   r	   r	   	   s3    2f'P&&#.IV1r+   r	   N)sympy.core.containersr   sympy.core.singletonr   sympy.core.symbolr   sympy.core.sympifyr   typesr   r	   r   r+   r   <module>r      s     ' " $ + e er+   