
    Ed
                     l    d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZ  G d de          Zd ZdS )	a  
This module implements the functionality to take any Python expression as a
string and fix all numbers and other things before evaluating it,
thus

1/2

returns

Integer(1)/Integer(2)

We use the ast module for this. It is well documented at docs.python.org.

Some tips to understand how this works: use dump() to get a nice
representation of any node. Then write a string of what you want to get,
e.g. "Integer(1)", parse it, dump it and you'll see that you need to do
"Call(Name('Integer', Load()), [node], [], None, None)". You do not need
to bother with lineno and col_offset, just call fix_missing_locations()
before returning the node.
    )Basic)SympifyError)parseNodeTransformerCallNameLoadfix_missing_locationsStrTuplec                   &    e Zd Zd Zd Zd Zd ZdS )	Transformc                 J    t          j        |            || _        || _        d S )N)r   __init__
local_dictglobal_dict)selfr   r   s      8lib/python3.11/site-packages/sympy/parsing/ast_parser.pyr   zTransform.__init__   s(     &&&$&    c           	      V   t          |j        t                    r:t          t	          t          dt                                |gg                     S t          |j        t                    r:t          t	          t          dt                                |gg                     S |S )NIntegerfuncargskeywordsFloat)
isinstancevalueintr
   r   r   r	   float)r   nodes     r   visit_ConstantzTransform.visit_Constant#   s    dj#&& 	/(4	4663J3J"*. *. *. / / /
E** 	/(43H3H"*. *. *. / / /r   c           	      l   |j         | j        v r|S |j         | j        v r@| j        |j                  }t          |t          t
          f          st          |          r|S n|j         dv r|S t          t          t          dt                                t          |j                   gg                     S )N)TrueFalseSymbolr   )idr   r   r   r   typecallabler
   r   r   r	   r   )r   r!   name_objs      r   
visit_NamezTransform.visit_Name,   s    7do% 	KW(( 	'0H(UDM22 hx6H6H W)) 	K$TtHdff/E/E$'ll^b&2 &2 &2 3 3 	3r   c                      fd|j         j         D             }                     |j                  }t          t	          dt                                t          |t                                |gg           }t          |          S )Nc                 :    g | ]}                     |          S  )visit).0argr   s     r   
<listcomp>z*Transform.visit_Lambda.<locals>.<listcomp>:   s#    :::C

3:::r   Lambdar   )r   r/   bodyr   r   r	   r   r
   )r   r!   r   r4   ns   `    r   visit_LambdazTransform.visit_Lambda9   s}    ::::49>:::zz$)$$d8TVV,,dff%%t,r; ; ;$Q'''r   N)__name__
__module____qualname__r   r"   r+   r6   r.   r   r   r   r      sP        ' ' '
  3 3 3( ( ( ( (r   r   c                 T   i }t          d|           	 t          |                                 d          }n-# t          $ r  t	          dt          |           z            w xY wt          ||                              |          }t          |dd          }t          |||          S )z
    Converts the string "s" to a SymPy expression, in local_dict.

    It converts all numbers to Integers before feeding it to Python and
    automatically creates Symbols.
    zfrom sympy import *eval)modezCannot parse %s.z<string>)
execr   stripSyntaxErrorr   reprr   r/   compiler;   )sr   r   aes        r   
parse_exprrE   @   s     K	,,,9!''))&))) 9 9 9-Q78889*k**0033A:v&&A;
+++s	   #8 *A"N)__doc__sympy.core.basicr   sympy.core.sympifyr   astr   r   r   r   r	   r
   r   r   r   rE   r.   r   r   <module>rJ      s    * # " " " " " + + + + + +& & & & & & & & & & & & & & & & & & & &"( "( "( "( "( "( "( "(H, , , , ,r   