o
    ݹi                     @  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)deprecated_since_versionactive_deprecations_target)rP   MathematicaParserrL   
_parse_old)sadditional_translationsparser rX   V/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/sympy/parsing/mathematica.pymathematica   s   rZ   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))
    )rS   parse)rU   rW   rX   rX   rY   parse_mathematica    s   2
r\   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arX   rX   rY   
<listcomp>[   s    z#_parse_Function.<locals>.<listcomp>zdummy0:clsc                   s   i | ]\}} |d  |qS )r]   rX   )r`   ivr^   rX   rY   
<dictcomp>_   s    z#_parse_Function.<locals>.<dictcomp>rX      z&Function node expects 1 or 2 arguments)lenr=   atomsmax
isinstancerI   rK   rJ   rH   xreplace	enumerateSyntaxError)r_   argslotsnumbersnumber_of_arguments	variablesbodyrX   rg   rY   _parse_FunctionV   s   

"

rw   c                 C  s   |    | S N)_initialize_classrc   rX   rX   rY   _decoi   s   rz   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  rS   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]) Arc)SinCosTanCotSecCsc)r{   hz[x]ra   z(x)r{   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 rx   )_compile_dictionaryCORRESPONDENCESr   update)rd   drX   rX   rY   ry      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   rm   dict
ValueErrorr   r   )selfrV   r   rX   rX   rY   __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   \rX   )r`   xrX   rX   rY   rb   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startrj   joinARGS_PATTERN_TEMPLATErecompileVERBOSE)rd   dicr   fmr   merrfm_namer_   endkey_argkeyre_argsxyzpatStrr   rX   rX   rY   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 oner{   r   TN)r   r   r   r   r   _convert_one_function)
r   rU   r   scannedcurr   r   r_   r   bgnrX   rX   rY   _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   r{   )rj   r   r   zipro   r   r   r   r   r   r   r   )r   rU   r   r_   r   r   r   x_argsr   re   r   r   templater   r   r   r   xbgnrX   rX   rY   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   ro   appendpop)rd   r   rU   ancsquarecurlyr_   r   re   cfunc_endrX   rX   rY   r     s.   

zMathematicaParser._get_argsc                 C  s   | j | }|||}|S rx   )REPLACEMENTSreplace)rd   rU   befaftrX   rX   rY   r     s   
zMathematicaParser._replacec                 C  s   | j | \}}|||S rx   )RULESsub)rd   rU   r   r   r   rX   rX   rY   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   )rd   rU   bracketr   rX   rX   rY   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   rU   rX   rX   rY   rT     s   

zMathematicaParser._parse_oldc                 C  s"   |  |}| |}| |}|S rx   )_from_mathematica_to_tokens_from_tokens_to_fullformlist_from_fullformlist_to_sympy)r   rU   s2s3s4rX   rX   rY   r[     s   


zMathematicaParser.parseInfixPrefixPostfixFlatRightLeft;c                 C  s.   t | tr| r| d dkr| dg S d| dgS )Nr   CompoundExpressionNull)rm   listr   rX   rX   rY   <lambda>%     . zMathematicaParser.<lambda>r   Set
SetDelayedAddToSubtractFromTimesByDivideBy)=z:=z+=z-=z*=z/=z//c                 C  s   | |gS rx   rX   r   yrX   rX   rY   r   (      &r=   z/.
ReplaceAllRuleRuleDelayed)z->z:>z/;	Conditionr   AlternativesRepeatedRepeatedNull)z..z...z||rF   z&&rG   !NotSameQUnsameQ)z===z=!=EqualUnequal	LessEqualLessGreaterEqualGreater)z==z!=z<=<z>=>z;;SpanPlus+-Times)r   /.Dotc                 C  s
   t | S rx   )rS   _get_negr   rX   rX   rY   r   8     
 c                 C  s   | S rx   rX   r   rX   rX   rY   r   9  s    )r  r  r   PowerApplyMapMapAllc                 C  s   d| |ddggS )Nr  List1rX   r   rX   rX   rY   r   ;      )z@@z/@z//@z@@@
Derivative	Factorial
Factorial2	Decrement)'r  z!!z--c                 C  s
   | g|S rx   rX   r   rX   rX   rY   r   =  r  c                 C  s   d| g|S )NPartrX   r   rX   rX   rY   r   =      )r   [[c                 C  s
   dg| S )Nr  rX   r   rX   rX   rY   r   >  r  c                 C  s   | d S )Nr   rX   r   rX   rX   rY   r   >  r   )r   r   ?PatternTestc                 C     d| dggS NPatternBlankrX   r   rX   rX   rY   r   A  r%  c                 C  s   dd| dgggS )NOptionalr+  r,  rX   r   rX   rX   rY   r   B  r  c                 C  r)  )Nr+  BlankSequencerX   r   rX   rX   rY   r   C  r%  c                 C  r)  )Nr+  BlankNullSequencerX   r   rX   rX   rY   r   D  r%  )_z_._____r0  c                 C  s   d| d|ggS r*  rX   r   rX   rX   rY   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  rX   rX   rX   rX   rY   r   K  r   c                   C  r6  )Nr3  r  rX   rX   rX   rX   rY   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)rm   strr   matchrS   _numberrd   r   rX   rX   rY   r  U  s   ,zMathematicaParser._get_negc                 C  s
   d|dgS )Nr  r8  rX   r<  rX   rX   rY   _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 rx   )rj   r   rX   rX   rY   r   h  r  z2MathematicaParser._get_tokenizer.<locals>.<lambda>)r   r   
r   r   r   )_regex_tokenizer_literalr;  _enclosure_open_enclosure_closer5  r   sortextendmapr   escaper   r   )r   tokenstokens_escapetypstratsymdictk	tokenizerrX   rX   rY   _get_tokenizer_  s   


z MathematicaParser._get_tokenizercoder9  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 "  " expression_Strz\"z(*z*)zmismatch in comment (*  *) coderi   c                   s.   g | ]}t |tr| r |n|gqS rX   )rm   r9  isasciifindall)r`   re   rM  rX   rY   rb     r   zAMathematicaParser._from_mathematica_to_tokens.<locals>.<listcomp>c                 S  s   g | ]	}|D ]}|qqS rX   rX   )r`   re   jrX   rX   rY   rb     s    r>  )rN  findrj   r   r   r   rp   r   r   ro   rm   r   r   )r   rO  code_splitsstring_start	match_end
string_endre   
code_splitpos_comment_startpos_comment_endtoken_listsrG  rX   rT  rY   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)rm   r   r   r:  r@  r;  r   r_  rX   rX   rY   _is_op  s   
zMathematicaParser._is_opc                 C     |dv rdS |  | S )N)r   r   Trd  rc  rX   rX   rY   _is_valid_star1     z!MathematicaParser._is_valid_star1c                 C  re  )N)r   r   Trf  rc  rX   rX   rY   _is_valid_star2  rh  z!MathematicaParser._is_valid_star2rG  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 enclosurer7  r   r]   r   r&  ri   r   z( ) not valid syntaxTz1( must be followed by one expression, %i detectedz"Stack should have only one element)rj   rA  r   rp   _parse_after_bracesrB  indexinsertr   reverseRuntimeError)
r   rG  stackopen_seqpointerr_  indunmatched_enclosure
last_stacknew_stack_elementrX   rX   rY   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   )rj   r   rk  rp   rD  r   range)	r   rw  rG  rx  rr  sizer_  	prev_exprre   rX   rX   rY   _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   )rj   rg  ri  rm  )r   rG  rz  rr  rX   rX   rY   _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  ri   r   z1'Prefix' op_type should not have a grouping stratz0unable to create a single AST for the expressionr   )r|  reversedr5  r}  rj   rm   r9  PREFIXrd  INFIXr   r=  r  r   FLAT_check_op_compatibleRIGHTLEFT	TypeError_missing_arguments_defaultPOSTFIXr   typingcastclearr   rD  rk  rp   )r   rG  rx  changedrw  op_typegrouping_stratop_dictrz  rr  r_  op_namenodefirst_indexarg1arg2node_pother_opop_callnew_nodecompound_expressionrX   rX   rY   rk  !  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  FrX   )r   r  r  muldivaddsubrX   rX   rY   r    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   r{   r   r   r   )	r   finditerr   r   stripr   r   r   r   )	r   r  outrp  	generatorlast_posr:  position	last_exprrX   rX   rY   _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 rX   rX   r`   rq   )	converterrX   rY   rb         z\MathematicaParser._from_fullformlist_to_fullformsympy.<locals>.converter.<locals>.<listcomp>r]   zEmpty list of expressions)rm   r   rj   r   r9  rM   )exprheadr_   r=   r  r  rX   rY   r    s   

zHMathematicaParser._from_fullformlist_to_fullformsympy.<locals>.converter)sympyr=   r  )r   r  rX   r  rY   #_from_fullformlist_to_fullformsympy  s   z5MathematicaParser._from_fullformlist_to_fullformsympyr	   Logc                  G  s   t t|  S rx   )r
   r~  ra   rX   rX   rY   r     r%  Log2c                 C  
   t | dS Nri   r
   r   rX   rX   rY   r     r  Log10c                 C  r  )N
   r  r   rX   rX   rY   r     r  ExpSqrtr}   r~   r   r   r   r   ArcSinArcCosArcTanc                  G  s    t | dkrtt|  S t|  S r  )rj   r)   r~  r(   r  rX   rX   rY   r     s     ArcCotArcSecArcCscSinhCoshTanhCothSechCschArcSinhArcCoshArcTanhArcCothArcSechArcCschExpandImReFlattenPolylogCancel
TrigExpandSignSimplifyDeferIdentityr   c                  G  s   t jS rx   )r'   Zeror  rX   rX   rY   r     s    r*   r+   r,   
PochhammerExpIntegralEiSinIntegralCosIntegralAiryAiAiryAiPrimeAiryBiAiryBiPrimeLogIntegralPrimePiPrime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                   r  rX   rX   r  )recurserX   rY   rb   2  r  zRMathematicaParser._from_fullformlist_to_sympy.<locals>.recurse.<locals>.<listcomp>r]   )rm   r   _node_conversionsgetr=   _atom_conversionsrL   )r  r  r  r   rX   rY   r  ,  s   
z>MathematicaParser._from_fullformlist_to_sympy.<locals>.recurserX   )r   full_form_listrX   r  rY   r   *  s   
z-MathematicaParser._from_fullformlist_to_sympyc                 C  s,   |}| j  D ]\}}|t||}q|S rx   )r  r   r   r=   )r   mformr  mma_form
sympy_noderX   rX   rY   _from_fullformsympy_to_sympy8  s   z.MathematicaParser._from_fullformsympy_to_sympyrx   )rO  r9  )r_  r`  ra  rb  )rG  r   )rw  r   rG  r   rx  rb  )F)rG  r   rx  rb  )r  r9  r  r9  )r  r9  )r  r   )__name__
__module____qualname____doc__r   r   arctrir   r   lowerr   r   r   r   r   r   r   r   ARG_MTRX_PATTERNr   r   __annotations__r   r   classmethodry   r   r   r   r   r   r   r   r   rT   r[   r  r  r  r  r  r  r5  r  r@  r;  rA  rB  r  r=  r?  rN  r   rd  rg  ri  r   r|  r}  rk  r  r  r  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   r  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   rw   r  r>   r?   r  r   r  rX   rX   rX   rY   rS   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rS   rx   )]
__future__r   r   r  	itertoolsr   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,   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   sympy.core.sympifyrL   rM   sympy.functions.special.besselrN   'sympy.functions.special.error_functionsrO   sympy.utilities.exceptionsrP   rZ   r\   rw   rz   rS   rX   rX   rX   rY   <module>   s$    " 
6