Re: [sympy] problem with Imaginary in sympy
I answered on StackOverflow. You can pass in custom functions as the second argument to sympify(). Aaron Meurer On Thu, Apr 4, 2019 at 10:47 AM Xuemei Gu wrote: > > Thank you very much, I tried this, but it doesn't work. It only give the > output but the the functions (LI, OAMHolo) are not executed. > > For simple example > stringA='3+4' > S(stringA) > > It will give you the results 7. It's correct but in my case these functions > don't work. > > I made a question in stackoverflow about the question, which make more clear: > https://stackoverflow.com/questions/55520809/how-to-implement-a-function-with-pythonsympy-realizing-the-same-as-toexpressi > > Did I misunderstand? Thank you very much! > > > On Thu, Apr 4, 2019 at 6:00 PM Oscar Benjamin > wrote: >> >> You can do it like this: >> >> In [7]: setupstr='LI(OAMHolo(OAMHolo(XX,e,6),f,2),a,f)' >> >> In [8]: from sympy import S >> >> In [9]: S(setupstr) >> Out[9]: LI(OAMHolo(OAMHolo(XX, e, 6), f, 2), a, f) >> >> >> On Thu, 4 Apr 2019 at 15:41, Xuemei Gu wrote: >> > >> > Thank you very much! >> > >> > I have another question: >> > >> > I get a string list such as >> > setupstr='LI(OAMHolo(OAMHolo(XX,e,6),f,2),a,f)' >> > >> > however in the string, LI OAMHolo are own defined functions, I don't know >> > how to replace them as functions. >> > I want to know how to do in sympy like I use ToExpression in Mathematica. >> > >> > Thank you very much! >> > best regards >> > Mei >> > >> > On Mon, Apr 1, 2019 at 9:31 PM Aaron Meurer wrote: >> >> >> >> I was hoping something like collect(x*y + x, [x, y], evaluate=False) >> >> would do what you want, but it doesn't quite. >> >> >> >> You could create a Poly with the coefficients as variables and use >> >> Poly.as_coefficients_dict. >> >> >> >> Aaron Meurer >> >> >> >> On Mon, Apr 1, 2019 at 1:02 PM Xuemei Gu wrote: >> >> > >> >> > >> >> > hey, >> >> > >> >> > I wander whether one has occurred such problem: >> >> > >> >> > I define a initial state: >> >> > >> >> > state=a[1]*b[0]*c[0]*d[0]*1j+a[1]*b[0]*c[0]*d[0] + a[2]*b[1]*c[1]*d[1] >> >> ># for some reason I have to do such decomposition >> >> > >> >> > datalist=state.as_coefficients_dict() >> >> > >> >> > >> >> > I can get: >> >> > { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, >> >> > I*FF2[0]*FF3[0]*FF4[0]: 1 } >> >> > >> >> > Now the problem is : >> >> > >> >> > Because I is a Imaginary number, it's not a symbol. How can I get >> >> > something such as { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, >> >> >FF2[0]*FF3[0]*FF4[0]: 1j} or { FF2[0]*FF3[0]*FF4[0]: 1+1j, >> >> > FF2[1]*FF3[1]*FF4[1]: 1 } >> >> > >> >> > Thank you very much! >> >> > >> >> > >> >> > >> >> > >> >> > -- >> >> > 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 post to this group, send email to sympy@googlegroups.com. >> >> > Visit this group at https://groups.google.com/group/sympy. >> >> > To view this discussion on the web visit >> >> > https://groups.google.com/d/msgid/sympy/d4505824-6110-4541-8199-09b6768315d9%40googlegroups.com. >> >> > For more options, visit https://groups.google.com/d/optout. >> >> >> >> -- >> >> You received this message because you are subscribed to a topic in the >> >> Google Groups "sympy" group. >> >> To unsubscribe from this topic, visit >> >> https://groups.google.com/d/topic/sympy/GKRuQ1iYgEI/unsubscribe. >> >> To unsubscribe from this group and all its topics, send an email to >> >> sympy+unsubscr...@googlegroups.com. >> >> To post to this group, send email to sympy@googlegroups.com. >> >> Visit this group at https://groups.google.com/group/sympy. >> >> To view this discussion on the web visit >> >> https://groups.google.com/d/msgid/sympy/CAKgW%3D6J5MX4JqkoRkVaL1a6C57wpGBKaXBH%3DhOZeK-cPe04SKg%40mail.gmail.com. >> >> For more options, visit https://groups.google.com/d/optout. >> > >> > >> > >> > -- >> > Xuemei Gu >> > PhD Student >> > >> > State Key Laboratory for Novel Software Technology, Nanjing University >> > 163 Xianlin Avenue, Qixia District, 210023, Nanjing City, China >> > >> > Institute for Quantum Optics and Quantum Information, Vienna >> > Boltzmanngasse 3, A-1090 Vienna, Austria >> > >> > http://iqoqi-vienna.at/ >> > Office: +43 (0) 1 4277 29568 >> > >> > -- >> > 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 post to this group, send email to sympy@googlegroups.com. >> > Visit this group at https://groups.google.com/group/sympy. >> > To view this discussion on the web visit >> > https://groups.google.com/d/msgid/sympy/CA%2BDAqr9yd3BkQnNYQ%3Dp6cXKccc8yZrFgirqxB3DmxEq%3Djy1grg%40mail.gmail.com. >> > For more
Re: [sympy] problem with Imaginary in sympy
Thank you very much, I tried this, but it doesn't work. It only give the output but the the functions (LI, OAMHolo) are not executed. For simple example stringA='3+4' S(stringA) It will give you the results 7. It's correct but in my case these functions don't work. I made a question in stackoverflow about the question, which make more clear: https://stackoverflow.com/questions/55520809/how-to-implement-a-function-with-pythonsympy-realizing-the-same-as-toexpressi Did I misunderstand? Thank you very much! On Thu, Apr 4, 2019 at 6:00 PM Oscar Benjamin wrote: > You can do it like this: > > In [7]: setupstr='LI(OAMHolo(OAMHolo(XX,e,6),f,2),a,f)' > > In [8]: from sympy import S > > In [9]: S(setupstr) > Out[9]: LI(OAMHolo(OAMHolo(XX, e, 6), f, 2), a, f) > > > On Thu, 4 Apr 2019 at 15:41, Xuemei Gu wrote: > > > > Thank you very much! > > > > I have another question: > > > > I get a string list such as > setupstr='LI(OAMHolo(OAMHolo(XX,e,6),f,2),a,f)' > > > > however in the string, LI OAMHolo are own defined functions, I don't > know how to replace them as functions. > > I want to know how to do in sympy like I use ToExpression in Mathematica. > > > > Thank you very much! > > best regards > > Mei > > > > On Mon, Apr 1, 2019 at 9:31 PM Aaron Meurer wrote: > >> > >> I was hoping something like collect(x*y + x, [x, y], evaluate=False) > >> would do what you want, but it doesn't quite. > >> > >> You could create a Poly with the coefficients as variables and use > >> Poly.as_coefficients_dict. > >> > >> Aaron Meurer > >> > >> On Mon, Apr 1, 2019 at 1:02 PM Xuemei Gu wrote: > >> > > >> > > >> > hey, > >> > > >> > I wander whether one has occurred such problem: > >> > > >> > I define a initial state: > >> > > >> > state=a[1]*b[0]*c[0]*d[0]*1j+a[1]*b[0]*c[0]*d[0] + > a[2]*b[1]*c[1]*d[1] # for some reason I have to do such decomposition > >> > > >> > datalist=state.as_coefficients_dict() > >> > > >> > > >> > I can get: > >> > { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, > I*FF2[0]*FF3[0]*FF4[0]: 1 } > >> > > >> > Now the problem is : > >> > > >> > Because I is a Imaginary number, it's not a symbol. How can I get > something such as { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, > FF2[0]*FF3[0]*FF4[0]: 1j} or { FF2[0]*FF3[0]*FF4[0]: 1+1j, > FF2[1]*FF3[1]*FF4[1]: 1 } > >> > > >> > Thank you very much! > >> > > >> > > >> > > >> > > >> > -- > >> > 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 post to this group, send email to sympy@googlegroups.com. > >> > Visit this group at https://groups.google.com/group/sympy. > >> > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/d4505824-6110-4541-8199-09b6768315d9%40googlegroups.com > . > >> > For more options, visit https://groups.google.com/d/optout. > >> > >> -- > >> You received this message because you are subscribed to a topic in the > Google Groups "sympy" group. > >> To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sympy/GKRuQ1iYgEI/unsubscribe. > >> To unsubscribe from this group and all its topics, send an email to > sympy+unsubscr...@googlegroups.com. > >> To post to this group, send email to sympy@googlegroups.com. > >> Visit this group at https://groups.google.com/group/sympy. > >> To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/CAKgW%3D6J5MX4JqkoRkVaL1a6C57wpGBKaXBH%3DhOZeK-cPe04SKg%40mail.gmail.com > . > >> For more options, visit https://groups.google.com/d/optout. > > > > > > > > -- > > Xuemei Gu > > PhD Student > > > > State Key Laboratory for Novel Software Technology, Nanjing University > > 163 Xianlin Avenue, Qixia District, 210023, Nanjing City, China > > > > Institute for Quantum Optics and Quantum Information, Vienna > > Boltzmanngasse 3, A-1090 Vienna, Austria > > > > http://iqoqi-vienna.at/ > > Office: +43 (0) 1 4277 29568 > > > > -- > > 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 post to this group, send email to sympy@googlegroups.com. > > Visit this group at https://groups.google.com/group/sympy. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/CA%2BDAqr9yd3BkQnNYQ%3Dp6cXKccc8yZrFgirqxB3DmxEq%3Djy1grg%40mail.gmail.com > . > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sympy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sympy/GKRuQ1iYgEI/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > sympy+unsubscr...@googlegroups.com. > To post to this
Re: [sympy] problem with Imaginary in sympy
You can do it like this: In [7]: setupstr='LI(OAMHolo(OAMHolo(XX,e,6),f,2),a,f)' In [8]: from sympy import S In [9]: S(setupstr) Out[9]: LI(OAMHolo(OAMHolo(XX, e, 6), f, 2), a, f) On Thu, 4 Apr 2019 at 15:41, Xuemei Gu wrote: > > Thank you very much! > > I have another question: > > I get a string list such as setupstr='LI(OAMHolo(OAMHolo(XX,e,6),f,2),a,f)' > > however in the string, LI OAMHolo are own defined functions, I don't know how > to replace them as functions. > I want to know how to do in sympy like I use ToExpression in Mathematica. > > Thank you very much! > best regards > Mei > > On Mon, Apr 1, 2019 at 9:31 PM Aaron Meurer wrote: >> >> I was hoping something like collect(x*y + x, [x, y], evaluate=False) >> would do what you want, but it doesn't quite. >> >> You could create a Poly with the coefficients as variables and use >> Poly.as_coefficients_dict. >> >> Aaron Meurer >> >> On Mon, Apr 1, 2019 at 1:02 PM Xuemei Gu wrote: >> > >> > >> > hey, >> > >> > I wander whether one has occurred such problem: >> > >> > I define a initial state: >> > >> > state=a[1]*b[0]*c[0]*d[0]*1j+a[1]*b[0]*c[0]*d[0] + a[2]*b[1]*c[1]*d[1] >> > # for some reason I have to do such decomposition >> > >> > datalist=state.as_coefficients_dict() >> > >> > >> > I can get: >> > { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, >> > I*FF2[0]*FF3[0]*FF4[0]: 1 } >> > >> > Now the problem is : >> > >> > Because I is a Imaginary number, it's not a symbol. How can I get >> > something such as { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, >> > FF2[0]*FF3[0]*FF4[0]: 1j} or { FF2[0]*FF3[0]*FF4[0]: 1+1j, >> > FF2[1]*FF3[1]*FF4[1]: 1 } >> > >> > Thank you very much! >> > >> > >> > >> > >> > -- >> > 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 post to this group, send email to sympy@googlegroups.com. >> > Visit this group at https://groups.google.com/group/sympy. >> > To view this discussion on the web visit >> > https://groups.google.com/d/msgid/sympy/d4505824-6110-4541-8199-09b6768315d9%40googlegroups.com. >> > For more options, visit https://groups.google.com/d/optout. >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "sympy" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/sympy/GKRuQ1iYgEI/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> sympy+unsubscr...@googlegroups.com. >> To post to this group, send email to sympy@googlegroups.com. >> Visit this group at https://groups.google.com/group/sympy. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/CAKgW%3D6J5MX4JqkoRkVaL1a6C57wpGBKaXBH%3DhOZeK-cPe04SKg%40mail.gmail.com. >> For more options, visit https://groups.google.com/d/optout. > > > > -- > Xuemei Gu > PhD Student > > State Key Laboratory for Novel Software Technology, Nanjing University > 163 Xianlin Avenue, Qixia District, 210023, Nanjing City, China > > Institute for Quantum Optics and Quantum Information, Vienna > Boltzmanngasse 3, A-1090 Vienna, Austria > > http://iqoqi-vienna.at/ > Office: +43 (0) 1 4277 29568 > > -- > 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 post to this group, send email to sympy@googlegroups.com. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/CA%2BDAqr9yd3BkQnNYQ%3Dp6cXKccc8yZrFgirqxB3DmxEq%3Djy1grg%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- 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 post to this group, send email to sympy@googlegroups.com. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxR77kisBe8rkjsZ8cVgvqwf5Ggd5BuaKuBfFwRK0sWdsA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [sympy] problem with Imaginary in sympy
Thank you very much! I have another question: I get a string list such as setupstr='LI(OAMHolo(OAMHolo(XX,e,6),f,2),a,f)' however in the string, LI OAMHolo are own defined functions, I don't know how to replace them as functions. I want to know how to do in sympy like I use ToExpression in Mathematica. Thank you very much! best regards Mei On Mon, Apr 1, 2019 at 9:31 PM Aaron Meurer wrote: > I was hoping something like collect(x*y + x, [x, y], evaluate=False) > would do what you want, but it doesn't quite. > > You could create a Poly with the coefficients as variables and use > Poly.as_coefficients_dict. > > Aaron Meurer > > On Mon, Apr 1, 2019 at 1:02 PM Xuemei Gu wrote: > > > > > > hey, > > > > I wander whether one has occurred such problem: > > > > I define a initial state: > > > > state=a[1]*b[0]*c[0]*d[0]*1j+a[1]*b[0]*c[0]*d[0] + a[2]*b[1]*c[1]*d[1] ># for some reason I have to do such decomposition > > > > datalist=state.as_coefficients_dict() > > > > > > I can get: > > { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, > I*FF2[0]*FF3[0]*FF4[0]: 1 } > > > > Now the problem is : > > > > Because I is a Imaginary number, it's not a symbol. How can I get > something such as { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, > FF2[0]*FF3[0]*FF4[0]: 1j} or { FF2[0]*FF3[0]*FF4[0]: 1+1j, > FF2[1]*FF3[1]*FF4[1]: 1 } > > > > Thank you very much! > > > > > > > > > > -- > > 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 post to this group, send email to sympy@googlegroups.com. > > Visit this group at https://groups.google.com/group/sympy. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/d4505824-6110-4541-8199-09b6768315d9%40googlegroups.com > . > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sympy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sympy/GKRuQ1iYgEI/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > sympy+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@googlegroups.com. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/CAKgW%3D6J5MX4JqkoRkVaL1a6C57wpGBKaXBH%3DhOZeK-cPe04SKg%40mail.gmail.com > . > For more options, visit https://groups.google.com/d/optout. > -- Xuemei Gu PhD Student State Key Laboratory for Novel Software Technology, Nanjing University 163 Xianlin Avenue, Qixia District, 210023, Nanjing City, China Institute for Quantum Optics and Quantum Information, Vienna Boltzmanngasse 3, A-1090 Vienna, Austria http://iqoqi-vienna.at/ Office: +43 (0) 1 4277 29568 -- 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 post to this group, send email to sympy@googlegroups.com. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CA%2BDAqr9yd3BkQnNYQ%3Dp6cXKccc8yZrFgirqxB3DmxEq%3Djy1grg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [sympy] problem with Imaginary in sympy
I was hoping something like collect(x*y + x, [x, y], evaluate=False) would do what you want, but it doesn't quite. You could create a Poly with the coefficients as variables and use Poly.as_coefficients_dict. Aaron Meurer On Mon, Apr 1, 2019 at 1:02 PM Xuemei Gu wrote: > > > hey, > > I wander whether one has occurred such problem: > > I define a initial state: > > state=a[1]*b[0]*c[0]*d[0]*1j+a[1]*b[0]*c[0]*d[0] + a[2]*b[1]*c[1]*d[1] # > for some reason I have to do such decomposition > > datalist=state.as_coefficients_dict() > > > I can get: > { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, > I*FF2[0]*FF3[0]*FF4[0]: 1 } > > Now the problem is : > > Because I is a Imaginary number, it's not a symbol. How can I get something > such as { FF2[0]*FF3[0]*FF4[0]: 1, FF2[1]*FF3[1]*FF4[1]: 1, > FF2[0]*FF3[0]*FF4[0]: 1j} or { FF2[0]*FF3[0]*FF4[0]: 1+1j, > FF2[1]*FF3[1]*FF4[1]: 1 } > > Thank you very much! > > > > > -- > 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 post to this group, send email to sympy@googlegroups.com. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/d4505824-6110-4541-8199-09b6768315d9%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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 post to this group, send email to sympy@googlegroups.com. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6J5MX4JqkoRkVaL1a6C57wpGBKaXBH%3DhOZeK-cPe04SKg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.