U
    0er                     @  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@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZM d dlNmOZOmPZP d dlQmRZR d dlSmTZT d d	lUmVZV dfd
dZWdd ZXdd ZYdd ZZeZG dd dZ[dS )    )annotationsN)product)AnyCallable)EMulAddPow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)rO   MathematicaParserrK   
_parse_old)sadditional_translationsparser rU   =/tmp/pip-unpacked-wheel-_6tpq7m6/sympy/parsing/mathematica.pymathematica   s    rW   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))
    )rP   parse)rR   rT   rU   rU   rV   parse_mathematica    s    2rY   c                    s   t | dkr| d }td | }dd |D }t|}t|trztd| td}t||	 fdd	t
|D S td
|S t | dkr| d }| d }t||S tdd S )N   r   Slotc                 S  s   g | ]}|j d  qS )r   )args).0arU   rU   rV   
<listcomp>[   s     z#_parse_Function.<locals>.<listcomp>zdummy0:clsc                   s   i | ]\}} |d  |qS )rZ   rU   )r]   ivr[   rU   rV   
<dictcomp>_   s     
 z#_parse_Function.<locals>.<dictcomp>rU      z&Function node expects 1 or 2 arguments)lenr<   Zatomsmax
isinstancerH   rJ   rI   rG   Zxreplace	enumerateSyntaxError)r\   argslotsZnumbersZnumber_of_arguments	variablesbodyrU   rd   rV   _parse_FunctionV   s    

"

rp   c                 C  s   |    | S N)_initialize_classr`   rU   rU   rV   _decoi   s    rs   c                E   @  s\  e Zd ZU dZ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 ]R\ZZZee e d Z	erde
  e d Zne
 e d Zee	ei qLdd d!d"d#Zed$ejd%fed&ejd%fed'e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d/ed0< i Zd/ed1< i Zd/ed2< ed3d4 Zdd6d7Zed8d9 Zd:d; Zd<d= Zed>d? Zed@dA Z edBdC Z!edDdE Z"dFdG Z#dHdI Z$dJZ%dKZ&dLZ'dMZ(dNZ)dOZ*e'd5dPdQdR ife%e(dPdSife%e)dTdUdVdWdXdYdZfe%e*d[d\dR ife'd5d]d^ife%e*d_d`ife%e)dadbdcfe%e*dddeife%e(dfdgife'd5dhdidjfe%e(dkdlife%e(dmdnife&d5dodpife%e(dqdrdsfe%e(dtdudvdwdxdydzfe%d5d{d|ife%e(d}d}d~fe%e(dddfe%e(ddife&d5ddR ddR dfe%e)ddife%e)dddddR dfe'd5dddddfe%d5ddR ddR dfe&d5ddR ddR dfe%d5ddife'd5ddR ddR ddR ddR dfe%d5dddR ife&d5dddfgZ+ded< ddR ddR dZ,dZ-dZ.dd!ddgZ/dd"ddgZ0edd Z1edd Z2d5Z3dd Z4ddddZ5dddddZ6dddddZ7dddddZ8ddĜddƄZ9ddddǜddɄZ:ddĜdd˄Z;dddd͜ddτZ<dddМdd҄Z=ddӜddՄZ>dd֜dd؄Z?e@eAeBddR ddR ddR eCeDeEeFeGeHeIeJeKeLddR eMeNeOePeQeReSeTeUeVeWeXeYeZe[e\e]e^je_e`eaebecedeeefddR egeheiejekelemeneoepeqereseteuevewexeyeze{e|e}e~dޜDZeedߜZdd Zdd Zd5S )rP   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exp(x)zlog(x)zlog(y,x)zlog(x,2)z	log(x,10)zMod(x,y)zMax(*x)zMin(*x)zrf(x,y)z
atan2(y,x)zEi(x)zSi(x)zCi(x)z	airyai(x)zairyaiprime(x)z	airybi(x)zairybiprime(x)z li(x)z
primepi(x)zprime(x)z
isprime(x))zSqrt[x]zExp[x]zLog[x]zLog[x,y]zLog2[x]zLog10[x]zMod[x,y]zMax[*x]zMin[*x]zPochhammer[x,y]zArcTan[x,y]zExpIntegralEi[x]zSinIntegral[x]zCosIntegral[x]z	AiryAi[x]zAiryAiPrime[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)rt   hz[x]r^   z(x)rt   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 rq   )_compile_dictionaryCORRESPONDENCESr   update)ra   drU   rU   rV   rr      s    z#MathematicaParser._initialize_classNc                 C  sl   i | _ | j | j |d kr i }| jj|krXt|ts>td| |}|| j_|| j_	| j | jj	 d S )NzThe argument must be dict type)
translationsr   r   	__class__r   ri   dict
ValueErrorr   r   )selfrS   r   rU   rU   rV   __init__   s    

zMathematicaParser.__init__c                 C  sX  i }|  D ]D\}}| | | | | |d}| |d}| |d}| |d}| j|}|d krdj|d}t|| }| 	|\}}	|
 dks|	t|krdj|d}t||d d dkrd}
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   \rU   )r]   xrU   rU   rV   r_   B  s     z9MathematicaParser._compile_dictionary.<locals>.<listcomp>z(?:(|z)))	argumentsfsr\   pat)items_check_input_apply_rules_replace
FM_PATTERNsearchformatr   group	_get_argsstartrg   joinARGS_PATTERN_TEMPLATErecompileVERBOSE)ra   Zdicr   fmr   merrZfm_namer\   endZkey_argkeyZre_argsZxyzZpatStrr   rU   rU   rV   r     s<    

z%MathematicaParser._compile_dictionaryc           
      C  s   | j }d}d}||}|dkr*||7 }q|| }| |\}}| }	| ||||	|}|	}||d| 7 }||d }q|S )z'Parse Mathematica function to SymPy onert   r   N)r   r   r   r   r   _convert_one_function)
r   rR   r   scannedcurr   r   r\   r   bgnrU   rU   rV   _convert_functionT  s    
z#MathematicaParser._convert_functionc                 C  sf  |t |f| jkrB|t |f}| j| d }dd t||D }n|df| jkr|df}| j| d }i }t|D ]:\}	}
|
d dkrd||	d  ||
<  q||	 ||
< qrndj|d}t|| j| d	 }| j| d
 }d}d}||}|d kr||7 }qF| }
|	 }||d | ||
  7 }|
 }||d  }q|d | | ||d   }|S )Nr\   c                 S  s   i | ]\}}||qS rU   rU   )r]   krc   rU   rU   rV   re     s      z;MathematicaParser._convert_one_function.<locals>.<dictcomp>r   r   ,z'{f}' is out of the whitelist.r   r   r   rt   )rg   r   ziprj   r   r   r   r   r   r   r   )r   rR   r   r\   r   r   r   Zx_argsr   rb   r   r   templater   r   r   r   ZxbgnrU   rU   rV   r   {  s<    

z'MathematicaParser._convert_one_functionc                 C  s   |j }| d }g g  }}g }|}t||d |D ]\}}	|	dkrh|sh|sh||||  |d }|	dkr|||	 n|	dkr|  |	dkr||	 q6|	dkr6|r|  q6||||   qq6|d }
||
fS )z'Get arguments of a Mathematica functionrZ   Nr   r   r   r|   r}   )stringr   rj   appendpop)ra   r   rR   ZancZsquareZcurlyr\   r   rb   cZfunc_endrU   rU   rV   r     s,    

zMathematicaParser._get_argsc                 C  s   | j | }|||}|S rq   )REPLACEMENTSreplace)ra   rR   befaftrU   rU   rV   r     s    
zMathematicaParser._replacec                 C  s   | j | \}}|||S rq   )RULESsub)ra   rR   r   r   r   rU   rU   rV   r     s    zMathematicaParser._apply_rulesc                 C  sR   dD ]4}| |d | |d krdj|d}t|qd|krNd}t|d S )N))r|   r}   )r   r   )()r   rZ   r   r   r   z Currently list is not supported.)countr   r   )ra   rR   Zbracketr   rU   rU   rV   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   rR   rU   rU   rV   rQ     s    

zMathematicaParser._parse_oldc                 C  s"   |  |}| |}| |}|S rq   )_from_mathematica_to_tokens_from_tokens_to_fullformlist_from_fullformlist_to_sympy)r   rR   s2Zs3Zs4rU   rU   rV   rX     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)ri   listr   rU   rU   rV   <lambda>$      zMathematicaParser.<lambda>r   SetZ
SetDelayedZAddToZSubtractFromZTimesByZDivideBy)=z:=z+=z-=z*=z/=z//c                 C  s   | |gS rq   rU   r   yrU   rU   rV   r   '  r   &r<   z/.Z
ReplaceAllZRuleZRuleDelayed)z->z:>z/;	Conditionr   ZAlternativesZRepeatedZRepeatedNull)z..z...z||rE   z&&rF   !ZNotZSameQZUnsameQ)z===z=!=EqualZUnequal	LessEqualLessGreaterEqualGreater)z==z!=z<=<z>=>z;;ZSpanPlus+-Times)r   /.ZDotc                 C  s
   t | S rq   )rP   _get_negr   rU   rU   rV   r   7  r   c                 C  s   | S rq   rU   r   rU   rU   rV   r   8  r   )r   r   r   PowerApplyZMapZMapAllc                 C  s   d| |ddggS )Nr   List1rU   r   rU   rU   rV   r   :  r   )z@@z/@z//@z@@@Z
DerivativeZ	FactorialZ
Factorial2Z	Decrement)'r   z!!z--c                 C  s
   | f|S rq   rU   r   rU   rU   rV   r   <  r   c                 C  s   d| f|S )NZPartrU   r   rU   rU   rV   r   <  r   )r|   [[c                 C  s   d| S )Nr   )r   rU   r   rU   rU   rV   r   =  r   c                 C  s   | d S )Nr   rU   r   rU   rU   rV   r   =  r   )r   r   ?ZPatternTestc                 C  s   d| dggS NPatternBlankrU   r   rU   rU   rV   r   @  r   c                 C  s   dd| dgggS )NOptionalr   r   rU   r   rU   rU   rV   r   A  r   c                 C  s   d| dggS )Nr   ZBlankSequencerU   r   rU   rU   rV   r   B  r   c                 C  s   d| dggS )Nr   ZBlankNullSequencerU   r   rU   rU   rV   r   C  r   )_z_.__Z___r   c                 C  s   d| d|ggS r   rU   r   rU   rU   rV   r   E  r   r[   SlotSequence)#z##z7list[tuple[str, str | None, dict[str, str | Callable]]]_mathematica_op_precedencec                   C  s   ddgS )Nr[   r   rU   rU   rU   rU   rV   r   J  r   c                   C  s   ddgS )Nr   r   rU   rU   rU   rU   rV   r   K  r   z[A-Za-z][A-Za-z0-9]*z (?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)r   r   r   r   ]]r   c                 C  s,   t |tr"ttj|r"d| S dd|gS )Nr   r   -1)ri   strr   matchrP   _numberra   r   rU   rU   rV   r   T  s    zMathematicaParser._get_negc                 C  s
   d|dgS )Nr   r   rU   r   rU   rU   rV   _get_invX  s    zMathematicaParser._get_invc                 C  s   | j d k	r| j S | j| jg}| jd d  | jd d   }| jD ]\}}}|D ]}|| qLq>|jdd d |t	t
j| |d |d t
dd| d }|| _ | j S )	Nc                 S  s
   t |  S rq   )rg   r   rU   rU   rV   r   g  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symdictr   	tokenizerrU   rU   rV   _get_tokenizer^  s    


z MathematicaParser._get_tokenizerr   )codec                   s  |    g }|d}|dkr6t|dkr|| qtd||d d  }|d kr^td||  d }|dkr||d |  |d||d | ddg ||d d  }qt	|D ]v\}}t
|trq|d	}|dkrq2|d
}	|	dks|	|k rtd|d | ||	d d   }q|||< qć fdd|D }
dd |
D }|r~|d dkr~|d q\|r|d dkr|d q~|S )N"r   r   z(?<!\\)"rZ   z"mismatch in string "  " expressionZ_Strz\"z(*z*)zmismatch in comment (*  *) coderf   c                   s.   g | ]&}t |tr$| r$ |n|gqS rU   )ri   r   isasciifindall)r]   rb   r  rU   rV   r_     s     zAMathematicaParser._from_mathematica_to_tokens.<locals>.<listcomp>c                 S  s   g | ]}|D ]}|qqS rU   rU   )r]   rb   jrU   rU   rV   r_     s       r   )r  findrg   r   r   r   rk   r   r   rj   ri   r   r   )r   r  Zcode_splitsZstring_startZ	match_endZ
string_endrb   Z
code_splitZpos_comment_startZpos_comment_endZtoken_listsr	  rU   r  rV   r   o  sB    

"



z-MathematicaParser._from_mathematica_to_tokensz
str | listbool)tokenreturnc                 C  s:   t |trdS t| j|r dS td| j |r6dS dS )NFz-?T)ri   r   r   r   r  r   r   r  rU   rU   rV   _is_op  s    
zMathematicaParser._is_opc                 C  s   |dkrdS |  | S )N)r   r   Tr  r  rU   rU   rV   _is_valid_star1  s    z!MathematicaParser._is_valid_star1c                 C  s   |dkrdS |  | S )N)r   r   Tr  r  rU   rU   rV   _is_valid_star2  s    z!MathematicaParser._is_valid_star2r   )r	  c           
      C  sz  g g}g }d}|t |k rZ|| }|| jkrT|d | || |g  n|dkrt |d dkr|d d |d krtd|d  | |d |d< |g  n|| jkrB| j|}| j| |d krtd}|dkr|d dkr|d dkr||d	 d
 nb|d dkr||d	  d
krJd||d	 < n4||d	  dkrzd||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|	|  q|		  |d dkr(t |	d	kr(tdt |	 |d |	 |d n|d | |d	7 }qt |d	kslt
| |d S )Nr   r   r   z %s cannot be followed by comma ,zunmatched enclosurer   r|   rZ   r}   r   rf   r   z( ) not valid syntaxTz1( must be followed by one expression, %i detected)rg   r  r   rk   _parse_after_bracesr  indexinsertr   reverseAssertionError)
r   r	  stackZopen_seqpointerr  indZunmatched_enclosureZ
last_stackZnew_stack_elementrU   rU   rV   r     sZ    

$$
z.MathematicaParser._from_tokens_to_fullformlist)linesr	  inside_enclosurec           	      C  s  d}t |}||k r|| }|dkr|r@|| |d8 }q|dkr\|d |d8 }q|dkrz| |d | |}W q tk
r   || |d8 }Y qY qX n|d }t |dkr|d dkr||dd   n
|| t|D ]}|d q||8 }d}q|d7 }qd S )Nr   r   rZ   r   )rg   r   r  rk   r  r   range)	r   r%  r	  r&  r#  sizer  Z	prev_exprrb   rU   rU   rV   _util_remove_newlines  s<    





z'MathematicaParser._util_remove_newlinesc                 C  s   t |}d}||k r|dkr| ||d  r| || r|| dkrjd||< ||d  d ||d < n||d |d7 }|d7 }|d7 }qd S )Nr   rZ   r   r   )rg   r  r  r  )r   r	  r(  r#  rU   rU   rV   _util_add_missing_asterisks
  s    z-MathematicaParser._util_add_missing_asterisksF)r	  r&  c                 C  s
  d}g }|  ||| t| jD ]R\}}}d|kr>| | t|}d}	|	|k r ||	 }
t|
trj|
|krj||
 }t|tr|g}d}ng }d}|
dkr|| jkr|	dkr| ||	d  s|	d7 }	qJ|| j	kr"|	dks|	|d ks| ||	d  s| ||	d  r"|	d7 }	qJd}|||	< || j	krH|
|	d }|
|	}|
dkrh| |}n|
dkr|| |}|	d8 }	|d	8 }|| |}|| jkr4|	d	 |k r&| ||	d  |
r&|| |
|	d }|
|	d }|dkr| |}n|dkr| |}|d	8 }q|| q"|| jkr|	d	 |k r||	d  |
kr|||g |d
 }|
|	d  |
|	d }|d	8 }q@|| n|| jkr<|	d |k r0||	d  |
kr0t|tr||| |g||< n||| |||< |
|	d  |
|	d }|d	8 }q|| n
|| n|| jkr|d ksbt|	|d ks| ||	d  r| j|
  ||	< n||
|	d  |d8 }nn|| jkr"|d kst|	dks| ||	d  r| j|
  ||	< n$||
|	d  |	d8 }	|d8 }t|trjtt|}|| }|  t|trb|| n|||	< |	d7 }	qJq t|dkst|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||}|S |d S )NFr   r   rZ   r   Tr   r   rf   r   z0unable to create a single AST for the expressionr   )r   )r)  reversedr   r*  rg   ri   r   PREFIXr  INFIXr   r   r   r   FLAT_check_op_compatibleRIGHTLEFTr!  _missing_arguments_defaultPOSTFIXr   typingcastclearr   r  r  rk   )r   r	  r&  changedr%  Zop_typeZgrouping_stratZop_dictr(  r#  r  Zop_namenodeZfirst_indexZarg1Zarg2Znode_pZother_opZop_callZnew_nodeZcompound_expressionrU   rU   rV   r    s    

,@




$



  "
*
z%MathematicaParser._parse_after_braces)op1op2c                 C  sH   ||krdS ddh}ddh}||kr0||kr0dS ||krD||krDdS dS )NTr   r   r   r   FrU   )r   r9  r:  ZmuldivZaddsubrU   rU   rV   r/    s    z&MathematicaParser._check_op_compatible)wmexprc           	      C  s   g }|g}t d|}d}|D ]}|dkr. q| }||| dddddd }| dkr|dkr|d | nZ| dkr|dkr|d | |  n.| dkr|d |g ||d d  | }q|d S )	zH
        Parses FullForm[Downvalues[]] generated by Mathematica
        z[\[\],]r   Nr   rt   r}   r|   r   )	r   finditerr   r   stripr   r   r   r   )	r   r;  outr"  	generatorZlast_posr   position	last_exprrU   rU   rV   _from_fullform_to_fullformlist  s*    (

z0MathematicaParser._from_fullform_to_fullformlist)pylistc                   s(   ddl m m  fdd|S )Nr   )r<   Symbolc                   sl   t | trNt| dkrD| d }fdd| dd  D } || S tdnt | tr`| S t| S d S )Nr   c                   s   g | ]} |qS rU   rU   r]   rl   )	converterrU   rV   r_     s     z\MathematicaParser._from_fullformlist_to_fullformsympy.<locals>.converter.<locals>.<listcomp>rZ   zEmpty list of expressions)ri   r   rg   r   r   rL   )exprheadr\   r<   rD  rF  rU   rV   rF    s    


zHMathematicaParser._from_fullformlist_to_fullformsympy.<locals>.converter)sympyr<   rD  )r   rC  rU   rI  rV   #_from_fullformlist_to_fullformsympy  s    z5MathematicaParser._from_fullformlist_to_fullformsympyc                  G  s   t t|  S rq   )r	   r+  r^   rU   rU   rV   r     r   c                 C  s
   t | dS Nrf   r	   r   rU   rU   rV   r     r   c                 C  s
   t | dS )N
   rN  r   rU   rU   rV   r     r   c                  G  s    t | dkrtt|  S t|  S rM  )rg   r(   r+  r'   rL  rU   rU   rV   r     r   c                  G  s   t jS rq   )r&   ZZerorL  rU   rU   rV   r     r   )Dr   r   r   LogZLog2ZLog10ZExpZSqrtru   rv   rw   rx   ry   rz   ZArcSinZArcCosZArcTanZ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   r)   r*   r+   Z
PochhammerZExpIntegralEiZSinIntegralZCosIntegralZAiryAiZAiryAiPrimeZAiryBiZAiryBiPrimeZLogIntegralZPrimePiPrimeZPrimeQr   r   r   r   r   r   rE   rF   r<   )r=   r   c                   s    fdd  |S )Nc                   st   t | tr^t | d tr& | d }nj| d t| d }| fdd| dd  D  S j| t| S d S )Nr   c                   s   g | ]} |qS rU   rU   rE  )recurserU   rV   r_   -  s     zRMathematicaParser._from_fullformlist_to_sympy.<locals>.recurse.<locals>.<listcomp>rZ   )ri   r   _node_conversionsgetr<   _atom_conversionsrK   )rG  rH  rR  r   rU   rV   rR  '  s    
z>MathematicaParser._from_fullformlist_to_sympy.<locals>.recurserU   )r   Zfull_form_listrU   rV  rV   r   %  s    
z-MathematicaParser._from_fullformlist_to_sympyc                 C  s,   |}| j  D ]\}}|t||}q|S rq   )rS  r   r   r<   )r   ZmformrG  Zmma_formZ
sympy_noderU   rU   rV   _from_fullformsympy_to_sympy3  s    z.MathematicaParser._from_fullformsympy_to_sympy)N)F)__name__
__module____qualname____doc__r   r   ZarcZtrir{   r   lowerr   r   r   r   r   r   r   r   ZARG_MTRX_PATTERNr   r   __annotations__r   r   classmethodrr   r   r   r   r   r   r   r   r   rQ   rX   r-  r,  r3  r.  r0  r1  r   r2  r  r   r  r  r   r   r  r  r   r  r  r  r   r)  r*  r  r/  rB  rK  r   r   r   r
   r   r   r   r   r6   r7   r8   r   r   r   r   r   r   r   r   r;   r:   r9   r   r   r   r   r   r   r   r   rJ  r   r    r!   r"   r#   r$   r%   r&   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   rM   rN   r3   r4   r5   r?   rA   r@   rB   rC   rD   rE   rF   rp   rS  r=   r>   rU  r   rW  rU   rU   rU   rV   rP   n   s  




)		


?'B
%




'

/	6#wSrP   )\
__future__r   r   r4  	itertoolsr   r   r   rJ  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   Zsympy.core.sympifyrK   rL   Zsympy.functions.special.besselrM   Z'sympy.functions.special.error_functionsrN   Zsympy.utilities.exceptionsrO   rW   rY   rp   rs   rP   rU   rU   rU   rV   <module>   s"    6