
    \h.                     T    S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	   " S S5      r
g)	    )Tuple)S)Symbol)SympifyError)FunctionTypec                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)	TableForm	   as  
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                 Z   SSK Jn  [        X5      (       a  UR                  5       n[	        U5      nUR                  SS5      nSnUc  SnSn[        U5      n[        S U 5       5      n[        U5       Hj  u  p[	        U	5      U:w  a!  U	R                  U/U[	        U	5      -
  -  5        [        U	5       H"  u  pUc
  U(       d  UnO [        U5      nXU
'   M$     XU'   Ml     [        U Vs/ s H  n[        U6 PM     sn6 nUR                  S	SS/5      nUS
:X  a  [        SUS-   5      [        SUS-   5      /nO3Uu  nnUS
:X  a  [        SUS-   5      nUS
:X  a  [        SUS-   5      nUU/nSnUR                  SS5      nS nU" U5      nUU;   a  U/U-  nO8/ nU H0  nU" U5      nUR                  U5        US;  d  M$  [!        SU-  5      e   US   (       a  [	        U5      US-   :X  a  US   nUSS nOSn[	        U5      U:w  a  [!        SU< S[	        U5      < 35      eUR                  SS/U-  5      nUR                  SS5      nXpl        X@l        Xl        Xl        UU l        UU l        UU l        UU l        g! [         a    [        [        U5      5      n GNf = fs  snf )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   8   #    U  H  n[        U5      v   M     g 7fNlen).0lines     P/var/www/auris/envauris/lib/python3.13/site-packages/sympy/printing/tableform.py	<genexpr>%TableForm.__init__.<locals>.<genexpr>   s     ,ttTt   headings	automatic   )lrc
alignmentsr   c                     U R                  5       R                  5       n [        U 5      S:  a  SSSS.R                  X 5      $ SSSS.R                  X 5      $ )Nr   r   r   r   )leftrightcenter)<>^)striplowerr   get)as    r   
_std_align&TableForm.__init__.<locals>._std_align   sO    	!A1vz #cSAEEaKK s599!??    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   r<   r   ok_Noner;   ir   jljdr=   r   r>   h1h2allowr    r,   	std_alignr@   r+   r?   rA   rB   s                              r   __init__TableForm.__init__#   s   f 	0 d##;;=DY iit$;CGSk,t,, GA4yBSE2D	>23"4:" -rU Q ) G ' D1DqD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   J,J(J%$J%c                     SSK Jn  U" U S S9$ Nr   )sstr)orderr7   rS   rC   rS   s     r   __repr__TableForm.__repr__       D%%r.   c                     SSK Jn  U" U S S9$ rR   rU   rV   s     r   __str__TableForm.__str__   rY   r.   c                 2    SSK Jn  U" U R                  5      $ )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   )r1   r   r=   )rC   r   s     r   	as_matrixTableForm.as_matrix   s    ( 	0dkk""r.   c                     [        U 5      $ r   r7   )rC   s    r   as_strTableForm.as_str   s    4yr.   c                     SSK J n  U" U 5      $ )Nr   latexre   )rC   rf   s     r   as_latexTableForm.as_latex   s     T{r.   c           	         S/U R                   -  n/ nU R                   H  n/ n[        U R                   5       HQ  n[        XF   5      nU R                  (       a  US:X  a  Sn[        U5      nXU   :  a  XU'   UR                  U5        MS     UR                  U5        M     U R                  S   (       aU  U R                  S    V	s/ s H  n	[        U	5      PM     sn	U R                  S'   [        S U R                  S    5       5      n
U R                  S   (       ao  / n[        U R                   5       HF  n[        U R                  S   U   5      n[        U5      nXU   :  a  XU'   UR                  U5        MH     XPR                  S'   / nS n[        U R                  U5       VVs/ s H  u  pU" X5      PM     nnnU R                  S   (       a5  UR                  SU" U R                  W
5      5        UR                  SS5        SR                  U5      S-   n/ nU R                  S   (       ak  U R                  S   nU R                  S   (       a  S	/U-   nU[        U5      -  nUR                  U5        UR                  S
[        U5      S-
  -  S-   5        [        U5       H  u  pd[        U5       VVs/ s H/  u  nnU R                  U   S:w  a  UOUR!                  UU   5      PM1     nnnU R                  S   (       a;  U R                  S   U   nU R                  S:w  a  UOUR!                  W
5      nU/U-   nUR                  U[        U5      -  5        M     S	R                  U5      SS $ s  sn	f s  snnf s  snnf )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   8   #    U  H  n[        U5      v   M     g 7fr   r   )r   xs     r   r   &TableForm._sympystr.<locals>.<genexpr>  s     @.?c!ff.?r   r   c                 8    SU S:X  a  SOS< [        U5      < S3$ )Nz%r   - sra   )alignws     r   _align#TableForm._sympystr.<locals>._align  s!    ",A r.   |
rp   ro   r   N)r;   r=   r8   r7   rB   r   r9   r>   r4   zipr@   insertr?   jointupler5   r$   )rC   pcolumn_widthslinesr   new_linerG   rq   rs   rl   _head_width
format_strrt   rr   rJ   
first_linerH   r   s                     r   	_sympystrTableForm._sympystr   s<    dggKKDH477^L##cAFQ'''(!$" $ LL"   >>!151B C1BAQ1B CDNN1@dnnQ.?@@K>>!H477^q)!,-FQ'''(!$" $ !)NN1
	
 $**M:<: ,45fU&: 	 <>>!a(8(8+!FGa%XXj)D0
>>!q!A~~a D1H#eAh.JHHZ HHSC
Oa/0478 'GA8A$I8G1 &&q)S0-*+,8G  I~~a NN1%a(**c1QXXk* C!GHHZ%(*+ ( wwqz#2Y !D(< Is   M=-N 6Nc                    U R                   S   (       aV  / n[        U R                  5       H-  nUR                  [	        U R                   S   U   5      5        M/     X R                   S'   / nU R                   S   (       aC  U R                   S    Vs/ s H  n[	        U5      PM     snU R                   S'   U R
                  /nUR                  U R                  5        SSR                  U5      -   S-   nU R                   S   (       aI  U R                   S   nU R                   S   (       a  S/U-   nSR                  U5      S-   S	-   nXh-  nUS
-  n[        U R                  5       GH  u  p9/ n[        U	5       H  u  pU R                  (       a  US;   a  UR                  S5        M/  U R                  U
   nU(       aJ  [        U[        5      (       a  U" XSU
5      nUc  UR                  U5      nOX-  nUR                  U5        M  UR                  U5      nUR                  SU-  5        M     U R                   S   (       a  U R                   S   U   /U-   nUSR                  U5      S-   S	-   -  nGM     US-  nU$ s  snf )z.
Returns the string representation of 'self'.
r   r   z\begin{tabular}{r   z}
rp   z & z \\rw   z\hline
)r   rj   z$%s$z\end{tabular})r>   r8   r;   r9   r7   r?   r6   r@   r{   r5   r=   rB   rA   r2   r   _print)rC   printerr   rG   r    rl   rq   rJ   r   r   rH   fvs                r   _latexTableForm._latex=  s9   
 >>!H477^DNN1$5a$8 9: $ !)NN1
>>!151B C1BAQ1B CDNN1**+J$**+#((:"66>>>!q!A~~a D1HA/$6JOA!!A -GAA!$##hHHSM((+!!\22aAJ9 'q 1AEHHQKq)AHHVaZ( (  ~~a ^^A&q)*Q.A'$..A) .* 	
G !Ds   J)r@   rA   r<   r?   r>   r=   r;   rB   N)__name__
__module____qualname____firstlineno____doc__rO   rW   r[   r^   rb   rg   r   r   __static_attributes__ 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.   