U
    hۚ                     @  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f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   =/tmp/pip-unpacked-wheel-6t8vlncq/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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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slotsZnumbersZnumber_of_arguments	variablesbodyrV   re   rW   _parse_FunctionV   s    

"

rq   c                 C  s   |    | S N)_initialize_classra   rV   rV   rW   _decoi   s    rt   c                G   @  sb  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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 qNd 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d0ed1< i Zd0ed2< i Zd0ed3< ed4d5 Zdd7d8Zed9d: Zd;d< Zd=d> Zed?d@ ZedAdB Z edCdD Z!edEdF Z"dGdH Z#dIdJ Z$dKZ%dLZ&dMZ'dNZ(dOZ)dPZ*e'd6dQdRdS ife%e(dQdTife%e)dUdVdWdXdYdZd[fe%e*d\d]dS ife'd6d^d_ife%e*d`daife%e)dbdcddfe%e*dedfife%e(dgdhife'd6didjdkfe%e(dldmife%e(dndoife&d6dpdqife%e(drdsdtfe%e(dudvdwdxdydzd{fe%d6d|d}ife%e(d~d~dfe%e(dddfe%e(ddife&d6ddS ddS dfe%e)ddife%e)dddddS dfe'd6dddddfe%d6ddS ddS dfe&d6ddS ddS dfe%d6ddife'd6ddS ddS ddS ddS dfe%d6dddS ife&d6dddfgZ+ded< ddS ddS dZ,dZ-dZ.dd"ddgZ/dd#ddgZ0edd Z1edd Z2d6Z3dd 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@eAeBeCddS ddS ddS eCeDeEeFeGeHeIeJeKeLeMddS eNeOePeQeReSeTeUeVeWeXeYeZe[e\e]e^e_je`eaebecedeeefegddS eheiejekelemeneoepeqereseteuevewexeyeze{e|e}e~edߜFZeedZdd Zdd Zd6S )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Rational(x,y)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Rational[x,y]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)ru   hz[x]r_   z(x)ru   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 rr   )_compile_dictionaryCORRESPONDENCESr   update)rb   drV   rV   rW   rs      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   rj   dict
ValueErrorr   r   )selfrT   r   rV   rV   rW   __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   \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kr*||7 }q|| }| |\}}| }	| ||||	|}|	}||d| 7 }||d }q|S )z'Parse Mathematica function to SymPy oneru   r   N)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kr<|t |f}| j| d }tt||}n|df| jkr|df}| j| d }i }t|D ]:\}	}
|
d dkrd||	d  ||
<  q||	 ||
< qlndj|d}t|| j| d }| j| d }d	}d}||}|d kr||7 }q@|	 }
|
 }||d | ||
  7 }| }||d  }q|d | | ||d   }|S )
Nr]   r   r   ,z'{f}' is out of the whitelist.r   r   r   ru   )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   |  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 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 rr   )REPLACEMENTSreplace)rb   rS   befaftrV   rV   rW   r     s    
zMathematicaParser._replacec                 C  s   | j | \}}|||S rr   )RULESsub)rb   rS   r   r   r   rV   rV   rW   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   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 rr   )_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 rr   rV   r   yrV   rV   rW   r   (  r   &r=   z/.Z
ReplaceAllZRuleZRuleDelayed)z->z:>z/;	Conditionr   ZAlternativesZRepeatedZRepeatedNull)z..z...z||rF   z&&rG   !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 rr   )rQ   _get_negr   rV   rV   rW   r   8  r   c                 C  s   | S rr   rV   r   rV   rV   rW   r   9  r   )r   r   r   PowerApplyZMapZMapAllc                 C  s   d| |ddggS )Nr   List1rV   r   rV   rV   rW   r   ;  r   )z@@z/@z//@z@@@Z
DerivativeZ	FactorialZ
Factorial2Z	Decrement)'r   z!!z--c                 C  s
   | f|S rr   rV   r   rV   rV   rW   r   =  r   c                 C  s   d| f|S )NZPartrV   r   rV   rV   rW   r   =  r   )r}   [[c                 C  s   d| S )Nr   )r   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  s   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  s   d| dggS )Nr   ZBlankSequencerV   r   rV   rV   rW   r   C  r   c                 C  s   d| dggS )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  r   r\   SlotSequence)#z##z7list[tuple[str, str | None, dict[str, str | Callable]]]_mathematica_op_precedencec                   C  s   ddgS )Nr\   r   rV   rV   rV   rV   rW   r   K  r   c                   C  s   ddgS )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   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 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 rr   )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_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(?<!\\)"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`     s     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_splitsZstring_startZ	match_endZ
string_endrc   Z
code_splitZpos_comment_startZpos_comment_endZtoken_listsr	  rV   r  rW   r   p  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)rj   r   r   r   r  r   r   r  rV   rV   rW   _is_op  s    
zMathematicaParser._is_opc                 C  s   |dkrdS |  | S )N)r   r   Tr  r  rV   rV   rW   _is_valid_star1  s    z!MathematicaParser._is_valid_star1c                 C  s   |dkrdS |  | S )N)r   r   Tr  r  rV   rV   rW   _is_valid_star2  s    z!MathematicaParser._is_valid_star2r   )r	  c           
      C  s~  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rpt
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     s\    

$$
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   r[   r   )rh   r   r  rl   r  r   range)	r   r&  r	  r'  r$  sizer  Z	prev_exprrc   rV   rV   rW   _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   r[   r   r   )rh   r  r  r   )r   r	  r)  r$  rV   rV   rW   _util_add_missing_asterisks  s    z-MathematicaParser._util_add_missing_asterisksF)r	  r'  c                 C  s  d}g }|  ||| t| jD ]Z\}}}d|kr>| | t|}d}	|	|k r ||	 }
t|
trr|
|krr||
 }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	rftd|	|d ks| ||	d  r| j|
  ||	< n||
|	d  |d8 }nr|| jkr*|d k	rtd|	dks| ||	d  r| j|
  ||	< n$||
|	d  |	d8 }	|d8 }t|trrtt|}|| }|  t|trj|| 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   r[   r   Tr   r   rg   r   z1'Prefix' op_type should not have a grouping stratz0unable to create a single AST for the expressionr   )r   )r*  reversedr   r+  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	  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_expressionrV   rV   rW   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   FrV   )r   r;  r<  ZmuldivZaddsubrV   rV   rW   r0    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   ru   r~   r}   r   )	r   finditerr   r   stripr   r   r   r   )	r   r=  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                   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 rV   rV   r^   rm   )	converterrV   rW   r`     s     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=   rF  rH  rV   rW   rH    s    


zHMathematicaParser._from_fullformlist_to_fullformsympy.<locals>.converter)sympyr=   rF  )r   rE  rV   rK  rW   #_from_fullformlist_to_fullformsympy  s    z5MathematicaParser._from_fullformlist_to_fullformsympyc                  G  s   t t|  S rr   )r
   r,  r_   rV   rV   rW   r     r   c                 C  s
   t | dS Nrg   r
   r   rV   rV   rW   r     r   c                 C  s
   t | dS )N
   rP  r   rV   rV   rW   r     r   c                  G  s    t | dkrtt|  S t|  S rO  )rh   r)   r,  r(   rN  rV   rV   rW   r     r   c                  G  s   t jS rr   )r'   ZZerorN  rV   rV   rW   r   	  r   )Fr   r   r   r	   LogZLog2ZLog10r	   ZExpZSqrtrv   rw   rx   ry   rz   r{   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   rF   rG   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 rV   rV   rG  )recurserV   rW   r`   3  s     zRMathematicaParser._from_fullformlist_to_sympy.<locals>.recurse.<locals>.<listcomp>r[   )rj   r   _node_conversionsgetr=   _atom_conversionsrL   )rI  rJ  rT  r   rV   rW   rT  -  s    
z>MathematicaParser._from_fullformlist_to_sympy.<locals>.recurserV   )r   Zfull_form_listrV   rX  rW   r   +  s    
z-MathematicaParser._from_fullformlist_to_sympyc                 C  s,   |}| j  D ]\}}|t||}q|S rr   )rU  r   r   r=   )r   ZmformrI  Zmma_formZ
sympy_noderV   rV   rW   _from_fullformsympy_to_sympy9  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   classmethodrs   r   r   r   r   r   r   r   r   rR   rY   r.  r-  r5  r/  r1  r2  r   r4  r  r   r  r  r   r   r  r  r   r  r  r  r   r*  r+  r  r0  rD  rM  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   rL  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   rq   rU  r>   r?   rW  r   rY  rV   rV   rV   rW   rQ   n   s  




)		


?'B
%




'

/	7#yUrQ   )]
__future__r   r   r6  	itertoolsr   r   r   rL  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   rq   rt   rQ   rV   rV   rV   rW   <module>   s"    !6