On Sun, Jul 7, 2013 at 12:03 PM, Aaron Meurer <asmeu...@gmail.com> wrote: > > > > On Sat, Jul 6, 2013 at 5:45 PM, Amit Saha <amitsaha...@gmail.com> wrote: >> >> On Sun, Jul 7, 2013 at 4:50 AM, Aaron Meurer <asmeu...@gmail.com> wrote: >> > I think you are confusing the assumptions system and the numeric classes >> > in >> > SymPy. >> > >> > First, for the numeric classes, SymPy does not have a complex type. >> > Rather, >> > we just have the object I, which represents sqrt(-1). If you want 12 + >> > 3*I, >> > you just type exactly that. Internally, it is represented as Add(12, >> > Mul(3, >> > I)). One difference you'll notice here is that, because it is just an >> > Add, >> > things like (12 + 3*I)**2 or 1/(12 + 2*I) are not reevaluated to real + >> > imag*I by default. You can use expand_complex() to do that (or >> > as_real_imag >> > if you want to pull out the real and imaginary parts). >> >> Thanks for the explanation. Here is what I tried: >> >> >>> from sympy import Symbol >> >>> >> >>> i=Symbol('i') >> >>> c = 1 + 2*i >> >>> c.as_real_imag(c) >> (2*re(i) + 1, 2*im(i)) >> >> Good so far, I understand that the real and imaginary components are >> being expressed as multiples of the real and and imaginary components >> of i, respectively. >> >> Now, I tried to to add this to a native CPython complex number: >> >> >>> c = c + 1+2j >> >>> c.as_real_imag(c) >> (2*re(i) + 2, 2*im(i) + 2.0) >> >> Here the real part is clear to me: 2*re(i) + 2 = 2*0 + 2 = 2 >> >> But, I don't quite understand what the imaginary part: 2*im(i) + 2 is >> supposed to mean. I was expecting it to be 4*im(i). > > > Why? Symbol('i') has nothing to do with sqrt(-1). It's just a symbol named > i. If you want sqrt(-1), use I (not Symbol('I'), just I). > > If you look, your c is 2 + 2*i + 2*I. The i is Symbol('i') and the I is > sqrt(-1), which comes from the 2j. > > It's also clear if you enable unicode pretty printing, because I is printed > as ⅈ.
My mistake, I assumed that i and I both would be understood as denoting an imaginary object. Thanks, it's clear now. > > Aaron Meurer > >> >> >> >> > >> > Now, for the assumptions. Symbol('x', complex=True) means that the >> > symbol is >> > assumed to be complex. This is in contrast to Symbol('x', real=True), >> > which >> > is assumed to be real. This matters for things like x.is_real, and >> > affects >> > how things are simplified. For example, sqrt(x**2) == x only when x is >> > positive, so it will remain unevaluated by default, but if you create >> > Symbol('x', positive=True), then sqrt(x**2) will simplify to just x. >> > >> > Symbols are assumed to be complex by default, so actually Symbol('x', >> > complex=True) is unnecessary. Actually, this isn't entirely true; >> > apparently >> > Symbol('x', complex=True) is different from just Symbol('x'), which I >> > don't >> > entirely understand why. I think this might be a bug. Could you open an >> > issue for it? >> >> >> Filed: https://github.com/sympy/sympy/issues/2260 >> >> I hope I got the description right. >> >> Thanks, >> Amit. >> >> >> >> -- >> http://echorand.me >> >> -- >> 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 http://groups.google.com/group/sympy. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > -- > 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 http://groups.google.com/group/sympy. > For more options, visit https://groups.google.com/groups/opt_out. > > -- http://echorand.me -- 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 http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.