o
    GZh                     @  s  d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dlZd dlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZN d dlOmPZPmQZQ d dlRmSZS d dlTmUZU d d	lVmWZW dd
dZXdd ZYdd ZZdd Z[e[G dd dZ\dS )    )annotationsN)product)AnyCallable)FMulAddPowRationallogexpsqrtcossintanasinacosacotasecacscsinhcoshtanhasinhacoshatanhacothasechacschexpandimflattenpolylogcancelexpand_trigsignsimplifyUnevaluatedExprSatanatan2ModMaxMinrfEiSiCiairyaiairyaiprimeairybiprimepiprimeisprimecotseccsccschsechcothFunctionIpiTupleGreaterThanStrictGreaterThanStrictLessThanLessThanEqualityOrAndLambdaIntegerDummysymbols)sympify_sympify)airybiprime)li)sympy_deprecation_warningc                 C  s$   t dddd t|}t|| S )NzThe ``mathematica`` function for the Mathematica parser is now
deprecated. Use ``parse_mathematica`` instead.
The parameter ``additional_translation`` can be replaced by SymPy's
.replace( ) or .subs( ) methods on the output expression instead.z1.11zmathematica-parser-new)Zdeprecated_since_versionZactive_deprecations_target)rP   MathematicaParserrL   
_parse_old)sadditional_translationsparser rV   H/var/www/auris/lib/python3.10/site-packages/sympy/parsing/mathematica.pymathematica   s   rX   c                 C  s   t  }|| S )a  
    Translate a string containing a Wolfram Mathematica expression to a SymPy
    expression.

    If the translator is unable to find a suitable SymPy expression, the
    ``FullForm`` of the Mathematica expression will be output, using SymPy
    ``Function`` objects as nodes of the syntax tree.

    Examples
    ========

    >>> from sympy.parsing.mathematica import parse_mathematica
    >>> parse_mathematica("Sin[x]^2 Tan[y]")
    sin(x)**2*tan(y)
    >>> e = parse_mathematica("F[7,5,3]")
    >>> e
    F(7, 5, 3)
    >>> from sympy import Function, Max, Min
    >>> e.replace(Function("F"), lambda *x: Max(*x)*Min(*x))
    21

    Both standard input form and Mathematica full form are supported:

    >>> parse_mathematica("x*(a + b)")
    x*(a + b)
    >>> parse_mathematica("Times[x, Plus[a, b]]")
    x*(a + b)

    To get a matrix from Wolfram's code:

    >>> m = parse_mathematica("{{a, b}, {c, d}}")
    >>> m
    ((a, b), (c, d))
    >>> from sympy import Matrix
    >>> Matrix(m)
    Matrix([
    [a, b],
    [c, d]])

    If the translation into equivalent SymPy expressions fails, an SymPy
    expression equivalent to Wolfram Mathematica's "FullForm" will be created:

    >>> parse_mathematica("x_.")
    Optional(Pattern(x, Blank()))
    >>> parse_mathematica("Plus @@ {x, y, z}")
    Apply(Plus, (x, y, z))
    >>> parse_mathematica("f[x_, 3] := x^3 /; x > 0")
    SetDelayed(f(Pattern(x, Blank()), 3), Condition(x**3, x > 0))
    )rQ   parse)rS   rU   rV   rV   rW   parse_mathematica    s   2
rZ   c                    s   t | dkrB| d }td | }dd |D }t|}t|tr=td| td}t||	 fdd	t
|D S td
|S t | dkrU| d }| d }t||S td)N   r   Slotc                 S  s   g | ]}|j d  qS )r   )args).0arV   rV   rW   
<listcomp>[   s    z#_parse_Function.<locals>.<listcomp>zdummy0:clsc                   s   i | ]\}} |d  |qS )r[   rV   )r^   ivr\   rV   rW   
<dictcomp>_   s    z#_parse_Function.<locals>.<dictcomp>rV      z&Function node expects 1 or 2 arguments)lenr=   Zatomsmax
isinstancerI   rK   rJ   rH   Zxreplace	enumerateSyntaxError)r]   argslotsnumbersZnumber_of_arguments	variablesbodyrV   re   rW   _parse_FunctionV   s   

"

rr   c                 C  s   |    | S N)_initialize_classra   rV   rV   rW   _decoi   s   ru   c                !   @  s  e Zd ZU dZi dddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*Zed+d,d-D ])\ZZZee e d. Z	ered/e
  e d0 Zne
 e d0 Zee	ei qKd1d2d3d4d5Zed6ejd7fed8ejd7fed9ejd:fed;ejd<fd=Zed>ejZed?ejZd@Zi ZdAedB< i ZdAedC< i ZdAedD< edEdF Zd-dHdIZedJdK ZdLdM ZdNdO ZedPdQ ZedRdS Z edTdU Z!edVdW Z"dXdY Z#dZd[ Z$d\Z%d]Z&d^Z'd_Z(d`Z)daZ*e'dGdbdcdd ife%e(dbdeife%e)dfdgdhdidjdkdlfe%e*dmdndd ife'dGdodpife%e*dqdrife%e)dsdtdufe%e*dvdwife%e(dxdyife'dGdzd{d|fe%e(d}d~ife%e(ddife&dGddife%e(dddfe%e(dddddddfe%dGddife%e(dddfe%e(dddfe%e(ddife&dGddd ddd dfe%e)ddife%e)dddddd dfe'dGdddddfe%dGddd ddd dfe&dGddd ddd dfe%dGddife'dGddd ddd ddd ddd dfe%dGdddd ife&dGdddfgZ+ded< ddd ddd dZ,dZ-dZ.g dZ/g dZ0edd Z1edd Z2dGZ3ddÄ Z4d.ddǄZ5d/dd̈́Z6d/ddτZ7d/ddфZ8d0ddՄZ9d1ddلZ:d0ddۄZ;d2d3ddބZ<d4ddZ=d5ddZ>d6ddZ?i de@deAdeBdeCdddd dddd dddd deDdeEdeFdeGdeHdeIdeJdeKdeLdeMi dddd deNdeOdePdeQd eRdeSdeTdeUdeVdeWdeXdeYdeZd	e[d
e\de]i de^de_jde`deadebdecdeddeedefdegdddd dehdeidejdekdeldemi dendeod epd!eqd"erd#esd$etd%eud&evd'ewdexdeydezde{de|d~e}de~dpeiZeed(Zd)d* Zd+d, ZdGS (7  rQ   ap  
    An instance of this class converts a string of a Wolfram Mathematica
    expression to a SymPy expression.

    The main parser acts internally in three stages:

    1. tokenizer: tokenizes the Mathematica expression and adds the missing *
        operators. Handled by ``_from_mathematica_to_tokens(...)``
    2. full form list: sort the list of strings output by the tokenizer into a
        syntax tree of nested lists and strings, equivalent to Mathematica's
        ``FullForm`` expression output. This is handled by the function
        ``_from_tokens_to_fullformlist(...)``.
    3. SymPy expression: the syntax tree expressed as full form list is visited
        and the nodes with equivalent classes in SymPy are replaced. Unknown
        syntax tree nodes are cast to SymPy ``Function`` objects. This is
        handled by ``_from_fullformlist_to_sympy(...)``.

    zSqrt[x]zsqrt(x)zRational[x,y]zRational(x,y)zExp[x]zexp(x)zLog[x]zlog(x)zLog[x,y]zlog(y,x)zLog2[x]zlog(x,2)zLog10[x]z	log(x,10)zMod[x,y]zMod(x,y)zMax[*x]zMax(*x)zMin[*x]zMin(*x)zPochhammer[x,y]zrf(x,y)zArcTan[x,y]z
atan2(y,x)zExpIntegralEi[x]zEi(x)zSinIntegral[x]zSi(x)zCosIntegral[x]zCi(x)z	AiryAi[x]z	airyai(x)zAiryAiPrime[x]zairyaiprime(x)z	airybi(x)zairybiprime(x)z li(x)z
primepi(x)zprime(x)z
isprime(x))z	AiryBi[x]zAiryBiPrime[x]zLogIntegral[x]z
PrimePi[x]zPrime[x]z	PrimeQ[x]) ZArc)SinCosTanCotSecCsc)rv   hz[x]r_   z(x)rv   z**[]) ^{}z
                (?:(?<=[a-zA-Z\d])|(?<=\d\.))     # a letter or a number
                \s+                               # any number of whitespaces
                (?:(?=[a-zA-Z\d])|(?=\.\d))       # a letter or a number
                *z
                (?:(?<=[])\d])|(?<=\d\.))       # ], ) or a number
                                                # ''
                (?=[(a-zA-Z])                   # ( or a single letter
                z
                (?<=[a-zA-Z])       # a letter
                \(                  # ( as a character
                (?=.)               # any characters
                z*(z
                (?:
                \A|(?<=[^a-zA-Z])
                )
                Pi                  # 'Pi' is 3.14159... in Mathematica
                (?=[^a-zA-Z])
                r?   )
whitespaceadd*_1add*_2Piz
                (?:
                \A|(?<=[^a-zA-Z])   # at the top or a non-letter
                )
                [A-Z][a-zA-Z\d]*    # Function
                (?=\[)              # [ as a character
                z(
                \{.*\}
                z
                (?:
                \A|(?<=[^a-zA-Z])
                )
                {arguments}         # model argument like x, y,...
                (?=[^a-zA-Z])
                z%dict[tuple[str, int], dict[str, Any]]TRANSLATIONScache_originalcache_compiledc                 C  s   |  | j}| j| d S rs   )_compile_dictionaryCORRESPONDENCESr   update)rb   drV   rV   rW   rt      s   z#MathematicaParser._initialize_classNc                 C  sl   i | _ | j | j |d u ri }| jj|kr,t|tstd| |}|| j_|| j_	| j | jj	 d S )NzThe argument must be dict type)
translationsr   r   	__class__r   rj   dict
ValueErrorr   r   )selfrT   r   rV   rV   rW   __init__   s   

zMathematicaParser.__init__c                 C  sV  i }|  D ]\}}| | | | | |d}| |d}| |d}| |d}| j|}|d u r@dj|d}t|| }| 	|\}}	|
 dksW|	t|kradj|d}t||d d dkrld}
nt|}
||
f}dd	 |D }d
d| d }| jj|d}t|tj}i ||< ||| d< ||| d< ||| d< q|S )Nr   r   '{f}' function form is invalid.fr   r   c                 S  s$   g | ]}|d  dkr|nd| qS )r   r   \rV   )r^   xrV   rV   rW   r`   C  s   $ z9MathematicaParser._compile_dictionary.<locals>.<listcomp>z(?:(|z)))	argumentsfsr]   pat)items_check_input_apply_rules_replace
FM_PATTERNsearchformatr   group	_get_argsstartrh   joinARGS_PATTERN_TEMPLATErecompileVERBOSE)rb   Zdicr   fmr   merrZfm_namer]   endZkey_argkeyZre_argsZxyzZpatStrr   rV   rV   rW   r     s<   

z%MathematicaParser._compile_dictionaryc           
      C  s   | j }d}d}	 ||}|du r||7 }	 |S | }| |\}}| }	| ||||	|}|	}||d| 7 }||d }q)z'Parse Mathematica function to SymPy onerv   r   TN)r   r   r   r   r   _convert_one_function)
r   rS   r   scannedcurr   r   r]   r   bgnrV   rV   rW   _convert_functionU  s"   
z#MathematicaParser._convert_functionc                 C  s^  |t |f| jv r|t |f}| j| d }tt||}nA|df| jv rU|df}| j| d }i }t|D ]\}	}
|
d dkrMd||	d  ||
<  n||	 ||
< q6n
dj|d}t|| j| d }| j| d }d	}d}	 ||}|d u r||7 }n|	 }
|
 }||d | ||
  7 }| }||d  }qr|d | | ||d   }|S )
Nr]   r   r   ,z'{f}' is out of the whitelist.r   r   r   rv   )rh   r   r   ziprk   r   r   r   r   r   r   r   )r   rS   r   r]   r   r   r   Zx_argsr   rc   r   r   templater   r   r   r   ZxbgnrV   rV   rW   r   |  sB   
z'MathematicaParser._convert_one_functionc                 C  s   |j }| d }g g }}g }|}t||d |D ]K\}}	|	dkr4|s4|s4||||  |d }|	dkr>||	 n|	dkrF|  |	dkrP||	 q|	dkrf|r[|  q||||   nq|d }
||
fS )z'Get arguments of a Mathematica functionr[   Nr   r   r   r~   r   )stringr   rk   appendpop)rb   r   rS   ZancZsquareZcurlyr]   r   rc   cZfunc_endrV   rV   rW   r     s.   

zMathematicaParser._get_argsc                 C  s   | j | }|||}|S rs   )REPLACEMENTSreplace)rb   rS   befaftrV   rV   rW   r     s   
zMathematicaParser._replacec                 C  s   | j | \}}|||S rs   )RULESsub)rb   rS   r   r   r   rV   rV   rW   r     s   zMathematicaParser._apply_rulesc                 C  sR   dD ]}| |d | |d krdj|d}t|qd|v r'd}t|d S )N))r~   r   )r   r   )()r   r[   r   r   r   z Currently list is not supported.)countr   r   )rb   rS   Zbracketr   rV   rV   rW   r     s   zMathematicaParser._check_inputc                 C  s`   |  | | |d}| |d}| |d}| |d}| |}| |d}| |d}|S )Nr   r   r   r   r   r   )r   r   r   r   )r   rS   rV   rV   rW   rR     s   

zMathematicaParser._parse_oldc                 C  s"   |  |}| |}| |}|S rs   )_from_mathematica_to_tokens_from_tokens_to_fullformlist_from_fullformlist_to_sympy)r   rS   s2Zs3Zs4rV   rV   rW   rY     s   


zMathematicaParser.parseZInfixZPrefixZPostfixZFlatZRightZLeft;c                 C  s.   t | tr| r| d dkr| dg S d| dgS )Nr   CompoundExpressionNull)rj   listr   rV   rV   rW   <lambda>%     . zMathematicaParser.<lambda>r   SetZ
SetDelayedZAddToZSubtractFromZTimesByZDivideBy)=z:=z+=z-=z*=z/=z//c                 C  s   | |gS rs   rV   r   yrV   rV   rW   r   (      &r=   z/.Z
ReplaceAllRuleZRuleDelayed)z->z:>z/;	Conditionr   ZAlternativesZRepeatedZRepeatedNull)z..z...z||rF   z&&rG   !NotZSameQZUnsameQ)z===z=!=ZEqualZUnequalZ	LessEqualZLessZGreaterEqualZGreater)z==z!=z<=<z>=>z;;SpanZPlus+-Times)r   /.ZDotc                 C  s
   t | S rs   )rQ   _get_negr   rV   rV   rW   r   8     
 c                 C  s   | S rs   rV   r   rV   rV   rW   r   9  s    )r   r   r   PowerApplyZMapZMapAllc                 C  s   d| |ddggS )Nr   List1rV   r   rV   rV   rW   r   ;      )z@@z/@z//@z@@@Z
DerivativeZ	FactorialZ
Factorial2Z	Decrement)'r   z!!z--c                 C  s
   | g|S rs   rV   r   rV   rV   rW   r   =  r   c                 C  s   d| g|S )NZPartrV   r   rV   rV   rW   r   =      )r~   [[c                 C  s
   dg| S )Nr   rV   r   rV   rV   rW   r   >  r   c                 C  s   | d S )Nr   rV   r   rV   rV   rW   r   >  r   )r   r   ?ZPatternTestc                 C     d| dggS NPatternBlankrV   r   rV   rV   rW   r   A  r   c                 C  s   dd| dgggS )NOptionalr   r   rV   r   rV   rV   rW   r   B  r   c                 C  r   )Nr   ZBlankSequencerV   r   rV   rV   rW   r   C  r   c                 C  r   )Nr   ZBlankNullSequencerV   r   rV   rV   rW   r   D  r   )_z_.__Z___r   c                 C  s   d| d|ggS r   rV   r   rV   rV   rW   r   F  s    r\   SlotSequence)#z##z7list[tuple[str, str | None, dict[str, str | Callable]]]_mathematica_op_precedencec                   C     ddgS )Nr\   r   rV   rV   rV   rV   rW   r   K  r   c                   C  r   )Nr   r   rV   rV   rV   rV   rW   r   L  r   z[A-Za-z][A-Za-z0-9]*z (?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+))r   r~   r   r   )r   r   ]]r   c                 C  s,   t |trttj|rd| S dd|gS )Nr   r   -1)rj   strr   matchrQ   _numberrb   r   rV   rV   rW   r   U  s   ,zMathematicaParser._get_negc                 C  s
   d|dgS )Nr   r   rV   r  rV   rV   rW   _get_invY  s   
zMathematicaParser._get_invc                 C  s   | j d ur| j S | j| jg}| jd d  | jd d   }| jD ]\}}}|D ]}|| q&q|jdd d |t	t
j| |d |d t
dd| d }|| _ | j S )	Nc                 S  s
   t |  S rs   )rh   r   rV   rV   rW   r   h  r   z2MathematicaParser._get_tokenizer.<locals>.<lambda>)r   r   
r   r   r   )_regex_tokenizer_literalr  _enclosure_open_enclosure_closer   r   sortextendmapr   escaper   r   )r   tokensZtokens_escapetypZstratZsymdictk	tokenizerrV   rV   rW   _get_tokenizer_  s   


z MathematicaParser._get_tokenizercoder   c                   s  |    g }	 |d}|dkrt|dkr|| nCtd||d d  }|d u r0td||  d }|dkrE||d |  |d||d | d	dg ||d d  }qt	|D ]9\}}t
|trmqc	 |d
}|dkrxn |d}	|	dks|	|k rtd|d | ||	d d   }qn|||< qc fdd|D }
dd |
D }|r|d dkr|d |r|d dks|r|d dkr|d |r|d dks|S )NT"r   r   z(?<!\\)"r[   z"mismatch in string "  " expressionZ_Strz\"z(*z*)zmismatch in comment (*  *) coderg   c                   s.   g | ]}t |tr| r |n|gqS rV   )rj   r   isasciifindall)r^   rc   r  rV   rW   r`     r   zAMathematicaParser._from_mathematica_to_tokens.<locals>.<listcomp>c                 S  s   g | ]	}|D ]}|qqS rV   rV   )r^   rc   jrV   rV   rW   r`     s    r  )r  findrh   r   r   r   rl   r   r   rk   rj   r   r   )r   r  Zcode_splitsstring_startZ	match_end
string_endrc   Z
code_splitZpos_comment_startZpos_comment_endZtoken_listsr  rV   r  rW   r   p  sN   

"





z-MathematicaParser._from_mathematica_to_tokenstoken
str | listreturnboolc                 C  s:   t |trdS t| j|rdS td| j |rdS dS )NFz-?T)rj   r   r   r   r  r  r   r  rV   rV   rW   _is_op  s   
zMathematicaParser._is_opc                 C     |dv rdS |  | S )N)r   r   Tr   r  rV   rV   rW   _is_valid_star1     z!MathematicaParser._is_valid_star1c                 C  r!  )N)r   r   Tr"  r  rV   rV   rW   _is_valid_star2  r$  z!MathematicaParser._is_valid_star2r  r   c           
      C  s  g g}g }d}|t |k r.|| }|| jv r)|d | || |g  n|dkrVt |d dkrG|d d |d krGtd|d  | |d |d< |g  n|| jv r| j|}| j| |d krtd}|dkr|d dkr|d dkr||d	 d
 n1|d dkr||d	  d
krd||d	 < n||d	  dkrd||d	 < ||d d
 n|n|t |d dkr|d d dkrtd| |d d}||d< g }	|d d |d kr|	|  |d d |d ks|		  |d dkrt |	d	krtdt |	 |d |	 |d n|d | |d	7 }|t |k st |d	kr9t
d| |d S )Nr   r   r   z %s cannot be followed by comma ,zunmatched enclosurer   r~   r[   r   r   rg   r   z( ) not valid syntaxTz1( must be followed by one expression, %i detectedz"Stack should have only one element)rh   r  r   rl   _parse_after_bracesr  indexinsertr   reverseRuntimeError)
r   r  stackZopen_seqpointerr  indZunmatched_enclosureZ
last_stackZnew_stack_elementrV   rV   rW   r     sb   

$	 /z.MathematicaParser._from_tokens_to_fullformlistlinesinside_enclosurec           	      C  s  d}t |}||k r|| }|dkr|r|| |d8 }q|dkr,|d |d8 }q|dkrOz| |d | |}W n tyN   || |d8 }Y qw |d }t |dkri|d dkri||dd   n|| t|D ]}|d qr||8 }d}q|d7 }||k s
d S d S )Nr   r  r[   r   )rh   r   r'  rl   r
  r   range)	r   r/  r  r0  r-  sizer  Z	prev_exprrc   rV   rV   rW   _util_remove_newlines  s@   



z'MathematicaParser._util_remove_newlinesc                 C  s   t |}d}||k rM|dkrC| ||d  rC| || rC|| dkr5d||< ||d  d ||d < n||d |d7 }|d7 }|d7 }||k s
d S d S )Nr   r[   r   r   )rh   r#  r%  r)  )r   r  r2  r-  rV   rV   rW   _util_add_missing_asterisks  s    z-MathematicaParser._util_add_missing_asterisksFc                 C  sd  d}g }|  ||| t| jD ]T\}}}d|v r| | t|}d}	|	|k re||	 }
t|
tr]|
|v r]||
 }t|trH|g}d}ng }d}|
dv rg|| jkrg|	dkrg| ||	d  sg|	d7 }	q%|| j	kr|	dks|	|d ks| ||	d  s| ||	d  r|	d7 }	q%d}|||	< || j	kr|
|	d }|
|	}|
dkr| |}n	|
dkr| |}|	d8 }	|d	8 }|| |}|| jkr"|	d	 |k r| ||	d  |
r|| |
|	d }|
|	d }|dkr| |}n
|dkr| |}|d	8 }|	d	 |k r| ||	d  |
s|| n|| jkrk|	d	 |k re||	d  |
kre|||g |d
 }|
|	d  |
|	d }|d	8 }|	d	 |k re||	d  |
ks8|| n|| jkr|	d |k r||	d  |
krt|tr||| |g||< n	||| |||< |
|	d  |
|	d }|d	8 }|	d |k r||	d  |
ks|| nw|| nq|| jkr |d urtd|	|d ks| ||	d  r| j|
  ||	< nH||
|	d  |d8 }n9|| jkr9|d urtd|	dks| ||	d  r'| j|
  ||	< n||
|	d  |	d8 }	|d8 }t|tr]tt|}|| }|  t|trY|| n|||	< |	d7 }	|	|k s*qt|dks{t|dkrt|dkr|r| ||S tdt|dkr|d r|d d dkr|d dd  }dg||}|S |d S )NFr   r   r[   r   Tr   r   rg   r   z1'Prefix' op_type should not have a grouping stratz0unable to create a single AST for the expressionr   )r3  reversedr   r4  rh   rj   r   PREFIXr   INFIXr   r  r   r   FLAT_check_op_compatibleRIGHTLEFT	TypeError_missing_arguments_defaultPOSTFIXr   typingcastclearr   r
  r'  rl   )r   r  r0  changedr/  Zop_typeZgrouping_stratZop_dictr2  r-  r  Zop_namenodeZfirst_indexZarg1Zarg2Znode_pZother_opZop_callnew_nodeZcompound_expressionrV   rV   rW   r'  !  s   


,
8


$


"	    
"

*[z%MathematicaParser._parse_after_bracesop1op2c                 C  sH   ||krdS ddh}ddh}||v r||v rdS ||v r"||v r"dS dS )NTr   r   r   r   FrV   )r   rE  rF  ZmuldivZaddsubrV   rV   rW   r9    s   z&MathematicaParser._check_op_compatiblewmexprc           	      C  s   g }|g}t d|}d}|D ]f}|du r |d S | }||| dddddd }| dkrD|dkrC|d | n-| dkrZ|dkrU|d | |  n| dkrq|d |g ||d d  | }q|d S )	zH
        Parses FullForm[Downvalues[]] generated by Mathematica
        z[\[\],]r   Nr   rv   r   r~   r   )	r   finditerr   r   stripr   r   r   r   )	r   rG  outr,  	generatorZlast_posr   position	last_exprrV   rV   rW   _from_fullform_to_fullformlist  s.   (

z0MathematicaParser._from_fullform_to_fullformlistpylistc                   s(   ddl m m  fdd|S )Nr   )r=   Symbolc                   sf   t | tr&t| dkr"| d }fdd| dd  D } || S tdt | tr/| S t| S )Nr   c                      g | ]} |qS rV   rV   r^   rm   )	converterrV   rW   r`         z\MathematicaParser._from_fullformlist_to_fullformsympy.<locals>.converter.<locals>.<listcomp>r[   zEmpty list of expressions)rj   r   rh   r   r   rM   )exprheadr]   r=   rP  rS  rV   rW   rS    s   

zHMathematicaParser._from_fullformlist_to_fullformsympy.<locals>.converter)sympyr=   rP  )r   rO  rV   rW  rW   #_from_fullformlist_to_fullformsympy  s   z5MathematicaParser._from_fullformlist_to_fullformsympyr	   ZLogc                  G  s   t t|  S rs   )r
   r5  r_   rV   rV   rW   r     r   ZLog2c                 C  
   t | dS Nrg   r
   r   rV   rV   rW   r     r   ZLog10c                 C  r[  )N
   r]  r   rV   rV   rW   r     r   ZExpZSqrtrw   rx   ry   rz   r{   r|   ZArcSinZArcCosZArcTanc                  G  s    t | dkrtt|  S t|  S r\  )rh   r)   r5  r(   rZ  rV   rV   rW   r     s     ZArcCotZArcSecZArcCscZSinhZCoshZTanhZCothZSechZCschZArcSinhZArcCoshZArcTanhZArcCothZArcSechZArcCschZExpandZImZReZFlattenZPolylogZCancelZ
TrigExpandZSignZSimplifyZDeferZIdentityr   c                  G  s   t jS rs   )r'   ZZerorZ  rV   rV   rW   r     s    r*   r+   r,   Z
PochhammerZExpIntegralEiZSinIntegralZCosIntegralZAiryAiZAiryAiPrimeZAiryBiZAiryBiPrimeZLogIntegralZPrimePiPrimeZPrimeQr   )r>   r   c                   s    fdd  |S )Nc                   sp   t | tr/t | d tr | d }nj| d t| d }| fdd| dd  D  S j| t| S )Nr   c                   rQ  rV   rV   rR  )recurserV   rW   r`   2  rT  zRMathematicaParser._from_fullformlist_to_sympy.<locals>.recurse.<locals>.<listcomp>r[   )rj   r   _node_conversionsgetr=   _atom_conversionsrL   )rU  rV  r`  r   rV   rW   r`  ,  s   
z>MathematicaParser._from_fullformlist_to_sympy.<locals>.recurserV   )r   Zfull_form_listrV   rd  rW   r   *  s   
z-MathematicaParser._from_fullformlist_to_sympyc                 C  s,   |}| j  D ]\}}|t||}q|S rs   )ra  r   r   r=   )r   ZmformrU  Zmma_formZ
sympy_noderV   rV   rW   _from_fullformsympy_to_sympy8  s   z.MathematicaParser._from_fullformsympy_to_sympyrs   )r  r   )r  r  r  r  )r  r   )r/  r   r  r   r0  r  )F)r  r   r0  r  )rE  r   rF  r   )rG  r   )rO  r   )__name__
__module____qualname____doc__r   r   arcZtrir}   r   lowerr   r   r   r   r   r   r   r   ZARG_MTRX_PATTERNr   r   __annotations__r   r   classmethodrt   r   r   r   r   r   r   r   r   rR   rY   r7  r6  r>  r8  r:  r;  r   r=  r  r  r  r  r   r  r  r  r   r   r#  r%  r   r3  r4  r'  r9  rN  rY  r   r   r   r	   r   r   r   r   r   r7   r8   r9   r   r   r   r   r   r   r   r   r<   r;   r:   r   r   r   r   r   r   r   r   rX  r    r!   r"   r#   r$   r%   r&   r'   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   rN   rO   r4   r5   r6   r@   rB   rA   rC   rD   rE   rF   rG   rr   ra  r>   r?   rc  r   re  rV   rV   rV   rW   rQ   n   sx  
 	




)		

?'B
%




'

/	7#y	 !"#$%'()*+,./0126789:;<=>?@ABCDEGHIJKLMNPTrQ   rs   )]
__future__r   r   r?  	itertoolsr   r   r   rX  r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   Zsympy.core.sympifyrL   rM   Zsympy.functions.special.besselrN   Z'sympy.functions.special.error_functionsrO   Zsympy.utilities.exceptionsrP   rX   rZ   rr   ru   rQ   rV   rV   rV   rW   <module>   s$    " 
6