On Fri, Sep 16, 2022 at 3:37 PM Yang Liu <micat...@gmail.com> wrote: > > Hi Aron, > > Many thanks for your answers. I previously use say f.args[0] to access input > like \nabla*f to check. But has() is more error free. > > Is there any more robust way to get the specific args symbol? For instance, > if the input is like (expr=x*y*z). But I want to get the x from this > expression. I would say expr.arg[0]. But if I change the expression order. > This doesn't work.
expr.free_symbols will give you a set of all the symbols in an expression. Does that give you what you need? If not, I'm not clear what you mean by "the x from this expression". Note that if you just want a symbol named "x" you can create another one with Symbol('x'). SymPy treats any two symbols with the same name and assumptions as equal, so recreating a symbol with the same name is equivalent to reusing the same symbol object. Aaron Meurer > > Thanks! > > On Friday, September 16, 2022 at 9:27:10 PM UTC+2 asme...@gmail.com wrote: >> >> You can name a symbol any string you want, so Symbol(r'\nabla') will >> create a symbol named \nabla. >> >> To test if a symbol is in an expression, use .has(): >> >> >>> (x + 1).has(x) >> True >> >>> (y + 1).has(x) >> False >> >> Aaron Meurer >> >> On Fri, Sep 16, 2022 at 6:26 AM Yang Liu <mica...@gmail.com> wrote: >> > >> > Hi, >> > >> > I want to represent the \nabla symbolically without calculation. Is there >> > a way to declare such a symbol? Also for \triangle? >> > >> > Moreover, I want to write a function say F(\nabla u) take \nabla*u as an >> > input. Is there a way to detect if I pass the "\nabla" into the function? >> > Pseudo code would be something like: >> > >> > F(expression): >> > if \nabla in expression: >> > do something >> > else: >> > >> > Many Thanks! >> > >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "sympy" group. >> > To unsubscribe from this group and stop receiving emails from it, send an >> > email to sympy+un...@googlegroups.com. >> > To view this discussion on the web visit >> > https://groups.google.com/d/msgid/sympy/cab2a16d-8fa0-4875-971e-7e39a10077d2n%40googlegroups.com. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sympy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/4fe989e9-6104-4026-a3e1-4d112a07f3bfn%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6LCQgmqLCgFSVu-cbksA39KxA_g_yQNbT7nK7KMHcr3DA%40mail.gmail.com.