K i/ddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZdd lmZd Zdd ZdZddZdZdZdZy)Tuple)Basic)Expr) AppliedUndef) Relational)Dummy)sympify)BooleanFunction)ImageSet) FiniteSet)Indexedct|tttfs|g}t d|Dr tStj |Dcgc]}|j tc}}|j |Dcgc]}|j tc}}|xs/tj |Dcgc]}|jc}Scc}wcc}wcc}w)aReturns the free symbols of a symbolic expression. If the expression contains any of these elements, assume that they are the "free symbols" of the expression: * indexed objects * applied undefined function (useful for sympy.physics.mechanics module) c32K|]}t|ywNcallable).0es Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/plotting/utils.py z$_get_free_symbols..s &18A; &s) isinstancelisttuplesetallunionatomsrr free_symbols)exprsrfrees r_get_free_symbolsr"s edE3/ 0 & &&u 35;;59a)9 :D 4::u=! -= >D  @;35;; ?A ?@@:= ?sCC?C c |jt}|D]H}t|}tt dDcgc] }t |c}}|j ||}J|Scc}w)aExtract numerical solutions from a set solution (computed by solveset, linsolve, nonlinsolve). Often, it is not trivial do get something useful out of them. Parameters ========== n : int, optional In order to replace ImageSet with FiniteSet, an iterator is created for each ImageSet contained in `set_sol`, starting from 0 up to `n`. Default value: 10. r)findr iterr rangenextsubs)set_solnimagesimitss rextract_solutionr/!se\\( #F& "X %1+6QR6 7,,r1%& N7sA% cxt|tr|St|}t|D]\}}t|ttfrt t |ddi||<4t|ttfrKt|rW|jjdk(rt|tst|||<|S)aThis function recursively loop over the arguments passed to the plot functions: the sympify function will be applied to all arguments except those of type string/dict. Generally, users can provide the following arguments to a plot function: expr, range1 [tuple, opt], ..., label [str, opt], rendering_kw [dict, opt] `expr, range1, ...` can be sympified, whereas `label, rendering_kw` can't. In particular, whenever a special character like $, {, }, ... is used in the `label`, sympify will raise an error. r FVector)rrr enumeraterr _plot_sympifystrdictr __class____name__rr )argsias rr3r36s$ :D$ !1 a$ ']1-=u=DGQd , %%1:a;OajDG ! KNcd}t|}||j|j}t||kDr9t ddj |zdj t||zt||kDrt dt|d|t j|Dcgc]}|d c}}t|t|k7r t dt||krw|j|} | t k7r| D]} |j|| t|t|z D]!} |j|t#t||k(rvt j|Dcgc]}|d c}}t|j|dkDr/t d d j |zd j |z|Scc}wcc}w) aThis function does two things: 1. Check if the number of free symbols is in agreement with the type of plot chosen. For example, plot() requires 1 free symbol; plot3d() requires 2 free symbols. 2. Sometime users create plots without providing ranges for the variables. Here we create the necessary ranges. Parameters ========== exprs : iterable The expressions from which to extract the free symbols ranges : iterable The limiting ranges provided by the user npar : int The number of free symbols required by the plot functions. For example, npar=1 for plot, npar=2 for plot3d, ... params : dict A dictionary mapping symbols to parameters for interactive plot. ct|ddS)Ni r)symbols rz _create_ranges..lsuVS"'=r;zToo many free symbols. zExpected {} free symbols. zReceived {}: {}zToo many ranges. Received z , expected rz$Multiple ranges with the same symbolz>Incompatible free symbols of the expressions with the ranges. z$Free symbols in the expressions: {} zFree symbols in the ranges: {}) r" differencekeyslen ValueErrorformatrrappendr&r ) r rangesnparlabelparamsget_default_rangerrrfssymbolsr.r9s r_create_rangesrOUs.>$U+L #..v{{}=  <4 &+2248 9&&s<'8,G H   6{T;>v; MO O %++V,qt, -C 3x3v;?@@ 6{T))#. ce  4 /23 4tc&k)* 6A MM+EG4 5 6 <D ekk0A1Q401 |&&s+ ,q 0 9@@NO399#>?  M5-$1s 6 G6 G;c.t|txrt|dk(xrtt|jdt xrT|jdj xr9t|jdt xr|jdj S)zUA range is defined as (symbol, start, end). start and end should be numbers. )rrrCr8r4 is_number)rLs r _is_rangerUs 1e E Vq[ EAFF1Is+ + E121D1D EAFF1Is+ + E231D1D r;c|Dcgc]}t|s|}}|Dcgc]}t|ts|}}|sdn|d}|Dcgc]}t|ts|}}|sdn|d}|Dcgc],}t|xst|ttfxs|du .}}t ||Dcgc] \}}|s | } }}| |||fScc}wcc}wcc}wcc}wcc}}w)aGiven a list/tuple of arguments previously processed by _plot_sympify() and/or _check_arguments(), separates and returns its components: expressions, ranges, label and rendering keywords. Examples ======== >>> from sympy import cos, sin, symbols >>> from sympy.plotting.utils import _plot_sympify, _unpack_args >>> x, y = symbols('x, y') >>> args = (sin(x), (x, -10, 10), "f1") >>> args = _plot_sympify(args) >>> _unpack_args(*args) ([sin(x)], [(x, -10, 10)], 'f1', None) >>> args = (sin(x**2 + y**2), (x, -2, 2), (y, -3, 3), "f2") >>> args = _plot_sympify(args) >>> _unpack_args(*args) ([sin(x**2 + y**2)], [(x, -2, 2), (y, -3, 3)], 'f2', None) >>> args = (sin(x + y), cos(x - y), x + y, (x, -2, 2), (y, -3, 3), "f3") >>> args = _plot_sympify(args) >>> _unpack_args(*args) ([sin(x + y), cos(x - y), x + y], [(x, -2, 2), (y, -3, 3)], 'f3', None) Nr)rUrr4r5zip) r8trGlabelsrI rendering_kwr:resultsbr s r _unpack_argsr]s4 .A1a .F . 4AAs!3a 4F 4DF1IE#;!z!T':A;L;+4aLY]]STIaLMJq3+$>M19N]G]tW- 341aQ 3E 3 &% --/ 4;^ 3s2C C CC CC21C4 C ?C c &|sgSg}|jdd}td|d|Drt|\}}}} tj|D cgc]} | j c} } t |||||}|dkDrt||k(r t|f}|D]>} t| tttf} | r| fn| } |jg| ||| @|St|\}}}} |r|gng}t|t|z| t| ndz}|dkDr|d| n|}t|dtttfs|g}|D]'}|Dcgc]}t|t s|}}|s|}|Dcgc]}t#|s|}}|s|j%}|Dcgc]}t|t&s|}}t|dk(r| n|d}t)|Dcgc]}|| }}t} td|Dr'| j|Dcgc]}|j c}} t||k7rt |||d|}|sdn|d}|jg||||*|Scc} wcc}wcc}wcc}wcc}wcc}w)a,Checks the arguments and converts into tuples of the form (exprs, ranges, label, rendering_kw). Parameters ========== args The arguments provided to the plot functions nexpr The number of sub-expression forming an expression to be plotted. For example: nexpr=1 for plot. nexpr=2 for plot_parametric: a curve is represented by a tuple of two elements. nexpr=1 for plot3d. nexpr=3 for plot3d_parametric_line: a curve is represented by a tuple of three elements. npar The number of free symbols required by the plot functions. For example, npar=1 for plot, npar=2 for plot3d, ... **kwargs : keyword arguments passed to the plotting function. It will be used to verify if ``params`` has ben provided. Examples ======== .. plot:: :context: reset :format: doctest :include-source: True >>> from sympy import cos, sin, symbols >>> from sympy.plotting.plot import _check_arguments >>> x = symbols('x') >>> _check_arguments([cos(x), sin(x)], 2, 1) [(cos(x), sin(x), (x, -10, 10), None, None)] >>> _check_arguments([cos(x), sin(x), "test"], 2, 1) [(cos(x), sin(x), (x, -10, 10), 'test', None)] >>> _check_arguments([cos(x), sin(x), "test", {"a": 0, "b": 1}], 2, 1) [(cos(x), sin(x), (x, -10, 10), 'test', {'a': 0, 'b': 1})] >>> _check_arguments([x, x**2], 1, 1) [(x, (x, -10, 10), None, None), (x**2, (x, -10, 10), None, None)] rJNc3RK|]}t|tttf!ywr)rrrr rr:s rrz#_check_arguments..s T!:a$ O< = Ts%'rRrc34K|]}t| ywrrr`s rrz#_check_arguments..<s0qx{?0s)getrr]rrrrOrCrrrrr rFrrr4rUcopyr5r&)r8nexprrHkwargsoutputrJr rGrIrZrrexpris_expr_rYr*new_argsargr:lrLrend_kwr9s r_check_argumentsros`  F ZZ$ 'F TtFU| TT .:4-@*vul"su{{U$CQ^^$CD vtUFC 195zU"u >D!j/'JKG"A MMd MM+7*='66<#&[3v; &".":S C !A4!94 (1+eU';< zH 6C6q:a#56A60q9Q<0A0KKM"%=QAt) 14Qs6I5I:&I:4I?I?!J7J J J )r>)rbN)sympy.core.containersrsympy.core.basicrsympy.core.exprrsympy.core.functionrsympy.core.relationalrsympy.core.symbolr sympy.core.sympifyr sympy.logic.boolalgr sympy.sets.fancysetsr sympy.sets.setsr sympy.tensor.indexedrr"r/r3rOrUr]ror;rr|sN'" ,,#&/)%(A&*>CL #.Lur;